From cc520153109aa88ea4764b1ad934a7eed9a396c8 Mon Sep 17 00:00:00 2001 From: Jeff Muizelaar Date: Wed, 25 Aug 2021 22:34:19 +0000 Subject: [PATCH] Bug 1727634 - Remove RotatedBuffer. r=mstange Differential Revision: https://phabricator.services.mozilla.com/D123683 --- gfx/layers/RotatedBuffer.cpp | 444 ----------------------------- gfx/layers/RotatedBuffer.h | 409 -------------------------- gfx/layers/client/ContentClient.h | 44 --- gfx/layers/composite/ContentHost.h | 1 - gfx/layers/moz.build | 2 - 5 files changed, 900 deletions(-) delete mode 100644 gfx/layers/RotatedBuffer.cpp delete mode 100644 gfx/layers/RotatedBuffer.h diff --git a/gfx/layers/RotatedBuffer.cpp b/gfx/layers/RotatedBuffer.cpp deleted file mode 100644 index a37b15feb5dd..000000000000 --- a/gfx/layers/RotatedBuffer.cpp +++ /dev/null @@ -1,444 +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 "RotatedBuffer.h" - -#include // for int32_t - -#include // for max -#include // for Move - -#include "Layers.h" // for PaintedLayer, Layer, etc -#include "gfx2DGlue.h" -#include "gfxPlatform.h" // for gfxPlatform -#include "gfxUtils.h" // for gfxUtils -#include "mozilla/ArrayUtils.h" // for ArrayLength -#include "mozilla/ProfilerLabels.h" -#include "mozilla/StaticPrefs_layers.h" -#include "mozilla/gfx/BasePoint.h" // for BasePoint -#include "mozilla/gfx/BaseRect.h" // for BaseRect -#include "mozilla/gfx/BaseSize.h" // for BaseSize -#include "mozilla/gfx/Matrix.h" // for Matrix -#include "mozilla/gfx/Point.h" // for Point, IntPoint -#include "mozilla/gfx/Point.h" // for IntSize -#include "mozilla/gfx/Rect.h" // for Rect, IntRect -#include "mozilla/gfx/Types.h" // for ExtendMode::ExtendMode::CLAMP, etc -#include "mozilla/layers/ShadowLayers.h" // for ShadowableLayer -#include "mozilla/layers/TextureClient.h" // for TextureClient -#include "nsLayoutUtils.h" // for invalidation debugging - -namespace mozilla { - -using namespace gfx; - -namespace layers { - -void BorrowDrawTarget::ReturnDrawTarget(gfx::DrawTarget*& aReturned) { - MOZ_ASSERT(mLoanedDrawTarget); - MOZ_ASSERT(aReturned == mLoanedDrawTarget); - if (mLoanedDrawTarget) { - mLoanedDrawTarget->SetTransform(mLoanedTransform); - mLoanedDrawTarget = nullptr; - } - aReturned = nullptr; -} - -IntRect RotatedBuffer::GetQuadrantRectangle(XSide aXSide, YSide aYSide) const { - // quadrantTranslation is the amount we translate the top-left - // of the quadrant by to get coordinates relative to the layer - IntPoint quadrantTranslation = -mBufferRotation; - quadrantTranslation.x += aXSide == LEFT ? mBufferRect.Width() : 0; - quadrantTranslation.y += aYSide == TOP ? mBufferRect.Height() : 0; - return mBufferRect + quadrantTranslation; -} - -Rect RotatedBuffer::GetSourceRectangle(XSide aXSide, YSide aYSide) const { - Rect result; - if (aXSide == LEFT) { - result.SetBoxX(0, mBufferRotation.x); - } else { - result.SetBoxX(mBufferRotation.x, mBufferRect.Width()); - } - if (aYSide == TOP) { - result.SetBoxY(0, mBufferRotation.y); - } else { - result.SetBoxY(mBufferRotation.y, mBufferRect.Height()); - } - return result; -} - -void RotatedBuffer::BeginCapture() { - RefPtr target = GetBufferTarget(); - - MOZ_ASSERT(!mCapture); - MOZ_ASSERT(target); - mCapture = Factory::CreateCaptureDrawTargetForTarget( - target, StaticPrefs::layers_omtp_capture_limit_AtStartup()); -} - -RefPtr RotatedBuffer::EndCapture() { - MOZ_ASSERT(mCapture); - return std::move(mCapture); -} - -/** - * @param aXSide LEFT means we draw from the left side of the buffer (which - * is drawn on the right side of mBufferRect). RIGHT means we draw from - * the right side of the buffer (which is drawn on the left side of - * mBufferRect). - * @param aYSide TOP means we draw from the top side of the buffer (which - * is drawn on the bottom side of mBufferRect). BOTTOM means we draw from - * the bottom side of the buffer (which is drawn on the top side of - * mBufferRect). - */ -void RotatedBuffer::DrawBufferQuadrant( - gfx::DrawTarget* aTarget, XSide aXSide, YSide aYSide, float aOpacity, - gfx::CompositionOp aOperator, gfx::SourceSurface* aMask, - const gfx::Matrix* aMaskTransform) const { - // The rectangle that we're going to fill. Basically we're going to - // render the buffer at mBufferRect + quadrantTranslation to get the - // pixels in the right place, but we're only going to paint within - // mBufferRect - IntRect quadrantRect = GetQuadrantRectangle(aXSide, aYSide); - IntRect fillRect; - if (!fillRect.IntersectRect(mBufferRect, quadrantRect)) return; - - gfx::Point quadrantTranslation(quadrantRect.X(), quadrantRect.Y()); - - RefPtr snapshot = GetBufferSource(); - - if (!snapshot) { - gfxCriticalError() - << "Invalid snapshot in RotatedBuffer::DrawBufferQuadrant"; - return; - } - - // direct2d is much slower when using OP_SOURCE so use OP_OVER and - // (maybe) a clear instead. Normally we need to draw in a single operation - // (to avoid flickering) but direct2d is ok since it defers rendering. - // We should try abstract this logic in a helper when we have other use - // cases. - if ((aTarget->GetBackendType() == BackendType::DIRECT2D || - aTarget->GetBackendType() == BackendType::DIRECT2D1_1) && - aOperator == CompositionOp::OP_SOURCE) { - aOperator = CompositionOp::OP_OVER; - if (snapshot->GetFormat() == SurfaceFormat::B8G8R8A8) { - aTarget->ClearRect(IntRectToRect(fillRect)); - } - } - - // OP_SOURCE is unbounded in Azure, and we really don't want that behaviour - // here. We also can't do a ClearRect+FillRect since we need the drawing to - // happen as an atomic operation (to prevent flickering). We also need this - // clip in the case where we have a mask, since the mask surface might cover - // more than fillRect, but we only want to touch the pixels inside fillRect. - aTarget->PushClipRect(IntRectToRect(fillRect)); - - if (aMask) { - Matrix oldTransform = aTarget->GetTransform(); - - // Transform from user -> buffer space. - Matrix transform = - Matrix::Translation(quadrantTranslation.x, quadrantTranslation.y); - - Matrix inverseMask = *aMaskTransform; - inverseMask.Invert(); - - transform *= oldTransform; - transform *= inverseMask; - -#ifdef MOZ_GFX_OPTIMIZE_MOBILE - SurfacePattern source(snapshot, ExtendMode::CLAMP, transform, - SamplingFilter::POINT); -#else - SurfacePattern source(snapshot, ExtendMode::CLAMP, transform); -#endif - - aTarget->SetTransform(*aMaskTransform); - aTarget->MaskSurface(source, aMask, Point(0, 0), - DrawOptions(aOpacity, aOperator)); - aTarget->SetTransform(oldTransform); - } else { -#ifdef MOZ_GFX_OPTIMIZE_MOBILE - DrawSurfaceOptions options(SamplingFilter::POINT); -#else - DrawSurfaceOptions options; -#endif - aTarget->DrawSurface(snapshot, IntRectToRect(fillRect), - GetSourceRectangle(aXSide, aYSide), options, - DrawOptions(aOpacity, aOperator)); - } - - aTarget->PopClip(); -} - -void RotatedBuffer::DrawBufferWithRotation( - gfx::DrawTarget* aTarget, float aOpacity, gfx::CompositionOp aOperator, - gfx::SourceSurface* aMask, const gfx::Matrix* aMaskTransform) const { - AUTO_PROFILER_LABEL("RotatedBuffer::DrawBufferWithRotation", GRAPHICS); - - // See above, in Azure Repeat should always be a safe, even faster choice - // though! Particularly on D2D Repeat should be a lot faster, need to look - // into that. TODO[Bas] - DrawBufferQuadrant(aTarget, LEFT, TOP, aOpacity, aOperator, aMask, - aMaskTransform); - DrawBufferQuadrant(aTarget, RIGHT, TOP, aOpacity, aOperator, aMask, - aMaskTransform); - DrawBufferQuadrant(aTarget, LEFT, BOTTOM, aOpacity, aOperator, aMask, - aMaskTransform); - DrawBufferQuadrant(aTarget, RIGHT, BOTTOM, aOpacity, aOperator, aMask, - aMaskTransform); -} - -static bool IsClippingCheap(gfx::DrawTarget* aTarget, - const nsIntRegion& aRegion) { - // Assume clipping is cheap if the draw target just has an integer - // translation, and the visible region is simple. - return !aTarget->GetTransform().HasNonIntegerTranslation() && - aRegion.GetNumRects() <= 1; -} - -void RotatedBuffer::UpdateDestinationFrom(const RotatedBuffer& aSource, - const gfx::IntRect& aUpdateRect) { - DrawIterator iter; - while (DrawTarget* destDT = - BorrowDrawTargetForQuadrantUpdate(aUpdateRect, &iter)) { - bool isClippingCheap = IsClippingCheap(destDT, iter.mDrawRegion); - if (isClippingCheap) { - gfxUtils::ClipToRegion(destDT, iter.mDrawRegion); - } - - aSource.DrawBufferWithRotation(destDT, 1.0, CompositionOp::OP_SOURCE); - if (isClippingCheap) { - destDT->PopClip(); - } - ReturnDrawTarget(destDT); - } -} - -static void WrapRotationAxis(int32_t* aRotationPoint, int32_t aSize) { - if (*aRotationPoint < 0) { - *aRotationPoint += aSize; - } else if (*aRotationPoint >= aSize) { - *aRotationPoint -= aSize; - } -} - -bool RotatedBuffer::Parameters::IsRotated() const { - return mBufferRotation != IntPoint(0, 0); -} - -bool RotatedBuffer::Parameters::RectWrapsBuffer( - const gfx::IntRect& aRect) const { - int32_t xBoundary = mBufferRect.XMost() - mBufferRotation.x; - int32_t yBoundary = mBufferRect.YMost() - mBufferRotation.y; - return (aRect.X() < xBoundary && xBoundary < aRect.XMost()) || - (aRect.Y() < yBoundary && yBoundary < aRect.YMost()); -} - -void RotatedBuffer::Parameters::SetUnrotated() { - mBufferRotation = IntPoint(0, 0); - mDidSelfCopy = true; -} - -RotatedBuffer::Parameters RotatedBuffer::AdjustedParameters( - const gfx::IntRect& aDestBufferRect) const { - IntRect keepArea; - if (keepArea.IntersectRect(aDestBufferRect, mBufferRect)) { - // Set mBufferRotation so that the pixels currently in mDTBuffer - // will still be rendered in the right place when mBufferRect - // changes to aDestBufferRect. - IntPoint newRotation = - mBufferRotation + (aDestBufferRect.TopLeft() - mBufferRect.TopLeft()); - WrapRotationAxis(&newRotation.x, mBufferRect.Width()); - WrapRotationAxis(&newRotation.y, mBufferRect.Height()); - NS_ASSERTION(gfx::IntRect(gfx::IntPoint(0, 0), mBufferRect.Size()) - .Contains(newRotation), - "newRotation out of bounds"); - - return Parameters{aDestBufferRect, newRotation}; - } - - // No pixels are going to be kept. The whole visible region - // will be redrawn, so we don't need to copy anything, so we don't - // set destBuffer. - return Parameters{aDestBufferRect, IntPoint(0, 0)}; -} - -bool RotatedBuffer::UnrotateBufferTo(const Parameters& aParameters) { - RefPtr drawTarget = GetDrawTarget(); - MOZ_ASSERT(drawTarget && drawTarget->IsValid()); - - if (mBufferRotation == IntPoint(0, 0)) { - IntRect srcRect(IntPoint(0, 0), mBufferRect.Size()); - IntPoint dest = mBufferRect.TopLeft() - aParameters.mBufferRect.TopLeft(); - - drawTarget->CopyRect(srcRect, dest); - return true; - } else { - return drawTarget->Unrotate(aParameters.mBufferRotation); - } -} - -void RotatedBuffer::SetParameters( - const RotatedBuffer::Parameters& aParameters) { - mBufferRect = aParameters.mBufferRect; - mBufferRotation = aParameters.mBufferRotation; - mDidSelfCopy = aParameters.mDidSelfCopy; -} - -RotatedBuffer::ContentType RotatedBuffer::GetContentType() const { - return ContentForFormat(GetFormat()); -} - -DrawTarget* RotatedBuffer::BorrowDrawTargetForQuadrantUpdate( - const IntRect& aBounds, DrawIterator* aIter) { - IntRect bounds = aBounds; - if (aIter) { - // If an iterator was provided, then BeginPaint must have been run with - // PAINT_CAN_DRAW_ROTATED, and the draw region might cover multiple - // quadrants. Iterate over each of them, and return an appropriate buffer - // each time we find one that intersects the draw region. The iterator - // mCount value tracks which quadrants we have considered across multiple - // calls to this function. - aIter->mDrawRegion.SetEmpty(); - while (aIter->mCount < 4) { - IntRect quadrant = - GetQuadrantRectangle((aIter->mCount & 1) ? LEFT : RIGHT, - (aIter->mCount & 2) ? TOP : BOTTOM); - aIter->mDrawRegion.And(aBounds, quadrant); - aIter->mCount++; - if (!aIter->mDrawRegion.IsEmpty()) { - break; - } - } - if (aIter->mDrawRegion.IsEmpty()) { - return nullptr; - } - bounds = aIter->mDrawRegion.GetBounds(); - } - - MOZ_ASSERT(!mLoanedDrawTarget, - "draw target has been borrowed and not returned"); - mLoanedDrawTarget = GetDrawTarget(); - - // Figure out which quadrant to draw in - int32_t xBoundary = mBufferRect.XMost() - mBufferRotation.x; - int32_t yBoundary = mBufferRect.YMost() - mBufferRotation.y; - XSide sideX = bounds.XMost() <= xBoundary ? RIGHT : LEFT; - YSide sideY = bounds.YMost() <= yBoundary ? BOTTOM : TOP; - IntRect quadrantRect = GetQuadrantRectangle(sideX, sideY); - NS_ASSERTION(quadrantRect.Contains(bounds), "Messed up quadrants"); - - mLoanedTransform = mLoanedDrawTarget->GetTransform(); - Matrix transform = Matrix(mLoanedTransform) - .PreTranslate(-quadrantRect.X(), -quadrantRect.Y()); - mLoanedDrawTarget->SetTransform(transform); - - return mLoanedDrawTarget; -} - -gfx::SurfaceFormat RemoteRotatedBuffer::GetFormat() const { - return mClient->GetFormat(); -} - -bool RemoteRotatedBuffer::IsLocked() { return mClient->IsLocked(); } - -bool RemoteRotatedBuffer::Lock(OpenMode aMode) { - MOZ_ASSERT(!mTarget); - MOZ_ASSERT(!mTargetOnWhite); - - bool locked = - mClient->Lock(aMode) && (!mClientOnWhite || mClientOnWhite->Lock(aMode)); - if (!locked) { - Unlock(); - return false; - } - - mTarget = mClient->BorrowDrawTarget(); - if (!mTarget || !mTarget->IsValid()) { - gfxCriticalNote << "Invalid draw target " << hexa(mTarget) - << " in RemoteRotatedBuffer::Lock"; - Unlock(); - return false; - } - - if (mClientOnWhite) { - mTargetOnWhite = mClientOnWhite->BorrowDrawTarget(); - if (!mTargetOnWhite || !mTargetOnWhite->IsValid()) { - gfxCriticalNote << "Invalid draw target(s) " << hexa(mTarget) << " and " - << hexa(mTargetOnWhite) - << " in RemoteRotatedBuffer::Lock"; - Unlock(); - return false; - } - } - - if (mTargetOnWhite) { - mTargetDual = Factory::CreateDualDrawTarget(mTarget, mTargetOnWhite); - - if (!mTargetDual || !mTargetDual->IsValid()) { - gfxCriticalNote << "Invalid dual draw target " << hexa(mTargetDual) - << " in RemoteRotatedBuffer::Lock"; - Unlock(); - return false; - } - } else { - mTargetDual = mTarget; - } - - return true; -} - -void RemoteRotatedBuffer::Unlock() { - mTarget = nullptr; - mTargetOnWhite = nullptr; - mTargetDual = nullptr; - - if (mClient->IsLocked()) { - mClient->Unlock(); - } - if (mClientOnWhite && mClientOnWhite->IsLocked()) { - mClientOnWhite->Unlock(); - } -} - -void RemoteRotatedBuffer::SyncWithObject(RefPtr aSyncObject) { - mClient->SyncWithObject(aSyncObject); - if (mClientOnWhite) { - mClientOnWhite->SyncWithObject(aSyncObject); - } -} - -void RemoteRotatedBuffer::Clear() { - MOZ_ASSERT(!mTarget && !mTargetOnWhite); - mClient = nullptr; - mClientOnWhite = nullptr; -} - -gfx::DrawTarget* RemoteRotatedBuffer::GetBufferTarget() const { - return mTargetDual; -} - -gfx::SurfaceFormat DrawTargetRotatedBuffer::GetFormat() const { - return mTarget->GetFormat(); -} - -gfx::DrawTarget* DrawTargetRotatedBuffer::GetBufferTarget() const { - return mTargetDual; -} - -gfx::SurfaceFormat SourceRotatedBuffer::GetFormat() const { - return mSource->GetFormat(); -} - -already_AddRefed SourceRotatedBuffer::GetBufferSource() const { - RefPtr sourceDual = mSourceDual; - return sourceDual.forget(); -} - -} // namespace layers -} // namespace mozilla diff --git a/gfx/layers/RotatedBuffer.h b/gfx/layers/RotatedBuffer.h deleted file mode 100644 index 5c6d672fbb4b..000000000000 --- a/gfx/layers/RotatedBuffer.h +++ /dev/null @@ -1,409 +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 ROTATEDBUFFER_H_ -#define ROTATEDBUFFER_H_ - -#include "gfxTypes.h" -#include // for uint32_t -#include "mozilla/AlreadyAddRefed.h" // for already_AddRefed -#include "mozilla/Assertions.h" // for MOZ_ASSERT, etc -#include "mozilla/RefPtr.h" // for RefPtr, already_AddRefed -#include "mozilla/gfx/2D.h" // for DrawTarget, etc -#include "mozilla/gfx/MatrixFwd.h" // for Matrix -#include "mozilla/layers/TextureClient.h" // for TextureClient -#include "mozilla/mozalloc.h" // for operator delete -#include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, etc -#include "nsRegion.h" // for nsIntRegion - -namespace mozilla { -namespace layers { - -class PaintedLayer; -class ContentClient; - -// Mixin class for classes which need logic for loaning out a draw target. -// See comments on BorrowDrawTargetForQuadrantUpdate. -class BorrowDrawTarget { - public: - void ReturnDrawTarget(gfx::DrawTarget*& aReturned); - - protected: - // The draw target loaned by BorrowDrawTargetForQuadrantUpdate. It should not - // be used, we just keep a reference to ensure it is kept alive and so we can - // correctly restore state when it is returned. - RefPtr mLoanedDrawTarget; - gfx::Matrix mLoanedTransform; -}; - -/** - * This is a cairo/Thebes surface, but with a literal twist. Scrolling - * causes the layer's visible region to move. We want to keep - * reusing the same surface if the region size hasn't changed, but we don't - * want to keep moving the contents of the surface around in memory. So - * we use a trick. - * Consider just the vertical case, and suppose the buffer is H pixels - * high and we're scrolling down by N pixels. Instead of copying the - * buffer contents up by N pixels, we leave the buffer contents in place, - * and paint content rows H to H+N-1 into rows 0 to N-1 of the buffer. - * Then we can refresh the screen by painting rows N to H-1 of the buffer - * at row 0 on the screen, and then painting rows 0 to N-1 of the buffer - * at row H-N on the screen. - * mBufferRotation.y would be N in this example. - */ -class RotatedBuffer : public BorrowDrawTarget { - public: - typedef gfxContentType ContentType; - - NS_INLINE_DECL_THREADSAFE_REFCOUNTING(RotatedBuffer) - - RotatedBuffer(const gfx::IntRect& aBufferRect, - const gfx::IntPoint& aBufferRotation) - : mCapture(nullptr), - mBufferRect(aBufferRect), - mBufferRotation(aBufferRotation), - mDidSelfCopy(false) {} - RotatedBuffer() : mCapture(nullptr), mDidSelfCopy(false) {} - - /** - * Initializes the rotated buffer to begin capturing all drawing performed - * on it, to be eventually replayed. Callers must call EndCapture, or - * FlushCapture before the rotated buffer is destroyed. - */ - void BeginCapture(); - - /** - * Finishes a capture and returns it. The capture must be replayed to the - * buffer before it is presented or it will contain invalid contents. - */ - RefPtr EndCapture(); - - /** - * Returns whether the RotatedBuffer is currently capturing all drawing - * performed on it, to be eventually replayed. - */ - bool IsCapturing() const { return !!mCapture; } - - /** - * Draws the contents of this rotated buffer into the specified draw target. - * It is the callers repsonsibility to ensure aTarget is flushed after calling - * this method. - */ - void DrawBufferWithRotation( - gfx::DrawTarget* aTarget, float aOpacity = 1.0, - gfx::CompositionOp aOperator = gfx::CompositionOp::OP_OVER, - gfx::SourceSurface* aMask = nullptr, - const gfx::Matrix* aMaskTransform = nullptr) const; - - /** - * Update the specified region of this rotated buffer with the contents - * of a source rotated buffer. - */ - void UpdateDestinationFrom(const RotatedBuffer& aSource, - const gfx::IntRect& aUpdateRect); - - /** - * A draw iterator is used to keep track of which quadrant of a rotated - * buffer and region of that quadrant is being updated. - */ - struct DrawIterator { - friend class RotatedBuffer; - DrawIterator() : mCount(0) {} - - nsIntRegion mDrawRegion; - - private: - uint32_t mCount; - }; - - /** - * Get a draw target at the specified resolution for updating |aBounds|, - * which must be contained within a single quadrant. - * - * The result should only be held temporarily by the caller (it will be kept - * alive by this). Once used it should be returned using ReturnDrawTarget. - * BorrowDrawTargetForQuadrantUpdate may not be called more than once without - * first calling ReturnDrawTarget. - * - * ReturnDrawTarget will by default restore the transform on the draw target. - * But it is the callers responsibility to restore the clip. - * The caller should flush the draw target, if necessary. - * If aSetTransform is false, the required transform will be set in - * aOutTransform. - */ - gfx::DrawTarget* BorrowDrawTargetForQuadrantUpdate( - const gfx::IntRect& aBounds, DrawIterator* aIter); - - struct Parameters { - Parameters(const gfx::IntRect& aBufferRect, - const gfx::IntPoint& aBufferRotation) - : mBufferRect(aBufferRect), - mBufferRotation(aBufferRotation), - mDidSelfCopy(false) {} - - bool IsRotated() const; - bool RectWrapsBuffer(const gfx::IntRect& aRect) const; - - void SetUnrotated(); - - gfx::IntRect mBufferRect; - gfx::IntPoint mBufferRotation; - bool mDidSelfCopy; - }; - - /** - * Returns the new buffer parameters for rotating to a - * destination buffer rect. - */ - Parameters AdjustedParameters(const gfx::IntRect& aDestBufferRect) const; - - /** - * Unrotates the pixels of the rotated buffer for the specified - * new buffer parameters. - */ - bool UnrotateBufferTo(const Parameters& aParameters); - - void SetParameters(const Parameters& aParameters); - - /** - * |BufferRect()| is the rect of device pixels that this - * RotatedBuffer covers. That is what DrawBufferWithRotation() - * will paint when it's called. - */ - const gfx::IntRect& BufferRect() const { return mBufferRect; } - const gfx::IntPoint& BufferRotation() const { return mBufferRotation; } - - /** - * Overrides the current buffer rect with the specified rect. - * Do not do this unless you know what you're doing. - */ - void SetBufferRect(const gfx::IntRect& aBufferRect) { - mBufferRect = aBufferRect; - } - - /** - * Overrides the current buffer rotation with the specified point. - * Do not do this unless you know what you're doing. - */ - void SetBufferRotation(const gfx::IntPoint& aBufferRotation) { - mBufferRotation = aBufferRotation; - } - - /** - * Returns whether this buffer did a self copy when adjusting to - * a new buffer rect. This is only used externally for syncing - * rotated buffers. - */ - bool DidSelfCopy() const { return mDidSelfCopy; } - - /** - * Clears the self copy flag. - */ - void ClearDidSelfCopy() { mDidSelfCopy = false; } - - /** - * Gets the content type for this buffer. - */ - ContentType GetContentType() const; - - virtual bool IsLocked() = 0; - virtual bool Lock(OpenMode aMode) = 0; - virtual void Unlock() = 0; - - virtual bool HaveBuffer() const = 0; - virtual bool HaveBufferOnWhite() const = 0; - - virtual gfx::SurfaceFormat GetFormat() const = 0; - - virtual already_AddRefed GetBufferSource() const { - return GetBufferTarget()->Snapshot(); - } - virtual gfx::DrawTarget* GetBufferTarget() const = 0; - - virtual TextureClient* GetClient() const { return nullptr; } - virtual TextureClient* GetClientOnWhite() const { return nullptr; } - - protected: - virtual ~RotatedBuffer() { MOZ_ASSERT(!mCapture); } - - enum XSide { LEFT, RIGHT }; - enum YSide { TOP, BOTTOM }; - gfx::IntRect GetQuadrantRectangle(XSide aXSide, YSide aYSide) const; - - gfx::Rect GetSourceRectangle(XSide aXSide, YSide aYSide) const; - - gfx::DrawTarget* GetDrawTarget() const { - if (mCapture) { - return mCapture; - } - return GetBufferTarget(); - } - - /* - * If aMask is non-null, then it is used as an alpha mask for rendering this - * buffer. aMaskTransform must be non-null if aMask is non-null, and is used - * to adjust the coordinate space of the mask. - */ - void DrawBufferQuadrant(gfx::DrawTarget* aTarget, XSide aXSide, YSide aYSide, - float aOpacity, gfx::CompositionOp aOperator, - gfx::SourceSurface* aMask, - const gfx::Matrix* aMaskTransform) const; - - RefPtr mCapture; - - /** The area of the PaintedLayer that is covered by the buffer as a whole */ - gfx::IntRect mBufferRect; - /** - * The x and y rotation of the buffer. Conceptually the buffer - * has its origin translated to mBufferRect.TopLeft() - mBufferRotation, - * is tiled to fill the plane, and the result is clipped to mBufferRect. - * So the pixel at mBufferRotation within the buffer is what gets painted at - * mBufferRect.TopLeft(). - * This is "rotation" in the sense of rotating items in a linear buffer, - * where items falling off the end of the buffer are returned to the - * buffer at the other end, not 2D rotation! - */ - gfx::IntPoint mBufferRotation; - /** - * When this is true it means that all pixels have moved inside the buffer. - * It's not possible to sync with another buffer without a full copy. - */ - bool mDidSelfCopy; -}; - -/** - * RemoteRotatedBuffer is a rotated buffer that is backed by texture - * clients. Before you use this class you must successfully lock it with - * an appropriate open mode, and then also unlock it when you're finished. - * RemoteRotatedBuffer is used by ContentClientSingleBuffered and - * ContentClientDoubleBuffered for the OMTC code path. - */ -class RemoteRotatedBuffer : public RotatedBuffer { - public: - RemoteRotatedBuffer(TextureClient* aClient, TextureClient* aClientOnWhite, - const gfx::IntRect& aBufferRect, - const gfx::IntPoint& aBufferRotation) - : RotatedBuffer(aBufferRect, aBufferRotation), - mClient(aClient), - mClientOnWhite(aClientOnWhite) {} - - virtual bool IsLocked() override; - virtual bool Lock(OpenMode aMode) override; - virtual void Unlock() override; - - virtual bool HaveBuffer() const override { return !!mClient; } - virtual bool HaveBufferOnWhite() const override { return !!mClientOnWhite; } - - virtual gfx::SurfaceFormat GetFormat() const override; - - virtual gfx::DrawTarget* GetBufferTarget() const override; - - virtual TextureClient* GetClient() const override { return mClient; } - virtual TextureClient* GetClientOnWhite() const override { - return mClientOnWhite; - } - - void SyncWithObject(RefPtr aSyncObject); - void Clear(); - - private: - RemoteRotatedBuffer(TextureClient* aClient, TextureClient* aClientOnWhite, - gfx::DrawTarget* aTarget, gfx::DrawTarget* aTargetOnWhite, - gfx::DrawTarget* aTargetDual, - const gfx::IntRect& aBufferRect, - const gfx::IntPoint& aBufferRotation) - : RotatedBuffer(aBufferRect, aBufferRotation), - mClient(aClient), - mClientOnWhite(aClientOnWhite), - mTarget(aTarget), - mTargetOnWhite(aTargetOnWhite), - mTargetDual(aTargetDual) {} - - RefPtr mClient; - RefPtr mClientOnWhite; - - RefPtr mTarget; - RefPtr mTargetOnWhite; - RefPtr mTargetDual; -}; - -/** - * DrawTargetRotatedBuffer is a rotated buffer that is backed by draw targets, - * and is used by ContentClientBasic for the on-mtc code path. - */ -class DrawTargetRotatedBuffer : public RotatedBuffer { - public: - DrawTargetRotatedBuffer(gfx::DrawTarget* aTarget, - gfx::DrawTarget* aTargetOnWhite, - const gfx::IntRect& aBufferRect, - const gfx::IntPoint& aBufferRotation) - : RotatedBuffer(aBufferRect, aBufferRotation), - mTarget(aTarget), - mTargetOnWhite(aTargetOnWhite) { - if (mTargetOnWhite) { - mTargetDual = gfx::Factory::CreateDualDrawTarget(mTarget, mTargetOnWhite); - } else { - mTargetDual = mTarget; - } - } - - virtual bool IsLocked() override { return false; } - virtual bool Lock(OpenMode aMode) override { return true; } - virtual void Unlock() override {} - - virtual bool HaveBuffer() const override { return !!mTargetDual; } - virtual bool HaveBufferOnWhite() const override { return !!mTargetOnWhite; } - - virtual gfx::SurfaceFormat GetFormat() const override; - - virtual gfx::DrawTarget* GetBufferTarget() const override; - - private: - RefPtr mTarget; - RefPtr mTargetOnWhite; - RefPtr mTargetDual; -}; - -/** - * SourceRotatedBuffer is a rotated buffer that is backed by source surfaces, - * and may only be used to draw into other buffers or be read directly. - */ -class SourceRotatedBuffer : public RotatedBuffer { - public: - SourceRotatedBuffer(gfx::SourceSurface* aSource, - gfx::SourceSurface* aSourceOnWhite, - const gfx::IntRect& aBufferRect, - const gfx::IntPoint& aBufferRotation) - : RotatedBuffer(aBufferRect, aBufferRotation), - mSource(aSource), - mSourceOnWhite(aSourceOnWhite) { - mSourceDual = - gfx::Factory::CreateDualSourceSurface(mSource, mSourceOnWhite); - } - - virtual bool IsLocked() override { return false; } - virtual bool Lock(OpenMode aMode) override { return false; } - virtual void Unlock() override {} - - virtual already_AddRefed GetBufferSource() const override; - - virtual gfx::SurfaceFormat GetFormat() const override; - - virtual bool HaveBuffer() const override { return !!mSourceDual; } - virtual bool HaveBufferOnWhite() const override { return !!mSourceOnWhite; } - - virtual gfx::DrawTarget* GetBufferTarget() const override { return nullptr; } - - private: - RefPtr mSource; - RefPtr mSourceOnWhite; - RefPtr mSourceDual; -}; - -} // namespace layers -} // namespace mozilla - -#endif /* ROTATEDBUFFER_H_ */ diff --git a/gfx/layers/client/ContentClient.h b/gfx/layers/client/ContentClient.h index d828d7b8b32c..61808ac53a17 100644 --- a/gfx/layers/client/ContentClient.h +++ b/gfx/layers/client/ContentClient.h @@ -8,7 +8,6 @@ #define MOZILLA_GFX_CONTENTCLIENT_H #include // for uint32_t -#include "RotatedBuffer.h" // for RotatedBuffer, etc #include "gfxTypes.h" #include "gfxPlatform.h" // for gfxPlatform #include "mozilla/Assertions.h" // for MOZ_CRASH @@ -140,24 +139,6 @@ class ContentClient : public CompositableClient { PaintState& aPaintState, nsTArray* aReadbackUpdates = nullptr); - /** - * Fetch a DrawTarget for rendering. The DrawTarget remains owned by - * this. See notes on BorrowDrawTargetForQuadrantUpdate. - * May return null. If the return value is non-null, it must be - * 'un-borrowed' using ReturnDrawTarget. - * - * If PAINT_CAN_DRAW_ROTATED was specified for BeginPaint, then the caller - * must call this function repeatedly (with an iterator) until it returns - * nullptr. The caller should draw the mDrawRegion of the iterator instead - * of mRegionToDraw in the PaintState. - * - * @param aPaintState Paint state data returned by a call to BeginPaint - * @param aIter Paint state iterator. Only required if PAINT_CAN_DRAW_ROTATED - * was specified to BeginPaint. - */ - virtual gfx::DrawTarget* BorrowDrawTargetForPainting( - PaintState& aPaintState, RotatedBuffer::DrawIterator* aIter = nullptr); - void ReturnDrawTarget(gfx::DrawTarget*& aReturned); enum { @@ -196,17 +177,6 @@ class ContentClient : public CompositableClient { */ virtual void FinalizeFrame(PaintState& aPaintState) {} - virtual RefPtr GetFrontBuffer() const { return mBuffer; } - - /** - * Create a new rotated buffer for the specified content type, buffer rect, - * and buffer flags. - */ - virtual RefPtr CreateBuffer(gfxContentType aType, - const gfx::IntRect& aRect, - uint32_t aFlags) = 0; - - RefPtr mBuffer; BufferSizePolicy mBufferSizePolicy; }; @@ -255,17 +225,6 @@ class ContentClientRemoteBuffer : public ContentClient { virtual nsIntRegion GetUpdatedRegion(const nsIntRegion& aRegionToDraw, const nsIntRegion& aVisibleRegion); - RefPtr CreateBuffer(gfxContentType aType, - const gfx::IntRect& aRect, - uint32_t aFlags) override; - - RefPtr CreateBufferInternal(const gfx::IntRect& aRect, - gfx::SurfaceFormat aFormat, - TextureFlags aFlags); - - RemoteRotatedBuffer* GetRemoteBuffer() const { - return static_cast(mBuffer.get()); - } bool mIsNewBuffer; }; @@ -296,8 +255,6 @@ class ContentClientDoubleBuffered : public ContentClientRemoteBuffer { void FinalizeFrame(PaintState& aPaintState) override; - RefPtr GetFrontBuffer() const override { return mFrontBuffer; } - TextureInfo GetTextureInfo() const override { return TextureInfo(CompositableType::CONTENT_DOUBLE, mTextureFlags); } @@ -305,7 +262,6 @@ class ContentClientDoubleBuffered : public ContentClientRemoteBuffer { private: void EnsureBackBufferIfFrontBuffer(); - RefPtr mFrontBuffer; nsIntRegion mFrontUpdatedRegion; bool mFrontAndBackBufferDiffer; }; diff --git a/gfx/layers/composite/ContentHost.h b/gfx/layers/composite/ContentHost.h index 03b595657112..a666a3352ce9 100644 --- a/gfx/layers/composite/ContentHost.h +++ b/gfx/layers/composite/ContentHost.h @@ -11,7 +11,6 @@ #include // for FILE #include "mozilla-config.h" // for MOZ_DUMP_PAINTING #include "CompositableHost.h" // for CompositableHost, etc -#include "RotatedBuffer.h" // for RotatedBuffer, etc #include "mozilla/Attributes.h" // for override #include "mozilla/RefPtr.h" // for RefPtr #include "mozilla/gfx/BasePoint.h" // for BasePoint diff --git a/gfx/layers/moz.build b/gfx/layers/moz.build index 0481a0865afd..33501fbc768b 100755 --- a/gfx/layers/moz.build +++ b/gfx/layers/moz.build @@ -223,7 +223,6 @@ EXPORTS.mozilla.layers += [ "ProfilerScreenshots.h", "RenderTrace.h", "RepaintRequest.h", - "RotatedBuffer.h", "SampleTime.h", "ScreenshotGrabber.h", "ScrollableLayerGuid.h", @@ -475,7 +474,6 @@ UNIFIED_SOURCES += [ "ReadbackProcessor.cpp", "RenderTrace.cpp", "RepaintRequest.cpp", - "RotatedBuffer.cpp", "SampleTime.cpp", "ScreenshotGrabber.cpp", "ScrollableLayerGuid.cpp",