2010-05-17 21:04:22 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2010-02-28 23:56:18 -08: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>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#ifndef GFX_LAYERS_H
|
|
|
|
#define GFX_LAYERS_H
|
|
|
|
|
|
|
|
#include "gfxTypes.h"
|
2010-05-17 21:04:22 -07:00
|
|
|
#include "gfxASurface.h"
|
2010-02-28 23:56:18 -08:00
|
|
|
#include "nsRegion.h"
|
|
|
|
#include "nsPoint.h"
|
|
|
|
#include "nsRect.h"
|
2010-04-01 11:05:40 -07:00
|
|
|
#include "nsISupportsImpl.h"
|
|
|
|
#include "nsAutoPtr.h"
|
2010-03-01 15:08:28 -08:00
|
|
|
#include "gfx3DMatrix.h"
|
2010-05-12 17:56:11 -07:00
|
|
|
#include "gfxColor.h"
|
2010-05-17 21:04:22 -07:00
|
|
|
#include "gfxPattern.h"
|
2010-02-28 23:56:18 -08:00
|
|
|
|
2010-07-21 11:06:33 -07:00
|
|
|
#if defined(DEBUG) || defined(PR_LOGGING)
|
2010-07-21 11:06:33 -07:00
|
|
|
# include <stdio.h> // FILE
|
|
|
|
# include "prlog.h"
|
2010-07-21 11:06:33 -07:00
|
|
|
# define MOZ_LAYERS_HAVE_LOG
|
2010-07-21 11:06:33 -07:00
|
|
|
# define MOZ_LAYERS_LOG(_args) \
|
|
|
|
PR_LOG(LayerManager::GetLog(), PR_LOG_DEBUG, _args)
|
|
|
|
#else
|
|
|
|
struct PRLogModuleInfo;
|
|
|
|
# define MOZ_LAYERS_LOG(_args)
|
|
|
|
#endif // if defined(DEBUG) || defined(PR_LOGGING)
|
2010-07-21 11:06:33 -07:00
|
|
|
|
2010-02-28 23:56:18 -08:00
|
|
|
class gfxContext;
|
|
|
|
class nsPaintEvent;
|
|
|
|
|
|
|
|
namespace mozilla {
|
2010-05-17 21:04:22 -07:00
|
|
|
namespace gl {
|
|
|
|
class GLContext;
|
|
|
|
}
|
|
|
|
|
2010-02-28 23:56:18 -08:00
|
|
|
namespace layers {
|
|
|
|
|
|
|
|
class Layer;
|
|
|
|
class ThebesLayer;
|
|
|
|
class ContainerLayer;
|
2010-03-01 15:09:35 -08:00
|
|
|
class ImageLayer;
|
2010-05-12 17:56:11 -07:00
|
|
|
class ColorLayer;
|
2010-03-01 15:09:35 -08:00
|
|
|
class ImageContainer;
|
2010-05-17 21:04:22 -07:00
|
|
|
class CanvasLayer;
|
2010-10-13 15:55:45 -07:00
|
|
|
class ShadowLayer;
|
2010-07-21 14:17:33 -07:00
|
|
|
class SpecificLayerAttributes;
|
2010-02-28 23:56:18 -08:00
|
|
|
|
2010-09-03 13:10:45 -07:00
|
|
|
/**
|
|
|
|
* The viewport and displayport metrics for the painted frame at the
|
|
|
|
* time of a layer-tree transaction. These metrics are especially
|
|
|
|
* useful for shadow layers, because the metrics values are updated
|
|
|
|
* atomically with new pixels.
|
|
|
|
*/
|
|
|
|
struct FrameMetrics {
|
|
|
|
FrameMetrics()
|
|
|
|
: mViewportSize(0, 0)
|
|
|
|
, mViewportScrollOffset(0, 0)
|
|
|
|
{}
|
|
|
|
|
|
|
|
// Default copy ctor and operator= are fine
|
|
|
|
|
|
|
|
PRBool operator==(const FrameMetrics& aOther) const
|
|
|
|
{
|
|
|
|
return (mViewportSize == aOther.mViewportSize &&
|
|
|
|
mViewportScrollOffset == aOther.mViewportScrollOffset &&
|
|
|
|
mDisplayPort == aOther.mDisplayPort);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool IsDefault() const
|
|
|
|
{
|
|
|
|
return (FrameMetrics() == *this);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIntSize mViewportSize;
|
|
|
|
nsIntPoint mViewportScrollOffset;
|
|
|
|
nsIntRect mDisplayPort;
|
|
|
|
};
|
|
|
|
|
2010-07-21 11:06:33 -07:00
|
|
|
#define MOZ_LAYER_DECL_NAME(n, e) \
|
|
|
|
virtual const char* Name() const { return n; } \
|
|
|
|
virtual LayerType GetType() const { return e; }
|
2010-07-01 18:01:09 -07:00
|
|
|
|
2010-09-02 02:18:39 -07:00
|
|
|
/**
|
|
|
|
* Base class for userdata objects attached to layers and layer managers.
|
|
|
|
*/
|
|
|
|
class THEBES_API LayerUserData {
|
|
|
|
public:
|
|
|
|
virtual ~LayerUserData() {}
|
|
|
|
};
|
|
|
|
|
2010-02-28 23:56:18 -08:00
|
|
|
/*
|
|
|
|
* Motivation: For truly smooth animation and video playback, we need to
|
|
|
|
* be able to compose frames and render them on a dedicated thread (i.e.
|
|
|
|
* off the main thread where DOM manipulation, script execution and layout
|
|
|
|
* induce difficult-to-bound latency). This requires Gecko to construct
|
|
|
|
* some kind of persistent scene structure (graph or tree) that can be
|
|
|
|
* safely transmitted across threads. We have other scenarios (e.g. mobile
|
|
|
|
* browsing) where retaining some rendered data between paints is desired
|
|
|
|
* for performance, so again we need a retained scene structure.
|
|
|
|
*
|
|
|
|
* Our retained scene structure is a layer tree. Each layer represents
|
|
|
|
* content which can be composited onto a destination surface; the root
|
|
|
|
* layer is usually composited into a window, and non-root layers are
|
|
|
|
* composited into their parent layers. Layers have attributes (e.g.
|
|
|
|
* opacity and clipping) that influence their compositing.
|
|
|
|
*
|
|
|
|
* We want to support a variety of layer implementations, including
|
|
|
|
* a simple "immediate mode" implementation that doesn't retain any
|
|
|
|
* rendered data between paints (i.e. uses cairo in just the way that
|
|
|
|
* Gecko used it before layers were introduced). But we also don't want
|
|
|
|
* to have bifurcated "layers"/"non-layers" rendering paths in Gecko.
|
|
|
|
* Therefore the layers API is carefully designed to permit maximally
|
|
|
|
* efficient implementation in an "immediate mode" style. See the
|
|
|
|
* BasicLayerManager for such an implementation.
|
|
|
|
*/
|
|
|
|
|
2010-09-02 02:18:39 -07:00
|
|
|
/**
|
|
|
|
* Helper class to manage user data for layers and LayerManagers.
|
|
|
|
*/
|
|
|
|
class THEBES_API LayerUserDataSet {
|
|
|
|
public:
|
|
|
|
LayerUserDataSet() : mKey(nsnull) {}
|
|
|
|
|
|
|
|
void Set(void* aKey, LayerUserData* aValue)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!mKey || mKey == aKey,
|
|
|
|
"Multiple LayerUserData objects not supported");
|
|
|
|
mKey = aKey;
|
|
|
|
mValue = aValue;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* This can be used anytime. Ownership passes to the caller!
|
|
|
|
*/
|
|
|
|
LayerUserData* Remove(void* aKey)
|
|
|
|
{
|
|
|
|
if (mKey == aKey) {
|
|
|
|
mKey = nsnull;
|
|
|
|
LayerUserData* d = mValue.forget();
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* This getter can be used anytime.
|
|
|
|
*/
|
|
|
|
PRBool Has(void* aKey)
|
|
|
|
{
|
|
|
|
return mKey == aKey;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* This getter can be used anytime. Ownership is retained by this object.
|
|
|
|
*/
|
|
|
|
LayerUserData* Get(void* aKey)
|
|
|
|
{
|
|
|
|
return mKey == aKey ? mValue.get() : nsnull;
|
|
|
|
}
|
|
|
|
|
2010-12-06 18:05:25 -08:00
|
|
|
/**
|
|
|
|
* Clear out current user data.
|
|
|
|
*/
|
|
|
|
void Clear()
|
|
|
|
{
|
|
|
|
mKey = nsnull;
|
|
|
|
mValue = nsnull;
|
|
|
|
}
|
|
|
|
|
2010-09-02 02:18:39 -07:00
|
|
|
private:
|
|
|
|
void* mKey;
|
|
|
|
nsAutoPtr<LayerUserData> mValue;
|
|
|
|
};
|
|
|
|
|
2010-02-28 23:56:18 -08:00
|
|
|
/**
|
|
|
|
* A LayerManager controls a tree of layers. All layers in the tree
|
|
|
|
* must use the same LayerManager.
|
|
|
|
*
|
|
|
|
* All modifications to a layer tree must happen inside a transaction.
|
|
|
|
* Only the state of the layer tree at the end of a transaction is
|
|
|
|
* rendered. Transactions cannot be nested
|
|
|
|
*
|
|
|
|
* Each transaction has two phases:
|
|
|
|
* 1) Construction: layers are created, inserted, removed and have
|
|
|
|
* properties set on them in this phase.
|
|
|
|
* BeginTransaction and BeginTransactionWithTarget start a transaction in
|
|
|
|
* the Construction phase. When the client has finished constructing the layer
|
|
|
|
* tree, it should call EndConstruction() to enter the drawing phase.
|
|
|
|
* 2) Drawing: ThebesLayers are rendered into in this phase, in tree
|
|
|
|
* order. When the client has finished drawing into the ThebesLayers, it should
|
|
|
|
* call EndTransaction to complete the transaction.
|
|
|
|
*
|
|
|
|
* All layer API calls happen on the main thread.
|
|
|
|
*
|
|
|
|
* Layers are refcounted. The layer manager holds a reference to the
|
|
|
|
* root layer, and each container layer holds a reference to its children.
|
|
|
|
*/
|
|
|
|
class THEBES_API LayerManager {
|
2010-04-01 11:05:40 -07:00
|
|
|
NS_INLINE_DECL_REFCOUNTING(LayerManager)
|
2010-02-28 23:56:18 -08:00
|
|
|
|
|
|
|
public:
|
2010-03-30 11:58:37 -07:00
|
|
|
enum LayersBackend {
|
2010-12-30 23:40:19 -08:00
|
|
|
LAYERS_NONE = 0,
|
|
|
|
LAYERS_BASIC,
|
2010-05-24 08:28:51 -07:00
|
|
|
LAYERS_OPENGL,
|
2010-09-30 15:53:51 -07:00
|
|
|
LAYERS_D3D9,
|
2010-12-30 23:40:19 -08:00
|
|
|
LAYERS_D3D10,
|
|
|
|
LAYERS_LAST
|
2010-03-30 11:58:37 -07:00
|
|
|
};
|
|
|
|
|
2010-11-08 01:06:15 -08:00
|
|
|
LayerManager() : mDestroyed(PR_FALSE), mSnapEffectiveTransforms(PR_TRUE)
|
2010-07-21 11:06:33 -07:00
|
|
|
{
|
|
|
|
InitLog();
|
|
|
|
}
|
2010-02-28 23:56:18 -08:00
|
|
|
virtual ~LayerManager() {}
|
|
|
|
|
2010-08-06 22:09:17 -07:00
|
|
|
/**
|
|
|
|
* Release layers and resources held by this layer manager, and mark
|
|
|
|
* it as destroyed. Should do any cleanup necessary in preparation
|
|
|
|
* for its widget going away. After this call, only user data calls
|
|
|
|
* are valid on the layer manager.
|
|
|
|
*/
|
2010-12-06 18:05:25 -08:00
|
|
|
virtual void Destroy() { mDestroyed = PR_TRUE; mUserData.Clear(); }
|
2010-08-06 22:09:17 -07:00
|
|
|
PRBool IsDestroyed() { return mDestroyed; }
|
|
|
|
|
2010-02-28 23:56:18 -08:00
|
|
|
/**
|
|
|
|
* Start a new transaction. Nested transactions are not allowed so
|
|
|
|
* there must be no transaction currently in progress.
|
|
|
|
* This transaction will update the state of the window from which
|
|
|
|
* this LayerManager was obtained.
|
|
|
|
*/
|
|
|
|
virtual void BeginTransaction() = 0;
|
|
|
|
/**
|
|
|
|
* Start a new transaction. Nested transactions are not allowed so
|
|
|
|
* there must be no transaction currently in progress.
|
|
|
|
* This transaction will render the contents of the layer tree to
|
|
|
|
* the given target context. The rendering will be complete when
|
|
|
|
* EndTransaction returns.
|
|
|
|
*/
|
|
|
|
virtual void BeginTransactionWithTarget(gfxContext* aTarget) = 0;
|
|
|
|
/**
|
2010-05-20 20:20:48 -07:00
|
|
|
* Function called to draw the contents of each ThebesLayer.
|
|
|
|
* aRegionToDraw contains the region that needs to be drawn.
|
2010-03-03 13:37:04 -08:00
|
|
|
* This would normally be a subregion of the visible region.
|
|
|
|
* The callee must draw all of aRegionToDraw. Drawing outside
|
|
|
|
* aRegionToDraw will be clipped out or ignored.
|
2010-05-20 20:20:48 -07:00
|
|
|
* The callee must draw all of aRegionToDraw.
|
2010-07-15 14:07:51 -07:00
|
|
|
* This region is relative to 0,0 in the ThebesLayer.
|
2010-05-20 20:20:48 -07:00
|
|
|
*
|
2010-03-03 13:37:04 -08:00
|
|
|
* aRegionToInvalidate contains a region whose contents have been
|
|
|
|
* changed by the layer manager and which must therefore be invalidated.
|
2010-07-15 14:07:51 -07:00
|
|
|
* For example, this could be non-empty if a retained layer internally
|
|
|
|
* switches from RGBA to RGB or back ... we might want to repaint it to
|
2010-03-03 13:37:04 -08:00
|
|
|
* consistently use subpixel-AA or not.
|
2010-07-15 14:07:51 -07:00
|
|
|
* This region is relative to 0,0 in the ThebesLayer.
|
|
|
|
* aRegionToInvalidate may contain areas that are outside
|
|
|
|
* aRegionToDraw; the callee must ensure that these areas are repainted
|
|
|
|
* in the current layer manager transaction or in a later layer
|
|
|
|
* manager transaction.
|
2010-03-03 13:37:04 -08:00
|
|
|
*
|
2010-05-20 20:20:48 -07:00
|
|
|
* aContext must not be used after the call has returned.
|
|
|
|
* We guarantee that buffered contents in the visible
|
|
|
|
* region are valid once drawing is complete.
|
2010-07-15 14:07:51 -07:00
|
|
|
*
|
|
|
|
* The origin of aContext is 0,0 in the ThebesLayer.
|
2010-02-28 23:56:18 -08:00
|
|
|
*/
|
2010-05-20 20:20:48 -07:00
|
|
|
typedef void (* DrawThebesLayerCallback)(ThebesLayer* aLayer,
|
|
|
|
gfxContext* aContext,
|
|
|
|
const nsIntRegion& aRegionToDraw,
|
2010-03-03 13:37:04 -08:00
|
|
|
const nsIntRegion& aRegionToInvalidate,
|
2010-05-20 20:20:48 -07:00
|
|
|
void* aCallbackData);
|
2010-02-28 23:56:18 -08:00
|
|
|
/**
|
2010-05-20 20:20:48 -07:00
|
|
|
* Finish the construction phase of the transaction, perform the
|
|
|
|
* drawing phase, and end the transaction.
|
|
|
|
* During the drawing phase, all ThebesLayers in the tree are
|
|
|
|
* drawn in tree order, exactly once each, except for those layers
|
|
|
|
* where it is known that the visible region is empty.
|
2010-02-28 23:56:18 -08:00
|
|
|
*/
|
2010-12-13 16:14:07 -08:00
|
|
|
virtual void EndTransaction(DrawThebesLayerCallback aCallback,
|
2010-05-20 20:20:48 -07:00
|
|
|
void* aCallbackData) = 0;
|
2010-02-28 23:56:18 -08:00
|
|
|
|
2010-12-26 22:12:17 -08:00
|
|
|
/**
|
|
|
|
* Attempts to perform an "empty transaction", i.e., a BeginTransaction()
|
|
|
|
* followed by no changes to the layer tree and an EndTransaction with no
|
|
|
|
* ThebesLayer drawing callback. This will only work if no ThebesLayers
|
|
|
|
* need to be updated (i.e. the visible region of each ThebesLayer is already
|
|
|
|
* fully retained). Since this cannot be predicted in advance,
|
|
|
|
* DoEmptyTransaction is allowed to fail and return false. When
|
|
|
|
* DoEmptyTransaction fails it must be immediately (within the same paint
|
|
|
|
* event) followed by a normal BeginTransaction/EndTransaction pair.
|
|
|
|
*/
|
|
|
|
virtual bool DoEmptyTransaction()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-11-08 01:06:15 -08:00
|
|
|
PRBool IsSnappingEffectiveTransforms() { return mSnapEffectiveTransforms; }
|
|
|
|
|
2010-02-28 23:56:18 -08:00
|
|
|
/**
|
|
|
|
* CONSTRUCTION PHASE ONLY
|
|
|
|
* Set the root layer.
|
|
|
|
*/
|
|
|
|
virtual void SetRoot(Layer* aLayer) = 0;
|
2010-05-31 16:29:37 -07:00
|
|
|
/**
|
|
|
|
* Can be called anytime
|
|
|
|
*/
|
|
|
|
Layer* GetRoot() { return mRoot; }
|
2010-02-28 23:56:18 -08:00
|
|
|
|
2010-07-21 14:17:33 -07:00
|
|
|
/**
|
|
|
|
* CONSTRUCTION PHASE ONLY
|
|
|
|
* Called when a managee has mutated.
|
|
|
|
*/
|
|
|
|
virtual void Mutated(Layer* aLayer) { }
|
|
|
|
|
2010-02-28 23:56:18 -08:00
|
|
|
/**
|
|
|
|
* CONSTRUCTION PHASE ONLY
|
|
|
|
* Create a ThebesLayer for this manager's layer tree.
|
|
|
|
*/
|
|
|
|
virtual already_AddRefed<ThebesLayer> CreateThebesLayer() = 0;
|
|
|
|
/**
|
|
|
|
* CONSTRUCTION PHASE ONLY
|
|
|
|
* Create a ContainerLayer for this manager's layer tree.
|
|
|
|
*/
|
|
|
|
virtual already_AddRefed<ContainerLayer> CreateContainerLayer() = 0;
|
2010-03-01 15:09:35 -08:00
|
|
|
/**
|
|
|
|
* CONSTRUCTION PHASE ONLY
|
|
|
|
* Create an ImageLayer for this manager's layer tree.
|
|
|
|
*/
|
|
|
|
virtual already_AddRefed<ImageLayer> CreateImageLayer() = 0;
|
2010-05-12 17:56:11 -07:00
|
|
|
/**
|
|
|
|
* CONSTRUCTION PHASE ONLY
|
|
|
|
* Create a ColorLayer for this manager's layer tree.
|
|
|
|
*/
|
|
|
|
virtual already_AddRefed<ColorLayer> CreateColorLayer() = 0;
|
2010-05-17 21:04:22 -07:00
|
|
|
/**
|
|
|
|
* CONSTRUCTION PHASE ONLY
|
|
|
|
* Create a CanvasLayer for this manager's layer tree.
|
|
|
|
*/
|
|
|
|
virtual already_AddRefed<CanvasLayer> CreateCanvasLayer() = 0;
|
2010-03-01 15:09:35 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Can be called anytime
|
|
|
|
*/
|
|
|
|
virtual already_AddRefed<ImageContainer> CreateImageContainer() = 0;
|
2010-03-30 11:58:37 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Type of layer manager his is. This is to be used sparsely in order to
|
|
|
|
* avoid a lot of Layers backend specific code. It should be used only when
|
|
|
|
* Layers backend specific functionality is necessary.
|
|
|
|
*/
|
|
|
|
virtual LayersBackend GetBackendType() = 0;
|
2010-09-07 20:27:29 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a layer which is optimized for inter-operating with this layer
|
|
|
|
* manager.
|
|
|
|
*/
|
|
|
|
virtual already_AddRefed<gfxASurface>
|
|
|
|
CreateOptimalSurface(const gfxIntSize &aSize,
|
|
|
|
gfxASurface::gfxImageFormat imageFormat);
|
2010-05-31 16:29:37 -07:00
|
|
|
|
2010-09-03 11:01:05 -07:00
|
|
|
/**
|
|
|
|
* Return the name of the layer manager's backend.
|
|
|
|
*/
|
|
|
|
virtual void GetBackendName(nsAString& aName) = 0;
|
|
|
|
|
2010-09-02 02:18:39 -07:00
|
|
|
/**
|
|
|
|
* This setter can be used anytime. The user data for all keys is
|
|
|
|
* initially null. Ownership pases to the layer manager.
|
|
|
|
*/
|
|
|
|
void SetUserData(void* aKey, LayerUserData* aData)
|
|
|
|
{ mUserData.Set(aKey, aData); }
|
|
|
|
/**
|
|
|
|
* This can be used anytime. Ownership passes to the caller!
|
|
|
|
*/
|
|
|
|
nsAutoPtr<LayerUserData> RemoveUserData(void* aKey)
|
|
|
|
{ nsAutoPtr<LayerUserData> d(mUserData.Remove(aKey)); return d; }
|
|
|
|
/**
|
|
|
|
* This getter can be used anytime.
|
|
|
|
*/
|
|
|
|
PRBool HasUserData(void* aKey)
|
|
|
|
{ return mUserData.Has(aKey); }
|
|
|
|
/**
|
|
|
|
* This getter can be used anytime. Ownership is retained by the layer
|
|
|
|
* manager.
|
|
|
|
*/
|
|
|
|
LayerUserData* GetUserData(void* aKey)
|
|
|
|
{ return mUserData.Get(aKey); }
|
2010-05-31 16:29:37 -07:00
|
|
|
|
2010-07-21 11:06:33 -07:00
|
|
|
// We always declare the following logging symbols, because it's
|
|
|
|
// extremely tricky to conditionally declare them. However, for
|
|
|
|
// ifndef MOZ_LAYERS_HAVE_LOG builds, they only have trivial
|
|
|
|
// definitions in Layers.cpp.
|
2010-07-21 11:06:33 -07:00
|
|
|
virtual const char* Name() const { return "???"; }
|
2010-07-21 11:06:33 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Dump information about this layer manager and its managed tree to
|
|
|
|
* aFile, which defaults to stderr.
|
|
|
|
*/
|
|
|
|
void Dump(FILE* aFile=NULL, const char* aPrefix="");
|
|
|
|
/**
|
|
|
|
* Dump information about just this layer manager itself to aFile,
|
|
|
|
* which defaults to stderr.
|
|
|
|
*/
|
|
|
|
void DumpSelf(FILE* aFile=NULL, const char* aPrefix="");
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Log information about this layer manager and its managed tree to
|
|
|
|
* the NSPR log (if enabled for "Layers").
|
|
|
|
*/
|
|
|
|
void Log(const char* aPrefix="");
|
|
|
|
/**
|
|
|
|
* Log information about just this layer manager itself to the NSPR
|
|
|
|
* log (if enabled for "Layers").
|
|
|
|
*/
|
|
|
|
void LogSelf(const char* aPrefix="");
|
|
|
|
|
|
|
|
static bool IsLogEnabled();
|
|
|
|
static PRLogModuleInfo* GetLog() { return sLog; }
|
2010-07-21 11:06:33 -07:00
|
|
|
|
2010-05-31 16:29:37 -07:00
|
|
|
protected:
|
|
|
|
nsRefPtr<Layer> mRoot;
|
2010-09-02 02:18:39 -07:00
|
|
|
LayerUserDataSet mUserData;
|
2010-08-06 22:09:17 -07:00
|
|
|
PRPackedBool mDestroyed;
|
2010-11-08 01:06:15 -08:00
|
|
|
PRPackedBool mSnapEffectiveTransforms;
|
2010-07-21 11:06:33 -07:00
|
|
|
|
|
|
|
// Print interesting information about this into aTo. Internally
|
|
|
|
// used to implement Dump*() and Log*().
|
|
|
|
virtual nsACString& PrintInfo(nsACString& aTo, const char* aPrefix);
|
|
|
|
|
|
|
|
static void InitLog();
|
|
|
|
static PRLogModuleInfo* sLog;
|
2010-02-28 23:56:18 -08:00
|
|
|
};
|
|
|
|
|
2010-05-20 20:20:48 -07:00
|
|
|
class ThebesLayer;
|
|
|
|
|
2010-02-28 23:56:18 -08:00
|
|
|
/**
|
|
|
|
* A Layer represents anything that can be rendered onto a destination
|
|
|
|
* surface.
|
|
|
|
*/
|
|
|
|
class THEBES_API Layer {
|
2010-04-01 11:05:40 -07:00
|
|
|
NS_INLINE_DECL_REFCOUNTING(Layer)
|
2010-02-28 23:56:18 -08:00
|
|
|
|
|
|
|
public:
|
2010-07-01 18:01:09 -07:00
|
|
|
enum LayerType {
|
|
|
|
TYPE_THEBES,
|
|
|
|
TYPE_CONTAINER,
|
|
|
|
TYPE_IMAGE,
|
|
|
|
TYPE_COLOR,
|
2010-07-21 14:17:33 -07:00
|
|
|
TYPE_CANVAS,
|
|
|
|
TYPE_SHADOW
|
2010-07-01 18:01:09 -07:00
|
|
|
};
|
|
|
|
|
2010-02-28 23:56:18 -08:00
|
|
|
virtual ~Layer() {}
|
|
|
|
|
|
|
|
/**
|
2010-08-06 22:09:17 -07:00
|
|
|
* Returns the LayerManager this Layer belongs to. Note that the layer
|
|
|
|
* manager might be in a destroyed state, at which point it's only
|
|
|
|
* valid to set/get user data from it.
|
2010-02-28 23:56:18 -08:00
|
|
|
*/
|
|
|
|
LayerManager* Manager() { return mManager; }
|
|
|
|
|
2010-09-02 02:18:40 -07:00
|
|
|
enum {
|
|
|
|
/**
|
|
|
|
* If this is set, the caller is promising that by the end of this
|
|
|
|
* transaction the entire visible region (as specified by
|
|
|
|
* SetVisibleRegion) will be filled with opaque content.
|
|
|
|
*/
|
|
|
|
CONTENT_OPAQUE = 0x01,
|
|
|
|
/**
|
2010-12-19 17:26:14 -08:00
|
|
|
* If this is set, the caller is notifying that the contents of this layer
|
|
|
|
* require per-component alpha for optimal fidelity. However, there is no
|
|
|
|
* guarantee that component alpha will be supported for this layer at
|
|
|
|
* paint time.
|
|
|
|
* This should never be set at the same time as CONTENT_OPAQUE.
|
2010-09-02 02:18:40 -07:00
|
|
|
*/
|
2010-12-19 17:26:14 -08:00
|
|
|
CONTENT_COMPONENT_ALPHA = 0x02
|
2010-09-02 02:18:40 -07:00
|
|
|
};
|
2010-02-28 23:56:18 -08:00
|
|
|
/**
|
|
|
|
* CONSTRUCTION PHASE ONLY
|
2010-09-02 02:18:40 -07:00
|
|
|
* This lets layout make some promises about what will be drawn into the
|
|
|
|
* visible region of the ThebesLayer. This enables internal quality
|
|
|
|
* and performance optimizations.
|
2010-02-28 23:56:18 -08:00
|
|
|
*/
|
2010-09-02 02:18:40 -07:00
|
|
|
void SetContentFlags(PRUint32 aFlags)
|
2010-07-21 14:17:33 -07:00
|
|
|
{
|
2010-12-19 17:26:14 -08:00
|
|
|
NS_ASSERTION((aFlags & (CONTENT_OPAQUE | CONTENT_COMPONENT_ALPHA)) !=
|
|
|
|
(CONTENT_OPAQUE | CONTENT_COMPONENT_ALPHA),
|
|
|
|
"Can't be opaque and require component alpha");
|
2010-09-02 02:18:40 -07:00
|
|
|
mContentFlags = aFlags;
|
2010-07-21 14:17:33 -07:00
|
|
|
Mutated();
|
|
|
|
}
|
2010-02-28 23:56:18 -08:00
|
|
|
/**
|
|
|
|
* CONSTRUCTION PHASE ONLY
|
2010-09-17 12:29:52 -07:00
|
|
|
* Tell this layer which region will be visible. The visible region
|
|
|
|
* is a region which contains all the contents of the layer that can
|
|
|
|
* actually affect the rendering of the window. It can exclude areas
|
|
|
|
* that are covered by opaque contents of other layers, and it can
|
|
|
|
* exclude areas where this layer simply contains no content at all.
|
|
|
|
* (This can be an overapproximation to the "true" visible region.)
|
|
|
|
*
|
|
|
|
* There is no general guarantee that drawing outside the bounds of the
|
|
|
|
* visible region will be ignored. So if a layer draws outside the bounds
|
|
|
|
* of its visible region, it needs to ensure that what it draws is valid.
|
2010-02-28 23:56:18 -08:00
|
|
|
*/
|
2010-07-21 14:17:33 -07:00
|
|
|
virtual void SetVisibleRegion(const nsIntRegion& aRegion)
|
|
|
|
{
|
|
|
|
mVisibleRegion = aRegion;
|
|
|
|
Mutated();
|
|
|
|
}
|
2010-02-28 23:56:18 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* CONSTRUCTION PHASE ONLY
|
|
|
|
* Set the opacity which will be applied to this layer as it
|
|
|
|
* is composited to the destination.
|
|
|
|
*/
|
2010-07-21 14:17:33 -07:00
|
|
|
void SetOpacity(float aOpacity)
|
|
|
|
{
|
|
|
|
mOpacity = aOpacity;
|
|
|
|
Mutated();
|
|
|
|
}
|
2010-02-28 23:56:18 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* CONSTRUCTION PHASE ONLY
|
|
|
|
* Set a clip rect which will be applied to this layer as it is
|
|
|
|
* composited to the destination. The coordinates are relative to
|
|
|
|
* the parent layer (i.e. the contents of this layer
|
|
|
|
* are transformed before this clip rect is applied).
|
|
|
|
* For the root layer, the coordinates are relative to the widget,
|
|
|
|
* in device pixels.
|
|
|
|
* If aRect is null no clipping will be performed.
|
|
|
|
*/
|
|
|
|
void SetClipRect(const nsIntRect* aRect)
|
|
|
|
{
|
|
|
|
mUseClipRect = aRect != nsnull;
|
|
|
|
if (aRect) {
|
|
|
|
mClipRect = *aRect;
|
|
|
|
}
|
2010-07-21 14:17:33 -07:00
|
|
|
Mutated();
|
2010-02-28 23:56:18 -08:00
|
|
|
}
|
2010-08-06 22:09:17 -07:00
|
|
|
|
2010-02-28 23:56:18 -08:00
|
|
|
/**
|
|
|
|
* CONSTRUCTION PHASE ONLY
|
|
|
|
* Set a clip rect which will be applied to this layer as it is
|
|
|
|
* composited to the destination. The coordinates are relative to
|
|
|
|
* the parent layer (i.e. the contents of this layer
|
|
|
|
* are transformed before this clip rect is applied).
|
|
|
|
* For the root layer, the coordinates are relative to the widget,
|
|
|
|
* in device pixels.
|
|
|
|
* The provided rect is intersected with any existing clip rect.
|
|
|
|
*/
|
|
|
|
void IntersectClipRect(const nsIntRect& aRect)
|
|
|
|
{
|
|
|
|
if (mUseClipRect) {
|
|
|
|
mClipRect.IntersectRect(mClipRect, aRect);
|
|
|
|
} else {
|
|
|
|
mUseClipRect = PR_TRUE;
|
|
|
|
mClipRect = aRect;
|
|
|
|
}
|
2010-07-21 14:17:33 -07:00
|
|
|
Mutated();
|
2010-02-28 23:56:18 -08:00
|
|
|
}
|
|
|
|
|
2010-03-01 15:08:28 -08:00
|
|
|
/**
|
|
|
|
* CONSTRUCTION PHASE ONLY
|
|
|
|
* Tell this layer what its transform should be. The transformation
|
|
|
|
* is applied when compositing the layer into its parent container.
|
|
|
|
* XXX Currently only transformations corresponding to 2D affine transforms
|
|
|
|
* are supported.
|
|
|
|
*/
|
2010-07-21 14:17:33 -07:00
|
|
|
void SetTransform(const gfx3DMatrix& aMatrix)
|
|
|
|
{
|
|
|
|
mTransform = aMatrix;
|
|
|
|
Mutated();
|
|
|
|
}
|
2010-03-01 15:08:28 -08:00
|
|
|
|
2010-02-28 23:56:18 -08:00
|
|
|
// These getters can be used anytime.
|
|
|
|
float GetOpacity() { return mOpacity; }
|
|
|
|
const nsIntRect* GetClipRect() { return mUseClipRect ? &mClipRect : nsnull; }
|
2010-09-02 02:18:40 -07:00
|
|
|
PRUint32 GetContentFlags() { return mContentFlags; }
|
2010-05-31 16:29:37 -07:00
|
|
|
const nsIntRegion& GetVisibleRegion() { return mVisibleRegion; }
|
2010-02-28 23:56:18 -08:00
|
|
|
ContainerLayer* GetParent() { return mParent; }
|
|
|
|
Layer* GetNextSibling() { return mNextSibling; }
|
|
|
|
Layer* GetPrevSibling() { return mPrevSibling; }
|
|
|
|
virtual Layer* GetFirstChild() { return nsnull; }
|
2010-11-16 15:33:56 -08:00
|
|
|
virtual Layer* GetLastChild() { return nsnull; }
|
2010-03-01 15:08:28 -08:00
|
|
|
const gfx3DMatrix& GetTransform() { return mTransform; }
|
2010-02-28 23:56:18 -08:00
|
|
|
|
2010-07-21 14:17:33 -07:00
|
|
|
/**
|
|
|
|
* DRAWING PHASE ONLY
|
|
|
|
*
|
|
|
|
* Write layer-subtype-specific attributes into aAttrs. Used to
|
|
|
|
* synchronize layer attributes to their shadows'.
|
|
|
|
*/
|
|
|
|
virtual void FillSpecificAttributes(SpecificLayerAttributes& aAttrs) { }
|
|
|
|
|
2010-07-21 11:06:33 -07:00
|
|
|
// Returns true if it's OK to save the contents of aLayer in an
|
|
|
|
// opaque surface (a surface without an alpha channel).
|
|
|
|
// If we can use a surface without an alpha channel, we should, because
|
|
|
|
// it will often make painting of antialiased text faster and higher
|
|
|
|
// quality.
|
|
|
|
PRBool CanUseOpaqueSurface();
|
|
|
|
|
2010-09-02 02:18:39 -07:00
|
|
|
/**
|
|
|
|
* This setter can be used anytime. The user data for all keys is
|
|
|
|
* initially null. Ownership pases to the layer manager.
|
|
|
|
*/
|
|
|
|
void SetUserData(void* aKey, LayerUserData* aData)
|
|
|
|
{ mUserData.Set(aKey, aData); }
|
|
|
|
/**
|
|
|
|
* This can be used anytime. Ownership passes to the caller!
|
|
|
|
*/
|
|
|
|
nsAutoPtr<LayerUserData> RemoveUserData(void* aKey)
|
|
|
|
{ nsAutoPtr<LayerUserData> d(mUserData.Remove(aKey)); return d; }
|
|
|
|
/**
|
|
|
|
* This getter can be used anytime.
|
|
|
|
*/
|
|
|
|
PRBool HasUserData(void* aKey)
|
|
|
|
{ return mUserData.Has(aKey); }
|
|
|
|
/**
|
|
|
|
* This getter can be used anytime. Ownership is retained by the layer
|
|
|
|
* manager.
|
|
|
|
*/
|
|
|
|
LayerUserData* GetUserData(void* aKey)
|
|
|
|
{ return mUserData.Get(aKey); }
|
2010-05-20 20:20:48 -07:00
|
|
|
|
2010-08-20 16:24:41 -07:00
|
|
|
/**
|
|
|
|
* |Disconnect()| is used by layers hooked up over IPC. It may be
|
|
|
|
* called at any time, and may not be called at all. Using an
|
|
|
|
* IPC-enabled layer after Destroy() (drawing etc.) results in a
|
|
|
|
* safe no-op; no crashy or uaf etc.
|
|
|
|
*
|
|
|
|
* XXX: this interface is essentially LayerManager::Destroy, but at
|
|
|
|
* Layer granularity. It might be beneficial to unify them.
|
|
|
|
*/
|
|
|
|
virtual void Disconnect() {}
|
|
|
|
|
2010-05-20 20:20:48 -07:00
|
|
|
/**
|
|
|
|
* Dynamic downcast to a Thebes layer. Returns null if this is not
|
|
|
|
* a ThebesLayer.
|
|
|
|
*/
|
|
|
|
virtual ThebesLayer* AsThebesLayer() { return nsnull; }
|
2010-07-01 18:01:09 -07:00
|
|
|
|
2010-10-13 15:55:45 -07:00
|
|
|
/**
|
|
|
|
* Dynamic cast to a ShadowLayer. Return null if this is not a
|
|
|
|
* ShadowLayer. Can be used anytime.
|
|
|
|
*/
|
|
|
|
virtual ShadowLayer* AsShadowLayer() { return nsnull; }
|
|
|
|
|
|
|
|
// These getters can be used anytime. They return the effective
|
|
|
|
// values that should be used when drawing this layer to screen,
|
|
|
|
// accounting for this layer possibly being a shadow.
|
|
|
|
const nsIntRect* GetEffectiveClipRect();
|
|
|
|
const nsIntRegion& GetEffectiveVisibleRegion();
|
2010-11-08 01:06:15 -08:00
|
|
|
/**
|
|
|
|
* Returns the product of the opacities of this layer and all ancestors up
|
|
|
|
* to and excluding the nearest ancestor that has UseIntermediateSurface() set.
|
|
|
|
*/
|
|
|
|
float GetEffectiveOpacity();
|
|
|
|
/**
|
|
|
|
* This returns the effective transform computed by
|
|
|
|
* ComputeEffectiveTransforms. Typically this is a transform that transforms
|
|
|
|
* this layer all the way to some intermediate surface or destination
|
|
|
|
* surface. For non-BasicLayers this will be a transform to the nearest
|
|
|
|
* ancestor with UseIntermediateSurface() (or to the root, if there is no
|
|
|
|
* such ancestor), but for BasicLayers it's different.
|
|
|
|
*/
|
|
|
|
const gfx3DMatrix& GetEffectiveTransform() const { return mEffectiveTransform; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param aTransformToSurface the composition of the transforms
|
|
|
|
* from the parent layer (if any) to the destination pixel grid.
|
|
|
|
*
|
|
|
|
* Computes mEffectiveTransform for this layer and all its descendants.
|
|
|
|
* mEffectiveTransform transforms this layer up to the destination
|
|
|
|
* pixel grid (whatever aTransformToSurface is relative to).
|
|
|
|
*
|
|
|
|
* We promise that when this is called on a layer, all ancestor layers
|
|
|
|
* have already had ComputeEffectiveTransforms called.
|
|
|
|
*/
|
|
|
|
virtual void ComputeEffectiveTransforms(const gfx3DMatrix& aTransformToSurface) = 0;
|
2010-10-13 15:55:45 -07:00
|
|
|
|
2010-07-21 11:06:33 -07:00
|
|
|
virtual const char* Name() const =0;
|
|
|
|
virtual LayerType GetType() const =0;
|
2010-07-01 18:01:09 -07:00
|
|
|
|
2010-02-28 23:56:18 -08:00
|
|
|
/**
|
|
|
|
* Only the implementation should call this. This is per-implementation
|
|
|
|
* private data. Normally, all layers with a given layer manager
|
|
|
|
* use the same type of ImplData.
|
|
|
|
*/
|
|
|
|
void* ImplData() { return mImplData; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Only the implementation should use these methods.
|
|
|
|
*/
|
|
|
|
void SetParent(ContainerLayer* aParent) { mParent = aParent; }
|
|
|
|
void SetNextSibling(Layer* aSibling) { mNextSibling = aSibling; }
|
|
|
|
void SetPrevSibling(Layer* aSibling) { mPrevSibling = aSibling; }
|
|
|
|
|
2010-07-21 11:06:33 -07:00
|
|
|
/**
|
|
|
|
* Dump information about this layer manager and its managed tree to
|
|
|
|
* aFile, which defaults to stderr.
|
|
|
|
*/
|
|
|
|
void Dump(FILE* aFile=NULL, const char* aPrefix="");
|
|
|
|
/**
|
|
|
|
* Dump information about just this layer manager itself to aFile,
|
|
|
|
* which defaults to stderr.
|
|
|
|
*/
|
|
|
|
void DumpSelf(FILE* aFile=NULL, const char* aPrefix="");
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Log information about this layer manager and its managed tree to
|
|
|
|
* the NSPR log (if enabled for "Layers").
|
|
|
|
*/
|
|
|
|
void Log(const char* aPrefix="");
|
|
|
|
/**
|
|
|
|
* Log information about just this layer manager itself to the NSPR
|
|
|
|
* log (if enabled for "Layers").
|
|
|
|
*/
|
|
|
|
void LogSelf(const char* aPrefix="");
|
|
|
|
|
|
|
|
static bool IsLogEnabled() { return LayerManager::IsLogEnabled(); }
|
|
|
|
|
2010-02-28 23:56:18 -08:00
|
|
|
protected:
|
|
|
|
Layer(LayerManager* aManager, void* aImplData) :
|
|
|
|
mManager(aManager),
|
|
|
|
mParent(nsnull),
|
|
|
|
mNextSibling(nsnull),
|
|
|
|
mPrevSibling(nsnull),
|
|
|
|
mImplData(aImplData),
|
|
|
|
mOpacity(1.0),
|
2010-12-19 17:26:14 -08:00
|
|
|
mContentFlags(0),
|
2010-09-02 02:18:40 -07:00
|
|
|
mUseClipRect(PR_FALSE)
|
2010-02-28 23:56:18 -08:00
|
|
|
{}
|
|
|
|
|
2010-07-21 14:17:33 -07:00
|
|
|
void Mutated() { mManager->Mutated(this); }
|
|
|
|
|
2010-07-21 11:06:33 -07:00
|
|
|
// Print interesting information about this into aTo. Internally
|
|
|
|
// used to implement Dump*() and Log*(). If subclasses have
|
|
|
|
// additional interesting properties, they should override this with
|
|
|
|
// an implementation that first calls the base implementation then
|
|
|
|
// appends additional info to aTo.
|
|
|
|
virtual nsACString& PrintInfo(nsACString& aTo, const char* aPrefix);
|
|
|
|
|
2010-11-08 01:06:15 -08:00
|
|
|
/**
|
|
|
|
* Returns the local transform for this layer: either mTransform or,
|
|
|
|
* for shadow layers, GetShadowTransform()
|
|
|
|
*/
|
|
|
|
const gfx3DMatrix& GetLocalTransform();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Computes a tweaked version of aTransform that snaps a point or a rectangle
|
|
|
|
* to pixel boundaries. Snapping is only performed if this layer's
|
|
|
|
* layer manager has enabled snapping (which is the default).
|
|
|
|
* @param aSnapRect a rectangle whose edges should be snapped to pixel
|
|
|
|
* boundaries in the destination surface. If the rectangle is empty,
|
|
|
|
* then the snapping process should preserve the scale factors of the
|
|
|
|
* transform matrix
|
|
|
|
* @param aResidualTransform a transform to apply before mEffectiveTransform
|
|
|
|
* in order to get the results to completely match aTransform
|
|
|
|
*/
|
|
|
|
gfx3DMatrix SnapTransform(const gfx3DMatrix& aTransform,
|
|
|
|
const gfxRect& aSnapRect,
|
|
|
|
gfxMatrix* aResidualTransform);
|
|
|
|
|
2010-02-28 23:56:18 -08:00
|
|
|
LayerManager* mManager;
|
|
|
|
ContainerLayer* mParent;
|
|
|
|
Layer* mNextSibling;
|
|
|
|
Layer* mPrevSibling;
|
|
|
|
void* mImplData;
|
2010-09-02 02:18:39 -07:00
|
|
|
LayerUserDataSet mUserData;
|
2010-05-31 16:29:37 -07:00
|
|
|
nsIntRegion mVisibleRegion;
|
2010-03-01 15:08:28 -08:00
|
|
|
gfx3DMatrix mTransform;
|
2010-11-08 01:06:15 -08:00
|
|
|
gfx3DMatrix mEffectiveTransform;
|
2010-02-28 23:56:18 -08:00
|
|
|
float mOpacity;
|
|
|
|
nsIntRect mClipRect;
|
2010-09-02 02:18:40 -07:00
|
|
|
PRUint32 mContentFlags;
|
2010-02-28 23:56:18 -08:00
|
|
|
PRPackedBool mUseClipRect;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A Layer which we can draw into using Thebes. It is a conceptually
|
|
|
|
* infinite surface, but each ThebesLayer has an associated "valid region"
|
|
|
|
* of contents that it is currently storing, which is finite. ThebesLayer
|
|
|
|
* implementations can store content between paints.
|
|
|
|
*
|
|
|
|
* ThebesLayers are rendered into during the drawing phase of a transaction.
|
|
|
|
*
|
|
|
|
* Currently the contents of a ThebesLayer are in the device output color
|
|
|
|
* space.
|
|
|
|
*/
|
|
|
|
class THEBES_API ThebesLayer : public Layer {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* CONSTRUCTION PHASE ONLY
|
|
|
|
* Tell this layer that the content in some region has changed and
|
|
|
|
* will need to be repainted. This area is removed from the valid
|
|
|
|
* region.
|
|
|
|
*/
|
|
|
|
virtual void InvalidateRegion(const nsIntRegion& aRegion) = 0;
|
|
|
|
|
2010-05-31 16:29:37 -07:00
|
|
|
/**
|
|
|
|
* Can be used anytime
|
|
|
|
*/
|
2010-09-03 13:10:46 -07:00
|
|
|
const nsIntRegion& GetValidRegion() const { return mValidRegion; }
|
|
|
|
float GetXResolution() const { return mXResolution; }
|
|
|
|
float GetYResolution() const { return mYResolution; }
|
2010-05-31 16:29:37 -07:00
|
|
|
|
2010-05-20 20:20:48 -07:00
|
|
|
virtual ThebesLayer* AsThebesLayer() { return this; }
|
2010-02-28 23:56:18 -08:00
|
|
|
|
2010-07-21 11:06:33 -07:00
|
|
|
MOZ_LAYER_DECL_NAME("ThebesLayer", TYPE_THEBES)
|
2010-07-01 18:01:09 -07:00
|
|
|
|
2010-11-08 01:06:15 -08:00
|
|
|
virtual void ComputeEffectiveTransforms(const gfx3DMatrix& aTransformToSurface)
|
|
|
|
{
|
|
|
|
// The default implementation just snaps 0,0 to pixels.
|
|
|
|
gfx3DMatrix idealTransform = GetLocalTransform()*aTransformToSurface;
|
|
|
|
mEffectiveTransform = SnapTransform(idealTransform, gfxRect(0, 0, 0, 0), nsnull);
|
|
|
|
}
|
|
|
|
|
2010-02-28 23:56:18 -08:00
|
|
|
protected:
|
|
|
|
ThebesLayer(LayerManager* aManager, void* aImplData)
|
2010-09-03 13:10:46 -07:00
|
|
|
: Layer(aManager, aImplData)
|
|
|
|
, mValidRegion()
|
|
|
|
, mXResolution(1.0)
|
|
|
|
, mYResolution(1.0)
|
2010-12-19 17:26:14 -08:00
|
|
|
{
|
|
|
|
mContentFlags = 0; // Clear NO_TEXT, NO_TEXT_OVER_TRANSPARENT
|
|
|
|
}
|
2010-05-31 16:29:37 -07:00
|
|
|
|
2010-07-21 11:06:33 -07:00
|
|
|
virtual nsACString& PrintInfo(nsACString& aTo, const char* aPrefix);
|
|
|
|
|
2010-05-31 16:29:37 -07:00
|
|
|
nsIntRegion mValidRegion;
|
2010-09-03 13:10:46 -07:00
|
|
|
// Resolution values tell this to paint its content scaled by
|
|
|
|
// <aXResolution, aYResolution>, into a backing buffer with
|
|
|
|
// dimensions scaled the same. A non-1.0 resolution also tells this
|
|
|
|
// to set scaling factors that compensate for the re-paint
|
|
|
|
// resolution when rendering itself to render targets
|
|
|
|
//
|
|
|
|
// Resolution doesn't affect the visible region, valid region, or
|
|
|
|
// re-painted regions at all. It only affects how scalable thebes
|
|
|
|
// content is rasterized to device pixels.
|
|
|
|
//
|
|
|
|
// Setting the resolution isn't part of the public ThebesLayer API
|
|
|
|
// because it's backend-specific, and it doesn't necessarily make
|
|
|
|
// sense for all backends to fully support it.
|
|
|
|
float mXResolution;
|
|
|
|
float mYResolution;
|
2010-02-28 23:56:18 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A Layer which other layers render into. It holds references to its
|
|
|
|
* children.
|
|
|
|
*/
|
|
|
|
class THEBES_API ContainerLayer : public Layer {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* CONSTRUCTION PHASE ONLY
|
|
|
|
* Insert aChild into the child list of this container. aChild must
|
|
|
|
* not be currently in any child list or the root for the layer manager.
|
|
|
|
* If aAfter is non-null, it must be a child of this container and
|
|
|
|
* we insert after that layer. If it's null we insert at the start.
|
|
|
|
*/
|
|
|
|
virtual void InsertAfter(Layer* aChild, Layer* aAfter) = 0;
|
|
|
|
/**
|
|
|
|
* CONSTRUCTION PHASE ONLY
|
|
|
|
* Remove aChild from the child list of this container. aChild must
|
|
|
|
* be a child of this container.
|
|
|
|
*/
|
|
|
|
virtual void RemoveChild(Layer* aChild) = 0;
|
|
|
|
|
2010-09-03 13:10:45 -07:00
|
|
|
/**
|
|
|
|
* CONSTRUCTION PHASE ONLY
|
|
|
|
* Set the (sub)document metrics used to render the Layer subtree
|
|
|
|
* rooted at this.
|
|
|
|
*/
|
|
|
|
void SetFrameMetrics(const FrameMetrics& aFrameMetrics)
|
|
|
|
{
|
|
|
|
mFrameMetrics = aFrameMetrics;
|
|
|
|
}
|
|
|
|
|
|
|
|
// These getters can be used anytime.
|
|
|
|
|
2010-02-28 23:56:18 -08:00
|
|
|
virtual Layer* GetFirstChild() { return mFirstChild; }
|
2010-11-16 15:33:56 -08:00
|
|
|
virtual Layer* GetLastChild() { return mLastChild; }
|
2010-09-03 13:10:45 -07:00
|
|
|
const FrameMetrics& GetFrameMetrics() { return mFrameMetrics; }
|
2010-02-28 23:56:18 -08:00
|
|
|
|
2010-07-21 11:06:33 -07:00
|
|
|
MOZ_LAYER_DECL_NAME("ContainerLayer", TYPE_CONTAINER)
|
2010-07-01 18:01:09 -07:00
|
|
|
|
2010-11-08 01:06:15 -08:00
|
|
|
/**
|
|
|
|
* ContainerLayer backends need to override ComputeEffectiveTransforms
|
|
|
|
* since the decision about whether to use a temporary surface for the
|
|
|
|
* container is backend-specific. ComputeEffectiveTransforms must also set
|
|
|
|
* mUseIntermediateSurface.
|
|
|
|
*/
|
|
|
|
virtual void ComputeEffectiveTransforms(const gfx3DMatrix& aTransformToSurface) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Call this only after ComputeEffectiveTransforms has been invoked
|
|
|
|
* on this layer.
|
|
|
|
* Returns true if this will use an intermediate surface. This is largely
|
|
|
|
* backend-dependent, but it affects the operation of GetEffectiveOpacity().
|
|
|
|
*/
|
|
|
|
PRBool UseIntermediateSurface() { return mUseIntermediateSurface; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if this container has more than one non-empty child
|
|
|
|
*/
|
|
|
|
PRBool HasMultipleChildren();
|
|
|
|
|
2010-02-28 23:56:18 -08:00
|
|
|
protected:
|
|
|
|
ContainerLayer(LayerManager* aManager, void* aImplData)
|
|
|
|
: Layer(aManager, aImplData),
|
2010-11-08 01:06:15 -08:00
|
|
|
mFirstChild(nsnull),
|
2010-11-16 15:33:56 -08:00
|
|
|
mLastChild(nsnull),
|
2010-11-08 01:06:15 -08:00
|
|
|
mUseIntermediateSurface(PR_FALSE)
|
2010-12-19 17:26:14 -08:00
|
|
|
{
|
|
|
|
mContentFlags = 0; // Clear NO_TEXT, NO_TEXT_OVER_TRANSPARENT
|
|
|
|
}
|
2010-02-28 23:56:18 -08:00
|
|
|
|
2010-11-08 01:06:15 -08:00
|
|
|
/**
|
|
|
|
* A default implementation of ComputeEffectiveTransforms for use by OpenGL
|
|
|
|
* and D3D.
|
|
|
|
*/
|
|
|
|
void DefaultComputeEffectiveTransforms(const gfx3DMatrix& aTransformToSurface);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loops over the children calling ComputeEffectiveTransforms on them.
|
|
|
|
*/
|
|
|
|
void ComputeEffectiveTransformsForChildren(const gfx3DMatrix& aTransformToSurface);
|
|
|
|
|
2010-09-03 13:10:45 -07:00
|
|
|
virtual nsACString& PrintInfo(nsACString& aTo, const char* aPrefix);
|
|
|
|
|
2010-02-28 23:56:18 -08:00
|
|
|
Layer* mFirstChild;
|
2010-11-16 15:33:56 -08:00
|
|
|
Layer* mLastChild;
|
2010-09-03 13:10:45 -07:00
|
|
|
FrameMetrics mFrameMetrics;
|
2010-11-08 01:06:15 -08:00
|
|
|
PRPackedBool mUseIntermediateSurface;
|
2010-02-28 23:56:18 -08:00
|
|
|
};
|
|
|
|
|
2010-05-12 17:56:11 -07:00
|
|
|
/**
|
2010-05-12 17:56:11 -07:00
|
|
|
* A Layer which just renders a solid color in its visible region. It actually
|
|
|
|
* can fill any area that contains the visible region, so if you need to
|
|
|
|
* restrict the area filled, set a clip region on this layer.
|
2010-05-12 17:56:11 -07:00
|
|
|
*/
|
|
|
|
class THEBES_API ColorLayer : public Layer {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* CONSTRUCTION PHASE ONLY
|
|
|
|
* Set the color of the layer.
|
|
|
|
*/
|
|
|
|
virtual void SetColor(const gfxRGBA& aColor)
|
|
|
|
{
|
|
|
|
mColor = aColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This getter can be used anytime.
|
|
|
|
virtual const gfxRGBA& GetColor() { return mColor; }
|
|
|
|
|
2010-07-21 11:06:33 -07:00
|
|
|
MOZ_LAYER_DECL_NAME("ColorLayer", TYPE_COLOR)
|
2010-07-01 18:01:09 -07:00
|
|
|
|
2010-11-08 01:06:15 -08:00
|
|
|
virtual void ComputeEffectiveTransforms(const gfx3DMatrix& aTransformToSurface)
|
|
|
|
{
|
|
|
|
// Snap 0,0 to pixel boundaries, no extra internal transform.
|
|
|
|
gfx3DMatrix idealTransform = GetLocalTransform()*aTransformToSurface;
|
|
|
|
mEffectiveTransform = SnapTransform(idealTransform, gfxRect(0, 0, 0, 0), nsnull);
|
|
|
|
}
|
|
|
|
|
2010-05-12 17:56:11 -07:00
|
|
|
protected:
|
|
|
|
ColorLayer(LayerManager* aManager, void* aImplData)
|
|
|
|
: Layer(aManager, aImplData),
|
|
|
|
mColor(0.0, 0.0, 0.0, 0.0)
|
|
|
|
{}
|
|
|
|
|
2010-07-21 11:06:33 -07:00
|
|
|
virtual nsACString& PrintInfo(nsACString& aTo, const char* aPrefix);
|
|
|
|
|
2010-05-12 17:56:11 -07:00
|
|
|
gfxRGBA mColor;
|
|
|
|
};
|
|
|
|
|
2010-05-17 21:04:22 -07:00
|
|
|
/**
|
|
|
|
* A Layer for HTML Canvas elements. It's backed by either a
|
|
|
|
* gfxASurface or a GLContext (for WebGL layers), and has some control
|
|
|
|
* for intelligent updating from the source if necessary (for example,
|
|
|
|
* if hardware compositing is not available, for reading from the GL
|
|
|
|
* buffer into an image surface that we can layer composite.)
|
|
|
|
*
|
|
|
|
* After Initialize is called, the underlying canvas Surface/GLContext
|
|
|
|
* must not be modified during a layer transaction.
|
|
|
|
*/
|
|
|
|
class THEBES_API CanvasLayer : public Layer {
|
|
|
|
public:
|
|
|
|
struct Data {
|
|
|
|
Data()
|
|
|
|
: mSurface(nsnull), mGLContext(nsnull),
|
|
|
|
mGLBufferIsPremultiplied(PR_FALSE)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
/* One of these two must be specified, but never both */
|
|
|
|
gfxASurface* mSurface; // a gfx Surface for the canvas contents
|
|
|
|
mozilla::gl::GLContext* mGLContext; // a GL PBuffer Context
|
|
|
|
|
|
|
|
/* The size of the canvas content */
|
|
|
|
nsIntSize mSize;
|
|
|
|
|
|
|
|
/* Whether the GLContext contains premultiplied alpha
|
|
|
|
* values in the framebuffer or not. Defaults to FALSE.
|
|
|
|
*/
|
|
|
|
PRPackedBool mGLBufferIsPremultiplied;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* CONSTRUCTION PHASE ONLY
|
|
|
|
* Initialize this CanvasLayer with the given data. The data must
|
|
|
|
* have either mSurface or mGLContext initialized (but not both), as
|
|
|
|
* well as mSize.
|
|
|
|
*
|
|
|
|
* This must only be called once.
|
|
|
|
*/
|
|
|
|
virtual void Initialize(const Data& aData) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* CONSTRUCTION PHASE ONLY
|
|
|
|
* Notify this CanvasLayer that the rectangle given by aRect
|
|
|
|
* has been updated, and any work that needs to be done
|
|
|
|
* to bring the contents from the Surface/GLContext to the
|
|
|
|
* Layer in preparation for compositing should be performed.
|
|
|
|
*/
|
|
|
|
virtual void Updated(const nsIntRect& aRect) = 0;
|
|
|
|
|
2010-05-17 21:04:22 -07:00
|
|
|
/**
|
|
|
|
* CONSTRUCTION PHASE ONLY
|
|
|
|
* Set the filter used to resample this image (if necessary).
|
|
|
|
*/
|
|
|
|
void SetFilter(gfxPattern::GraphicsFilter aFilter) { mFilter = aFilter; }
|
|
|
|
gfxPattern::GraphicsFilter GetFilter() const { return mFilter; }
|
|
|
|
|
2010-07-21 11:06:33 -07:00
|
|
|
MOZ_LAYER_DECL_NAME("CanvasLayer", TYPE_CANVAS)
|
2010-07-01 18:01:09 -07:00
|
|
|
|
2010-11-08 01:06:15 -08:00
|
|
|
virtual void ComputeEffectiveTransforms(const gfx3DMatrix& aTransformToSurface)
|
|
|
|
{
|
|
|
|
// Snap our local transform first, and snap the inherited transform as well.
|
|
|
|
// This makes our snapping equivalent to what would happen if our content
|
|
|
|
// was drawn into a ThebesLayer (gfxContext would snap using the local
|
|
|
|
// transform, then we'd snap again when compositing the ThebesLayer).
|
|
|
|
mEffectiveTransform =
|
|
|
|
SnapTransform(GetLocalTransform(), gfxRect(0, 0, mBounds.width, mBounds.height),
|
|
|
|
nsnull)*
|
|
|
|
SnapTransform(aTransformToSurface, gfxRect(0, 0, 0, 0), nsnull);
|
|
|
|
}
|
|
|
|
|
2010-05-17 21:04:22 -07:00
|
|
|
protected:
|
|
|
|
CanvasLayer(LayerManager* aManager, void* aImplData)
|
2010-05-17 21:04:22 -07:00
|
|
|
: Layer(aManager, aImplData), mFilter(gfxPattern::FILTER_GOOD) {}
|
|
|
|
|
2010-07-21 11:06:33 -07:00
|
|
|
virtual nsACString& PrintInfo(nsACString& aTo, const char* aPrefix);
|
|
|
|
|
2010-11-08 01:06:15 -08:00
|
|
|
/**
|
|
|
|
* 0, 0, canvaswidth, canvasheight
|
|
|
|
*/
|
|
|
|
nsIntRect mBounds;
|
2010-05-17 21:04:22 -07:00
|
|
|
gfxPattern::GraphicsFilter mFilter;
|
2010-05-17 21:04:22 -07:00
|
|
|
};
|
|
|
|
|
2010-02-28 23:56:18 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* GFX_LAYERS_H */
|