diff --git a/gfx/layers/opengl/LayerManagerOGL.h b/gfx/layers/opengl/LayerManagerOGL.h index 4a54edf87a09..4bba11eca6dd 100644 --- a/gfx/layers/opengl/LayerManagerOGL.h +++ b/gfx/layers/opengl/LayerManagerOGL.h @@ -10,6 +10,7 @@ #include "mozilla/layers/ShadowLayers.h" #include "mozilla/TimeStamp.h" +#include "nsPoint.h" #ifdef XP_WIN #include @@ -435,12 +436,20 @@ enum LayerRenderStateFlags { }; struct LayerRenderState { - LayerRenderState() : mSurface(nullptr), mFlags(0) + LayerRenderState() : mSurface(nullptr), mFlags(0), mHasOwnOffset(false) {} LayerRenderState(SurfaceDescriptor* aSurface, uint32_t aFlags = 0) : mSurface(aSurface) , mFlags(aFlags) + , mHasOwnOffset(false) + {} + + LayerRenderState(SurfaceDescriptor* aSurface, nsIntPoint aOffset, uint32_t aFlags = 0) + : mSurface(aSurface) + , mFlags(aFlags) + , mOffset(aOffset) + , mHasOwnOffset(true) {} bool YFlipped() const @@ -451,6 +460,8 @@ struct LayerRenderState { SurfaceDescriptor* mSurface; uint32_t mFlags; + nsIntPoint mOffset; + bool mHasOwnOffset; }; /** diff --git a/gfx/layers/opengl/ThebesLayerOGL.cpp b/gfx/layers/opengl/ThebesLayerOGL.cpp index 5147120ee80c..432ada089aac 100644 --- a/gfx/layers/opengl/ThebesLayerOGL.cpp +++ b/gfx/layers/opengl/ThebesLayerOGL.cpp @@ -98,8 +98,8 @@ public: bool Initialised() { return mInitialised; } -protected: virtual nsIntPoint GetOriginOffset() = 0; +protected: GLContext* gl() const { return mOGLLayer->gl(); } @@ -343,7 +343,6 @@ public: return mTexImage ? mTexImage->GetBackingSurface() : nullptr; } -protected: virtual nsIntPoint GetOriginOffset() { return BufferRect().TopLeft() - BufferRotation(); } @@ -366,6 +365,10 @@ public: virtual PaintState BeginPaint(ContentType aContentType, uint32_t aFlags); + virtual nsIntPoint GetOriginOffset() { + return mBufferRect.TopLeft() - mBufferRotation; + } + protected: enum XSide { @@ -376,10 +379,6 @@ protected: }; nsIntRect GetQuadrantRectangle(XSide aXSide, YSide aYSide); - virtual nsIntPoint GetOriginOffset() { - return mBufferRect.TopLeft() - mBufferRotation; - } - private: nsIntRect mBufferRect; nsIntPoint mBufferRotation; @@ -947,7 +946,6 @@ public: return mBufferRotation; } -protected: virtual nsIntPoint GetOriginOffset() { return mBufferRect.TopLeft() - mBufferRotation; } @@ -1156,7 +1154,7 @@ ShadowThebesLayerOGL::GetRenderState() } uint32_t flags = (mBuffer->Rotation() != nsIntPoint()) ? LAYER_RENDER_STATE_BUFFER_ROTATION : 0; - return LayerRenderState(&mBufferDescriptor, flags); + return LayerRenderState(&mBufferDescriptor, mBuffer->GetOriginOffset(), flags); } bool diff --git a/widget/gonk/HwcComposer2D.cpp b/widget/gonk/HwcComposer2D.cpp index 3d9e9ee75b64..4d08cfa903f2 100644 --- a/widget/gonk/HwcComposer2D.cpp +++ b/widget/gonk/HwcComposer2D.cpp @@ -174,13 +174,13 @@ HwcComposer2D::GetRotation() * Sets hwc layer rectangles required for hwc composition * * @param aVisible Input. Layer's unclipped visible rectangle - * The origin is the layer's buffer + * The origin is the top-left corner of the layer * @param aTransform Input. Layer's transformation matrix * It transforms from layer space to screen space * @param aClip Input. A clipping rectangle. * The origin is the top-left corner of the screen * @param aBufferRect Input. The layer's buffer bounds - * The origin is the buffer itself and hence always (0,0) + * The origin is the top-left corner of the layer * @param aSurceCrop Output. Area of the source to consider, * the origin is the top-left corner of the buffer * @param aVisibleRegionScreen Output. Visible region in screen space. @@ -207,9 +207,7 @@ PrepareLayerRects(nsIntRect aVisible, const gfxMatrix& aTransform, gfxMatrix inverse(aTransform); inverse.Invert(); gfxRect crop = inverse.TransformBounds(visibleRectScreen); - // Map to buffer space - crop -= visibleRect.TopLeft(); - gfxRect bufferRect(aBufferRect); + //clip to buffer size crop.IntersectRect(crop, aBufferRect); crop.RoundOut(); @@ -219,11 +217,13 @@ PrepareLayerRects(nsIntRect aVisible, const gfxMatrix& aTransform, return false; } - //propagate buffer clipping back to visible rect - visibleRectScreen = aTransform.TransformBounds(crop + visibleRect.TopLeft()); + visibleRectScreen = aTransform.TransformBounds(crop); visibleRectScreen.RoundOut(); + // Map from layer space to buffer space + crop -= aBufferRect.TopLeft(); + aSourceCrop->left = crop.x; aSourceCrop->top = crop.y; aSourceCrop->right = crop.x + crop.width; @@ -326,11 +326,15 @@ HwcComposer2D::PrepareLayerList(Layer* aLayer, nsIntRect bufferRect; if (fillColor) { - bufferRect = nsIntRect(0, 0, visibleRect.width, - visibleRect.height); + bufferRect = nsIntRect(visibleRect); } else { - bufferRect = nsIntRect(0, 0, int(buffer->getWidth()), - int(buffer->getHeight())); + if(state.mHasOwnOffset) { + bufferRect = nsIntRect(state.mOffset.x, state.mOffset.y, + int(buffer->getWidth()), int(buffer->getHeight())); + } else { + bufferRect = nsIntRect(visibleRect.x, visibleRect.y, + int(buffer->getWidth()), int(buffer->getHeight())); + } } hwc_layer_t& hwcLayer = mList->hwLayers[current];