2010-05-20 20:20:48 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2012-05-21 04:12:37 -07:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-05-20 20:20:48 -07:00
|
|
|
|
|
|
|
#ifndef FRAMELAYERBUILDER_H_
|
|
|
|
#define FRAMELAYERBUILDER_H_
|
|
|
|
|
2010-07-15 14:07:51 -07:00
|
|
|
#include "nsTHashtable.h"
|
|
|
|
#include "nsHashKeys.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsRegion.h"
|
|
|
|
#include "nsIFrame.h"
|
2012-09-24 13:31:30 -07:00
|
|
|
#include "ImageLayers.h"
|
2013-03-04 01:55:59 -08:00
|
|
|
#include "DisplayItemClip.h"
|
2010-05-20 20:20:48 -07:00
|
|
|
|
|
|
|
class nsDisplayListBuilder;
|
|
|
|
class nsDisplayList;
|
|
|
|
class nsDisplayItem;
|
2010-07-15 14:07:46 -07:00
|
|
|
class gfxContext;
|
2013-08-19 15:55:18 -07:00
|
|
|
class nsDisplayItemGeometry;
|
2010-05-20 20:20:48 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
2012-07-18 09:31:40 -07:00
|
|
|
namespace layers {
|
|
|
|
class ContainerLayer;
|
2012-08-20 21:06:46 -07:00
|
|
|
class LayerManager;
|
2013-11-06 11:10:49 -08:00
|
|
|
class BasicLayerManager;
|
2012-07-18 09:31:40 -07:00
|
|
|
class ThebesLayer;
|
|
|
|
}
|
2010-05-20 20:20:48 -07:00
|
|
|
|
2012-07-17 10:03:51 -07:00
|
|
|
class FrameLayerBuilder;
|
2012-08-28 22:47:15 -07:00
|
|
|
class LayerManagerData;
|
2012-07-17 10:03:51 -07:00
|
|
|
|
2010-07-15 14:08:05 -07:00
|
|
|
enum LayerState {
|
|
|
|
LAYER_NONE,
|
|
|
|
LAYER_INACTIVE,
|
2011-03-15 16:20:19 -07:00
|
|
|
LAYER_ACTIVE,
|
|
|
|
// Force an active layer even if it causes incorrect rendering, e.g.
|
|
|
|
// when the layer has rounded rect clips.
|
2011-04-11 13:53:01 -07:00
|
|
|
LAYER_ACTIVE_FORCE,
|
|
|
|
// Special layer that is metadata only.
|
2012-07-17 10:03:51 -07:00
|
|
|
LAYER_ACTIVE_EMPTY,
|
|
|
|
// Inactive style layer for rendering SVG effects.
|
|
|
|
LAYER_SVG_EFFECTS
|
2010-07-15 14:08:05 -07:00
|
|
|
};
|
|
|
|
|
2012-07-14 00:49:05 -07:00
|
|
|
class RefCountedRegion : public RefCounted<RefCountedRegion> {
|
|
|
|
public:
|
2012-08-23 04:14:47 -07:00
|
|
|
RefCountedRegion() : mIsInfinite(false) {}
|
2012-07-14 00:49:05 -07:00
|
|
|
nsRegion mRegion;
|
2012-08-23 04:14:47 -07:00
|
|
|
bool mIsInfinite;
|
2012-07-14 00:49:05 -07:00
|
|
|
};
|
|
|
|
|
2010-07-15 14:07:51 -07:00
|
|
|
/**
|
2012-08-28 22:47:15 -07:00
|
|
|
* The FrameLayerBuilder is responsible for converting display lists
|
|
|
|
* into layer trees. Every LayerManager needs a unique FrameLayerBuilder
|
|
|
|
* to build layers.
|
2010-07-15 14:07:51 -07:00
|
|
|
*
|
|
|
|
* The most important API in this class is BuildContainerLayerFor. This
|
|
|
|
* method takes a display list as input and constructs a ContainerLayer
|
|
|
|
* with child layers that render the contents of the display list. It
|
2012-09-28 04:19:39 -07:00
|
|
|
* records the relationship between frames and layers.
|
2010-07-15 14:07:51 -07:00
|
|
|
*
|
|
|
|
* That data enables us to retain layer trees. When constructing a
|
|
|
|
* ContainerLayer, we first check to see if there's an existing
|
|
|
|
* ContainerLayer for the same frame that can be recycled. If we recycle
|
|
|
|
* it, we also try to reuse its existing ThebesLayer children to render
|
|
|
|
* the display items without layers of their own. The idea is that by
|
|
|
|
* recycling layers deterministically, we can ensure that when nothing
|
|
|
|
* changes in a display list, we will reuse the existing layers without
|
|
|
|
* changes.
|
|
|
|
*
|
|
|
|
* We expose a GetLeafLayerFor method that can be called by display items
|
|
|
|
* that make their own layers (e.g. canvas and video); this method
|
|
|
|
* locates the last layer used to render the display item, if any, and
|
|
|
|
* return it as a candidate for recycling.
|
|
|
|
*
|
|
|
|
* FrameLayerBuilder sets up ThebesLayers so that 0,0 in the Thebes layer
|
|
|
|
* corresponds to the (pixel-snapped) top-left of the aActiveScrolledRoot.
|
|
|
|
* It sets up ContainerLayers so that 0,0 in the container layer
|
2012-09-28 04:19:39 -07:00
|
|
|
* corresponds to the snapped top-left of the display item reference frame.
|
2011-06-22 05:11:27 -07:00
|
|
|
*
|
|
|
|
* When we construct a container layer, we know the transform that will be
|
|
|
|
* applied to the layer. If the transform scales the content, we can get
|
|
|
|
* better results when intermediate buffers are used by pushing some scale
|
|
|
|
* from the container's transform down to the children. For ThebesLayer
|
|
|
|
* children, the scaling can be achieved by changing the size of the layer
|
|
|
|
* and drawing into it with increased or decreased resolution. By convention,
|
|
|
|
* integer types (nsIntPoint/nsIntSize/nsIntRect/nsIntRegion) are all in layer
|
|
|
|
* coordinates, post-scaling, whereas appunit types are all pre-scaling.
|
2010-07-15 14:07:51 -07:00
|
|
|
*/
|
2012-08-28 22:48:15 -07:00
|
|
|
class FrameLayerBuilder : public layers::LayerUserData {
|
2010-05-20 20:20:48 -07:00
|
|
|
public:
|
2012-08-20 21:06:46 -07:00
|
|
|
typedef layers::ContainerLayer ContainerLayer;
|
|
|
|
typedef layers::Layer Layer;
|
2010-07-15 14:07:51 -07:00
|
|
|
typedef layers::ThebesLayer ThebesLayer;
|
2012-09-24 13:31:30 -07:00
|
|
|
typedef layers::ImageLayer ImageLayer;
|
2010-07-15 14:07:51 -07:00
|
|
|
typedef layers::LayerManager LayerManager;
|
2013-11-06 11:10:49 -08:00
|
|
|
typedef layers::BasicLayerManager BasicLayerManager;
|
2010-07-15 14:07:51 -07:00
|
|
|
|
|
|
|
FrameLayerBuilder() :
|
2012-07-30 07:20:58 -07:00
|
|
|
mRetainingManager(nullptr),
|
2011-10-17 07:59:28 -07:00
|
|
|
mDetectedDOMModification(false),
|
2012-07-22 20:00:36 -07:00
|
|
|
mInvalidateAllLayers(false),
|
|
|
|
mContainerLayerGeneration(0),
|
|
|
|
mMaxContainerLayerGeneration(0)
|
2010-07-15 14:07:51 -07:00
|
|
|
{
|
2012-07-17 10:03:51 -07:00
|
|
|
MOZ_COUNT_CTOR(FrameLayerBuilder);
|
2010-07-15 14:07:51 -07:00
|
|
|
}
|
2012-07-17 10:03:51 -07:00
|
|
|
~FrameLayerBuilder()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(FrameLayerBuilder);
|
|
|
|
}
|
2010-07-15 14:07:51 -07:00
|
|
|
|
2012-06-25 19:43:30 -07:00
|
|
|
static void Shutdown();
|
|
|
|
|
2012-08-20 21:06:46 -07:00
|
|
|
void Init(nsDisplayListBuilder* aBuilder, LayerManager* aManager);
|
2010-09-17 12:09:08 -07:00
|
|
|
|
2010-07-15 14:07:51 -07:00
|
|
|
/**
|
2011-01-19 00:27:54 -08:00
|
|
|
* Call this to notify that we have just started a transaction on the
|
2010-07-15 14:08:11 -07:00
|
|
|
* retained layer manager aManager.
|
2010-07-15 14:07:51 -07:00
|
|
|
*/
|
2011-01-19 00:27:54 -08:00
|
|
|
void DidBeginRetainedLayerTransaction(LayerManager* aManager);
|
2010-07-15 14:07:51 -07:00
|
|
|
|
|
|
|
/**
|
2012-08-28 22:47:15 -07:00
|
|
|
* Call this just before we end a transaction.
|
2010-07-15 14:08:11 -07:00
|
|
|
*/
|
2012-08-28 22:47:15 -07:00
|
|
|
void WillEndTransaction();
|
2010-07-15 14:08:11 -07:00
|
|
|
|
|
|
|
/**
|
2012-08-28 22:47:15 -07:00
|
|
|
* Call this after we end a transaction.
|
2010-07-15 14:07:51 -07:00
|
|
|
*/
|
2012-08-28 22:47:15 -07:00
|
|
|
void DidEndTransaction();
|
2010-05-20 20:20:48 -07:00
|
|
|
|
2011-06-22 05:11:27 -07:00
|
|
|
struct ContainerParameters {
|
2011-06-22 05:11:28 -07:00
|
|
|
ContainerParameters() :
|
2013-03-21 19:17:29 -07:00
|
|
|
mXScale(1), mYScale(1), mAncestorClipRect(nullptr),
|
2012-01-11 03:26:33 -08:00
|
|
|
mInTransformedSubtree(false), mInActiveTransformedSubtree(false),
|
|
|
|
mDisableSubpixelAntialiasingInDescendants(false)
|
|
|
|
{}
|
2011-06-22 05:11:27 -07:00
|
|
|
ContainerParameters(float aXScale, float aYScale) :
|
2013-03-21 19:17:29 -07:00
|
|
|
mXScale(aXScale), mYScale(aYScale), mAncestorClipRect(nullptr),
|
2012-01-11 03:26:33 -08:00
|
|
|
mInTransformedSubtree(false), mInActiveTransformedSubtree(false),
|
|
|
|
mDisableSubpixelAntialiasingInDescendants(false)
|
|
|
|
{}
|
2011-06-22 05:11:28 -07:00
|
|
|
ContainerParameters(float aXScale, float aYScale,
|
2012-09-16 15:25:33 -07:00
|
|
|
const nsIntPoint& aOffset,
|
2011-06-22 05:11:28 -07:00
|
|
|
const ContainerParameters& aParent) :
|
2013-03-21 19:17:29 -07:00
|
|
|
mXScale(aXScale), mYScale(aYScale), mAncestorClipRect(nullptr),
|
2012-09-16 15:25:33 -07:00
|
|
|
mOffset(aOffset),
|
2011-06-22 05:11:28 -07:00
|
|
|
mInTransformedSubtree(aParent.mInTransformedSubtree),
|
2012-01-11 03:26:33 -08:00
|
|
|
mInActiveTransformedSubtree(aParent.mInActiveTransformedSubtree),
|
|
|
|
mDisableSubpixelAntialiasingInDescendants(aParent.mDisableSubpixelAntialiasingInDescendants)
|
|
|
|
{}
|
2011-06-22 05:11:27 -07:00
|
|
|
float mXScale, mYScale;
|
2013-03-21 19:17:29 -07:00
|
|
|
/**
|
|
|
|
* An ancestor clip rect that can be applied to restrict the visibility
|
|
|
|
* of this container. Null if none available.
|
|
|
|
*/
|
|
|
|
const nsIntRect* mAncestorClipRect;
|
2012-09-16 15:25:33 -07:00
|
|
|
/**
|
|
|
|
* An offset to append to the transform set on all child layers created.
|
|
|
|
*/
|
|
|
|
nsIntPoint mOffset;
|
|
|
|
|
2011-06-22 05:11:28 -07:00
|
|
|
bool mInTransformedSubtree;
|
|
|
|
bool mInActiveTransformedSubtree;
|
2012-01-11 03:26:33 -08:00
|
|
|
bool mDisableSubpixelAntialiasingInDescendants;
|
2012-04-10 04:24:18 -07:00
|
|
|
/**
|
|
|
|
* When this is false, ThebesLayer coordinates are drawn to with an integer
|
|
|
|
* translation and the scale in mXScale/mYScale.
|
|
|
|
*/
|
|
|
|
bool AllowResidualTranslation()
|
|
|
|
{
|
|
|
|
// If we're in a transformed subtree, but no ancestor transform is actively
|
|
|
|
// changing, we'll use the residual translation when drawing into the
|
|
|
|
// ThebesLayer to ensure that snapping exactly matches the ideal transform.
|
|
|
|
return mInTransformedSubtree && !mInActiveTransformedSubtree;
|
|
|
|
}
|
2011-06-22 05:11:27 -07:00
|
|
|
};
|
2013-03-21 19:17:29 -07:00
|
|
|
enum {
|
|
|
|
CONTAINER_NOT_CLIPPED_BY_ANCESTORS = 0x01
|
|
|
|
};
|
2010-05-20 20:20:48 -07:00
|
|
|
/**
|
2010-07-15 14:07:51 -07:00
|
|
|
* Build a container layer for a display item that contains a child
|
|
|
|
* list, either reusing an existing one or creating a new one. It
|
|
|
|
* sets the container layer children to layers which together render
|
|
|
|
* the contents of the display list. It reuses existing layers from
|
|
|
|
* the retained layer manager if possible.
|
2010-05-20 20:20:48 -07:00
|
|
|
* aContainer may be null, in which case we construct a root layer.
|
2010-07-15 14:07:51 -07:00
|
|
|
* This gets called by display list code. It calls BuildLayer on the
|
|
|
|
* items in the display list, making items with their own layers
|
|
|
|
* children of the new container, and assigning all other items to
|
|
|
|
* ThebesLayer children created and managed by the FrameLayerBuilder.
|
|
|
|
* Returns a layer with clip rect cleared; it is the
|
2011-02-22 21:38:09 -08:00
|
|
|
* caller's responsibility to add any clip rect. The visible region
|
|
|
|
* is set based on what's in the layer.
|
2011-06-22 05:11:27 -07:00
|
|
|
* The container layer is transformed by aTransform (if non-null), and
|
|
|
|
* the result is transformed by the scale factors in aContainerParameters.
|
2010-05-20 20:20:48 -07:00
|
|
|
*/
|
2010-09-03 13:10:45 -07:00
|
|
|
already_AddRefed<ContainerLayer>
|
|
|
|
BuildContainerLayerFor(nsDisplayListBuilder* aBuilder,
|
|
|
|
LayerManager* aManager,
|
|
|
|
nsIFrame* aContainerFrame,
|
|
|
|
nsDisplayItem* aContainerItem,
|
2011-06-22 05:11:27 -07:00
|
|
|
const nsDisplayList& aChildren,
|
|
|
|
const ContainerParameters& aContainerParameters,
|
2013-03-21 19:17:29 -07:00
|
|
|
const gfx3DMatrix* aTransform,
|
|
|
|
uint32_t aFlags = 0);
|
2010-07-15 14:07:46 -07:00
|
|
|
|
|
|
|
/**
|
2010-07-15 14:07:51 -07:00
|
|
|
* Get a retained layer for a display item that needs to create its own
|
|
|
|
* layer for rendering (i.e. under nsDisplayItem::BuildLayer). Returns
|
|
|
|
* null if no retained layer is available, which usually means that this
|
|
|
|
* display item didn't have a layer before so the caller will
|
|
|
|
* need to create one.
|
|
|
|
* Returns a layer with clip rect cleared; it is the
|
|
|
|
* caller's responsibility to add any clip rect and set the visible
|
|
|
|
* region.
|
2010-07-15 14:07:46 -07:00
|
|
|
*/
|
|
|
|
Layer* GetLeafLayerFor(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsDisplayItem* aItem);
|
|
|
|
|
2010-07-15 14:07:51 -07:00
|
|
|
/**
|
|
|
|
* Call this to force all retained layers to be discarded and recreated at
|
|
|
|
* the next paint.
|
|
|
|
*/
|
|
|
|
static void InvalidateAllLayers(LayerManager* aManager);
|
2012-08-28 22:48:45 -07:00
|
|
|
static void InvalidateAllLayersForFrame(nsIFrame *aFrame);
|
2010-07-15 14:07:53 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Call this to determine if a frame has a dedicated (non-Thebes) layer
|
2011-03-27 16:59:47 -07:00
|
|
|
* for the given display item key. If there isn't one, we return null,
|
|
|
|
* otherwise we return the layer.
|
2010-07-15 14:07:53 -07:00
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
static Layer* GetDedicatedLayer(nsIFrame* aFrame, uint32_t aDisplayItemKey);
|
2012-07-03 17:24:55 -07:00
|
|
|
|
2010-05-20 20:20:48 -07:00
|
|
|
/**
|
|
|
|
* This callback must be provided to EndTransaction. The callback data
|
|
|
|
* must be the nsDisplayListBuilder containing this FrameLayerBuilder.
|
2012-07-06 10:57:47 -07:00
|
|
|
* This function can be called multiple times in a row to draw
|
|
|
|
* different regions.
|
2010-05-20 20:20:48 -07:00
|
|
|
*/
|
|
|
|
static void DrawThebesLayer(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-07-15 14:07:51 -07:00
|
|
|
|
2011-11-16 19:44:16 -08:00
|
|
|
#ifdef MOZ_DUMP_PAINTING
|
2010-07-15 14:07:51 -07:00
|
|
|
/**
|
|
|
|
* Dumps this FrameLayerBuilder's retained layer manager's retained
|
2012-08-07 10:57:26 -07:00
|
|
|
* layer tree. Defaults to dumping to stdout in non-HTML format.
|
2010-07-15 14:07:51 -07:00
|
|
|
*/
|
2012-08-07 10:57:26 -07:00
|
|
|
static void DumpRetainedLayerTree(LayerManager* aManager, FILE* aFile = stdout, bool aDumpHtml = false);
|
2010-07-15 14:07:51 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/******* PRIVATE METHODS to FrameLayerBuilder.cpp ********/
|
|
|
|
/* These are only in the public section because they need
|
|
|
|
* to be called by file-scope helper functions in FrameLayerBuilder.cpp.
|
|
|
|
*/
|
2012-08-29 03:53:27 -07:00
|
|
|
|
2010-07-15 14:07:51 -07:00
|
|
|
/**
|
|
|
|
* Record aItem as a display item that is rendered by aLayer.
|
2012-08-28 22:47:15 -07:00
|
|
|
*
|
|
|
|
* @param aLayer Layer that the display item will be rendered into
|
|
|
|
* @param aItem Display item to be drawn.
|
|
|
|
* @param aLayerState What LayerState the item is using.
|
2012-09-28 04:19:39 -07:00
|
|
|
* @param aTopLeft offset from active scrolled root to reference frame
|
2012-08-28 22:47:15 -07:00
|
|
|
* @param aManager If the layer is in the LAYER_INACTIVE state,
|
|
|
|
* then this is the temporary layer manager to draw with.
|
2010-07-15 14:07:51 -07:00
|
|
|
*/
|
2012-12-13 14:50:57 -08:00
|
|
|
void AddLayerDisplayItem(Layer* aLayer,
|
|
|
|
nsDisplayItem* aItem,
|
2013-03-04 01:55:59 -08:00
|
|
|
const DisplayItemClip& aClip,
|
2012-12-13 14:50:57 -08:00
|
|
|
LayerState aLayerState,
|
|
|
|
const nsPoint& aTopLeft,
|
2013-11-06 11:10:49 -08:00
|
|
|
BasicLayerManager* aManager,
|
2012-12-13 14:50:57 -08:00
|
|
|
nsAutoPtr<nsDisplayItemGeometry> aGeometry);
|
2012-08-29 03:53:27 -07:00
|
|
|
|
2010-07-15 14:07:51 -07:00
|
|
|
/**
|
|
|
|
* Record aItem as a display item that is rendered by the ThebesLayer
|
|
|
|
* aLayer, with aClipRect, where aContainerLayerFrame is the frame
|
|
|
|
* for the container layer this ThebesItem belongs to.
|
|
|
|
* aItem must have an underlying frame.
|
2012-09-28 04:19:39 -07:00
|
|
|
* @param aTopLeft offset from active scrolled root to reference frame
|
2010-07-15 14:07:51 -07:00
|
|
|
*/
|
2010-07-15 14:08:05 -07:00
|
|
|
void AddThebesDisplayItem(ThebesLayer* aLayer,
|
|
|
|
nsDisplayItem* aItem,
|
2013-03-04 01:55:59 -08:00
|
|
|
const DisplayItemClip& aClip,
|
2010-07-15 14:08:05 -07:00
|
|
|
nsIFrame* aContainerLayerFrame,
|
2012-08-28 22:47:15 -07:00
|
|
|
LayerState aLayerState,
|
2012-10-11 16:38:24 -07:00
|
|
|
const nsPoint& aTopLeft,
|
|
|
|
nsAutoPtr<nsDisplayItemGeometry> aGeometry);
|
2012-08-28 22:48:41 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the frame property descriptor for the given manager, or for the current
|
|
|
|
* widget layer manager if nullptr is passed.
|
|
|
|
*/
|
|
|
|
static const FramePropertyDescriptor* GetDescriptorForManager(LayerManager* aManager);
|
|
|
|
|
2012-08-29 03:53:27 -07:00
|
|
|
/**
|
|
|
|
* Calls GetOldLayerForFrame on the underlying frame of the display item,
|
|
|
|
* and each subsequent merged frame if no layer is found for the underlying
|
|
|
|
* frame.
|
|
|
|
*/
|
2012-10-15 18:23:07 -07:00
|
|
|
Layer* GetOldLayerFor(nsDisplayItem* aItem,
|
|
|
|
nsDisplayItemGeometry** aOldGeometry = nullptr,
|
2013-03-04 01:55:59 -08:00
|
|
|
DisplayItemClip** aOldClip = nullptr,
|
2012-11-06 14:04:53 -08:00
|
|
|
nsTArray<nsIFrame*>* aChangedFrames = nullptr,
|
|
|
|
bool *aIsInvalid = nullptr);
|
2010-07-15 14:07:51 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
static Layer* GetDebugOldLayerFor(nsIFrame* aFrame, uint32_t aDisplayItemKey);
|
2012-08-28 22:47:15 -07:00
|
|
|
|
2010-09-18 04:28:49 -07:00
|
|
|
/**
|
2011-10-06 14:35:08 -07:00
|
|
|
* Destroy any stored LayerManagerDataProperty and the associated data for
|
|
|
|
* aFrame.
|
2010-09-18 04:28:49 -07:00
|
|
|
*/
|
2012-08-28 22:48:41 -07:00
|
|
|
static void DestroyDisplayItemDataFor(nsIFrame* aFrame);
|
2010-09-18 04:28:49 -07:00
|
|
|
|
2011-02-10 00:58:11 -08:00
|
|
|
LayerManager* GetRetainingLayerManager() { return mRetainingManager; }
|
|
|
|
|
2012-08-28 22:48:45 -07:00
|
|
|
/**
|
2012-12-13 14:51:00 -08:00
|
|
|
* Returns true if the given display item was rendered during the previous
|
|
|
|
* paint. Returns false otherwise.
|
2012-08-28 22:48:45 -07:00
|
|
|
*/
|
2012-12-13 14:51:00 -08:00
|
|
|
static bool HasRetainedDataFor(nsIFrame* aFrame, uint32_t aDisplayItemKey);
|
2012-08-28 22:48:45 -07:00
|
|
|
|
2012-12-13 14:50:57 -08:00
|
|
|
class DisplayItemData;
|
2012-11-06 14:04:53 -08:00
|
|
|
typedef void (*DisplayItemDataCallback)(nsIFrame *aFrame, DisplayItemData* aItem);
|
|
|
|
|
2012-12-13 14:50:57 -08:00
|
|
|
static void IterateRetainedDataFor(nsIFrame* aFrame, DisplayItemDataCallback aCallback);
|
2012-11-06 14:04:53 -08:00
|
|
|
|
2012-08-28 22:48:45 -07:00
|
|
|
/**
|
2012-08-28 22:47:15 -07:00
|
|
|
* Save transform that was in aLayer when we last painted, and the position
|
|
|
|
* of the active scrolled root frame. It must be an integer
|
2011-05-17 22:48:43 -07:00
|
|
|
* translation.
|
2011-05-16 16:05:56 -07:00
|
|
|
*/
|
2011-05-17 22:48:43 -07:00
|
|
|
void SaveLastPaintOffset(ThebesLayer* aLayer);
|
2011-05-16 16:05:56 -07:00
|
|
|
/**
|
2011-05-17 22:48:43 -07:00
|
|
|
* Get the translation transform that was in aLayer when we last painted. It's either
|
2011-05-16 16:05:56 -07:00
|
|
|
* the transform saved by SaveLastPaintTransform, or else the transform
|
2011-05-17 22:48:43 -07:00
|
|
|
* that's currently in the layer (which must be an integer translation).
|
2011-05-16 16:05:56 -07:00
|
|
|
*/
|
2011-05-17 22:48:43 -07:00
|
|
|
nsIntPoint GetLastPaintOffset(ThebesLayer* aLayer);
|
2011-05-16 16:05:56 -07:00
|
|
|
|
2012-05-09 22:24:18 -07:00
|
|
|
/**
|
2012-08-04 05:26:38 -07:00
|
|
|
* Return the resolution at which we expect to render aFrame's contents,
|
|
|
|
* assuming they are being painted to retained layers. This takes into account
|
|
|
|
* the resolution the contents of the ContainerLayer containing aFrame are
|
|
|
|
* being rendered at, as well as any currently-inactive transforms between
|
|
|
|
* aFrame and that container layer.
|
2012-05-09 22:24:18 -07:00
|
|
|
*/
|
2012-08-04 05:26:38 -07:00
|
|
|
static gfxSize GetThebesLayerScaleForFrame(nsIFrame* aFrame);
|
2012-05-09 22:24:18 -07:00
|
|
|
|
2012-09-24 13:31:30 -07:00
|
|
|
/**
|
|
|
|
* Stores a Layer as the dedicated layer in the DisplayItemData for a given frame/key pair.
|
|
|
|
*
|
|
|
|
* Used when we optimize a ThebesLayer into an ImageLayer and want to retroactively update the
|
|
|
|
* DisplayItemData so we can retrieve the layer from within layout.
|
|
|
|
*/
|
2012-10-11 19:39:46 -07:00
|
|
|
void StoreOptimizedLayerForFrame(nsDisplayItem* aItem, Layer* aLayer);
|
2012-08-28 22:48:41 -07:00
|
|
|
|
|
|
|
NS_DECLARE_FRAME_PROPERTY_WITH_FRAME_IN_DTOR(LayerManagerDataProperty,
|
|
|
|
RemoveFrameFromLayerManager)
|
|
|
|
|
2010-07-15 14:07:51 -07:00
|
|
|
/**
|
2012-10-11 16:38:24 -07:00
|
|
|
* Retained data storage:
|
|
|
|
*
|
|
|
|
* Each layer manager (widget, and inactive) stores a LayerManagerData object
|
|
|
|
* that keeps a hash-set of DisplayItemData items that were drawn into it.
|
|
|
|
* Each frame also keeps a list of DisplayItemData pointers that were
|
2012-10-11 19:39:46 -07:00
|
|
|
* created for that frame. DisplayItemData objects manage these lists automatically.
|
2012-10-11 16:38:24 -07:00
|
|
|
*
|
2012-10-11 19:39:46 -07:00
|
|
|
* During layer construction we update the data in the LayerManagerData object, marking
|
|
|
|
* items that are modified. At the end we sweep the LayerManagerData hash-set and remove
|
|
|
|
* all items that haven't been modified.
|
2012-10-11 16:38:24 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retained data for a display item.
|
2010-07-15 14:07:51 -07:00
|
|
|
*/
|
|
|
|
class DisplayItemData {
|
|
|
|
public:
|
2012-11-06 14:04:53 -08:00
|
|
|
friend class FrameLayerBuilder;
|
|
|
|
|
|
|
|
uint32_t GetDisplayItemKey() { return mDisplayItemKey; }
|
|
|
|
Layer* GetLayer() { return mLayer; }
|
|
|
|
void Invalidate() { mIsInvalid = true; }
|
|
|
|
protected:
|
2012-10-11 16:38:24 -07:00
|
|
|
|
2012-10-11 19:39:46 -07:00
|
|
|
DisplayItemData(LayerManagerData* aParent, uint32_t aKey, Layer* aLayer, LayerState aLayerState, uint32_t aGeneration);
|
2012-08-28 22:47:15 -07:00
|
|
|
DisplayItemData(DisplayItemData &toCopy);
|
2012-10-11 19:39:46 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes any references to this object from frames
|
|
|
|
* in mFrameList.
|
|
|
|
*/
|
2012-08-20 21:06:46 -07:00
|
|
|
~DisplayItemData();
|
2010-07-15 14:07:51 -07:00
|
|
|
|
2012-08-28 22:47:15 -07:00
|
|
|
NS_INLINE_DECL_REFCOUNTING(DisplayItemData)
|
|
|
|
|
2012-11-06 14:04:53 -08:00
|
|
|
|
2012-10-11 19:39:46 -07:00
|
|
|
/**
|
|
|
|
* Associates this DisplayItemData with a frame, and adds it
|
|
|
|
* to the LayerManagerDataProperty list on the frame.
|
2012-10-11 16:38:24 -07:00
|
|
|
*/
|
2012-10-11 19:39:46 -07:00
|
|
|
void AddFrame(nsIFrame* aFrame);
|
2012-10-15 18:23:07 -07:00
|
|
|
void RemoveFrame(nsIFrame* aFrame);
|
|
|
|
void GetFrameListChanges(nsDisplayItem* aOther, nsTArray<nsIFrame*>& aOut);
|
2012-08-28 22:47:15 -07:00
|
|
|
|
2012-10-11 16:38:24 -07:00
|
|
|
/**
|
2012-10-11 19:39:46 -07:00
|
|
|
* Updates the contents of this item to a new set of data, instead of allocating a new
|
|
|
|
* object.
|
|
|
|
* Set the passed in parameters, and clears the opt layer, inactive manager, geometry
|
|
|
|
* and clip.
|
|
|
|
* Parent, frame list and display item key are assumed to be the same.
|
2012-10-11 16:38:24 -07:00
|
|
|
*/
|
2012-10-15 18:23:07 -07:00
|
|
|
void UpdateContents(Layer* aLayer, LayerState aState,
|
|
|
|
uint32_t aContainerLayerGeneration, nsDisplayItem* aItem = nullptr);
|
2012-10-11 16:38:24 -07:00
|
|
|
|
|
|
|
LayerManagerData* mParent;
|
2010-07-15 14:07:51 -07:00
|
|
|
nsRefPtr<Layer> mLayer;
|
2012-09-24 13:31:30 -07:00
|
|
|
nsRefPtr<Layer> mOptLayer;
|
2013-11-06 11:10:49 -08:00
|
|
|
nsRefPtr<BasicLayerManager> mInactiveManager;
|
2012-10-11 16:38:24 -07:00
|
|
|
nsAutoTArray<nsIFrame*, 1> mFrameList;
|
2012-08-28 22:47:15 -07:00
|
|
|
nsAutoPtr<nsDisplayItemGeometry> mGeometry;
|
2013-03-04 01:55:59 -08:00
|
|
|
DisplayItemClip mClip;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mDisplayItemKey;
|
|
|
|
uint32_t mContainerLayerGeneration;
|
2012-04-13 04:44:05 -07:00
|
|
|
LayerState mLayerState;
|
2012-08-28 22:47:15 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to track if data currently stored in mFramesWithLayers (from an existing
|
2012-10-11 19:39:46 -07:00
|
|
|
* paint) has been updated in the current paint.
|
2012-08-28 22:47:15 -07:00
|
|
|
*/
|
|
|
|
bool mUsed;
|
2012-11-06 14:04:53 -08:00
|
|
|
bool mIsInvalid;
|
2010-07-15 14:07:51 -07:00
|
|
|
};
|
|
|
|
|
2012-11-06 14:04:53 -08:00
|
|
|
protected:
|
|
|
|
|
2012-07-03 17:17:01 -07:00
|
|
|
friend class LayerManagerData;
|
|
|
|
|
2012-10-11 16:38:24 -07:00
|
|
|
static void RemoveFrameFromLayerManager(nsIFrame* aFrame, void* aPropertyValue);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given a frame and a display item key that uniquely identifies a
|
|
|
|
* display item for the frame, find the layer that was last used to
|
|
|
|
* render that display item. Returns null if there is no such layer.
|
|
|
|
* This could be a dedicated layer for the display item, or a ThebesLayer
|
|
|
|
* that renders many display items.
|
|
|
|
*/
|
|
|
|
DisplayItemData* GetOldLayerForFrame(nsIFrame* aFrame, uint32_t aDisplayItemKey);
|
|
|
|
|
2012-08-28 22:47:15 -07:00
|
|
|
/**
|
|
|
|
* Stores DisplayItemData associated with aFrame, stores the data in
|
|
|
|
* mNewDisplayItemData.
|
|
|
|
*/
|
2012-10-11 19:39:46 -07:00
|
|
|
DisplayItemData* StoreDataForFrame(nsDisplayItem* aItem, Layer* aLayer, LayerState aState);
|
|
|
|
void StoreDataForFrame(nsIFrame* aFrame,
|
|
|
|
uint32_t aDisplayItemKey,
|
|
|
|
Layer* aLayer,
|
|
|
|
LayerState aState);
|
2012-08-28 22:47:15 -07:00
|
|
|
|
2011-11-14 20:59:03 -08:00
|
|
|
// Flash the area within the context clip if paint flashing is enabled.
|
|
|
|
static void FlashPaint(gfxContext *aContext);
|
|
|
|
|
2011-10-06 14:35:08 -07:00
|
|
|
/*
|
|
|
|
* Get the DisplayItemData array associated with this frame, or null if one
|
|
|
|
* doesn't exist.
|
|
|
|
*
|
|
|
|
* Note that the pointer returned here is only valid so long as you don't
|
|
|
|
* poke the LayerManagerData's mFramesWithLayers hashtable.
|
|
|
|
*/
|
2012-10-11 16:38:24 -07:00
|
|
|
DisplayItemData* GetDisplayItemData(nsIFrame *aFrame, uint32_t aKey);
|
2012-08-28 22:47:15 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the DisplayItemData associated with this frame / display item pair,
|
|
|
|
* using the LayerManager instead of FrameLayerBuilder.
|
|
|
|
*/
|
|
|
|
static DisplayItemData* GetDisplayItemDataForManager(nsIFrame* aFrame,
|
|
|
|
uint32_t aDisplayItemKey,
|
|
|
|
LayerManager* aManager);
|
2012-08-28 22:48:45 -07:00
|
|
|
static DisplayItemData* GetDisplayItemDataForManager(nsIFrame* aFrame,
|
|
|
|
uint32_t aDisplayItemKey);
|
2012-08-28 22:47:15 -07:00
|
|
|
static DisplayItemData* GetDisplayItemDataForManager(nsDisplayItem* aItem, LayerManager* aManager);
|
2012-08-28 22:48:45 -07:00
|
|
|
static DisplayItemData* GetDisplayItemDataForManager(nsIFrame* aFrame,
|
|
|
|
uint32_t aDisplayItemKey,
|
|
|
|
LayerManagerData* aData);
|
2011-10-06 14:35:08 -07:00
|
|
|
|
2012-10-11 16:38:25 -07:00
|
|
|
static PLDHashOperator DumpDisplayItemDataForFrame(nsRefPtrHashKey<DisplayItemData>* aEntry,
|
|
|
|
void* aClosure);
|
2010-07-15 14:07:51 -07:00
|
|
|
/**
|
|
|
|
* We store one of these for each display item associated with a
|
|
|
|
* ThebesLayer, in a hashtable that maps each ThebesLayer to an array
|
|
|
|
* of ClippedDisplayItems. (ThebesLayerItemsEntry is the hash entry
|
|
|
|
* for that hashtable.)
|
|
|
|
* These are only stored during the paint process, so that the
|
|
|
|
* DrawThebesLayer callback can figure out which items to draw for the
|
|
|
|
* ThebesLayer.
|
|
|
|
*/
|
|
|
|
struct ClippedDisplayItem {
|
2013-03-04 01:56:02 -08:00
|
|
|
ClippedDisplayItem(nsDisplayItem* aItem, uint32_t aGeneration)
|
|
|
|
: mItem(aItem), mContainerLayerGeneration(aGeneration)
|
2010-07-15 14:07:51 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-08-28 22:47:15 -07:00
|
|
|
~ClippedDisplayItem();
|
|
|
|
|
2010-07-15 14:07:51 -07:00
|
|
|
nsDisplayItem* mItem;
|
2012-08-28 22:47:15 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* If the display item is being rendered as an inactive
|
|
|
|
* layer, then this stores the layer manager being
|
|
|
|
* used for the inactive transaction.
|
|
|
|
*/
|
2012-10-23 04:05:14 -07:00
|
|
|
nsRefPtr<LayerManager> mInactiveLayerManager;
|
2012-08-28 22:47:15 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mContainerLayerGeneration;
|
2010-07-15 14:07:51 -07:00
|
|
|
};
|
|
|
|
|
2013-11-06 11:10:49 -08:00
|
|
|
static void RecomputeVisibilityForItems(nsTArray<ClippedDisplayItem>& aItems,
|
|
|
|
nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsIntRegion& aRegionToDraw,
|
|
|
|
const nsIntPoint& aOffset,
|
|
|
|
int32_t aAppUnitsPerDevPixel,
|
|
|
|
float aXScale,
|
|
|
|
float aYScale);
|
|
|
|
|
|
|
|
void PaintItems(nsTArray<ClippedDisplayItem>& aItems,
|
|
|
|
gfxContext* aContext,
|
|
|
|
nsRenderingContext* aRC,
|
|
|
|
nsDisplayListBuilder* aBuilder,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
int32_t aCommonClipCount);
|
|
|
|
|
2010-07-15 14:07:51 -07:00
|
|
|
/**
|
|
|
|
* We accumulate ClippedDisplayItem elements in a hashtable during
|
|
|
|
* the paint process. This is the hashentry for that hashtable.
|
|
|
|
*/
|
2012-02-07 14:27:44 -08:00
|
|
|
public:
|
2010-07-15 14:07:51 -07:00
|
|
|
class ThebesLayerItemsEntry : public nsPtrHashKey<ThebesLayer> {
|
|
|
|
public:
|
2011-05-16 16:05:56 -07:00
|
|
|
ThebesLayerItemsEntry(const ThebesLayer *key) :
|
2012-07-30 07:20:58 -07:00
|
|
|
nsPtrHashKey<ThebesLayer>(key), mContainerLayerFrame(nullptr),
|
2012-09-11 14:17:26 -07:00
|
|
|
mContainerLayerGeneration(0),
|
2012-05-14 16:01:05 -07:00
|
|
|
mHasExplicitLastPaintOffset(false), mCommonClipCount(0) {}
|
2010-07-15 14:07:51 -07:00
|
|
|
ThebesLayerItemsEntry(const ThebesLayerItemsEntry &toCopy) :
|
|
|
|
nsPtrHashKey<ThebesLayer>(toCopy.mKey), mItems(toCopy.mItems)
|
|
|
|
{
|
|
|
|
NS_ERROR("Should never be called, since we ALLOW_MEMMOVE");
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTArray<ClippedDisplayItem> mItems;
|
|
|
|
nsIFrame* mContainerLayerFrame;
|
2011-05-17 22:48:43 -07:00
|
|
|
// The translation set on this ThebesLayer before we started updating the
|
2011-05-16 16:05:56 -07:00
|
|
|
// layer tree.
|
2011-05-17 22:48:43 -07:00
|
|
|
nsIntPoint mLastPaintOffset;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mContainerLayerGeneration;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mHasExplicitLastPaintOffset;
|
2012-02-07 14:27:44 -08:00
|
|
|
/**
|
|
|
|
* The first mCommonClipCount rounded rectangle clips are identical for
|
|
|
|
* all items in the layer. Computed in ThebesLayerData.
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mCommonClipCount;
|
2010-07-15 14:07:51 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
enum { ALLOW_MEMMOVE = true };
|
2010-07-15 14:07:51 -07:00
|
|
|
};
|
|
|
|
|
2012-02-07 14:27:44 -08:00
|
|
|
/**
|
|
|
|
* Get the ThebesLayerItemsEntry object associated with aLayer in this
|
|
|
|
* FrameLayerBuilder
|
|
|
|
*/
|
|
|
|
ThebesLayerItemsEntry* GetThebesLayerItemsEntry(ThebesLayer* aLayer)
|
|
|
|
{
|
|
|
|
return mThebesLayerItems.GetEntry(aLayer);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2012-08-29 03:53:34 -07:00
|
|
|
void RemoveThebesItemsAndOwnerDataForLayerSubtree(Layer* aLayer,
|
|
|
|
bool aRemoveThebesItems,
|
|
|
|
bool aRemoveOwnerData);
|
2010-07-15 14:07:51 -07:00
|
|
|
|
2012-12-12 12:47:05 -08:00
|
|
|
static PLDHashOperator ProcessRemovedDisplayItems(nsRefPtrHashKey<DisplayItemData>* aEntry,
|
|
|
|
void* aUserArg);
|
2012-10-11 19:39:46 -07:00
|
|
|
static PLDHashOperator RestoreDisplayItemData(nsRefPtrHashKey<DisplayItemData>* aEntry,
|
2012-07-22 20:00:36 -07:00
|
|
|
void *aUserArg);
|
|
|
|
|
|
|
|
static PLDHashOperator RestoreThebesLayerItemEntries(ThebesLayerItemsEntry* aEntry,
|
|
|
|
void *aUserArg);
|
2010-07-15 14:07:51 -07:00
|
|
|
|
2010-09-17 12:09:08 -07:00
|
|
|
/**
|
|
|
|
* Returns true if the DOM has been modified since we started painting,
|
|
|
|
* in which case we should bail out and not paint anymore. This should
|
|
|
|
* never happen, but plugins can trigger it in some cases.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
bool CheckDOMModified();
|
2010-09-17 12:09:08 -07:00
|
|
|
|
2010-07-15 14:07:51 -07:00
|
|
|
/**
|
|
|
|
* The layer manager belonging to the widget that is being retained
|
|
|
|
* across paints.
|
|
|
|
*/
|
|
|
|
LayerManager* mRetainingManager;
|
2010-09-17 12:09:08 -07:00
|
|
|
/**
|
|
|
|
* The root prescontext for the display list builder reference frame
|
|
|
|
*/
|
2012-10-04 20:20:35 -07:00
|
|
|
nsRefPtr<nsRootPresContext> mRootPresContext;
|
2012-08-28 22:47:15 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The display list builder being used.
|
|
|
|
*/
|
|
|
|
nsDisplayListBuilder* mDisplayListBuilder;
|
2010-07-15 14:07:51 -07:00
|
|
|
/**
|
|
|
|
* A map from ThebesLayers to the list of display items (plus
|
|
|
|
* clipping data) to be rendered in the layer.
|
|
|
|
*/
|
|
|
|
nsTHashtable<ThebesLayerItemsEntry> mThebesLayerItems;
|
2010-09-17 12:09:08 -07:00
|
|
|
/**
|
|
|
|
* Saved generation counter so we can detect DOM changes.
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mInitialDOMGeneration;
|
2010-09-17 12:09:08 -07:00
|
|
|
/**
|
|
|
|
* Set to true if we have detected and reported DOM modification during
|
|
|
|
* the current paint.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mDetectedDOMModification;
|
2010-07-15 14:07:51 -07:00
|
|
|
/**
|
|
|
|
* Indicates that the entire layer tree should be rerendered
|
|
|
|
* during this paint.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mInvalidateAllLayers;
|
2012-07-22 20:00:36 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mContainerLayerGeneration;
|
|
|
|
uint32_t mMaxContainerLayerGeneration;
|
2010-05-20 20:20:48 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* FRAMELAYERBUILDER_H_ */
|