2010-05-18 08:04:22 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 20; 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 ***** */
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
#ifdef MOZ_IPC
|
2010-07-22 01:17:33 +04:00
|
|
|
# include "gfxSharedImageSurface.h"
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
# include "mozilla/layers/PLayerChild.h"
|
|
|
|
# include "mozilla/layers/PLayersChild.h"
|
2010-07-22 01:17:33 +04:00
|
|
|
# include "mozilla/layers/PLayersParent.h"
|
|
|
|
# include "ipc/ShadowLayerChild.h"
|
2010-07-22 01:17:33 +04:00
|
|
|
#endif
|
|
|
|
|
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"
|
|
|
|
#include "nsIRenderingContext.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"
|
2010-05-18 08:04:22 +04:00
|
|
|
|
|
|
|
#include "GLContext.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:
|
|
|
|
BasicImplData()
|
|
|
|
{
|
|
|
|
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).
|
|
|
|
*/
|
2010-05-21 07:20:48 +04:00
|
|
|
virtual void Paint(gfxContext* aContext,
|
|
|
|
LayerManager::DrawThebesLayerCallback aCallback,
|
2010-11-08 12:06:15 +03:00
|
|
|
void* aCallbackData) {}
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* This variable is used by layer manager in order to
|
|
|
|
* MarkLeafLayersCoveredByOpaque() before painting.
|
|
|
|
* We keep it here for now. Once we need to cull completely covered
|
|
|
|
* non-Basic layers, mCoveredByOpaque should be moved to Layer.
|
|
|
|
*/
|
|
|
|
void SetCoveredByOpaque(PRBool aCovered) { mCoveredByOpaque = aCovered; }
|
|
|
|
PRBool IsCoveredByOpaque() const { return mCoveredByOpaque; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
PRPackedBool mCoveredByOpaque;
|
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);
|
|
|
|
|
2010-03-01 10:56:18 +03:00
|
|
|
class BasicContainerLayer : public ContainerLayer, 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);
|
|
|
|
}
|
|
|
|
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.
|
|
|
|
gfx3DMatrix idealTransform = GetLocalTransform()*aTransformToSurface;
|
|
|
|
mEffectiveTransform = SnapTransform(idealTransform, gfxRect(0, 0, 0, 0), nsnull);
|
|
|
|
// 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
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
NS_ADDREF(aChild);
|
|
|
|
|
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;
|
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);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
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)
|
|
|
|
{}
|
|
|
|
|
|
|
|
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>
|
|
|
|
CreateBuffer(ContentType aType, const nsIntSize& aSize);
|
|
|
|
|
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
|
|
|
{
|
|
|
|
gfxIntSize prevSize = gfxIntSize(BufferDims().width, BufferDims().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;
|
|
|
|
oldBuffer = SetBuffer(aBuffer, nsIntSize(newSize.width, newSize.height),
|
|
|
|
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,
|
|
|
|
const nsIntRegion& aUpdateRegion, float aXResolution, float aYResolution);
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
gfxIntSize sz = aBuffer->GetSize();
|
|
|
|
SetBuffer(aBuffer, nsIntSize(sz.width, sz.height), aRect, aRotation);
|
|
|
|
}
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
BasicThebesLayer* mLayer;
|
|
|
|
};
|
|
|
|
|
2010-03-01 10:56:18 +03:00
|
|
|
class BasicThebesLayer : public ThebesLayer, BasicImplData {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2010-05-21 07:20:48 +04:00
|
|
|
virtual void Paint(gfxContext* aContext,
|
|
|
|
LayerManager::DrawThebesLayerCallback aCallback,
|
2010-11-08 12:06:15 +03:00
|
|
|
void* aCallbackData);
|
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));
|
|
|
|
}
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
protected:
|
|
|
|
BasicLayerManager* BasicManager()
|
|
|
|
{
|
|
|
|
return static_cast<BasicLayerManager*>(mManager);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
PaintBuffer(gfxContext* aContext,
|
|
|
|
const nsIntRegion& aRegionToDraw,
|
|
|
|
const nsIntRegion& aRegionToInvalidate,
|
|
|
|
LayerManager::DrawThebesLayerCallback aCallback,
|
|
|
|
void* aCallbackData)
|
|
|
|
{
|
|
|
|
aCallback(this, aContext, aRegionToDraw, aRegionToInvalidate,
|
|
|
|
aCallbackData);
|
|
|
|
mValidRegion.Or(mValidRegion, aRegionToDraw);
|
|
|
|
}
|
|
|
|
|
2010-07-21 22:06:33 +04:00
|
|
|
Buffer mBuffer;
|
2010-03-01 10:56:18 +03:00
|
|
|
};
|
|
|
|
|
2010-07-16 01:08:04 +04:00
|
|
|
static void
|
|
|
|
ClipToContain(gfxContext* aContext, const nsIntRect& aRect)
|
|
|
|
{
|
|
|
|
gfxRect deviceRect =
|
|
|
|
aContext->UserToDevice(gfxRect(aRect.x, aRect.y, aRect.width, aRect.height));
|
|
|
|
deviceRect.RoundOut();
|
|
|
|
|
|
|
|
gfxMatrix currentMatrix = aContext->CurrentMatrix();
|
|
|
|
aContext->IdentityMatrix();
|
|
|
|
aContext->NewPath();
|
|
|
|
aContext->Rectangle(deviceRect);
|
|
|
|
aContext->Clip();
|
|
|
|
aContext->SetMatrix(currentMatrix);
|
|
|
|
}
|
|
|
|
|
2010-09-02 13:18:41 +04:00
|
|
|
static PRBool
|
|
|
|
ShouldRetainTransparentSurface(PRUint32 aContentFlags,
|
|
|
|
gfxASurface* aTargetSurface)
|
|
|
|
{
|
|
|
|
if (aContentFlags & Layer::CONTENT_NO_TEXT)
|
|
|
|
return PR_TRUE;
|
|
|
|
|
|
|
|
switch (aTargetSurface->GetTextQualityInTransparentSurfaces()) {
|
|
|
|
case gfxASurface::TEXT_QUALITY_OK:
|
|
|
|
return PR_TRUE;
|
|
|
|
case gfxASurface::TEXT_QUALITY_OK_OVER_OPAQUE_PIXELS:
|
2010-09-06 07:02:43 +04:00
|
|
|
// Retain the buffer if all text is over opaque pixels. Otherwise,
|
|
|
|
// don't retain the buffer, in the hope that the backbuffer has
|
|
|
|
// opaque pixels where our layer does not.
|
2010-09-02 13:18:41 +04:00
|
|
|
return (aContentFlags & Layer::CONTENT_NO_TEXT_OVER_TRANSPARENT) != 0;
|
2010-09-06 07:02:43 +04:00
|
|
|
case gfxASurface::TEXT_QUALITY_BAD:
|
|
|
|
// If the backbuffer is opaque, then draw directly into it to get
|
|
|
|
// subpixel AA. If the backbuffer is not an opaque format, then we won't get
|
|
|
|
// subpixel AA by drawing into it, so we might as well retain.
|
|
|
|
return aTargetSurface->GetContentType() != gfxASurface::CONTENT_COLOR;
|
2010-09-02 13:18:41 +04:00
|
|
|
default:
|
2010-09-06 07:02:43 +04:00
|
|
|
NS_ERROR("Unknown quality type");
|
|
|
|
return PR_TRUE;
|
2010-09-02 13:18:41 +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;
|
|
|
|
}
|
|
|
|
|
2010-05-21 07:20:48 +04:00
|
|
|
void
|
|
|
|
BasicThebesLayer::Paint(gfxContext* aContext,
|
|
|
|
LayerManager::DrawThebesLayerCallback aCallback,
|
2010-11-08 12:06:15 +03:00
|
|
|
void* aCallbackData)
|
2010-03-01 10:56:18 +03:00
|
|
|
{
|
|
|
|
NS_ASSERTION(BasicManager()->InDrawing(),
|
|
|
|
"Can only draw in drawing phase");
|
|
|
|
gfxContext* target = BasicManager()->GetTarget();
|
2010-05-21 07:20:48 +04:00
|
|
|
NS_ASSERTION(target, "We shouldn't be called if there's no target");
|
2010-09-02 13:18:41 +04:00
|
|
|
nsRefPtr<gfxASurface> targetSurface = aContext->CurrentSurface();
|
2010-03-01 10:56:18 +03:00
|
|
|
|
2010-09-02 13:18:41 +04:00
|
|
|
PRBool 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-11-08 12:06:15 +03:00
|
|
|
(opacity == 1.0 && !canUseOpaqueSurface &&
|
2010-10-11 22:36:20 +04:00
|
|
|
!ShouldRetainTransparentSurface(mContentFlags, targetSurface) &&
|
2010-10-13 23:22:17 +04:00
|
|
|
!MustRetainContent())) {
|
2010-03-04 00:37:04 +03:00
|
|
|
mValidRegion.SetEmpty();
|
|
|
|
mBuffer.Clear();
|
2010-03-01 10:56:18 +03:00
|
|
|
|
2010-09-06 07:00:10 +04:00
|
|
|
nsIntRegion toDraw = IntersectWithClip(mVisibleRegion, target);
|
|
|
|
if (!toDraw.IsEmpty()) {
|
2010-12-10 22:32:52 +03:00
|
|
|
if (!aCallback) {
|
|
|
|
BasicManager()->SetTransactionIncomplete();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-09-06 07:00:10 +04:00
|
|
|
target->Save();
|
|
|
|
gfxUtils::ClipToRegionSnapped(target, toDraw);
|
2010-11-08 12:06:15 +03:00
|
|
|
if (opacity != 1.0) {
|
2010-09-06 07:00:10 +04:00
|
|
|
target->PushGroup(contentType);
|
|
|
|
}
|
|
|
|
aCallback(this, target, toDraw, nsIntRegion(), aCallbackData);
|
2010-11-08 12:06:15 +03:00
|
|
|
if (opacity != 1.0) {
|
2010-09-06 07:00:10 +04:00
|
|
|
target->PopGroupToSource();
|
2010-11-08 12:06:15 +03:00
|
|
|
target->Paint(opacity);
|
2010-09-06 07:00:10 +04:00
|
|
|
}
|
|
|
|
target->Restore();
|
2010-07-16 01:08:04 +04:00
|
|
|
}
|
2010-03-04 00:37:04 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2010-09-04 00:10:46 +04:00
|
|
|
float paintXRes = BasicManager()->XResolution();
|
|
|
|
float paintYRes = BasicManager()->YResolution();
|
|
|
|
Buffer::PaintState state =
|
|
|
|
mBuffer.BeginPaint(this, contentType, paintXRes, paintYRes);
|
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)
|
|
|
|
state.mRegionToInvalidate.And(state.mRegionToInvalidate, mVisibleRegion);
|
2010-09-29 02:05:30 +04:00
|
|
|
mXResolution = paintXRes;
|
|
|
|
mYResolution = paintYRes;
|
2010-07-22 01:17:33 +04:00
|
|
|
PaintBuffer(state.mContext,
|
|
|
|
state.mRegionToDraw, state.mRegionToInvalidate,
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-12 04:43:42 +03:00
|
|
|
mBuffer.DrawTo(this, target, opacity);
|
2010-07-21 22:06:33 +04:00
|
|
|
}
|
|
|
|
|
2010-09-17 23:29:52 +04:00
|
|
|
static PRBool
|
|
|
|
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.
|
|
|
|
if (!aLayer->GetValidRegion().Contains(BufferRect()) ||
|
|
|
|
IsClippingCheap(aTarget, aLayer->GetVisibleRegion())) {
|
|
|
|
// 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,
|
|
|
|
// we might sample pixels outside GetVisibleRegion(), which is wrong
|
|
|
|
// and may cause gray lines.
|
|
|
|
gfxUtils::ClipToRegionSnapped(aTarget, aLayer->GetVisibleRegion());
|
2010-09-17 23:29:52 +04:00
|
|
|
}
|
2010-09-04 00:10:46 +04:00
|
|
|
DrawBufferWithRotation(aTarget, aOpacity,
|
|
|
|
aLayer->GetXResolution(), aLayer->GetYResolution());
|
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,
|
|
|
|
const nsIntSize& aSize)
|
|
|
|
{
|
|
|
|
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,
|
|
|
|
const nsIntRegion& aUpdateRegion, float aXResolution, float aYResolution)
|
|
|
|
{
|
|
|
|
SetBackingBuffer(aBuffer, aRect, aRotation);
|
|
|
|
nsRefPtr<gfxContext> destCtx =
|
|
|
|
GetContextForQuadrantUpdate(aUpdateRegion.GetBounds(),
|
|
|
|
aXResolution, aYResolution);
|
|
|
|
destCtx->SetOperator(gfxContext::OPERATOR_SOURCE);
|
|
|
|
if (IsClippingCheap(destCtx, aUpdateRegion)) {
|
|
|
|
gfxUtils::ClipToRegion(destCtx, aUpdateRegion);
|
|
|
|
}
|
|
|
|
|
|
|
|
BasicThebesLayerBuffer srcBuffer(aSource, aRect, aRotation);
|
|
|
|
srcBuffer.DrawBufferWithRotation(destCtx, 1.0, aXResolution, aYResolution);
|
|
|
|
}
|
|
|
|
|
2010-03-02 02:09:35 +03:00
|
|
|
class BasicImageLayer : public ImageLayer, BasicImplData {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2010-05-21 07:20:48 +04:00
|
|
|
virtual void Paint(gfxContext* aContext,
|
|
|
|
LayerManager::DrawThebesLayerCallback aCallback,
|
2010-11-08 12:06:15 +03:00
|
|
|
void* aCallbackData);
|
2010-03-02 02:09:35 +03:00
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
static void PaintContext(gfxPattern* aPattern,
|
|
|
|
const gfxIntSize& aSize,
|
|
|
|
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
|
2010-05-21 07:20:48 +04:00
|
|
|
BasicImageLayer::Paint(gfxContext* aContext,
|
|
|
|
LayerManager::DrawThebesLayerCallback aCallback,
|
2010-11-08 12:06:15 +03:00
|
|
|
void* aCallbackData)
|
2010-07-22 01:17:33 +04:00
|
|
|
{
|
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
|
|
|
|
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);
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
PaintContext(pat, mSize, aOpacity, aContext);
|
|
|
|
return pat.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ void
|
|
|
|
BasicImageLayer::PaintContext(gfxPattern* aPattern,
|
|
|
|
const gfxIntSize& aSize,
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
aPattern->SetExtend(extend);
|
2010-03-02 02:09:35 +03:00
|
|
|
|
|
|
|
/* Draw RGB surface onto frame */
|
|
|
|
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(gfxRect(0, 0, aSize.width, aSize.height));
|
|
|
|
aContext->SetPattern(aPattern);
|
2010-07-16 01:08:04 +04:00
|
|
|
if (aOpacity != 1.0) {
|
|
|
|
aContext->Save();
|
|
|
|
aContext->Clip();
|
|
|
|
aContext->Paint(aOpacity);
|
|
|
|
aContext->Restore();
|
|
|
|
} else {
|
|
|
|
aContext->Fill();
|
|
|
|
}
|
2010-03-02 02:09:35 +03:00
|
|
|
}
|
|
|
|
|
2010-05-13 04:56:11 +04:00
|
|
|
class BasicColorLayer : public ColorLayer, BasicImplData {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2010-05-21 07:20:48 +04:00
|
|
|
virtual void Paint(gfxContext* aContext,
|
|
|
|
LayerManager::DrawThebesLayerCallback aCallback,
|
2010-11-08 12:06:15 +03:00
|
|
|
void* aCallbackData)
|
2010-10-14 02:55:45 +04:00
|
|
|
{
|
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,
|
|
|
|
BasicImplData
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
virtual void Updated(const nsIntRect& aRect);
|
2010-05-21 07:20:48 +04:00
|
|
|
virtual void Paint(gfxContext* aContext,
|
|
|
|
LayerManager::DrawThebesLayerCallback aCallback,
|
2010-11-08 12:06:15 +03:00
|
|
|
void* aCallbackData);
|
2010-05-18 08:04:22 +04:00
|
|
|
|
|
|
|
protected:
|
2010-07-16 01:08:04 +04:00
|
|
|
BasicLayerManager* BasicManager()
|
|
|
|
{
|
|
|
|
return static_cast<BasicLayerManager*>(mManager);
|
|
|
|
}
|
|
|
|
|
2010-05-18 08:04:22 +04:00
|
|
|
nsRefPtr<gfxASurface> mSurface;
|
|
|
|
nsRefPtr<mozilla::gl::GLContext> mGLContext;
|
2010-07-19 09:01:14 +04:00
|
|
|
PRUint32 mCanvasFramebuffer;
|
2010-05-18 08:04:22 +04:00
|
|
|
|
|
|
|
nsIntRect mUpdatedRect;
|
|
|
|
|
|
|
|
PRPackedBool mGLBufferIsPremultiplied;
|
2010-05-18 08:04:22 +04:00
|
|
|
PRPackedBool mNeedsYFlip;
|
2010-05-18 08:04:22 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
BasicCanvasLayer::Initialize(const Data& aData)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mSurface == nsnull, "BasicCanvasLayer::Initialize called twice!");
|
|
|
|
|
|
|
|
mUpdatedRect.Empty();
|
|
|
|
|
|
|
|
if (aData.mSurface) {
|
|
|
|
mSurface = aData.mSurface;
|
|
|
|
NS_ASSERTION(aData.mGLContext == nsnull,
|
|
|
|
"CanvasLayer can't have both surface and GLContext");
|
2010-05-18 08:04:22 +04:00
|
|
|
mNeedsYFlip = PR_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();
|
2010-05-18 08:04:22 +04:00
|
|
|
mNeedsYFlip = PR_TRUE;
|
2010-05-18 08:04:22 +04:00
|
|
|
} else {
|
|
|
|
NS_ERROR("CanvasLayer created without mSurface or mGLContext?");
|
|
|
|
}
|
|
|
|
|
|
|
|
mBounds.SetRect(0, 0, aData.mSize.width, aData.mSize.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BasicCanvasLayer::Updated(const nsIntRect& aRect)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mUpdatedRect.IsEmpty(),
|
|
|
|
"CanvasLayer::Updated called more than once in a transaction!");
|
|
|
|
|
|
|
|
mUpdatedRect.UnionRect(mUpdatedRect, aRect);
|
|
|
|
|
|
|
|
if (mGLContext) {
|
|
|
|
nsRefPtr<gfxImageSurface> isurf =
|
|
|
|
new gfxImageSurface(gfxIntSize(mBounds.width, mBounds.height),
|
2010-09-02 13:18:40 +04:00
|
|
|
(GetContentFlags() & CONTENT_OPAQUE)
|
2010-05-18 08:04:22 +04:00
|
|
|
? gfxASurface::ImageFormatRGB24
|
|
|
|
: gfxASurface::ImageFormatARGB32);
|
|
|
|
if (!isurf || isurf->CairoStatus() != 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(isurf->Stride() == mBounds.width * 4, "gfxImageSurface stride isn't what we expect!");
|
|
|
|
|
|
|
|
// We need to read from the GLContext
|
|
|
|
mGLContext->MakeCurrent();
|
|
|
|
|
|
|
|
// 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-05-18 08:04:22 +04:00
|
|
|
// For simplicity, we read the entire framebuffer for now -- in
|
2010-05-18 08:04:22 +04:00
|
|
|
// the future we should use mUpdatedRect, though with WebGL we don't
|
2010-05-18 08:04:22 +04:00
|
|
|
// have an easy way to generate one.
|
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
|
|
|
|
mSurface = isurf;
|
|
|
|
}
|
|
|
|
|
|
|
|
// sanity
|
|
|
|
NS_ASSERTION(mUpdatedRect.IsEmpty() || mBounds.Contains(mUpdatedRect),
|
|
|
|
"CanvasLayer: Updated rect bigger than bounds!");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-05-21 07:20:48 +04:00
|
|
|
BasicCanvasLayer::Paint(gfxContext* aContext,
|
|
|
|
LayerManager::DrawThebesLayerCallback aCallback,
|
2010-11-08 12:06:15 +03:00
|
|
|
void* aCallbackData)
|
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);
|
|
|
|
}
|
|
|
|
|
2010-11-08 12:06:15 +03:00
|
|
|
float opacity = GetEffectiveOpacity();
|
|
|
|
|
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);
|
|
|
|
if (opacity != 1.0) {
|
2010-07-16 01:08:04 +04:00
|
|
|
aContext->Save();
|
|
|
|
aContext->Clip();
|
2010-11-08 12:06:15 +03:00
|
|
|
aContext->Paint(opacity);
|
2010-07-16 01:08:04 +04:00
|
|
|
aContext->Restore();
|
|
|
|
} else {
|
|
|
|
aContext->Fill();
|
|
|
|
}
|
2010-05-18 08:04:22 +04:00
|
|
|
|
2010-05-18 08:04:22 +04:00
|
|
|
if (mNeedsYFlip) {
|
|
|
|
aContext->SetMatrix(m);
|
|
|
|
}
|
|
|
|
|
2010-05-18 08:04:22 +04:00
|
|
|
mUpdatedRect.Empty();
|
|
|
|
}
|
|
|
|
|
2010-07-16 01:08:05 +04:00
|
|
|
static nsIntRect
|
|
|
|
ToOutsideIntRect(const gfxRect &aRect)
|
|
|
|
{
|
|
|
|
gfxRect r = aRect;
|
|
|
|
r.RoundOut();
|
|
|
|
return nsIntRect(r.pos.x, r.pos.y, r.size.width, r.size.height);
|
|
|
|
}
|
|
|
|
|
2010-11-17 02:33:56 +03:00
|
|
|
static nsIntRect
|
|
|
|
ToInsideIntRect(const gfxRect& aRect)
|
|
|
|
{
|
|
|
|
gfxRect r = aRect;
|
|
|
|
r.RoundIn();
|
|
|
|
return nsIntRect(r.pos.x, r.pos.y, r.size.width, r.size.height);
|
|
|
|
}
|
|
|
|
|
2010-07-16 01:08:05 +04:00
|
|
|
/**
|
|
|
|
* Returns false if there is at most one leaf layer overlapping aBounds
|
|
|
|
* and that layer is opaque.
|
|
|
|
* aDirtyVisibleRegionInContainer is filled in only if we return false.
|
|
|
|
* It contains the union of the visible regions of leaf layers under aLayer.
|
|
|
|
*/
|
|
|
|
static PRBool
|
|
|
|
MayHaveOverlappingOrTransparentLayers(Layer* aLayer,
|
|
|
|
const nsIntRect& aBounds,
|
|
|
|
nsIntRegion* aDirtyVisibleRegionInContainer)
|
|
|
|
{
|
2010-09-02 13:18:40 +04:00
|
|
|
if (!(aLayer->GetContentFlags() & Layer::CONTENT_OPAQUE)) {
|
2010-07-16 01:08:05 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxMatrix matrix;
|
|
|
|
if (!aLayer->GetTransform().Is2D(&matrix) ||
|
|
|
|
matrix.HasNonIntegerTranslation()) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIntPoint translation = nsIntPoint(PRInt32(matrix.x0), PRInt32(matrix.y0));
|
|
|
|
nsIntRect bounds = aBounds - translation;
|
|
|
|
|
|
|
|
nsIntRect clippedDirtyRect = bounds;
|
|
|
|
const nsIntRect* clipRect = aLayer->GetClipRect();
|
|
|
|
if (clipRect) {
|
|
|
|
clippedDirtyRect.IntersectRect(clippedDirtyRect, *clipRect - translation);
|
|
|
|
}
|
|
|
|
aDirtyVisibleRegionInContainer->And(aLayer->GetVisibleRegion(), clippedDirtyRect);
|
|
|
|
aDirtyVisibleRegionInContainer->MoveBy(translation);
|
|
|
|
|
|
|
|
/* Ignore layers outside the clip rect */
|
|
|
|
if (aDirtyVisibleRegionInContainer->IsEmpty()) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIntRegion region;
|
|
|
|
|
|
|
|
for (Layer* child = aLayer->GetFirstChild(); child;
|
|
|
|
child = child->GetNextSibling()) {
|
|
|
|
nsIntRegion childRegion;
|
|
|
|
if (MayHaveOverlappingOrTransparentLayers(child, bounds, &childRegion)) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIntRegion tmp;
|
|
|
|
tmp.And(region, childRegion);
|
|
|
|
if (!tmp.IsEmpty()) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
region.Or(region, childRegion);
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
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
|
2010-09-04 00:10:46 +04:00
|
|
|
mXResolution(1.0)
|
|
|
|
, mYResolution(1.0)
|
|
|
|
, mWidget(aWidget)
|
2010-07-16 01:08:10 +04:00
|
|
|
, mDoubleBuffering(BUFFER_NONE), mUsingDefaultTarget(PR_FALSE)
|
2010-12-10 22:32:52 +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)
|
2010-07-16 01:08:10 +04:00
|
|
|
, mDoubleBuffering(BUFFER_NONE), mUsingDefaultTarget(PR_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()
|
|
|
|
{
|
2010-07-16 01:08:04 +04:00
|
|
|
mUsingDefaultTarget = PR_TRUE;
|
|
|
|
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,
|
|
|
|
gfxASurface::gfxContentType aContent,
|
|
|
|
gfxPoint *aSavedOffset)
|
|
|
|
{
|
|
|
|
gfxContextMatrixAutoSaveRestore saveMatrix(aTarget);
|
|
|
|
aTarget->IdentityMatrix();
|
|
|
|
|
|
|
|
nsRefPtr<gfxASurface> currentSurf = aTarget->CurrentSurface();
|
|
|
|
gfxRect clip = aTarget->GetClipExtents();
|
|
|
|
clip.RoundOut();
|
|
|
|
|
2010-07-16 01:08:09 +04:00
|
|
|
nsRefPtr<gfxContext> ctx =
|
|
|
|
mCachedSurface.Get(aContent,
|
|
|
|
gfxIntSize(clip.size.width, clip.size.height),
|
|
|
|
currentSurf);
|
2010-07-16 01:08:04 +04:00
|
|
|
/* Align our buffer for the original surface */
|
|
|
|
ctx->Translate(-clip.pos);
|
|
|
|
*aSavedOffset = clip.pos;
|
|
|
|
ctx->Multiply(saveMatrix.Matrix());
|
|
|
|
return ctx.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BasicLayerManager::PopGroupWithCachedSurface(gfxContext *aTarget,
|
|
|
|
const gfxPoint& aSavedOffset)
|
|
|
|
{
|
2010-07-16 01:08:09 +04:00
|
|
|
if (!mTarget)
|
2010-07-16 01:08:04 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
gfxContextMatrixAutoSaveRestore saveMatrix(aTarget);
|
|
|
|
aTarget->IdentityMatrix();
|
|
|
|
|
2010-07-16 01:08:09 +04:00
|
|
|
aTarget->SetSource(mTarget->OriginalSurface(), aSavedOffset);
|
2010-07-16 01:08:04 +04:00
|
|
|
aTarget->Paint();
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This implementation assumes that GetEffectiveTransform transforms
|
|
|
|
// all layers to the same coordinate system. It can't be used as is
|
|
|
|
// by accelerated layers because of intermediate surfaces.
|
|
|
|
static void
|
|
|
|
MarkLeafLayersCoveredByOpaque(Layer* aLayer, const nsIntRect& aClipRect,
|
|
|
|
nsIntRegion& aRegion)
|
|
|
|
{
|
|
|
|
Layer* child = aLayer->GetLastChild();
|
|
|
|
BasicImplData* data = ToData(aLayer);
|
|
|
|
data->SetCoveredByOpaque(PR_FALSE);
|
|
|
|
|
|
|
|
const nsIntRect* clipRect = aLayer->GetEffectiveClipRect();
|
|
|
|
nsIntRect newClipRect(aClipRect);
|
|
|
|
|
|
|
|
// Allow aLayer or aLayer's descendants to cover underlying layers
|
|
|
|
// only if it's opaque. GetEffectiveOpacity() could be used instead,
|
|
|
|
// but it does extra passes from descendant to ancestor.
|
|
|
|
if (aLayer->GetOpacity() != 1.0f) {
|
|
|
|
newClipRect.SetRect(0, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (clipRect) {
|
|
|
|
nsIntRect cr = *clipRect;
|
|
|
|
gfxMatrix tr;
|
|
|
|
if (aLayer->GetEffectiveTransform().Is2D(&tr)) {
|
|
|
|
TransformIntRect(cr, tr, ToInsideIntRect);
|
|
|
|
newClipRect.IntersectRect(newClipRect, cr);
|
|
|
|
} else {
|
|
|
|
newClipRect.SetRect(0, 0, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!child) {
|
|
|
|
gfxMatrix transform;
|
|
|
|
if (!aLayer->GetEffectiveTransform().Is2D(&transform)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIntRegion region = aLayer->GetEffectiveVisibleRegion();
|
|
|
|
nsIntRect r = region.GetBounds();
|
|
|
|
TransformIntRect(r, transform, ToOutsideIntRect);
|
|
|
|
data->SetCoveredByOpaque(aRegion.Contains(r));
|
|
|
|
|
|
|
|
// Allow aLayer to cover underlying layers only if aLayer's
|
|
|
|
// content is opaque
|
|
|
|
if (!(aLayer->GetContentFlags() & Layer::CONTENT_OPAQUE)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIntRegionRectIterator it(region);
|
|
|
|
while (const nsIntRect* sr = it.Next()) {
|
|
|
|
r = *sr;
|
|
|
|
TransformIntRect(r, transform, ToInsideIntRect);
|
|
|
|
|
|
|
|
r.IntersectRect(r, newClipRect);
|
|
|
|
if (!r.IsEmpty()) {
|
|
|
|
aRegion.Or(aRegion, r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (; child; child = child->GetPrevSibling()) {
|
|
|
|
MarkLeafLayersCoveredByOpaque(child, newClipRect, aRegion);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-10 22:32:52 +03:00
|
|
|
bool
|
2010-05-21 07:20:48 +04:00
|
|
|
BasicLayerManager::EndTransaction(DrawThebesLayerCallback aCallback,
|
|
|
|
void* aCallbackData)
|
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-12-10 22:32:52 +03:00
|
|
|
mTransactionIncomplete = false;
|
|
|
|
|
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-05-21 07:20:48 +04:00
|
|
|
if (mTarget) {
|
2010-07-16 01:08:05 +04:00
|
|
|
NS_ASSERTION(mRoot, "Root not set");
|
|
|
|
|
2010-07-16 01:08:04 +04:00
|
|
|
nsRefPtr<gfxContext> finalTarget = mTarget;
|
|
|
|
gfxPoint cachedSurfaceOffset;
|
|
|
|
|
2010-07-16 01:08:05 +04:00
|
|
|
nsIntRegion rootRegion;
|
|
|
|
PRBool useDoubleBuffering = mUsingDefaultTarget &&
|
|
|
|
mDoubleBuffering != BUFFER_NONE &&
|
|
|
|
MayHaveOverlappingOrTransparentLayers(mRoot,
|
|
|
|
ToOutsideIntRect(mTarget->GetClipExtents()),
|
|
|
|
&rootRegion);
|
|
|
|
if (useDoubleBuffering) {
|
2010-07-16 01:08:04 +04:00
|
|
|
nsRefPtr<gfxASurface> targetSurface = mTarget->CurrentSurface();
|
2010-07-16 01:08:04 +04:00
|
|
|
mTarget = PushGroupWithCachedSurface(mTarget, targetSurface->GetContentType(),
|
|
|
|
&cachedSurfaceOffset);
|
2010-07-16 01:08:04 +04:00
|
|
|
}
|
|
|
|
|
2010-11-08 12:06:15 +03:00
|
|
|
mSnapEffectiveTransforms =
|
|
|
|
!(mTarget->GetFlags() & gfxContext::FLAG_DISABLE_SNAPPING);
|
|
|
|
mRoot->ComputeEffectiveTransforms(gfx3DMatrix::From2D(mTarget->CurrentMatrix()));
|
2010-11-17 02:33:56 +03:00
|
|
|
|
|
|
|
nsIntRegion region;
|
|
|
|
MarkLeafLayersCoveredByOpaque(mRoot,
|
|
|
|
mRoot->GetEffectiveVisibleRegion().GetBounds(),
|
|
|
|
region);
|
2010-11-08 12:06:15 +03:00
|
|
|
PaintLayer(mRoot, aCallback, aCallbackData);
|
2010-12-10 22:32:52 +03:00
|
|
|
if (mTransactionIncomplete) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
mPhase = PHASE_NONE;
|
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
}
|
2010-11-08 12:06:15 +03:00
|
|
|
|
2010-07-16 01:08:05 +04:00
|
|
|
if (useDoubleBuffering) {
|
2010-07-16 01:08:04 +04:00
|
|
|
finalTarget->SetOperator(gfxContext::OPERATOR_SOURCE);
|
|
|
|
PopGroupWithCachedSurface(finalTarget, cachedSurfaceOffset);
|
2010-07-16 01:08:04 +04:00
|
|
|
}
|
|
|
|
|
2010-05-21 07:20:48 +04:00
|
|
|
mTarget = nsnull;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
mPhase = PHASE_NONE;
|
|
|
|
#endif
|
2010-07-16 01:08:04 +04:00
|
|
|
mUsingDefaultTarget = PR_FALSE;
|
2010-12-10 22:32:52 +03:00
|
|
|
return true;
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-05-21 07:20:48 +04:00
|
|
|
BasicLayerManager::PaintLayer(Layer* aLayer,
|
|
|
|
DrawThebesLayerCallback aCallback,
|
2010-11-08 12:06:15 +03:00
|
|
|
void* aCallbackData)
|
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();
|
|
|
|
PRBool needsGroup = aLayer->GetFirstChild() &&
|
|
|
|
static_cast<BasicContainerLayer*>(aLayer)->UseIntermediateSurface();
|
|
|
|
// If needsSaveRestore is false, we should still save and restore
|
|
|
|
// the CTM
|
|
|
|
PRBool needsSaveRestore = needsGroup || clipRect;
|
2010-05-21 07:20:48 +04:00
|
|
|
|
2010-11-08 12:06:15 +03:00
|
|
|
gfxMatrix savedMatrix;
|
|
|
|
if (needsSaveRestore) {
|
2010-03-02 02:08:28 +03:00
|
|
|
mTarget->Save();
|
|
|
|
|
2010-11-08 12:06:15 +03:00
|
|
|
if (clipRect) {
|
2010-03-02 02:08:28 +03:00
|
|
|
mTarget->NewPath();
|
2010-11-08 12:06:15 +03:00
|
|
|
mTarget->Rectangle(gfxRect(clipRect->x, clipRect->y, clipRect->width, clipRect->height), PR_TRUE);
|
2010-03-02 02:08:28 +03:00
|
|
|
mTarget->Clip();
|
2010-03-01 10:56:18 +03:00
|
|
|
}
|
2010-11-08 12:06:15 +03:00
|
|
|
} else {
|
|
|
|
savedMatrix = mTarget->CurrentMatrix();
|
|
|
|
}
|
2010-03-01 10:56:18 +03:00
|
|
|
|
2010-11-08 12:06:15 +03:00
|
|
|
gfxMatrix transform;
|
|
|
|
// XXX we need to add some kind of 3D transform support, possibly
|
|
|
|
// using pixman?
|
|
|
|
NS_ASSERTION(effectiveTransform.Is2D(),
|
|
|
|
"Only 2D transforms supported currently");
|
|
|
|
effectiveTransform.Is2D(&transform);
|
|
|
|
mTarget->SetMatrix(transform);
|
|
|
|
|
|
|
|
if (needsGroup) {
|
|
|
|
// If we need to call PushGroup, we should clip to the smallest possible
|
|
|
|
// area first to minimize the size of the temporary surface.
|
|
|
|
ClipToContain(mTarget, aLayer->GetEffectiveVisibleRegion().GetBounds());
|
|
|
|
|
|
|
|
gfxASurface::gfxContentType type = aLayer->CanUseOpaqueSurface()
|
|
|
|
? gfxASurface::CONTENT_COLOR : gfxASurface::CONTENT_COLOR_ALPHA;
|
|
|
|
mTarget->PushGroup(type);
|
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
|
|
|
BasicImplData* data = ToData(aLayer);
|
|
|
|
#ifdef MOZ_LAYERS_HAVE_LOG
|
|
|
|
MOZ_LAYERS_LOG(("%s (0x%p) is covered: %i\n", __FUNCTION__,
|
|
|
|
(void*)aLayer, data->IsCoveredByOpaque()));
|
|
|
|
#endif
|
|
|
|
if (!data->IsCoveredByOpaque()) {
|
|
|
|
data->Paint(mTarget, aCallback, aCallbackData);
|
2010-12-10 22:32:52 +03:00
|
|
|
if (mTransactionIncomplete) {
|
|
|
|
return;
|
|
|
|
}
|
2010-11-17 02:33:56 +03:00
|
|
|
}
|
2010-07-16 01:08:04 +04:00
|
|
|
} else {
|
2010-11-08 12:06:15 +03:00
|
|
|
for (; child; child = child->GetNextSibling()) {
|
|
|
|
PaintLayer(child, aCallback, aCallbackData);
|
2010-12-10 22:32:52 +03:00
|
|
|
if (mTransactionIncomplete) {
|
|
|
|
return;
|
|
|
|
}
|
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) {
|
|
|
|
mTarget->PopGroupToSource();
|
2010-11-12 04:43:42 +03:00
|
|
|
// If the layer is opaque in its visible region we pushed a CONTENT_COLOR
|
|
|
|
// group. We need to make sure that only pixels inside the layer's visible
|
|
|
|
// region are copied back to the destination.
|
|
|
|
gfxUtils::ClipToRegionSnapped(mTarget, aLayer->GetEffectiveVisibleRegion());
|
2010-11-08 12:06:15 +03:00
|
|
|
mTarget->Paint(aLayer->GetEffectiveOpacity());
|
|
|
|
}
|
2010-03-01 10:56:18 +03:00
|
|
|
|
2010-11-08 12:06:15 +03:00
|
|
|
if (needsSaveRestore) {
|
2010-03-01 10:56:18 +03:00
|
|
|
mTarget->Restore();
|
2010-11-08 12:06:15 +03:00
|
|
|
} else {
|
|
|
|
mTarget->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();
|
|
|
|
}
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
|
|
|
|
#ifdef MOZ_IPC
|
|
|
|
|
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 SetBackBufferImage(gfxSharedImageSurface* aBuffer)
|
|
|
|
{
|
|
|
|
NS_RUNTIMEABORT("if this default impl is called, |aBuffer| leaks");
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual PRBool SupportsSurfaceDescriptor() const { return PR_FALSE; }
|
|
|
|
virtual void SetBackBuffer(const SurfaceDescriptor& aBuffer)
|
2010-07-22 01:17:33 +04:00
|
|
|
{
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
2010-09-04 00:10:45 +04:00
|
|
|
virtual void FillSpecificAttributes(SpecificLayerAttributes& aAttrs)
|
|
|
|
{
|
|
|
|
aAttrs = ContainerLayerAttributes(GetFrameMetrics());
|
|
|
|
}
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
if (HasShadow()) {
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
if (HasShadow()) {
|
|
|
|
ShadowManager()->RemoveChild(ShadowManager()->Hold(this),
|
|
|
|
ShadowManager()->Hold(aChild));
|
|
|
|
}
|
|
|
|
BasicContainerLayer::RemoveChild(aChild);
|
|
|
|
}
|
|
|
|
|
2010-09-14 09:23:08 +04:00
|
|
|
static PRBool
|
|
|
|
IsSurfaceDescriptorValid(const SurfaceDescriptor& aSurface)
|
|
|
|
{
|
|
|
|
return SurfaceDescriptor::T__None != aSurface.type();
|
|
|
|
}
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
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)
|
2010-07-22 01:17:33 +04:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(BasicShadowableThebesLayer);
|
|
|
|
}
|
|
|
|
virtual ~BasicShadowableThebesLayer()
|
|
|
|
{
|
2010-11-25 06:33:37 +03:00
|
|
|
NS_ABORT_IF_FALSE(!HasShadow() || !BasicManager()->InTransaction(),
|
|
|
|
"Shadow layers can't be destroyed during txns!");
|
2010-09-14 09:23:08 +04:00
|
|
|
if (IsSurfaceDescriptorValid(mBackBuffer))
|
|
|
|
BasicManager()->ShadowLayerForwarder::DestroySharedSurface(&mBackBuffer);
|
2010-07-22 01:17:33 +04:00
|
|
|
MOZ_COUNT_DTOR(BasicShadowableThebesLayer);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void FillSpecificAttributes(SpecificLayerAttributes& aAttrs)
|
|
|
|
{
|
2010-09-04 00:10:46 +04:00
|
|
|
aAttrs = ThebesLayerAttributes(GetValidRegion(),
|
|
|
|
mXResolution, mYResolution);
|
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
|
|
|
|
2010-09-14 09:23:08 +04:00
|
|
|
virtual PRBool SupportsSurfaceDescriptor() const { return PR_TRUE; }
|
|
|
|
|
2010-09-14 09:23:08 +04:00
|
|
|
void SetBackBufferAndAttrs(const ThebesBuffer& aBuffer,
|
|
|
|
const nsIntRegion& aValidRegion,
|
2010-11-05 10:17:07 +03:00
|
|
|
float aXResolution, float aYResolution,
|
|
|
|
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; }
|
|
|
|
|
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,
|
|
|
|
const nsIntRegion& aRegionToInvalidate,
|
|
|
|
LayerManager::DrawThebesLayerCallback aCallback,
|
|
|
|
void* aCallbackData);
|
|
|
|
|
|
|
|
NS_OVERRIDE virtual already_AddRefed<gfxASurface>
|
|
|
|
CreateBuffer(Buffer::ContentType aType, const nsIntSize& aSize);
|
|
|
|
|
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;
|
2010-11-13 01:21:05 +03:00
|
|
|
|
|
|
|
PRPackedBool mIsNewBuffer;
|
2010-07-22 01:17:33 +04:00
|
|
|
};
|
2010-11-05 10:17:07 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
BasicShadowableThebesLayer::SetBackBufferAndAttrs(const ThebesBuffer& aBuffer,
|
|
|
|
const nsIntRegion& aValidRegion,
|
|
|
|
float aXResolution,
|
2010-11-05 10:17:07 +03:00
|
|
|
float aYResolution,
|
|
|
|
const OptionalThebesBuffer& aReadOnlyFrontBuffer,
|
|
|
|
const nsIntRegion& aFrontUpdatedRegion)
|
2010-11-05 10:17:07 +03:00
|
|
|
{
|
|
|
|
mBackBuffer = aBuffer.buffer();
|
|
|
|
nsRefPtr<gfxASurface> backBuffer = BasicManager()->OpenDescriptor(mBackBuffer);
|
2010-11-05 10:17:07 +03:00
|
|
|
|
|
|
|
if (OptionalThebesBuffer::Tnull_t == aReadOnlyFrontBuffer.type()) {
|
|
|
|
// 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, ...
|
|
|
|
mValidRegion = aValidRegion;
|
|
|
|
mXResolution = aXResolution;
|
|
|
|
mYResolution = aYResolution;
|
|
|
|
mBuffer.SetBackingBuffer(backBuffer, aBuffer.rect(), aBuffer.rotation());
|
|
|
|
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,
|
|
|
|
aFrontUpdatedRegion.GetBounds().x,
|
|
|
|
aFrontUpdatedRegion.GetBounds().y,
|
|
|
|
aFrontUpdatedRegion.GetBounds().width,
|
|
|
|
aFrontUpdatedRegion.GetBounds().height));
|
|
|
|
|
2010-11-05 10:17:07 +03:00
|
|
|
const ThebesBuffer roFront = aReadOnlyFrontBuffer.get_ThebesBuffer();
|
|
|
|
nsRefPtr<gfxASurface> roFrontBuffer = BasicManager()->OpenDescriptor(roFront.buffer());
|
|
|
|
mBuffer.SetBackingBufferAndUpdateFrom(
|
|
|
|
backBuffer,
|
|
|
|
roFrontBuffer, roFront.rect(), roFront.rotation(),
|
|
|
|
aFrontUpdatedRegion, mXResolution, mYResolution);
|
|
|
|
// 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,
|
|
|
|
const nsIntRegion& aRegionToInvalidate,
|
|
|
|
LayerManager::DrawThebesLayerCallback aCallback,
|
|
|
|
void* aCallbackData)
|
|
|
|
{
|
2010-12-10 22:32:52 +03:00
|
|
|
if (!aCallback) {
|
|
|
|
BasicManager()->SetTransactionIncomplete();
|
|
|
|
mIsNewBuffer = false;
|
|
|
|
return;
|
|
|
|
}
|
2010-07-22 01:17:33 +04:00
|
|
|
Base::PaintBuffer(aContext, aRegionToDraw, aRegionToInvalidate,
|
|
|
|
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;
|
|
|
|
if (mIsNewBuffer) {
|
|
|
|
// 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.
|
|
|
|
updatedRegion = mVisibleRegion;
|
|
|
|
mIsNewBuffer = false;
|
|
|
|
} else {
|
|
|
|
updatedRegion = aRegionToDraw;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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)) {
|
2010-09-14 09:23:08 +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
|
2010-11-05 10:17:07 +03:00
|
|
|
SurfaceDescriptor tmpFront;
|
2010-09-14 09:23:08 +04:00
|
|
|
if (!BasicManager()->AllocDoubleBuffer(gfxIntSize(aSize.width, aSize.height),
|
2010-09-14 09:23:08 +04:00
|
|
|
aType,
|
2010-11-05 10:17:07 +03:00
|
|
|
&tmpFront,
|
2010-09-14 09:23:08 +04:00
|
|
|
&mBackBuffer))
|
2010-09-14 09:23:08 +04: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?");
|
|
|
|
mIsNewBuffer = true;
|
|
|
|
|
2010-11-05 10:17:07 +03:00
|
|
|
BasicManager()->CreatedThebesBuffer(BasicManager()->Hold(this),
|
|
|
|
nsIntRegion(),
|
|
|
|
1.0, 1.0,
|
|
|
|
nsIntRect(),
|
|
|
|
tmpFront);
|
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()
|
|
|
|
{
|
2010-07-22 01:17:33 +04:00
|
|
|
if (mBackSurface) {
|
|
|
|
BasicManager()->ShadowLayerForwarder::DestroySharedSurface(mBackSurface);
|
|
|
|
}
|
2010-07-22 01:17:33 +04:00
|
|
|
MOZ_COUNT_DTOR(BasicShadowableImageLayer);
|
|
|
|
}
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
virtual void Paint(gfxContext* aContext,
|
|
|
|
LayerManager::DrawThebesLayerCallback aCallback,
|
2010-11-08 12:06:15 +03:00
|
|
|
void* aCallbackData);
|
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
|
|
|
|
2010-09-14 09:23:08 +04:00
|
|
|
virtual void SetBackBufferImage(gfxSharedImageSurface* aBuffer)
|
2010-07-22 01:17:33 +04:00
|
|
|
{
|
|
|
|
mBackSurface = aBuffer;
|
|
|
|
}
|
|
|
|
|
2010-08-21 03:24:41 +04:00
|
|
|
virtual void Disconnect()
|
|
|
|
{
|
|
|
|
mBackSurface = nsnull;
|
|
|
|
BasicShadowableLayer::Disconnect();
|
|
|
|
}
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
private:
|
|
|
|
BasicShadowLayerManager* BasicManager()
|
|
|
|
{
|
|
|
|
return static_cast<BasicShadowLayerManager*>(mManager);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<gfxSharedImageSurface> mBackSurface;
|
2010-07-22 01:17:33 +04:00
|
|
|
};
|
2010-07-22 01:17:33 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
BasicShadowableImageLayer::Paint(gfxContext* aContext,
|
|
|
|
LayerManager::DrawThebesLayerCallback aCallback,
|
2010-11-08 12:06:15 +03:00
|
|
|
void* aCallbackData)
|
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;
|
|
|
|
|
|
|
|
if (oldSize != mSize) {
|
2010-09-21 10:57:25 +04:00
|
|
|
NS_ASSERTION(oldSize == gfxIntSize(-1, -1), "video changed size?");
|
2010-07-22 01:17:33 +04:00
|
|
|
|
2010-09-03 07:05:01 +04:00
|
|
|
if (mBackSurface) {
|
|
|
|
BasicManager()->ShadowLayerForwarder::DestroySharedSurface(mBackSurface);
|
|
|
|
mBackSurface = nsnull;
|
|
|
|
|
|
|
|
BasicManager()->DestroyedImageBuffer(BasicManager()->Hold(this));
|
|
|
|
}
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
nsRefPtr<gfxSharedImageSurface> tmpFrontSurface;
|
|
|
|
// XXX error handling?
|
|
|
|
if (!BasicManager()->AllocDoubleBuffer(
|
2010-09-17 01:24:17 +04:00
|
|
|
mSize,
|
|
|
|
(GetContentFlags() & CONTENT_OPAQUE) ?
|
|
|
|
gfxASurface::CONTENT_COLOR : gfxASurface::CONTENT_COLOR_ALPHA,
|
2010-07-22 01:17:33 +04:00
|
|
|
getter_AddRefs(tmpFrontSurface), getter_AddRefs(mBackSurface)))
|
|
|
|
NS_RUNTIMEABORT("creating ImageLayer 'front buffer' failed!");
|
|
|
|
|
|
|
|
BasicManager()->CreatedImageBuffer(BasicManager()->Hold(this),
|
|
|
|
nsIntSize(mSize.width, mSize.height),
|
|
|
|
tmpFrontSurface);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<gfxContext> tmpCtx = new gfxContext(mBackSurface);
|
|
|
|
PaintContext(pat, mSize, 1.0, tmpCtx);
|
|
|
|
|
|
|
|
BasicManager()->PaintedImage(BasicManager()->Hold(this),
|
|
|
|
mBackSurface);
|
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
{
|
2010-07-22 01:17:33 +04:00
|
|
|
if (mBackBuffer) {
|
2010-07-22 01:17:33 +04:00
|
|
|
BasicManager()->ShadowLayerForwarder::DestroySharedSurface(mBackBuffer);
|
2010-07-22 01:17:33 +04:00
|
|
|
}
|
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);
|
|
|
|
virtual void Paint(gfxContext* aContext,
|
|
|
|
LayerManager::DrawThebesLayerCallback aCallback,
|
2010-11-08 12:06:15 +03:00
|
|
|
void* aCallbackData);
|
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
|
|
|
|
2010-09-14 09:23:08 +04:00
|
|
|
virtual void SetBackBufferImage(gfxSharedImageSurface* aBuffer)
|
2010-07-22 01:17:33 +04:00
|
|
|
{
|
|
|
|
mBackBuffer = aBuffer;
|
|
|
|
}
|
2010-08-21 03:24:41 +04:00
|
|
|
|
|
|
|
virtual void Disconnect()
|
|
|
|
{
|
|
|
|
mBackBuffer = nsnull;
|
|
|
|
BasicShadowableLayer::Disconnect();
|
|
|
|
}
|
2010-07-22 01:17:33 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
BasicShadowLayerManager* BasicManager()
|
|
|
|
{
|
|
|
|
return static_cast<BasicShadowLayerManager*>(mManager);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<gfxSharedImageSurface> 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
|
|
|
|
if (mBackBuffer) {
|
|
|
|
BasicManager()->ShadowLayerForwarder::DestroySharedSurface(mBackBuffer);
|
|
|
|
mBackBuffer = nsnull;
|
|
|
|
|
|
|
|
BasicManager()->DestroyedCanvasBuffer(BasicManager()->Hold(this));
|
|
|
|
}
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
nsRefPtr<gfxSharedImageSurface> tmpFrontBuffer;
|
|
|
|
// XXX error handling?
|
|
|
|
if (!BasicManager()->AllocDoubleBuffer(
|
|
|
|
gfxIntSize(aData.mSize.width, aData.mSize.height),
|
2010-09-17 01:24:17 +04:00
|
|
|
(GetContentFlags() & CONTENT_OPAQUE) ?
|
|
|
|
gfxASurface::CONTENT_COLOR : gfxASurface::CONTENT_COLOR_ALPHA,
|
2010-07-22 01:17:33 +04:00
|
|
|
getter_AddRefs(tmpFrontBuffer), getter_AddRefs(mBackBuffer)))
|
|
|
|
NS_RUNTIMEABORT("creating CanvasLayer back buffer failed!");
|
|
|
|
|
|
|
|
BasicManager()->CreatedCanvasBuffer(BasicManager()->Hold(this),
|
|
|
|
aData.mSize,
|
|
|
|
tmpFrontBuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BasicShadowableCanvasLayer::Paint(gfxContext* aContext,
|
|
|
|
LayerManager::DrawThebesLayerCallback aCallback,
|
2010-11-08 12:06:15 +03:00
|
|
|
void* aCallbackData)
|
2010-07-22 01:17:33 +04:00
|
|
|
{
|
2010-11-08 12:06:15 +03:00
|
|
|
BasicCanvasLayer::Paint(aContext, aCallback, aCallbackData);
|
2010-07-22 01:17:33 +04:00
|
|
|
if (!HasShadow())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// XXX this is yucky and slow. It'd be nice to draw directly into
|
|
|
|
// the shmem back buffer
|
|
|
|
nsRefPtr<gfxContext> tmpCtx = new gfxContext(mBackBuffer);
|
2010-09-03 08:14:12 +04:00
|
|
|
tmpCtx->SetOperator(gfxContext::OPERATOR_SOURCE);
|
2010-07-22 01:17:33 +04:00
|
|
|
tmpCtx->DrawSurface(mSurface, gfxSize(mBounds.width, mBounds.height));
|
|
|
|
|
|
|
|
BasicManager()->PaintedCanvas(BasicManager()->Hold(this),
|
|
|
|
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();
|
|
|
|
|
|
|
|
gfxIntSize newSize = aNewBuffer->GetSize();
|
|
|
|
nsRefPtr<gfxASurface> oldBuffer;
|
|
|
|
oldBuffer = SetBuffer(aNewBuffer,
|
|
|
|
nsIntSize(newSize.width, newSize.height),
|
|
|
|
aNewRect, aNewRotation);
|
|
|
|
oldBuffer.forget(aOldBuffer);
|
2010-07-22 01:17:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual already_AddRefed<gfxASurface>
|
|
|
|
CreateBuffer(ContentType aType, const nsIntSize& aSize)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
class BasicShadowThebesLayer : public ShadowThebesLayer, BasicImplData {
|
|
|
|
public:
|
2010-09-14 09:23:08 +04:00
|
|
|
BasicShadowThebesLayer(BasicShadowLayerManager* aLayerManager)
|
|
|
|
: ShadowThebesLayer(aLayerManager, static_cast<BasicImplData*>(this))
|
|
|
|
, mOldXResolution(1.0)
|
|
|
|
, mOldYResolution(1.0)
|
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-29 02:05:30 +04:00
|
|
|
virtual void SetFrontBuffer(const ThebesBuffer& aNewFront,
|
|
|
|
const nsIntRegion& aValidRegion,
|
|
|
|
float aXResolution, float aYResolution);
|
|
|
|
|
2010-09-14 09:23:08 +04:00
|
|
|
virtual void SetValidRegion(const nsIntRegion& aRegion)
|
|
|
|
{
|
|
|
|
mOldValidRegion = mValidRegion;
|
|
|
|
ShadowThebesLayer::SetValidRegion(aRegion);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void SetResolution(float aXResolution, float aYResolution)
|
|
|
|
{
|
|
|
|
mOldXResolution = mXResolution;
|
|
|
|
mOldYResolution = mYResolution;
|
|
|
|
ShadowThebesLayer::SetResolution(aXResolution, aYResolution);
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
ThebesBuffer* aNewBack, nsIntRegion* aNewBackValidRegion,
|
2010-11-05 10:17:07 +03:00
|
|
|
float* aNewXResolution, float* aNewYResolution,
|
|
|
|
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();
|
|
|
|
mOldXResolution = 1.0;
|
|
|
|
mOldYResolution = 1.0;
|
|
|
|
|
2010-09-14 09:23:08 +04:00
|
|
|
if (IsSurfaceDescriptorValid(mFrontBufferDescriptor)) {
|
2010-09-25 02:41:31 +04:00
|
|
|
BasicManager()->ShadowLayerManager::DestroySharedSurface(&mFrontBufferDescriptor, mAllocator);
|
2010-09-03 07:05:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
virtual void Paint(gfxContext* aContext,
|
|
|
|
LayerManager::DrawThebesLayerCallback aCallback,
|
2010-11-08 12:06:15 +03:00
|
|
|
void* aCallbackData);
|
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;
|
|
|
|
float mOldXResolution;
|
|
|
|
float mOldYResolution;
|
2010-07-22 01:17:33 +04:00
|
|
|
};
|
|
|
|
|
2010-09-29 02:05:30 +04:00
|
|
|
void
|
|
|
|
BasicShadowThebesLayer::SetFrontBuffer(const ThebesBuffer& aNewFront,
|
|
|
|
const nsIntRegion& aValidRegion,
|
|
|
|
float aXResolution, float aYResolution)
|
|
|
|
{
|
|
|
|
mValidRegion = mOldValidRegion = aValidRegion;
|
|
|
|
mXResolution = mOldXResolution = aXResolution;
|
|
|
|
mYResolution = mOldYResolution = aYResolution;
|
|
|
|
nsRefPtr<gfxASurface> newFrontBuffer =
|
|
|
|
BasicManager()->OpenDescriptor(aNewFront.buffer());
|
|
|
|
|
|
|
|
nsRefPtr<gfxASurface> unused;
|
|
|
|
nsIntRect unusedRect;
|
|
|
|
nsIntPoint unusedRotation;
|
|
|
|
mFrontBuffer.Swap(newFrontBuffer, aNewFront.rect(), aNewFront.rotation(),
|
|
|
|
getter_AddRefs(unused), &unusedRect, &unusedRotation);
|
|
|
|
mFrontBufferDescriptor = aNewFront.buffer();
|
|
|
|
}
|
|
|
|
|
2010-09-14 09:23:08 +04:00
|
|
|
void
|
|
|
|
BasicShadowThebesLayer::Swap(const ThebesBuffer& aNewFront,
|
|
|
|
const nsIntRegion& aUpdatedRegion,
|
|
|
|
ThebesBuffer* aNewBack,
|
|
|
|
nsIntRegion* aNewBackValidRegion,
|
2010-11-05 10:17:07 +03:00
|
|
|
float* aNewXResolution, float* aNewYResolution,
|
|
|
|
OptionalThebesBuffer* aReadOnlyFront,
|
|
|
|
nsIntRegion* aFrontUpdatedRegion)
|
2010-09-14 09:23:08 +04:00
|
|
|
{
|
2010-09-16 01:03:13 +04:00
|
|
|
// This code relies on Swap() arriving *after* attribute mutations.
|
2010-09-14 09:23:08 +04:00
|
|
|
aNewBack->buffer() = mFrontBufferDescriptor;
|
|
|
|
// We have to invalidate the pixels painted into the new buffer.
|
|
|
|
// They might overlap with our old pixels.
|
2010-09-16 01:03:13 +04:00
|
|
|
if (mOldXResolution == mXResolution && mOldYResolution == mYResolution) {
|
2010-09-29 02:05:30 +04:00
|
|
|
aNewBackValidRegion->Sub(mOldValidRegion, aUpdatedRegion);
|
2010-09-16 01:03:13 +04:00
|
|
|
} else {
|
|
|
|
// On resolution changes, pretend that our buffer has the new
|
|
|
|
// resolution, but just has no valid content. This can avoid
|
|
|
|
// unnecessary buffer reallocs.
|
2010-09-29 02:05:30 +04:00
|
|
|
//
|
|
|
|
// FIXME/bug 598866: when we start re-using buffers after
|
|
|
|
// resolution changes, we're going to need to implement
|
|
|
|
// front->back copies to avoid thrashing our valid region by
|
|
|
|
// always nullifying it.
|
2010-09-16 01:03:13 +04:00
|
|
|
aNewBackValidRegion->SetEmpty();
|
|
|
|
mOldXResolution = mXResolution;
|
|
|
|
mOldYResolution = mYResolution;
|
|
|
|
}
|
2010-09-29 02:05:30 +04:00
|
|
|
NS_ASSERTION(mXResolution == mOldXResolution && mYResolution == mOldYResolution,
|
|
|
|
"Uh-oh, buffer allocation thrash forthcoming!");
|
2010-09-16 01:03:13 +04:00
|
|
|
*aNewXResolution = mXResolution;
|
|
|
|
*aNewYResolution = mYResolution;
|
2010-09-14 09:23:08 +04:00
|
|
|
|
2010-09-14 09:23:08 +04:00
|
|
|
nsRefPtr<gfxASurface> newFrontBuffer =
|
2010-09-14 09:23:08 +04:00
|
|
|
BasicManager()->OpenDescriptor(aNewFront.buffer());
|
2010-09-14 09:23:08 +04:00
|
|
|
|
2010-09-14 09:23:08 +04:00
|
|
|
nsRefPtr<gfxASurface> unused;
|
|
|
|
mFrontBuffer.Swap(
|
|
|
|
newFrontBuffer, aNewFront.rect(), aNewFront.rotation(),
|
|
|
|
getter_AddRefs(unused), &aNewBack->rect(), &aNewBack->rotation());
|
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
|
|
|
|
BasicShadowThebesLayer::Paint(gfxContext* aContext,
|
|
|
|
LayerManager::DrawThebesLayerCallback aCallback,
|
2010-11-08 12:06:15 +03:00
|
|
|
void* aCallbackData)
|
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;
|
|
|
|
}
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
gfxContext* target = BasicManager()->GetTarget();
|
|
|
|
NS_ASSERTION(target, "We shouldn't be called if there's no target");
|
|
|
|
|
2010-11-12 04:43:42 +03:00
|
|
|
mFrontBuffer.DrawTo(this, target, GetEffectiveOpacity());
|
2010-07-22 01:17:33 +04:00
|
|
|
}
|
|
|
|
|
2010-10-14 02:55:45 +04:00
|
|
|
class BasicShadowContainerLayer : public ShadowContainerLayer, BasicImplData {
|
|
|
|
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.
|
|
|
|
gfx3DMatrix idealTransform = GetLocalTransform()*aTransformToSurface;
|
|
|
|
mEffectiveTransform = SnapTransform(idealTransform, gfxRect(0, 0, 0, 0), nsnull);
|
|
|
|
// 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
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
class BasicShadowImageLayer : public ShadowImageLayer, BasicImplData {
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
DestroyFrontBuffer();
|
|
|
|
ShadowImageLayer::Disconnect();
|
|
|
|
}
|
2010-08-21 03:24:41 +04:00
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
virtual PRBool Init(gfxSharedImageSurface* front, const nsIntSize& size);
|
2010-07-22 01:17:33 +04:00
|
|
|
|
|
|
|
virtual already_AddRefed<gfxSharedImageSurface>
|
2010-07-22 01:17:33 +04:00
|
|
|
Swap(gfxSharedImageSurface* newFront);
|
2010-07-22 01:17:33 +04:00
|
|
|
|
2010-09-03 07:05:01 +04:00
|
|
|
virtual void DestroyFrontBuffer()
|
|
|
|
{
|
|
|
|
if (mFrontSurface) {
|
2010-09-25 02:41:31 +04:00
|
|
|
BasicManager()->ShadowLayerManager::DestroySharedSurface(mFrontSurface, mAllocator);
|
2010-09-03 07:05:01 +04:00
|
|
|
}
|
|
|
|
mFrontSurface = nsnull;
|
|
|
|
}
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
virtual void Paint(gfxContext* aContext,
|
|
|
|
LayerManager::DrawThebesLayerCallback aCallback,
|
2010-11-08 12:06:15 +03:00
|
|
|
void* aCallbackData);
|
2010-07-22 01:17:33 +04:00
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
protected:
|
|
|
|
BasicShadowLayerManager* BasicManager()
|
|
|
|
{
|
|
|
|
return static_cast<BasicShadowLayerManager*>(mManager);
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX ShmemImage?
|
|
|
|
nsRefPtr<gfxSharedImageSurface> mFrontSurface;
|
|
|
|
gfxIntSize mSize;
|
2010-07-22 01:17:33 +04:00
|
|
|
};
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
PRBool
|
|
|
|
BasicShadowImageLayer::Init(gfxSharedImageSurface* front,
|
|
|
|
const nsIntSize& size)
|
|
|
|
{
|
|
|
|
mFrontSurface = front;
|
|
|
|
mSize = gfxIntSize(size.width, size.height);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<gfxSharedImageSurface>
|
|
|
|
BasicShadowImageLayer::Swap(gfxSharedImageSurface* newFront)
|
|
|
|
{
|
|
|
|
already_AddRefed<gfxSharedImageSurface> tmp = mFrontSurface.forget();
|
|
|
|
mFrontSurface = newFront;
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BasicShadowImageLayer::Paint(gfxContext* aContext,
|
|
|
|
LayerManager::DrawThebesLayerCallback aCallback,
|
2010-11-08 12:06:15 +03:00
|
|
|
void* aCallbackData)
|
2010-07-22 01:17:33 +04:00
|
|
|
{
|
2010-08-21 03:24:41 +04:00
|
|
|
if (!mFrontSurface) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
nsRefPtr<gfxPattern> pat = new gfxPattern(mFrontSurface);
|
|
|
|
pat->SetFilter(mFilter);
|
2010-11-08 12:06:15 +03:00
|
|
|
BasicImageLayer::PaintContext(pat, mSize, GetEffectiveOpacity(), aContext);
|
2010-07-22 01:17:33 +04:00
|
|
|
}
|
|
|
|
|
2010-10-14 02:55:45 +04:00
|
|
|
class BasicShadowColorLayer : public ShadowColorLayer,
|
|
|
|
BasicImplData
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
BasicShadowColorLayer(BasicShadowLayerManager* aLayerManager) :
|
|
|
|
ShadowColorLayer(aLayerManager, static_cast<BasicImplData*>(this))
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(BasicShadowColorLayer);
|
|
|
|
}
|
|
|
|
virtual ~BasicShadowColorLayer()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(BasicShadowColorLayer);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Paint(gfxContext* aContext,
|
|
|
|
LayerManager::DrawThebesLayerCallback aCallback,
|
2010-11-08 12:06:15 +03:00
|
|
|
void* aCallbackData)
|
2010-10-14 02:55:45 +04:00
|
|
|
{
|
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,
|
|
|
|
BasicImplData
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
BasicShadowCanvasLayer(BasicShadowLayerManager* aLayerManager) :
|
|
|
|
ShadowCanvasLayer(aLayerManager, static_cast<BasicImplData*>(this))
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(BasicShadowCanvasLayer);
|
|
|
|
}
|
|
|
|
virtual ~BasicShadowCanvasLayer()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(BasicShadowCanvasLayer);
|
|
|
|
}
|
|
|
|
|
2010-09-03 07:05:01 +04:00
|
|
|
virtual void Disconnect()
|
|
|
|
{
|
|
|
|
DestroyFrontBuffer();
|
|
|
|
ShadowCanvasLayer::Disconnect();
|
|
|
|
}
|
2010-08-21 03:24:41 +04:00
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
virtual void Initialize(const Data& aData);
|
2010-07-22 01:17:33 +04:00
|
|
|
|
|
|
|
virtual void Updated(const nsIntRect& aRect)
|
|
|
|
{}
|
|
|
|
|
|
|
|
virtual already_AddRefed<gfxSharedImageSurface>
|
2010-07-22 01:17:33 +04:00
|
|
|
Swap(gfxSharedImageSurface* newFront);
|
2010-07-22 01:17:33 +04:00
|
|
|
|
2010-09-03 07:05:01 +04:00
|
|
|
virtual void DestroyFrontBuffer()
|
|
|
|
{
|
|
|
|
if (mFrontSurface) {
|
2010-09-25 02:41:31 +04:00
|
|
|
BasicManager()->ShadowLayerManager::DestroySharedSurface(mFrontSurface, mAllocator);
|
2010-09-03 07:05:01 +04:00
|
|
|
}
|
|
|
|
mFrontSurface = nsnull;
|
|
|
|
}
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
virtual void Paint(gfxContext* aContext,
|
|
|
|
LayerManager::DrawThebesLayerCallback aCallback,
|
2010-11-08 12:06:15 +03:00
|
|
|
void* aCallbackData);
|
2010-07-22 01:17:33 +04:00
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
private:
|
|
|
|
BasicShadowLayerManager* BasicManager()
|
|
|
|
{
|
|
|
|
return static_cast<BasicShadowLayerManager*>(mManager);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<gfxSharedImageSurface> mFrontSurface;
|
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)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mFrontSurface == nsnull,
|
|
|
|
"BasicCanvasLayer::Initialize called twice!");
|
|
|
|
NS_ASSERTION(aData.mSurface && !aData.mGLContext, "no comprende OpenGL!");
|
|
|
|
|
|
|
|
mFrontSurface = static_cast<gfxSharedImageSurface*>(aData.mSurface);
|
|
|
|
mBounds.SetRect(0, 0, aData.mSize.width, aData.mSize.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<gfxSharedImageSurface>
|
|
|
|
BasicShadowCanvasLayer::Swap(gfxSharedImageSurface* newFront)
|
|
|
|
{
|
|
|
|
already_AddRefed<gfxSharedImageSurface> tmp = mFrontSurface.forget();
|
|
|
|
mFrontSurface = newFront;
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BasicShadowCanvasLayer::Paint(gfxContext* aContext,
|
|
|
|
LayerManager::DrawThebesLayerCallback aCallback,
|
2010-11-08 12:06:15 +03:00
|
|
|
void* aCallbackData)
|
2010-07-22 01:17:33 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(BasicManager()->InDrawing(),
|
|
|
|
"Can only draw in drawing phase");
|
|
|
|
|
2010-08-21 03:24:41 +04:00
|
|
|
if (!mFrontSurface) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-07-22 01:17:33 +04:00
|
|
|
nsRefPtr<gfxPattern> pat = new gfxPattern(mFrontSurface);
|
|
|
|
|
|
|
|
pat->SetFilter(mFilter);
|
|
|
|
pat->SetExtend(gfxPattern::EXTEND_PAD);
|
|
|
|
|
|
|
|
gfxRect r(0, 0, mBounds.width, mBounds.height);
|
|
|
|
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);
|
2010-07-22 01:17:33 +04:00
|
|
|
aContext->Fill();
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(InConstruction() || InDrawing(), "wrong phase");
|
|
|
|
if (HasShadowManager()) {
|
|
|
|
ShadowLayerForwarder::Mutated(Hold(aLayer));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BasicShadowLayerManager::BeginTransactionWithTarget(gfxContext* aTarget)
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(mKeepAlive.IsEmpty(), "uncommitted txn?");
|
|
|
|
if (HasShadowManager()) {
|
|
|
|
ShadowLayerForwarder::BeginTransaction();
|
|
|
|
}
|
|
|
|
BasicLayerManager::BeginTransactionWithTarget(aTarget);
|
|
|
|
}
|
|
|
|
|
2010-12-10 22:32:52 +03:00
|
|
|
bool
|
2010-07-22 01:17:33 +04:00
|
|
|
BasicShadowLayerManager::EndTransaction(DrawThebesLayerCallback aCallback,
|
|
|
|
void* aCallbackData)
|
|
|
|
{
|
2010-12-10 22:32:52 +03:00
|
|
|
if (!BasicLayerManager::EndTransaction(aCallback, aCallbackData)) {
|
|
|
|
NS_WARNING("Failed to finish transaction, clear mKeepAlive");
|
|
|
|
if (HasShadowManager())
|
|
|
|
ShadowLayerForwarder::EndTransaction(nsnull);
|
|
|
|
mKeepAlive.Clear();
|
|
|
|
#ifdef DEBUG
|
|
|
|
mPhase = PHASE_NONE;
|
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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(
|
|
|
|
obs.newBackBuffer(),
|
2010-11-05 10:17:07 +03:00
|
|
|
obs.newValidRegion(), obs.newXResolution(), obs.newYResolution(),
|
|
|
|
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();
|
2010-09-14 09:23:08 +04:00
|
|
|
const SurfaceDescriptor& descr = obs.newBackBuffer();
|
|
|
|
BasicShadowableLayer* layer = GetBasicShadowable(obs);
|
|
|
|
if (layer->SupportsSurfaceDescriptor()) {
|
|
|
|
layer->SetBackBuffer(descr);
|
|
|
|
} else {
|
|
|
|
if (SurfaceDescriptor::TShmem != descr.type()) {
|
|
|
|
NS_RUNTIMEABORT("non-Shmem surface sent to a layer that expected one!");
|
|
|
|
}
|
|
|
|
nsRefPtr<gfxASurface> imageSurf = OpenDescriptor(descr);
|
|
|
|
layer->SetBackBufferImage(
|
|
|
|
static_cast<gfxSharedImageSurface*>(imageSurf.get()));
|
|
|
|
}
|
2010-07-22 01:17:33 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
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-12-10 22:32:52 +03:00
|
|
|
return true;
|
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;
|
|
|
|
}
|
|
|
|
#endif // MOZ_IPC
|
|
|
|
|
2010-03-01 10:56:18 +03:00
|
|
|
}
|
|
|
|
}
|