diff --git a/gfx/layers/RotatedBuffer.h b/gfx/layers/RotatedBuffer.h index bd4e9703d0a6..dbd96cdf77c9 100644 --- a/gfx/layers/RotatedBuffer.h +++ b/gfx/layers/RotatedBuffer.h @@ -81,18 +81,6 @@ public: : mDidSelfCopy(false) { } - struct DrawIterator { - friend class RotatedBuffer; - DrawIterator() - : mCount(0) - {} - - nsIntRegion mDrawRegion; - - private: - uint32_t mCount; - }; - /* * Which buffer should be drawn to/read from. */ @@ -101,8 +89,12 @@ public: BUFFER_WHITE, // The buffer with white background, only valid with component alpha. BUFFER_BOTH // The combined black/white buffers, only valid for writing operations, not reading. }; - // It is the callers repsonsibility to ensure aTarget is flushed after calling - // this method. + + /** + * 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, ContextSource aSource, float aOpacity = 1.0, gfx::CompositionOp aOperator = gfx::CompositionOp::OP_OVER, @@ -121,47 +113,28 @@ public: gfx::SourceSurface* aMask, const gfx::Matrix* aMaskTransform); + /** + * Update the specified region of this rotated buffer with the contents + * of a source rotated buffer. + */ void UpdateDestinationFrom(const RotatedBuffer& aSource, const nsIntRegion& aUpdateRegion); /** - * Adjusts the buffer to be centered on the destination buffer rect, - * and ready to draw the specified bounds. Returns whether a new buffer - * needs to be created. + * A draw iterator is used to keep track of which quadrant of a rotated + * buffer and region of that quadrant is being updated. */ - bool AdjustTo(const gfx::IntRect& aDestBufferRect, - const gfx::IntRect& aDrawBounds, - bool aCanHaveRotation, - bool aCanDrawRotated); + struct DrawIterator { + friend class RotatedBuffer; + DrawIterator() + : mCount(0) + {} - /** - * |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; } + nsIntRegion mDrawRegion; - void SetBufferRect(const gfx::IntRect& aBufferRect) { - mBufferRect = aBufferRect; - } - void SetBufferRotation(const gfx::IntPoint& aBufferRotation) { - mBufferRotation = aBufferRotation; - } - - bool DidSelfCopy() const { return mDidSelfCopy; } - void ClearDidSelfCopy() { mDidSelfCopy = false; } - - virtual gfx::SurfaceFormat GetFormat() const = 0; - - virtual bool HaveBuffer() const = 0; - virtual bool HaveBufferOnWhite() const = 0; - - virtual bool IsLocked() = 0; - virtual bool Lock(OpenMode aMode) = 0; - virtual void Unlock() = 0; - - virtual already_AddRefed GetSourceSurface(ContextSource aSource) const = 0; + private: + uint32_t mCount; + }; /** * Get a draw target at the specified resolution for updating |aBounds|, @@ -184,6 +157,63 @@ public: bool aSetTransform = true, gfx::Matrix* aOutTransform = nullptr); + /** + * Adjusts the buffer to be centered on the destination buffer rect, + * and ready to draw the specified bounds. Returns whether a new buffer + * needs to be created. + */ + bool AdjustTo(const gfx::IntRect& aDestBufferRect, + const gfx::IntRect& aDrawBounds, + bool aCanHaveRotation, + bool aCanDrawRotated); + + /** + * |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; } + + 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 GetSourceSurface(ContextSource aSource) const = 0; + virtual gfx::DrawTarget* GetDTBuffer() const = 0; virtual gfx::DrawTarget* GetDTBufferOnWhite() const = 0; @@ -213,7 +243,7 @@ protected: const gfx::Matrix* aMaskTransform) const; /** The area of the PaintedLayer that is covered by the buffer as a whole */ - gfx::IntRect mBufferRect; + gfx::IntRect mBufferRect; /** * The x and y rotation of the buffer. Conceptually the buffer * has its origin translated to mBufferRect.TopLeft() - mBufferRotation, @@ -224,10 +254,12 @@ protected: * 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; + 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; }; class RemoteRotatedBuffer : public RotatedBuffer @@ -245,22 +277,21 @@ public: virtual bool Lock(OpenMode aMode) override; virtual void Unlock() override; - void SyncWithObject(SyncObjectClient* aSyncObject); - void Clear(); + virtual bool HaveBuffer() const override { return !!mClient; } + virtual bool HaveBufferOnWhite() const override { return !!mClientOnWhite; } + + virtual gfx::SurfaceFormat GetFormat() const override; + + virtual already_AddRefed GetSourceSurface(ContextSource aSource) const override; + + virtual gfx::DrawTarget* GetDTBuffer() const override; + virtual gfx::DrawTarget* GetDTBufferOnWhite() const override; TextureClient* GetClient() const { return mClient; } TextureClient* GetClientOnWhite() const { return mClientOnWhite; } - virtual gfx::SurfaceFormat GetFormat() const override; - - virtual bool HaveBuffer() const override { return !!mClient; } - virtual bool HaveBufferOnWhite() const override { return !!mClientOnWhite; } - - virtual already_AddRefed GetSourceSurface(ContextSource aSource) const override; - -protected: - virtual gfx::DrawTarget* GetDTBuffer() const override; - virtual gfx::DrawTarget* GetDTBufferOnWhite() const override; + void SyncWithObject(SyncObjectClient* aSyncObject); + void Clear(); private: RefPtr mClient; @@ -285,14 +316,13 @@ public: virtual bool Lock(OpenMode aMode) override { return true; } virtual void Unlock() override {} - virtual gfx::SurfaceFormat GetFormat() const override; - virtual bool HaveBuffer() const override { return !!mTarget; } virtual bool HaveBufferOnWhite() const override { return !!mTargetOnWhite; } + virtual gfx::SurfaceFormat GetFormat() const override; + virtual already_AddRefed GetSourceSurface(ContextSource aSource) const override; -protected: virtual gfx::DrawTarget* GetDTBuffer() const override; virtual gfx::DrawTarget* GetDTBufferOnWhite() const override; @@ -323,7 +353,6 @@ public: virtual bool HaveBuffer() const { return !!mSource; } virtual bool HaveBufferOnWhite() const { return !!mSourceOnWhite; } -protected: virtual gfx::DrawTarget* GetDTBuffer() const { return nullptr; } virtual gfx::DrawTarget* GetDTBufferOnWhite() const { return nullptr; }