From 9de2acbf91e1bba3c859af8ecc2caff8170b298b Mon Sep 17 00:00:00 2001 From: Nicholas Cameron Date: Thu, 28 Nov 2013 10:16:34 +1300 Subject: [PATCH] Bug 893301. Changes to texture clients. r=nical --- gfx/layers/client/CompositableClient.cpp | 54 +++++++++++++++++++++--- gfx/layers/client/CompositableClient.h | 9 ++++ gfx/layers/client/TextureClient.cpp | 13 ++++++ gfx/layers/client/TextureClient.h | 15 ++++++- 4 files changed, 85 insertions(+), 6 deletions(-) diff --git a/gfx/layers/client/CompositableClient.cpp b/gfx/layers/client/CompositableClient.cpp index 8b94bf07799b..63984f396e85 100644 --- a/gfx/layers/client/CompositableClient.cpp +++ b/gfx/layers/client/CompositableClient.cpp @@ -15,8 +15,11 @@ #include "mozilla/layers/TextureD3D9.h" #include "mozilla/layers/TextureD3D11.h" #include "gfxWindowsPlatform.h" +#include "gfx2DGlue.h" #endif +using namespace mozilla::gfx; + namespace mozilla { namespace layers { @@ -193,8 +196,8 @@ CompositableClient::CreateDeprecatedTextureClient(DeprecatedTextureClientType aD } TemporaryRef -CompositableClient::CreateBufferTextureClient(gfx::SurfaceFormat aFormat, - uint32_t aTextureFlags) +CompositableClient::CreateBufferTextureClient(SurfaceFormat aFormat, + TextureFlags aTextureFlags) { // XXX - Once bug 908196 is fixed, we can use gralloc textures here which will // improve performances of videos using SharedPlanarYCbCrImage on b2g. @@ -214,15 +217,56 @@ CompositableClient::CreateBufferTextureClient(gfx::SurfaceFormat aFormat, return result.forget(); } -bool -CompositableClient::AddTextureClient(TextureClient* aClient) +TemporaryRef +CompositableClient::CreateTextureClientForDrawing(SurfaceFormat aFormat, + TextureFlags aTextureFlags) +{ + RefPtr result; + +#ifdef XP_WIN + LayersBackend parentBackend = GetForwarder()->GetCompositorBackendType(); + // XXX[nrc] uncomment once we have new texture clients for windows + if (parentBackend == LAYERS_D3D11 && gfxWindowsPlatform::GetPlatform()->GetD2DDevice() && + !(aTextureFlags & TEXTURE_ALLOC_FALLBACK)) { + //result = new TextureClientD3D11(GetForwarder(), GetTextureInfo()); + } + if (parentBackend == LAYERS_D3D9 && + !GetForwarder()->ForwardsToDifferentProcess() && + !(aTextureFlags & TEXTURE_ALLOC_FALLBACK)) { + // non-DIB textures don't work with alpha, see notes in TextureD3D9. + if (ContentForFormat(aFormat) == GFX_CONTENT_COLOR_ALPHA) { + //result = new TextureClientDIB(GetForwarder(), GetTextureInfo()); + } else { + //result = new TextureClientD3D9(GetForwarder(), GetTextureInfo()); + } + } +#endif + // Can't do any better than a buffer texture client. + if (!result) { + result = CreateBufferTextureClient(aFormat, aTextureFlags); + } + + MOZ_ASSERT(!result || result->AsTextureClientDrawTarget(), + "Not a TextureClientDrawTarget?"); + return result; +} + +uint64_t +CompositableClient::NextTextureID() { ++mNextTextureID; // 0 is always an invalid ID if (mNextTextureID == 0) { ++mNextTextureID; } - aClient->SetID(mNextTextureID); + + return mNextTextureID; +} + +bool +CompositableClient::AddTextureClient(TextureClient* aClient) +{ + aClient->SetID(NextTextureID()); return mForwarder->AddTexture(this, aClient); } diff --git a/gfx/layers/client/CompositableClient.h b/gfx/layers/client/CompositableClient.h index 6078bd6feb87..b5a50cb366c4 100644 --- a/gfx/layers/client/CompositableClient.h +++ b/gfx/layers/client/CompositableClient.h @@ -88,6 +88,12 @@ public: CreateBufferTextureClient(gfx::SurfaceFormat aFormat, TextureFlags aFlags = TEXTURE_FLAGS_DEFAULT); + // If we return a non-null TextureClient, then AsTextureClientDrawTarget will + // always be non-null. + TemporaryRef + CreateTextureClientForDrawing(gfx::SurfaceFormat aFormat, + TextureFlags aTextureFlags); + virtual void SetDescriptorFromReply(TextureIdentifier aTextureId, const SurfaceDescriptor& aDescriptor) { @@ -168,6 +174,9 @@ public: virtual void OnActorDestroy() = 0; protected: + // return the next texture ID + uint64_t NextTextureID(); + struct TextureIDAndFlags { TextureIDAndFlags(uint64_t aID, TextureFlags aFlags) : mID(aID), mFlags(aFlags) {} diff --git a/gfx/layers/client/TextureClient.cpp b/gfx/layers/client/TextureClient.cpp index f4d67e0c21a7..cfbe1c4ca1f7 100644 --- a/gfx/layers/client/TextureClient.cpp +++ b/gfx/layers/client/TextureClient.cpp @@ -321,6 +321,19 @@ BufferTextureClient::AllocateForSurface(gfx::IntSize aSize) return true; } +TemporaryRef +BufferTextureClient::GetAsDrawTarget() +{ + MOZ_ASSERT(IsValid()); + + ImageDataSerializer serializer(GetBuffer()); + if (!serializer.IsValid()) { + return nullptr; + } + + return serializer.GetAsDrawTarget(); +} + bool BufferTextureClient::UpdateYCbCr(const PlanarYCbCrData& aData) { diff --git a/gfx/layers/client/TextureClient.h b/gfx/layers/client/TextureClient.h index 55fad537f8d7..9d09d1d36eb3 100644 --- a/gfx/layers/client/TextureClient.h +++ b/gfx/layers/client/TextureClient.h @@ -59,6 +59,17 @@ public: virtual bool AllocateForSurface(gfx::IntSize aSize) = 0; }; +/** + * Interface for TextureClients that can be updated using a DrawTarget. + */ +class TextureClientDrawTarget +{ +public: + virtual TemporaryRef GetAsDrawTarget() = 0; + virtual gfx::SurfaceFormat GetFormat() const = 0; + virtual bool AllocateForSurface(gfx::IntSize aSize) = 0; +}; + /** * Interface for TextureClients that can be updated using YCbCr data. */ @@ -124,6 +135,7 @@ public: virtual ~TextureClient(); virtual TextureClientSurface* AsTextureClientSurface() { return nullptr; } + virtual TextureClientDrawTarget* AsTextureClientDrawTarget() { return nullptr; } virtual TextureClientYCbCr* AsTextureClientYCbCr() { return nullptr; } /** @@ -240,7 +252,8 @@ protected: */ class BufferTextureClient : public TextureClient , public TextureClientSurface - , TextureClientYCbCr + , public TextureClientYCbCr + , public TextureClientDrawTarget { public: BufferTextureClient(CompositableClient* aCompositable, gfx::SurfaceFormat aFormat,