2010-05-21 07:20:48 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Corporation code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Mozilla Foundation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Robert O'Callahan <robert@ocallahan.org>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#ifndef FRAMELAYERBUILDER_H_
|
|
|
|
#define FRAMELAYERBUILDER_H_
|
|
|
|
|
2010-07-16 01:07:51 +04:00
|
|
|
#include "nsTHashtable.h"
|
|
|
|
#include "nsHashKeys.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsRegion.h"
|
|
|
|
#include "nsIFrame.h"
|
2010-08-31 04:46:26 +04:00
|
|
|
#include "Layers.h"
|
2010-05-21 07:20:48 +04:00
|
|
|
|
|
|
|
class nsDisplayListBuilder;
|
|
|
|
class nsDisplayList;
|
|
|
|
class nsDisplayItem;
|
2010-07-16 01:07:46 +04:00
|
|
|
class gfxContext;
|
2010-09-17 23:09:08 +04:00
|
|
|
class nsRootPresContext;
|
2010-05-21 07:20:48 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2010-07-16 01:08:05 +04:00
|
|
|
enum LayerState {
|
|
|
|
LAYER_NONE,
|
|
|
|
LAYER_INACTIVE,
|
2011-03-16 02:20:19 +03:00
|
|
|
LAYER_ACTIVE,
|
|
|
|
// Force an active layer even if it causes incorrect rendering, e.g.
|
|
|
|
// when the layer has rounded rect clips.
|
2011-04-12 00:53:01 +04:00
|
|
|
LAYER_ACTIVE_FORCE,
|
|
|
|
// Special layer that is metadata only.
|
|
|
|
LAYER_ACTIVE_EMPTY
|
2010-07-16 01:08:05 +04:00
|
|
|
};
|
|
|
|
|
2010-07-16 01:07:51 +04:00
|
|
|
/**
|
|
|
|
* The FrameLayerBuilder belongs to an nsDisplayListBuilder and is
|
|
|
|
* responsible for converting display lists into layer trees.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* also updates userdata for the retained layer manager, and
|
|
|
|
* DisplayItemDataProperty data for frames, to record the relationship
|
|
|
|
* between frames and layers.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* corresponds to the snapped top-left of the display list reference frame.
|
2011-06-22 16:11:27 +04: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-16 01:07:51 +04:00
|
|
|
*/
|
2010-05-21 07:20:48 +04:00
|
|
|
class FrameLayerBuilder {
|
|
|
|
public:
|
2010-09-04 00:10:45 +04:00
|
|
|
typedef layers::ContainerLayer ContainerLayer;
|
2010-07-16 01:07:51 +04:00
|
|
|
typedef layers::Layer Layer;
|
|
|
|
typedef layers::ThebesLayer ThebesLayer;
|
|
|
|
typedef layers::LayerManager LayerManager;
|
|
|
|
|
|
|
|
FrameLayerBuilder() :
|
|
|
|
mRetainingManager(nsnull),
|
2011-10-17 18:59:28 +04:00
|
|
|
mDetectedDOMModification(false),
|
|
|
|
mInvalidateAllLayers(false)
|
2010-07-16 01:07:51 +04:00
|
|
|
{
|
|
|
|
mNewDisplayItemData.Init();
|
|
|
|
mThebesLayerItems.Init();
|
|
|
|
}
|
|
|
|
|
2010-09-17 23:09:08 +04:00
|
|
|
void Init(nsDisplayListBuilder* aBuilder);
|
|
|
|
|
2010-07-16 01:07:51 +04:00
|
|
|
/**
|
2011-01-19 11:27:54 +03:00
|
|
|
* Call this to notify that we have just started a transaction on the
|
2010-07-16 01:08:11 +04:00
|
|
|
* retained layer manager aManager.
|
2010-07-16 01:07:51 +04:00
|
|
|
*/
|
2011-01-19 11:27:54 +03:00
|
|
|
void DidBeginRetainedLayerTransaction(LayerManager* aManager);
|
2010-07-16 01:07:51 +04:00
|
|
|
|
|
|
|
/**
|
2010-07-16 01:08:11 +04:00
|
|
|
* Call this just before we end a transaction on aManager. If aManager
|
|
|
|
* is not the retained layer manager then it must be a temporary layer
|
|
|
|
* manager that will not be used again.
|
|
|
|
*/
|
|
|
|
void WillEndTransaction(LayerManager* aManager);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Call this after we end a transaction on aManager. If aManager
|
2010-07-16 01:07:51 +04:00
|
|
|
* is not the retained layer manager then it must be a temporary layer
|
|
|
|
* manager that will not be used again.
|
|
|
|
*/
|
|
|
|
void DidEndTransaction(LayerManager* aManager);
|
2010-05-21 07:20:48 +04:00
|
|
|
|
2011-06-22 16:11:27 +04:00
|
|
|
struct ContainerParameters {
|
2011-06-22 16:11:28 +04:00
|
|
|
ContainerParameters() :
|
|
|
|
mXScale(1), mYScale(1),
|
2012-01-11 15:26:33 +04:00
|
|
|
mInTransformedSubtree(false), mInActiveTransformedSubtree(false),
|
|
|
|
mDisableSubpixelAntialiasingInDescendants(false)
|
|
|
|
{}
|
2011-06-22 16:11:27 +04:00
|
|
|
ContainerParameters(float aXScale, float aYScale) :
|
2011-06-22 16:11:28 +04:00
|
|
|
mXScale(aXScale), mYScale(aYScale),
|
2012-01-11 15:26:33 +04:00
|
|
|
mInTransformedSubtree(false), mInActiveTransformedSubtree(false),
|
|
|
|
mDisableSubpixelAntialiasingInDescendants(false)
|
|
|
|
{}
|
2011-06-22 16:11:28 +04:00
|
|
|
ContainerParameters(float aXScale, float aYScale,
|
|
|
|
const ContainerParameters& aParent) :
|
|
|
|
mXScale(aXScale), mYScale(aYScale),
|
|
|
|
mInTransformedSubtree(aParent.mInTransformedSubtree),
|
2012-01-11 15:26:33 +04:00
|
|
|
mInActiveTransformedSubtree(aParent.mInActiveTransformedSubtree),
|
|
|
|
mDisableSubpixelAntialiasingInDescendants(aParent.mDisableSubpixelAntialiasingInDescendants)
|
|
|
|
{}
|
2011-06-22 16:11:27 +04:00
|
|
|
float mXScale, mYScale;
|
2011-06-22 16:11:28 +04:00
|
|
|
bool mInTransformedSubtree;
|
|
|
|
bool mInActiveTransformedSubtree;
|
2012-01-11 15:26:33 +04:00
|
|
|
bool mDisableSubpixelAntialiasingInDescendants;
|
2011-06-22 16:11:27 +04:00
|
|
|
};
|
2010-05-21 07:20:48 +04:00
|
|
|
/**
|
2010-07-16 01:07:51 +04: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-21 07:20:48 +04:00
|
|
|
* aContainer may be null, in which case we construct a root layer.
|
2010-07-16 01:07:51 +04: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-23 08:38:09 +03:00
|
|
|
* caller's responsibility to add any clip rect. The visible region
|
|
|
|
* is set based on what's in the layer.
|
2011-06-22 16:11:27 +04:00
|
|
|
* The container layer is transformed by aTransform (if non-null), and
|
|
|
|
* the result is transformed by the scale factors in aContainerParameters.
|
2010-05-21 07:20:48 +04:00
|
|
|
*/
|
2010-09-04 00:10:45 +04:00
|
|
|
already_AddRefed<ContainerLayer>
|
|
|
|
BuildContainerLayerFor(nsDisplayListBuilder* aBuilder,
|
|
|
|
LayerManager* aManager,
|
|
|
|
nsIFrame* aContainerFrame,
|
|
|
|
nsDisplayItem* aContainerItem,
|
2011-06-22 16:11:27 +04:00
|
|
|
const nsDisplayList& aChildren,
|
|
|
|
const ContainerParameters& aContainerParameters,
|
|
|
|
const gfx3DMatrix* aTransform);
|
2010-07-16 01:07:46 +04:00
|
|
|
|
|
|
|
/**
|
2010-07-16 01:07:51 +04: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-16 01:07:46 +04:00
|
|
|
*/
|
|
|
|
Layer* GetLeafLayerFor(nsDisplayListBuilder* aBuilder,
|
|
|
|
LayerManager* aManager,
|
|
|
|
nsDisplayItem* aItem);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Call this during invalidation if aFrame has
|
|
|
|
* the NS_FRAME_HAS_CONTAINER_LAYER state bit. Only the nearest
|
|
|
|
* ancestor frame of the damaged frame that has
|
|
|
|
* NS_FRAME_HAS_CONTAINER_LAYER needs to be invalidated this way.
|
|
|
|
*/
|
|
|
|
static void InvalidateThebesLayerContents(nsIFrame* aFrame,
|
|
|
|
const nsRect& aRect);
|
2010-05-21 07:20:48 +04:00
|
|
|
|
2010-08-31 04:46:26 +04:00
|
|
|
/**
|
|
|
|
* For any descendant frame of aFrame (including across documents) that
|
|
|
|
* has an associated container layer, invalidate all the contents of
|
|
|
|
* all ThebesLayer children of the container. Useful when aFrame is
|
|
|
|
* being moved and we need to invalidate everything in aFrame's subtree.
|
|
|
|
*/
|
|
|
|
static void InvalidateThebesLayersInSubtree(nsIFrame* aFrame);
|
|
|
|
|
2010-07-16 01:07:51 +04:00
|
|
|
/**
|
|
|
|
* Call this to force all retained layers to be discarded and recreated at
|
|
|
|
* the next paint.
|
|
|
|
*/
|
|
|
|
static void InvalidateAllLayers(LayerManager* aManager);
|
2010-07-16 01:07:53 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Call this to determine if a frame has a dedicated (non-Thebes) layer
|
2011-03-28 03:59:47 +04:00
|
|
|
* for the given display item key. If there isn't one, we return null,
|
|
|
|
* otherwise we return the layer.
|
2010-07-16 01:07:53 +04:00
|
|
|
*/
|
2011-03-28 03:59:47 +04:00
|
|
|
static Layer* GetDedicatedLayer(nsIFrame* aFrame, PRUint32 aDisplayItemKey);
|
2010-07-16 01:07:53 +04:00
|
|
|
|
2010-05-21 07:20:48 +04:00
|
|
|
/**
|
|
|
|
* This callback must be provided to EndTransaction. The callback data
|
|
|
|
* must be the nsDisplayListBuilder containing this FrameLayerBuilder.
|
|
|
|
*/
|
|
|
|
static void DrawThebesLayer(ThebesLayer* aLayer,
|
|
|
|
gfxContext* aContext,
|
|
|
|
const nsIntRegion& aRegionToDraw,
|
2010-03-04 00:37:04 +03:00
|
|
|
const nsIntRegion& aRegionToInvalidate,
|
2010-05-21 07:20:48 +04:00
|
|
|
void* aCallbackData);
|
2010-07-16 01:07:51 +04:00
|
|
|
|
2011-11-17 07:44:16 +04:00
|
|
|
#ifdef MOZ_DUMP_PAINTING
|
2010-07-16 01:07:51 +04:00
|
|
|
/**
|
|
|
|
* Dumps this FrameLayerBuilder's retained layer manager's retained
|
|
|
|
* layer tree to stderr.
|
|
|
|
*/
|
2012-03-01 12:26:09 +04:00
|
|
|
void DumpRetainedLayerTree(FILE* aFile = stdout);
|
2010-07-16 01:07:51 +04: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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Record aItem as a display item that is rendered by aLayer.
|
|
|
|
*/
|
2011-05-19 02:54:31 +04:00
|
|
|
void AddLayerDisplayItem(Layer* aLayer,
|
|
|
|
nsDisplayItem* aItem,
|
|
|
|
LayerState aLayerState);
|
2010-07-16 01:07:51 +04: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.
|
|
|
|
*/
|
2010-09-09 19:21:46 +04:00
|
|
|
struct Clip;
|
2010-07-16 01:08:05 +04:00
|
|
|
void AddThebesDisplayItem(ThebesLayer* aLayer,
|
|
|
|
nsDisplayItem* aItem,
|
2010-09-09 19:21:46 +04:00
|
|
|
const Clip& aClip,
|
2010-07-16 01:08:05 +04:00
|
|
|
nsIFrame* aContainerLayerFrame,
|
2011-02-10 11:58:11 +03:00
|
|
|
LayerState aLayerState);
|
2010-07-16 01:07:51 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
Layer* GetOldLayerFor(nsIFrame* aFrame, PRUint32 aDisplayItemKey);
|
|
|
|
|
2010-09-02 13:18:39 +04:00
|
|
|
/**
|
|
|
|
* Try to determine whether the ThebesLayer aLayer paints an opaque
|
|
|
|
* single color everywhere it's visible in aRect.
|
|
|
|
* If successful, return that color, otherwise return NS_RGBA(0,0,0,0).
|
|
|
|
*/
|
|
|
|
nscolor FindOpaqueColorCovering(nsDisplayListBuilder* aBuilder,
|
|
|
|
ThebesLayer* aLayer, const nsRect& aRect);
|
|
|
|
|
2010-09-18 15:28:49 +04:00
|
|
|
/**
|
2011-10-07 01:35:08 +04:00
|
|
|
* Destroy any stored LayerManagerDataProperty and the associated data for
|
|
|
|
* aFrame.
|
2010-09-18 15:28:49 +04:00
|
|
|
*/
|
|
|
|
static void DestroyDisplayItemDataFor(nsIFrame* aFrame)
|
|
|
|
{
|
2011-10-07 01:35:08 +04:00
|
|
|
aFrame->Properties().Delete(LayerManagerDataProperty());
|
2010-09-18 15:28:49 +04:00
|
|
|
}
|
|
|
|
|
2011-02-10 11:58:11 +03:00
|
|
|
LayerManager* GetRetainingLayerManager() { return mRetainingManager; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the given item (which we assume here is
|
|
|
|
* background-attachment:fixed) needs to be repainted as we scroll in its
|
|
|
|
* document.
|
|
|
|
* Returns false if it doesn't need to be repainted because the layer system
|
|
|
|
* is ensuring its fixed-ness for us.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool NeedToInvalidateFixedDisplayItem(nsDisplayListBuilder* aBuilder,
|
2011-02-10 11:58:11 +03:00
|
|
|
nsDisplayItem* aItem);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the given display item was rendered directly
|
|
|
|
* into a retained layer.
|
|
|
|
* Returns false if it was rendered into a temporary layer manager and then
|
|
|
|
* into a retained layer.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool HasRetainedLayerFor(nsIFrame* aFrame, PRUint32 aDisplayItemKey);
|
2011-02-10 11:58:11 +03:00
|
|
|
|
2011-05-17 03:05:56 +04:00
|
|
|
/**
|
2011-05-18 09:48:43 +04:00
|
|
|
* Save transform that was in aLayer when we last painted. It must be an integer
|
|
|
|
* translation.
|
2011-05-17 03:05:56 +04:00
|
|
|
*/
|
2011-05-18 09:48:43 +04:00
|
|
|
void SaveLastPaintOffset(ThebesLayer* aLayer);
|
2011-05-17 03:05:56 +04:00
|
|
|
/**
|
2011-05-18 09:48:43 +04:00
|
|
|
* Get the translation transform that was in aLayer when we last painted. It's either
|
2011-05-17 03:05:56 +04:00
|
|
|
* the transform saved by SaveLastPaintTransform, or else the transform
|
2011-05-18 09:48:43 +04:00
|
|
|
* that's currently in the layer (which must be an integer translation).
|
2011-05-17 03:05:56 +04:00
|
|
|
*/
|
2011-05-18 09:48:43 +04:00
|
|
|
nsIntPoint GetLastPaintOffset(ThebesLayer* aLayer);
|
2011-05-17 03:05:56 +04:00
|
|
|
|
2010-09-09 19:21:46 +04:00
|
|
|
/**
|
|
|
|
* Clip represents the intersection of an optional rectangle with a
|
|
|
|
* list of rounded rectangles.
|
|
|
|
*/
|
|
|
|
struct Clip {
|
|
|
|
struct RoundedRect {
|
|
|
|
nsRect mRect;
|
|
|
|
// Indices into mRadii are the NS_CORNER_* constants in nsStyleConsts.h
|
|
|
|
nscoord mRadii[8];
|
|
|
|
|
|
|
|
bool operator==(const RoundedRect& aOther) const {
|
2011-04-19 07:07:23 +04:00
|
|
|
if (!mRect.IsEqualInterior(aOther.mRect)) {
|
2010-09-09 19:21:46 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_FOR_CSS_HALF_CORNERS(corner) {
|
|
|
|
if (mRadii[corner] != aOther.mRadii[corner]) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool operator!=(const RoundedRect& aOther) const {
|
|
|
|
return !(*this == aOther);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
nsRect mClipRect;
|
|
|
|
nsTArray<RoundedRect> mRoundedClipRects;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mHaveClipRect;
|
2010-09-09 19:21:46 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
Clip() : mHaveClipRect(false) {}
|
2010-09-09 19:21:46 +04:00
|
|
|
|
|
|
|
// Construct as the intersection of aOther and aClipItem.
|
|
|
|
Clip(const Clip& aOther, nsDisplayItem* aClipItem);
|
|
|
|
|
|
|
|
// Apply this |Clip| to the given gfxContext. Any saving of state
|
|
|
|
// or clearing of other clips must be done by the caller.
|
|
|
|
void ApplyTo(gfxContext* aContext, nsPresContext* aPresContext);
|
|
|
|
|
2011-01-03 04:48:09 +03:00
|
|
|
// Return a rectangle contained in the intersection of aRect with this
|
|
|
|
// clip region. Tries to return the largest possible rectangle, but may
|
|
|
|
// not succeed.
|
|
|
|
nsRect ApproximateIntersect(const nsRect& aRect) const;
|
|
|
|
|
2011-01-26 21:36:11 +03:00
|
|
|
// Returns false if aRect is definitely not clipped by a rounded corner in
|
|
|
|
// this clip. Returns true if aRect is clipped by a rounded corner in this
|
|
|
|
// clip or it can not be quickly determined that it is not clipped by a
|
|
|
|
// rounded corner in this clip.
|
|
|
|
bool IsRectClippedByRoundedCorner(const nsRect& aRect) const;
|
|
|
|
|
|
|
|
// Intersection of all rects in this clip ignoring any rounded corners.
|
|
|
|
nsRect NonRoundedIntersection() const;
|
|
|
|
|
|
|
|
// Gets rid of any rounded corners in this clip.
|
|
|
|
void RemoveRoundedCorners();
|
|
|
|
|
2010-09-09 19:21:46 +04:00
|
|
|
bool operator==(const Clip& aOther) const {
|
|
|
|
return mHaveClipRect == aOther.mHaveClipRect &&
|
2011-04-19 07:07:23 +04:00
|
|
|
(!mHaveClipRect || mClipRect.IsEqualInterior(aOther.mClipRect)) &&
|
2010-09-09 19:21:46 +04:00
|
|
|
mRoundedClipRects == aOther.mRoundedClipRects;
|
|
|
|
}
|
|
|
|
bool operator!=(const Clip& aOther) const {
|
|
|
|
return !(*this == aOther);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-07-16 01:07:51 +04:00
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* We store an array of these for each frame that is associated with
|
|
|
|
* one or more retained layers. Each DisplayItemData records the layer
|
|
|
|
* used to render one of the frame's display items.
|
|
|
|
*/
|
|
|
|
class DisplayItemData {
|
|
|
|
public:
|
2011-05-19 02:54:31 +04:00
|
|
|
DisplayItemData(Layer* aLayer, PRUint32 aKey, LayerState aLayerState)
|
|
|
|
: mLayer(aLayer), mDisplayItemKey(aKey), mLayerState(aLayerState) {}
|
2010-07-16 01:07:51 +04:00
|
|
|
|
|
|
|
nsRefPtr<Layer> mLayer;
|
|
|
|
PRUint32 mDisplayItemKey;
|
2011-05-19 02:54:31 +04:00
|
|
|
LayerState mLayerState;
|
2010-07-16 01:07:51 +04:00
|
|
|
};
|
|
|
|
|
2011-10-07 01:35:08 +04:00
|
|
|
static void RemoveFrameFromLayerManager(nsIFrame* aFrame, void* aPropertyValue);
|
2010-07-16 01:07:51 +04:00
|
|
|
|
2011-10-07 01:35:08 +04:00
|
|
|
NS_DECLARE_FRAME_PROPERTY_WITH_FRAME_IN_DTOR(LayerManagerDataProperty,
|
|
|
|
RemoveFrameFromLayerManager)
|
2010-07-16 01:07:51 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* We accumulate DisplayItemData elements in a hashtable during
|
|
|
|
* the paint process, and store them in the frame property only when
|
|
|
|
* paint is complete. This is the hashentry for that hashtable.
|
|
|
|
*/
|
|
|
|
class DisplayItemDataEntry : public nsPtrHashKey<nsIFrame> {
|
|
|
|
public:
|
|
|
|
DisplayItemDataEntry(const nsIFrame *key) : nsPtrHashKey<nsIFrame>(key) {}
|
2011-10-07 01:35:08 +04:00
|
|
|
DisplayItemDataEntry(DisplayItemDataEntry &toCopy) :
|
|
|
|
nsPtrHashKey<nsIFrame>(toCopy.mKey)
|
2010-07-16 01:07:51 +04:00
|
|
|
{
|
2011-10-07 01:35:08 +04:00
|
|
|
// This isn't actually a copy-constructor; notice that it steals toCopy's
|
|
|
|
// array. Be careful.
|
|
|
|
mData.SwapElements(toCopy.mData);
|
2010-07-16 01:07:51 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool HasNonEmptyContainerLayer();
|
2010-07-16 01:07:51 +04:00
|
|
|
|
2011-10-07 01:35:08 +04:00
|
|
|
nsAutoTArray<DisplayItemData, 1> mData;
|
2010-07-16 01:07:51 +04:00
|
|
|
|
2011-10-07 01:35:08 +04:00
|
|
|
enum { ALLOW_MEMMOVE = false };
|
2010-07-16 01:07:51 +04:00
|
|
|
};
|
|
|
|
|
2011-10-07 01:35:08 +04:00
|
|
|
// LayerManagerData needs to see DisplayItemDataEntry.
|
|
|
|
friend class LayerManagerData;
|
|
|
|
|
2011-11-15 08:59:03 +04:00
|
|
|
// Flash the area within the context clip if paint flashing is enabled.
|
|
|
|
static void FlashPaint(gfxContext *aContext);
|
|
|
|
|
2011-10-07 01:35:08 +04: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.
|
|
|
|
*/
|
|
|
|
static nsTArray<DisplayItemData>* GetDisplayItemDataArrayForFrame(nsIFrame *aFrame);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A useful hashtable iteration function that removes the
|
|
|
|
* DisplayItemData property for the frame, clears its
|
|
|
|
* NS_FRAME_HAS_CONTAINER_LAYER bit and returns PL_DHASH_REMOVE.
|
|
|
|
* aClosure is ignored.
|
|
|
|
*/
|
|
|
|
static PLDHashOperator RemoveDisplayItemDataForFrame(DisplayItemDataEntry* aEntry,
|
|
|
|
void* aClosure)
|
|
|
|
{
|
|
|
|
return UpdateDisplayItemDataForFrame(aEntry, nsnull);
|
|
|
|
}
|
|
|
|
|
2010-07-16 01:07:51 +04: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.
|
|
|
|
* mItem always has an underlying frame.
|
|
|
|
*/
|
|
|
|
struct ClippedDisplayItem {
|
2010-09-09 19:21:46 +04:00
|
|
|
ClippedDisplayItem(nsDisplayItem* aItem, const Clip& aClip)
|
|
|
|
: mItem(aItem), mClip(aClip)
|
2010-07-16 01:07:51 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDisplayItem* mItem;
|
2010-09-09 19:21:46 +04:00
|
|
|
Clip mClip;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mInactiveLayer;
|
2010-07-16 01:07:51 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* We accumulate ClippedDisplayItem elements in a hashtable during
|
|
|
|
* the paint process. This is the hashentry for that hashtable.
|
|
|
|
*/
|
|
|
|
class ThebesLayerItemsEntry : public nsPtrHashKey<ThebesLayer> {
|
|
|
|
public:
|
2011-05-17 03:05:56 +04:00
|
|
|
ThebesLayerItemsEntry(const ThebesLayer *key) :
|
|
|
|
nsPtrHashKey<ThebesLayer>(key), mContainerLayerFrame(nsnull),
|
2011-10-17 18:59:28 +04:00
|
|
|
mHasExplicitLastPaintOffset(false) {}
|
2010-07-16 01:07:51 +04: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-18 09:48:43 +04:00
|
|
|
// The translation set on this ThebesLayer before we started updating the
|
2011-05-17 03:05:56 +04:00
|
|
|
// layer tree.
|
2011-05-18 09:48:43 +04:00
|
|
|
nsIntPoint mLastPaintOffset;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mHasExplicitLastPaintOffset;
|
2010-07-16 01:07:51 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
enum { ALLOW_MEMMOVE = true };
|
2010-07-16 01:07:51 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
void RemoveThebesItemsForLayerSubtree(Layer* aLayer);
|
|
|
|
|
2011-10-07 01:35:08 +04:00
|
|
|
static PLDHashOperator UpdateDisplayItemDataForFrame(DisplayItemDataEntry* aEntry,
|
2010-07-16 01:07:51 +04:00
|
|
|
void* aUserArg);
|
|
|
|
static PLDHashOperator StoreNewDisplayItemData(DisplayItemDataEntry* aEntry,
|
|
|
|
void* aUserArg);
|
|
|
|
|
2010-09-17 23:09:08 +04: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-29 10:19:26 +04:00
|
|
|
bool CheckDOMModified();
|
2010-09-17 23:09:08 +04:00
|
|
|
|
2010-07-16 01:07:51 +04:00
|
|
|
/**
|
|
|
|
* The layer manager belonging to the widget that is being retained
|
|
|
|
* across paints.
|
|
|
|
*/
|
|
|
|
LayerManager* mRetainingManager;
|
2010-09-17 23:09:08 +04:00
|
|
|
/**
|
|
|
|
* The root prescontext for the display list builder reference frame
|
|
|
|
*/
|
|
|
|
nsRootPresContext* mRootPresContext;
|
2010-07-16 01:07:51 +04:00
|
|
|
/**
|
|
|
|
* A map from frames to a list of (display item key, layer) pairs that
|
|
|
|
* describes what layers various parts of the frame are assigned to.
|
|
|
|
*/
|
|
|
|
nsTHashtable<DisplayItemDataEntry> mNewDisplayItemData;
|
|
|
|
/**
|
|
|
|
* 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 23:09:08 +04:00
|
|
|
/**
|
|
|
|
* Saved generation counter so we can detect DOM changes.
|
|
|
|
*/
|
|
|
|
PRUint32 mInitialDOMGeneration;
|
|
|
|
/**
|
|
|
|
* Set to true if we have detected and reported DOM modification during
|
|
|
|
* the current paint.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mDetectedDOMModification;
|
2010-07-16 01:07:51 +04:00
|
|
|
/**
|
|
|
|
* Indicates that the entire layer tree should be rerendered
|
|
|
|
* during this paint.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mInvalidateAllLayers;
|
2010-05-21 07:20:48 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* FRAMELAYERBUILDER_H_ */
|