зеркало из https://github.com/mozilla/gecko-dev.git
Bug 597950 - Part 1: Add API to create a D2D surface from a D3D10 Texture. r=vlad
This commit is contained in:
Родитель
748194ef3d
Коммит
afde1b864a
|
@ -3791,6 +3791,89 @@ FAIL_CREATEHANDLE:
|
|||
return _cairo_surface_create_in_error(_cairo_error(status));
|
||||
}
|
||||
|
||||
cairo_surface_t *
|
||||
cairo_d2d_surface_create_for_texture(cairo_device_t *device,
|
||||
ID3D10Texture2D *texture,
|
||||
cairo_content_t content)
|
||||
{
|
||||
cairo_d2d_device_t *d2d_device = reinterpret_cast<cairo_d2d_device_t*>(device);
|
||||
cairo_d2d_surface_t *newSurf = static_cast<cairo_d2d_surface_t*>(malloc(sizeof(cairo_d2d_surface_t)));
|
||||
new (newSurf) cairo_d2d_surface_t();
|
||||
|
||||
D2D1_ALPHA_MODE alpha = D2D1_ALPHA_MODE_PREMULTIPLIED;
|
||||
if (content == CAIRO_CONTENT_COLOR) {
|
||||
_cairo_surface_init(&newSurf->base, &cairo_d2d_surface_backend, CAIRO_CONTENT_COLOR);
|
||||
alpha = D2D1_ALPHA_MODE_IGNORE;
|
||||
} else {
|
||||
_cairo_surface_init(&newSurf->base, &cairo_d2d_surface_backend, content);
|
||||
}
|
||||
|
||||
D2D1_SIZE_U sizePixels;
|
||||
HRESULT hr;
|
||||
|
||||
D3D10_TEXTURE2D_DESC desc;
|
||||
RefPtr<IDXGISurface> dxgiSurface;
|
||||
D2D1_BITMAP_PROPERTIES bitProps;
|
||||
D2D1_RENDER_TARGET_PROPERTIES props;
|
||||
|
||||
texture->GetDesc(&desc);
|
||||
|
||||
sizePixels.width = desc.Width;
|
||||
sizePixels.height = desc.Height;
|
||||
|
||||
newSurf->surface = texture;
|
||||
|
||||
/** Create the DXGI surface. */
|
||||
hr = newSurf->surface->QueryInterface(IID_IDXGISurface, (void**)&dxgiSurface);
|
||||
if (FAILED(hr)) {
|
||||
goto FAIL_CREATE;
|
||||
}
|
||||
|
||||
props = D2D1::RenderTargetProperties(D2D1_RENDER_TARGET_TYPE_DEFAULT,
|
||||
D2D1::PixelFormat(DXGI_FORMAT_UNKNOWN, alpha));
|
||||
|
||||
if (desc.MiscFlags & D3D10_RESOURCE_MISC_GDI_COMPATIBLE)
|
||||
props.usage = D2D1_RENDER_TARGET_USAGE_GDI_COMPATIBLE;
|
||||
|
||||
hr = sD2DFactory->CreateDxgiSurfaceRenderTarget(dxgiSurface,
|
||||
props,
|
||||
&newSurf->rt);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
goto FAIL_CREATE;
|
||||
}
|
||||
|
||||
bitProps = D2D1::BitmapProperties(D2D1::PixelFormat(DXGI_FORMAT_UNKNOWN,
|
||||
alpha));
|
||||
|
||||
if (content != CAIRO_CONTENT_ALPHA) {
|
||||
/* For some reason creation of shared bitmaps for A8 UNORM surfaces
|
||||
* doesn't work even though the documentation suggests it does. The
|
||||
* function will return an error if we try */
|
||||
hr = newSurf->rt->CreateSharedBitmap(IID_IDXGISurface,
|
||||
dxgiSurface,
|
||||
&bitProps,
|
||||
&newSurf->surfaceBitmap);
|
||||
|
||||
if (FAILED(hr)) {
|
||||
goto FAIL_CREATE;
|
||||
}
|
||||
}
|
||||
|
||||
newSurf->rt->CreateSolidColorBrush(D2D1::ColorF(0, 1.0), &newSurf->solidColorBrush);
|
||||
|
||||
newSurf->device = d2d_device;
|
||||
cairo_addref_device(device);
|
||||
d2d_device->mVRAMUsage += _cairo_d2d_compute_surface_mem_size(newSurf);
|
||||
|
||||
return reinterpret_cast<cairo_surface_t*>(newSurf);
|
||||
|
||||
FAIL_CREATE:
|
||||
newSurf->~cairo_d2d_surface_t();
|
||||
free(newSurf);
|
||||
return _cairo_surface_create_in_error(_cairo_error(CAIRO_STATUS_NO_MEMORY));
|
||||
}
|
||||
|
||||
void cairo_d2d_scroll(cairo_surface_t *surface, int x, int y, cairo_rectangle_t *clip)
|
||||
{
|
||||
if (surface->type != CAIRO_SURFACE_TYPE_D2D) {
|
||||
|
|
|
@ -217,6 +217,22 @@ cairo_d2d_surface_create(cairo_device_t *device,
|
|||
cairo_public cairo_surface_t *
|
||||
cairo_d2d_surface_create_for_handle(cairo_device_t *device, HANDLE handle, cairo_content_t content);
|
||||
|
||||
/**
|
||||
* Create a D3D surface from an ID3D10Texture2D texture, this is obtained from a
|
||||
* CreateTexture2D call on a D3D10 device. This has to be an A8R8G8B8 format
|
||||
* or an A8 format, the treatment of the alpha channel can be indicated using
|
||||
* the content parameter.
|
||||
*
|
||||
* \param device Device used to create the surface
|
||||
* \param texture Texture that we want to wrap
|
||||
* \param content Content of the texture
|
||||
* \return New cairo surface
|
||||
*/
|
||||
cairo_public cairo_surface_t *
|
||||
cairo_d2d_surface_create_for_texture(cairo_device_t *device,
|
||||
struct ID3D10Texture2D *texture,
|
||||
cairo_content_t content);
|
||||
|
||||
/**
|
||||
* Present the backbuffer for a surface create for an HWND. This needs
|
||||
* to be called when the owner of the original window surface wants to
|
||||
|
|
Загрузка…
Ссылка в новой задаче