diff --git a/gfx/layers/d3d9/TextureD3D9.cpp b/gfx/layers/d3d9/TextureD3D9.cpp index 189ff4e5e7eb..0d487b1783d3 100644 --- a/gfx/layers/d3d9/TextureD3D9.cpp +++ b/gfx/layers/d3d9/TextureD3D9.cpp @@ -288,16 +288,24 @@ TextureSourceD3D9::SurfaceToTexture(DeviceManagerD3D9* aDeviceManager, return nullptr; } - nsRefPtr imgSurface = - new gfxImageSurface(reinterpret_cast(lockedRect.pBits), - gfxIntSize(aSize.width, aSize.height), - lockedRect.Pitch, - gfxPlatform::GetPlatform()->OptimalFormatForContent(aSurface->GetContentType())); + { + RefPtr dt = + Factory::CreateDrawTargetForData(BackendType::CAIRO, + reinterpret_cast(lockedRect.pBits), + aSize, lockedRect.Pitch, + gfxPlatform::GetPlatform()->Optimal2DFormatForContent(aSurface->GetContentType())); + NativeSurface nativeSurf; + nativeSurf.mSize = aSize; + nativeSurf.mType = NativeSurfaceType::CAIRO_SURFACE; + // We don't know that this is actually the right format, but it's the best + // we can get for the content type. In practice this probably always works. + nativeSurf.mFormat = dt->GetFormat(); + nativeSurf.mSurface = aSurface->CairoSurface(); - nsRefPtr context = new gfxContext(imgSurface); - context->SetSource(aSurface); - context->SetOperator(gfxContext::OPERATOR_SOURCE); - context->Paint(); + RefPtr surf = dt->CreateSourceSurfaceFromNativeSurface(nativeSurf); + + dt->CopySurface(surf, IntRect(IntPoint(), aSize), IntPoint()); + } FinishTextures(aDeviceManager, texture, surface);