2011-02-04 21:11:24 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2010-03-01 10:56:18 +03:00
|
|
|
* ***** 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) 2009
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Robert O'Callahan <robert@ocallahan.org>
|
2010-07-22 01:17:33 +04:00
|
|
|
* Chris Jones <jones.chris.g@gmail.com>
|
2010-03-01 10:56:18 +03:00
|
|
|
*
|
|
|
|
* 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 ***** */
|
|
|
|
|
2011-04-03 06:14:00 +04:00
|
|
|
#include "gfxSharedImageSurface.h"
|
2010-07-22 01:17:33 +04:00
|
|
|
|
2011-04-03 06:14:00 +04:00
|
|
|
#include "mozilla/layers/PLayerChild.h"
|
|
|
|
#include "mozilla/layers/PLayersChild.h"
|
|
|
|
#include "mozilla/layers/PLayersParent.h"
|
2011-06-24 21:41:18 +04:00
|
|
|
#include "mozilla/gfx/2D.h"
|
|
|
|
|
2011-04-03 06:14:00 +04:00
|
|
|
#include "ipc/ShadowLayerChild.h"
|
2010-07-22 01:17:33 +04:00
|
|
|
|
2010-03-01 10:56:18 +03:00
|
|
|
#include "BasicLayers.h"
|
2010-03-02 02:09:35 +03:00
|
|
|
#include "ImageLayers.h"
|
|
|
|
|
2010-03-01 10:56:18 +03:00
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsGUIEvent.h"
|
2010-03-02 02:09:35 +03:00
|
|
|
#include "gfxContext.h"
|
2010-05-18 08:04:22 +04:00
|
|
|
#include "gfxImageSurface.h"
|
2010-03-02 02:09:35 +03:00
|
|
|
#include "gfxPattern.h"
|
2010-03-04 00:37:04 +03:00
|
|
|
#include "gfxPlatform.h"
|
2010-05-18 08:04:22 +04:00
|
|
|
#include "gfxUtils.h"
|
2010-03-04 00:37:04 +03:00
|
|
|
#include "ThebesLayerBuffer.h"
|
2010-07-16 01:08:10 +04:00
|
|
|
#include "nsIWidget.h"
|
2011-02-17 01:43:30 +03:00
|
|
|
#include "ReadbackProcessor.h"
|
2011-04-21 01:45:57 +04:00
|
|
|
#ifdef MOZ_X11
|
|
|
|
#include "gfxXlibSurface.h"
|
|
|
|
#endif
|
2010-05-18 08:04:22 +04:00
|
|
|
|
|
|
|
#include "GLContext.h"
|
2011-08-27 04:04:06 +04:00
|
|
|
#include "pixman.h"
|
2010-03-01 10:56:18 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
|
|
|
class BasicContainerLayer;
|
2010-07-22 01:17:33 +04:00
|
|
|
class ShadowableLayer;
|
2010-03-01 10:56:18 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This is the ImplData for all Basic layers. It also exposes methods
|
2010-03-02 02:09:35 +03:00
|
|
|
* private to the Basic implementation that are common to all Basic layer types.
|
|
|
|
* In particular, there is an internal Paint() method that we can use
|
|
|
|
* to paint the contents of non-Thebes layers.
|
|
|
|
*
|
|
|
|
* The class hierarchy for Basic layers is like this:
|
|
|
|
* BasicImplData
|
|
|
|
* Layer | | |
|
|
|
|
* | | | |
|
|
|
|
* +-> ContainerLayer | | |
|
|
|
|
* | | | | |
|
|
|
|
* | +-> BasicContainerLayer <--+ | |
|
|
|
|
* | | |
|
|
|
|
* +-> ThebesLayer | |
|
|
|
|
* | | | |
|
|
|
|
* | +-> BasicThebesLayer <---------+ |
|
|
|
|
* | |
|
|
|
|
* +-> ImageLayer |
|
|
|
|
* | |
|
|
|
|
* +-> BasicImageLayer <--------------+
|
2010-03-01 10:56:18 +03:00
|
|
|
*/
|
|
|
|
class BasicImplData {
|
|
|
|
public:
|
2011-10-17 18:59:28 +04:00
|
|
|
BasicImplData() : mHidden(false),
|
|
|
|
mClipToVisibleRegion(false), mOperator(gfxContext::OPERATOR_OVER)
|
2010-03-01 10:56:18 +03:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(BasicImplData);
|
|
|
|
}
|
2010-07-22 01:17:33 +04:00
|
|
|
virtual ~BasicImplData()
|
2010-03-01 10:56:18 +03:00
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(BasicImplData);
|
|
|
|
}
|
|
|
|
|
2010-03-02 02:09:35 +03:00
|
|
|
/**
|
|
|
|
* Layers that paint themselves, such as ImageLayers, should paint
|
|
|
|
* in response to this method call. aContext will already have been
|
|
|
|
* set up to account for all the properties of the layer (transform,
|
|
|
|
* opacity, etc).
|
|
|
|
*/
|
2011-02-17 01:43:30 +03:00
|
|
|
virtual void Paint(gfxContext* aContext) {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Like Paint() but called for ThebesLayers with the additional parameters
|
|
|
|
* they need.
|
2011-08-12 02:44:50 +04:00
|
|
|
* If mClipToVisibleRegion is set, then the layer must clip to its
|
|
|
|
* effective visible region (snapped or unsnapped, it doesn't matter).
|
2011-02-17 01:43:30 +03:00
|
|
|
*/
|
|
|
|
virtual void PaintThebes(gfxContext* aContext,
|
|
|
|
LayerManager::DrawThebesLayerCallback aCallback,
|
|
|
|
void* aCallbackData,
|
|
|
|
ReadbackProcessor* aReadback) {}
|
2010-07-22 01:17:33 +04:00
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
virtual ShadowableLayer* AsShadowableLayer() { return nsnull; }
|
2010-08-20 07:40:49 +04:00
|
|
|
|
2010-10-13 23:22:17 +04:00
|
|
|
/**
|
|
|
|
* Implementations return true here if they *must* retain their
|
|
|
|
* layer contents. This is true of shadowable layers with shadows,
|
|
|
|
* because there's no target on which to composite directly in the
|
|
|
|
* layer-publishing child process.
|
|
|
|
*/
|
|
|
|
virtual bool MustRetainContent() { return false; }
|
|
|
|
|
2010-08-20 07:40:49 +04:00
|
|
|
/**
|
|
|
|
* Layers will get this call when their layer manager is destroyed, this
|
|
|
|
* indicates they should clear resources they don't really need after their
|
|
|
|
* LayerManager ceases to exist.
|
|
|
|
*/
|
|
|
|
virtual void ClearCachedResources() {}
|
2010-11-17 02:33:56 +03:00
|
|
|
|
|
|
|
/**
|
2011-05-30 07:48:13 +04:00
|
|
|
* This variable is set by MarkLayersHidden() before painting. It indicates
|
|
|
|
* that the layer should not be composited during this transaction.
|
2010-11-17 02:33:56 +03:00
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
void SetHidden(bool aCovered) { mHidden = aCovered; }
|
|
|
|
bool IsHidden() const { return false; }
|
2011-05-30 07:48:13 +04:00
|
|
|
/**
|
|
|
|
* This variable is set by MarkLayersHidden() before painting. This is
|
|
|
|
* the operator to be used when compositing the layer in this transaction. It must
|
|
|
|
* be OVER or SOURCE.
|
|
|
|
*/
|
|
|
|
void SetOperator(gfxContext::GraphicsOperator aOperator)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aOperator == gfxContext::OPERATOR_OVER ||
|
|
|
|
aOperator == gfxContext::OPERATOR_SOURCE,
|
|
|
|
"Bad composition operator");
|
|
|
|
mOperator = aOperator;
|
|
|
|
}
|
|
|
|
gfxContext::GraphicsOperator GetOperator() const { return mOperator; }
|
2010-11-17 02:33:56 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool GetClipToVisibleRegion() { return mClipToVisibleRegion; }
|
|
|
|
void SetClipToVisibleRegion(bool aClip) { mClipToVisibleRegion = aClip; }
|
2011-08-12 02:44:50 +04:00
|
|
|
|
2010-11-17 02:33:56 +03:00
|
|
|
protected:
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mHidden;
|
|
|
|
bool mClipToVisibleRegion;
|
2011-05-30 07:48:13 +04:00
|
|
|
gfxContext::GraphicsOperator mOperator;
|
|
|
|
};
|
|
|
|
|
|
|
|
class AutoSetOperator {
|
|
|
|
public:
|
|
|
|
AutoSetOperator(gfxContext* aContext, gfxContext::GraphicsOperator aOperator) {
|
|
|
|
if (aOperator != gfxContext::OPERATOR_OVER) {
|
|
|
|
aContext->SetOperator(aOperator);
|
|
|
|
mContext = aContext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
~AutoSetOperator() {
|
|
|
|
if (mContext) {
|
|
|
|
mContext->SetOperator(gfxContext::OPERATOR_OVER);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
nsRefPtr<gfxContext> mContext;
|
2010-03-01 10:56:18 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static BasicImplData*
|
|
|
|
ToData(Layer* aLayer)
|
|
|
|
{
|
|
|
|
return static_cast<BasicImplData*>(aLayer->ImplData());
|
|
|
|
}
|
|
|
|
|
2010-10-14 02:55:45 +04:00
|
|
|
template<class Container>
|
|
|
|
static void ContainerInsertAfter(Layer* aChild, Layer* aAfter, Container* aContainer);
|
|
|
|
template<class Container>
|
|
|
|
static void ContainerRemoveChild(Layer* aChild, Container* aContainer);
|
|
|
|
|
2011-05-30 07:48:13 +04:00
|
|
|
class BasicContainerLayer : public ContainerLayer, public BasicImplData {
|
2010-10-14 02:55:45 +04:00
|
|
|
template<class Container>
|
|
|
|
friend void ContainerInsertAfter(Layer* aChild, Layer* aAfter, Container* aContainer);
|
|
|
|
template<class Container>
|
|
|
|
friend void ContainerRemoveChild(Layer* aChild, Container* aContainer);
|
|
|
|
|
2010-03-01 10:56:18 +03:00
|
|
|
public:
|
|
|
|
BasicContainerLayer(BasicLayerManager* aManager) :
|
|
|
|
ContainerLayer(aManager, static_cast<BasicImplData*>(this))
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(BasicContainerLayer);
|
2011-10-17 18:59:28 +04:00
|
|
|
mSupportsComponentAlphaChildren = true;
|
2010-03-01 10:56:18 +03:00
|
|
|
}
|
|
|
|
virtual ~BasicContainerLayer();
|
|
|
|
|
|
|
|
virtual void SetVisibleRegion(const nsIntRegion& aRegion)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(BasicManager()->InConstruction(),
|
|
|
|
"Can only set properties in construction phase");
|
2010-06-01 03:29:37 +04:00
|
|
|
ContainerLayer::SetVisibleRegion(aRegion);
|
2010-03-01 10:56:18 +03:00
|
|
|
}
|
2010-10-14 02:55:45 +04:00
|
|
|
virtual void InsertAfter(Layer* aChild, Layer* aAfter)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(BasicManager()->InConstruction(),
|
|
|
|
"Can only set properties in construction phase");
|
|
|
|
ContainerInsertAfter(aChild, aAfter, this);
|
|
|
|
}
|
2010-03-01 10:56:18 +03:00
|
|
|
|
2010-10-14 02:55:45 +04:00
|
|
|
virtual void RemoveChild(Layer* aChild)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(BasicManager()->InConstruction(),
|
|
|
|
"Can only set properties in construction phase");
|
|
|
|
ContainerRemoveChild(aChild, this);
|
|
|
|
}
|
2010-06-01 03:32:05 +04:00
|
|
|
|
2010-11-08 12:06:15 +03:00
|
|
|
virtual void ComputeEffectiveTransforms(const gfx3DMatrix& aTransformToSurface)
|
|
|
|
{
|
|
|
|
// We push groups for container layers if we need to, which always
|
|
|
|
// are aligned in device space, so it doesn't really matter how we snap
|
|
|
|
// containers.
|
2011-08-27 04:04:06 +04:00
|
|
|
gfxMatrix residual;
|
2010-11-08 12:06:15 +03:00
|
|
|
gfx3DMatrix idealTransform = GetLocalTransform()*aTransformToSurface;
|
2011-08-27 04:04:06 +04:00
|
|
|
|
|
|
|
if (!idealTransform.CanDraw2D()) {
|
|
|
|
mEffectiveTransform = idealTransform;
|
|
|
|
ComputeEffectiveTransformsForChildren(gfx3DMatrix());
|
2011-10-17 18:59:28 +04:00
|
|
|
mUseIntermediateSurface = true;
|
2011-08-27 04:04:06 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mEffectiveTransform = SnapTransform(idealTransform, gfxRect(0, 0, 0, 0), &residual);
|
2010-11-08 12:06:15 +03:00
|
|
|
// We always pass the ideal matrix down to our children, so there is no
|
|
|
|
// need to apply any compensation using the residual from SnapTransform.
|
|
|
|
ComputeEffectiveTransformsForChildren(idealTransform);
|
|
|
|
|
|
|
|
/* If we have a single child, it can just inherit our opacity,
|
|
|
|
* otherwise we need a PushGroup and we need to mark ourselves as using
|
|
|
|
* an intermediate surface so our children don't inherit our opacity
|
|
|
|
* via GetEffectiveOpacity.
|
|
|
|
*/
|
|
|
|
mUseIntermediateSurface = GetEffectiveOpacity() != 1.0 && HasMultipleChildren();
|
|
|
|
}
|
|
|
|
|
2011-05-30 07:48:23 +04:00
|
|
|
/**
|
|
|
|
* Returns true when:
|
|
|
|
* a) no (non-hidden) childrens' visible areas overlap in
|
|
|
|
* (aInRect intersected with this layer's visible region).
|
|
|
|
* b) the (non-hidden) childrens' visible areas cover
|
|
|
|
* (aInRect intersected with this layer's visible region).
|
|
|
|
* c) this layer and all (non-hidden) children have transforms that are translations
|
|
|
|
* by integers.
|
|
|
|
* aInRect is in the root coordinate system.
|
|
|
|
* Child layers with opacity do not contribute to the covered area in check b).
|
|
|
|
* This method can be conservative; it's OK to return false under any
|
|
|
|
* circumstances.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool ChildrenPartitionVisibleRegion(const nsIntRect& aInRect);
|
2011-05-30 07:48:23 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
void ForceIntermediateSurface() { mUseIntermediateSurface = true; }
|
2011-05-30 07:48:23 +04:00
|
|
|
|
2010-10-14 02:55:45 +04:00
|
|
|
protected:
|
2010-03-01 10:56:18 +03:00
|
|
|
BasicLayerManager* BasicManager()
|
|
|
|
{
|
|
|
|
return static_cast<BasicLayerManager*>(mManager);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
BasicContainerLayer::~BasicContainerLayer()
|
|
|
|
{
|
|
|
|
while (mFirstChild) {
|
2010-10-14 02:55:45 +04:00
|
|
|
ContainerRemoveChild(mFirstChild, this);
|
2010-03-01 10:56:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_COUNT_DTOR(BasicContainerLayer);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2011-05-30 07:48:23 +04:00
|
|
|
BasicContainerLayer::ChildrenPartitionVisibleRegion(const nsIntRect& aInRect)
|
|
|
|
{
|
|
|
|
gfxMatrix transform;
|
2011-08-27 04:04:06 +04:00
|
|
|
if (!GetEffectiveTransform().CanDraw2D(&transform) ||
|
2011-05-30 07:48:23 +04:00
|
|
|
transform.HasNonIntegerTranslation())
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2011-05-30 07:48:23 +04:00
|
|
|
|
|
|
|
nsIntPoint offset(PRInt32(transform.x0), PRInt32(transform.y0));
|
|
|
|
nsIntRect rect = aInRect.Intersect(GetEffectiveVisibleRegion().GetBounds() + offset);
|
|
|
|
nsIntRegion covered;
|
|
|
|
|
|
|
|
for (Layer* l = mFirstChild; l; l = l->GetNextSibling()) {
|
|
|
|
if (ToData(l)->IsHidden())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
gfxMatrix childTransform;
|
2011-08-27 04:04:06 +04:00
|
|
|
if (!l->GetEffectiveTransform().CanDraw2D(&childTransform) ||
|
2011-05-30 07:48:23 +04:00
|
|
|
childTransform.HasNonIntegerTranslation() ||
|
|
|
|
l->GetEffectiveOpacity() != 1.0)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2011-05-30 07:48:23 +04:00
|
|
|
nsIntRegion childRegion = l->GetEffectiveVisibleRegion();
|
|
|
|
childRegion.MoveBy(PRInt32(childTransform.x0), PRInt32(childTransform.y0));
|
|
|
|
childRegion.And(childRegion, rect);
|
|
|
|
if (l->GetClipRect()) {
|
|
|
|
childRegion.And(childRegion, *l->GetClipRect() + offset);
|
|
|
|
}
|
|
|
|
nsIntRegion intersection;
|
|
|
|
intersection.And(covered, childRegion);
|
|
|
|
if (!intersection.IsEmpty())
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2011-05-30 07:48:23 +04:00
|
|
|
covered.Or(covered, childRegion);
|
|
|
|
}
|
|
|
|
|
|
|
|
return covered.Contains(rect);
|
|
|
|
}
|
|
|
|
|
2010-10-14 02:55:45 +04:00
|
|
|
template<class Container>
|
|
|
|
static void
|
|
|
|
ContainerInsertAfter(Layer* aChild, Layer* aAfter, Container* aContainer)
|
2010-03-01 10:56:18 +03:00
|
|
|
{
|
2010-10-14 02:55:45 +04:00
|
|
|
NS_ASSERTION(aChild->Manager() == aContainer->Manager(),
|
2010-03-01 10:56:18 +03:00
|
|
|
"Child has wrong manager");
|
|
|
|
NS_ASSERTION(!aChild->GetParent(),
|
|
|
|
"aChild already in the tree");
|
|
|
|
NS_ASSERTION(!aChild->GetNextSibling() && !aChild->GetPrevSibling(),
|
|
|
|
"aChild already has siblings?");
|
|
|
|
NS_ASSERTION(!aAfter ||
|
2010-10-14 02:55:45 +04:00
|
|
|
(aAfter->Manager() == aContainer->Manager() &&
|
|
|
|
aAfter->GetParent() == aContainer),
|
2010-03-01 10:56:18 +03:00
|
|
|
"aAfter is not our child");
|
|
|
|
|
2010-10-14 02:55:45 +04:00
|
|
|
aChild->SetParent(aContainer);
|
2010-11-17 02:33:56 +03:00
|
|
|
if (aAfter == aContainer->mLastChild) {
|
|
|
|
aContainer->mLastChild = aChild;
|
|
|
|
}
|
2010-03-01 10:56:18 +03:00
|
|
|
if (!aAfter) {
|
2010-10-14 02:55:45 +04:00
|
|
|
aChild->SetNextSibling(aContainer->mFirstChild);
|
|
|
|
if (aContainer->mFirstChild) {
|
|
|
|
aContainer->mFirstChild->SetPrevSibling(aChild);
|
2010-03-01 10:56:18 +03:00
|
|
|
}
|
2010-10-14 02:55:45 +04:00
|
|
|
aContainer->mFirstChild = aChild;
|
2011-02-17 01:43:30 +03:00
|
|
|
NS_ADDREF(aChild);
|
|
|
|
aContainer->DidInsertChild(aChild);
|
2010-03-01 10:56:18 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Layer* next = aAfter->GetNextSibling();
|
|
|
|
aChild->SetNextSibling(next);
|
|
|
|
aChild->SetPrevSibling(aAfter);
|
|
|
|
if (next) {
|
|
|
|
next->SetPrevSibling(aChild);
|
|
|
|
}
|
|
|
|
aAfter->SetNextSibling(aChild);
|
2011-02-17 01:43:30 +03:00
|
|
|
NS_ADDREF(aChild);
|
|
|
|
aContainer->DidInsertChild(aChild);
|
2010-03-01 10:56:18 +03:00
|
|
|
}
|
|
|
|
|
2010-10-14 02:55:45 +04:00
|
|
|
template<class Container>
|
|
|
|
static void
|
|
|
|
ContainerRemoveChild(Layer* aChild, Container* aContainer)
|
2010-06-01 03:32:05 +04:00
|
|
|
{
|
2010-10-14 02:55:45 +04:00
|
|
|
NS_ASSERTION(aChild->Manager() == aContainer->Manager(),
|
2010-03-01 10:56:18 +03:00
|
|
|
"Child has wrong manager");
|
2010-10-14 02:55:45 +04:00
|
|
|
NS_ASSERTION(aChild->GetParent() == aContainer,
|
2010-03-01 10:56:18 +03:00
|
|
|
"aChild not our child");
|
|
|
|
|
|
|
|
Layer* prev = aChild->GetPrevSibling();
|
|
|
|
Layer* next = aChild->GetNextSibling();
|
|
|
|
if (prev) {
|
|
|
|
prev->SetNextSibling(next);
|
|
|
|
} else {
|
2010-10-14 02:55:45 +04:00
|
|
|
aContainer->mFirstChild = next;
|
2010-03-01 10:56:18 +03:00
|
|
|
}
|
|
|
|
if (next) {
|
|
|
|
next->SetPrevSibling(prev);
|
2010-11-17 02:33:56 +03:00
|
|
|
} else {
|
|
|
|
aContainer->mLastChild = prev;
|
2010-03-01 10:56:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
aChild->SetNextSibling(nsnull);
|
|
|
|
aChild->SetPrevSibling(nsnull);
|
|
|
|
aChild->SetParent(nsnull);
|
|
|
|
|
2011-02-17 01:43:30 +03:00
|
|
|
aContainer->DidRemoveChild(aChild);
|
2010-03-01 10:56:18 +03:00
|
|
|
NS_RELEASE(aChild);
|
|
|
|
}
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
class BasicThebesLayer;
|
|
|
|
class BasicThebesLayerBuffer : public ThebesLayerBuffer {
|
|
|
|
typedef ThebesLayerBuffer Base;
|
|
|
|
|
|
|
|
public:
|
|
|
|
BasicThebesLayerBuffer(BasicThebesLayer* aLayer)
|
|
|
|
: Base(ContainsVisibleBounds)
|
|
|
|
, mLayer(aLayer)
|
2011-03-01 23:30:16 +03:00
|
|
|
{
|
|
|
|
}
|
2010-07-22 01:17:33 +04:00
|
|
|
|
|
|
|
virtual ~BasicThebesLayerBuffer()
|
|
|
|
{}
|
|
|
|
|
|
|
|
using Base::BufferRect;
|
|
|
|
using Base::BufferRotation;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2010-11-12 04:43:42 +03:00
|
|
|
void DrawTo(ThebesLayer* aLayer, gfxContext* aTarget, float aOpacity);
|
2010-07-22 01:17:33 +04:00
|
|
|
|
|
|
|
virtual already_AddRefed<gfxASurface>
|
2011-04-01 01:33:46 +04:00
|
|
|
CreateBuffer(ContentType aType, const nsIntSize& aSize, PRUint32 aFlags);
|
2010-07-22 01:17:33 +04:00
|
|
|
|
2010-09-14 09:23:08 +04:00
|
|
|
/**
|
2010-09-14 09:23:08 +04:00
|
|
|
* Swap out the old backing buffer for |aBuffer| and attributes.
|
2010-09-14 09:23:08 +04:00
|
|
|
*/
|
2010-09-14 09:23:08 +04:00
|
|
|
void SetBackingBuffer(gfxASurface* aBuffer,
|
|
|
|
const nsIntRect& aRect, const nsIntPoint& aRotation)
|
2010-09-14 09:23:08 +04:00
|
|
|
{
|
2011-06-22 16:11:28 +04:00
|
|
|
gfxIntSize prevSize = gfxIntSize(BufferRect().width, BufferRect().height);
|
2010-09-14 09:23:08 +04:00
|
|
|
gfxIntSize newSize = aBuffer->GetSize();
|
|
|
|
NS_ABORT_IF_FALSE(newSize == prevSize,
|
2010-09-14 09:23:08 +04:00
|
|
|
"Swapped-in buffer size doesn't match old buffer's!");
|
2010-11-05 19:37:40 +03:00
|
|
|
nsRefPtr<gfxASurface> oldBuffer;
|
2011-06-22 16:11:28 +04:00
|
|
|
oldBuffer = SetBuffer(aBuffer, aRect, aRotation);
|
2010-09-14 09:23:08 +04:00
|
|
|
}
|
|
|
|
|
2010-11-05 10:17:07 +03:00
|
|
|
void SetBackingBufferAndUpdateFrom(
|
|
|
|
gfxASurface* aBuffer,
|
|
|
|
gfxASurface* aSource, const nsIntRect& aRect, const nsIntPoint& aRotation,
|
2011-06-22 16:11:28 +04:00
|
|
|
const nsIntRegion& aUpdateRegion);
|
2010-11-05 10:17:07 +03:00
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
private:
|
2010-11-05 10:17:07 +03:00
|
|
|
BasicThebesLayerBuffer(gfxASurface* aBuffer,
|
|
|
|
const nsIntRect& aRect, const nsIntPoint& aRotation)
|
|
|
|
// The size policy doesn't really matter here; this constructor is
|
|
|
|
// intended to be used for creating temporaries
|
|
|
|
: ThebesLayerBuffer(ContainsVisibleBounds)
|
|
|
|
{
|
2011-06-22 16:11:28 +04:00
|
|
|
SetBuffer(aBuffer, aRect, aRotation);
|
2010-11-05 10:17:07 +03:00
|
|
|
}
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
BasicThebesLayer* mLayer;
|
|
|
|
};
|
|
|
|
|
2011-05-30 07:48:13 +04:00
|
|
|
class BasicThebesLayer : public ThebesLayer, public BasicImplData {
|
2010-03-01 10:56:18 +03:00
|
|
|
public:
|
2010-07-22 01:17:33 +04:00
|
|
|
typedef BasicThebesLayerBuffer Buffer;
|
|
|
|
|
2010-03-01 10:56:18 +03:00
|
|
|
BasicThebesLayer(BasicLayerManager* aLayerManager) :
|
2010-07-21 22:06:33 +04:00
|
|
|
ThebesLayer(aLayerManager, static_cast<BasicImplData*>(this)),
|
|
|
|
mBuffer(this)
|
2010-03-01 10:56:18 +03:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(BasicThebesLayer);
|
|
|
|
}
|
|
|
|
virtual ~BasicThebesLayer()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(BasicThebesLayer);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void SetVisibleRegion(const nsIntRegion& aRegion)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(BasicManager()->InConstruction(),
|
|
|
|
"Can only set properties in construction phase");
|
2010-06-01 03:29:37 +04:00
|
|
|
ThebesLayer::SetVisibleRegion(aRegion);
|
2010-03-01 10:56:18 +03:00
|
|
|
}
|
|
|
|
virtual void InvalidateRegion(const nsIntRegion& aRegion)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(BasicManager()->InConstruction(),
|
|
|
|
"Can only set properties in construction phase");
|
2010-03-04 00:37:04 +03:00
|
|
|
mValidRegion.Sub(mValidRegion, aRegion);
|
2010-03-01 10:56:18 +03:00
|
|
|
}
|
|
|
|
|
2011-02-17 01:43:30 +03:00
|
|
|
virtual void PaintThebes(gfxContext* aContext,
|
|
|
|
LayerManager::DrawThebesLayerCallback aCallback,
|
|
|
|
void* aCallbackData,
|
|
|
|
ReadbackProcessor* aReadback);
|
2010-08-20 07:40:49 +04:00
|
|
|
|
|
|
|
virtual void ClearCachedResources() { mBuffer.Clear(); mValidRegion.SetEmpty(); }
|
2010-07-21 22:06:33 +04:00
|
|
|
|
|
|
|
virtual already_AddRefed<gfxASurface>
|
|
|
|
CreateBuffer(Buffer::ContentType aType, const nsIntSize& aSize)
|
|
|
|
{
|
|
|
|
nsRefPtr<gfxASurface> referenceSurface = mBuffer.GetBuffer();
|
|
|
|
if (!referenceSurface) {
|
|
|
|
gfxContext* defaultTarget = BasicManager()->GetDefaultTarget();
|
|
|
|
if (defaultTarget) {
|
|
|
|
referenceSurface = defaultTarget->CurrentSurface();
|
|
|
|
} else {
|
|
|
|
nsIWidget* widget = BasicManager()->GetRetainerWidget();
|
|
|
|
if (widget) {
|
|
|
|
referenceSurface = widget->GetThebesSurface();
|
|
|
|
} else {
|
|
|
|
referenceSurface = BasicManager()->GetTarget()->CurrentSurface();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return referenceSurface->CreateSimilarSurface(
|
|
|
|
aType, gfxIntSize(aSize.width, aSize.height));
|
|
|
|
}
|
|
|
|
|
2011-06-22 16:11:27 +04:00
|
|
|
virtual void ComputeEffectiveTransforms(const gfx3DMatrix& aTransformToSurface)
|
|
|
|
{
|
|
|
|
if (!BasicManager()->IsRetained()) {
|
|
|
|
// Don't do any snapping of our transform, since we're just going to
|
|
|
|
// draw straight through without intermediate buffers.
|
|
|
|
mEffectiveTransform = GetLocalTransform()*aTransformToSurface;
|
2011-06-22 16:11:28 +04:00
|
|
|
if (gfxPoint(0,0) != mResidualTranslation) {
|
|
|
|
mResidualTranslation = gfxPoint(0,0);
|
|
|
|
mValidRegion.SetEmpty();
|
|
|
|
}
|
2011-06-22 16:11:27 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
ThebesLayer::ComputeEffectiveTransforms(aTransformToSurface);
|
|
|
|
}
|
|
|
|
|
2011-10-10 20:47:27 +04:00
|
|
|
// Sync front/back buffers content
|
|
|
|
virtual void SyncFrontBufferToBackBuffer() {}
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
protected:
|
|
|
|
BasicLayerManager* BasicManager()
|
|
|
|
{
|
|
|
|
return static_cast<BasicLayerManager*>(mManager);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
PaintBuffer(gfxContext* aContext,
|
|
|
|
const nsIntRegion& aRegionToDraw,
|
2011-03-09 20:27:37 +03:00
|
|
|
const nsIntRegion& aExtendedRegionToDraw,
|
2010-07-22 01:17:33 +04:00
|
|
|
const nsIntRegion& aRegionToInvalidate,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aDidSelfCopy,
|
2010-07-22 01:17:33 +04:00
|
|
|
LayerManager::DrawThebesLayerCallback aCallback,
|
|
|
|
void* aCallbackData)
|
|
|
|
{
|
2010-12-27 09:12:17 +03:00
|
|
|
if (!aCallback) {
|
|
|
|
BasicManager()->SetTransactionIncomplete();
|
|
|
|
return;
|
|
|
|
}
|
2011-03-09 20:27:37 +03:00
|
|
|
aCallback(this, aContext, aExtendedRegionToDraw, aRegionToInvalidate,
|
2010-07-22 01:17:33 +04:00
|
|
|
aCallbackData);
|
2011-03-01 23:30:16 +03:00
|
|
|
// Everything that's visible has been validated. Do this instead of just
|
2011-01-16 13:38:45 +03:00
|
|
|
// OR-ing with aRegionToDraw, since that can lead to a very complex region
|
|
|
|
// here (OR doesn't automatically simplify to the simplest possible
|
|
|
|
// representation of a region.)
|
2011-03-01 23:30:16 +03:00
|
|
|
nsIntRegion tmp;
|
2011-03-09 20:27:37 +03:00
|
|
|
tmp.Or(mVisibleRegion, aExtendedRegionToDraw);
|
2011-03-01 23:30:16 +03:00
|
|
|
mValidRegion.Or(mValidRegion, tmp);
|
2010-07-22 01:17:33 +04:00
|
|
|
}
|
|
|
|
|
2010-07-21 22:06:33 +04:00
|
|
|
Buffer mBuffer;
|
2010-03-01 10:56:18 +03:00
|
|
|
};
|
|
|
|
|
2011-01-04 13:35:57 +03:00
|
|
|
/**
|
|
|
|
* Clips to the smallest device-pixel-aligned rectangle containing aRect
|
|
|
|
* in user space.
|
|
|
|
* Returns true if the clip is "perfect", i.e. we actually clipped exactly to
|
|
|
|
* aRect.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2010-07-16 01:08:04 +04:00
|
|
|
ClipToContain(gfxContext* aContext, const nsIntRect& aRect)
|
|
|
|
{
|
2011-01-04 13:35:57 +03:00
|
|
|
gfxRect userRect(aRect.x, aRect.y, aRect.width, aRect.height);
|
|
|
|
gfxRect deviceRect = aContext->UserToDevice(userRect);
|
2010-07-16 01:08:04 +04:00
|
|
|
deviceRect.RoundOut();
|
|
|
|
|
|
|
|
gfxMatrix currentMatrix = aContext->CurrentMatrix();
|
|
|
|
aContext->IdentityMatrix();
|
|
|
|
aContext->NewPath();
|
|
|
|
aContext->Rectangle(deviceRect);
|
|
|
|
aContext->Clip();
|
|
|
|
aContext->SetMatrix(currentMatrix);
|
2011-01-04 13:35:57 +03:00
|
|
|
|
2011-04-19 07:07:23 +04:00
|
|
|
return aContext->DeviceToUser(deviceRect).IsEqualInterior(userRect);
|
2010-07-16 01:08:04 +04:00
|
|
|
}
|
|
|
|
|
2010-09-06 07:00:10 +04:00
|
|
|
static nsIntRegion
|
|
|
|
IntersectWithClip(const nsIntRegion& aRegion, gfxContext* aContext)
|
|
|
|
{
|
|
|
|
gfxRect clip = aContext->GetClipExtents();
|
|
|
|
clip.RoundOut();
|
|
|
|
nsIntRect r(clip.X(), clip.Y(), clip.Width(), clip.Height());
|
|
|
|
nsIntRegion result;
|
|
|
|
result.And(aRegion, r);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-01-03 04:48:08 +03:00
|
|
|
static void
|
|
|
|
SetAntialiasingFlags(Layer* aLayer, gfxContext* aTarget)
|
|
|
|
{
|
|
|
|
nsRefPtr<gfxASurface> surface = aTarget->CurrentSurface();
|
|
|
|
if (surface->GetContentType() != gfxASurface::CONTENT_COLOR_ALPHA) {
|
|
|
|
// Destination doesn't have alpha channel; no need to set any special flags
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-01 23:32:23 +03:00
|
|
|
const nsIntRect& bounds = aLayer->GetVisibleRegion().GetBounds();
|
2011-01-03 04:48:08 +03:00
|
|
|
surface->SetSubpixelAntialiasingEnabled(
|
2011-03-01 23:32:23 +03:00
|
|
|
!(aLayer->GetContentFlags() & Layer::CONTENT_COMPONENT_ALPHA) ||
|
|
|
|
surface->GetOpaqueRect().Contains(
|
|
|
|
aTarget->UserToDevice(gfxRect(bounds.x, bounds.y, bounds.width, bounds.height))));
|
2011-01-03 04:48:08 +03:00
|
|
|
}
|
|
|
|
|
2011-05-30 07:48:29 +04:00
|
|
|
already_AddRefed<gfxContext>
|
|
|
|
BasicLayerManager::PushGroupForLayer(gfxContext* aContext, Layer* aLayer,
|
|
|
|
const nsIntRegion& aRegion,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool* aNeedsClipToVisibleRegion)
|
2011-01-04 13:35:57 +03:00
|
|
|
{
|
|
|
|
// If we need to call PushGroup, we should clip to the smallest possible
|
|
|
|
// area first to minimize the size of the temporary surface.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool didCompleteClip = ClipToContain(aContext, aRegion.GetBounds());
|
2011-01-04 13:35:57 +03:00
|
|
|
|
2011-05-30 07:48:29 +04:00
|
|
|
nsRefPtr<gfxContext> result;
|
2011-01-04 13:35:57 +03:00
|
|
|
if (aLayer->CanUseOpaqueSurface() &&
|
|
|
|
((didCompleteClip && aRegion.GetNumRects() == 1) ||
|
|
|
|
!aContext->CurrentMatrix().HasNonIntegerTranslation())) {
|
|
|
|
// If the layer is opaque in its visible region we can push a CONTENT_COLOR
|
|
|
|
// group. We need to make sure that only pixels inside the layer's visible
|
|
|
|
// region are copied back to the destination. Remember if we've already
|
|
|
|
// clipped precisely to the visible region.
|
2011-05-30 07:48:29 +04:00
|
|
|
*aNeedsClipToVisibleRegion = !didCompleteClip || aRegion.GetNumRects() > 1;
|
|
|
|
result = PushGroupWithCachedSurface(aContext, gfxASurface::CONTENT_COLOR);
|
|
|
|
} else {
|
2011-10-17 18:59:28 +04:00
|
|
|
*aNeedsClipToVisibleRegion = false;
|
2011-05-30 07:48:29 +04:00
|
|
|
result = aContext;
|
|
|
|
aContext->PushGroupAndCopyBackground(gfxASurface::CONTENT_COLOR_ALPHA);
|
2011-01-04 13:35:57 +03:00
|
|
|
}
|
2011-05-30 07:48:29 +04:00
|
|
|
return result.forget();
|
2011-01-04 13:35:57 +03:00
|
|
|
}
|
|
|
|
|
2010-05-21 07:20:48 +04:00
|
|
|
void
|
2011-02-17 01:43:30 +03:00
|
|
|
BasicThebesLayer::PaintThebes(gfxContext* aContext,
|
|
|
|
LayerManager::DrawThebesLayerCallback aCallback,
|
|
|
|
void* aCallbackData,
|
|
|
|
ReadbackProcessor* aReadback)
|
2010-03-01 10:56:18 +03:00
|
|
|
{
|
|
|
|
NS_ASSERTION(BasicManager()->InDrawing(),
|
|
|
|
"Can only draw in drawing phase");
|
2010-09-02 13:18:41 +04:00
|
|
|
nsRefPtr<gfxASurface> targetSurface = aContext->CurrentSurface();
|
2010-03-01 10:56:18 +03:00
|
|
|
|
2011-02-17 01:43:30 +03:00
|
|
|
nsTArray<ReadbackProcessor::Update> readbackUpdates;
|
|
|
|
if (aReadback && UsedForReadback()) {
|
|
|
|
aReadback->GetThebesLayerUpdates(this, &readbackUpdates);
|
|
|
|
}
|
2011-10-10 20:47:27 +04:00
|
|
|
SyncFrontBufferToBackBuffer();
|
2011-02-17 01:43:30 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool canUseOpaqueSurface = CanUseOpaqueSurface();
|
2010-09-03 06:31:42 +04:00
|
|
|
Buffer::ContentType contentType =
|
2010-11-12 04:43:40 +03:00
|
|
|
canUseOpaqueSurface ? gfxASurface::CONTENT_COLOR :
|
|
|
|
gfxASurface::CONTENT_COLOR_ALPHA;
|
2010-11-08 12:06:15 +03:00
|
|
|
float opacity = GetEffectiveOpacity();
|
2010-09-03 06:31:42 +04:00
|
|
|
|
2010-09-02 13:18:41 +04:00
|
|
|
if (!BasicManager()->IsRetained() ||
|
2010-12-20 04:26:14 +03:00
|
|
|
(!canUseOpaqueSurface &&
|
2010-12-20 04:26:14 +03:00
|
|
|
(mContentFlags & CONTENT_COMPONENT_ALPHA) &&
|
2010-10-13 23:22:17 +04:00
|
|
|
!MustRetainContent())) {
|
2011-02-17 01:43:30 +03:00
|
|
|
NS_ASSERTION(readbackUpdates.IsEmpty(), "Can't do readback for non-retained layer");
|
|
|
|
|
2010-03-04 00:37:04 +03:00
|
|
|
mValidRegion.SetEmpty();
|
|
|
|
mBuffer.Clear();
|
2010-03-01 10:56:18 +03:00
|
|
|
|
2011-05-30 07:48:13 +04:00
|
|
|
nsIntRegion toDraw = IntersectWithClip(GetEffectiveVisibleRegion(), aContext);
|
2011-05-18 15:24:52 +04:00
|
|
|
if (!toDraw.IsEmpty() && !IsHidden()) {
|
2010-12-27 09:12:17 +03:00
|
|
|
if (!aCallback) {
|
|
|
|
BasicManager()->SetTransactionIncomplete();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-01-04 13:35:57 +03:00
|
|
|
aContext->Save();
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool needsClipToVisibleRegion = GetClipToVisibleRegion();
|
|
|
|
bool needsGroup =
|
2011-05-30 07:48:13 +04:00
|
|
|
opacity != 1.0 || GetOperator() != gfxContext::OPERATOR_OVER;
|
2011-05-30 07:48:29 +04:00
|
|
|
nsRefPtr<gfxContext> groupContext;
|
2011-05-30 07:48:13 +04:00
|
|
|
if (needsGroup) {
|
2011-05-30 07:48:29 +04:00
|
|
|
groupContext =
|
|
|
|
BasicManager()->PushGroupForLayer(aContext, this, toDraw,
|
|
|
|
&needsClipToVisibleRegion);
|
|
|
|
if (GetOperator() != gfxContext::OPERATOR_OVER) {
|
2011-10-17 18:59:28 +04:00
|
|
|
needsClipToVisibleRegion = true;
|
2011-05-30 07:48:29 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
groupContext = aContext;
|
2010-09-06 07:00:10 +04:00
|
|
|
}
|
2011-05-30 07:48:29 +04:00
|
|
|
SetAntialiasingFlags(this, groupContext);
|
|
|
|
aCallback(this, groupContext, toDraw, nsIntRegion(), aCallbackData);
|
2011-05-30 07:48:13 +04:00
|
|
|
if (needsGroup) {
|
2011-05-30 07:48:29 +04:00
|
|
|
BasicManager()->PopGroupToSourceWithCachedSurface(aContext, groupContext);
|
2011-01-04 13:35:57 +03:00
|
|
|
if (needsClipToVisibleRegion) {
|
|
|
|
gfxUtils::ClipToRegion(aContext, toDraw);
|
|
|
|
}
|
2011-05-30 07:48:13 +04:00
|
|
|
AutoSetOperator setOperator(aContext, GetOperator());
|
2011-01-04 13:35:57 +03:00
|
|
|
aContext->Paint(opacity);
|
2010-09-06 07:00:10 +04:00
|
|
|
}
|
2011-01-04 13:35:57 +03:00
|
|
|
|
|
|
|
aContext->Restore();
|
2010-07-16 01:08:04 +04:00
|
|
|
}
|
2010-03-04 00:37:04 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2011-03-01 23:30:16 +03:00
|
|
|
PRUint32 flags = 0;
|
2011-08-29 21:56:50 +04:00
|
|
|
#ifndef MOZ_GFX_OPTIMIZE_MOBILE
|
2011-03-01 23:30:16 +03:00
|
|
|
gfxMatrix transform;
|
2011-08-27 04:04:06 +04:00
|
|
|
if (!GetEffectiveTransform().CanDraw2D(&transform) ||
|
2011-08-29 21:56:50 +04:00
|
|
|
transform.HasNonIntegerTranslation()) {
|
2011-03-01 23:30:16 +03:00
|
|
|
flags |= ThebesLayerBuffer::PAINT_WILL_RESAMPLE;
|
|
|
|
}
|
2011-08-29 21:56:50 +04:00
|
|
|
#endif
|
2010-09-04 00:10:46 +04:00
|
|
|
Buffer::PaintState state =
|
2011-06-22 16:11:28 +04:00
|
|
|
mBuffer.BeginPaint(this, contentType, flags);
|
2010-03-04 00:37:04 +03:00
|
|
|
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)
|
2011-05-30 07:48:13 +04:00
|
|
|
state.mRegionToInvalidate.And(state.mRegionToInvalidate,
|
|
|
|
GetEffectiveVisibleRegion());
|
2011-03-09 20:27:37 +03:00
|
|
|
nsIntRegion extendedDrawRegion = state.mRegionToDraw;
|
2011-01-03 04:48:08 +03:00
|
|
|
SetAntialiasingFlags(this, state.mContext);
|
2010-07-22 01:17:33 +04:00
|
|
|
PaintBuffer(state.mContext,
|
2011-03-09 20:27:37 +03:00
|
|
|
state.mRegionToDraw, extendedDrawRegion, state.mRegionToInvalidate,
|
2011-03-12 08:22:39 +03:00
|
|
|
state.mDidSelfCopy,
|
2010-07-22 01:17:33 +04:00
|
|
|
aCallback, aCallbackData);
|
2010-09-04 00:10:46 +04:00
|
|
|
Mutated();
|
2010-03-04 00:37:04 +03:00
|
|
|
} else {
|
2010-07-16 01:08:10 +04:00
|
|
|
// It's possible that state.mRegionToInvalidate is nonempty here,
|
|
|
|
// if we are shrinking the valid region to nothing.
|
|
|
|
NS_ASSERTION(state.mRegionToDraw.IsEmpty(),
|
2010-03-04 00:37:04 +03:00
|
|
|
"If we need to draw, we should have a context");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-18 15:24:52 +04:00
|
|
|
if (!IsHidden()) {
|
2011-05-30 07:48:13 +04:00
|
|
|
AutoSetOperator setOperator(aContext, GetOperator());
|
2011-05-18 15:24:52 +04:00
|
|
|
mBuffer.DrawTo(this, aContext, opacity);
|
|
|
|
}
|
2011-02-17 01:43:30 +03:00
|
|
|
|
|
|
|
for (PRUint32 i = 0; i < readbackUpdates.Length(); ++i) {
|
|
|
|
ReadbackProcessor::Update& update = readbackUpdates[i];
|
|
|
|
nsIntPoint offset = update.mLayer->GetBackgroundLayerOffset();
|
|
|
|
nsRefPtr<gfxContext> ctx =
|
|
|
|
update.mLayer->GetSink()->BeginUpdate(update.mUpdateRect + offset,
|
|
|
|
update.mSequenceCounter);
|
|
|
|
if (ctx) {
|
|
|
|
NS_ASSERTION(opacity == 1.0, "Should only read back opaque layers");
|
|
|
|
ctx->Translate(gfxPoint(offset.x, offset.y));
|
|
|
|
mBuffer.DrawTo(this, ctx, 1.0);
|
|
|
|
update.mLayer->GetSink()->EndUpdate(ctx, update.mUpdateRect + offset);
|
|
|
|
}
|
|
|
|
}
|
2010-07-21 22:06:33 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2010-09-17 23:29:52 +04:00
|
|
|
IsClippingCheap(gfxContext* aTarget, const nsIntRegion& aRegion)
|
|
|
|
{
|
|
|
|
// Assume clipping is cheap if the context just has an integer
|
|
|
|
// translation, and the visible region is simple.
|
|
|
|
return !aTarget->CurrentMatrix().HasNonIntegerTranslation() &&
|
|
|
|
aRegion.GetNumRects() <= 1;
|
|
|
|
}
|
|
|
|
|
2010-07-21 22:06:33 +04:00
|
|
|
void
|
2010-07-22 01:17:33 +04:00
|
|
|
BasicThebesLayerBuffer::DrawTo(ThebesLayer* aLayer,
|
|
|
|
gfxContext* aTarget,
|
|
|
|
float aOpacity)
|
2010-07-21 22:06:33 +04:00
|
|
|
{
|
|
|
|
aTarget->Save();
|
2010-09-17 23:29:52 +04:00
|
|
|
// If the entire buffer is valid, we can just draw the whole thing,
|
|
|
|
// no need to clip. But we'll still clip if clipping is cheap ---
|
|
|
|
// that might let us copy a smaller region of the buffer.
|
2011-08-12 02:44:50 +04:00
|
|
|
// Also clip to the visible region if we're told to.
|
2010-09-17 23:29:52 +04:00
|
|
|
if (!aLayer->GetValidRegion().Contains(BufferRect()) ||
|
2011-08-12 02:44:50 +04:00
|
|
|
(ToData(aLayer)->GetClipToVisibleRegion() &&
|
|
|
|
!aLayer->GetVisibleRegion().Contains(BufferRect())) ||
|
2011-05-30 07:48:13 +04:00
|
|
|
IsClippingCheap(aTarget, aLayer->GetEffectiveVisibleRegion())) {
|
2010-09-17 23:29:52 +04:00
|
|
|
// We don't want to draw invalid stuff, so we need to clip. Might as
|
|
|
|
// well clip to the smallest area possible --- the visible region.
|
2010-09-24 07:09:00 +04:00
|
|
|
// Bug 599189 if there is a non-integer-translation transform in aTarget,
|
2011-05-30 07:48:13 +04:00
|
|
|
// we might sample pixels outside GetEffectiveVisibleRegion(), which is wrong
|
2010-09-24 07:09:00 +04:00
|
|
|
// and may cause gray lines.
|
2011-05-30 07:48:13 +04:00
|
|
|
gfxUtils::ClipToRegionSnapped(aTarget, aLayer->GetEffectiveVisibleRegion());
|
2010-09-17 23:29:52 +04:00
|
|
|
}
|
2011-06-22 16:11:28 +04:00
|
|
|
DrawBufferWithRotation(aTarget, aOpacity);
|
2010-07-21 22:06:33 +04:00
|
|
|
aTarget->Restore();
|
2010-03-01 10:56:18 +03:00
|
|
|
}
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
already_AddRefed<gfxASurface>
|
|
|
|
BasicThebesLayerBuffer::CreateBuffer(ContentType aType,
|
2011-04-01 01:33:46 +04:00
|
|
|
const nsIntSize& aSize, PRUint32 aFlags)
|
2010-07-22 01:17:33 +04:00
|
|
|
{
|
|
|
|
return mLayer->CreateBuffer(aType, aSize);
|
|
|
|
}
|
|
|
|
|
2010-11-05 10:17:07 +03:00
|
|
|
void
|
|
|
|
BasicThebesLayerBuffer::SetBackingBufferAndUpdateFrom(
|
|
|
|
gfxASurface* aBuffer,
|
|
|
|
gfxASurface* aSource, const nsIntRect& aRect, const nsIntPoint& aRotation,
|
2011-06-22 16:11:28 +04:00
|
|
|
const nsIntRegion& aUpdateRegion)
|
2010-11-05 10:17:07 +03:00
|
|
|
{
|
|
|
|
SetBackingBuffer(aBuffer, aRect, aRotation);
|
|
|
|
nsRefPtr<gfxContext> destCtx =
|
2011-06-22 16:11:28 +04:00
|
|
|
GetContextForQuadrantUpdate(aUpdateRegion.GetBounds());
|
2010-11-05 10:17:07 +03:00
|
|
|
destCtx->SetOperator(gfxContext::OPERATOR_SOURCE);
|
|
|
|
if (IsClippingCheap(destCtx, aUpdateRegion)) {
|
|
|
|
gfxUtils::ClipToRegion(destCtx, aUpdateRegion);
|
|
|
|
}
|
|
|
|
|
|
|
|
BasicThebesLayerBuffer srcBuffer(aSource, aRect, aRotation);
|
2011-06-22 16:11:28 +04:00
|
|
|
srcBuffer.DrawBufferWithRotation(destCtx, 1.0);
|
2010-11-05 10:17:07 +03:00
|
|
|
}
|
|
|
|
|
2011-05-30 07:48:13 +04:00
|
|
|
class BasicImageLayer : public ImageLayer, public BasicImplData {
|
2010-03-02 02:09:35 +03:00
|
|
|
public:
|
|
|
|
BasicImageLayer(BasicLayerManager* aLayerManager) :
|
2010-09-21 10:57:25 +04:00
|
|
|
ImageLayer(aLayerManager, static_cast<BasicImplData*>(this)),
|
|
|
|
mSize(-1, -1)
|
2010-03-02 02:09:35 +03:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(BasicImageLayer);
|
|
|
|
}
|
|
|
|
virtual ~BasicImageLayer()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(BasicImageLayer);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void SetVisibleRegion(const nsIntRegion& aRegion)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(BasicManager()->InConstruction(),
|
|
|
|
"Can only set properties in construction phase");
|
2010-03-04 00:37:04 +03:00
|
|
|
ImageLayer::SetVisibleRegion(aRegion);
|
2010-03-02 02:09:35 +03:00
|
|
|
}
|
|
|
|
|
2011-02-17 01:43:30 +03:00
|
|
|
virtual void Paint(gfxContext* aContext);
|
2010-03-02 02:09:35 +03:00
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
static void PaintContext(gfxPattern* aPattern,
|
2011-01-26 09:26:37 +03:00
|
|
|
const nsIntRegion& aVisible,
|
|
|
|
const nsIntRect* aTileSourceRect,
|
2010-07-22 01:17:33 +04:00
|
|
|
float aOpacity,
|
|
|
|
gfxContext* aContext);
|
|
|
|
|
2010-03-02 02:09:35 +03:00
|
|
|
protected:
|
|
|
|
BasicLayerManager* BasicManager()
|
|
|
|
{
|
|
|
|
return static_cast<BasicLayerManager*>(mManager);
|
|
|
|
}
|
2010-07-22 01:17:33 +04:00
|
|
|
|
|
|
|
already_AddRefed<gfxPattern>
|
|
|
|
GetAndPaintCurrentImage(gfxContext* aContext,
|
|
|
|
float aOpacity);
|
|
|
|
|
|
|
|
gfxIntSize mSize;
|
2010-03-02 02:09:35 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
2011-02-17 01:43:30 +03:00
|
|
|
BasicImageLayer::Paint(gfxContext* aContext)
|
2010-07-22 01:17:33 +04:00
|
|
|
{
|
2011-05-18 15:24:52 +04:00
|
|
|
if (IsHidden())
|
|
|
|
return;
|
2010-11-08 12:06:15 +03:00
|
|
|
nsRefPtr<gfxPattern> dontcare =
|
|
|
|
GetAndPaintCurrentImage(aContext, GetEffectiveOpacity());
|
2010-07-22 01:17:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<gfxPattern>
|
|
|
|
BasicImageLayer::GetAndPaintCurrentImage(gfxContext* aContext,
|
|
|
|
float aOpacity)
|
2010-03-02 02:09:35 +03:00
|
|
|
{
|
|
|
|
if (!mContainer)
|
2010-07-22 01:17:33 +04:00
|
|
|
return nsnull;
|
2010-03-02 02:09:35 +03:00
|
|
|
|
2011-03-24 01:28:57 +03:00
|
|
|
nsRefPtr<Image> image = mContainer->GetCurrentImage();
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
nsRefPtr<gfxASurface> surface = mContainer->GetCurrentAsSurface(&mSize);
|
2010-03-02 02:09:35 +03:00
|
|
|
if (!surface) {
|
2010-07-22 01:17:33 +04:00
|
|
|
return nsnull;
|
2010-03-02 02:09:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<gfxPattern> pat = new gfxPattern(surface);
|
|
|
|
if (!pat) {
|
2010-07-22 01:17:33 +04:00
|
|
|
return nsnull;
|
2010-03-02 02:09:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
pat->SetFilter(mFilter);
|
|
|
|
|
2011-01-27 01:12:06 +03:00
|
|
|
// The visible region can extend outside the image. If we're not
|
|
|
|
// tiling, we don't want to draw into that area, so just draw within
|
|
|
|
// the image bounds.
|
|
|
|
const nsIntRect* tileSrcRect = GetTileSourceRect();
|
2011-05-30 07:48:13 +04:00
|
|
|
AutoSetOperator setOperator(aContext, GetOperator());
|
2011-01-27 01:12:06 +03:00
|
|
|
PaintContext(pat,
|
|
|
|
tileSrcRect ? GetVisibleRegion() : nsIntRegion(nsIntRect(0, 0, mSize.width, mSize.height)),
|
|
|
|
tileSrcRect,
|
2011-03-24 01:28:57 +03:00
|
|
|
aOpacity, aContext);
|
|
|
|
|
|
|
|
GetContainer()->NotifyPaintedImage(image);
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
return pat.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ void
|
|
|
|
BasicImageLayer::PaintContext(gfxPattern* aPattern,
|
2011-01-26 09:26:37 +03:00
|
|
|
const nsIntRegion& aVisible,
|
|
|
|
const nsIntRect* aTileSourceRect,
|
2010-07-22 01:17:33 +04:00
|
|
|
float aOpacity,
|
|
|
|
gfxContext* aContext)
|
|
|
|
{
|
2010-03-02 02:09:35 +03:00
|
|
|
// Set PAD mode so that when the video is being scaled, we do not sample
|
|
|
|
// outside the bounds of the video image.
|
|
|
|
gfxPattern::GraphicsExtend extend = gfxPattern::EXTEND_PAD;
|
|
|
|
|
|
|
|
// PAD is slow with X11 and Quartz surfaces, so prefer speed over correctness
|
|
|
|
// and use NONE.
|
|
|
|
nsRefPtr<gfxASurface> target = aContext->CurrentSurface();
|
|
|
|
gfxASurface::gfxSurfaceType type = target->GetType();
|
|
|
|
if (type == gfxASurface::SurfaceTypeXlib ||
|
|
|
|
type == gfxASurface::SurfaceTypeXcb ||
|
|
|
|
type == gfxASurface::SurfaceTypeQuartz) {
|
|
|
|
extend = gfxPattern::EXTEND_NONE;
|
|
|
|
}
|
|
|
|
|
2011-01-26 09:26:37 +03:00
|
|
|
if (!aTileSourceRect) {
|
|
|
|
aContext->NewPath();
|
|
|
|
// No need to snap here; our transform has already taken care of it.
|
|
|
|
// XXX true for arbitrary regions? Don't care yet though
|
|
|
|
gfxUtils::PathFromRegion(aContext, aVisible);
|
|
|
|
aPattern->SetExtend(extend);
|
|
|
|
aContext->SetPattern(aPattern);
|
|
|
|
aContext->FillWithOpacity(aOpacity);
|
|
|
|
} else {
|
|
|
|
nsRefPtr<gfxASurface> source = aPattern->GetSurface();
|
|
|
|
NS_ABORT_IF_FALSE(source, "Expecting a surface pattern");
|
|
|
|
gfxIntSize sourceSize = source->GetSize();
|
|
|
|
nsIntRect sourceRect(0, 0, sourceSize.width, sourceSize.height);
|
|
|
|
NS_ABORT_IF_FALSE(sourceRect == *aTileSourceRect,
|
|
|
|
"Cowardly refusing to create a temporary surface for tiling");
|
2010-03-02 02:09:35 +03:00
|
|
|
|
2011-01-26 09:26:37 +03:00
|
|
|
gfxContextAutoSaveRestore saveRestore(aContext);
|
|
|
|
|
|
|
|
aContext->NewPath();
|
|
|
|
gfxUtils::PathFromRegion(aContext, aVisible);
|
|
|
|
|
|
|
|
aPattern->SetExtend(gfxPattern::EXTEND_REPEAT);
|
|
|
|
aContext->SetPattern(aPattern);
|
|
|
|
aContext->FillWithOpacity(aOpacity);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reset extend mode for callers that need to reuse the pattern
|
|
|
|
aPattern->SetExtend(extend);
|
2010-03-02 02:09:35 +03:00
|
|
|
}
|
|
|
|
|
2011-05-30 07:48:13 +04:00
|
|
|
class BasicColorLayer : public ColorLayer, public BasicImplData {
|
2010-05-13 04:56:11 +04:00
|
|
|
public:
|
|
|
|
BasicColorLayer(BasicLayerManager* aLayerManager) :
|
|
|
|
ColorLayer(aLayerManager, static_cast<BasicImplData*>(this))
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(BasicColorLayer);
|
|
|
|
}
|
|
|
|
virtual ~BasicColorLayer()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(BasicColorLayer);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void SetVisibleRegion(const nsIntRegion& aRegion)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(BasicManager()->InConstruction(),
|
|
|
|
"Can only set properties in construction phase");
|
2010-03-04 00:37:04 +03:00
|
|
|
ColorLayer::SetVisibleRegion(aRegion);
|
2010-05-13 04:56:11 +04:00
|
|
|
}
|
|
|
|
|
2011-02-17 01:43:30 +03:00
|
|
|
virtual void Paint(gfxContext* aContext)
|
2010-10-14 02:55:45 +04:00
|
|
|
{
|
2011-05-18 15:24:52 +04:00
|
|
|
if (IsHidden())
|
|
|
|
return;
|
2011-05-30 07:48:13 +04:00
|
|
|
AutoSetOperator setOperator(aContext, GetOperator());
|
2010-11-08 12:06:15 +03:00
|
|
|
PaintColorTo(mColor, GetEffectiveOpacity(), aContext);
|
2010-10-14 02:55:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void PaintColorTo(gfxRGBA aColor, float aOpacity,
|
|
|
|
gfxContext* aContext);
|
2010-05-13 04:56:11 +04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
BasicLayerManager* BasicManager()
|
|
|
|
{
|
|
|
|
return static_cast<BasicLayerManager*>(mManager);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-10-14 02:55:45 +04:00
|
|
|
/*static*/ void
|
|
|
|
BasicColorLayer::PaintColorTo(gfxRGBA aColor, float aOpacity,
|
|
|
|
gfxContext* aContext)
|
2010-05-13 04:56:11 +04:00
|
|
|
{
|
2010-10-14 02:55:45 +04:00
|
|
|
aContext->SetColor(aColor);
|
2010-07-16 01:08:04 +04:00
|
|
|
aContext->Paint(aOpacity);
|
2010-05-13 04:56:11 +04:00
|
|
|
}
|
|
|
|
|
2010-05-18 08:04:22 +04:00
|
|
|
class BasicCanvasLayer : public CanvasLayer,
|
2011-05-30 07:48:13 +04:00
|
|
|
public BasicImplData
|
2010-05-18 08:04:22 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
BasicCanvasLayer(BasicLayerManager* aLayerManager) :
|
|
|
|
CanvasLayer(aLayerManager, static_cast<BasicImplData*>(this))
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(BasicCanvasLayer);
|
|
|
|
}
|
|
|
|
virtual ~BasicCanvasLayer()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(BasicCanvasLayer);
|
|
|
|
}
|
|
|
|
|
2010-07-16 01:08:04 +04:00
|
|
|
virtual void SetVisibleRegion(const nsIntRegion& aRegion)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(BasicManager()->InConstruction(),
|
|
|
|
"Can only set properties in construction phase");
|
|
|
|
CanvasLayer::SetVisibleRegion(aRegion);
|
|
|
|
}
|
|
|
|
|
2010-05-18 08:04:22 +04:00
|
|
|
virtual void Initialize(const Data& aData);
|
2011-02-17 01:43:30 +03:00
|
|
|
virtual void Paint(gfxContext* aContext);
|
2010-05-18 08:04:22 +04:00
|
|
|
|
2011-01-26 01:18:41 +03:00
|
|
|
virtual void PaintWithOpacity(gfxContext* aContext,
|
|
|
|
float aOpacity);
|
|
|
|
|
2010-05-18 08:04:22 +04:00
|
|
|
protected:
|
2010-07-16 01:08:04 +04:00
|
|
|
BasicLayerManager* BasicManager()
|
|
|
|
{
|
|
|
|
return static_cast<BasicLayerManager*>(mManager);
|
|
|
|
}
|
2011-06-10 05:17:02 +04:00
|
|
|
void UpdateSurface(gfxASurface* aDestSurface = nsnull);
|
2010-07-16 01:08:04 +04:00
|
|
|
|
2010-05-18 08:04:22 +04:00
|
|
|
nsRefPtr<gfxASurface> mSurface;
|
|
|
|
nsRefPtr<mozilla::gl::GLContext> mGLContext;
|
2011-06-24 21:41:18 +04:00
|
|
|
mozilla::RefPtr<mozilla::gfx::DrawTarget> mDrawTarget;
|
|
|
|
|
2010-07-19 09:01:14 +04:00
|
|
|
PRUint32 mCanvasFramebuffer;
|
2010-05-18 08:04:22 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mGLBufferIsPremultiplied;
|
|
|
|
bool mNeedsYFlip;
|
2010-05-18 08:04:22 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
BasicCanvasLayer::Initialize(const Data& aData)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mSurface == nsnull, "BasicCanvasLayer::Initialize called twice!");
|
|
|
|
|
|
|
|
if (aData.mSurface) {
|
|
|
|
mSurface = aData.mSurface;
|
|
|
|
NS_ASSERTION(aData.mGLContext == nsnull,
|
|
|
|
"CanvasLayer can't have both surface and GLContext");
|
2011-10-17 18:59:28 +04:00
|
|
|
mNeedsYFlip = false;
|
2010-05-18 08:04:22 +04:00
|
|
|
} else if (aData.mGLContext) {
|
2010-07-19 09:01:14 +04:00
|
|
|
NS_ASSERTION(aData.mGLContext->IsOffscreen(), "canvas gl context isn't offscreen");
|
2010-05-18 08:04:22 +04:00
|
|
|
mGLContext = aData.mGLContext;
|
|
|
|
mGLBufferIsPremultiplied = aData.mGLBufferIsPremultiplied;
|
2010-07-19 09:01:14 +04:00
|
|
|
mCanvasFramebuffer = mGLContext->GetOffscreenFBO();
|
2011-10-17 18:59:28 +04:00
|
|
|
mNeedsYFlip = true;
|
2011-06-24 21:41:18 +04:00
|
|
|
} else if (aData.mDrawTarget) {
|
|
|
|
mDrawTarget = aData.mDrawTarget;
|
|
|
|
mSurface = gfxPlatform::GetPlatform()->GetThebesSurfaceForDrawTarget(mDrawTarget);
|
2011-10-17 18:59:28 +04:00
|
|
|
mNeedsYFlip = false;
|
2010-05-18 08:04:22 +04:00
|
|
|
} else {
|
2011-06-24 21:41:18 +04:00
|
|
|
NS_ERROR("CanvasLayer created without mSurface, mDrawTarget or mGLContext?");
|
2010-05-18 08:04:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
mBounds.SetRect(0, 0, aData.mSize.width, aData.mSize.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-06-10 05:17:02 +04:00
|
|
|
BasicCanvasLayer::UpdateSurface(gfxASurface* aDestSurface)
|
2010-05-18 08:04:22 +04:00
|
|
|
{
|
2011-06-24 21:41:18 +04:00
|
|
|
if (mDrawTarget) {
|
|
|
|
mDrawTarget->Flush();
|
|
|
|
}
|
|
|
|
|
2011-06-10 05:17:02 +04:00
|
|
|
if (!mGLContext && aDestSurface) {
|
|
|
|
nsRefPtr<gfxContext> tmpCtx = new gfxContext(aDestSurface);
|
|
|
|
tmpCtx->SetOperator(gfxContext::OPERATOR_SOURCE);
|
|
|
|
BasicCanvasLayer::PaintWithOpacity(tmpCtx, 1.0f);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-28 03:59:46 +04:00
|
|
|
if (!mDirty)
|
|
|
|
return;
|
2011-10-17 18:59:28 +04:00
|
|
|
mDirty = false;
|
2010-05-18 08:04:22 +04:00
|
|
|
|
|
|
|
if (mGLContext) {
|
2011-06-10 05:17:02 +04:00
|
|
|
if (aDestSurface && aDestSurface->GetType() != gfxASurface::SurfaceTypeImage) {
|
|
|
|
NS_ASSERTION(aDestSurface->GetType() == gfxASurface::SurfaceTypeImage,
|
|
|
|
"Destination surface must be ImageSurface type");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-27 15:00:17 +04:00
|
|
|
// We need to read from the GLContext
|
|
|
|
mGLContext->MakeCurrent();
|
|
|
|
|
|
|
|
#if defined (MOZ_X11) && defined (MOZ_EGL_XRENDER_COMPOSITE)
|
2011-10-19 23:31:33 +04:00
|
|
|
mGLContext->fFinish();
|
2011-07-27 15:00:17 +04:00
|
|
|
gfxASurface* offscreenSurface = mGLContext->GetOffscreenPixmapSurface();
|
|
|
|
|
|
|
|
// XRender can only blend premuliplied alpha, so only allow xrender
|
|
|
|
// path if we have premultiplied alpha or opaque content.
|
|
|
|
if (offscreenSurface && (mGLBufferIsPremultiplied || (GetContentFlags() & CONTENT_OPAQUE))) {
|
|
|
|
mSurface = offscreenSurface;
|
|
|
|
mNeedsYFlip = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
2011-06-10 05:17:02 +04:00
|
|
|
nsRefPtr<gfxImageSurface> isurf = aDestSurface ?
|
|
|
|
static_cast<gfxImageSurface*>(aDestSurface) :
|
|
|
|
new gfxImageSurface(gfxIntSize(mBounds.width, mBounds.height),
|
|
|
|
(GetContentFlags() & CONTENT_OPAQUE)
|
|
|
|
? gfxASurface::ImageFormatRGB24
|
|
|
|
: gfxASurface::ImageFormatARGB32);
|
|
|
|
|
2010-05-18 08:04:22 +04:00
|
|
|
if (!isurf || isurf->CairoStatus() != 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(isurf->Stride() == mBounds.width * 4, "gfxImageSurface stride isn't what we expect!");
|
|
|
|
|
|
|
|
// We have to flush to ensure that any buffered GL operations are
|
|
|
|
// in the framebuffer before we read.
|
|
|
|
mGLContext->fFlush();
|
|
|
|
|
2010-07-19 09:01:14 +04:00
|
|
|
PRUint32 currentFramebuffer = 0;
|
|
|
|
|
|
|
|
mGLContext->fGetIntegerv(LOCAL_GL_FRAMEBUFFER_BINDING, (GLint*)¤tFramebuffer);
|
|
|
|
|
|
|
|
// Make sure that we read pixels from the correct framebuffer, regardless
|
|
|
|
// of what's currently bound.
|
|
|
|
if (currentFramebuffer != mCanvasFramebuffer)
|
|
|
|
mGLContext->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, mCanvasFramebuffer);
|
|
|
|
|
2010-08-07 09:09:18 +04:00
|
|
|
mGLContext->ReadPixelsIntoImageSurface(0, 0,
|
|
|
|
mBounds.width, mBounds.height,
|
|
|
|
isurf);
|
2010-05-18 08:04:22 +04:00
|
|
|
|
2010-07-19 09:01:14 +04:00
|
|
|
// Put back the previous framebuffer binding.
|
|
|
|
if (currentFramebuffer != mCanvasFramebuffer)
|
|
|
|
mGLContext->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, currentFramebuffer);
|
|
|
|
|
2010-05-18 08:04:22 +04:00
|
|
|
// If the underlying GLContext doesn't have a framebuffer into which
|
|
|
|
// premultiplied values were written, we have to do this ourselves here.
|
|
|
|
// Note that this is a WebGL attribute; GL itself has no knowledge of
|
|
|
|
// premultiplied or unpremultiplied alpha.
|
|
|
|
if (!mGLBufferIsPremultiplied)
|
|
|
|
gfxUtils::PremultiplyImageSurface(isurf);
|
|
|
|
|
|
|
|
// stick our surface into mSurface, so that the Paint() path is the same
|
2011-06-10 05:17:02 +04:00
|
|
|
if (!aDestSurface) {
|
|
|
|
mSurface = isurf;
|
|
|
|
}
|
2010-05-18 08:04:22 +04:00
|
|
|
}
|
|
|
|
}
|
2011-07-27 15:00:17 +04:00
|
|
|
}
|
2010-05-18 08:04:22 +04:00
|
|
|
|
|
|
|
void
|
2011-02-17 01:43:30 +03:00
|
|
|
BasicCanvasLayer::Paint(gfxContext* aContext)
|
2011-01-26 01:18:41 +03:00
|
|
|
{
|
2011-05-18 15:24:52 +04:00
|
|
|
if (IsHidden())
|
|
|
|
return;
|
2011-03-28 03:59:46 +04:00
|
|
|
UpdateSurface();
|
2011-03-28 03:59:46 +04:00
|
|
|
FireDidTransactionCallback();
|
2011-01-26 01:18:41 +03:00
|
|
|
PaintWithOpacity(aContext, GetEffectiveOpacity());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BasicCanvasLayer::PaintWithOpacity(gfxContext* aContext,
|
|
|
|
float aOpacity)
|
2010-05-18 08:04:22 +04:00
|
|
|
{
|
2010-07-22 01:17:33 +04:00
|
|
|
NS_ASSERTION(BasicManager()->InDrawing(),
|
|
|
|
"Can only draw in drawing phase");
|
|
|
|
|
2010-05-18 08:04:22 +04:00
|
|
|
nsRefPtr<gfxPattern> pat = new gfxPattern(mSurface);
|
|
|
|
|
2010-05-18 08:04:22 +04:00
|
|
|
pat->SetFilter(mFilter);
|
2010-05-19 07:04:32 +04:00
|
|
|
pat->SetExtend(gfxPattern::EXTEND_PAD);
|
2010-05-18 08:04:22 +04:00
|
|
|
|
2010-05-18 08:04:22 +04:00
|
|
|
gfxMatrix m;
|
|
|
|
if (mNeedsYFlip) {
|
|
|
|
m = aContext->CurrentMatrix();
|
|
|
|
aContext->Translate(gfxPoint(0.0, mBounds.height));
|
|
|
|
aContext->Scale(1.0, -1.0);
|
|
|
|
}
|
|
|
|
|
2011-07-27 15:00:17 +04:00
|
|
|
// If content opaque, then save off current operator and set to source.
|
|
|
|
// This ensures that alpha is not applied even if the source surface
|
|
|
|
// has an alpha channel
|
|
|
|
gfxContext::GraphicsOperator savedOp;
|
|
|
|
if (GetContentFlags() & CONTENT_OPAQUE) {
|
|
|
|
savedOp = aContext->CurrentOperator();
|
|
|
|
aContext->SetOperator(gfxContext::OPERATOR_SOURCE);
|
|
|
|
}
|
|
|
|
|
2011-05-30 07:48:13 +04:00
|
|
|
AutoSetOperator setOperator(aContext, GetOperator());
|
2010-05-18 08:04:22 +04:00
|
|
|
aContext->NewPath();
|
2010-11-08 12:06:15 +03:00
|
|
|
// No need to snap here; our transform is already set up to snap our rect
|
|
|
|
aContext->Rectangle(gfxRect(0, 0, mBounds.width, mBounds.height));
|
|
|
|
aContext->SetPattern(pat);
|
2011-01-26 09:26:37 +03:00
|
|
|
aContext->FillWithOpacity(aOpacity);
|
2010-05-18 08:04:22 +04:00
|
|
|
|
2011-07-27 15:00:17 +04:00
|
|
|
#if defined (MOZ_X11) && defined (MOZ_EGL_XRENDER_COMPOSITE)
|
|
|
|
if (mGLContext) {
|
|
|
|
// Wait for X to complete all operations before continuing
|
|
|
|
// Otherwise gl context could get cleared before X is done.
|
|
|
|
mGLContext->WaitNative();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Restore surface operator
|
|
|
|
if (GetContentFlags() & CONTENT_OPAQUE) {
|
|
|
|
aContext->SetOperator(savedOp);
|
|
|
|
}
|
|
|
|
|
2010-05-18 08:04:22 +04:00
|
|
|
if (mNeedsYFlip) {
|
|
|
|
aContext->SetMatrix(m);
|
|
|
|
}
|
2010-05-18 08:04:22 +04:00
|
|
|
}
|
|
|
|
|
2011-02-17 01:43:30 +03:00
|
|
|
class BasicReadbackLayer : public ReadbackLayer,
|
2011-05-30 07:48:13 +04:00
|
|
|
public BasicImplData
|
2011-02-17 01:43:30 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
BasicReadbackLayer(BasicLayerManager* aLayerManager) :
|
|
|
|
ReadbackLayer(aLayerManager, static_cast<BasicImplData*>(this))
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(BasicReadbackLayer);
|
|
|
|
}
|
|
|
|
virtual ~BasicReadbackLayer()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(BasicReadbackLayer);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void SetVisibleRegion(const nsIntRegion& aRegion)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(BasicManager()->InConstruction(),
|
|
|
|
"Can only set properties in construction phase");
|
|
|
|
ReadbackLayer::SetVisibleRegion(aRegion);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
BasicLayerManager* BasicManager()
|
|
|
|
{
|
|
|
|
return static_cast<BasicLayerManager*>(mManager);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-07-16 01:08:05 +04:00
|
|
|
static nsIntRect
|
|
|
|
ToOutsideIntRect(const gfxRect &aRect)
|
|
|
|
{
|
|
|
|
gfxRect r = aRect;
|
|
|
|
r.RoundOut();
|
2011-04-19 07:07:21 +04:00
|
|
|
return nsIntRect(r.X(), r.Y(), r.Width(), r.Height());
|
2010-07-16 01:08:05 +04:00
|
|
|
}
|
|
|
|
|
2010-11-17 02:33:56 +03:00
|
|
|
static nsIntRect
|
|
|
|
ToInsideIntRect(const gfxRect& aRect)
|
|
|
|
{
|
|
|
|
gfxRect r = aRect;
|
|
|
|
r.RoundIn();
|
2011-04-19 07:07:21 +04:00
|
|
|
return nsIntRect(r.X(), r.Y(), r.Width(), r.Height());
|
2010-11-17 02:33:56 +03:00
|
|
|
}
|
|
|
|
|
2010-07-16 01:08:10 +04:00
|
|
|
BasicLayerManager::BasicLayerManager(nsIWidget* aWidget) :
|
2010-03-01 10:56:18 +03:00
|
|
|
#ifdef DEBUG
|
2010-07-22 01:17:33 +04:00
|
|
|
mPhase(PHASE_NONE),
|
2010-03-01 10:56:18 +03:00
|
|
|
#endif
|
2011-06-22 16:11:28 +04:00
|
|
|
mWidget(aWidget)
|
2011-10-17 18:59:28 +04:00
|
|
|
, mDoubleBuffering(BUFFER_NONE), mUsingDefaultTarget(false)
|
|
|
|
, mCachedSurfaceInUse(false)
|
2010-12-27 09:12:17 +03:00
|
|
|
, mTransactionIncomplete(false)
|
2010-07-16 01:08:10 +04:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(BasicLayerManager);
|
|
|
|
NS_ASSERTION(aWidget, "Must provide a widget");
|
|
|
|
}
|
|
|
|
|
|
|
|
BasicLayerManager::BasicLayerManager() :
|
|
|
|
#ifdef DEBUG
|
2010-07-22 01:17:33 +04:00
|
|
|
mPhase(PHASE_NONE),
|
2010-07-16 01:08:10 +04:00
|
|
|
#endif
|
2010-07-22 01:17:33 +04:00
|
|
|
mWidget(nsnull)
|
2011-10-17 18:59:28 +04:00
|
|
|
, mDoubleBuffering(BUFFER_NONE), mUsingDefaultTarget(false)
|
2010-03-01 10:56:18 +03:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(BasicLayerManager);
|
|
|
|
}
|
|
|
|
|
|
|
|
BasicLayerManager::~BasicLayerManager()
|
|
|
|
{
|
2010-03-04 00:37:04 +03:00
|
|
|
NS_ASSERTION(!InTransaction(), "Died during transaction?");
|
2010-07-22 01:17:33 +04:00
|
|
|
|
2010-08-20 07:40:49 +04:00
|
|
|
ClearCachedResources();
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
mRoot = nsnull;
|
|
|
|
|
2010-03-01 10:56:18 +03:00
|
|
|
MOZ_COUNT_DTOR(BasicLayerManager);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-07-16 01:08:04 +04:00
|
|
|
BasicLayerManager::SetDefaultTarget(gfxContext* aContext,
|
|
|
|
BufferMode aDoubleBuffering)
|
2010-03-01 10:56:18 +03:00
|
|
|
{
|
2010-03-04 00:37:04 +03:00
|
|
|
NS_ASSERTION(!InTransaction(),
|
2010-03-01 10:56:18 +03:00
|
|
|
"Must set default target outside transaction");
|
|
|
|
mDefaultTarget = aContext;
|
2010-07-16 01:08:04 +04:00
|
|
|
mDoubleBuffering = aDoubleBuffering;
|
2010-03-01 10:56:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BasicLayerManager::BeginTransaction()
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
mUsingDefaultTarget = true;
|
2010-07-16 01:08:04 +04:00
|
|
|
BeginTransactionWithTarget(mDefaultTarget);
|
2010-03-01 10:56:18 +03:00
|
|
|
}
|
|
|
|
|
2010-07-16 01:08:04 +04:00
|
|
|
already_AddRefed<gfxContext>
|
|
|
|
BasicLayerManager::PushGroupWithCachedSurface(gfxContext *aTarget,
|
2011-05-30 07:48:29 +04:00
|
|
|
gfxASurface::gfxContentType aContent)
|
2010-07-16 01:08:04 +04:00
|
|
|
{
|
2011-05-30 07:48:29 +04:00
|
|
|
if (mCachedSurfaceInUse) {
|
|
|
|
aTarget->PushGroup(aContent);
|
|
|
|
nsRefPtr<gfxContext> result = aTarget;
|
|
|
|
return result.forget();
|
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
mCachedSurfaceInUse = true;
|
2011-05-30 07:48:29 +04:00
|
|
|
|
2010-07-16 01:08:04 +04:00
|
|
|
gfxContextMatrixAutoSaveRestore saveMatrix(aTarget);
|
|
|
|
aTarget->IdentityMatrix();
|
|
|
|
|
|
|
|
nsRefPtr<gfxASurface> currentSurf = aTarget->CurrentSurface();
|
|
|
|
gfxRect clip = aTarget->GetClipExtents();
|
|
|
|
clip.RoundOut();
|
|
|
|
|
2011-05-30 07:48:29 +04:00
|
|
|
nsRefPtr<gfxContext> ctx = mCachedSurface.Get(aContent, clip, currentSurf);
|
2010-07-16 01:08:04 +04:00
|
|
|
/* Align our buffer for the original surface */
|
2011-05-30 07:48:29 +04:00
|
|
|
ctx->SetMatrix(saveMatrix.Matrix());
|
2010-07-16 01:08:04 +04:00
|
|
|
return ctx.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-05-30 07:48:29 +04:00
|
|
|
BasicLayerManager::PopGroupToSourceWithCachedSurface(gfxContext *aTarget, gfxContext *aPushed)
|
2010-07-16 01:08:04 +04:00
|
|
|
{
|
2011-05-30 07:48:29 +04:00
|
|
|
if (!aTarget)
|
2010-07-16 01:08:04 +04:00
|
|
|
return;
|
2011-05-30 07:48:29 +04:00
|
|
|
nsRefPtr<gfxASurface> current = aPushed->CurrentSurface();
|
|
|
|
if (mCachedSurface.IsSurface(current)) {
|
|
|
|
gfxContextMatrixAutoSaveRestore saveMatrix(aTarget);
|
|
|
|
aTarget->IdentityMatrix();
|
|
|
|
aTarget->SetSource(current);
|
2011-10-17 18:59:28 +04:00
|
|
|
mCachedSurfaceInUse = false;
|
2011-05-30 07:48:29 +04:00
|
|
|
} else {
|
|
|
|
aTarget->PopGroupToSource();
|
|
|
|
}
|
2010-07-16 01:08:04 +04:00
|
|
|
}
|
|
|
|
|
2010-03-01 10:56:18 +03:00
|
|
|
void
|
|
|
|
BasicLayerManager::BeginTransactionWithTarget(gfxContext* aTarget)
|
|
|
|
{
|
2010-07-21 22:06:33 +04:00
|
|
|
#ifdef MOZ_LAYERS_HAVE_LOG
|
|
|
|
MOZ_LAYERS_LOG(("[----- BeginTransaction"));
|
|
|
|
Log();
|
|
|
|
#endif
|
|
|
|
|
2010-03-04 00:37:04 +03:00
|
|
|
NS_ASSERTION(!InTransaction(), "Nested transactions not allowed");
|
2010-03-01 10:56:18 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
mPhase = PHASE_CONSTRUCTION;
|
|
|
|
#endif
|
|
|
|
mTarget = aTarget;
|
|
|
|
}
|
|
|
|
|
2010-11-17 02:33:56 +03:00
|
|
|
static void
|
|
|
|
TransformIntRect(nsIntRect& aRect, const gfxMatrix& aMatrix,
|
|
|
|
nsIntRect (*aRoundMethod)(const gfxRect&))
|
|
|
|
{
|
|
|
|
gfxRect gr = gfxRect(aRect.x, aRect.y, aRect.width, aRect.height);
|
|
|
|
gr = aMatrix.TransformBounds(gr);
|
|
|
|
aRect = (*aRoundMethod)(gr);
|
|
|
|
}
|
|
|
|
|
2011-05-18 15:24:52 +04:00
|
|
|
/**
|
|
|
|
* This function assumes that GetEffectiveTransform transforms
|
|
|
|
* all layers to the same coordinate system (the "root coordinate system").
|
|
|
|
* It can't be used as is by accelerated layers because of intermediate surfaces.
|
|
|
|
* This must set the hidden flag to true or false on *all* layers in the subtree.
|
2011-05-30 07:48:23 +04:00
|
|
|
* It also sets the operator for all layers to "OVER".
|
2011-08-12 02:44:50 +04:00
|
|
|
* It clears mClipToVisibleRegion on all layers.
|
2011-05-18 15:24:52 +04:00
|
|
|
* @param aClipRect the cliprect, in the root coordinate system. We assume
|
|
|
|
* that any layer drawing is clipped to this rect. It is therefore not
|
|
|
|
* allowed to add to the opaque region outside that rect.
|
|
|
|
* @param aDirtyRect the dirty rect that will be painted, in the root
|
|
|
|
* coordinate system. Layers outside this rect should be hidden.
|
|
|
|
* @param aOpaqueRegion the opaque region covering aLayer, in the
|
|
|
|
* root coordinate system.
|
|
|
|
*/
|
2011-05-30 07:48:08 +04:00
|
|
|
enum {
|
|
|
|
ALLOW_OPAQUE = 0x01,
|
|
|
|
};
|
2010-11-17 02:33:56 +03:00
|
|
|
static void
|
2011-05-30 07:48:08 +04:00
|
|
|
MarkLayersHidden(Layer* aLayer, const nsIntRect& aClipRect,
|
|
|
|
const nsIntRect& aDirtyRect,
|
|
|
|
nsIntRegion& aOpaqueRegion,
|
|
|
|
PRUint32 aFlags)
|
2010-11-17 02:33:56 +03:00
|
|
|
{
|
|
|
|
nsIntRect newClipRect(aClipRect);
|
2011-05-30 07:48:08 +04:00
|
|
|
PRUint32 newFlags = aFlags;
|
2010-11-17 02:33:56 +03:00
|
|
|
|
|
|
|
// Allow aLayer or aLayer's descendants to cover underlying layers
|
2011-05-30 07:48:08 +04:00
|
|
|
// only if it's opaque.
|
2010-11-17 02:33:56 +03:00
|
|
|
if (aLayer->GetOpacity() != 1.0f) {
|
2011-05-30 07:48:08 +04:00
|
|
|
newFlags &= ~ALLOW_OPAQUE;
|
2010-11-17 02:33:56 +03:00
|
|
|
}
|
|
|
|
|
2011-04-01 01:33:46 +04:00
|
|
|
{
|
|
|
|
const nsIntRect* clipRect = aLayer->GetEffectiveClipRect();
|
|
|
|
if (clipRect) {
|
|
|
|
nsIntRect cr = *clipRect;
|
|
|
|
// clipRect is in the container's coordinate system. Get it into the
|
|
|
|
// global coordinate system.
|
|
|
|
if (aLayer->GetParent()) {
|
|
|
|
gfxMatrix tr;
|
2011-08-27 04:04:06 +04:00
|
|
|
if (aLayer->GetParent()->GetEffectiveTransform().CanDraw2D(&tr)) {
|
2011-05-18 15:24:52 +04:00
|
|
|
// Clip rect is applied after aLayer's transform, i.e., in the coordinate
|
|
|
|
// system of aLayer's parent.
|
2011-04-01 01:33:46 +04:00
|
|
|
TransformIntRect(cr, tr, ToInsideIntRect);
|
|
|
|
} else {
|
|
|
|
cr.SetRect(0, 0, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
2010-11-17 02:33:56 +03:00
|
|
|
newClipRect.IntersectRect(newClipRect, cr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-30 07:48:08 +04:00
|
|
|
BasicImplData* data = ToData(aLayer);
|
2011-05-30 07:48:23 +04:00
|
|
|
data->SetOperator(gfxContext::OPERATOR_OVER);
|
2011-10-17 18:59:28 +04:00
|
|
|
data->SetClipToVisibleRegion(false);
|
2011-05-30 07:48:23 +04:00
|
|
|
|
|
|
|
if (!aLayer->AsContainerLayer()) {
|
2010-11-17 02:33:56 +03:00
|
|
|
gfxMatrix transform;
|
2011-08-27 04:04:06 +04:00
|
|
|
if (!aLayer->GetEffectiveTransform().CanDraw2D(&transform)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
data->SetHidden(false);
|
2010-11-17 02:33:56 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIntRegion region = aLayer->GetEffectiveVisibleRegion();
|
|
|
|
nsIntRect r = region.GetBounds();
|
|
|
|
TransformIntRect(r, transform, ToOutsideIntRect);
|
2011-05-18 15:24:52 +04:00
|
|
|
r.IntersectRect(r, aDirtyRect);
|
|
|
|
data->SetHidden(aOpaqueRegion.Contains(r));
|
2010-11-17 02:33:56 +03:00
|
|
|
|
|
|
|
// Allow aLayer to cover underlying layers only if aLayer's
|
|
|
|
// content is opaque
|
2011-05-30 07:48:08 +04:00
|
|
|
if ((aLayer->GetContentFlags() & Layer::CONTENT_OPAQUE) &&
|
|
|
|
(newFlags & ALLOW_OPAQUE)) {
|
|
|
|
nsIntRegionRectIterator it(region);
|
|
|
|
while (const nsIntRect* sr = it.Next()) {
|
|
|
|
r = *sr;
|
|
|
|
TransformIntRect(r, transform, ToInsideIntRect);
|
|
|
|
|
|
|
|
r.IntersectRect(r, newClipRect);
|
2011-05-20 19:45:00 +04:00
|
|
|
aOpaqueRegion.Or(aOpaqueRegion, r);
|
2011-05-18 15:24:52 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2011-05-30 07:48:23 +04:00
|
|
|
Layer* child = aLayer->GetLastChild();
|
2011-09-29 10:19:26 +04:00
|
|
|
bool allHidden = true;
|
2011-05-20 19:45:00 +04:00
|
|
|
for (; child; child = child->GetPrevSibling()) {
|
2011-05-30 07:48:08 +04:00
|
|
|
MarkLayersHidden(child, newClipRect, aDirtyRect, aOpaqueRegion, newFlags);
|
|
|
|
if (!ToData(child)->IsHidden()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
allHidden = false;
|
2011-05-30 07:48:08 +04:00
|
|
|
}
|
2011-05-18 15:24:52 +04:00
|
|
|
}
|
2011-05-30 07:48:08 +04:00
|
|
|
data->SetHidden(allHidden);
|
2011-05-18 15:24:52 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-30 07:48:23 +04:00
|
|
|
/**
|
|
|
|
* This function assumes that GetEffectiveTransform transforms
|
|
|
|
* all layers to the same coordinate system (the "root coordinate system").
|
|
|
|
* MarkLayersHidden must be called before calling this.
|
|
|
|
* @param aVisibleRect the rectangle of aLayer that is visible (i.e. not
|
|
|
|
* clipped and in the dirty rect), in the root coordinate system.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ApplyDoubleBuffering(Layer* aLayer, const nsIntRect& aVisibleRect)
|
|
|
|
{
|
|
|
|
BasicImplData* data = ToData(aLayer);
|
|
|
|
if (data->IsHidden())
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsIntRect newVisibleRect(aVisibleRect);
|
|
|
|
|
|
|
|
{
|
|
|
|
const nsIntRect* clipRect = aLayer->GetEffectiveClipRect();
|
|
|
|
if (clipRect) {
|
|
|
|
nsIntRect cr = *clipRect;
|
|
|
|
// clipRect is in the container's coordinate system. Get it into the
|
|
|
|
// global coordinate system.
|
|
|
|
if (aLayer->GetParent()) {
|
|
|
|
gfxMatrix tr;
|
2011-08-27 04:04:06 +04:00
|
|
|
if (aLayer->GetParent()->GetEffectiveTransform().CanDraw2D(&tr)) {
|
2011-05-30 07:48:23 +04:00
|
|
|
NS_ASSERTION(!tr.HasNonIntegerTranslation(),
|
|
|
|
"Parent can only have an integer translation");
|
|
|
|
cr += nsIntPoint(PRInt32(tr.x0), PRInt32(tr.y0));
|
|
|
|
} else {
|
|
|
|
NS_ERROR("Parent can only have an integer translation");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
newVisibleRect.IntersectRect(newVisibleRect, cr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BasicContainerLayer* container =
|
|
|
|
static_cast<BasicContainerLayer*>(aLayer->AsContainerLayer());
|
|
|
|
// Layers that act as their own backbuffers should be drawn to the destination
|
|
|
|
// using OPERATOR_SOURCE to ensure that alpha values in a transparent window
|
|
|
|
// are cleared. This can also be faster than OPERATOR_OVER.
|
|
|
|
if (!container) {
|
|
|
|
data->SetOperator(gfxContext::OPERATOR_SOURCE);
|
|
|
|
} else {
|
|
|
|
if (container->UseIntermediateSurface() ||
|
|
|
|
!container->ChildrenPartitionVisibleRegion(newVisibleRect)) {
|
|
|
|
// We need to double-buffer this container.
|
|
|
|
data->SetOperator(gfxContext::OPERATOR_SOURCE);
|
|
|
|
container->ForceIntermediateSurface();
|
|
|
|
} else {
|
2011-08-12 02:44:50 +04:00
|
|
|
// Tell the children to clip to their visible regions so our assumption
|
|
|
|
// that they don't paint outside their visible regions is valid!
|
2011-05-30 07:48:23 +04:00
|
|
|
for (Layer* child = aLayer->GetFirstChild(); child;
|
|
|
|
child = child->GetNextSibling()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
ToData(child)->SetClipToVisibleRegion(true);
|
2011-05-30 07:48:23 +04:00
|
|
|
ApplyDoubleBuffering(child, newVisibleRect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-14 03:14:07 +03:00
|
|
|
void
|
2010-05-21 07:20:48 +04:00
|
|
|
BasicLayerManager::EndTransaction(DrawThebesLayerCallback aCallback,
|
2011-09-26 17:20:42 +04:00
|
|
|
void* aCallbackData,
|
|
|
|
EndTransactionFlags aFlags)
|
2010-12-27 09:12:17 +03:00
|
|
|
{
|
2011-09-26 17:20:42 +04:00
|
|
|
EndTransactionInternal(aCallback, aCallbackData, aFlags);
|
2010-12-27 09:12:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
BasicLayerManager::EndTransactionInternal(DrawThebesLayerCallback aCallback,
|
2011-09-26 17:20:42 +04:00
|
|
|
void* aCallbackData,
|
|
|
|
EndTransactionFlags aFlags)
|
2010-03-01 10:56:18 +03:00
|
|
|
{
|
2010-07-21 22:06:33 +04:00
|
|
|
#ifdef MOZ_LAYERS_HAVE_LOG
|
2010-07-22 01:17:33 +04:00
|
|
|
MOZ_LAYERS_LOG((" ----- (beginning paint)"));
|
2010-07-21 22:06:33 +04:00
|
|
|
Log();
|
|
|
|
#endif
|
|
|
|
|
2010-03-04 00:37:04 +03:00
|
|
|
NS_ASSERTION(InConstruction(), "Should be in construction phase");
|
2010-03-01 10:56:18 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
mPhase = PHASE_DRAWING;
|
|
|
|
#endif
|
|
|
|
|
2010-12-27 09:12:17 +03:00
|
|
|
mTransactionIncomplete = false;
|
|
|
|
|
2011-09-26 17:20:42 +04:00
|
|
|
if (mTarget && mRoot && !(aFlags & END_NO_IMMEDIATE_REDRAW)) {
|
2011-05-18 15:24:52 +04:00
|
|
|
nsIntRect clipRect;
|
|
|
|
if (HasShadowManager()) {
|
|
|
|
// If this has a shadow manager, the clip extents of mTarget are meaningless.
|
|
|
|
// So instead just use the root layer's visible region bounds.
|
|
|
|
const nsIntRect& bounds = mRoot->GetVisibleRegion().GetBounds();
|
|
|
|
gfxRect deviceRect =
|
|
|
|
mTarget->UserToDevice(gfxRect(bounds.x, bounds.y, bounds.width, bounds.height));
|
|
|
|
clipRect = ToOutsideIntRect(deviceRect);
|
|
|
|
} else {
|
|
|
|
gfxContextMatrixAutoSaveRestore save(mTarget);
|
|
|
|
mTarget->SetMatrix(gfxMatrix());
|
|
|
|
clipRect = ToOutsideIntRect(mTarget->GetClipExtents());
|
|
|
|
}
|
|
|
|
|
2011-05-30 07:48:23 +04:00
|
|
|
// Need to do this before we call ApplyDoubleBuffering,
|
2011-05-18 15:24:52 +04:00
|
|
|
// which depends on correct effective transforms
|
|
|
|
mSnapEffectiveTransforms =
|
|
|
|
!(mTarget->GetFlags() & gfxContext::FLAG_DISABLE_SNAPPING);
|
|
|
|
mRoot->ComputeEffectiveTransforms(gfx3DMatrix::From2D(mTarget->CurrentMatrix()));
|
|
|
|
|
|
|
|
if (IsRetained()) {
|
|
|
|
nsIntRegion region;
|
2011-05-30 07:48:08 +04:00
|
|
|
MarkLayersHidden(mRoot, clipRect, clipRect, region, ALLOW_OPAQUE);
|
2011-05-30 07:48:23 +04:00
|
|
|
if (mUsingDefaultTarget && mDoubleBuffering != BUFFER_NONE) {
|
|
|
|
ApplyDoubleBuffering(mRoot, clipRect);
|
|
|
|
}
|
2011-05-17 03:41:39 +04:00
|
|
|
}
|
|
|
|
|
2011-05-30 07:48:29 +04:00
|
|
|
PaintLayer(mTarget, mRoot, aCallback, aCallbackData, nsnull);
|
2011-05-20 19:45:00 +04:00
|
|
|
|
2011-01-21 08:46:38 +03:00
|
|
|
if (!mTransactionIncomplete) {
|
|
|
|
// Clear out target if we have a complete transaction.
|
|
|
|
mTarget = nsnull;
|
|
|
|
}
|
2010-05-21 07:20:48 +04:00
|
|
|
}
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
#ifdef MOZ_LAYERS_HAVE_LOG
|
|
|
|
Log();
|
|
|
|
MOZ_LAYERS_LOG(("]----- EndTransaction"));
|
|
|
|
#endif
|
|
|
|
|
2010-03-01 10:56:18 +03:00
|
|
|
#ifdef DEBUG
|
2011-01-19 11:27:54 +03:00
|
|
|
// Go back to the construction phase if the transaction isn't complete.
|
|
|
|
// Layout will update the layer tree and call EndTransaction().
|
|
|
|
mPhase = mTransactionIncomplete ? PHASE_CONSTRUCTION : PHASE_NONE;
|
2010-03-01 10:56:18 +03:00
|
|
|
#endif
|
2011-01-21 08:46:38 +03:00
|
|
|
|
|
|
|
if (!mTransactionIncomplete) {
|
|
|
|
// This is still valid if the transaction was incomplete.
|
2011-10-17 18:59:28 +04:00
|
|
|
mUsingDefaultTarget = false;
|
2011-01-21 08:46:38 +03:00
|
|
|
}
|
2010-12-27 09:12:17 +03:00
|
|
|
|
|
|
|
NS_ASSERTION(!aCallback || !mTransactionIncomplete,
|
|
|
|
"If callback is not null, transaction must be complete");
|
2011-01-19 11:27:54 +03:00
|
|
|
|
2011-01-21 08:46:38 +03:00
|
|
|
// XXX - We should probably assert here that for an incomplete transaction
|
|
|
|
// out target is the default target.
|
|
|
|
|
2010-12-27 09:12:17 +03:00
|
|
|
return !mTransactionIncomplete;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2011-01-19 11:27:54 +03:00
|
|
|
BasicLayerManager::EndEmptyTransaction()
|
2010-12-27 09:12:17 +03:00
|
|
|
{
|
|
|
|
if (!mRoot) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EndTransactionInternal(nsnull, nsnull);
|
2010-03-01 10:56:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BasicLayerManager::SetRoot(Layer* aLayer)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aLayer, "Root can't be null");
|
|
|
|
NS_ASSERTION(aLayer->Manager() == this, "Wrong manager");
|
|
|
|
NS_ASSERTION(InConstruction(), "Only allowed in construction phase");
|
|
|
|
mRoot = aLayer;
|
|
|
|
}
|
|
|
|
|
2011-08-27 04:04:06 +04:00
|
|
|
static pixman_transform
|
|
|
|
Matrix3DToPixman(const gfx3DMatrix& aMatrix)
|
|
|
|
{
|
|
|
|
pixman_f_transform transform;
|
|
|
|
|
|
|
|
transform.m[0][0] = aMatrix._11;
|
|
|
|
transform.m[0][1] = aMatrix._21;
|
|
|
|
transform.m[0][2] = aMatrix._41;
|
|
|
|
transform.m[1][0] = aMatrix._12;
|
|
|
|
transform.m[1][1] = aMatrix._22;
|
|
|
|
transform.m[1][2] = aMatrix._42;
|
|
|
|
transform.m[2][0] = aMatrix._14;
|
|
|
|
transform.m[2][1] = aMatrix._24;
|
|
|
|
transform.m[2][2] = aMatrix._44;
|
|
|
|
|
|
|
|
pixman_transform result;
|
|
|
|
pixman_transform_from_pixman_f_transform(&result, &transform);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
PixmanTransform(const gfxImageSurface *aDest,
|
|
|
|
const gfxImageSurface *aSrc,
|
|
|
|
const gfx3DMatrix& aTransform,
|
|
|
|
gfxPoint aDestOffset)
|
|
|
|
{
|
|
|
|
gfxIntSize destSize = aDest->GetSize();
|
|
|
|
pixman_image_t* dest = pixman_image_create_bits(aDest->Format() == gfxASurface::ImageFormatARGB32 ? PIXMAN_a8r8g8b8 : PIXMAN_x8r8g8b8,
|
|
|
|
destSize.width,
|
|
|
|
destSize.height,
|
|
|
|
(uint32_t*)aDest->Data(),
|
|
|
|
aDest->Stride());
|
|
|
|
|
|
|
|
gfxIntSize srcSize = aSrc->GetSize();
|
|
|
|
pixman_image_t* src = pixman_image_create_bits(aSrc->Format() == gfxASurface::ImageFormatARGB32 ? PIXMAN_a8r8g8b8 : PIXMAN_x8r8g8b8,
|
|
|
|
srcSize.width,
|
|
|
|
srcSize.height,
|
|
|
|
(uint32_t*)aSrc->Data(),
|
|
|
|
aSrc->Stride());
|
|
|
|
|
|
|
|
NS_ABORT_IF_FALSE(src && dest, "Failed to create pixman images?");
|
|
|
|
|
|
|
|
pixman_transform pixTransform = Matrix3DToPixman(aTransform);
|
|
|
|
pixman_transform pixTransformInverted;
|
|
|
|
|
|
|
|
// If the transform is singular then nothing would be drawn anyway, return here
|
|
|
|
if (!pixman_transform_invert(&pixTransformInverted, &pixTransform)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
pixman_image_set_transform(src, &pixTransformInverted);
|
|
|
|
|
|
|
|
pixman_image_composite32(PIXMAN_OP_SRC,
|
|
|
|
src,
|
|
|
|
nsnull,
|
|
|
|
dest,
|
|
|
|
aDestOffset.x,
|
|
|
|
aDestOffset.y,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
destSize.width,
|
|
|
|
destSize.height);
|
|
|
|
|
|
|
|
pixman_image_unref(dest);
|
|
|
|
pixman_image_unref(src);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transform a surface using a gfx3DMatrix and blit to the destination if
|
|
|
|
* it is efficient to do so.
|
|
|
|
*
|
|
|
|
* @param aSource Source surface.
|
|
|
|
* @param aDest Desintation context.
|
|
|
|
* @param aBounds Area represented by aSource.
|
|
|
|
* @param aTransform Transformation matrix.
|
|
|
|
* @param aDrawOffset Location to draw returned surface on aDest.
|
|
|
|
* @param aDontBlit Never draw to aDest if this is true.
|
|
|
|
* @return Transformed surface, or nsnull if it has been drawn to aDest.
|
|
|
|
*/
|
|
|
|
static already_AddRefed<gfxASurface>
|
|
|
|
Transform3D(gfxASurface* aSource, gfxContext* aDest,
|
|
|
|
const gfxRect& aBounds, const gfx3DMatrix& aTransform,
|
2011-09-29 10:19:26 +04:00
|
|
|
gfxPoint& aDrawOffset, bool aDontBlit)
|
2011-08-27 04:04:06 +04:00
|
|
|
{
|
|
|
|
nsRefPtr<gfxImageSurface> sourceImage = aSource->GetAsImageSurface();
|
|
|
|
if (!sourceImage) {
|
|
|
|
sourceImage = new gfxImageSurface(gfxIntSize(aBounds.width, aBounds.height), gfxASurface::FormatFromContent(aSource->GetContentType()));
|
|
|
|
nsRefPtr<gfxContext> ctx = new gfxContext(sourceImage);
|
|
|
|
|
|
|
|
aSource->SetDeviceOffset(gfxPoint(0, 0));
|
|
|
|
ctx->SetSource(aSource);
|
|
|
|
ctx->SetOperator(gfxContext::OPERATOR_SOURCE);
|
|
|
|
ctx->Paint();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find the transformed rectangle of our layer.
|
|
|
|
gfxRect offsetRect = aTransform.TransformBounds(aBounds);
|
|
|
|
|
|
|
|
// Intersect the transformed layer with the destination rectangle.
|
|
|
|
// This is in device space since we have an identity transform set on aTarget.
|
|
|
|
gfxRect destRect = aDest->GetClipExtents();
|
|
|
|
destRect.IntersectRect(destRect, offsetRect);
|
|
|
|
|
|
|
|
// Create a surface the size of the transformed object.
|
|
|
|
nsRefPtr<gfxASurface> dest = aDest->CurrentSurface();
|
|
|
|
nsRefPtr<gfxImageSurface> destImage = dest->GetAsImageSurface();
|
|
|
|
destImage = nsnull;
|
|
|
|
gfxPoint offset;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool blitComplete;
|
2011-08-27 04:04:06 +04:00
|
|
|
if (!destImage || aDontBlit || !aDest->ClipContainsRect(destRect)) {
|
|
|
|
destImage = new gfxImageSurface(gfxIntSize(destRect.width, destRect.height),
|
|
|
|
gfxASurface::ImageFormatARGB32);
|
|
|
|
offset = destRect.TopLeft();
|
2011-10-17 18:59:28 +04:00
|
|
|
blitComplete = false;
|
2011-08-27 04:04:06 +04:00
|
|
|
} else {
|
|
|
|
offset = -dest->GetDeviceOffset();
|
2011-10-17 18:59:28 +04:00
|
|
|
blitComplete = true;
|
2011-08-27 04:04:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Include a translation to the correct origin.
|
|
|
|
gfx3DMatrix translation = gfx3DMatrix::Translation(aBounds.x, aBounds.y, 0);
|
|
|
|
|
|
|
|
// Transform the content and offset it such that the content begins at the origin.
|
|
|
|
PixmanTransform(destImage, sourceImage, translation * aTransform, offset);
|
|
|
|
|
|
|
|
if (blitComplete) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we haven't actually drawn to aDest then return our temporary image so that
|
|
|
|
// the caller can do this.
|
|
|
|
aDrawOffset = destRect.TopLeft();
|
|
|
|
return destImage.forget();
|
|
|
|
}
|
|
|
|
|
2010-03-01 10:56:18 +03:00
|
|
|
void
|
2011-05-30 07:48:29 +04:00
|
|
|
BasicLayerManager::PaintLayer(gfxContext* aTarget,
|
|
|
|
Layer* aLayer,
|
2010-05-21 07:20:48 +04:00
|
|
|
DrawThebesLayerCallback aCallback,
|
2011-02-17 01:43:30 +03:00
|
|
|
void* aCallbackData,
|
|
|
|
ReadbackProcessor* aReadback)
|
2010-03-01 10:56:18 +03:00
|
|
|
{
|
2010-11-08 12:06:15 +03:00
|
|
|
const nsIntRect* clipRect = aLayer->GetEffectiveClipRect();
|
|
|
|
const gfx3DMatrix& effectiveTransform = aLayer->GetEffectiveTransform();
|
2011-05-30 07:48:13 +04:00
|
|
|
BasicContainerLayer* container = static_cast<BasicContainerLayer*>(aLayer);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool needsGroup = aLayer->GetFirstChild() &&
|
2011-05-30 07:48:13 +04:00
|
|
|
container->UseIntermediateSurface();
|
2011-08-12 02:44:50 +04:00
|
|
|
BasicImplData* data = ToData(aLayer);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool needsClipToVisibleRegion =
|
2011-08-12 02:44:50 +04:00
|
|
|
data->GetClipToVisibleRegion() && !aLayer->AsThebesLayer();
|
2011-05-30 07:48:13 +04:00
|
|
|
NS_ASSERTION(needsGroup || !aLayer->GetFirstChild() ||
|
|
|
|
container->GetOperator() == gfxContext::OPERATOR_OVER,
|
|
|
|
"non-OVER operator should have forced UseIntermediateSurface");
|
|
|
|
|
2010-11-08 12:06:15 +03:00
|
|
|
// If needsSaveRestore is false, we should still save and restore
|
|
|
|
// the CTM
|
2011-09-29 10:19:26 +04:00
|
|
|
bool needsSaveRestore = needsGroup || clipRect || needsClipToVisibleRegion;
|
2010-11-08 12:06:15 +03:00
|
|
|
gfxMatrix savedMatrix;
|
|
|
|
if (needsSaveRestore) {
|
2011-05-30 07:48:29 +04:00
|
|
|
aTarget->Save();
|
2010-03-02 02:08:28 +03:00
|
|
|
|
2010-11-08 12:06:15 +03:00
|
|
|
if (clipRect) {
|
2011-05-30 07:48:29 +04:00
|
|
|
aTarget->NewPath();
|
2011-10-17 18:59:28 +04:00
|
|
|
aTarget->Rectangle(gfxRect(clipRect->x, clipRect->y, clipRect->width, clipRect->height), true);
|
2011-05-30 07:48:29 +04:00
|
|
|
aTarget->Clip();
|
2010-03-01 10:56:18 +03:00
|
|
|
}
|
2010-11-08 12:06:15 +03:00
|
|
|
} else {
|
2011-05-30 07:48:29 +04:00
|
|
|
savedMatrix = aTarget->CurrentMatrix();
|
2010-11-08 12:06:15 +03:00
|
|
|
}
|
2010-03-01 10:56:18 +03:00
|
|
|
|
2010-11-08 12:06:15 +03:00
|
|
|
gfxMatrix transform;
|
2011-08-27 04:04:06 +04:00
|
|
|
// Will return an identity matrix for 3d transforms, and is handled separately below.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool is2D = effectiveTransform.CanDraw2D(&transform);
|
2011-08-27 04:04:06 +04:00
|
|
|
NS_ABORT_IF_FALSE(is2D || needsGroup || !aLayer->GetFirstChild(), "Must PushGroup for 3d transforms!");
|
|
|
|
if (is2D) {
|
|
|
|
aTarget->SetMatrix(transform);
|
|
|
|
} else {
|
|
|
|
aTarget->SetMatrix(gfxMatrix());
|
|
|
|
}
|
2010-11-08 12:06:15 +03:00
|
|
|
|
2011-01-03 04:48:08 +03:00
|
|
|
const nsIntRegion& visibleRegion = aLayer->GetEffectiveVisibleRegion();
|
2011-08-12 02:44:50 +04:00
|
|
|
// If needsGroup is true, we'll clip to the visible region after we've popped the group
|
|
|
|
if (needsClipToVisibleRegion && !needsGroup) {
|
|
|
|
gfxUtils::ClipToRegion(aTarget, visibleRegion);
|
|
|
|
// Don't need to clip to visible region again
|
2011-10-17 18:59:28 +04:00
|
|
|
needsClipToVisibleRegion = false;
|
2011-08-12 02:44:50 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool pushedTargetOpaqueRect = false;
|
2011-05-30 07:48:29 +04:00
|
|
|
nsRefPtr<gfxASurface> currentSurface = aTarget->CurrentSurface();
|
2011-01-03 04:48:08 +03:00
|
|
|
const gfxRect& targetOpaqueRect = currentSurface->GetOpaqueRect();
|
|
|
|
|
|
|
|
// Try to annotate currentSurface with a region of pixels that have been
|
|
|
|
// (or will be) painted opaque, if no such region is currently set.
|
2011-09-30 05:13:50 +04:00
|
|
|
const nsIntRect& bounds = visibleRegion.GetBounds();
|
2011-01-03 04:48:08 +03:00
|
|
|
if (targetOpaqueRect.IsEmpty() && visibleRegion.GetNumRects() == 1 &&
|
|
|
|
(aLayer->GetContentFlags() & Layer::CONTENT_OPAQUE) &&
|
|
|
|
!transform.HasNonAxisAlignedTransform()) {
|
|
|
|
currentSurface->SetOpaqueRect(
|
2011-05-30 07:48:29 +04:00
|
|
|
aTarget->UserToDevice(gfxRect(bounds.x, bounds.y, bounds.width, bounds.height)));
|
2011-10-17 18:59:28 +04:00
|
|
|
pushedTargetOpaqueRect = true;
|
2011-01-03 04:48:08 +03:00
|
|
|
}
|
|
|
|
|
2011-05-30 07:48:29 +04:00
|
|
|
nsRefPtr<gfxContext> groupTarget;
|
2011-09-30 05:13:50 +04:00
|
|
|
nsRefPtr<gfxASurface> untransformedSurface;
|
|
|
|
if (!is2D) {
|
|
|
|
untransformedSurface =
|
|
|
|
gfxPlatform::GetPlatform()->CreateOffscreenSurface(gfxIntSize(bounds.width, bounds.height),
|
|
|
|
gfxASurface::CONTENT_COLOR_ALPHA);
|
|
|
|
untransformedSurface->SetDeviceOffset(gfxPoint(-bounds.x, -bounds.y));
|
|
|
|
groupTarget = new gfxContext(untransformedSurface);
|
|
|
|
} else if (needsGroup) {
|
2011-05-30 07:48:29 +04:00
|
|
|
groupTarget = PushGroupForLayer(aTarget, aLayer, aLayer->GetEffectiveVisibleRegion(),
|
|
|
|
&needsClipToVisibleRegion);
|
|
|
|
} else {
|
|
|
|
groupTarget = aTarget;
|
2010-03-01 10:56:18 +03:00
|
|
|
}
|
|
|
|
|
2010-07-16 01:08:04 +04:00
|
|
|
/* Only paint ourself, or our children - This optimization relies on this! */
|
2010-11-08 12:06:15 +03:00
|
|
|
Layer* child = aLayer->GetFirstChild();
|
|
|
|
if (!child) {
|
2010-11-17 02:33:56 +03:00
|
|
|
#ifdef MOZ_LAYERS_HAVE_LOG
|
|
|
|
MOZ_LAYERS_LOG(("%s (0x%p) is covered: %i\n", __FUNCTION__,
|
2011-05-18 15:24:52 +04:00
|
|
|
(void*)aLayer, data->IsHidden()));
|
2010-11-17 02:33:56 +03:00
|
|
|
#endif
|
2011-05-18 15:24:52 +04:00
|
|
|
if (aLayer->AsThebesLayer()) {
|
2011-05-30 07:48:29 +04:00
|
|
|
data->PaintThebes(groupTarget, aCallback, aCallbackData, aReadback);
|
2011-05-18 15:24:52 +04:00
|
|
|
} else {
|
2011-05-30 07:48:29 +04:00
|
|
|
data->Paint(groupTarget);
|
2010-11-17 02:33:56 +03:00
|
|
|
}
|
2010-07-16 01:08:04 +04:00
|
|
|
} else {
|
2011-02-17 01:43:30 +03:00
|
|
|
ReadbackProcessor readback;
|
2011-10-07 01:24:32 +04:00
|
|
|
ContainerLayer* container = static_cast<ContainerLayer*>(aLayer);
|
2011-02-17 01:43:30 +03:00
|
|
|
if (IsRetained()) {
|
|
|
|
readback.BuildUpdates(container);
|
|
|
|
}
|
2011-10-07 01:24:32 +04:00
|
|
|
|
|
|
|
nsAutoTArray<Layer*, 12> children;
|
|
|
|
container->SortChildrenBy3DZOrder(children);
|
2011-02-17 01:43:30 +03:00
|
|
|
|
2011-10-07 01:24:32 +04:00
|
|
|
for (PRUint32 i = 0; i < children.Length(); i++) {
|
|
|
|
PaintLayer(groupTarget, children.ElementAt(i), aCallback, aCallbackData, &readback);
|
2010-12-27 09:12:17 +03:00
|
|
|
if (mTransactionIncomplete)
|
|
|
|
break;
|
2010-07-16 01:08:04 +04:00
|
|
|
}
|
2010-05-21 07:20:48 +04:00
|
|
|
}
|
2010-05-24 02:53:05 +04:00
|
|
|
|
2010-11-08 12:06:15 +03:00
|
|
|
if (needsGroup) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool blitComplete = false;
|
2011-08-27 04:04:06 +04:00
|
|
|
if (is2D) {
|
|
|
|
PopGroupToSourceWithCachedSurface(aTarget, groupTarget);
|
|
|
|
} else {
|
2011-09-30 05:13:50 +04:00
|
|
|
NS_ABORT_IF_FALSE(untransformedSurface,
|
|
|
|
"We should always allocate an untransformed surface with 3d transforms!");
|
2011-08-27 04:04:06 +04:00
|
|
|
|
|
|
|
gfxPoint offset;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool dontBlit = needsClipToVisibleRegion || mTransactionIncomplete ||
|
2011-08-27 04:04:06 +04:00
|
|
|
aLayer->GetEffectiveOpacity() != 1.0f;
|
|
|
|
nsRefPtr<gfxASurface> result =
|
2011-09-30 05:13:50 +04:00
|
|
|
Transform3D(untransformedSurface, aTarget, bounds,
|
2011-08-27 04:04:06 +04:00
|
|
|
effectiveTransform, offset, dontBlit);
|
|
|
|
|
|
|
|
blitComplete = !result;
|
|
|
|
if (result) {
|
|
|
|
aTarget->SetSource(result, offset);
|
|
|
|
}
|
|
|
|
}
|
2011-05-30 07:48:23 +04:00
|
|
|
// If we're doing our own double-buffering, we need to avoid drawing
|
|
|
|
// the results of an incomplete transaction to the destination surface ---
|
|
|
|
// that could cause flicker. Double-buffering is implemented using a
|
|
|
|
// temporary surface for one or more container layers, so we need to stop
|
2011-05-30 07:48:29 +04:00
|
|
|
// those temporary surfaces from being composited to aTarget.
|
2011-05-30 07:48:23 +04:00
|
|
|
// ApplyDoubleBuffering guarantees that this container layer can't
|
|
|
|
// intersect any other leaf layers, so if the transaction is not yet marked
|
|
|
|
// incomplete, the contents of this container layer are the final contents
|
|
|
|
// for the window.
|
2011-08-27 04:04:06 +04:00
|
|
|
if (!mTransactionIncomplete && !blitComplete) {
|
2011-05-30 07:48:23 +04:00
|
|
|
if (needsClipToVisibleRegion) {
|
2011-05-30 07:48:29 +04:00
|
|
|
gfxUtils::ClipToRegion(aTarget, aLayer->GetEffectiveVisibleRegion());
|
2011-05-30 07:48:23 +04:00
|
|
|
}
|
2011-05-30 07:48:29 +04:00
|
|
|
AutoSetOperator setOperator(aTarget, container->GetOperator());
|
|
|
|
aTarget->Paint(aLayer->GetEffectiveOpacity());
|
2011-01-04 13:35:57 +03:00
|
|
|
}
|
2010-11-08 12:06:15 +03:00
|
|
|
}
|
2010-03-01 10:56:18 +03:00
|
|
|
|
2011-01-03 04:48:08 +03:00
|
|
|
if (pushedTargetOpaqueRect) {
|
|
|
|
currentSurface->SetOpaqueRect(gfxRect(0, 0, 0, 0));
|
|
|
|
}
|
|
|
|
|
2010-11-08 12:06:15 +03:00
|
|
|
if (needsSaveRestore) {
|
2011-05-30 07:48:29 +04:00
|
|
|
aTarget->Restore();
|
2010-11-08 12:06:15 +03:00
|
|
|
} else {
|
2011-05-30 07:48:29 +04:00
|
|
|
aTarget->SetMatrix(savedMatrix);
|
2010-03-01 10:56:18 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-20 07:40:49 +04:00
|
|
|
void
|
|
|
|
BasicLayerManager::ClearCachedResources()
|
|
|
|
{
|
|
|
|
if (mRoot) {
|
|
|
|
ClearLayer(mRoot);
|
|
|
|
}
|
|
|
|
|
|
|
|
mCachedSurface.Expire();
|
|
|
|
}
|
|
|
|
void
|
|
|
|
BasicLayerManager::ClearLayer(Layer* aLayer)
|
|
|
|
{
|
2010-08-20 07:58:44 +04:00
|
|
|
ToData(aLayer)->ClearCachedResources();
|
2010-08-20 07:40:49 +04:00
|
|
|
for (Layer* child = aLayer->GetFirstChild(); child;
|
|
|
|
child = child->GetNextSibling()) {
|
|
|
|
ClearLayer(child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-01 10:56:18 +03:00
|
|
|
already_AddRefed<ThebesLayer>
|
|
|
|
BasicLayerManager::CreateThebesLayer()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(InConstruction(), "Only allowed in construction phase");
|
|
|
|
nsRefPtr<ThebesLayer> layer = new BasicThebesLayer(this);
|
|
|
|
return layer.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<ContainerLayer>
|
|
|
|
BasicLayerManager::CreateContainerLayer()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(InConstruction(), "Only allowed in construction phase");
|
|
|
|
nsRefPtr<ContainerLayer> layer = new BasicContainerLayer(this);
|
|
|
|
return layer.forget();
|
|
|
|
}
|
|
|
|
|
2010-03-02 02:09:35 +03:00
|
|
|
already_AddRefed<ImageLayer>
|
|
|
|
BasicLayerManager::CreateImageLayer()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(InConstruction(), "Only allowed in construction phase");
|
|
|
|
nsRefPtr<ImageLayer> layer = new BasicImageLayer(this);
|
|
|
|
return layer.forget();
|
|
|
|
}
|
|
|
|
|
2010-05-13 04:56:11 +04:00
|
|
|
already_AddRefed<ColorLayer>
|
|
|
|
BasicLayerManager::CreateColorLayer()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(InConstruction(), "Only allowed in construction phase");
|
|
|
|
nsRefPtr<ColorLayer> layer = new BasicColorLayer(this);
|
|
|
|
return layer.forget();
|
|
|
|
}
|
|
|
|
|
2010-05-18 08:04:22 +04:00
|
|
|
already_AddRefed<CanvasLayer>
|
|
|
|
BasicLayerManager::CreateCanvasLayer()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(InConstruction(), "Only allowed in construction phase");
|
|
|
|
nsRefPtr<CanvasLayer> layer = new BasicCanvasLayer(this);
|
|
|
|
return layer.forget();
|
|
|
|
}
|
|
|
|
|
2011-02-17 01:43:30 +03:00
|
|
|
already_AddRefed<ReadbackLayer>
|
|
|
|
BasicLayerManager::CreateReadbackLayer()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(InConstruction(), "Only allowed in construction phase");
|
|
|
|
nsRefPtr<ReadbackLayer> layer = new BasicReadbackLayer(this);
|
|
|
|
return layer.forget();
|
|
|
|
}
|
2010-07-22 01:17:33 +04:00
|
|
|
|
2010-09-14 09:23:08 +04:00
|
|
|
class BasicShadowableThebesLayer;
|
2010-07-22 01:17:33 +04:00
|
|
|
class BasicShadowableLayer : public ShadowableLayer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
BasicShadowableLayer()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(BasicShadowableLayer);
|
|
|
|
}
|
|
|
|
|
|
|
|
~BasicShadowableLayer()
|
|
|
|
{
|
|
|
|
if (HasShadow()) {
|
|
|
|
PLayerChild::Send__delete__(GetShadow());
|
|
|
|
}
|
|
|
|
MOZ_COUNT_DTOR(BasicShadowableLayer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetShadow(PLayerChild* aShadow)
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(!mShadow, "can't have two shadows (yet)");
|
|
|
|
mShadow = aShadow;
|
|
|
|
}
|
2010-07-22 01:17:33 +04:00
|
|
|
|
2010-09-14 09:23:08 +04:00
|
|
|
virtual void SetBackBuffer(const SurfaceDescriptor& aBuffer)
|
2010-07-22 01:17:33 +04:00
|
|
|
{
|
|
|
|
NS_RUNTIMEABORT("if this default impl is called, |aBuffer| leaks");
|
|
|
|
}
|
2011-04-21 08:38:39 +04:00
|
|
|
|
|
|
|
virtual void SetBackBufferYUVImage(gfxSharedImageSurface* aYBuffer,
|
|
|
|
gfxSharedImageSurface* aUBuffer,
|
|
|
|
gfxSharedImageSurface* aVBuffer)
|
|
|
|
{
|
|
|
|
NS_RUNTIMEABORT("if this default impl is called, |aBuffer| leaks");
|
|
|
|
}
|
2010-08-21 03:24:41 +04:00
|
|
|
|
|
|
|
virtual void Disconnect()
|
|
|
|
{
|
|
|
|
// This is an "emergency Disconnect()", called when the compositing
|
|
|
|
// process has died. |mShadow| and our Shmem buffers are
|
|
|
|
// automatically managed by IPDL, so we don't need to explicitly
|
|
|
|
// free them here (it's hard to get that right on emergency
|
|
|
|
// shutdown anyway).
|
|
|
|
mShadow = nsnull;
|
|
|
|
}
|
2010-09-14 09:23:08 +04:00
|
|
|
|
|
|
|
virtual BasicShadowableThebesLayer* AsThebes() { return nsnull; }
|
2010-07-22 01:17:33 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static ShadowableLayer*
|
|
|
|
ToShadowable(Layer* aLayer)
|
|
|
|
{
|
|
|
|
return ToData(aLayer)->AsShadowableLayer();
|
|
|
|
}
|
|
|
|
|
2011-02-17 01:43:30 +03:00
|
|
|
// Some layers, like ReadbackLayers, can't be shadowed and shadowing
|
|
|
|
// them doesn't make sense anyway
|
|
|
|
static bool
|
|
|
|
ShouldShadow(Layer* aLayer)
|
|
|
|
{
|
|
|
|
if (!ToShadowable(aLayer)) {
|
|
|
|
NS_ABORT_IF_FALSE(aLayer->GetType() == Layer::TYPE_READBACK,
|
|
|
|
"Only expect not to shadow ReadbackLayers");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
template<class OpT>
|
|
|
|
static BasicShadowableLayer*
|
|
|
|
GetBasicShadowable(const OpT& op)
|
|
|
|
{
|
|
|
|
return static_cast<BasicShadowableLayer*>(
|
|
|
|
static_cast<const ShadowLayerChild*>(op.layerChild())->layer());
|
|
|
|
}
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
class BasicShadowableContainerLayer : public BasicContainerLayer,
|
|
|
|
public BasicShadowableLayer {
|
|
|
|
public:
|
|
|
|
BasicShadowableContainerLayer(BasicShadowLayerManager* aManager) :
|
|
|
|
BasicContainerLayer(aManager)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(BasicShadowableContainerLayer);
|
|
|
|
}
|
|
|
|
virtual ~BasicShadowableContainerLayer()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(BasicShadowableContainerLayer);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void InsertAfter(Layer* aChild, Layer* aAfter);
|
|
|
|
virtual void RemoveChild(Layer* aChild);
|
|
|
|
|
|
|
|
virtual Layer* AsLayer() { return this; }
|
|
|
|
virtual ShadowableLayer* AsShadowableLayer() { return this; }
|
|
|
|
|
2010-08-21 03:24:41 +04:00
|
|
|
virtual void Disconnect()
|
|
|
|
{
|
|
|
|
BasicShadowableLayer::Disconnect();
|
|
|
|
}
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
private:
|
|
|
|
BasicShadowLayerManager* ShadowManager()
|
|
|
|
{
|
|
|
|
return static_cast<BasicShadowLayerManager*>(mManager);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
BasicShadowableContainerLayer::InsertAfter(Layer* aChild, Layer* aAfter)
|
|
|
|
{
|
2011-02-17 01:43:30 +03:00
|
|
|
if (HasShadow() && ShouldShadow(aChild)) {
|
|
|
|
while (aAfter && !ShouldShadow(aAfter)) {
|
|
|
|
aAfter = aAfter->GetPrevSibling();
|
|
|
|
}
|
2010-07-22 01:17:33 +04:00
|
|
|
ShadowManager()->InsertAfter(ShadowManager()->Hold(this),
|
|
|
|
ShadowManager()->Hold(aChild),
|
2010-07-22 01:17:33 +04:00
|
|
|
aAfter ? ShadowManager()->Hold(aAfter) : nsnull);
|
2010-07-22 01:17:33 +04:00
|
|
|
}
|
|
|
|
BasicContainerLayer::InsertAfter(aChild, aAfter);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BasicShadowableContainerLayer::RemoveChild(Layer* aChild)
|
|
|
|
{
|
2011-02-17 01:43:30 +03:00
|
|
|
if (HasShadow() && ShouldShadow(aChild)) {
|
2010-07-22 01:17:33 +04:00
|
|
|
ShadowManager()->RemoveChild(ShadowManager()->Hold(this),
|
|
|
|
ShadowManager()->Hold(aChild));
|
|
|
|
}
|
|
|
|
BasicContainerLayer::RemoveChild(aChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
class BasicShadowableThebesLayer : public BasicThebesLayer,
|
|
|
|
public BasicShadowableLayer
|
|
|
|
{
|
2010-07-22 01:17:33 +04:00
|
|
|
typedef BasicThebesLayer Base;
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
public:
|
2010-11-13 01:21:05 +03:00
|
|
|
BasicShadowableThebesLayer(BasicShadowLayerManager* aManager)
|
|
|
|
: BasicThebesLayer(aManager)
|
|
|
|
, mIsNewBuffer(false)
|
2011-10-10 20:47:27 +04:00
|
|
|
, mFrontAndBackBufferDiffer(false)
|
2010-07-22 01:17:33 +04:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(BasicShadowableThebesLayer);
|
|
|
|
}
|
|
|
|
virtual ~BasicShadowableThebesLayer()
|
|
|
|
{
|
2011-10-10 20:47:27 +04:00
|
|
|
DestroyBackBuffer();
|
2010-07-22 01:17:33 +04:00
|
|
|
MOZ_COUNT_DTOR(BasicShadowableThebesLayer);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void FillSpecificAttributes(SpecificLayerAttributes& aAttrs)
|
|
|
|
{
|
2011-06-22 16:11:28 +04:00
|
|
|
aAttrs = ThebesLayerAttributes(GetValidRegion());
|
2010-07-22 01:17:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual Layer* AsLayer() { return this; }
|
|
|
|
virtual ShadowableLayer* AsShadowableLayer() { return this; }
|
2010-10-13 23:22:17 +04:00
|
|
|
virtual bool MustRetainContent() { return HasShadow(); }
|
2010-07-22 01:17:33 +04:00
|
|
|
|
2011-10-10 20:47:27 +04:00
|
|
|
void SetBackBufferAndAttrs(const OptionalThebesBuffer& aBuffer,
|
2010-09-14 09:23:08 +04:00
|
|
|
const nsIntRegion& aValidRegion,
|
2010-11-05 10:17:07 +03:00
|
|
|
const OptionalThebesBuffer& aReadOnlyFrontBuffer,
|
|
|
|
const nsIntRegion& aFrontUpdatedRegion);
|
2010-07-22 01:17:33 +04:00
|
|
|
|
2010-08-21 03:24:41 +04:00
|
|
|
virtual void Disconnect()
|
|
|
|
{
|
2010-09-14 09:23:08 +04:00
|
|
|
mBackBuffer = SurfaceDescriptor();
|
2010-08-21 03:24:41 +04:00
|
|
|
BasicShadowableLayer::Disconnect();
|
|
|
|
}
|
|
|
|
|
2010-09-14 09:23:08 +04:00
|
|
|
virtual BasicShadowableThebesLayer* AsThebes() { return this; }
|
|
|
|
|
2011-10-10 20:47:27 +04:00
|
|
|
virtual void SyncFrontBufferToBackBuffer();
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
private:
|
|
|
|
BasicShadowLayerManager* BasicManager()
|
|
|
|
{
|
|
|
|
return static_cast<BasicShadowLayerManager*>(mManager);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_OVERRIDE virtual void
|
|
|
|
PaintBuffer(gfxContext* aContext,
|
|
|
|
const nsIntRegion& aRegionToDraw,
|
2011-03-09 20:27:37 +03:00
|
|
|
const nsIntRegion& aExtendedRegionToDraw,
|
2010-07-22 01:17:33 +04:00
|
|
|
const nsIntRegion& aRegionToInvalidate,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aDidSelfCopy,
|
2010-07-22 01:17:33 +04:00
|
|
|
LayerManager::DrawThebesLayerCallback aCallback,
|
|
|
|
void* aCallbackData);
|
|
|
|
|
|
|
|
NS_OVERRIDE virtual already_AddRefed<gfxASurface>
|
|
|
|
CreateBuffer(Buffer::ContentType aType, const nsIntSize& aSize);
|
|
|
|
|
2011-10-10 20:47:27 +04:00
|
|
|
void DestroyBackBuffer()
|
|
|
|
{
|
|
|
|
if (IsSurfaceDescriptorValid(mBackBuffer)) {
|
|
|
|
BasicManager()->ShadowLayerForwarder::DestroySharedSurface(&mBackBuffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-14 09:23:08 +04:00
|
|
|
// This describes the gfxASurface we hand to mBuffer. We keep a
|
|
|
|
// copy of the descriptor here so that we can call
|
|
|
|
// DestroySharedSurface() on the descriptor.
|
|
|
|
SurfaceDescriptor mBackBuffer;
|
2011-10-10 20:47:27 +04:00
|
|
|
nsIntRect mBackBufferRect;
|
|
|
|
nsIntPoint mBackBufferRectRotation;
|
2010-11-13 01:21:05 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mIsNewBuffer;
|
2011-10-10 20:47:27 +04:00
|
|
|
OptionalThebesBuffer mROFrontBuffer;
|
|
|
|
nsIntRegion mFrontUpdatedRegion;
|
|
|
|
nsIntRegion mFrontValidRegion;
|
|
|
|
PRPackedBool mFrontAndBackBufferDiffer;
|
2010-07-22 01:17:33 +04:00
|
|
|
};
|
2010-11-05 10:17:07 +03:00
|
|
|
|
|
|
|
void
|
2011-10-10 20:47:27 +04:00
|
|
|
BasicShadowableThebesLayer::SetBackBufferAndAttrs(const OptionalThebesBuffer& aBuffer,
|
2010-11-05 10:17:07 +03:00
|
|
|
const nsIntRegion& aValidRegion,
|
2010-11-05 10:17:07 +03:00
|
|
|
const OptionalThebesBuffer& aReadOnlyFrontBuffer,
|
|
|
|
const nsIntRegion& aFrontUpdatedRegion)
|
2010-11-05 10:17:07 +03:00
|
|
|
{
|
2011-10-10 20:47:27 +04:00
|
|
|
if (OptionalThebesBuffer::Tnull_t == aBuffer.type()) {
|
|
|
|
mBackBuffer = SurfaceDescriptor();
|
|
|
|
} else {
|
|
|
|
mBackBuffer = aBuffer.get_ThebesBuffer().buffer();
|
|
|
|
mBackBufferRect = aBuffer.get_ThebesBuffer().rect();
|
|
|
|
mBackBufferRectRotation = aBuffer.get_ThebesBuffer().rotation();
|
|
|
|
}
|
|
|
|
mFrontAndBackBufferDiffer = true;
|
|
|
|
mROFrontBuffer = aReadOnlyFrontBuffer;
|
|
|
|
mFrontUpdatedRegion = aFrontUpdatedRegion;
|
|
|
|
mFrontValidRegion = aValidRegion;
|
2011-10-16 00:07:10 +04:00
|
|
|
if (OptionalThebesBuffer::Tnull_t == mROFrontBuffer.type()) {
|
|
|
|
// For null readonly front, we have single buffer mode
|
|
|
|
// so we can do sync right now, because it does not create new buffer and
|
|
|
|
// don't do any graphic operations
|
|
|
|
SyncFrontBufferToBackBuffer();
|
|
|
|
}
|
2011-10-10 20:47:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BasicShadowableThebesLayer::SyncFrontBufferToBackBuffer()
|
|
|
|
{
|
|
|
|
if (!mFrontAndBackBufferDiffer) {
|
|
|
|
return;
|
|
|
|
}
|
2010-11-05 10:17:07 +03:00
|
|
|
|
2011-10-10 20:47:27 +04:00
|
|
|
nsRefPtr<gfxASurface> backBuffer;
|
|
|
|
if (!IsSurfaceDescriptorValid(mBackBuffer)) {
|
|
|
|
NS_ABORT_IF_FALSE(mROFrontBuffer.type() == OptionalThebesBuffer::TThebesBuffer,
|
|
|
|
"should have a front RO buffer by now");
|
|
|
|
const ThebesBuffer roFront = mROFrontBuffer.get_ThebesBuffer();
|
|
|
|
nsRefPtr<gfxASurface> roFrontBuffer = BasicManager()->OpenDescriptor(roFront.buffer());
|
|
|
|
backBuffer = CreateBuffer(roFrontBuffer->GetContentType(), roFrontBuffer->GetSize());
|
|
|
|
} else {
|
|
|
|
backBuffer = BasicManager()->OpenDescriptor(mBackBuffer);
|
|
|
|
}
|
|
|
|
mFrontAndBackBufferDiffer = false;
|
|
|
|
|
|
|
|
if (OptionalThebesBuffer::Tnull_t == mROFrontBuffer.type()) {
|
2010-11-05 10:17:07 +03:00
|
|
|
// We didn't get back a read-only ref to our old back buffer (the
|
|
|
|
// parent's new front buffer). If the parent is pushing updates
|
|
|
|
// to a texture it owns, then we probably got back the same buffer
|
|
|
|
// we pushed in the update and all is well. If not, ...
|
2011-10-10 20:47:27 +04:00
|
|
|
mValidRegion = mFrontValidRegion;
|
|
|
|
mBuffer.SetBackingBuffer(backBuffer, mBackBufferRect, mBackBufferRectRotation);
|
2010-11-05 10:17:07 +03:00
|
|
|
return;
|
|
|
|
}
|
2010-11-05 10:17:07 +03:00
|
|
|
|
2010-11-05 10:17:07 +03:00
|
|
|
MOZ_LAYERS_LOG(("BasicShadowableThebes(%p): reading back <x=%d,y=%d,w=%d,h=%d>",
|
|
|
|
this,
|
2011-10-10 20:47:27 +04:00
|
|
|
mFrontUpdatedRegion.GetBounds().x,
|
|
|
|
mFrontUpdatedRegion.GetBounds().y,
|
|
|
|
mFrontUpdatedRegion.GetBounds().width,
|
|
|
|
mFrontUpdatedRegion.GetBounds().height));
|
2010-11-05 10:17:07 +03:00
|
|
|
|
2011-10-10 20:47:27 +04:00
|
|
|
const ThebesBuffer roFront = mROFrontBuffer.get_ThebesBuffer();
|
2010-11-05 10:17:07 +03:00
|
|
|
nsRefPtr<gfxASurface> roFrontBuffer = BasicManager()->OpenDescriptor(roFront.buffer());
|
|
|
|
mBuffer.SetBackingBufferAndUpdateFrom(
|
|
|
|
backBuffer,
|
|
|
|
roFrontBuffer, roFront.rect(), roFront.rotation(),
|
2011-10-10 20:47:27 +04:00
|
|
|
mFrontUpdatedRegion);
|
|
|
|
mIsNewBuffer = false;
|
2010-11-05 10:17:07 +03:00
|
|
|
// Now the new back buffer has the same (interesting) pixels as the
|
|
|
|
// new front buffer, and mValidRegion et al. are correct wrt the new
|
|
|
|
// back buffer (i.e. as they were for the old back buffer)
|
2010-11-05 10:17:07 +03:00
|
|
|
}
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
void
|
|
|
|
BasicShadowableThebesLayer::PaintBuffer(gfxContext* aContext,
|
|
|
|
const nsIntRegion& aRegionToDraw,
|
2011-03-09 20:27:37 +03:00
|
|
|
const nsIntRegion& aExtendedRegionToDraw,
|
2010-07-22 01:17:33 +04:00
|
|
|
const nsIntRegion& aRegionToInvalidate,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aDidSelfCopy,
|
2010-07-22 01:17:33 +04:00
|
|
|
LayerManager::DrawThebesLayerCallback aCallback,
|
|
|
|
void* aCallbackData)
|
|
|
|
{
|
2011-03-09 20:27:37 +03:00
|
|
|
Base::PaintBuffer(aContext,
|
|
|
|
aRegionToDraw, aExtendedRegionToDraw, aRegionToInvalidate,
|
2011-03-12 08:22:39 +03:00
|
|
|
aDidSelfCopy,
|
2010-07-22 01:17:33 +04:00
|
|
|
aCallback, aCallbackData);
|
2010-11-05 10:17:07 +03:00
|
|
|
if (!HasShadow()) {
|
|
|
|
return;
|
|
|
|
}
|
2010-07-22 01:17:33 +04:00
|
|
|
|
2010-11-13 01:21:05 +03:00
|
|
|
nsIntRegion updatedRegion;
|
2011-03-12 08:22:39 +03:00
|
|
|
if (mIsNewBuffer || aDidSelfCopy) {
|
2010-11-13 01:21:05 +03:00
|
|
|
// A buffer reallocation clears both buffers. The front buffer has all the
|
|
|
|
// content by now, but the back buffer is still clear. Here, in effect, we
|
|
|
|
// are saying to copy all of the pixels of the front buffer to the back.
|
2011-03-12 08:22:39 +03:00
|
|
|
// Also when we self-copied in the buffer, the buffer space
|
|
|
|
// changes and some changed buffer content isn't reflected in the
|
|
|
|
// draw or invalidate region (on purpose!). When this happens, we
|
|
|
|
// need to read back the entire buffer too.
|
2010-11-13 01:21:05 +03:00
|
|
|
updatedRegion = mVisibleRegion;
|
|
|
|
mIsNewBuffer = false;
|
|
|
|
} else {
|
|
|
|
updatedRegion = aRegionToDraw;
|
|
|
|
}
|
|
|
|
|
2011-03-09 20:27:37 +03:00
|
|
|
NS_ASSERTION(mBuffer.BufferRect().Contains(aRegionToDraw.GetBounds()),
|
|
|
|
"Update outside of buffer rect!");
|
2010-11-05 10:17:07 +03:00
|
|
|
NS_ABORT_IF_FALSE(IsSurfaceDescriptorValid(mBackBuffer),
|
|
|
|
"should have a back buffer by now");
|
|
|
|
BasicManager()->PaintedThebesBuffer(BasicManager()->Hold(this),
|
2010-11-13 01:21:05 +03:00
|
|
|
updatedRegion,
|
2010-11-05 10:17:07 +03:00
|
|
|
mBuffer.BufferRect(),
|
|
|
|
mBuffer.BufferRotation(),
|
|
|
|
mBackBuffer);
|
2010-07-22 01:17:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<gfxASurface>
|
|
|
|
BasicShadowableThebesLayer::CreateBuffer(Buffer::ContentType aType,
|
|
|
|
const nsIntSize& aSize)
|
|
|
|
{
|
2010-09-14 09:23:08 +04:00
|
|
|
if (!HasShadow()) {
|
|
|
|
return BasicThebesLayer::CreateBuffer(aType, aSize);
|
|
|
|
}
|
2010-09-03 07:05:01 +04:00
|
|
|
|
2010-11-05 10:17:07 +03:00
|
|
|
MOZ_LAYERS_LOG(("BasicShadowableThebes(%p): creating %d x %d buffer(x2)",
|
|
|
|
this,
|
|
|
|
aSize.width, aSize.height));
|
|
|
|
|
2010-09-14 09:23:08 +04:00
|
|
|
if (IsSurfaceDescriptorValid(mBackBuffer)) {
|
2011-10-11 03:43:56 +04:00
|
|
|
BasicManager()->DestroyedThebesBuffer(BasicManager()->Hold(this),
|
|
|
|
mBackBuffer);
|
2010-09-14 09:23:08 +04:00
|
|
|
mBackBuffer = SurfaceDescriptor();
|
2010-09-14 09:23:08 +04:00
|
|
|
}
|
2010-09-03 07:05:01 +04:00
|
|
|
|
2010-09-14 09:23:08 +04:00
|
|
|
// XXX error handling
|
2011-10-10 20:47:27 +04:00
|
|
|
if (!BasicManager()->AllocBuffer(gfxIntSize(aSize.width, aSize.height),
|
|
|
|
aType,
|
|
|
|
&mBackBuffer)) {
|
2010-12-31 10:40:31 +03:00
|
|
|
NS_RUNTIMEABORT("creating ThebesLayer 'back buffer' failed!");
|
|
|
|
}
|
2010-11-05 10:17:07 +03:00
|
|
|
|
2010-11-13 01:21:05 +03:00
|
|
|
NS_ABORT_IF_FALSE(!mIsNewBuffer,
|
|
|
|
"Bad! Did we create a buffer twice without painting?");
|
2011-10-10 20:47:27 +04:00
|
|
|
|
2010-11-13 01:21:05 +03:00
|
|
|
mIsNewBuffer = true;
|
|
|
|
|
2010-09-14 09:23:08 +04:00
|
|
|
return BasicManager()->OpenDescriptor(mBackBuffer);
|
2010-07-22 01:17:33 +04:00
|
|
|
}
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
|
|
|
|
class BasicShadowableImageLayer : public BasicImageLayer,
|
|
|
|
public BasicShadowableLayer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
BasicShadowableImageLayer(BasicShadowLayerManager* aManager) :
|
|
|
|
BasicImageLayer(aManager)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(BasicShadowableImageLayer);
|
|
|
|
}
|
|
|
|
virtual ~BasicShadowableImageLayer()
|
|
|
|
{
|
2011-09-28 02:19:26 +04:00
|
|
|
DestroyBackBuffer();
|
2010-07-22 01:17:33 +04:00
|
|
|
MOZ_COUNT_DTOR(BasicShadowableImageLayer);
|
|
|
|
}
|
|
|
|
|
2011-02-17 01:43:30 +03:00
|
|
|
virtual void Paint(gfxContext* aContext);
|
2010-07-22 01:17:33 +04:00
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
virtual void FillSpecificAttributes(SpecificLayerAttributes& aAttrs)
|
|
|
|
{
|
|
|
|
aAttrs = ImageLayerAttributes(mFilter);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual Layer* AsLayer() { return this; }
|
|
|
|
virtual ShadowableLayer* AsShadowableLayer() { return this; }
|
2010-07-22 01:17:33 +04:00
|
|
|
|
2011-04-21 01:45:57 +04:00
|
|
|
virtual void SetBackBuffer(const SurfaceDescriptor& aBuffer)
|
2010-07-22 01:17:33 +04:00
|
|
|
{
|
2011-04-21 01:45:57 +04:00
|
|
|
mBackBuffer = aBuffer;
|
2010-07-22 01:17:33 +04:00
|
|
|
}
|
|
|
|
|
2011-04-21 08:38:39 +04:00
|
|
|
virtual void SetBackBufferYUVImage(gfxSharedImageSurface* aYBuffer,
|
|
|
|
gfxSharedImageSurface* aUBuffer,
|
|
|
|
gfxSharedImageSurface* aVBuffer)
|
|
|
|
{
|
|
|
|
mBackBufferY = aYBuffer;
|
|
|
|
mBackBufferU = aUBuffer;
|
|
|
|
mBackBufferV = aVBuffer;
|
|
|
|
}
|
|
|
|
|
2010-08-21 03:24:41 +04:00
|
|
|
virtual void Disconnect()
|
|
|
|
{
|
2011-09-28 02:19:26 +04:00
|
|
|
mBackBufferY = mBackBufferU = mBackBufferV = nsnull;
|
2011-04-21 01:45:57 +04:00
|
|
|
mBackBuffer = SurfaceDescriptor();
|
2010-08-21 03:24:41 +04:00
|
|
|
BasicShadowableLayer::Disconnect();
|
|
|
|
}
|
|
|
|
|
2011-09-28 02:19:26 +04:00
|
|
|
void DestroyBackBuffer()
|
|
|
|
{
|
|
|
|
if (IsSurfaceDescriptorValid(mBackBuffer)) {
|
|
|
|
BasicManager()->ShadowLayerForwarder::DestroySharedSurface(&mBackBuffer);
|
|
|
|
}
|
|
|
|
if (mBackBufferY) {
|
|
|
|
BasicManager()->ShadowLayerForwarder::DestroySharedSurface(mBackBufferY);
|
|
|
|
BasicManager()->ShadowLayerForwarder::DestroySharedSurface(mBackBufferU);
|
|
|
|
BasicManager()->ShadowLayerForwarder::DestroySharedSurface(mBackBufferV);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
private:
|
|
|
|
BasicShadowLayerManager* BasicManager()
|
|
|
|
{
|
|
|
|
return static_cast<BasicShadowLayerManager*>(mManager);
|
|
|
|
}
|
|
|
|
|
2011-04-21 08:38:39 +04:00
|
|
|
// For YUV Images these are the 3 planes (Y, Cb and Cr),
|
|
|
|
// for RGB images only mBackSurface is used.
|
2011-04-21 01:45:57 +04:00
|
|
|
SurfaceDescriptor mBackBuffer;
|
2011-04-21 08:38:39 +04:00
|
|
|
nsRefPtr<gfxSharedImageSurface> mBackBufferY;
|
|
|
|
nsRefPtr<gfxSharedImageSurface> mBackBufferU;
|
|
|
|
nsRefPtr<gfxSharedImageSurface> mBackBufferV;
|
|
|
|
gfxIntSize mCbCrSize;
|
2010-07-22 01:17:33 +04:00
|
|
|
};
|
2010-07-22 01:17:33 +04:00
|
|
|
|
|
|
|
void
|
2011-02-17 01:43:30 +03:00
|
|
|
BasicShadowableImageLayer::Paint(gfxContext* aContext)
|
2010-07-22 01:17:33 +04:00
|
|
|
{
|
2011-05-13 04:38:44 +04:00
|
|
|
if (!mContainer) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-04-21 08:38:39 +04:00
|
|
|
nsRefPtr<Image> image = mContainer->GetCurrentImage();
|
2011-05-13 04:38:44 +04:00
|
|
|
if (!image) {
|
|
|
|
return;
|
|
|
|
}
|
2011-04-21 08:38:39 +04:00
|
|
|
|
|
|
|
if (image->GetFormat() == Image::PLANAR_YCBCR && BasicManager()->IsCompositingCheap()) {
|
|
|
|
PlanarYCbCrImage *YCbCrImage = static_cast<PlanarYCbCrImage*>(image.get());
|
|
|
|
const PlanarYCbCrImage::Data *data = YCbCrImage->GetData();
|
|
|
|
NS_ASSERTION(data, "Must be able to retrieve yuv data from image!");
|
|
|
|
|
2011-09-28 02:19:26 +04:00
|
|
|
if (mSize != data->mYSize || mCbCrSize != data->mCbCrSize || !mBackBufferY) {
|
|
|
|
DestroyBackBuffer();
|
2011-04-21 08:38:39 +04:00
|
|
|
mSize = data->mYSize;
|
|
|
|
mCbCrSize = data->mCbCrSize;
|
|
|
|
|
2011-09-28 02:19:26 +04:00
|
|
|
if (!BasicManager()->AllocBuffer(mSize, gfxASurface::CONTENT_ALPHA,
|
|
|
|
getter_AddRefs(mBackBufferY)) ||
|
|
|
|
!BasicManager()->AllocBuffer(mCbCrSize, gfxASurface::CONTENT_ALPHA,
|
|
|
|
getter_AddRefs(mBackBufferU)) ||
|
|
|
|
!BasicManager()->AllocBuffer(mCbCrSize, gfxASurface::CONTENT_ALPHA,
|
|
|
|
getter_AddRefs(mBackBufferV))) {
|
2011-04-21 08:38:39 +04:00
|
|
|
NS_RUNTIMEABORT("creating ImageLayer 'front buffer' failed!");
|
2011-09-28 02:19:26 +04:00
|
|
|
}
|
2011-04-21 08:38:39 +04:00
|
|
|
}
|
2011-09-28 02:19:26 +04:00
|
|
|
|
2011-07-05 06:52:00 +04:00
|
|
|
for (int i = 0; i < data->mYSize.height; i++) {
|
|
|
|
memcpy(mBackBufferY->Data() + i * mBackBufferY->Stride(),
|
|
|
|
data->mYChannel + i * data->mYStride,
|
|
|
|
data->mYSize.width);
|
|
|
|
}
|
|
|
|
for (int i = 0; i < data->mCbCrSize.height; i++) {
|
|
|
|
memcpy(mBackBufferU->Data() + i * mBackBufferU->Stride(),
|
|
|
|
data->mCbChannel + i * data->mCbCrStride,
|
|
|
|
data->mCbCrSize.width);
|
|
|
|
memcpy(mBackBufferV->Data() + i * mBackBufferV->Stride(),
|
|
|
|
data->mCrChannel + i * data->mCbCrStride,
|
|
|
|
data->mCbCrSize.width);
|
|
|
|
}
|
2011-09-28 02:19:26 +04:00
|
|
|
|
2011-04-21 08:38:39 +04:00
|
|
|
YUVImage yuv(mBackBufferY->GetShmem(),
|
|
|
|
mBackBufferU->GetShmem(),
|
2011-07-05 06:52:00 +04:00
|
|
|
mBackBufferV->GetShmem(),
|
|
|
|
data->GetPictureRect());
|
2011-09-28 02:19:26 +04:00
|
|
|
|
2011-04-21 08:38:39 +04:00
|
|
|
BasicManager()->PaintedImage(BasicManager()->Hold(this),
|
|
|
|
yuv);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
gfxIntSize oldSize = mSize;
|
2010-11-08 12:06:15 +03:00
|
|
|
nsRefPtr<gfxPattern> pat = GetAndPaintCurrentImage(aContext, GetEffectiveOpacity());
|
2010-07-22 01:17:33 +04:00
|
|
|
if (!pat || !HasShadow())
|
|
|
|
return;
|
|
|
|
|
2011-09-28 02:19:26 +04:00
|
|
|
if (oldSize != mSize || !IsSurfaceDescriptorValid(mBackBuffer)) {
|
|
|
|
DestroyBackBuffer();
|
2010-09-03 07:05:01 +04:00
|
|
|
|
2011-09-28 02:19:26 +04:00
|
|
|
if (!BasicManager()->AllocBuffer(
|
2010-09-17 01:24:17 +04:00
|
|
|
mSize,
|
|
|
|
(GetContentFlags() & CONTENT_OPAQUE) ?
|
|
|
|
gfxASurface::CONTENT_COLOR : gfxASurface::CONTENT_COLOR_ALPHA,
|
2011-09-28 02:19:26 +04:00
|
|
|
&mBackBuffer))
|
2010-07-22 01:17:33 +04:00
|
|
|
NS_RUNTIMEABORT("creating ImageLayer 'front buffer' failed!");
|
|
|
|
}
|
|
|
|
|
2011-04-21 01:45:57 +04:00
|
|
|
nsRefPtr<gfxASurface> backSurface =
|
|
|
|
BasicManager()->OpenDescriptor(mBackBuffer);
|
|
|
|
nsRefPtr<gfxContext> tmpCtx = new gfxContext(backSurface);
|
2011-09-14 11:51:24 +04:00
|
|
|
tmpCtx->SetOperator(gfxContext::OPERATOR_SOURCE);
|
2011-01-26 09:26:37 +03:00
|
|
|
PaintContext(pat,
|
|
|
|
nsIntRegion(nsIntRect(0, 0, mSize.width, mSize.height)),
|
|
|
|
nsnull, 1.0, tmpCtx);
|
2010-07-22 01:17:33 +04:00
|
|
|
|
|
|
|
BasicManager()->PaintedImage(BasicManager()->Hold(this),
|
2011-04-21 01:45:57 +04:00
|
|
|
mBackBuffer);
|
2010-07-22 01:17:33 +04:00
|
|
|
}
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
|
|
|
|
class BasicShadowableColorLayer : public BasicColorLayer,
|
|
|
|
public BasicShadowableLayer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
BasicShadowableColorLayer(BasicShadowLayerManager* aManager) :
|
|
|
|
BasicColorLayer(aManager)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(BasicShadowableColorLayer);
|
|
|
|
}
|
|
|
|
virtual ~BasicShadowableColorLayer()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(BasicShadowableColorLayer);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void FillSpecificAttributes(SpecificLayerAttributes& aAttrs)
|
|
|
|
{
|
|
|
|
aAttrs = ColorLayerAttributes(GetColor());
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual Layer* AsLayer() { return this; }
|
|
|
|
virtual ShadowableLayer* AsShadowableLayer() { return this; }
|
2010-08-21 03:24:41 +04:00
|
|
|
|
|
|
|
virtual void Disconnect()
|
|
|
|
{
|
|
|
|
BasicShadowableLayer::Disconnect();
|
|
|
|
}
|
2010-07-22 01:17:33 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
class BasicShadowableCanvasLayer : public BasicCanvasLayer,
|
|
|
|
public BasicShadowableLayer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
BasicShadowableCanvasLayer(BasicShadowLayerManager* aManager) :
|
|
|
|
BasicCanvasLayer(aManager)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(BasicShadowableCanvasLayer);
|
|
|
|
}
|
|
|
|
virtual ~BasicShadowableCanvasLayer()
|
|
|
|
{
|
2011-09-28 02:19:28 +04:00
|
|
|
DestroyBackBuffer();
|
2010-07-22 01:17:33 +04:00
|
|
|
MOZ_COUNT_DTOR(BasicShadowableCanvasLayer);
|
|
|
|
}
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
virtual void Initialize(const Data& aData);
|
2011-02-17 01:43:30 +03:00
|
|
|
virtual void Paint(gfxContext* aContext);
|
2010-07-22 01:17:33 +04:00
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
virtual void FillSpecificAttributes(SpecificLayerAttributes& aAttrs)
|
|
|
|
{
|
|
|
|
aAttrs = CanvasLayerAttributes(mFilter);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual Layer* AsLayer() { return this; }
|
|
|
|
virtual ShadowableLayer* AsShadowableLayer() { return this; }
|
2010-07-22 01:17:33 +04:00
|
|
|
|
2011-04-21 01:45:57 +04:00
|
|
|
virtual void SetBackBuffer(const SurfaceDescriptor& aBuffer)
|
2010-07-22 01:17:33 +04:00
|
|
|
{
|
|
|
|
mBackBuffer = aBuffer;
|
|
|
|
}
|
2011-04-21 01:45:57 +04:00
|
|
|
|
2010-08-21 03:24:41 +04:00
|
|
|
virtual void Disconnect()
|
|
|
|
{
|
2011-04-21 01:45:57 +04:00
|
|
|
mBackBuffer = SurfaceDescriptor();
|
2010-08-21 03:24:41 +04:00
|
|
|
BasicShadowableLayer::Disconnect();
|
|
|
|
}
|
2010-07-22 01:17:33 +04:00
|
|
|
|
2011-09-28 02:19:28 +04:00
|
|
|
void DestroyBackBuffer()
|
|
|
|
{
|
|
|
|
if (IsSurfaceDescriptorValid(mBackBuffer)) {
|
|
|
|
BasicManager()->ShadowLayerForwarder::DestroySharedSurface(&mBackBuffer);
|
|
|
|
mBackBuffer = SurfaceDescriptor();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
private:
|
|
|
|
BasicShadowLayerManager* BasicManager()
|
|
|
|
{
|
|
|
|
return static_cast<BasicShadowLayerManager*>(mManager);
|
|
|
|
}
|
|
|
|
|
2011-04-21 01:45:57 +04:00
|
|
|
SurfaceDescriptor mBackBuffer;
|
2010-07-22 01:17:33 +04:00
|
|
|
};
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
void
|
|
|
|
BasicShadowableCanvasLayer::Initialize(const Data& aData)
|
|
|
|
{
|
|
|
|
BasicCanvasLayer::Initialize(aData);
|
|
|
|
if (!HasShadow())
|
|
|
|
return;
|
|
|
|
|
2010-09-03 07:05:01 +04:00
|
|
|
// XXX won't get here currently; need to figure out what to do on
|
|
|
|
// canvas resizes
|
2011-04-21 01:45:57 +04:00
|
|
|
|
|
|
|
if (IsSurfaceDescriptorValid(mBackBuffer)) {
|
2011-09-28 02:19:28 +04:00
|
|
|
nsRefPtr<gfxASurface> backSurface =
|
|
|
|
BasicManager()->OpenDescriptor(mBackBuffer);
|
|
|
|
if (gfxIntSize(mBounds.width, mBounds.height) != backSurface->GetSize()) {
|
|
|
|
DestroyBackBuffer();
|
|
|
|
}
|
2010-09-03 07:05:01 +04:00
|
|
|
}
|
2010-07-22 01:17:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-02-17 01:43:30 +03:00
|
|
|
BasicShadowableCanvasLayer::Paint(gfxContext* aContext)
|
2010-07-22 01:17:33 +04:00
|
|
|
{
|
2011-06-10 05:17:02 +04:00
|
|
|
if (!HasShadow()) {
|
|
|
|
BasicCanvasLayer::Paint(aContext);
|
2010-07-22 01:17:33 +04:00
|
|
|
return;
|
2011-06-10 05:17:02 +04:00
|
|
|
}
|
2010-07-22 01:17:33 +04:00
|
|
|
|
2011-09-28 02:19:28 +04:00
|
|
|
if (!IsSurfaceDescriptorValid(mBackBuffer)) {
|
|
|
|
if (!BasicManager()->AllocBuffer(
|
|
|
|
gfxIntSize(mBounds.width, mBounds.height),
|
|
|
|
(GetContentFlags() & CONTENT_OPAQUE) ?
|
|
|
|
gfxASurface::CONTENT_COLOR : gfxASurface::CONTENT_COLOR_ALPHA,
|
|
|
|
&mBackBuffer))
|
|
|
|
NS_RUNTIMEABORT("creating CanvasLayer back buffer failed!");
|
|
|
|
}
|
|
|
|
|
2011-04-21 01:45:57 +04:00
|
|
|
nsRefPtr<gfxASurface> backSurface =
|
|
|
|
BasicManager()->OpenDescriptor(mBackBuffer);
|
2011-01-19 11:55:31 +03:00
|
|
|
|
2011-06-10 05:17:02 +04:00
|
|
|
UpdateSurface(backSurface);
|
|
|
|
FireDidTransactionCallback();
|
2010-07-22 01:17:33 +04:00
|
|
|
|
|
|
|
BasicManager()->PaintedCanvas(BasicManager()->Hold(this),
|
2011-09-28 02:19:28 +04:00
|
|
|
mNeedsYFlip ? true : false,
|
2010-07-22 01:17:33 +04:00
|
|
|
mBackBuffer);
|
|
|
|
}
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
class ShadowThebesLayerBuffer : public BasicThebesLayerBuffer
|
|
|
|
{
|
|
|
|
typedef BasicThebesLayerBuffer Base;
|
|
|
|
|
|
|
|
public:
|
|
|
|
ShadowThebesLayerBuffer()
|
|
|
|
: Base(NULL)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(ShadowThebesLayerBuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
~ShadowThebesLayerBuffer()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(ShadowThebesLayerBuffer);
|
|
|
|
}
|
|
|
|
|
2010-09-14 09:23:08 +04:00
|
|
|
void Swap(gfxASurface* aNewBuffer,
|
|
|
|
const nsIntRect& aNewRect, const nsIntPoint& aNewRotation,
|
|
|
|
gfxASurface** aOldBuffer,
|
|
|
|
nsIntRect* aOldRect, nsIntPoint* aOldRotation)
|
|
|
|
{
|
|
|
|
*aOldRect = BufferRect();
|
|
|
|
*aOldRotation = BufferRotation();
|
|
|
|
|
|
|
|
nsRefPtr<gfxASurface> oldBuffer;
|
|
|
|
oldBuffer = SetBuffer(aNewBuffer,
|
|
|
|
aNewRect, aNewRotation);
|
|
|
|
oldBuffer.forget(aOldBuffer);
|
2010-07-22 01:17:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual already_AddRefed<gfxASurface>
|
2011-09-24 23:01:18 +04:00
|
|
|
CreateBuffer(ContentType, const nsIntSize&, PRUint32)
|
2010-07-22 01:17:33 +04:00
|
|
|
{
|
|
|
|
NS_RUNTIMEABORT("ShadowThebesLayer can't paint content");
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
};
|
2010-07-22 01:17:33 +04:00
|
|
|
|
2010-09-14 09:23:08 +04:00
|
|
|
|
2011-05-30 07:48:13 +04:00
|
|
|
class BasicShadowThebesLayer : public ShadowThebesLayer, public BasicImplData {
|
2010-07-22 01:17:33 +04:00
|
|
|
public:
|
2010-09-14 09:23:08 +04:00
|
|
|
BasicShadowThebesLayer(BasicShadowLayerManager* aLayerManager)
|
|
|
|
: ShadowThebesLayer(aLayerManager, static_cast<BasicImplData*>(this))
|
2010-07-22 01:17:33 +04:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(BasicShadowThebesLayer);
|
|
|
|
}
|
2010-08-21 03:24:41 +04:00
|
|
|
virtual ~BasicShadowThebesLayer()
|
|
|
|
{
|
|
|
|
// If Disconnect() wasn't called on us, then we assume that the
|
|
|
|
// remote side shut down and IPC is disconnected, so we let IPDL
|
|
|
|
// clean up our front surface Shmem.
|
|
|
|
MOZ_COUNT_DTOR(BasicShadowThebesLayer);
|
|
|
|
}
|
|
|
|
|
2010-09-14 09:23:08 +04:00
|
|
|
virtual void SetValidRegion(const nsIntRegion& aRegion)
|
|
|
|
{
|
|
|
|
mOldValidRegion = mValidRegion;
|
|
|
|
ShadowThebesLayer::SetValidRegion(aRegion);
|
|
|
|
}
|
|
|
|
|
2010-09-03 07:05:01 +04:00
|
|
|
virtual void Disconnect()
|
|
|
|
{
|
|
|
|
DestroyFrontBuffer();
|
|
|
|
ShadowThebesLayer::Disconnect();
|
|
|
|
}
|
2010-07-22 01:17:33 +04:00
|
|
|
|
2010-09-14 09:23:08 +04:00
|
|
|
virtual void
|
|
|
|
Swap(const ThebesBuffer& aNewFront, const nsIntRegion& aUpdatedRegion,
|
2011-10-10 20:47:27 +04:00
|
|
|
OptionalThebesBuffer* aNewBack, nsIntRegion* aNewBackValidRegion,
|
2010-11-05 10:17:07 +03:00
|
|
|
OptionalThebesBuffer* aReadOnlyFront, nsIntRegion* aFrontUpdatedRegion);
|
2010-07-22 01:17:33 +04:00
|
|
|
|
2010-09-03 07:05:01 +04:00
|
|
|
virtual void DestroyFrontBuffer()
|
|
|
|
{
|
2010-09-14 09:23:08 +04:00
|
|
|
mFrontBuffer.Clear();
|
2010-09-16 01:03:13 +04:00
|
|
|
mValidRegion.SetEmpty();
|
2010-09-14 09:23:08 +04:00
|
|
|
mOldValidRegion.SetEmpty();
|
|
|
|
|
2010-09-14 09:23:08 +04:00
|
|
|
if (IsSurfaceDescriptorValid(mFrontBufferDescriptor)) {
|
2011-09-28 02:19:26 +04:00
|
|
|
mAllocator->DestroySharedSurface(&mFrontBufferDescriptor);
|
2011-10-10 20:47:27 +04:00
|
|
|
mFrontBufferDescriptor = SurfaceDescriptor();
|
2010-09-03 07:05:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-17 01:43:30 +03:00
|
|
|
virtual void PaintThebes(gfxContext* aContext,
|
|
|
|
LayerManager::DrawThebesLayerCallback aCallback,
|
|
|
|
void* aCallbackData,
|
|
|
|
ReadbackProcessor* aReadback);
|
2010-07-22 01:17:33 +04:00
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
private:
|
|
|
|
BasicShadowLayerManager* BasicManager()
|
|
|
|
{
|
|
|
|
return static_cast<BasicShadowLayerManager*>(mManager);
|
|
|
|
}
|
|
|
|
|
|
|
|
ShadowThebesLayerBuffer mFrontBuffer;
|
2010-09-14 09:23:08 +04:00
|
|
|
// Describes the gfxASurface we hand out to |mFrontBuffer|.
|
|
|
|
SurfaceDescriptor mFrontBufferDescriptor;
|
2010-09-14 09:23:08 +04:00
|
|
|
// When we receive an update from our remote partner, we stow away
|
|
|
|
// our previous parameters that described our previous front buffer.
|
|
|
|
// Then when we Swap() back/front buffers, we can return these
|
|
|
|
// parameters to our partner (adjusted as needed).
|
|
|
|
nsIntRegion mOldValidRegion;
|
2010-07-22 01:17:33 +04:00
|
|
|
};
|
|
|
|
|
2010-09-14 09:23:08 +04:00
|
|
|
void
|
|
|
|
BasicShadowThebesLayer::Swap(const ThebesBuffer& aNewFront,
|
|
|
|
const nsIntRegion& aUpdatedRegion,
|
2011-10-10 20:47:27 +04:00
|
|
|
OptionalThebesBuffer* aNewBack,
|
2010-09-14 09:23:08 +04:00
|
|
|
nsIntRegion* aNewBackValidRegion,
|
2010-11-05 10:17:07 +03:00
|
|
|
OptionalThebesBuffer* aReadOnlyFront,
|
|
|
|
nsIntRegion* aFrontUpdatedRegion)
|
2010-09-14 09:23:08 +04:00
|
|
|
{
|
2011-10-10 20:47:27 +04:00
|
|
|
nsRefPtr<gfxASurface> newFrontBuffer =
|
|
|
|
BasicManager()->OpenDescriptor(aNewFront.buffer());
|
|
|
|
|
|
|
|
if (IsSurfaceDescriptorValid(mFrontBufferDescriptor)) {
|
|
|
|
nsRefPtr<gfxASurface> currentFront = BasicManager()->OpenDescriptor(mFrontBufferDescriptor);
|
|
|
|
if (currentFront->GetSize() != newFrontBuffer->GetSize()) {
|
|
|
|
// Current front buffer is obsolete
|
|
|
|
DestroyFrontBuffer();
|
|
|
|
}
|
|
|
|
}
|
2010-09-16 01:03:13 +04:00
|
|
|
// This code relies on Swap() arriving *after* attribute mutations.
|
2011-10-10 20:47:27 +04:00
|
|
|
if (IsSurfaceDescriptorValid(mFrontBufferDescriptor)) {
|
|
|
|
*aNewBack = ThebesBuffer();
|
|
|
|
aNewBack->get_ThebesBuffer().buffer() = mFrontBufferDescriptor;
|
|
|
|
} else {
|
|
|
|
*aNewBack = null_t();
|
|
|
|
}
|
2010-09-14 09:23:08 +04:00
|
|
|
// We have to invalidate the pixels painted into the new buffer.
|
|
|
|
// They might overlap with our old pixels.
|
2011-06-22 16:11:28 +04:00
|
|
|
aNewBackValidRegion->Sub(mOldValidRegion, aUpdatedRegion);
|
2010-09-14 09:23:08 +04:00
|
|
|
|
|
|
|
nsRefPtr<gfxASurface> unused;
|
2011-10-10 20:47:27 +04:00
|
|
|
nsIntRect backRect;
|
|
|
|
nsIntPoint backRotation;
|
2010-09-14 09:23:08 +04:00
|
|
|
mFrontBuffer.Swap(
|
|
|
|
newFrontBuffer, aNewFront.rect(), aNewFront.rotation(),
|
2011-10-10 20:47:27 +04:00
|
|
|
getter_AddRefs(unused), &backRect, &backRotation);
|
|
|
|
|
|
|
|
if (aNewBack->type() != OptionalThebesBuffer::Tnull_t) {
|
|
|
|
aNewBack->get_ThebesBuffer().rect() = backRect;
|
|
|
|
aNewBack->get_ThebesBuffer().rotation() = backRotation;
|
|
|
|
}
|
2010-09-14 09:23:08 +04:00
|
|
|
|
2010-09-14 09:23:08 +04:00
|
|
|
mFrontBufferDescriptor = aNewFront.buffer();
|
2010-11-05 10:17:07 +03:00
|
|
|
|
2010-11-05 10:17:07 +03:00
|
|
|
*aReadOnlyFront = aNewFront;
|
|
|
|
*aFrontUpdatedRegion = aUpdatedRegion;
|
2010-09-14 09:23:08 +04:00
|
|
|
}
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
void
|
2011-02-17 01:43:30 +03:00
|
|
|
BasicShadowThebesLayer::PaintThebes(gfxContext* aContext,
|
|
|
|
LayerManager::DrawThebesLayerCallback aCallback,
|
|
|
|
void* aCallbackData,
|
|
|
|
ReadbackProcessor* aReadback)
|
2010-07-22 01:17:33 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(BasicManager()->InDrawing(),
|
|
|
|
"Can only draw in drawing phase");
|
|
|
|
NS_ASSERTION(BasicManager()->IsRetained(),
|
|
|
|
"ShadowThebesLayer makes no sense without retained mode");
|
|
|
|
|
2010-08-21 03:24:41 +04:00
|
|
|
if (!mFrontBuffer.GetBuffer()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-05-30 07:48:01 +04:00
|
|
|
mFrontBuffer.DrawTo(this, aContext, GetEffectiveOpacity());
|
2010-07-22 01:17:33 +04:00
|
|
|
}
|
|
|
|
|
2011-05-30 07:48:13 +04:00
|
|
|
class BasicShadowContainerLayer : public ShadowContainerLayer, public BasicImplData {
|
2010-10-14 02:55:45 +04:00
|
|
|
template<class Container>
|
|
|
|
friend void ContainerInsertAfter(Layer* aChild, Layer* aAfter, Container* aContainer);
|
|
|
|
template<class Container>
|
|
|
|
friend void ContainerRemoveChild(Layer* aChild, Container* aContainer);
|
|
|
|
|
|
|
|
public:
|
|
|
|
BasicShadowContainerLayer(BasicShadowLayerManager* aLayerManager) :
|
|
|
|
ShadowContainerLayer(aLayerManager, static_cast<BasicImplData*>(this))
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(BasicShadowContainerLayer);
|
|
|
|
}
|
|
|
|
virtual ~BasicShadowContainerLayer()
|
|
|
|
{
|
|
|
|
while (mFirstChild) {
|
|
|
|
ContainerRemoveChild(mFirstChild, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_COUNT_DTOR(BasicShadowContainerLayer);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void InsertAfter(Layer* aChild, Layer* aAfter)
|
|
|
|
{ ContainerInsertAfter(aChild, aAfter, this); }
|
|
|
|
virtual void RemoveChild(Layer* aChild)
|
|
|
|
{ ContainerRemoveChild(aChild, this); }
|
2010-11-08 12:06:15 +03:00
|
|
|
|
|
|
|
virtual void ComputeEffectiveTransforms(const gfx3DMatrix& aTransformToSurface)
|
|
|
|
{
|
|
|
|
// We push groups for container layers if we need to, which always
|
|
|
|
// are aligned in device space, so it doesn't really matter how we snap
|
|
|
|
// containers.
|
2011-08-27 04:04:06 +04:00
|
|
|
gfxMatrix residual;
|
2010-11-08 12:06:15 +03:00
|
|
|
gfx3DMatrix idealTransform = GetLocalTransform()*aTransformToSurface;
|
2011-08-27 04:04:06 +04:00
|
|
|
|
|
|
|
if (!idealTransform.CanDraw2D()) {
|
|
|
|
mEffectiveTransform = idealTransform;
|
|
|
|
ComputeEffectiveTransformsForChildren(gfx3DMatrix());
|
2011-10-17 18:59:28 +04:00
|
|
|
mUseIntermediateSurface = true;
|
2011-08-27 04:04:06 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mEffectiveTransform = SnapTransform(idealTransform, gfxRect(0, 0, 0, 0), &residual);
|
2010-11-08 12:06:15 +03:00
|
|
|
// We always pass the ideal matrix down to our children, so there is no
|
|
|
|
// need to apply any compensation using the residual from SnapTransform.
|
|
|
|
ComputeEffectiveTransformsForChildren(idealTransform);
|
|
|
|
|
|
|
|
/* If we have a single child, it can just inherit our opacity,
|
|
|
|
* otherwise we need a PushGroup and we need to mark ourselves as using
|
|
|
|
* an intermediate surface so our children don't inherit our opacity
|
|
|
|
* via GetEffectiveOpacity.
|
|
|
|
*/
|
|
|
|
mUseIntermediateSurface = GetEffectiveOpacity() != 1.0 && HasMultipleChildren();
|
|
|
|
}
|
2010-10-14 02:55:45 +04:00
|
|
|
};
|
2010-07-22 01:17:33 +04:00
|
|
|
|
2011-05-30 07:48:13 +04:00
|
|
|
class BasicShadowImageLayer : public ShadowImageLayer, public BasicImplData {
|
2010-07-22 01:17:33 +04:00
|
|
|
public:
|
|
|
|
BasicShadowImageLayer(BasicShadowLayerManager* aLayerManager) :
|
|
|
|
ShadowImageLayer(aLayerManager, static_cast<BasicImplData*>(this))
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(BasicShadowImageLayer);
|
|
|
|
}
|
|
|
|
virtual ~BasicShadowImageLayer()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(BasicShadowImageLayer);
|
|
|
|
}
|
|
|
|
|
2010-09-03 07:05:01 +04:00
|
|
|
virtual void Disconnect()
|
|
|
|
{
|
2011-09-28 02:19:26 +04:00
|
|
|
mFrontBuffer = SurfaceDescriptor();
|
2010-09-03 07:05:01 +04:00
|
|
|
ShadowImageLayer::Disconnect();
|
|
|
|
}
|
2010-08-21 03:24:41 +04:00
|
|
|
|
2011-09-28 02:19:26 +04:00
|
|
|
virtual void Swap(const SharedImage& aNewFront,
|
|
|
|
SharedImage* aNewBack);
|
2010-07-22 01:17:33 +04:00
|
|
|
|
2010-09-03 07:05:01 +04:00
|
|
|
virtual void DestroyFrontBuffer()
|
|
|
|
{
|
2011-09-28 02:19:26 +04:00
|
|
|
if (mAllocator && IsSurfaceDescriptorValid(mFrontBuffer)) {
|
|
|
|
mAllocator->DestroySharedSurface(&mFrontBuffer);
|
2010-09-03 07:05:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-17 01:43:30 +03:00
|
|
|
virtual void Paint(gfxContext* aContext);
|
2010-07-22 01:17:33 +04:00
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
protected:
|
|
|
|
BasicShadowLayerManager* BasicManager()
|
|
|
|
{
|
|
|
|
return static_cast<BasicShadowLayerManager*>(mManager);
|
|
|
|
}
|
|
|
|
|
2011-04-21 01:45:57 +04:00
|
|
|
SurfaceDescriptor mFrontBuffer;
|
2010-07-22 01:17:33 +04:00
|
|
|
gfxIntSize mSize;
|
2010-07-22 01:17:33 +04:00
|
|
|
};
|
|
|
|
|
2011-04-21 01:45:57 +04:00
|
|
|
void
|
2011-09-28 02:19:26 +04:00
|
|
|
BasicShadowImageLayer::Swap(const SharedImage& aNewFront,
|
|
|
|
SharedImage* aNewBack)
|
2010-07-22 01:17:33 +04:00
|
|
|
{
|
2011-09-28 02:19:26 +04:00
|
|
|
nsRefPtr<gfxASurface> surface =
|
|
|
|
BasicManager()->OpenDescriptor(aNewFront);
|
|
|
|
// Destroy mFrontBuffer if size different
|
|
|
|
if (surface->GetSize() != mSize) {
|
|
|
|
DestroyFrontBuffer();
|
|
|
|
mSize = surface->GetSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
// If mFrontBuffer
|
|
|
|
if (IsSurfaceDescriptorValid(mFrontBuffer)) {
|
|
|
|
*aNewBack = mFrontBuffer;
|
|
|
|
} else {
|
|
|
|
*aNewBack = null_t();
|
|
|
|
}
|
2011-04-21 03:21:56 +04:00
|
|
|
mFrontBuffer = aNewFront.get_SurfaceDescriptor();
|
2010-07-22 01:17:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-02-17 01:43:30 +03:00
|
|
|
BasicShadowImageLayer::Paint(gfxContext* aContext)
|
2010-07-22 01:17:33 +04:00
|
|
|
{
|
2011-04-21 01:45:57 +04:00
|
|
|
if (!IsSurfaceDescriptorValid(mFrontBuffer)) {
|
2010-08-21 03:24:41 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-04-21 01:45:57 +04:00
|
|
|
nsRefPtr<gfxASurface> surface =
|
|
|
|
BasicManager()->OpenDescriptor(mFrontBuffer);
|
|
|
|
nsRefPtr<gfxPattern> pat = new gfxPattern(surface);
|
2010-07-22 01:17:33 +04:00
|
|
|
pat->SetFilter(mFilter);
|
2011-02-12 05:31:09 +03:00
|
|
|
|
|
|
|
// The visible region can extend outside the image. If we're not
|
|
|
|
// tiling, we don't want to draw into that area, so just draw within
|
|
|
|
// the image bounds.
|
|
|
|
const nsIntRect* tileSrcRect = GetTileSourceRect();
|
2011-05-30 07:48:13 +04:00
|
|
|
AutoSetOperator setOperator(aContext, GetOperator());
|
2011-02-12 05:31:09 +03:00
|
|
|
BasicImageLayer::PaintContext(pat,
|
|
|
|
tileSrcRect ? GetEffectiveVisibleRegion() : nsIntRegion(nsIntRect(0, 0, mSize.width, mSize.height)),
|
|
|
|
tileSrcRect,
|
|
|
|
GetEffectiveOpacity(), aContext);
|
2010-07-22 01:17:33 +04:00
|
|
|
}
|
|
|
|
|
2010-10-14 02:55:45 +04:00
|
|
|
class BasicShadowColorLayer : public ShadowColorLayer,
|
2011-05-30 07:48:13 +04:00
|
|
|
public BasicImplData
|
2010-10-14 02:55:45 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
BasicShadowColorLayer(BasicShadowLayerManager* aLayerManager) :
|
|
|
|
ShadowColorLayer(aLayerManager, static_cast<BasicImplData*>(this))
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(BasicShadowColorLayer);
|
|
|
|
}
|
|
|
|
virtual ~BasicShadowColorLayer()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(BasicShadowColorLayer);
|
|
|
|
}
|
|
|
|
|
2011-02-17 01:43:30 +03:00
|
|
|
virtual void Paint(gfxContext* aContext)
|
2010-10-14 02:55:45 +04:00
|
|
|
{
|
2011-05-30 07:48:13 +04:00
|
|
|
AutoSetOperator setOperator(aContext, GetOperator());
|
2010-11-08 12:06:15 +03:00
|
|
|
BasicColorLayer::PaintColorTo(mColor, GetEffectiveOpacity(), aContext);
|
2010-10-14 02:55:45 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
class BasicShadowCanvasLayer : public ShadowCanvasLayer,
|
2011-05-30 07:48:13 +04:00
|
|
|
public BasicImplData
|
2010-07-22 01:17:33 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
BasicShadowCanvasLayer(BasicShadowLayerManager* aLayerManager) :
|
|
|
|
ShadowCanvasLayer(aLayerManager, static_cast<BasicImplData*>(this))
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(BasicShadowCanvasLayer);
|
|
|
|
}
|
|
|
|
virtual ~BasicShadowCanvasLayer()
|
|
|
|
{
|
2011-09-28 02:19:28 +04:00
|
|
|
DestroyFrontBuffer();
|
2010-07-22 01:17:33 +04:00
|
|
|
MOZ_COUNT_DTOR(BasicShadowCanvasLayer);
|
|
|
|
}
|
|
|
|
|
2010-09-03 07:05:01 +04:00
|
|
|
virtual void Disconnect()
|
|
|
|
{
|
2011-09-28 02:19:28 +04:00
|
|
|
mFrontSurface = SurfaceDescriptor();
|
2010-09-03 07:05:01 +04:00
|
|
|
ShadowCanvasLayer::Disconnect();
|
|
|
|
}
|
2010-08-21 03:24:41 +04:00
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
virtual void Initialize(const Data& aData);
|
2011-09-28 02:19:28 +04:00
|
|
|
void Swap(const CanvasSurface& aNewFront, bool needYFlip, CanvasSurface* aNewBack);
|
2010-07-22 01:17:33 +04:00
|
|
|
|
2010-09-03 07:05:01 +04:00
|
|
|
virtual void DestroyFrontBuffer()
|
|
|
|
{
|
2011-04-21 01:45:57 +04:00
|
|
|
if (IsSurfaceDescriptorValid(mFrontSurface)) {
|
2011-09-28 02:19:26 +04:00
|
|
|
mAllocator->DestroySharedSurface(&mFrontSurface);
|
2010-09-03 07:05:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-17 01:43:30 +03:00
|
|
|
virtual void Paint(gfxContext* aContext);
|
2010-07-22 01:17:33 +04:00
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
private:
|
|
|
|
BasicShadowLayerManager* BasicManager()
|
|
|
|
{
|
|
|
|
return static_cast<BasicShadowLayerManager*>(mManager);
|
|
|
|
}
|
|
|
|
|
2011-04-21 01:45:57 +04:00
|
|
|
SurfaceDescriptor mFrontSurface;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mNeedsYFlip;
|
2010-07-22 01:17:33 +04:00
|
|
|
};
|
|
|
|
|
2010-08-21 03:24:41 +04:00
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
void
|
|
|
|
BasicShadowCanvasLayer::Initialize(const Data& aData)
|
|
|
|
{
|
2011-04-21 01:45:57 +04:00
|
|
|
NS_RUNTIMEABORT("Incompatibe surface type");
|
|
|
|
}
|
2010-07-22 01:17:33 +04:00
|
|
|
|
2011-04-21 01:45:57 +04:00
|
|
|
void
|
2011-09-28 02:19:28 +04:00
|
|
|
BasicShadowCanvasLayer::Swap(const CanvasSurface& aNewFront, bool needYFlip,
|
|
|
|
CanvasSurface* aNewBack)
|
2011-04-21 01:45:57 +04:00
|
|
|
{
|
2011-09-28 02:19:28 +04:00
|
|
|
nsRefPtr<gfxASurface> surface =
|
|
|
|
BasicManager()->OpenDescriptor(aNewFront);
|
|
|
|
// Destroy mFrontBuffer if size different
|
|
|
|
gfxIntSize sz = surface->GetSize();
|
|
|
|
if (sz != gfxIntSize(mBounds.width, mBounds.height)) {
|
|
|
|
DestroyFrontBuffer();
|
|
|
|
mBounds.SetRect(0, 0, sz.width, sz.height);
|
|
|
|
}
|
2010-07-22 01:17:33 +04:00
|
|
|
|
2011-09-28 02:19:28 +04:00
|
|
|
mNeedsYFlip = needYFlip;
|
|
|
|
// If mFrontBuffer
|
|
|
|
if (IsSurfaceDescriptorValid(mFrontSurface)) {
|
|
|
|
*aNewBack = mFrontSurface;
|
|
|
|
} else {
|
|
|
|
*aNewBack = null_t();
|
|
|
|
}
|
|
|
|
mFrontSurface = aNewFront.get_SurfaceDescriptor();
|
2010-07-22 01:17:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-02-17 01:43:30 +03:00
|
|
|
BasicShadowCanvasLayer::Paint(gfxContext* aContext)
|
2010-07-22 01:17:33 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(BasicManager()->InDrawing(),
|
|
|
|
"Can only draw in drawing phase");
|
|
|
|
|
2011-04-21 01:45:57 +04:00
|
|
|
if (!IsSurfaceDescriptorValid(mFrontSurface)) {
|
2010-08-21 03:24:41 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-04-21 01:45:57 +04:00
|
|
|
nsRefPtr<gfxASurface> surface =
|
|
|
|
BasicManager()->OpenDescriptor(mFrontSurface);
|
|
|
|
nsRefPtr<gfxPattern> pat = new gfxPattern(surface);
|
2010-07-22 01:17:33 +04:00
|
|
|
|
|
|
|
pat->SetFilter(mFilter);
|
|
|
|
pat->SetExtend(gfxPattern::EXTEND_PAD);
|
|
|
|
|
|
|
|
gfxRect r(0, 0, mBounds.width, mBounds.height);
|
2011-06-10 05:17:02 +04:00
|
|
|
|
|
|
|
gfxMatrix m;
|
|
|
|
if (mNeedsYFlip) {
|
|
|
|
m = aContext->CurrentMatrix();
|
|
|
|
aContext->Translate(gfxPoint(0.0, mBounds.height));
|
|
|
|
aContext->Scale(1.0, -1.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
AutoSetOperator setOperator(aContext, GetOperator());
|
2010-07-22 01:17:33 +04:00
|
|
|
aContext->NewPath();
|
2010-11-08 12:06:15 +03:00
|
|
|
// No need to snap here; our transform has already taken care of it
|
|
|
|
aContext->Rectangle(r);
|
|
|
|
aContext->SetPattern(pat);
|
2011-01-26 09:26:37 +03:00
|
|
|
aContext->FillWithOpacity(GetEffectiveOpacity());
|
2011-06-10 05:17:02 +04:00
|
|
|
|
|
|
|
if (mNeedsYFlip) {
|
|
|
|
aContext->SetMatrix(m);
|
|
|
|
}
|
2010-07-22 01:17:33 +04:00
|
|
|
}
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
// Create a shadow layer (PLayerChild) for aLayer, if we're forwarding
|
|
|
|
// our layer tree to a parent process. Record the new layer creation
|
|
|
|
// in the current open transaction as a side effect.
|
|
|
|
template<typename CreatedMethod>
|
|
|
|
static void
|
|
|
|
MaybeCreateShadowFor(BasicShadowableLayer* aLayer,
|
|
|
|
BasicShadowLayerManager* aMgr,
|
|
|
|
CreatedMethod aMethod)
|
|
|
|
{
|
|
|
|
if (!aMgr->HasShadowManager()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PLayerChild* shadow = aMgr->ConstructShadowFor(aLayer);
|
|
|
|
// XXX error handling
|
|
|
|
NS_ABORT_IF_FALSE(shadow, "failed to create shadow");
|
|
|
|
|
|
|
|
aLayer->SetShadow(shadow);
|
|
|
|
(aMgr->*aMethod)(aLayer);
|
2010-09-16 08:49:31 +04:00
|
|
|
aMgr->Hold(aLayer->AsLayer());
|
2010-07-22 01:17:33 +04:00
|
|
|
}
|
|
|
|
#define MAYBE_CREATE_SHADOW(_type) \
|
|
|
|
MaybeCreateShadowFor(layer, this, \
|
|
|
|
&ShadowLayerForwarder::Created ## _type ## Layer)
|
|
|
|
|
|
|
|
already_AddRefed<ThebesLayer>
|
|
|
|
BasicShadowLayerManager::CreateThebesLayer()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(InConstruction(), "Only allowed in construction phase");
|
|
|
|
nsRefPtr<BasicShadowableThebesLayer> layer =
|
|
|
|
new BasicShadowableThebesLayer(this);
|
|
|
|
MAYBE_CREATE_SHADOW(Thebes);
|
|
|
|
return layer.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<ContainerLayer>
|
|
|
|
BasicShadowLayerManager::CreateContainerLayer()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(InConstruction(), "Only allowed in construction phase");
|
|
|
|
nsRefPtr<BasicShadowableContainerLayer> layer =
|
|
|
|
new BasicShadowableContainerLayer(this);
|
|
|
|
MAYBE_CREATE_SHADOW(Container);
|
|
|
|
return layer.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<ImageLayer>
|
|
|
|
BasicShadowLayerManager::CreateImageLayer()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(InConstruction(), "Only allowed in construction phase");
|
|
|
|
nsRefPtr<BasicShadowableImageLayer> layer =
|
|
|
|
new BasicShadowableImageLayer(this);
|
|
|
|
MAYBE_CREATE_SHADOW(Image);
|
|
|
|
return layer.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<ColorLayer>
|
|
|
|
BasicShadowLayerManager::CreateColorLayer()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(InConstruction(), "Only allowed in construction phase");
|
|
|
|
nsRefPtr<BasicShadowableColorLayer> layer =
|
|
|
|
new BasicShadowableColorLayer(this);
|
|
|
|
MAYBE_CREATE_SHADOW(Color);
|
|
|
|
return layer.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<CanvasLayer>
|
|
|
|
BasicShadowLayerManager::CreateCanvasLayer()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(InConstruction(), "Only allowed in construction phase");
|
|
|
|
nsRefPtr<BasicShadowableCanvasLayer> layer =
|
|
|
|
new BasicShadowableCanvasLayer(this);
|
|
|
|
MAYBE_CREATE_SHADOW(Canvas);
|
|
|
|
return layer.forget();
|
|
|
|
}
|
|
|
|
already_AddRefed<ShadowThebesLayer>
|
|
|
|
BasicShadowLayerManager::CreateShadowThebesLayer()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(InConstruction(), "Only allowed in construction phase");
|
|
|
|
nsRefPtr<ShadowThebesLayer> layer = new BasicShadowThebesLayer(this);
|
|
|
|
return layer.forget();
|
|
|
|
}
|
|
|
|
|
2010-10-14 02:55:45 +04:00
|
|
|
already_AddRefed<ShadowContainerLayer>
|
|
|
|
BasicShadowLayerManager::CreateShadowContainerLayer()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(InConstruction(), "Only allowed in construction phase");
|
|
|
|
nsRefPtr<ShadowContainerLayer> layer = new BasicShadowContainerLayer(this);
|
|
|
|
return layer.forget();
|
|
|
|
}
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
already_AddRefed<ShadowImageLayer>
|
|
|
|
BasicShadowLayerManager::CreateShadowImageLayer()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(InConstruction(), "Only allowed in construction phase");
|
|
|
|
nsRefPtr<ShadowImageLayer> layer = new BasicShadowImageLayer(this);
|
|
|
|
return layer.forget();
|
|
|
|
}
|
|
|
|
|
2010-10-14 02:55:45 +04:00
|
|
|
already_AddRefed<ShadowColorLayer>
|
|
|
|
BasicShadowLayerManager::CreateShadowColorLayer()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(InConstruction(), "Only allowed in construction phase");
|
|
|
|
nsRefPtr<ShadowColorLayer> layer = new BasicShadowColorLayer(this);
|
|
|
|
return layer.forget();
|
|
|
|
}
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
already_AddRefed<ShadowCanvasLayer>
|
|
|
|
BasicShadowLayerManager::CreateShadowCanvasLayer()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(InConstruction(), "Only allowed in construction phase");
|
|
|
|
nsRefPtr<ShadowCanvasLayer> layer = new BasicShadowCanvasLayer(this);
|
|
|
|
return layer.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
BasicShadowLayerManager::BasicShadowLayerManager(nsIWidget* aWidget) :
|
|
|
|
BasicLayerManager(aWidget)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(BasicShadowLayerManager);
|
|
|
|
}
|
|
|
|
|
|
|
|
BasicShadowLayerManager::~BasicShadowLayerManager()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(BasicShadowLayerManager);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BasicShadowLayerManager::SetRoot(Layer* aLayer)
|
|
|
|
{
|
|
|
|
if (mRoot != aLayer) {
|
|
|
|
if (HasShadowManager()) {
|
2010-11-25 06:33:37 +03:00
|
|
|
// Have to hold the old root and its children in order to
|
|
|
|
// maintain the same view of the layer tree in this process as
|
|
|
|
// the parent sees. Otherwise layers can be destroyed
|
|
|
|
// mid-transaction and bad things can happen (v. bug 612573)
|
|
|
|
if (mRoot) {
|
|
|
|
Hold(mRoot);
|
|
|
|
}
|
2010-07-22 01:17:33 +04:00
|
|
|
ShadowLayerForwarder::SetRoot(Hold(aLayer));
|
|
|
|
}
|
|
|
|
BasicLayerManager::SetRoot(aLayer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BasicShadowLayerManager::Mutated(Layer* aLayer)
|
|
|
|
{
|
2011-01-26 09:26:37 +03:00
|
|
|
BasicLayerManager::Mutated(aLayer);
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
NS_ASSERTION(InConstruction() || InDrawing(), "wrong phase");
|
2011-02-17 01:43:30 +03:00
|
|
|
if (HasShadowManager() && ShouldShadow(aLayer)) {
|
2010-07-22 01:17:33 +04:00
|
|
|
ShadowLayerForwarder::Mutated(Hold(aLayer));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BasicShadowLayerManager::BeginTransactionWithTarget(gfxContext* aTarget)
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(mKeepAlive.IsEmpty(), "uncommitted txn?");
|
2010-12-27 09:12:17 +03:00
|
|
|
// If the last transaction was incomplete (a failed DoEmptyTransaction),
|
|
|
|
// don't signal a new transaction to ShadowLayerForwarder. Carry on adding
|
|
|
|
// to the previous transaction.
|
2011-01-19 11:27:54 +03:00
|
|
|
if (HasShadowManager()) {
|
2010-07-22 01:17:33 +04:00
|
|
|
ShadowLayerForwarder::BeginTransaction();
|
|
|
|
}
|
|
|
|
BasicLayerManager::BeginTransactionWithTarget(aTarget);
|
|
|
|
}
|
|
|
|
|
2010-12-14 03:14:07 +03:00
|
|
|
void
|
2010-07-22 01:17:33 +04:00
|
|
|
BasicShadowLayerManager::EndTransaction(DrawThebesLayerCallback aCallback,
|
2011-09-26 17:20:42 +04:00
|
|
|
void* aCallbackData,
|
|
|
|
EndTransactionFlags aFlags)
|
2010-07-22 01:17:33 +04:00
|
|
|
{
|
2011-09-26 17:20:42 +04:00
|
|
|
BasicLayerManager::EndTransaction(aCallback, aCallbackData, aFlags);
|
2010-12-27 09:12:17 +03:00
|
|
|
ForwardTransaction();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2011-01-19 11:27:54 +03:00
|
|
|
BasicShadowLayerManager::EndEmptyTransaction()
|
2010-12-27 09:12:17 +03:00
|
|
|
{
|
2011-01-19 11:27:54 +03:00
|
|
|
if (!BasicLayerManager::EndEmptyTransaction()) {
|
2010-12-27 09:12:17 +03:00
|
|
|
// Return without calling ForwardTransaction. This leaves the
|
|
|
|
// ShadowLayerForwarder transaction open; the following
|
2011-01-19 11:27:54 +03:00
|
|
|
// EndTransaction will complete it.
|
2010-12-27 09:12:17 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
ForwardTransaction();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BasicShadowLayerManager::ForwardTransaction()
|
|
|
|
{
|
2010-07-22 01:17:33 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
mPhase = PHASE_FORWARD;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// forward this transaction's changeset to our ShadowLayerManager
|
2010-11-09 05:49:00 +03:00
|
|
|
AutoInfallibleTArray<EditReply, 10> replies;
|
2010-07-22 01:17:33 +04:00
|
|
|
if (HasShadowManager() && ShadowLayerForwarder::EndTransaction(&replies)) {
|
|
|
|
for (nsTArray<EditReply>::size_type i = 0; i < replies.Length(); ++i) {
|
|
|
|
const EditReply& reply = replies[i];
|
|
|
|
|
|
|
|
switch (reply.type()) {
|
2010-09-14 09:23:08 +04:00
|
|
|
case EditReply::TOpThebesBufferSwap: {
|
|
|
|
MOZ_LAYERS_LOG(("[LayersForwarder] ThebesBufferSwap"));
|
|
|
|
|
|
|
|
const OpThebesBufferSwap& obs = reply.get_OpThebesBufferSwap();
|
|
|
|
BasicShadowableThebesLayer* thebes = GetBasicShadowable(obs)->AsThebes();
|
|
|
|
thebes->SetBackBufferAndAttrs(
|
2011-06-22 16:11:28 +04:00
|
|
|
obs.newBackBuffer(), obs.newValidRegion(),
|
2010-11-05 10:17:07 +03:00
|
|
|
obs.readOnlyFrontBuffer(), obs.frontUpdatedRegion());
|
2010-09-14 09:23:08 +04:00
|
|
|
break;
|
|
|
|
}
|
2010-07-22 01:17:33 +04:00
|
|
|
case EditReply::TOpBufferSwap: {
|
|
|
|
MOZ_LAYERS_LOG(("[LayersForwarder] BufferSwap"));
|
|
|
|
|
|
|
|
const OpBufferSwap& obs = reply.get_OpBufferSwap();
|
2011-09-28 02:19:28 +04:00
|
|
|
const CanvasSurface& newBack = obs.newBackBuffer();
|
|
|
|
if (newBack.type() == CanvasSurface::TSurfaceDescriptor) {
|
|
|
|
GetBasicShadowable(obs)->SetBackBuffer(newBack.get_SurfaceDescriptor());
|
|
|
|
} else if (newBack.type() == CanvasSurface::Tnull_t) {
|
|
|
|
GetBasicShadowable(obs)->SetBackBuffer(SurfaceDescriptor());
|
|
|
|
} else {
|
|
|
|
NS_RUNTIMEABORT("Unknown back image type");
|
|
|
|
}
|
2010-07-22 01:17:33 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-04-21 08:38:39 +04:00
|
|
|
case EditReply::TOpImageSwap: {
|
|
|
|
MOZ_LAYERS_LOG(("[LayersForwarder] YUVBufferSwap"));
|
|
|
|
|
|
|
|
const OpImageSwap& ois = reply.get_OpImageSwap();
|
|
|
|
BasicShadowableLayer* layer = GetBasicShadowable(ois);
|
|
|
|
const SharedImage& newBack = ois.newBackImage();
|
|
|
|
|
|
|
|
if (newBack.type() == SharedImage::TSurfaceDescriptor) {
|
|
|
|
layer->SetBackBuffer(newBack.get_SurfaceDescriptor());
|
2011-09-28 02:19:26 +04:00
|
|
|
} else if (newBack.type() == SharedImage::TYUVImage) {
|
2011-04-21 08:38:39 +04:00
|
|
|
const YUVImage& yuv = newBack.get_YUVImage();
|
|
|
|
nsRefPtr<gfxSharedImageSurface> YSurf = gfxSharedImageSurface::Open(yuv.Ydata());
|
|
|
|
nsRefPtr<gfxSharedImageSurface> USurf = gfxSharedImageSurface::Open(yuv.Udata());
|
|
|
|
nsRefPtr<gfxSharedImageSurface> VSurf = gfxSharedImageSurface::Open(yuv.Vdata());
|
|
|
|
layer->SetBackBufferYUVImage(YSurf, USurf, VSurf);
|
2011-09-28 02:19:26 +04:00
|
|
|
} else {
|
|
|
|
layer->SetBackBuffer(SurfaceDescriptor());
|
|
|
|
layer->SetBackBufferYUVImage(nsnull, nsnull, nsnull);
|
2011-04-21 08:38:39 +04:00
|
|
|
}
|
2011-09-28 02:19:26 +04:00
|
|
|
|
2011-04-21 08:38:39 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
default:
|
|
|
|
NS_RUNTIMEABORT("not reached");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (HasShadowManager()) {
|
2010-07-22 01:17:33 +04:00
|
|
|
NS_WARNING("failed to forward Layers transaction");
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
mPhase = PHASE_NONE;
|
|
|
|
#endif
|
2010-11-25 06:33:37 +03:00
|
|
|
|
|
|
|
// this may result in Layers being deleted, which results in
|
|
|
|
// PLayer::Send__delete__() and DeallocShmem()
|
|
|
|
mKeepAlive.Clear();
|
2010-07-22 01:17:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
ShadowableLayer*
|
|
|
|
BasicShadowLayerManager::Hold(Layer* aLayer)
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(HasShadowManager(),
|
|
|
|
"top-level tree, no shadow tree to remote to");
|
|
|
|
|
|
|
|
ShadowableLayer* shadowable = ToShadowable(aLayer);
|
|
|
|
NS_ABORT_IF_FALSE(shadowable, "trying to remote an unshadowable layer");
|
|
|
|
|
|
|
|
mKeepAlive.AppendElement(aLayer);
|
|
|
|
return shadowable;
|
|
|
|
}
|
2011-02-04 21:11:24 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2011-02-04 21:11:24 +03:00
|
|
|
BasicShadowLayerManager::IsCompositingCheap()
|
|
|
|
{
|
|
|
|
// Whether compositing is cheap depends on the parent backend.
|
|
|
|
return mShadowManager &&
|
|
|
|
LayerManager::IsCompositingCheap(GetParentBackendType());
|
|
|
|
}
|
2010-07-22 01:17:33 +04:00
|
|
|
|
2010-03-01 10:56:18 +03:00
|
|
|
}
|
|
|
|
}
|