diff --git a/gfx/layers/client/CanvasClient.cpp b/gfx/layers/client/CanvasClient.cpp index 24a4d34b9e5d..c9df87ab24a0 100644 --- a/gfx/layers/client/CanvasClient.cpp +++ b/gfx/layers/client/CanvasClient.cpp @@ -65,7 +65,9 @@ CanvasClient2D::Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer) : gfxContentType::COLOR_ALPHA; gfxImageFormat format = gfxPlatform::GetPlatform()->OptimalFormatForContent(contentType); - mBuffer = CreateBufferTextureClient(gfx::ImageFormatToSurfaceFormat(format)); + mBuffer = CreateBufferTextureClient(gfx::ImageFormatToSurfaceFormat(format), + TEXTURE_FLAGS_DEFAULT, + gfxPlatform::GetPlatform()->GetPreferredCanvasBackend()); MOZ_ASSERT(mBuffer->AsTextureClientSurface()); mBuffer->AsTextureClientSurface()->AllocateForSurface(aSize); @@ -100,10 +102,12 @@ CanvasClient2D::Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer) } TemporaryRef -CanvasClient2D::CreateBufferTextureClient(gfx::SurfaceFormat aFormat, TextureFlags aFlags) +CanvasClient2D::CreateBufferTextureClient(gfx::SurfaceFormat aFormat, TextureFlags aFlags, + gfx::BackendType aMoz2DBackend) { return CompositableClient::CreateBufferTextureClient(aFormat, - mTextureInfo.mTextureFlags | aFlags); + mTextureInfo.mTextureFlags | aFlags, + aMoz2DBackend); } CanvasClientSurfaceStream::CanvasClientSurfaceStream(CompositableForwarder* aLayerForwarder, diff --git a/gfx/layers/client/CanvasClient.h b/gfx/layers/client/CanvasClient.h index 0aa21b1a20fa..bf67c4705aee 100644 --- a/gfx/layers/client/CanvasClient.h +++ b/gfx/layers/client/CanvasClient.h @@ -90,7 +90,8 @@ public: virtual TemporaryRef CreateBufferTextureClient(gfx::SurfaceFormat aFormat, - TextureFlags aFlags = TEXTURE_FLAGS_DEFAULT) MOZ_OVERRIDE; + TextureFlags aFlags = TEXTURE_FLAGS_DEFAULT, + gfx::BackendType aMoz2DBackend = gfx::BackendType::NONE) MOZ_OVERRIDE; virtual void OnDetach() MOZ_OVERRIDE { diff --git a/gfx/layers/client/CompositableClient.cpp b/gfx/layers/client/CompositableClient.cpp index 3a8715c3bba7..a38ad0237680 100644 --- a/gfx/layers/client/CompositableClient.cpp +++ b/gfx/layers/client/CompositableClient.cpp @@ -179,7 +179,8 @@ CompositableClient::CreateDeprecatedTextureClient(DeprecatedTextureClientType aD TemporaryRef CompositableClient::CreateBufferTextureClient(SurfaceFormat aFormat, - TextureFlags aTextureFlags) + TextureFlags aTextureFlags, + gfx::BackendType aMoz2DBackend) { // XXX - Once bug 908196 is fixed, we can use gralloc textures here which will // improve performances of videos using SharedPlanarYCbCrImage on b2g. @@ -192,10 +193,14 @@ CompositableClient::CreateBufferTextureClient(SurfaceFormat aFormat, // } //#endif if (gfxPlatform::GetPlatform()->PreferMemoryOverShmem()) { - RefPtr result = new MemoryTextureClient(this, aFormat, aTextureFlags); + RefPtr result = new MemoryTextureClient(this, aFormat, + aMoz2DBackend, + aTextureFlags); return result.forget(); } - RefPtr result = new ShmemTextureClient(this, aFormat, aTextureFlags); + RefPtr result = new ShmemTextureClient(this, aFormat, + aMoz2DBackend, + aTextureFlags); return result.forget(); } @@ -234,17 +239,26 @@ DisableGralloc(SurfaceFormat aFormat) TemporaryRef CompositableClient::CreateTextureClientForDrawing(SurfaceFormat aFormat, - TextureFlags aTextureFlags) + TextureFlags aTextureFlags, + gfx::BackendType aMoz2DBackend) { + if (aMoz2DBackend == gfx::BackendType::NONE) { + aMoz2DBackend = gfxPlatform::GetPlatform()->GetContentBackend(); + } + RefPtr result; #ifdef XP_WIN LayersBackend parentBackend = GetForwarder()->GetCompositorBackendType(); - if (parentBackend == LayersBackend::LAYERS_D3D11 && gfxWindowsPlatform::GetPlatform()->GetD2DDevice() && + if (parentBackend == LayersBackend::LAYERS_D3D11 && + (aMoz2DBackend == gfx::BackendType::DIRECT2D || + aMoz2DBackend == gfx::BackendType::DIRECT2D1_1) && + gfxWindowsPlatform::GetPlatform()->GetD2DDevice() && !(aTextureFlags & TEXTURE_ALLOC_FALLBACK)) { result = new TextureClientD3D11(aFormat, aTextureFlags); } if (parentBackend == LayersBackend::LAYERS_D3D9 && + aMoz2DBackend == gfx::BackendType::CAIRO && !GetForwarder()->ForwardsToDifferentProcess() && !(aTextureFlags & TEXTURE_ALLOC_FALLBACK)) { if (!gfxWindowsPlatform::GetPlatform()->GetD3D9Device()) { @@ -261,6 +275,7 @@ CompositableClient::CreateTextureClientForDrawing(SurfaceFormat aFormat, gfxPlatform::GetPlatform()->ScreenReferenceSurface()->GetType(); if (parentBackend == LayersBackend::LAYERS_BASIC && + aMoz2DBackend == gfx::BackendType::CAIRO && type == gfxSurfaceType::Xlib && !(aTextureFlags & TEXTURE_ALLOC_FALLBACK)) { @@ -268,6 +283,7 @@ CompositableClient::CreateTextureClientForDrawing(SurfaceFormat aFormat, } #ifdef GL_PROVIDER_GLX if (parentBackend == LayersBackend::LAYERS_OPENGL && + aMoz2DBackend == gfx::BackendType::CAIRO && type == gfxSurfaceType::Xlib && !(aTextureFlags & TEXTURE_ALLOC_FALLBACK) && aFormat != SurfaceFormat::A8 && @@ -286,7 +302,7 @@ CompositableClient::CreateTextureClientForDrawing(SurfaceFormat aFormat, // Can't do any better than a buffer texture client. if (!result) { - result = CreateBufferTextureClient(aFormat, aTextureFlags); + result = CreateBufferTextureClient(aFormat, aTextureFlags, aMoz2DBackend); } MOZ_ASSERT(!result || result->AsTextureClientDrawTarget(), diff --git a/gfx/layers/client/CompositableClient.h b/gfx/layers/client/CompositableClient.h index ce4144cdc9ba..09e1a2032735 100644 --- a/gfx/layers/client/CompositableClient.h +++ b/gfx/layers/client/CompositableClient.h @@ -84,15 +84,22 @@ public: CreateDeprecatedTextureClient(DeprecatedTextureClientType aDeprecatedTextureClientType, gfxContentType aContentType = gfxContentType::SENTINEL); + // Creates a TextureClient that can be mapped in memory and access through a + // raw pointer. + // Generally it is best to use CreateTextureClientForDrawing and draw into + // the texture through Moz2D. virtual TemporaryRef CreateBufferTextureClient(gfx::SurfaceFormat aFormat, - TextureFlags aFlags = TEXTURE_FLAGS_DEFAULT); + TextureFlags aFlags = TEXTURE_FLAGS_DEFAULT, + gfx::BackendType aMoz2DBackend = gfx::BackendType::NONE); // If we return a non-null TextureClient, then AsTextureClientDrawTarget will // always be non-null. + // If aBackend is NONE, default to the content backend type. TemporaryRef CreateTextureClientForDrawing(gfx::SurfaceFormat aFormat, - TextureFlags aTextureFlags); + TextureFlags aTextureFlags, + gfx::BackendType aMoz2DBackend = gfx::BackendType::NONE); virtual void SetDescriptorFromReply(TextureIdentifier aTextureId, const SurfaceDescriptor& aDescriptor) diff --git a/gfx/layers/client/ImageClient.cpp b/gfx/layers/client/ImageClient.cpp index 1cc212942cde..e084844c4d16 100644 --- a/gfx/layers/client/ImageClient.cpp +++ b/gfx/layers/client/ImageClient.cpp @@ -311,9 +311,11 @@ ImageClientSingle::AddTextureClient(TextureClient* aTexture) } TemporaryRef -ImageClientSingle::CreateBufferTextureClient(gfx::SurfaceFormat aFormat, TextureFlags aFlags) +ImageClientSingle::CreateBufferTextureClient(gfx::SurfaceFormat aFormat, TextureFlags aFlags, + gfx::BackendType aMoz2DBackend) { - return CompositableClient::CreateBufferTextureClient(aFormat, mTextureFlags | aFlags); + return CompositableClient::CreateBufferTextureClient(aFormat, mTextureFlags | aFlags, + aMoz2DBackend); } void diff --git a/gfx/layers/client/ImageClient.h b/gfx/layers/client/ImageClient.h index 81f700e33d26..056c67d27fc3 100644 --- a/gfx/layers/client/ImageClient.h +++ b/gfx/layers/client/ImageClient.h @@ -92,7 +92,8 @@ public: virtual TemporaryRef CreateBufferTextureClient(gfx::SurfaceFormat aFormat, - TextureFlags aFlags = TEXTURE_FLAGS_DEFAULT) MOZ_OVERRIDE; + TextureFlags aFlags = TEXTURE_FLAGS_DEFAULT, + gfx::BackendType aMoz2DBackend = gfx::BackendType::NONE) MOZ_OVERRIDE; virtual TextureInfo GetTextureInfo() const MOZ_OVERRIDE; diff --git a/gfx/layers/client/TextureClient.cpp b/gfx/layers/client/TextureClient.cpp index ab615b49363c..cf1cdaa7de70 100644 --- a/gfx/layers/client/TextureClient.cpp +++ b/gfx/layers/client/TextureClient.cpp @@ -365,8 +365,9 @@ ShmemTextureClient::GetBufferSize() const ShmemTextureClient::ShmemTextureClient(CompositableClient* aCompositable, gfx::SurfaceFormat aFormat, + gfx::BackendType aBackend, TextureFlags aFlags) - : BufferTextureClient(aCompositable, aFormat, aFlags) + : BufferTextureClient(aCompositable, aFormat, aBackend, aFlags) , mAllocated(false) { MOZ_COUNT_CTOR(ShmemTextureClient); @@ -411,8 +412,9 @@ MemoryTextureClient::Allocate(uint32_t aSize) MemoryTextureClient::MemoryTextureClient(CompositableClient* aCompositable, gfx::SurfaceFormat aFormat, + gfx::BackendType aBackend, TextureFlags aFlags) - : BufferTextureClient(aCompositable, aFormat, aFlags) + : BufferTextureClient(aCompositable, aFormat, aBackend, aFlags) , mBuffer(nullptr) , mBufSize(0) { @@ -432,10 +434,12 @@ MemoryTextureClient::~MemoryTextureClient() BufferTextureClient::BufferTextureClient(CompositableClient* aCompositable, gfx::SurfaceFormat aFormat, + gfx::BackendType aBackend, TextureFlags aFlags) : TextureClient(aFlags) , mCompositable(aCompositable) , mFormat(aFormat) + , mBackend(aBackend) , mUsingFallbackDrawTarget(false) , mLocked(false) {} @@ -538,15 +542,15 @@ BufferTextureClient::GetAsDrawTarget() } MOZ_ASSERT(mUsingFallbackDrawTarget == false); - mDrawTarget = serializer.GetAsDrawTarget(gfxPlatform::GetPlatform()->GetContentBackend()); + mDrawTarget = serializer.GetAsDrawTarget(mBackend); if (mDrawTarget) { return mDrawTarget; } // fallback path, probably because the Moz2D backend can't create a // DrawTarget around raw memory. This is going to be slow :( - mDrawTarget = gfxPlatform::GetPlatform()->CreateOffscreenContentDrawTarget( - serializer.GetSize(), serializer.GetFormat()); + mDrawTarget = gfx::Factory::CreateDrawTarget(mBackend, serializer.GetSize(), + serializer.GetFormat()); if (!mDrawTarget) { return nullptr; } diff --git a/gfx/layers/client/TextureClient.h b/gfx/layers/client/TextureClient.h index 4bfd7313f275..44ccad40c760 100644 --- a/gfx/layers/client/TextureClient.h +++ b/gfx/layers/client/TextureClient.h @@ -341,7 +341,7 @@ class BufferTextureClient : public TextureClient { public: BufferTextureClient(CompositableClient* aCompositable, gfx::SurfaceFormat aFormat, - TextureFlags aFlags); + gfx::BackendType aBackend, TextureFlags aFlags); virtual ~BufferTextureClient(); @@ -401,6 +401,7 @@ protected: CompositableClient* mCompositable; gfx::SurfaceFormat mFormat; gfx::IntSize mSize; + gfx::BackendType mBackend; OpenMode mOpenMode; bool mUsingFallbackDrawTarget; bool mLocked; @@ -414,7 +415,7 @@ class ShmemTextureClient : public BufferTextureClient { public: ShmemTextureClient(CompositableClient* aCompositable, gfx::SurfaceFormat aFormat, - TextureFlags aFlags); + gfx::BackendType aBackend, TextureFlags aFlags); ~ShmemTextureClient(); @@ -449,7 +450,7 @@ class MemoryTextureClient : public BufferTextureClient { public: MemoryTextureClient(CompositableClient* aCompositable, gfx::SurfaceFormat aFormat, - TextureFlags aFlags); + gfx::BackendType aBackend, TextureFlags aFlags); ~MemoryTextureClient(); diff --git a/gfx/tests/gtest/TestTextures.cpp b/gfx/tests/gtest/TestTextures.cpp index 9f48dbc10e17..eb9210690974 100644 --- a/gfx/tests/gtest/TestTextures.cpp +++ b/gfx/tests/gtest/TestTextures.cpp @@ -219,6 +219,7 @@ TEST(Layers, TextureSerialization) { RefPtr client = new MemoryTextureClient(nullptr, mozilla::gfx::ImageFormatToSurfaceFormat(surface->Format()), + gfx::BackendType::NONE, TEXTURE_DEALLOCATE_CLIENT); TestTextureClientSurface(client, surface); @@ -255,6 +256,7 @@ TEST(Layers, TextureYCbCrSerialization) { RefPtr client = new MemoryTextureClient(nullptr, mozilla::gfx::SurfaceFormat::YUV, + gfx::BackendType::NONE, TEXTURE_DEALLOCATE_CLIENT); TestTextureClientYCbCr(client, clientData);