diff --git a/gfx/layers/CompositorTypes.h b/gfx/layers/CompositorTypes.h index e882460612a0..ceaf02e66f29 100644 --- a/gfx/layers/CompositorTypes.h +++ b/gfx/layers/CompositorTypes.h @@ -156,10 +156,7 @@ enum class EffectTypes : uint8_t { */ enum class CompositableType : uint8_t { UNKNOWN, - CONTENT_TILED, // tiled painted layer - IMAGE, // image with single buffering - CONTENT_SINGLE, // painted layer interface, single buffering - CONTENT_DOUBLE, // painted layer interface, double buffering + IMAGE, // image with single buffering COUNT }; diff --git a/gfx/layers/LayerTreeInvalidation.cpp b/gfx/layers/LayerTreeInvalidation.cpp index 8c1e17c14602..9b7b735790e5 100644 --- a/gfx/layers/LayerTreeInvalidation.cpp +++ b/gfx/layers/LayerTreeInvalidation.cpp @@ -24,7 +24,6 @@ #include "nsRect.h" // for IntRect #include "nsTArray.h" // for AutoTArray, nsTArray_Impl #include "mozilla/Poison.h" -#include "mozilla/layers/ImageHost.h" #include "TreeTraversal.h" // for ForEachNode // LayerTreeInvalidation debugging @@ -613,32 +612,16 @@ struct ColorLayerProperties : public LayerPropertiesBase { IntRect mBounds; }; -static ImageHost* GetImageHost(Layer* aLayer) { return nullptr; } - struct ImageLayerProperties : public LayerPropertiesBase { explicit ImageLayerProperties(ImageLayer* aImage, bool aIsMask) : LayerPropertiesBase(aImage), mContainer(aImage->GetContainer()), - mImageHost(GetImageHost(aImage)), mSamplingFilter(aImage->GetSamplingFilter()), mScaleToSize(aImage->GetScaleToSize()), mScaleMode(aImage->GetScaleMode()), mLastProducerID(-1), mLastFrameID(-1), - mIsMask(aIsMask) { - if (mImageHost) { - if (aIsMask) { - // Mask layers never set the 'last' producer/frame - // id, since they never get composited as their own - // layer. - mLastProducerID = mImageHost->GetProducerID(); - mLastFrameID = mImageHost->GetFrameID(); - } else { - mLastProducerID = mImageHost->GetLastProducerID(); - mLastFrameID = mImageHost->GetLastFrameID(); - } - } - } + mIsMask(aIsMask) {} bool ComputeChangeInternal(const char* aPrefix, nsIntRegion& aOutRegion, NotifySubDocInvalidationFunc aCallback) override { @@ -653,13 +636,10 @@ struct ImageLayerProperties : public LayerPropertiesBase { } ImageContainer* container = imageLayer->GetContainer(); - ImageHost* host = GetImageHost(imageLayer); if (mContainer != container || mSamplingFilter != imageLayer->GetSamplingFilter() || mScaleToSize != imageLayer->GetScaleToSize() || - mScaleMode != imageLayer->GetScaleMode() || host != mImageHost || - (host && host->GetProducerID() != mLastProducerID) || - (host && host->GetFrameID() != mLastFrameID)) { + mScaleMode != imageLayer->GetScaleMode()) { if (mIsMask) { // Mask layers have an empty visible region, so we have to // use the image size instead. @@ -667,9 +647,6 @@ struct ImageLayerProperties : public LayerPropertiesBase { if (container) { size = container->GetCurrentSize(); } - if (host) { - size = host->GetImageSize(); - } IntRect rect(0, 0, size.width, size.height); LTI_DUMP(rect, "mask"); aOutRegion = TransformRect(rect, GetTransformForInvalidation(mLayer)); @@ -684,7 +661,6 @@ struct ImageLayerProperties : public LayerPropertiesBase { } RefPtr mContainer; - RefPtr mImageHost; SamplingFilter mSamplingFilter; gfx::IntSize mScaleToSize; ScaleMode mScaleMode; @@ -693,30 +669,6 @@ struct ImageLayerProperties : public LayerPropertiesBase { bool mIsMask; }; -struct CanvasLayerProperties : public LayerPropertiesBase { - explicit CanvasLayerProperties(CanvasLayer* aCanvas) - : LayerPropertiesBase(aCanvas), mImageHost(GetImageHost(aCanvas)) { - mFrameID = mImageHost ? mImageHost->GetFrameID() : -1; - } - - bool ComputeChangeInternal(const char* aPrefix, nsIntRegion& aOutRegion, - NotifySubDocInvalidationFunc aCallback) override { - CanvasLayer* canvasLayer = static_cast(mLayer.get()); - - ImageHost* host = GetImageHost(canvasLayer); - if (host && host->GetFrameID() != mFrameID) { - LTI_DUMP(NewTransformedBoundsForLeaf(), "frameId"); - aOutRegion = NewTransformedBoundsForLeaf(); - return true; - } - - return true; - } - - RefPtr mImageHost; - int32_t mFrameID; -}; - UniquePtr CloneLayerTreePropertiesInternal( Layer* aRoot, bool aIsMask /* = false */) { if (!aRoot) { @@ -737,8 +689,6 @@ UniquePtr CloneLayerTreePropertiesInternal( return MakeUnique(static_cast(aRoot), aIsMask); case Layer::TYPE_CANVAS: - return MakeUnique( - static_cast(aRoot)); case Layer::TYPE_DISPLAYITEM: case Layer::TYPE_READBACK: case Layer::TYPE_SHADOW: diff --git a/gfx/layers/composite/CompositableHost.cpp b/gfx/layers/composite/CompositableHost.cpp index b1f5954aeff5..c515792f3201 100644 --- a/gfx/layers/composite/CompositableHost.cpp +++ b/gfx/layers/composite/CompositableHost.cpp @@ -5,12 +5,10 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "CompositableHost.h" -#include // for _Rb_tree_iterator, map, etc -#include // for pair -#include "ContentHost.h" // for ContentHostDoubleBuffered, etc -#include "Effects.h" // for EffectMask, Effect, etc +#include // for _Rb_tree_iterator, map, etc +#include // for pair +#include "Effects.h" // for EffectMask, Effect, etc #include "gfxUtils.h" -#include "ImageHost.h" // for ImageHostBuffered, etc #include "Layers.h" #include "mozilla/gfx/gfxVars.h" #include "mozilla/layers/LayersSurfaces.h" // for SurfaceDescriptor @@ -106,26 +104,11 @@ void CompositableHost::RemoveMaskEffect() { /* static */ already_AddRefed CompositableHost::Create( - const TextureInfo& aTextureInfo, bool aUseWebRender) { + const TextureInfo& aTextureInfo) { RefPtr result; switch (aTextureInfo.mCompositableType) { case CompositableType::IMAGE: - if (aUseWebRender) { - result = new WebRenderImageHost(aTextureInfo); - } else { - result = new ImageHost(aTextureInfo); - } - break; - case CompositableType::CONTENT_SINGLE: - if (aUseWebRender) { - result = new WebRenderImageHost(aTextureInfo); - } else { - result = new ContentHostSingleBuffered(aTextureInfo); - } - break; - case CompositableType::CONTENT_DOUBLE: - MOZ_ASSERT(!aUseWebRender); - result = new ContentHostDoubleBuffered(aTextureInfo); + result = new WebRenderImageHost(aTextureInfo); break; default: NS_ERROR("Unknown CompositableType"); diff --git a/gfx/layers/composite/CompositableHost.h b/gfx/layers/composite/CompositableHost.h index 07930fad6c1a..925c957a6d6b 100644 --- a/gfx/layers/composite/CompositableHost.h +++ b/gfx/layers/composite/CompositableHost.h @@ -88,7 +88,7 @@ class CompositableHost { explicit CompositableHost(const TextureInfo& aTextureInfo); static already_AddRefed Create( - const TextureInfo& aTextureInfo, bool aUseWebRender); + const TextureInfo& aTextureInfo); virtual CompositableType GetType() = 0; diff --git a/gfx/layers/composite/ContentHost.cpp b/gfx/layers/composite/ContentHost.cpp deleted file mode 100644 index d4be5b0dc7eb..000000000000 --- a/gfx/layers/composite/ContentHost.cpp +++ /dev/null @@ -1,460 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "mozilla/layers/ContentHost.h" -#include "gfx2DGlue.h" // for ContentForFormat -#include "mozilla/gfx/Point.h" // for IntSize -#include "mozilla/Assertions.h" // for MOZ_ASSERT, etc -#include "mozilla/gfx/BaseRect.h" // for BaseRect -#include "mozilla/layers/Compositor.h" // for Compositor -#include "mozilla/layers/Effects.h" // for TexturedEffect, Effect, etc -#include "mozilla/layers/LayersMessages.h" // for ThebesBufferData -#include "nsAString.h" -#include "nsPrintfCString.h" // for nsPrintfCString -#include "nsString.h" // for nsAutoCString -#include "mozilla/layers/TextureHostOGL.h" // for TextureHostOGL - -namespace mozilla { -using namespace gfx; - -namespace layers { - -ContentHostBase::ContentHostBase(const TextureInfo& aTextureInfo) - : ContentHost(aTextureInfo), mInitialised(false) {} - -ContentHostBase::~ContentHostBase() = default; - -void ContentHostTexture::Composite( - Compositor* aCompositor, LayerComposite* aLayer, EffectChain& aEffectChain, - float aOpacity, const gfx::Matrix4x4& aTransform, - const SamplingFilter aSamplingFilter, const IntRect& aClipRect, - const nsIntRegion* aVisibleRegion, const Maybe& aGeometry) { - NS_ASSERTION(aVisibleRegion, "Requires a visible region"); - - AutoLockCompositableHost lock(this); - if (lock.Failed()) { - return; - } - - if (!mTextureHost->BindTextureSource(mTextureSource)) { - return; - } - MOZ_ASSERT(mTextureSource.get()); - - if (!mTextureHostOnWhite) { - mTextureSourceOnWhite = nullptr; - } - if (mTextureHostOnWhite && - !mTextureHostOnWhite->BindTextureSource(mTextureSourceOnWhite)) { - return; - } - - RefPtr effect = CreateTexturedEffect( - mTextureSource.get(), mTextureSourceOnWhite.get(), aSamplingFilter, true); - if (!effect) { - return; - } - - aEffectChain.mPrimaryEffect = effect; - - nsIntRegion tmpRegion; - const nsIntRegion* renderRegion; -#ifndef MOZ_IGNORE_PAINT_WILL_RESAMPLE - if (PaintWillResample()) { - // If we're resampling, then the texture image will contain exactly the - // entire visible region's bounds, and we should draw it all in one quad - // to avoid unexpected aliasing. - tmpRegion = aVisibleRegion->GetBounds(); - renderRegion = &tmpRegion; - } else { - renderRegion = aVisibleRegion; - } -#else - renderRegion = aVisibleRegion; -#endif - - nsIntRegion region(*renderRegion); - nsIntPoint origin = GetOriginOffset(); - // translate into TexImage space, buffer origin might not be at texture (0,0) - region.MoveBy(-origin); - - // Figure out the intersecting draw region - gfx::IntSize texSize = mTextureSource->GetSize(); - IntRect textureRect = IntRect(0, 0, texSize.width, texSize.height); - textureRect.MoveBy(region.GetBounds().TopLeft()); - nsIntRegion subregion; - subregion.And(region, textureRect); - if (subregion.IsEmpty()) { - // Region is empty, nothing to draw - return; - } - - nsIntRegion screenRects; - nsIntRegion regionRects; - - // Collect texture/screen coordinates for drawing - for (auto iter = subregion.RectIter(); !iter.Done(); iter.Next()) { - IntRect regionRect = iter.Get(); - IntRect screenRect = iter.Get(); - screenRect.MoveBy(origin); - - screenRects.Or(screenRects, screenRect); - regionRects.Or(regionRects, regionRect); - } - - BigImageIterator* bigImgIter = mTextureSource->AsBigImageIterator(); - BigImageIterator* iterOnWhite = nullptr; - if (bigImgIter) { - bigImgIter->BeginBigImageIteration(); - } - - if (mTextureSourceOnWhite) { - iterOnWhite = mTextureSourceOnWhite->AsBigImageIterator(); - MOZ_ASSERT(!bigImgIter || - bigImgIter->GetTileCount() == iterOnWhite->GetTileCount(), - "Tile count mismatch on component alpha texture"); - if (iterOnWhite) { - iterOnWhite->BeginBigImageIteration(); - } - } - - bool usingTiles = (bigImgIter && bigImgIter->GetTileCount() > 1); - do { - if (iterOnWhite && bigImgIter) { - MOZ_ASSERT(iterOnWhite->GetTileRect() == bigImgIter->GetTileRect(), - "component alpha textures should be the same size."); - } - - IntRect texRect = bigImgIter ? bigImgIter->GetTileRect() - : IntRect(0, 0, texSize.width, texSize.height); - - // Draw texture. If we're using tiles, we do repeating manually, as texture - // repeat would cause each individual tile to repeat instead of the - // compound texture as a whole. This involves drawing at most 4 sections, - // 2 for each axis that has texture repeat. - for (int y = 0; y < (usingTiles ? 2 : 1); y++) { - for (int x = 0; x < (usingTiles ? 2 : 1); x++) { - IntRect currentTileRect(texRect); - currentTileRect.MoveBy(x * texSize.width, y * texSize.height); - - for (auto screenIter = screenRects.RectIter(), - regionIter = regionRects.RectIter(); - !screenIter.Done() && !regionIter.Done(); - screenIter.Next(), regionIter.Next()) { - const IntRect& screenRect = screenIter.Get(); - const IntRect& regionRect = regionIter.Get(); - IntRect tileScreenRect(screenRect); - IntRect tileRegionRect(regionRect); - - // When we're using tiles, find the intersection between the tile - // rect and this region rect. Tiling is then handled by the - // outer for-loops and modifying the tile rect. - if (usingTiles) { - tileScreenRect.MoveBy(-origin); - tileScreenRect = tileScreenRect.Intersect(currentTileRect); - tileScreenRect.MoveBy(origin); - - if (tileScreenRect.IsEmpty()) continue; - - tileRegionRect = regionRect.Intersect(currentTileRect); - tileRegionRect.MoveBy(-currentTileRect.TopLeft()); - } - gfx::Rect rect(tileScreenRect.X(), tileScreenRect.Y(), - tileScreenRect.Width(), tileScreenRect.Height()); - - effect->mTextureCoords = - Rect(Float(tileRegionRect.X()) / texRect.Width(), - Float(tileRegionRect.Y()) / texRect.Height(), - Float(tileRegionRect.Width()) / texRect.Width(), - Float(tileRegionRect.Height()) / texRect.Height()); - - aCompositor->DrawGeometry(rect, aClipRect, aEffectChain, aOpacity, - aTransform, aGeometry); - - if (usingTiles) { - DiagnosticFlags diagnostics = - DiagnosticFlags::CONTENT | DiagnosticFlags::BIGIMAGE; - if (iterOnWhite) { - diagnostics |= DiagnosticFlags::COMPONENT_ALPHA; - } - aCompositor->DrawDiagnostics(diagnostics, rect, aClipRect, - aTransform, mFlashCounter); - } - } - } - } - - if (iterOnWhite) { - iterOnWhite->NextTile(); - } - } while (usingTiles && bigImgIter->NextTile()); - - if (bigImgIter) { - bigImgIter->EndBigImageIteration(); - } - if (iterOnWhite) { - iterOnWhite->EndBigImageIteration(); - } - - DiagnosticFlags diagnostics = DiagnosticFlags::CONTENT; - if (iterOnWhite) { - diagnostics |= DiagnosticFlags::COMPONENT_ALPHA; - } - aCompositor->DrawDiagnostics(diagnostics, nsIntRegion(mBufferRect), aClipRect, - aTransform, mFlashCounter); -} - -RefPtr ContentHostTexture::AcquireTextureSource() { - if (!mTextureHost || !mTextureHost->AcquireTextureSource(mTextureSource)) { - return nullptr; - } - return mTextureSource.get(); -} - -RefPtr ContentHostTexture::AcquireTextureSourceOnWhite() { - if (!mTextureHostOnWhite || - !mTextureHostOnWhite->AcquireTextureSource(mTextureSourceOnWhite)) { - return nullptr; - } - return mTextureSourceOnWhite.get(); -} - -void ContentHostTexture::UseTextureHost( - const nsTArray& aTextures) { - ContentHostBase::UseTextureHost(aTextures); - MOZ_ASSERT(aTextures.Length() == 1); - const TimedTexture& t = aTextures[0]; - MOZ_ASSERT(t.mPictureRect.IsEqualInterior( - nsIntRect(nsIntPoint(0, 0), nsIntSize(t.mTexture->GetSize()))), - "Only default picture rect supported"); - - if (t.mTexture != mTextureHost) { - mReceivedNewHost = true; - } - - mTextureHost = t.mTexture; - mTextureHostOnWhite = nullptr; - mTextureSourceOnWhite = nullptr; - if (mTextureHost) { - mTextureHost->PrepareTextureSource(mTextureSource); - } -} - -void ContentHostTexture::UseComponentAlphaTextures( - TextureHost* aTextureOnBlack, TextureHost* aTextureOnWhite) { - ContentHostBase::UseComponentAlphaTextures(aTextureOnBlack, aTextureOnWhite); - mTextureHost = aTextureOnBlack; - mTextureHostOnWhite = aTextureOnWhite; - if (mTextureHost) { - mTextureHost->PrepareTextureSource(mTextureSource); - } - if (mTextureHostOnWhite) { - mTextureHostOnWhite->PrepareTextureSource(mTextureSourceOnWhite); - } -} - -void ContentHostTexture::SetTextureSourceProvider( - TextureSourceProvider* aProvider) { - ContentHostBase::SetTextureSourceProvider(aProvider); - if (mTextureHost) { - mTextureHost->SetTextureSourceProvider(aProvider); - } - if (mTextureHostOnWhite) { - mTextureHostOnWhite->SetTextureSourceProvider(aProvider); - } -} - -void ContentHostTexture::Dump(std::stringstream& aStream, const char* aPrefix, - bool aDumpHtml) { -#ifdef MOZ_DUMP_PAINTING - if (aDumpHtml) { - aStream << "
    "; - } - if (mTextureHost) { - aStream << aPrefix; - if (aDumpHtml) { - aStream << "
  • Front buffer
  • "; - } else { - aStream << "\n"; - } - } - if (mTextureHostOnWhite) { - aStream << aPrefix; - if (aDumpHtml) { - aStream << "
  • Front buffer on white
  • "; - } else { - aStream << "\n"; - } - } - if (aDumpHtml) { - aStream << "
"; - } -#endif -} - -static inline void AddWrappedRegion(const nsIntRegion& aInput, - nsIntRegion& aOutput, const IntSize& aSize, - const nsIntPoint& aShift) { - nsIntRegion tempRegion; - tempRegion.And(IntRect(aShift, aSize), aInput); - tempRegion.MoveBy(-aShift); - aOutput.Or(aOutput, tempRegion); -} - -bool ContentHostSingleBuffered::UpdateThebes( - const ThebesBufferData& aData, const nsIntRegion& aUpdated, - const nsIntRegion& aOldValidRegionBack) { - if (!mTextureHost) { - mInitialised = false; - return true; // FIXME should we return false? Returning true for now - } // to preserve existing behavior of NOT causing IPC errors. - - // updated is in screen coordinates. Convert it to buffer coordinates. - nsIntRegion destRegion(aUpdated); - - if (mReceivedNewHost) { - destRegion.Or(destRegion, aOldValidRegionBack); - mReceivedNewHost = false; - } - destRegion.MoveBy(-aData.rect().TopLeft()); - - if (!aData.rect().Contains(aUpdated.GetBounds()) || - aData.rotation().x > aData.rect().Width() || - aData.rotation().y > aData.rect().Height()) { - NS_ERROR("Invalid update data"); - return false; - } - - // destRegion is now in logical coordinates relative to the buffer, but we - // need to account for rotation. We do that by moving the region to the - // rotation offset and then wrapping any pixels that extend off the - // bottom/right edges. - - // Shift to the rotation point - destRegion.MoveBy(aData.rotation()); - - IntSize bufferSize = aData.rect().Size(); - - // Select only the pixels that are still within the buffer. - nsIntRegion finalRegion; - finalRegion.And(IntRect(IntPoint(), bufferSize), destRegion); - - // For each of the overlap areas (right, bottom-right, bottom), select those - // pixels and wrap them around to the opposite edge of the buffer rect. - AddWrappedRegion(destRegion, finalRegion, bufferSize, - nsIntPoint(aData.rect().Width(), 0)); - AddWrappedRegion(destRegion, finalRegion, bufferSize, - nsIntPoint(aData.rect().Width(), aData.rect().Height())); - AddWrappedRegion(destRegion, finalRegion, bufferSize, - nsIntPoint(0, aData.rect().Height())); - - MOZ_ASSERT(IntRect(0, 0, aData.rect().Width(), aData.rect().Height()) - .Contains(finalRegion.GetBounds())); - - mTextureHost->Updated(&finalRegion); - if (mTextureHostOnWhite) { - mTextureHostOnWhite->Updated(&finalRegion); - } - mInitialised = true; - - mBufferRect = aData.rect(); - mBufferRotation = aData.rotation(); - - return true; -} - -bool ContentHostDoubleBuffered::UpdateThebes( - const ThebesBufferData& aData, const nsIntRegion& aUpdated, - const nsIntRegion& aOldValidRegionBack) { - if (!mTextureHost) { - mInitialised = false; - return true; - } - - // We don't need to calculate an update region because we assume that if we - // are using double buffering then we have render-to-texture and thus no - // upload to do. - mTextureHost->Updated(); - if (mTextureHostOnWhite) { - mTextureHostOnWhite->Updated(); - } - mInitialised = true; - - mBufferRect = aData.rect(); - mBufferRotation = aData.rotation(); - - // Save the current valid region of our front buffer, because if - // we're double buffering, it's going to be the valid region for the - // next back buffer sent back to the renderer. - // - // NB: we rely here on the fact that mValidRegion is initialized to - // empty, and that the first time Swap() is called we don't have a - // valid front buffer that we're going to return to content. - mValidRegionForNextBackBuffer = aOldValidRegionBack; - - return true; -} - -void ContentHostTexture::PrintInfo(std::stringstream& aStream, - const char* aPrefix) { - aStream << aPrefix; - aStream << nsPrintfCString("ContentHost (0x%p)", this).get() - << " [buffer-rect=" << mBufferRect << "]" - << " [buffer-rotation=" << mBufferRotation << "]"; - if (PaintWillResample()) { - aStream << " [paint-will-resample]"; - } - - if (mTextureHost) { - nsAutoCString pfx(aPrefix); - pfx += " "; - - aStream << "\n"; - mTextureHost->PrintInfo(aStream, pfx.get()); - } -} - -already_AddRefed ContentHostTexture::GenEffect( - const gfx::SamplingFilter aSamplingFilter) { - if (!mTextureHost) { - return nullptr; - } - if (!mTextureHost->BindTextureSource(mTextureSource)) { - return nullptr; - } - if (!mTextureHostOnWhite) { - mTextureSourceOnWhite = nullptr; - } - if (mTextureHostOnWhite && - !mTextureHostOnWhite->BindTextureSource(mTextureSourceOnWhite)) { - return nullptr; - } - return CreateTexturedEffect(mTextureSource.get(), mTextureSourceOnWhite.get(), - aSamplingFilter, true); -} - -already_AddRefed ContentHostTexture::GetAsSurface() { - if (!mTextureHost) { - return nullptr; - } - - return mTextureHost->GetAsSurface(); -} - -} // namespace layers -} // namespace mozilla diff --git a/gfx/layers/composite/ContentHost.h b/gfx/layers/composite/ContentHost.h deleted file mode 100644 index a666a3352ce9..000000000000 --- a/gfx/layers/composite/ContentHost.h +++ /dev/null @@ -1,233 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef GFX_CONTENTHOST_H -#define GFX_CONTENTHOST_H - -#include // for uint32_t -#include // for FILE -#include "mozilla-config.h" // for MOZ_DUMP_PAINTING -#include "CompositableHost.h" // for CompositableHost, etc -#include "mozilla/Attributes.h" // for override -#include "mozilla/RefPtr.h" // for RefPtr -#include "mozilla/gfx/BasePoint.h" // for BasePoint -#include "mozilla/gfx/MatrixFwd.h" // for Matrix4x4 -#include "mozilla/gfx/Point.h" // for Point -#include "mozilla/gfx/Polygon.h" // for Polygon -#include "mozilla/gfx/Rect.h" // for Rect -#include "mozilla/gfx/Types.h" // for SamplingFilter -#include "mozilla/layers/CompositorTypes.h" // for TextureInfo, etc -#include "mozilla/layers/ContentClient.h" // for ContentClient -#include "mozilla/layers/ISurfaceAllocator.h" // for ISurfaceAllocator -#include "mozilla/layers/LayersSurfaces.h" // for SurfaceDescriptor -#include "mozilla/layers/LayersTypes.h" // for etc -#include "mozilla/layers/TextureHost.h" // for TextureHost -#include "mozilla/mozalloc.h" // for operator delete -#include "mozilla/UniquePtr.h" // for UniquePtr -#include "nsCOMPtr.h" // for already_AddRefed -#include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, etc -#include "nsPoint.h" // for nsIntPoint -#include "nsRect.h" // for mozilla::gfx::IntRect -#include "nsRegion.h" // for nsIntRegion -#include "nsTArray.h" // for nsTArray -#include "nscore.h" // for nsACString - -namespace mozilla { -namespace layers { -class Compositor; -class ThebesBufferData; -struct EffectChain; - -struct TexturedEffect; - -/** - * ContentHosts are used for compositing Painted layers, always matched by a - * ContentClient of the same type. - * - * ContentHosts support only UpdateThebes(), not Update(). - */ -class ContentHost : public CompositableHost { - public: - virtual bool UpdateThebes( - const ThebesBufferData& aData, const nsIntRegion& aUpdated, - const nsIntRegion& aOldValidRegionBack) override = 0; - - virtual void SetPaintWillResample(bool aResample) { - mPaintWillResample = aResample; - } - bool PaintWillResample() { return mPaintWillResample; } - - // We use this to allow TiledContentHost to invalidate regions where - // tiles are fading in. - virtual void AddAnimationInvalidation(nsIntRegion& aRegion) {} - - virtual gfx::IntRect GetBufferRect() { - MOZ_ASSERT_UNREACHABLE("Must be implemented in derived class"); - return gfx::IntRect(); - } - - ContentHost* AsContentHost() override { return this; } - - protected: - explicit ContentHost(const TextureInfo& aTextureInfo) - : CompositableHost(aTextureInfo), mPaintWillResample(false) {} - - bool mPaintWillResample; -}; - -/** - * Base class for non-tiled ContentHosts. - * - * Ownership of the SurfaceDescriptor and the resources it represents is passed - * from the ContentClient to the ContentHost when the TextureClient/Hosts are - * created, that is recevied here by SetTextureHosts which assigns one or two - * texture hosts (for single and double buffering) to the ContentHost. - * - * It is the responsibility of the ContentHost to destroy its resources when - * they are recreated or the ContentHost dies. - */ -class ContentHostBase : public ContentHost { - public: - typedef ContentClient::ContentType ContentType; - typedef ContentClient::PaintState PaintState; - - explicit ContentHostBase(const TextureInfo& aTextureInfo); - virtual ~ContentHostBase(); - - gfx::IntRect GetBufferRect() override { return mBufferRect; } - - virtual nsIntPoint GetOriginOffset() { - return mBufferRect.TopLeft() - mBufferRotation; - } - - protected: - gfx::IntRect mBufferRect; - nsIntPoint mBufferRotation; - bool mInitialised; -}; - -/** - * Shared ContentHostBase implementation for content hosts that - * use up to two TextureHosts. - */ -class ContentHostTexture : public ContentHostBase { - public: - explicit ContentHostTexture(const TextureInfo& aTextureInfo) - : ContentHostBase(aTextureInfo), - mLocked(false), - mReceivedNewHost(false) {} - - void Composite(Compositor* aCompositor, LayerComposite* aLayer, - EffectChain& aEffectChain, float aOpacity, - const gfx::Matrix4x4& aTransform, - const gfx::SamplingFilter aSamplingFilter, - const gfx::IntRect& aClipRect, - const nsIntRegion* aVisibleRegion = nullptr, - const Maybe& aGeometry = Nothing()) override; - - void SetTextureSourceProvider(TextureSourceProvider* aProvider) override; - - already_AddRefed GetAsSurface() override; - - void Dump(std::stringstream& aStream, const char* aPrefix = "", - bool aDumpHtml = false) override; - - void PrintInfo(std::stringstream& aStream, const char* aPrefix) override; - - void UseTextureHost(const nsTArray& aTextures) override; - void UseComponentAlphaTextures(TextureHost* aTextureOnBlack, - TextureHost* aTextureOnWhite) override; - - bool Lock() override { - MOZ_ASSERT(!mLocked); - if (!mTextureHost) { - return false; - } - if (!mTextureHost->Lock()) { - return false; - } - - if (mTextureHostOnWhite && !mTextureHostOnWhite->Lock()) { - return false; - } - - mLocked = true; - return true; - } - void Unlock() override { - MOZ_ASSERT(mLocked); - mTextureHost->Unlock(); - if (mTextureHostOnWhite) { - mTextureHostOnWhite->Unlock(); - } - mLocked = false; - } - - bool HasComponentAlpha() const { return !!mTextureHostOnWhite; } - - RefPtr AcquireTextureSource(); - RefPtr AcquireTextureSourceOnWhite(); - - ContentHostTexture* AsContentHostTexture() override { return this; } - - already_AddRefed GenEffect( - const gfx::SamplingFilter aSamplingFilter) override; - - protected: - CompositableTextureHostRef mTextureHost; - CompositableTextureHostRef mTextureHostOnWhite; - CompositableTextureSourceRef mTextureSource; - CompositableTextureSourceRef mTextureSourceOnWhite; - bool mLocked; - bool mReceivedNewHost; -}; - -/** - * Double buffering is implemented by swapping the front and back TextureHosts. - * We assume that whenever we use double buffering, then we have - * render-to-texture and thus no texture upload to do. - */ -class ContentHostDoubleBuffered : public ContentHostTexture { - public: - explicit ContentHostDoubleBuffered(const TextureInfo& aTextureInfo) - : ContentHostTexture(aTextureInfo) {} - - virtual ~ContentHostDoubleBuffered() = default; - - CompositableType GetType() override { - return CompositableType::CONTENT_DOUBLE; - } - - virtual bool UpdateThebes(const ThebesBufferData& aData, - const nsIntRegion& aUpdated, - const nsIntRegion& aOldValidRegionBack) override; - - protected: - nsIntRegion mValidRegionForNextBackBuffer; -}; - -/** - * Single buffered, therefore we must synchronously upload the image from the - * TextureHost in the layers transaction (i.e., in UpdateThebes). - */ -class ContentHostSingleBuffered : public ContentHostTexture { - public: - explicit ContentHostSingleBuffered(const TextureInfo& aTextureInfo) - : ContentHostTexture(aTextureInfo) {} - virtual ~ContentHostSingleBuffered() = default; - - CompositableType GetType() override { - return CompositableType::CONTENT_SINGLE; - } - - bool UpdateThebes(const ThebesBufferData& aData, const nsIntRegion& aUpdated, - const nsIntRegion& aOldValidRegionBack) override; -}; - -} // namespace layers -} // namespace mozilla - -#endif diff --git a/gfx/layers/composite/ImageHost.cpp b/gfx/layers/composite/ImageHost.cpp deleted file mode 100644 index c491bcf1252d..000000000000 --- a/gfx/layers/composite/ImageHost.cpp +++ /dev/null @@ -1,402 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "ImageHost.h" - -#include - -#include "composite/CompositableHost.h" // for CompositableHost, etc -#include "ipc/IPCMessageUtils.h" // for null_t -#include "mozilla/layers/Compositor.h" // for Compositor -#include "mozilla/layers/Effects.h" // for TexturedEffect, Effect, etc -#include "nsAString.h" -#include "nsDebug.h" // for NS_WARNING, NS_ASSERTION -#include "nsPrintfCString.h" // for nsPrintfCString -#include "nsString.h" // for nsAutoCString - -namespace mozilla { - -using namespace gfx; - -namespace layers { - -class ISurfaceAllocator; - -ImageHost::ImageHost(const TextureInfo& aTextureInfo) - : CompositableHost(aTextureInfo), ImageComposite(), mLocked(false) {} - -ImageHost::~ImageHost() = default; - -void ImageHost::UseTextureHost(const nsTArray& aTextures) { - MOZ_ASSERT(!mLocked); - - CompositableHost::UseTextureHost(aTextures); - MOZ_ASSERT(aTextures.Length() >= 1); - - nsTArray newImages; - - for (uint32_t i = 0; i < aTextures.Length(); ++i) { - const TimedTexture& t = aTextures[i]; - MOZ_ASSERT(t.mTexture); - if (i + 1 < aTextures.Length() && t.mProducerID == mLastProducerID && - t.mFrameID < mLastFrameID) { - // Ignore frames before a frame that we already composited. We don't - // ever want to display these frames. This could be important if - // the frame producer adjusts timestamps (e.g. to track the audio clock) - // and the new frame times are earlier. - continue; - } - TimedImage& img = *newImages.AppendElement(); - img.mTextureHost = t.mTexture; - img.mTimeStamp = t.mTimeStamp; - img.mPictureRect = t.mPictureRect; - img.mFrameID = t.mFrameID; - img.mProducerID = t.mProducerID; - img.mTextureHost->SetCropRect(img.mPictureRect); - img.mTextureHost->Updated(); - } - - SetImages(std::move(newImages)); - - // If we only have one image we can upload it right away, otherwise we'll - // upload on-demand during composition after we have picked the proper - // timestamp. - if (ImagesCount() == 1) { - SetCurrentTextureHost(GetImage(0)->mTextureHost); - } -} - -void ImageHost::SetCurrentTextureHost(TextureHost* aTexture) { - if (aTexture == mCurrentTextureHost.get()) { - return; - } - - bool swapTextureSources = !!mCurrentTextureHost && !!mCurrentTextureSource && - mCurrentTextureHost->IsValid() && - mCurrentTextureHost->HasIntermediateBuffer(); - - if (swapTextureSources) { - auto dataSource = mCurrentTextureSource->AsDataTextureSource(); - if (dataSource) { - // The current textureHost has an internal buffer in the form of the - // DataTextureSource. Removing the ownership of the texture source - // will enable the next texture host we bind to the texture source to - // acquire it instead of creating a new one. This is desirable in - // ImageHost because the current texture won't be used again with the - // same content. It wouldn't be desirable with ContentHost for instance, - // because the latter reuses the texture's valid regions. - dataSource->SetOwner(nullptr); - } - - RefPtr tmp = mExtraTextureSource; - mExtraTextureSource = mCurrentTextureSource.get(); - mCurrentTextureSource = tmp; - } else { - mExtraTextureSource = nullptr; - } - - mCurrentTextureHost = aTexture; - mCurrentTextureHost->PrepareTextureSource(mCurrentTextureSource); -} - -void ImageHost::CleanupResources() { - mExtraTextureSource = nullptr; - mCurrentTextureSource = nullptr; - mCurrentTextureHost = nullptr; -} - -void ImageHost::RemoveTextureHost(TextureHost* aTexture) { - MOZ_ASSERT(!mLocked); - - CompositableHost::RemoveTextureHost(aTexture); - RemoveImagesWithTextureHost(aTexture); -} - -TimeStamp ImageHost::GetCompositionTime() const { - TimeStamp time; - return time; -} - -CompositionOpportunityId ImageHost::GetCompositionOpportunityId() const { - CompositionOpportunityId id; - return id; -} - -void ImageHost::AppendImageCompositeNotification( - const ImageCompositeNotificationInfo& aInfo) const {} - -TextureHost* ImageHost::GetAsTextureHost(IntRect* aPictureRect) { - const TimedImage* img = ChooseImage(); - if (!img) { - return nullptr; - } - SetCurrentTextureHost(img->mTextureHost); - if (aPictureRect) { - *aPictureRect = img->mPictureRect; - } - return img->mTextureHost; -} - -void ImageHost::Attach(Layer* aLayer, TextureSourceProvider* aProvider, - AttachFlags aFlags) { - CompositableHost::Attach(aLayer, aProvider, aFlags); - for (const auto& img : Images()) { - img.mTextureHost->SetTextureSourceProvider(aProvider); - img.mTextureHost->Updated(); - } -} - -void ImageHost::Composite(Compositor* aCompositor, LayerComposite* aLayer, - EffectChain& aEffectChain, float aOpacity, - const gfx::Matrix4x4& aTransform, - const gfx::SamplingFilter aSamplingFilter, - const gfx::IntRect& aClipRect, - const nsIntRegion* aVisibleRegion, - const Maybe& aGeometry) { - RenderInfo info; - if (!PrepareToRender(aCompositor, &info)) { - return; - } - - const TimedImage* img = info.img; - - { - AutoLockCompositableHost autoLock(this); - if (autoLock.Failed()) { - NS_WARNING("failed to lock front buffer"); - return; - } - - if (!mCurrentTextureHost->BindTextureSource(mCurrentTextureSource)) { - return; - } - - if (!mCurrentTextureSource) { - // BindTextureSource above should have returned false! - MOZ_ASSERT(false); - return; - } - - bool isAlphaPremultiplied = - !(mCurrentTextureHost->GetFlags() & TextureFlags::NON_PREMULTIPLIED); - RefPtr effect = - CreateTexturedEffect(mCurrentTextureHost, mCurrentTextureSource.get(), - aSamplingFilter, isAlphaPremultiplied); - if (!effect) { - return; - } - - if (!aCompositor->SupportsEffect(effect->mType)) { - return; - } - - DiagnosticFlags diagnosticFlags = DiagnosticFlags::IMAGE; - if (effect->mType == EffectTypes::NV12) { - diagnosticFlags |= DiagnosticFlags::NV12; - } else if (effect->mType == EffectTypes::YCBCR) { - diagnosticFlags |= DiagnosticFlags::YCBCR; - } - - aEffectChain.mPrimaryEffect = effect; - gfx::Rect pictureRect(0, 0, img->mPictureRect.Width(), - img->mPictureRect.Height()); - BigImageIterator* it = mCurrentTextureSource->AsBigImageIterator(); - if (it) { - // This iteration does not work if we have multiple texture sources here - // (e.g. 3 YCbCr textures). There's nothing preventing the different - // planes from having different resolutions or tile sizes. For example, a - // YCbCr frame could have Cb and Cr planes that are half the resolution of - // the Y plane, in such a way that the Y plane overflows the maximum - // texture size and the Cb and Cr planes do not. Then the Y plane would be - // split into multiple tiles and the Cb and Cr planes would just be one - // tile each. - // To handle the general case correctly, we'd have to create a grid of - // intersected tiles over all planes, and then draw each grid tile using - // the corresponding source tiles from all planes, with appropriate - // per-plane per-tile texture coords. - // DrawQuad currently assumes that all planes use the same texture coords. - MOZ_ASSERT( - it->GetTileCount() == 1 || !mCurrentTextureSource->GetNextSibling(), - "Can't handle multi-plane BigImages"); - - it->BeginBigImageIteration(); - do { - IntRect tileRect = it->GetTileRect(); - gfx::Rect rect(tileRect.X(), tileRect.Y(), tileRect.Width(), - tileRect.Height()); - rect = rect.Intersect(pictureRect); - effect->mTextureCoords = - Rect(Float(rect.X() - tileRect.X()) / tileRect.Width(), - Float(rect.Y() - tileRect.Y()) / tileRect.Height(), - Float(rect.Width()) / tileRect.Width(), - Float(rect.Height()) / tileRect.Height()); - if (img->mTextureHost->GetFlags() & TextureFlags::ORIGIN_BOTTOM_LEFT) { - effect->mTextureCoords.SetRectY(effect->mTextureCoords.YMost(), - -effect->mTextureCoords.Height()); - } - aCompositor->DrawGeometry(rect, aClipRect, aEffectChain, aOpacity, - aTransform, aGeometry); - aCompositor->DrawDiagnostics( - diagnosticFlags | DiagnosticFlags::BIGIMAGE, rect, aClipRect, - aTransform, mFlashCounter); - } while (it->NextTile()); - it->EndBigImageIteration(); - // layer border - aCompositor->DrawDiagnostics(diagnosticFlags, pictureRect, aClipRect, - aTransform, mFlashCounter); - } else { - IntSize textureSize = mCurrentTextureSource->GetSize(); - effect->mTextureCoords = - Rect(Float(img->mPictureRect.X()) / textureSize.width, - Float(img->mPictureRect.Y()) / textureSize.height, - Float(img->mPictureRect.Width()) / textureSize.width, - Float(img->mPictureRect.Height()) / textureSize.height); - - if (img->mTextureHost->GetFlags() & TextureFlags::ORIGIN_BOTTOM_LEFT) { - effect->mTextureCoords.SetRectY(effect->mTextureCoords.YMost(), - -effect->mTextureCoords.Height()); - } - - aCompositor->DrawGeometry(pictureRect, aClipRect, aEffectChain, aOpacity, - aTransform, aGeometry); - aCompositor->DrawDiagnostics(diagnosticFlags, pictureRect, aClipRect, - aTransform, mFlashCounter); - } - } - - FinishRendering(info); -} - -bool ImageHost::PrepareToRender(TextureSourceProvider* aProvider, - RenderInfo* aOutInfo) { - return false; -} - -RefPtr ImageHost::AcquireTextureSource(const RenderInfo& aInfo) { - MOZ_ASSERT(aInfo.host == mCurrentTextureHost); - if (!aInfo.host->AcquireTextureSource(mCurrentTextureSource)) { - return nullptr; - } - return mCurrentTextureSource.get(); -} - -void ImageHost::FinishRendering(const RenderInfo& aInfo) { - OnFinishRendering(aInfo.imageIndex, aInfo.img, mAsyncRef.mProcessId, - mAsyncRef.mHandle); -} - -void ImageHost::SetTextureSourceProvider(TextureSourceProvider* aProvider) { - if (mTextureSourceProvider != aProvider) { - for (const auto& img : Images()) { - img.mTextureHost->SetTextureSourceProvider(aProvider); - } - } - CompositableHost::SetTextureSourceProvider(aProvider); -} - -void ImageHost::PrintInfo(std::stringstream& aStream, const char* aPrefix) { - aStream << aPrefix; - aStream << nsPrintfCString("ImageHost (0x%p)", this).get(); - - nsAutoCString pfx(aPrefix); - pfx += " "; - for (const auto& img : Images()) { - aStream << "\n"; - img.mTextureHost->PrintInfo(aStream, pfx.get()); - aStream << " [picture-rect=" << img.mPictureRect << "]"; - } -} - -void ImageHost::Dump(std::stringstream& aStream, const char* aPrefix, - bool aDumpHtml) { - for (const auto& img : Images()) { - aStream << aPrefix; - aStream << (aDumpHtml ? "
  • TextureHost: " : "TextureHost: "); - DumpTextureHost(aStream, img.mTextureHost); - aStream << (aDumpHtml ? "
" : " "); - } -} - -already_AddRefed ImageHost::GetAsSurface() { - const TimedImage* img = ChooseImage(); - if (img) { - return img->mTextureHost->GetAsSurface(); - } - return nullptr; -} - -bool ImageHost::Lock() { - MOZ_ASSERT(!mLocked); - const TimedImage* img = ChooseImage(); - if (!img) { - return false; - } - - SetCurrentTextureHost(img->mTextureHost); - - if (!mCurrentTextureHost->Lock()) { - return false; - } - mLocked = true; - return true; -} - -void ImageHost::Unlock() { - MOZ_ASSERT(mLocked); - - if (mCurrentTextureHost) { - mCurrentTextureHost->Unlock(); - } - mLocked = false; -} - -IntSize ImageHost::GetImageSize() { - const TimedImage* img = ChooseImage(); - if (img) { - return IntSize(img->mPictureRect.Width(), img->mPictureRect.Height()); - } - return IntSize(); -} - -bool ImageHost::IsOpaque() { - const TimedImage* img = ChooseImage(); - if (!img) { - return false; - } - - if (img->mPictureRect.Width() == 0 || img->mPictureRect.Height() == 0 || - !img->mTextureHost) { - return false; - } - - gfx::SurfaceFormat format = img->mTextureHost->GetFormat(); - if (gfx::IsOpaque(format)) { - return true; - } - return false; -} - -already_AddRefed ImageHost::GenEffect( - const gfx::SamplingFilter aSamplingFilter) { - const TimedImage* img = ChooseImage(); - if (!img) { - return nullptr; - } - SetCurrentTextureHost(img->mTextureHost); - if (!mCurrentTextureHost->BindTextureSource(mCurrentTextureSource)) { - return nullptr; - } - bool isAlphaPremultiplied = true; - if (mCurrentTextureHost->GetFlags() & TextureFlags::NON_PREMULTIPLIED) { - isAlphaPremultiplied = false; - } - - return CreateTexturedEffect(mCurrentTextureHost, mCurrentTextureSource, - aSamplingFilter, isAlphaPremultiplied); -} - -} // namespace layers -} // namespace mozilla diff --git a/gfx/layers/composite/ImageHost.h b/gfx/layers/composite/ImageHost.h deleted file mode 100644 index 5d712d5bddeb..000000000000 --- a/gfx/layers/composite/ImageHost.h +++ /dev/null @@ -1,138 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef MOZILLA_GFX_IMAGEHOST_H -#define MOZILLA_GFX_IMAGEHOST_H - -#include // for FILE -#include "CompositableHost.h" // for CompositableHost -#include "mozilla/Attributes.h" // for override -#include "mozilla/RefPtr.h" // for RefPtr -#include "mozilla/gfx/MatrixFwd.h" // for Matrix4x4 -#include "mozilla/gfx/Point.h" // for Point -#include "mozilla/gfx/Polygon.h" // for Polygon -#include "mozilla/gfx/Rect.h" // for Rect -#include "mozilla/gfx/Types.h" // for SamplingFilter -#include "mozilla/layers/CompositorTypes.h" // for TextureInfo, etc -#include "mozilla/layers/ImageComposite.h" // for ImageComposite -#include "mozilla/layers/LayersSurfaces.h" // for SurfaceDescriptor -#include "mozilla/layers/LayersTypes.h" // for LayerRenderState, etc -#include "mozilla/layers/TextureHost.h" // for TextureHost, etc -#include "mozilla/mozalloc.h" // for operator delete -#include "nsCOMPtr.h" // for already_AddRefed -#include "nsRect.h" // for mozilla::gfx::IntRect -#include "nsRegionFwd.h" // for nsIntRegion -#include "nscore.h" // for nsACString - -namespace mozilla { -namespace layers { - -class Compositor; -struct EffectChain; -class HostLayerManager; - -/** - * ImageHost. Works with ImageClientSingle and ImageClientBuffered - */ -class ImageHost : public CompositableHost, public ImageComposite { - public: - explicit ImageHost(const TextureInfo& aTextureInfo); - virtual ~ImageHost(); - - CompositableType GetType() override { return mTextureInfo.mCompositableType; } - ImageHost* AsImageHost() override { return this; } - - void Composite(Compositor* aCompositor, LayerComposite* aLayer, - EffectChain& aEffectChain, float aOpacity, - const gfx::Matrix4x4& aTransform, - const gfx::SamplingFilter aSamplingFilter, - const gfx::IntRect& aClipRect, - const nsIntRegion* aVisibleRegion = nullptr, - const Maybe& aGeometry = Nothing()) override; - - void UseTextureHost(const nsTArray& aTextures) override; - - void RemoveTextureHost(TextureHost* aTexture) override; - - TextureHost* GetAsTextureHost(gfx::IntRect* aPictureRect = nullptr) override; - - void Attach(Layer* aLayer, TextureSourceProvider* aProvider, - AttachFlags aFlags = NO_FLAGS) override; - - void SetTextureSourceProvider(TextureSourceProvider* aProvider) override; - - gfx::IntSize GetImageSize() override; - - void PrintInfo(std::stringstream& aStream, const char* aPrefix) override; - - void Dump(std::stringstream& aStream, const char* aPrefix = "", - bool aDumpHtml = false) override; - - already_AddRefed GetAsSurface() override; - - bool Lock() override; - - void Unlock() override; - - already_AddRefed GenEffect( - const gfx::SamplingFilter aSamplingFilter) override; - - void SetCurrentTextureHost(TextureHost* aTexture); - - void CleanupResources() override; - - bool IsOpaque(); - - uint32_t GetDroppedFrames() override { return GetDroppedFramesAndReset(); } - - struct RenderInfo { - int imageIndex; - const TimedImage* img; - RefPtr host; - - RenderInfo() : imageIndex(-1), img(nullptr) {} - }; - - // Acquire rendering information for the current frame. - bool PrepareToRender(TextureSourceProvider* aProvider, RenderInfo* aOutInfo); - - // Acquire the TextureSource for the currently prepared frame. - RefPtr AcquireTextureSource(const RenderInfo& aInfo); - - // Send ImageComposite notifications. - void FinishRendering(const RenderInfo& aInfo); - - // This should only be called inside a lock, or during rendering. It is - // infallible to enforce this. - TextureHost* CurrentTextureHost() const { - MOZ_ASSERT(mCurrentTextureHost); - return mCurrentTextureHost; - } - - protected: - // ImageComposite - TimeStamp GetCompositionTime() const override; - CompositionOpportunityId GetCompositionOpportunityId() const override; - void AppendImageCompositeNotification( - const ImageCompositeNotificationInfo& aInfo) const override; - - // Use a simple RefPtr because the same texture is already held by a - // a CompositableTextureHostRef in the array of TimedImage. - // See the comment in CompositableTextureRef for more details. - RefPtr mCurrentTextureHost; - CompositableTextureSourceRef mCurrentTextureSource; - // When doing texture uploads it's best to alternate between two (or three) - // texture sources so that the texture we upload to isn't being used by - // the GPU to composite the previous frame. - RefPtr mExtraTextureSource; - - bool mLocked; -}; - -} // namespace layers -} // namespace mozilla - -#endif diff --git a/gfx/layers/d3d11/CompositorD3D11.cpp b/gfx/layers/d3d11/CompositorD3D11.cpp index e2e502455bdd..a9b8d5259c71 100644 --- a/gfx/layers/d3d11/CompositorD3D11.cpp +++ b/gfx/layers/d3d11/CompositorD3D11.cpp @@ -15,8 +15,6 @@ #include "mozilla/gfx/DeviceManagerDx.h" #include "mozilla/gfx/GPUParent.h" #include "mozilla/gfx/Swizzle.h" -#include "mozilla/layers/ImageHost.h" -#include "mozilla/layers/ContentHost.h" #include "mozilla/layers/Diagnostics.h" #include "mozilla/layers/DiagnosticsD3D11.h" #include "mozilla/layers/Effects.h" diff --git a/gfx/layers/ipc/CompositableTransactionParent.cpp b/gfx/layers/ipc/CompositableTransactionParent.cpp index b5680a64ea8c..60bcea442f8a 100644 --- a/gfx/layers/ipc/CompositableTransactionParent.cpp +++ b/gfx/layers/ipc/CompositableTransactionParent.cpp @@ -12,13 +12,12 @@ #include "mozilla/Assertions.h" // for MOZ_ASSERT, etc #include "mozilla/RefPtr.h" // for RefPtr #include "mozilla/layers/CompositorTypes.h" -#include "mozilla/layers/ContentHost.h" // for ContentHostBase #include "mozilla/layers/ImageBridgeParent.h" // for ImageBridgeParent #include "mozilla/layers/LayersSurfaces.h" // for SurfaceDescriptor #include "mozilla/layers/LayersTypes.h" // for MOZ_LAYERS_LOG #include "mozilla/layers/TextureHost.h" // for TextureHost #include "mozilla/layers/TextureHostOGL.h" // for TextureHostOGL -#include "mozilla/mozalloc.h" // for operator delete +#include "mozilla/mozalloc.h" // for operator delete #include "mozilla/Unused.h" #include "nsDebug.h" // for NS_WARNING, NS_ASSERTION #include "nsRegion.h" // for nsIntRegion @@ -81,12 +80,6 @@ bool CompositableParentManager::ReceiveCompositableUpdate( } switch (aDetail.type()) { - case CompositableOperationDetail::TOpPaintTextureRegion: { - return false; - } - case CompositableOperationDetail::TOpUseTiledLayerBuffer: { - return false; - } case CompositableOperationDetail::TOpRemoveTexture: { const OpRemoveTexture& op = aDetail.get_OpRemoveTexture(); @@ -132,42 +125,6 @@ bool CompositableParentManager::ReceiveCompositableUpdate( } break; } - case CompositableOperationDetail::TOpUseComponentAlphaTextures: { - const OpUseComponentAlphaTextures& op = - aDetail.get_OpUseComponentAlphaTextures(); - RefPtr texOnBlack = - TextureHost::AsTextureHost(op.textureOnBlackParent()); - RefPtr texOnWhite = - TextureHost::AsTextureHost(op.textureOnWhiteParent()); - if (op.readLockedBlack()) { - texOnBlack->SetReadLocked(); - } - if (op.readLockedWhite()) { - texOnWhite->SetReadLocked(); - } - - MOZ_ASSERT(texOnBlack && texOnWhite); - aCompositable->UseComponentAlphaTextures(texOnBlack, texOnWhite); - - if (texOnBlack) { - texOnBlack->SetLastFwdTransactionId(mFwdTransactionId); - // Make sure that each texture was handled by the compositable - // because the recycling logic depends on it. - MOZ_ASSERT(texOnBlack->NumCompositableRefs() > 0); - } - - if (texOnWhite) { - texOnWhite->SetLastFwdTransactionId(mFwdTransactionId); - // Make sure that each texture was handled by the compositable - // because the recycling logic depends on it. - MOZ_ASSERT(texOnWhite->NumCompositableRefs() > 0); - } - - if (UsesImageBridge()) { - ScheduleComposition(aCompositable); - } - break; - } case CompositableOperationDetail::TOpDeliverAcquireFence: { const OpDeliverAcquireFence& op = aDetail.get_OpDeliverAcquireFence(); RefPtr tex = TextureHost::AsTextureHost(op.textureParent()); @@ -204,8 +161,7 @@ void CompositableParentManager::DestroyActor(const OpDestroy& aOp) { } RefPtr CompositableParentManager::AddCompositable( - const CompositableHandle& aHandle, const TextureInfo& aInfo, - bool aUseWebRender) { + const CompositableHandle& aHandle, const TextureInfo& aInfo) { if (mCompositables.find(aHandle.Value()) != mCompositables.end()) { NS_ERROR("Client should not allocate duplicate handles"); return nullptr; @@ -215,8 +171,7 @@ RefPtr CompositableParentManager::AddCompositable( return nullptr; } - RefPtr host = - CompositableHost::Create(aInfo, aUseWebRender); + RefPtr host = CompositableHost::Create(aInfo); if (!host) { return nullptr; } @@ -226,33 +181,13 @@ RefPtr CompositableParentManager::AddCompositable( } RefPtr CompositableParentManager::FindCompositable( - const CompositableHandle& aHandle, bool aAllowDisablingWebRender) { + const CompositableHandle& aHandle) { auto iter = mCompositables.find(aHandle.Value()); if (iter == mCompositables.end()) { return nullptr; } - RefPtr host = iter->second; - if (!aAllowDisablingWebRender) { - return host; - } - - if (!host->AsWebRenderImageHost() || !host->GetAsyncRef()) { - return host; - } - - // Try to replace WebRenderImageHost of ImageBridge to ImageHost. - RefPtr newHost = CompositableHost::Create( - host->GetTextureInfo(), /* aUseWebRender */ false); - if (!newHost || !newHost->AsImageHost()) { - MOZ_ASSERT_UNREACHABLE("unexpected to be called"); - return host; - } - - newHost->SetAsyncRef(host->GetAsyncRef()); - mCompositables[aHandle.Value()] = newHost; - - return newHost; + return iter->second; } void CompositableParentManager::ReleaseCompositable( diff --git a/gfx/layers/ipc/CompositableTransactionParent.h b/gfx/layers/ipc/CompositableTransactionParent.h index 8912f50bceaf..e94cc5ded6c2 100644 --- a/gfx/layers/ipc/CompositableTransactionParent.h +++ b/gfx/layers/ipc/CompositableTransactionParent.h @@ -36,10 +36,8 @@ class CompositableParentManager : public HostIPCAllocator { uint64_t GetFwdTransactionId() { return mFwdTransactionId; } RefPtr AddCompositable(const CompositableHandle& aHandle, - const TextureInfo& aInfo, - bool aUseWebRender); - RefPtr FindCompositable( - const CompositableHandle& aHandle, bool aAllowDisablingWebRender = false); + const TextureInfo& aInfo); + RefPtr FindCompositable(const CompositableHandle& aHandle); protected: /** diff --git a/gfx/layers/ipc/ImageBridgeChild.cpp b/gfx/layers/ipc/ImageBridgeChild.cpp index 92bad5111f8c..ca6c26ef4e80 100644 --- a/gfx/layers/ipc/ImageBridgeChild.cpp +++ b/gfx/layers/ipc/ImageBridgeChild.cpp @@ -291,8 +291,7 @@ void ImageBridgeChild::Connect(CompositableClient* aCompositable, CompositableHandle handle(id); aCompositable->InitIPDL(handle); - SendNewCompositable(handle, aCompositable->GetTextureInfo(), - GetCompositorBackendType()); + SendNewCompositable(handle, aCompositable->GetTextureInfo()); } void ImageBridgeChild::ForgetImageContainer(const CompositableHandle& aHandle) { diff --git a/gfx/layers/ipc/ImageBridgeParent.cpp b/gfx/layers/ipc/ImageBridgeParent.cpp index 8a6ce73271fc..9e74c35e84e1 100644 --- a/gfx/layers/ipc/ImageBridgeParent.cpp +++ b/gfx/layers/ipc/ImageBridgeParent.cpp @@ -272,10 +272,8 @@ mozilla::ipc::IPCResult ImageBridgeParent::RecvWillClose() { } mozilla::ipc::IPCResult ImageBridgeParent::RecvNewCompositable( - const CompositableHandle& aHandle, const TextureInfo& aInfo, - const LayersBackend& aLayersBackend) { - bool useWebRender = aLayersBackend == LayersBackend::LAYERS_WR; - RefPtr host = AddCompositable(aHandle, aInfo, useWebRender); + const CompositableHandle& aHandle, const TextureInfo& aInfo) { + RefPtr host = AddCompositable(aHandle, aInfo); if (!host) { return IPC_FAIL_NO_REASON(this); } diff --git a/gfx/layers/ipc/ImageBridgeParent.h b/gfx/layers/ipc/ImageBridgeParent.h index 36e733d83b3e..d3e39db37abc 100644 --- a/gfx/layers/ipc/ImageBridgeParent.h +++ b/gfx/layers/ipc/ImageBridgeParent.h @@ -86,9 +86,8 @@ class ImageBridgeParent final : public PImageBridgeParent, const wr::MaybeExternalImageId& aExternalImageId); bool DeallocPTextureParent(PTextureParent* actor); - mozilla::ipc::IPCResult RecvNewCompositable( - const CompositableHandle& aHandle, const TextureInfo& aInfo, - const LayersBackend& aLayersBackend); + mozilla::ipc::IPCResult RecvNewCompositable(const CompositableHandle& aHandle, + const TextureInfo& aInfo); mozilla::ipc::IPCResult RecvReleaseCompositable( const CompositableHandle& aHandle); diff --git a/gfx/layers/ipc/LayersMessages.ipdlh b/gfx/layers/ipc/LayersMessages.ipdlh index e4f86b7f01f6..c2dcca25fa26 100644 --- a/gfx/layers/ipc/LayersMessages.ipdlh +++ b/gfx/layers/ipc/LayersMessages.ipdlh @@ -346,47 +346,6 @@ union ReadLockDescriptor { null_t; }; -struct TexturedTileDescriptor { - PTexture texture; - PTexture? textureOnWhite; - IntRect updateRect; - bool readLocked; - bool readLockedOnWhite; - bool wasPlaceholder; -}; - -struct PlaceholderTileDescriptor { -}; - -union TileDescriptor { - TexturedTileDescriptor; - PlaceholderTileDescriptor; -}; - -struct SurfaceDescriptorTiles { - nsIntRegion validRegion; - TileDescriptor[] tiles; - IntPoint tileOrigin; - IntSize tileSize; - int firstTileX; - int firstTileY; - int retainedWidth; - int retainedHeight; - float resolution; - float frameXResolution; - float frameYResolution; - bool isProgressive; -}; - -struct OpUseTiledLayerBuffer { - SurfaceDescriptorTiles tileLayerDescriptor; -}; - -struct OpPaintTextureRegion { - ThebesBufferData bufferData; - nsIntRegion updatedRegion; -}; - /** * Tells the CompositableHost to remove the corresponding TextureHost */ @@ -417,13 +376,6 @@ struct OpUseTexture { TimedTexture[] textures; }; -struct OpUseComponentAlphaTextures { - PTexture textureOnBlack; - PTexture textureOnWhite; - bool readLockedBlack; - bool readLockedWhite; -}; - struct OpNotifyNotUsed { uint64_t TextureId; uint64_t fwdTransactionId; @@ -442,14 +394,9 @@ struct OpDeliverReleaseFence { }; union CompositableOperationDetail { - OpPaintTextureRegion; - - OpUseTiledLayerBuffer; - OpRemoveTexture; OpUseTexture; - OpUseComponentAlphaTextures; OpDeliverAcquireFence; }; diff --git a/gfx/layers/ipc/PImageBridge.ipdl b/gfx/layers/ipc/PImageBridge.ipdl index 5c2ee896a865..d03cb70d0aba 100644 --- a/gfx/layers/ipc/PImageBridge.ipdl +++ b/gfx/layers/ipc/PImageBridge.ipdl @@ -54,7 +54,7 @@ parent: async PTexture(SurfaceDescriptor aSharedData, ReadLockDescriptor aReadLock, LayersBackend aBackend, TextureFlags aTextureFlags, uint64_t aSerial, MaybeExternalImageId aExternalImageId); async PMediaSystemResourceManager(); - sync NewCompositable(CompositableHandle aHandle, TextureInfo aInfo, LayersBackend aBackend); + sync NewCompositable(CompositableHandle aHandle, TextureInfo aInfo); async ReleaseCompositable(CompositableHandle aHandle); }; diff --git a/gfx/layers/moz.build b/gfx/layers/moz.build index 59fc23b20959..57b4f05e49e3 100755 --- a/gfx/layers/moz.build +++ b/gfx/layers/moz.build @@ -12,7 +12,6 @@ with Files("apz/**"): EXPORTS += [ "composite/CompositableHost.h", - "composite/ImageHost.h", "CompositorTypes.h", "D3D9SurfaceImage.h", "FrameMetrics.h", @@ -134,13 +133,11 @@ EXPORTS.mozilla.layers += [ "client/TextureClientRecycleAllocator.h", "client/TextureClientSharedSurface.h", "client/TextureRecorded.h", - "composite/ContentHost.h", "composite/Diagnostics.h", "composite/FPSCounter.h", "composite/FrameUniformityData.h", "composite/GPUVideoTextureHost.h", "composite/ImageComposite.h", - "composite/ImageHost.h", "composite/TextRenderer.h", "composite/TextureHost.h", "CompositionRecorder.h", @@ -381,13 +378,11 @@ UNIFIED_SOURCES += [ "client/TextureClientSharedSurface.cpp", "client/TextureRecorded.cpp", "composite/CompositableHost.cpp", - "composite/ContentHost.cpp", "composite/Diagnostics.cpp", "composite/FPSCounter.cpp", "composite/FrameUniformityData.cpp", "composite/GPUVideoTextureHost.cpp", "composite/ImageComposite.cpp", - "composite/ImageHost.cpp", "composite/TextRenderer.cpp", "composite/TextureHost.cpp", "CompositionRecorder.cpp", diff --git a/gfx/layers/wr/WebRenderBridgeParent.cpp b/gfx/layers/wr/WebRenderBridgeParent.cpp index de7fba76bbc2..1eadbf6bf326 100644 --- a/gfx/layers/wr/WebRenderBridgeParent.cpp +++ b/gfx/layers/wr/WebRenderBridgeParent.cpp @@ -2611,7 +2611,7 @@ mozilla::ipc::IPCResult WebRenderBridgeParent::RecvNewCompositable( if (mDestroyed) { return IPC_OK(); } - if (!AddCompositable(aHandle, aInfo, /* aUseWebRender */ true)) { + if (!AddCompositable(aHandle, aInfo)) { return IPC_FAIL_NO_REASON(this); } return IPC_OK();