зеркало из https://github.com/mozilla/pjs.git
Bug 564991. Part 6: Make BasicLayers support retained ThebesLayer contents. r=cjones,sr=vlad
This commit is contained in:
Родитель
561fe4b742
Коммит
678aafc9f4
|
@ -1669,6 +1669,7 @@ NS_IMETHODIMP nsWebBrowser::EnsureDocShellTreeOwner()
|
|||
static void DrawThebesLayer(ThebesLayer* aLayer,
|
||||
gfxContext* aContext,
|
||||
const nsIntRegion& aRegionToDraw,
|
||||
const nsIntRegion& aRegionToInvalidate,
|
||||
void* aCallbackData)
|
||||
{
|
||||
nscolor* color = static_cast<nscolor*>(aCallbackData);
|
||||
|
|
|
@ -156,10 +156,17 @@ public:
|
|||
/**
|
||||
* Function called to draw the contents of each ThebesLayer.
|
||||
* aRegionToDraw contains the region that needs to be drawn.
|
||||
* This would normally be a subregion of the visible region. Drawing is
|
||||
* not necessarily clipped to aRegionToDraw.
|
||||
* This would normally be a subregion of the visible region.
|
||||
* The callee must draw all of aRegionToDraw. Drawing outside
|
||||
* aRegionToDraw will be clipped out or ignored.
|
||||
* The callee must draw all of aRegionToDraw.
|
||||
*
|
||||
* aRegionToInvalidate contains a region whose contents have been
|
||||
* changed by the layer manager and which must therefore be invalidated.
|
||||
* For example, this could be non-empty if the layer internally switched
|
||||
* from RGBA to RGB or back ... we might want to repaint it to
|
||||
* consistently use subpixel-AA or not.
|
||||
*
|
||||
* aContext must not be used after the call has returned.
|
||||
* We guarantee that buffered contents in the visible
|
||||
* region are valid once drawing is complete.
|
||||
|
@ -167,6 +174,7 @@ public:
|
|||
typedef void (* DrawThebesLayerCallback)(ThebesLayer* aLayer,
|
||||
gfxContext* aContext,
|
||||
const nsIntRegion& aRegionToDraw,
|
||||
const nsIntRegion& aRegionToInvalidate,
|
||||
void* aCallbackData);
|
||||
/**
|
||||
* Finish the construction phase of the transaction, perform the
|
||||
|
|
|
@ -68,14 +68,15 @@ EXPORTS = \
|
|||
CPPSRCS = \
|
||||
BasicImages.cpp \
|
||||
BasicLayers.cpp \
|
||||
LayerManagerOGL.cpp \
|
||||
ThebesLayerBuffer.cpp \
|
||||
CanvasLayerOGL.cpp \
|
||||
ColorLayerOGL.cpp \
|
||||
ThebesLayerOGL.cpp \
|
||||
ContainerLayerOGL.cpp \
|
||||
ImageLayerOGL.cpp \
|
||||
CanvasLayerOGL.cpp \
|
||||
LayerManagerOGL.cpp \
|
||||
ThebesLayerOGL.cpp \
|
||||
$(NULL)
|
||||
|
||||
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
|
||||
ifdef MOZ_ENABLE_D3D9_LAYER
|
||||
EXPORTS += LayerManagerD3D9.h
|
||||
|
|
|
@ -44,7 +44,9 @@
|
|||
#include "gfxContext.h"
|
||||
#include "gfxImageSurface.h"
|
||||
#include "gfxPattern.h"
|
||||
#include "gfxPlatform.h"
|
||||
#include "gfxUtils.h"
|
||||
#include "ThebesLayerBuffer.h"
|
||||
|
||||
#include "GLContext.h"
|
||||
|
||||
|
@ -210,12 +212,28 @@ BasicContainerLayer::RemoveChildInternal(Layer* aChild)
|
|||
NS_RELEASE(aChild);
|
||||
}
|
||||
|
||||
/**
|
||||
* BasicThebesLayer does not currently retain any buffers. This
|
||||
* makes the implementation fairly simple. During a transaction the
|
||||
* valid region is just the visible region, and between transactions
|
||||
* the valid region is empty.
|
||||
*/
|
||||
// Returns true if it's OK to save the contents of aLayer in an
|
||||
// opaque surface (a surface without an alpha channel).
|
||||
// If we can use a surface without an alpha channel, we should, because
|
||||
// it will often make painting of antialiased text faster and higher
|
||||
// quality.
|
||||
static PRBool
|
||||
UseOpaqueSurface(Layer* aLayer)
|
||||
{
|
||||
// If the visible content in the layer is opaque, there is no need
|
||||
// for an alpha channel.
|
||||
if (aLayer->IsOpaqueContent())
|
||||
return PR_TRUE;
|
||||
// Also, if this layer is the bottommost layer in a container which
|
||||
// doesn't need an alpha channel, we can use an opaque surface for this
|
||||
// layer too. Any transparent areas must be covered by something else
|
||||
// in the container.
|
||||
BasicContainerLayer* parent =
|
||||
static_cast<BasicContainerLayer*>(aLayer->GetParent());
|
||||
return parent && parent->GetFirstChild() == aLayer &&
|
||||
UseOpaqueSurface(parent);
|
||||
}
|
||||
|
||||
class BasicThebesLayer : public ThebesLayer, BasicImplData {
|
||||
public:
|
||||
BasicThebesLayer(BasicLayerManager* aLayerManager) :
|
||||
|
@ -238,6 +256,7 @@ public:
|
|||
{
|
||||
NS_ASSERTION(BasicManager()->InConstruction(),
|
||||
"Can only set properties in construction phase");
|
||||
mValidRegion.Sub(mValidRegion, aRegion);
|
||||
}
|
||||
|
||||
virtual void Paint(gfxContext* aContext,
|
||||
|
@ -249,6 +268,8 @@ protected:
|
|||
{
|
||||
return static_cast<BasicLayerManager*>(mManager);
|
||||
}
|
||||
|
||||
ThebesLayerBuffer mBuffer;
|
||||
};
|
||||
|
||||
void
|
||||
|
@ -261,7 +282,40 @@ BasicThebesLayer::Paint(gfxContext* aContext,
|
|||
gfxContext* target = BasicManager()->GetTarget();
|
||||
NS_ASSERTION(target, "We shouldn't be called if there's no target");
|
||||
|
||||
aCallback(this, target, mVisibleRegion, aCallbackData);
|
||||
if (!BasicManager()->IsRetained()) {
|
||||
mValidRegion.SetEmpty();
|
||||
mBuffer.Clear();
|
||||
aCallback(this, target, mVisibleRegion, nsIntRegion(), aCallbackData);
|
||||
return;
|
||||
}
|
||||
|
||||
PRUint32 flags = 0;
|
||||
if (UseOpaqueSurface(this)) {
|
||||
flags |= ThebesLayerBuffer::OPAQUE_CONTENT;
|
||||
}
|
||||
|
||||
{
|
||||
ThebesLayerBuffer::PaintState state =
|
||||
mBuffer.BeginPaint(this, aContext, flags);
|
||||
mValidRegion.Sub(mValidRegion, state.mRegionToInvalidate);
|
||||
|
||||
if (state.mContext) {
|
||||
// The area that became invalid and is visible needs to be repainted
|
||||
// (this could be the whole visible area if our buffer switched
|
||||
// from RGB to RGBA, because we might need to repaint with
|
||||
// subpixel AA)
|
||||
state.mRegionToInvalidate.And(state.mRegionToInvalidate, mVisibleRegion);
|
||||
aCallback(this, state.mContext, state.mRegionToDraw,
|
||||
state.mRegionToInvalidate, aCallbackData);
|
||||
mValidRegion.Or(mValidRegion, state.mRegionToDraw);
|
||||
} else {
|
||||
NS_ASSERTION(state.mRegionToDraw.IsEmpty() &&
|
||||
state.mRegionToInvalidate.IsEmpty(),
|
||||
"If we need to draw, we should have a context");
|
||||
}
|
||||
}
|
||||
|
||||
mBuffer.DrawTo(this, flags, target);
|
||||
}
|
||||
|
||||
class BasicImageLayer : public ImageLayer, BasicImplData {
|
||||
|
@ -280,7 +334,7 @@ public:
|
|||
{
|
||||
NS_ASSERTION(BasicManager()->InConstruction(),
|
||||
"Can only set properties in construction phase");
|
||||
mVisibleRegion = aRegion;
|
||||
ImageLayer::SetVisibleRegion(aRegion);
|
||||
}
|
||||
|
||||
virtual void Paint(gfxContext* aContext,
|
||||
|
@ -354,7 +408,7 @@ public:
|
|||
{
|
||||
NS_ASSERTION(BasicManager()->InConstruction(),
|
||||
"Can only set properties in construction phase");
|
||||
mVisibleRegion = aRegion;
|
||||
ColorLayer::SetVisibleRegion(aRegion);
|
||||
}
|
||||
|
||||
virtual void Paint(gfxContext* aContext,
|
||||
|
@ -521,28 +575,37 @@ BasicLayerManager::BasicLayerManager(gfxContext* aContext) :
|
|||
#ifdef DEBUG
|
||||
, mPhase(PHASE_NONE)
|
||||
#endif
|
||||
, mRetain(PR_FALSE)
|
||||
{
|
||||
MOZ_COUNT_CTOR(BasicLayerManager);
|
||||
}
|
||||
|
||||
BasicLayerManager::~BasicLayerManager()
|
||||
{
|
||||
NS_ASSERTION(mPhase == PHASE_NONE, "Died during transaction?");
|
||||
NS_ASSERTION(!InTransaction(), "Died during transaction?");
|
||||
MOZ_COUNT_DTOR(BasicLayerManager);
|
||||
}
|
||||
|
||||
void
|
||||
BasicLayerManager::SetDefaultTarget(gfxContext* aContext)
|
||||
{
|
||||
NS_ASSERTION(mPhase == PHASE_NONE,
|
||||
NS_ASSERTION(!InTransaction(),
|
||||
"Must set default target outside transaction");
|
||||
mDefaultTarget = aContext;
|
||||
}
|
||||
|
||||
void
|
||||
BasicLayerManager::SetRetain(PRBool aRetain)
|
||||
{
|
||||
NS_ASSERTION(!InTransaction(),
|
||||
"Must set retained mode outside transaction");
|
||||
mRetain = aRetain;
|
||||
}
|
||||
|
||||
void
|
||||
BasicLayerManager::BeginTransaction()
|
||||
{
|
||||
NS_ASSERTION(mPhase == PHASE_NONE, "Nested transactions not allowed");
|
||||
NS_ASSERTION(!InTransaction(), "Nested transactions not allowed");
|
||||
#ifdef DEBUG
|
||||
mPhase = PHASE_CONSTRUCTION;
|
||||
#endif
|
||||
|
@ -552,7 +615,7 @@ BasicLayerManager::BeginTransaction()
|
|||
void
|
||||
BasicLayerManager::BeginTransactionWithTarget(gfxContext* aTarget)
|
||||
{
|
||||
NS_ASSERTION(mPhase == PHASE_NONE, "Nested transactions not allowed");
|
||||
NS_ASSERTION(!InTransaction(), "Nested transactions not allowed");
|
||||
#ifdef DEBUG
|
||||
mPhase = PHASE_CONSTRUCTION;
|
||||
#endif
|
||||
|
@ -564,7 +627,7 @@ BasicLayerManager::EndTransaction(DrawThebesLayerCallback aCallback,
|
|||
void* aCallbackData)
|
||||
{
|
||||
NS_ASSERTION(mRoot, "Root not set");
|
||||
NS_ASSERTION(mPhase == PHASE_CONSTRUCTION, "Should be in construction phase");
|
||||
NS_ASSERTION(InConstruction(), "Should be in construction phase");
|
||||
#ifdef DEBUG
|
||||
mPhase = PHASE_DRAWING;
|
||||
#endif
|
||||
|
@ -577,8 +640,6 @@ BasicLayerManager::EndTransaction(DrawThebesLayerCallback aCallback,
|
|||
#ifdef DEBUG
|
||||
mPhase = PHASE_NONE;
|
||||
#endif
|
||||
// No retained layers supported for now
|
||||
mRoot = nsnull;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -607,28 +668,6 @@ NeedsState(Layer* aLayer)
|
|||
!aLayer->GetTransform().IsIdentity();
|
||||
}
|
||||
|
||||
// Returns true if it's OK to save the contents of aLayer in an
|
||||
// opaque surface (a surface without an alpha channel).
|
||||
// If we can use a surface without an alpha channel, we should, because
|
||||
// it will often make painting of antialiased text faster and higher
|
||||
// quality.
|
||||
static PRBool
|
||||
UseOpaqueSurface(Layer* aLayer)
|
||||
{
|
||||
// If the visible content in the layer is opaque, there is no need
|
||||
// for an alpha channel.
|
||||
if (aLayer->IsOpaqueContent())
|
||||
return PR_TRUE;
|
||||
// Also, if this layer is the bottommost layer in a container which
|
||||
// doesn't need an alpha channel, we can use an opaque surface for this
|
||||
// layer too. Any transparent areas must be covered by something else
|
||||
// in the container.
|
||||
BasicContainerLayer* parent =
|
||||
static_cast<BasicContainerLayer*>(aLayer->GetParent());
|
||||
return parent && parent->GetFirstChild() == aLayer &&
|
||||
UseOpaqueSurface(parent);
|
||||
}
|
||||
|
||||
void
|
||||
BasicLayerManager::PaintLayer(Layer* aLayer,
|
||||
DrawThebesLayerCallback aCallback,
|
||||
|
|
|
@ -51,9 +51,6 @@ class BasicThebesLayer;
|
|||
|
||||
/**
|
||||
* This is a cairo/Thebes-only, main-thread-only implementation of layers.
|
||||
* Currently it only supports immediate mode but we will probably
|
||||
* extend it to support retained buffers. In other words, currently,
|
||||
* no buffers are retained between transactions.
|
||||
*
|
||||
* In each transaction, the client sets up the layer tree and then during
|
||||
* the drawing phase, each ThebesLayer is painted directly into the target
|
||||
|
@ -70,6 +67,13 @@ public:
|
|||
BasicLayerManager(gfxContext* aContext);
|
||||
virtual ~BasicLayerManager();
|
||||
|
||||
/**
|
||||
* When aRetain is true, we will try to retain the visible contents of
|
||||
* ThebesLayers as cairo surfaces. This can only be called outside a
|
||||
* transaction.
|
||||
*/
|
||||
void SetRetain(PRBool aRetain);
|
||||
|
||||
/**
|
||||
* Set the default target context that will be used when BeginTransaction
|
||||
* is called. This can only be called outside a transaction.
|
||||
|
@ -94,8 +98,10 @@ public:
|
|||
#ifdef DEBUG
|
||||
PRBool InConstruction() { return mPhase == PHASE_CONSTRUCTION; }
|
||||
PRBool InDrawing() { return mPhase == PHASE_DRAWING; }
|
||||
PRBool InTransaction() { return mPhase != PHASE_NONE; }
|
||||
#endif
|
||||
gfxContext* GetTarget() { return mTarget; }
|
||||
PRBool IsRetained() { return mRetain; }
|
||||
|
||||
private:
|
||||
// Paints aLayer to mTarget.
|
||||
|
@ -112,6 +118,8 @@ private:
|
|||
enum TransactionPhase { PHASE_NONE, PHASE_CONSTRUCTION, PHASE_DRAWING };
|
||||
TransactionPhase mPhase;
|
||||
#endif
|
||||
|
||||
PRPackedBool mRetain;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,264 @@
|
|||
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Corporation code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mozilla Foundation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Robert O'Callahan <robert@ocallahan.org>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "ThebesLayerBuffer.h"
|
||||
#include "Layers.h"
|
||||
#include "gfxContext.h"
|
||||
#include "gfxPlatform.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace layers {
|
||||
|
||||
static void
|
||||
ClipToRegion(gfxContext* aContext, const nsIntRegion& aRegion)
|
||||
{
|
||||
aContext->NewPath();
|
||||
nsIntRegionRectIterator iter(aRegion);
|
||||
const nsIntRect* r;
|
||||
while ((r = iter.Next()) != nsnull) {
|
||||
aContext->Rectangle(gfxRect(r->x, r->y, r->width, r->height));
|
||||
}
|
||||
aContext->Clip();
|
||||
}
|
||||
|
||||
nsIntRect
|
||||
ThebesLayerBuffer::GetQuadrantRectangle(XSide aXSide, YSide aYSide)
|
||||
{
|
||||
// quadrantTranslation is the amount we translate the top-left
|
||||
// of the quadrant by to get coordinates relative to the layer
|
||||
nsIntPoint quadrantTranslation = -mBufferRotation;
|
||||
quadrantTranslation.x += aXSide == LEFT ? mBufferRect.width : 0;
|
||||
quadrantTranslation.y += aYSide == TOP ? mBufferRect.height : 0;
|
||||
return mBufferRect + quadrantTranslation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
ThebesLayerBuffer::DrawBufferQuadrant(gfxContext* aTarget,
|
||||
XSide aXSide, YSide aYSide)
|
||||
{
|
||||
// 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
|
||||
nsIntRect quadrantRect = GetQuadrantRectangle(aXSide, aYSide);
|
||||
nsIntRect fillRect;
|
||||
if (!fillRect.IntersectRect(mBufferRect, quadrantRect))
|
||||
return;
|
||||
|
||||
aTarget->NewPath();
|
||||
aTarget->Rectangle(gfxRect(fillRect.x, fillRect.y, fillRect.width, fillRect.height),
|
||||
PR_TRUE);
|
||||
aTarget->SetSource(mBuffer, gfxPoint(quadrantRect.x, quadrantRect.y));
|
||||
aTarget->Fill();
|
||||
}
|
||||
|
||||
void
|
||||
ThebesLayerBuffer::DrawBufferWithRotation(gfxContext* aTarget)
|
||||
{
|
||||
// Draw four quadrants. We could use REPEAT_, but it's probably better
|
||||
// not to, to be performance-safe.
|
||||
DrawBufferQuadrant(aTarget, LEFT, TOP);
|
||||
DrawBufferQuadrant(aTarget, RIGHT, TOP);
|
||||
DrawBufferQuadrant(aTarget, LEFT, BOTTOM);
|
||||
DrawBufferQuadrant(aTarget, RIGHT, BOTTOM);
|
||||
}
|
||||
|
||||
static void
|
||||
WrapRotationAxis(PRInt32* aRotationPoint, PRInt32 aSize)
|
||||
{
|
||||
if (*aRotationPoint < 0) {
|
||||
*aRotationPoint += aSize;
|
||||
} else if (*aRotationPoint >= aSize) {
|
||||
*aRotationPoint -= aSize;
|
||||
}
|
||||
}
|
||||
|
||||
static already_AddRefed<gfxASurface>
|
||||
CreateBuffer(gfxASurface* aTargetSurface, gfxASurface::gfxContentType aType,
|
||||
const nsIntSize& aSize)
|
||||
{
|
||||
return aTargetSurface->CreateSimilarSurface(aType, gfxIntSize(aSize.width, aSize.height));
|
||||
}
|
||||
|
||||
ThebesLayerBuffer::PaintState
|
||||
ThebesLayerBuffer::BeginPaint(ThebesLayer* aLayer, gfxContext* aTarget,
|
||||
PRUint32 aFlags)
|
||||
{
|
||||
PaintState result;
|
||||
|
||||
gfxASurface::gfxContentType desiredContentType = gfxASurface::CONTENT_COLOR_ALPHA;
|
||||
nsRefPtr<gfxASurface> targetSurface = aTarget->CurrentSurface();
|
||||
if (targetSurface->AreSimilarSurfacesSensitiveToContentType()) {
|
||||
if (aFlags & OPAQUE_CONTENT) {
|
||||
desiredContentType = gfxASurface::CONTENT_COLOR;
|
||||
}
|
||||
if (mBuffer && desiredContentType != mBuffer->GetContentType()) {
|
||||
result.mRegionToInvalidate = aLayer->GetValidRegion();
|
||||
Clear();
|
||||
}
|
||||
}
|
||||
|
||||
result.mRegionToDraw.Sub(aLayer->GetVisibleRegion(), aLayer->GetValidRegion());
|
||||
if (result.mRegionToDraw.IsEmpty())
|
||||
return result;
|
||||
nsIntRect drawBounds = result.mRegionToDraw.GetBounds();
|
||||
|
||||
nsIntRect visibleBounds = aLayer->GetVisibleRegion().GetBounds();
|
||||
nsRefPtr<gfxASurface> destBuffer;
|
||||
nsIntRect destBufferRect;
|
||||
|
||||
if (mBufferRect.width >= visibleBounds.width &&
|
||||
mBufferRect.height >= visibleBounds.height) {
|
||||
// The current buffer is big enough to hold the visible area.
|
||||
if (mBufferRect.Contains(visibleBounds)) {
|
||||
// We don't need to adjust mBufferRect.
|
||||
destBufferRect = mBufferRect;
|
||||
} else {
|
||||
// The buffer's big enough but doesn't contain everything that's
|
||||
// going to be visible. We'll move it.
|
||||
destBufferRect = nsIntRect(visibleBounds.TopLeft(), mBufferRect.Size());
|
||||
}
|
||||
nsIntRect keepArea;
|
||||
if (keepArea.IntersectRect(destBufferRect, mBufferRect)) {
|
||||
// Set mBufferRotation so that the pixels currently in mBuffer
|
||||
// will still be rendered in the right place when mBufferRect
|
||||
// changes to destBufferRect.
|
||||
nsIntPoint newRotation = mBufferRotation +
|
||||
(destBufferRect.TopLeft() - mBufferRect.TopLeft());
|
||||
WrapRotationAxis(&newRotation.x, mBufferRect.width);
|
||||
WrapRotationAxis(&newRotation.y, mBufferRect.height);
|
||||
NS_ASSERTION(nsIntRect(nsIntPoint(0,0), mBufferRect.Size()).Contains(newRotation),
|
||||
"newRotation out of bounds");
|
||||
PRInt32 xBoundary = destBufferRect.XMost() - newRotation.x;
|
||||
PRInt32 yBoundary = destBufferRect.YMost() - newRotation.y;
|
||||
if ((drawBounds.x < xBoundary && xBoundary < drawBounds.XMost()) ||
|
||||
(drawBounds.y < yBoundary && yBoundary < drawBounds.YMost())) {
|
||||
// The stuff we need to redraw will wrap around an edge of the
|
||||
// buffer, so we will need to do a self-copy
|
||||
if (mBufferRotation == nsIntPoint(0,0)) {
|
||||
destBuffer = mBuffer;
|
||||
} else {
|
||||
// We can't do a real self-copy because the buffer is rotated.
|
||||
// So allocate a new buffer for the destination.
|
||||
destBufferRect = visibleBounds;
|
||||
destBuffer = CreateBuffer(targetSurface, desiredContentType, destBufferRect.Size());
|
||||
if (!destBuffer)
|
||||
return result;
|
||||
}
|
||||
} else {
|
||||
mBufferRect = destBufferRect;
|
||||
mBufferRotation = newRotation;
|
||||
}
|
||||
} else {
|
||||
// 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.
|
||||
mBufferRect = destBufferRect;
|
||||
mBufferRotation = nsIntPoint(0,0);
|
||||
}
|
||||
} else {
|
||||
// The buffer's not big enough, so allocate a new one
|
||||
destBufferRect = visibleBounds;
|
||||
destBuffer = CreateBuffer(targetSurface, desiredContentType, destBufferRect.Size());
|
||||
if (!destBuffer)
|
||||
return result;
|
||||
}
|
||||
|
||||
if (destBuffer) {
|
||||
if (mBuffer) {
|
||||
// Copy the bits
|
||||
nsRefPtr<gfxContext> tmpCtx = new gfxContext(destBuffer);
|
||||
nsIntPoint offset = -destBufferRect.TopLeft();
|
||||
tmpCtx->SetOperator(gfxContext::OPERATOR_SOURCE);
|
||||
tmpCtx->Translate(gfxPoint(offset.x, offset.y));
|
||||
DrawBufferWithRotation(tmpCtx);
|
||||
}
|
||||
|
||||
mBuffer = destBuffer.forget();
|
||||
mBufferRect = destBufferRect;
|
||||
mBufferRotation = nsIntPoint(0,0);
|
||||
}
|
||||
|
||||
nsIntRegion invalidate;
|
||||
invalidate.Sub(aLayer->GetValidRegion(), destBufferRect);
|
||||
result.mRegionToInvalidate.Or(result.mRegionToInvalidate, invalidate);
|
||||
|
||||
result.mContext = new gfxContext(mBuffer);
|
||||
|
||||
// Figure out which quadrant to draw in
|
||||
PRInt32 xBoundary = mBufferRect.XMost() - mBufferRotation.x;
|
||||
PRInt32 yBoundary = mBufferRect.YMost() - mBufferRotation.y;
|
||||
XSide sideX = drawBounds.XMost() <= xBoundary ? RIGHT : LEFT;
|
||||
YSide sideY = drawBounds.YMost() <= yBoundary ? BOTTOM : TOP;
|
||||
nsIntRect quadrantRect = GetQuadrantRectangle(sideX, sideY);
|
||||
NS_ASSERTION(quadrantRect.Contains(drawBounds), "Messed up quadrants");
|
||||
result.mContext->Translate(-gfxPoint(quadrantRect.x, quadrantRect.y));
|
||||
|
||||
ClipToRegion(result.mContext, result.mRegionToDraw);
|
||||
if (desiredContentType == gfxASurface::CONTENT_COLOR_ALPHA) {
|
||||
result.mContext->SetOperator(gfxContext::OPERATOR_CLEAR);
|
||||
result.mContext->Paint();
|
||||
result.mContext->SetOperator(gfxContext::OPERATOR_OVER);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
ThebesLayerBuffer::DrawTo(ThebesLayer* aLayer, PRUint32 aFlags, gfxContext* aTarget)
|
||||
{
|
||||
aTarget->Save();
|
||||
ClipToRegion(aTarget, aLayer->GetVisibleRegion());
|
||||
if (aFlags & OPAQUE_CONTENT) {
|
||||
aTarget->SetOperator(gfxContext::OPERATOR_SOURCE);
|
||||
}
|
||||
DrawBufferWithRotation(aTarget);
|
||||
aTarget->Restore();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,156 @@
|
|||
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Mozilla Corporation code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mozilla Foundation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Robert O'Callahan <robert@ocallahan.org>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef THEBESLAYERBUFFER_H_
|
||||
#define THEBESLAYERBUFFER_H_
|
||||
|
||||
#include "gfxContext.h"
|
||||
#include "gfxASurface.h"
|
||||
#include "nsRegion.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace layers {
|
||||
|
||||
class ThebesLayer;
|
||||
|
||||
/**
|
||||
* This class encapsulates the buffer used to retain ThebesLayer contents,
|
||||
* i.e., the contents of the layer's GetVisibleRegion().
|
||||
*
|
||||
* 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 ThebesLayerBuffer {
|
||||
public:
|
||||
ThebesLayerBuffer() : mBufferRotation(0,0)
|
||||
{
|
||||
MOZ_COUNT_CTOR(ThebesLayerBuffer);
|
||||
}
|
||||
~ThebesLayerBuffer()
|
||||
{
|
||||
MOZ_COUNT_DTOR(ThebesLayerBuffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wipe out all retained contents. Call this when the entire
|
||||
* buffer becomes invalid.
|
||||
*/
|
||||
void Clear()
|
||||
{
|
||||
mBuffer = nsnull;
|
||||
mBufferRect.Empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* This is returned by BeginPaint. The caller should draw into mContext.
|
||||
* mRegionToDraw must be drawn. mRegionToInvalidate has been invalidated
|
||||
* by ThebesLayerBuffer and must be redrawn on the screen.
|
||||
* mRegionToInvalidate is set when the buffer has changed from
|
||||
* opaque to transparent or vice versa, since the details of rendering can
|
||||
* depend on the buffer type.
|
||||
*/
|
||||
struct PaintState {
|
||||
nsRefPtr<gfxContext> mContext;
|
||||
nsIntRegion mRegionToDraw;
|
||||
nsIntRegion mRegionToInvalidate;
|
||||
};
|
||||
/**
|
||||
* Pass OPAQUE_CONTENT when we have determined that everything visible
|
||||
* in the buffer will be rendered with opaque pixels.
|
||||
*/
|
||||
enum {
|
||||
OPAQUE_CONTENT = 0x01
|
||||
};
|
||||
/**
|
||||
* Start a drawing operation. Ths returns a PaintState describing what
|
||||
* needs to be drawn to bring the buffer up to date in the visible region.
|
||||
* This queries aLayer to get the currently valid and visible regions.
|
||||
* The returned mContext may be null if mRegionToDraw is empty.
|
||||
* Otherwise it must not be null.
|
||||
* mRegionToInvalidate will contain mRegionToDraw.
|
||||
*/
|
||||
PaintState BeginPaint(ThebesLayer* aLayer, gfxContext* aTarget,
|
||||
PRUint32 aFlags);
|
||||
/**
|
||||
* Complete the drawing operation. The region to draw must have been drawn
|
||||
* before this is called. The contents of the buffer are drawn to aTarget.
|
||||
*/
|
||||
void DrawTo(ThebesLayer* aLayer, PRUint32 aFlags, gfxContext* aTarget);
|
||||
|
||||
protected:
|
||||
enum XSide {
|
||||
LEFT, RIGHT
|
||||
};
|
||||
enum YSide {
|
||||
TOP, BOTTOM
|
||||
};
|
||||
nsIntRect GetQuadrantRectangle(XSide aXSide, YSide aYSide);
|
||||
void DrawBufferQuadrant(gfxContext* aTarget, XSide aXSide, YSide aYSide);
|
||||
void DrawBufferWithRotation(gfxContext* aTarget);
|
||||
|
||||
private:
|
||||
nsRefPtr<gfxASurface> mBuffer;
|
||||
/** The area of the ThebesLayer that is covered by the buffer as a whole */
|
||||
nsIntRect 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!
|
||||
*/
|
||||
nsIntPoint mBufferRotation;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* THEBESLAYERBUFFER_H_ */
|
|
@ -106,7 +106,7 @@ ThebesLayerD3D9::RenderLayer()
|
|||
context = new gfxContext(destinationSurface);
|
||||
context->Translate(gfxPoint(-mInvalidatedRect.x, -mInvalidatedRect.y));
|
||||
LayerManagerD3D9::CallbackInfo cbInfo = mD3DManager->GetCallbackInfo();
|
||||
cbInfo.Callback(this, context, region, cbInfo.CallbackData);
|
||||
cbInfo.Callback(this, context, region, nsIntRegion(), cbInfo.CallbackData);
|
||||
|
||||
nsRefPtr<IDirect3DTexture9> tmpTexture;
|
||||
device()->CreateTexture(mInvalidatedRect.width, mInvalidatedRect.height, 1,
|
||||
|
|
|
@ -184,7 +184,8 @@ public:
|
|||
NS_ASSERTION(mThebesLayerCallback,
|
||||
"CallThebesLayerDrawCallback without callback!");
|
||||
mThebesLayerCallback(aLayer, aContext,
|
||||
aRegionToDraw, mThebesLayerCallbackData);
|
||||
aRegionToDraw, nsIntRegion(),
|
||||
mThebesLayerCallbackData);
|
||||
}
|
||||
|
||||
GLenum FBOTextureTarget() { return mFBOTextureTarget; }
|
||||
|
|
|
@ -475,8 +475,12 @@ FrameLayerBuilder::MakeContainerLayerFor(nsDisplayListBuilder* aBuilder,
|
|||
FrameLayerBuilder::DrawThebesLayer(ThebesLayer* aLayer,
|
||||
gfxContext* aContext,
|
||||
const nsIntRegion& aRegionToDraw,
|
||||
const nsIntRegion& aRegionToInvalidate,
|
||||
void* aCallbackData)
|
||||
{
|
||||
// For now, we can ignore aRegionToInvalidate since we don't
|
||||
// use retained layers.
|
||||
|
||||
LayerItems* layerItems = static_cast<LayerItems*>(aLayer->GetUserData());
|
||||
nsDisplayListBuilder* builder =
|
||||
static_cast<nsDisplayListBuilder*>(aCallbackData);
|
||||
|
|
|
@ -69,6 +69,7 @@ public:
|
|||
static void DrawThebesLayer(ThebesLayer* aLayer,
|
||||
gfxContext* aContext,
|
||||
const nsIntRegion& aRegionToDraw,
|
||||
const nsIntRegion& aRegionToInvalidate,
|
||||
void* aCallbackData);
|
||||
};
|
||||
|
||||
|
|
|
@ -5817,6 +5817,7 @@ struct PaintParams {
|
|||
static void DrawThebesLayer(ThebesLayer* aLayer,
|
||||
gfxContext* aContext,
|
||||
const nsIntRegion& aRegionToDraw,
|
||||
const nsIntRegion& aRegionToInvalidate,
|
||||
void* aCallbackData)
|
||||
{
|
||||
PaintParams* params = static_cast<PaintParams*>(aCallbackData);
|
||||
|
|
Загрузка…
Ссылка в новой задаче