diff --git a/gfx/layers/composite/TextureHost.h b/gfx/layers/composite/TextureHost.h index 37ee46613aa7..b40c9a97e3a6 100644 --- a/gfx/layers/composite/TextureHost.h +++ b/gfx/layers/composite/TextureHost.h @@ -175,6 +175,16 @@ class CompositableTextureRef { public: CompositableTextureRef() {} + explicit CompositableTextureRef(const CompositableTextureRef& aOther) + { + *this = aOther; + } + + explicit CompositableTextureRef(T* aOther) + { + *this = aOther; + } + ~CompositableTextureRef() { if (mRef) { @@ -182,6 +192,18 @@ public: } } + CompositableTextureRef& operator=(const CompositableTextureRef& aOther) + { + if (aOther.get()) { + aOther->AddCompositableRef(); + } + if (mRef) { + mRef->ReleaseCompositableRef(); + } + mRef = aOther.get(); + return *this; + } + CompositableTextureRef& operator=(const TemporaryRef& aOther) { RefPtr temp = aOther; diff --git a/gfx/layers/composite/TiledContentHost.cpp b/gfx/layers/composite/TiledContentHost.cpp index 6cd580dd9396..8ce13402ce99 100644 --- a/gfx/layers/composite/TiledContentHost.cpp +++ b/gfx/layers/composite/TiledContentHost.cpp @@ -41,7 +41,8 @@ TiledLayerBufferComposite::RecycleCallback(TextureHost* textureHost, void* aClos TiledLayerBufferComposite::TiledLayerBufferComposite(ISurfaceAllocator* aAllocator, const SurfaceDescriptorTiles& aDescriptor, - const nsIntRegion& aOldPaintedRegion) + const nsIntRegion& aOldPaintedRegion, + Compositor* aCompositor) { mIsValid = true; mHasDoubleBufferedTiles = false; @@ -61,8 +62,8 @@ TiledLayerBufferComposite::TiledLayerBufferComposite(ISurfaceAllocator* aAllocat const InfallibleTArray& tiles = aDescriptor.tiles(); for(size_t i = 0; i < tiles.Length(); i++) { - RefPtr texture; - RefPtr textureOnWhite; + CompositableTextureHostRef texture; + CompositableTextureHostRef textureOnWhite; const TileDescriptor& tileDesc = tiles[i]; switch (tileDesc.type()) { case TileDescriptor::TTexturedTileDescriptor : { @@ -94,7 +95,21 @@ TiledLayerBufferComposite::TiledLayerBufferComposite(ISurfaceAllocator* aAllocat } } - mRetainedTiles.AppendElement(TileHost(sharedLock, texture, textureOnWhite)); + CompositableTextureSourceRef textureSource; + CompositableTextureSourceRef textureSourceOnWhite; + if (texture) { + texture->SetCompositor(aCompositor); + texture->PrepareTextureSource(textureSource); + } + if (textureOnWhite) { + textureOnWhite->SetCompositor(aCompositor); + textureOnWhite->PrepareTextureSource(textureSourceOnWhite); + } + mRetainedTiles.AppendElement(TileHost(sharedLock, + texture.get(), + textureOnWhite.get(), + textureSource.get(), + textureSourceOnWhite.get())); break; } default: @@ -130,6 +145,8 @@ TiledLayerBufferComposite::ReleaseTextureHosts() for (size_t i = 0; i < mRetainedTiles.Length(); i++) { mRetainedTiles[i].mTextureHost = nullptr; mRetainedTiles[i].mTextureHostOnWhite = nullptr; + mRetainedTiles[i].mTextureSource = nullptr; + mRetainedTiles[i].mTextureSourceOnWhite = nullptr; } } @@ -321,8 +338,10 @@ TiledContentHost::UseTiledLayerBuffer(ISurfaceAllocator* aAllocator, } } mLowPrecisionTiledBuffer = - TiledLayerBufferComposite(aAllocator, aTiledDescriptor, - mLowPrecisionTiledBuffer.GetPaintedRegion()); + TiledLayerBufferComposite(aAllocator, + aTiledDescriptor, + mLowPrecisionTiledBuffer.GetPaintedRegion(), + mCompositor); if (!mLowPrecisionTiledBuffer.IsValid()) { // Something bad happened. Stop here, return false (kills the child process), // and do as little work as possible on the received data as it appears @@ -341,8 +360,10 @@ TiledContentHost::UseTiledLayerBuffer(ISurfaceAllocator* aAllocator, mOldTiledBuffer.ReleaseTextureHosts(); } } - mTiledBuffer = TiledLayerBufferComposite(aAllocator, aTiledDescriptor, - mTiledBuffer.GetPaintedRegion()); + mTiledBuffer = TiledLayerBufferComposite(aAllocator, + aTiledDescriptor, + mTiledBuffer.GetPaintedRegion(), + mCompositor); if (!mTiledBuffer.IsValid()) { // Something bad happened. Stop here, return false (kills the child process), // and do as little work as possible on the received data as it appears @@ -477,14 +498,16 @@ TiledContentHost::RenderTile(const TileHost& aTile, NS_WARNING("Failed to lock tile"); return; } - RefPtr source = aTile.mTextureHost->GetTextureSources(); - RefPtr sourceOnWhite = - aTile.mTextureHostOnWhite ? aTile.mTextureHostOnWhite->GetTextureSources() : nullptr; - if (!source || (aTile.mTextureHostOnWhite && !sourceOnWhite)) { + + if (!aTile.mTextureHost->BindTextureSource(aTile.mTextureSource)) { return; } - RefPtr effect = CreateTexturedEffect(source, sourceOnWhite, aFilter, true); + if (aTile.mTextureHostOnWhite && !aTile.mTextureHostOnWhite->BindTextureSource(aTile.mTextureSourceOnWhite)) { + return; + } + + RefPtr effect = CreateTexturedEffect(aTile.mTextureSource, aTile.mTextureSourceOnWhite, aFilter, true); if (!effect) { return; } diff --git a/gfx/layers/composite/TiledContentHost.h b/gfx/layers/composite/TiledContentHost.h index 66450f3b9bd7..11e70758110f 100644 --- a/gfx/layers/composite/TiledContentHost.h +++ b/gfx/layers/composite/TiledContentHost.h @@ -62,15 +62,21 @@ public: // Constructs a TileHost from a gfxSharedReadLock and TextureHost. TileHost(gfxSharedReadLock* aSharedLock, TextureHost* aTextureHost, - TextureHost* aTextureHostOnWhite) + TextureHost* aTextureHostOnWhite, + TextureSource* aSource, + TextureSource* aSourceOnWhite) : mSharedLock(aSharedLock) , mTextureHost(aTextureHost) , mTextureHostOnWhite(aTextureHostOnWhite) + , mTextureSource(aSource) + , mTextureSourceOnWhite(aSourceOnWhite) {} TileHost(const TileHost& o) { mTextureHost = o.mTextureHost; mTextureHostOnWhite = o.mTextureHostOnWhite; + mTextureSource = o.mTextureSource; + mTextureSourceOnWhite = o.mTextureSourceOnWhite; mSharedLock = o.mSharedLock; } TileHost& operator=(const TileHost& o) { @@ -79,6 +85,8 @@ public: } mTextureHost = o.mTextureHost; mTextureHostOnWhite = o.mTextureHostOnWhite; + mTextureSource = o.mTextureSource; + mTextureSourceOnWhite = o.mTextureSourceOnWhite; mSharedLock = o.mSharedLock; return *this; } @@ -99,8 +107,10 @@ public: } RefPtr mSharedLock; - RefPtr mTextureHost; - RefPtr mTextureHostOnWhite; + CompositableTextureHostRef mTextureHost; + CompositableTextureHostRef mTextureHostOnWhite; + mutable CompositableTextureSourceRef mTextureSource; + mutable CompositableTextureSourceRef mTextureSourceOnWhite; }; class TiledLayerBufferComposite @@ -114,7 +124,8 @@ public: TiledLayerBufferComposite(); TiledLayerBufferComposite(ISurfaceAllocator* aAllocator, const SurfaceDescriptorTiles& aDescriptor, - const nsIntRegion& aOldPaintedRegion); + const nsIntRegion& aOldPaintedRegion, + Compositor* aCompositor); TileHost GetPlaceholderTile() const { return TileHost(); }