2010-05-20 20:20:48 -07: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 ***** */
|
|
|
|
|
|
|
|
#include "FrameLayerBuilder.h"
|
|
|
|
|
|
|
|
#include "nsDisplayList.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsLayoutUtils.h"
|
2010-07-15 14:07:51 -07:00
|
|
|
#include "Layers.h"
|
2010-07-15 14:08:05 -07:00
|
|
|
#include "BasicLayers.h"
|
2010-08-30 17:49:07 -07:00
|
|
|
#include "nsSubDocumentFrame.h"
|
2010-09-09 08:21:46 -07:00
|
|
|
#include "nsCSSRendering.h"
|
2010-09-17 12:09:08 -07:00
|
|
|
#include "nsCSSFrameConstructor.h"
|
2010-11-24 01:35:21 -08:00
|
|
|
#include "gfxUtils.h"
|
2011-01-17 13:47:18 -08:00
|
|
|
#include "nsImageFrame.h"
|
2010-07-15 14:07:51 -07:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
#include <stdio.h>
|
|
|
|
#endif
|
2010-05-20 20:20:48 -07:00
|
|
|
|
|
|
|
using namespace mozilla::layers;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
/**
|
2010-07-15 14:07:51 -07:00
|
|
|
* This is the userdata we associate with a layer manager.
|
2010-05-20 20:20:48 -07:00
|
|
|
*/
|
2010-09-02 02:18:39 -07:00
|
|
|
class LayerManagerData : public LayerUserData {
|
2010-05-20 20:20:48 -07:00
|
|
|
public:
|
2010-12-07 18:24:05 -08:00
|
|
|
LayerManagerData(LayerManager *aManager) :
|
|
|
|
mInvalidateAllLayers(PR_FALSE),
|
|
|
|
mLayerManager(aManager)
|
2010-05-20 20:20:48 -07:00
|
|
|
{
|
2010-09-02 02:18:39 -07:00
|
|
|
MOZ_COUNT_CTOR(LayerManagerData);
|
2010-07-15 14:07:51 -07:00
|
|
|
mFramesWithLayers.Init();
|
2010-05-20 20:20:48 -07:00
|
|
|
}
|
2010-09-02 02:18:39 -07:00
|
|
|
~LayerManagerData() {
|
2010-09-02 02:18:39 -07:00
|
|
|
// Remove display item data properties now, since we won't be able
|
|
|
|
// to find these frames again without mFramesWithLayers.
|
|
|
|
mFramesWithLayers.EnumerateEntries(
|
|
|
|
FrameLayerBuilder::RemoveDisplayItemDataForFrame, nsnull);
|
2010-09-02 02:18:39 -07:00
|
|
|
MOZ_COUNT_DTOR(LayerManagerData);
|
|
|
|
}
|
2010-07-15 14:07:51 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Tracks which frames have layers associated with them.
|
|
|
|
*/
|
|
|
|
nsTHashtable<nsPtrHashKey<nsIFrame> > mFramesWithLayers;
|
|
|
|
PRPackedBool mInvalidateAllLayers;
|
2010-12-07 18:24:05 -08:00
|
|
|
/** Layer manager we belong to, we hold a reference to this object. */
|
|
|
|
nsRefPtr<LayerManager> mLayerManager;
|
2010-07-15 14:07:51 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
static void DestroyRegion(void* aPropertyValue)
|
|
|
|
{
|
|
|
|
delete static_cast<nsRegion*>(aPropertyValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This property represents a region that should be invalidated in every
|
|
|
|
* ThebesLayer child whose parent ContainerLayer is associated with the
|
|
|
|
* frame. This is an nsRegion*; the coordinates of the region are
|
|
|
|
* relative to the top-left of the border-box of the frame the property
|
|
|
|
* is attached to (which is the frame for the ContainerLayer).
|
|
|
|
*
|
|
|
|
* We add to this region in InvalidateThebesLayerContents. The region
|
|
|
|
* is propagated to ContainerState in BuildContainerLayerFor, and then
|
|
|
|
* the region(s) are actually invalidated in CreateOrRecycleThebesLayer.
|
2010-08-30 17:46:26 -07:00
|
|
|
*
|
|
|
|
* When the property value is null, the region is infinite --- i.e. all
|
|
|
|
* areas of the ThebesLayers should be invalidated.
|
2010-07-15 14:07:51 -07:00
|
|
|
*/
|
|
|
|
NS_DECLARE_FRAME_PROPERTY(ThebesLayerInvalidRegionProperty, DestroyRegion)
|
|
|
|
|
2011-03-10 23:58:29 -08:00
|
|
|
static void DestroyPoint(void* aPropertyValue)
|
|
|
|
{
|
|
|
|
delete static_cast<nsPoint*>(aPropertyValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The valid content in our child ThebesLayers is defined relative to
|
|
|
|
* the offset from this frame to its active scroll root, mapped back
|
|
|
|
* by the ThebesLayer's inverse transform. Since we accumulate the
|
|
|
|
* region invalidated between last-paint and next-paint, and because
|
|
|
|
* the offset of this frame to its active root may change during that
|
|
|
|
* period, we save the offset at last-paint in this property and use
|
|
|
|
* it to invalidate at next-paint.
|
|
|
|
*/
|
|
|
|
NS_DECLARE_FRAME_PROPERTY(ThebesLayerLastPaintOffsetProperty, DestroyPoint)
|
|
|
|
|
2010-07-15 14:07:51 -07:00
|
|
|
/**
|
|
|
|
* This is a helper object used to build up the layer children for
|
|
|
|
* a ContainerLayer.
|
|
|
|
*/
|
|
|
|
class ContainerState {
|
|
|
|
public:
|
|
|
|
ContainerState(nsDisplayListBuilder* aBuilder,
|
|
|
|
LayerManager* aManager,
|
|
|
|
nsIFrame* aContainerFrame,
|
|
|
|
ContainerLayer* aContainerLayer) :
|
|
|
|
mBuilder(aBuilder), mManager(aManager),
|
|
|
|
mContainerFrame(aContainerFrame), mContainerLayer(aContainerLayer),
|
2010-07-15 14:08:03 -07:00
|
|
|
mNextFreeRecycledThebesLayer(0), mNextFreeRecycledColorLayer(0),
|
2011-01-17 13:47:18 -08:00
|
|
|
mNextFreeRecycledImageLayer(0), mInvalidateAllThebesContent(PR_FALSE)
|
2010-05-20 20:20:48 -07:00
|
|
|
{
|
2010-07-15 14:08:03 -07:00
|
|
|
CollectOldLayers();
|
2010-05-20 20:20:48 -07:00
|
|
|
}
|
2010-07-15 14:07:51 -07:00
|
|
|
|
|
|
|
void SetInvalidThebesContent(const nsIntRegion& aRegion)
|
2010-05-20 20:20:48 -07:00
|
|
|
{
|
2010-07-15 14:07:51 -07:00
|
|
|
mInvalidThebesContent = aRegion;
|
2010-05-20 20:20:48 -07:00
|
|
|
}
|
2010-07-15 14:07:51 -07:00
|
|
|
void SetInvalidateAllThebesContent()
|
2010-05-20 20:20:48 -07:00
|
|
|
{
|
2010-07-15 14:07:51 -07:00
|
|
|
mInvalidateAllThebesContent = PR_TRUE;
|
2010-05-20 20:20:48 -07:00
|
|
|
}
|
2010-07-15 14:07:51 -07:00
|
|
|
/**
|
|
|
|
* This is the method that actually walks a display list and builds
|
|
|
|
* the child layers. We invoke it recursively to process clipped sublists.
|
|
|
|
* @param aClipRect the clip rect to apply to the list items, or null
|
|
|
|
* if no clipping is required
|
|
|
|
*/
|
|
|
|
void ProcessDisplayItems(const nsDisplayList& aList,
|
2011-01-26 10:36:11 -08:00
|
|
|
FrameLayerBuilder::Clip& aClip);
|
2010-07-15 14:07:51 -07:00
|
|
|
/**
|
|
|
|
* This finalizes all the open ThebesLayers by popping every element off
|
|
|
|
* mThebesLayerDataStack, then sets the children of the container layer
|
|
|
|
* to be all the layers in mNewChildLayers in that order and removes any
|
|
|
|
* layers as children of the container that aren't in mNewChildLayers.
|
2010-12-19 17:26:14 -08:00
|
|
|
* @param aTextContentFlags if any child layer has CONTENT_COMPONENT_ALPHA,
|
|
|
|
* set *aTextContentFlags to CONTENT_COMPONENT_ALPHA
|
2010-07-15 14:07:51 -07:00
|
|
|
*/
|
2010-12-19 17:26:14 -08:00
|
|
|
void Finish(PRUint32 *aTextContentFlags);
|
2010-07-15 14:07:51 -07:00
|
|
|
|
2011-02-22 21:38:09 -08:00
|
|
|
nsRect GetChildrenBounds() { return mBounds; }
|
|
|
|
|
2010-07-15 14:07:51 -07:00
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* We keep a stack of these to represent the ThebesLayers that are
|
|
|
|
* currently available to have display items added to.
|
|
|
|
* We use a stack here because as much as possible we want to
|
|
|
|
* assign display items to existing ThebesLayers, and to the lowest
|
|
|
|
* ThebesLayer in z-order. This reduces the number of layers and
|
|
|
|
* makes it more likely a display item will be rendered to an opaque
|
|
|
|
* layer, giving us the best chance of getting subpixel AA.
|
|
|
|
*/
|
|
|
|
class ThebesLayerData {
|
|
|
|
public:
|
2010-07-15 14:08:03 -07:00
|
|
|
ThebesLayerData() :
|
|
|
|
mActiveScrolledRoot(nsnull), mLayer(nsnull),
|
2010-09-02 02:18:40 -07:00
|
|
|
mIsSolidColorInVisibleRegion(PR_FALSE),
|
2010-12-19 17:26:14 -08:00
|
|
|
mNeedComponentAlpha(PR_FALSE),
|
2011-01-17 13:47:18 -08:00
|
|
|
mForceTransparentSurface(PR_FALSE),
|
|
|
|
mImage(nsnull) {}
|
2010-07-15 14:07:51 -07:00
|
|
|
/**
|
|
|
|
* Record that an item has been added to the ThebesLayer, so we
|
|
|
|
* need to update our regions.
|
2010-07-15 14:08:11 -07:00
|
|
|
* @param aVisibleRect the area of the item that's visible
|
2010-08-01 20:06:58 -07:00
|
|
|
* @param aDrawRect the area of the item that would be drawn if it
|
|
|
|
* was completely visible
|
2010-07-15 14:08:11 -07:00
|
|
|
* @param aOpaqueRect if non-null, the area of the item that's opaque.
|
|
|
|
* We pass in a separate opaque rect because the opaque rect can be
|
|
|
|
* bigger than the visible rect, and we want to have the biggest
|
|
|
|
* opaque rect that we can.
|
|
|
|
* @param aSolidColor if non-null, the visible area of the item is
|
|
|
|
* a constant color given by *aSolidColor
|
2010-07-15 14:07:51 -07:00
|
|
|
*/
|
2010-09-02 02:18:39 -07:00
|
|
|
void Accumulate(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsDisplayItem* aItem,
|
|
|
|
const nsIntRect& aVisibleRect,
|
2011-01-02 17:48:09 -08:00
|
|
|
const nsIntRect& aDrawRect,
|
|
|
|
const FrameLayerBuilder::Clip& aClip);
|
2010-07-15 14:07:51 -07:00
|
|
|
nsIFrame* GetActiveScrolledRoot() { return mActiveScrolledRoot; }
|
|
|
|
|
2011-01-17 13:47:18 -08:00
|
|
|
/**
|
|
|
|
* If this represents only a nsDisplayImage, and the image type
|
|
|
|
* supports being optimized to an ImageLayer (TYPE_RASTER only) returns
|
|
|
|
* an ImageContainer for the image.
|
|
|
|
*/
|
|
|
|
nsRefPtr<ImageContainer> CanOptimizeImageLayer(LayerManager* aManager);
|
|
|
|
|
2010-07-15 14:07:51 -07:00
|
|
|
/**
|
|
|
|
* The region of visible content in the layer, relative to the
|
|
|
|
* container layer (which is at the snapped top-left of the display
|
|
|
|
* list reference frame).
|
|
|
|
*/
|
|
|
|
nsIntRegion mVisibleRegion;
|
|
|
|
/**
|
|
|
|
* The region of visible content above the layer and below the
|
|
|
|
* next ThebesLayerData currently in the stack, if any. Note that not
|
|
|
|
* all ThebesLayers for the container are in the ThebesLayerData stack.
|
|
|
|
* Same coordinate system as mVisibleRegion.
|
|
|
|
*/
|
|
|
|
nsIntRegion mVisibleAboveRegion;
|
2010-08-01 20:06:58 -07:00
|
|
|
/**
|
|
|
|
* The region containing the bounds of all display items in the layer,
|
|
|
|
* regardless of visbility.
|
|
|
|
* Same coordinate system as mVisibleRegion.
|
|
|
|
*/
|
|
|
|
nsIntRegion mDrawRegion;
|
|
|
|
/**
|
|
|
|
* The region containing the bounds of all display items (regardless
|
|
|
|
* of visibility) in the layer and below the next ThebesLayerData
|
|
|
|
* currently in the stack, if any.
|
|
|
|
* Note that not all ThebesLayers for the container are in the
|
|
|
|
* ThebesLayerData stack.
|
|
|
|
* Same coordinate system as mVisibleRegion.
|
|
|
|
*/
|
|
|
|
nsIntRegion mDrawAboveRegion;
|
2010-07-15 14:07:51 -07:00
|
|
|
/**
|
|
|
|
* The region of visible content in the layer that is opaque.
|
|
|
|
* Same coordinate system as mVisibleRegion.
|
|
|
|
*/
|
|
|
|
nsIntRegion mOpaqueRegion;
|
|
|
|
/**
|
|
|
|
* The "active scrolled root" for all content in the layer. Must
|
|
|
|
* be non-null; all content in a ThebesLayer must have the same
|
|
|
|
* active scrolled root.
|
|
|
|
*/
|
|
|
|
nsIFrame* mActiveScrolledRoot;
|
|
|
|
ThebesLayer* mLayer;
|
2010-07-15 14:08:03 -07:00
|
|
|
/**
|
|
|
|
* If mIsSolidColorInVisibleRegion is true, this is the color of the visible
|
|
|
|
* region.
|
|
|
|
*/
|
|
|
|
nscolor mSolidColor;
|
|
|
|
/**
|
|
|
|
* True if every pixel in mVisibleRegion will have color mSolidColor.
|
|
|
|
*/
|
|
|
|
PRPackedBool mIsSolidColorInVisibleRegion;
|
2010-09-02 02:18:40 -07:00
|
|
|
/**
|
|
|
|
* True if there is any text visible in the layer that's over
|
|
|
|
* transparent pixels in the layer.
|
|
|
|
*/
|
2010-12-19 17:26:14 -08:00
|
|
|
PRPackedBool mNeedComponentAlpha;
|
2010-10-19 10:02:25 -07:00
|
|
|
/**
|
|
|
|
* Set if the layer should be treated as transparent, even if its entire
|
|
|
|
* area is covered by opaque display items. For example, this needs to
|
|
|
|
* be set if something is going to "punch holes" in the layer by clearing
|
|
|
|
* part of its surface.
|
|
|
|
*/
|
|
|
|
PRPackedBool mForceTransparentSurface;
|
2011-01-17 13:47:18 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Stores the pointer to the nsDisplayImage if we want to
|
|
|
|
* convert this to an ImageLayer.
|
|
|
|
*/
|
|
|
|
nsDisplayImage* mImage;
|
2011-03-31 14:33:46 -07:00
|
|
|
/**
|
|
|
|
* Stores the clip that we need to apply to the image.
|
|
|
|
*/
|
|
|
|
FrameLayerBuilder::Clip mImageClip;
|
2010-05-20 20:20:48 -07:00
|
|
|
};
|
|
|
|
|
2010-07-15 14:07:51 -07:00
|
|
|
/**
|
|
|
|
* Grab the next recyclable ThebesLayer, or create one if there are no
|
|
|
|
* more recyclable ThebesLayers. Does any necessary invalidation of
|
|
|
|
* a recycled ThebesLayer, and sets up the transform on the ThebesLayer
|
2010-07-15 14:08:03 -07:00
|
|
|
* to account for scrolling.
|
2010-07-15 14:07:51 -07:00
|
|
|
*/
|
|
|
|
already_AddRefed<ThebesLayer> CreateOrRecycleThebesLayer(nsIFrame* aActiveScrolledRoot);
|
|
|
|
/**
|
2010-07-15 14:08:03 -07:00
|
|
|
* Grab the next recyclable ColorLayer, or create one if there are no
|
|
|
|
* more recyclable ColorLayers.
|
|
|
|
*/
|
|
|
|
already_AddRefed<ColorLayer> CreateOrRecycleColorLayer();
|
2011-01-17 13:47:18 -08:00
|
|
|
/**
|
|
|
|
* Grab the next recyclable ImageLayer, or create one if there are no
|
|
|
|
* more recyclable ImageLayers.
|
|
|
|
*/
|
|
|
|
already_AddRefed<ImageLayer> CreateOrRecycleImageLayer();
|
2010-07-15 14:08:03 -07:00
|
|
|
/**
|
|
|
|
* Grabs all ThebesLayers and ColorLayers from the ContainerLayer and makes them
|
2010-07-15 14:07:51 -07:00
|
|
|
* available for recycling.
|
|
|
|
*/
|
2010-07-15 14:08:03 -07:00
|
|
|
void CollectOldLayers();
|
2010-07-15 14:08:05 -07:00
|
|
|
/**
|
|
|
|
* If aItem used to belong to a ThebesLayer, invalidates the area of
|
|
|
|
* aItem in that layer. If aNewLayer is a ThebesLayer, invalidates the area of
|
|
|
|
* aItem in that layer.
|
|
|
|
*/
|
|
|
|
void InvalidateForLayerChange(nsDisplayItem* aItem, Layer* aNewLayer);
|
2010-09-02 02:18:39 -07:00
|
|
|
/**
|
|
|
|
* Try to determine whether the ThebesLayer at aThebesLayerIndex
|
2011-01-04 02:35:57 -08:00
|
|
|
* has a single opaque color behind it, over the entire bounds of its visible
|
|
|
|
* region.
|
2010-09-02 02:18:39 -07:00
|
|
|
* If successful, return that color, otherwise return NS_RGBA(0,0,0,0).
|
|
|
|
*/
|
|
|
|
nscolor FindOpaqueBackgroundColorFor(PRInt32 aThebesLayerIndex);
|
2010-07-15 14:07:51 -07:00
|
|
|
/**
|
|
|
|
* Indicate that we are done adding items to the ThebesLayer at the top of
|
|
|
|
* mThebesLayerDataStack. Set the final visible region and opaque-content
|
|
|
|
* flag, and pop it off the stack.
|
|
|
|
*/
|
|
|
|
void PopThebesLayerData();
|
|
|
|
/**
|
|
|
|
* Find the ThebesLayer to which we should assign the next display item.
|
2010-08-01 20:06:58 -07:00
|
|
|
* We scan the ThebesLayerData stack to find the topmost ThebesLayer
|
|
|
|
* that is compatible with the display item (i.e., has the same
|
|
|
|
* active scrolled root), and that has no content from other layers above
|
|
|
|
* it and intersecting the aVisibleRect.
|
2010-07-15 14:07:51 -07:00
|
|
|
* Returns the layer, and also updates the ThebesLayerData. Will
|
2010-08-01 20:06:58 -07:00
|
|
|
* push a new ThebesLayerData onto the stack if no suitable existing
|
|
|
|
* layer is found. If we choose a ThebesLayer that's already on the
|
|
|
|
* ThebesLayerData stack, later elements on the stack will be popped off.
|
2010-07-15 14:07:51 -07:00
|
|
|
* @param aVisibleRect the area of the next display item that's visible
|
|
|
|
* @param aActiveScrolledRoot the active scrolled root for the next
|
|
|
|
* display item
|
2010-07-15 14:08:11 -07:00
|
|
|
* @param aOpaqueRect if non-null, a region of the display item that is opaque
|
2010-07-15 14:08:03 -07:00
|
|
|
* @param aSolidColor if non-null, indicates that every pixel in aVisibleRect
|
|
|
|
* will be painted with aSolidColor by the item
|
2010-07-15 14:07:51 -07:00
|
|
|
*/
|
2010-09-02 02:18:39 -07:00
|
|
|
already_AddRefed<ThebesLayer> FindThebesLayerFor(nsDisplayItem* aItem,
|
|
|
|
const nsIntRect& aVisibleRect,
|
2010-08-01 20:06:58 -07:00
|
|
|
const nsIntRect& aDrawRect,
|
2011-01-02 17:48:09 -08:00
|
|
|
const FrameLayerBuilder::Clip& aClip,
|
2010-09-02 02:18:39 -07:00
|
|
|
nsIFrame* aActiveScrolledRoot);
|
2010-07-15 14:07:51 -07:00
|
|
|
ThebesLayerData* GetTopThebesLayerData()
|
2010-05-20 20:20:48 -07:00
|
|
|
{
|
2010-07-15 14:07:51 -07:00
|
|
|
return mThebesLayerDataStack.IsEmpty() ? nsnull
|
|
|
|
: mThebesLayerDataStack[mThebesLayerDataStack.Length() - 1].get();
|
2010-05-20 20:20:48 -07:00
|
|
|
}
|
|
|
|
|
2010-07-15 14:07:51 -07:00
|
|
|
nsDisplayListBuilder* mBuilder;
|
|
|
|
LayerManager* mManager;
|
|
|
|
nsIFrame* mContainerFrame;
|
|
|
|
ContainerLayer* mContainerLayer;
|
|
|
|
/**
|
|
|
|
* The region of ThebesLayers that should be invalidated every time
|
|
|
|
* we recycle one.
|
|
|
|
*/
|
|
|
|
nsIntRegion mInvalidThebesContent;
|
2011-02-22 21:38:09 -08:00
|
|
|
nsRect mBounds;
|
2010-07-15 14:07:51 -07:00
|
|
|
nsAutoTArray<nsAutoPtr<ThebesLayerData>,1> mThebesLayerDataStack;
|
|
|
|
/**
|
|
|
|
* We collect the list of children in here. During ProcessDisplayItems,
|
|
|
|
* the layers in this array either have mContainerLayer as their parent,
|
|
|
|
* or no parent.
|
|
|
|
*/
|
2010-11-08 18:48:59 -08:00
|
|
|
typedef nsAutoTArray<nsRefPtr<Layer>,1> AutoLayersArray;
|
|
|
|
AutoLayersArray mNewChildLayers;
|
2010-07-15 14:07:51 -07:00
|
|
|
nsTArray<nsRefPtr<ThebesLayer> > mRecycledThebesLayers;
|
2010-07-15 14:08:03 -07:00
|
|
|
nsTArray<nsRefPtr<ColorLayer> > mRecycledColorLayers;
|
2011-01-17 13:47:18 -08:00
|
|
|
nsTArray<nsRefPtr<ImageLayer> > mRecycledImageLayers;
|
2010-07-15 14:07:51 -07:00
|
|
|
PRUint32 mNextFreeRecycledThebesLayer;
|
2010-07-15 14:08:03 -07:00
|
|
|
PRUint32 mNextFreeRecycledColorLayer;
|
2011-01-17 13:47:18 -08:00
|
|
|
PRUint32 mNextFreeRecycledImageLayer;
|
2010-07-15 14:07:51 -07:00
|
|
|
PRPackedBool mInvalidateAllThebesContent;
|
2010-05-20 20:20:48 -07:00
|
|
|
};
|
|
|
|
|
2010-09-02 02:18:39 -07:00
|
|
|
class ThebesDisplayItemLayerUserData : public LayerUserData
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ThebesDisplayItemLayerUserData() :
|
|
|
|
mForcedBackgroundColor(NS_RGBA(0,0,0,0)) {}
|
|
|
|
|
2011-01-04 02:35:57 -08:00
|
|
|
/**
|
|
|
|
* A color that should be painted over the bounds of the layer's visible
|
|
|
|
* region before any other content is painted.
|
|
|
|
*/
|
2010-09-02 02:18:39 -07:00
|
|
|
nscolor mForcedBackgroundColor;
|
|
|
|
};
|
|
|
|
|
2010-05-20 20:20:48 -07:00
|
|
|
/**
|
2010-07-15 14:07:51 -07:00
|
|
|
* The address of gThebesDisplayItemLayerUserData is used as the user
|
2010-09-02 02:18:39 -07:00
|
|
|
* data key for ThebesLayers created by FrameLayerBuilder.
|
2010-07-15 14:07:51 -07:00
|
|
|
* It identifies ThebesLayers used to draw non-layer content, which are
|
|
|
|
* therefore eligible for recycling. We want display items to be able to
|
|
|
|
* create their own dedicated ThebesLayers in BuildLayer, if necessary,
|
|
|
|
* and we wouldn't want to accidentally recycle those.
|
2010-09-02 02:18:39 -07:00
|
|
|
* The user data is a ThebesDisplayItemLayerUserData.
|
2010-05-20 20:20:48 -07:00
|
|
|
*/
|
2010-09-02 02:18:39 -07:00
|
|
|
PRUint8 gThebesDisplayItemLayerUserData;
|
2010-07-15 14:08:03 -07:00
|
|
|
/**
|
|
|
|
* The address of gColorLayerUserData is used as the user
|
2010-09-02 02:18:39 -07:00
|
|
|
* data key for ColorLayers created by FrameLayerBuilder.
|
|
|
|
* The user data is null.
|
2010-07-15 14:08:03 -07:00
|
|
|
*/
|
2010-09-02 02:18:39 -07:00
|
|
|
PRUint8 gColorLayerUserData;
|
2011-01-17 13:47:18 -08:00
|
|
|
/**
|
|
|
|
* The address of gImageLayerUserData is used as the user
|
|
|
|
* data key for ImageLayers created by FrameLayerBuilder.
|
|
|
|
* The user data is null.
|
|
|
|
*/
|
|
|
|
PRUint8 gImageLayerUserData;
|
2010-09-02 02:18:39 -07:00
|
|
|
/**
|
|
|
|
* The address of gLayerManagerUserData is used as the user
|
|
|
|
* data key for retained LayerManagers managed by FrameLayerBuilder.
|
|
|
|
* The user data is a LayerManagerData.
|
|
|
|
*/
|
|
|
|
PRUint8 gLayerManagerUserData;
|
2010-07-15 14:07:51 -07:00
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
2010-09-17 12:09:08 -07:00
|
|
|
void
|
|
|
|
FrameLayerBuilder::Init(nsDisplayListBuilder* aBuilder)
|
|
|
|
{
|
|
|
|
mRootPresContext = aBuilder->ReferenceFrame()->PresContext()->GetRootPresContext();
|
|
|
|
if (mRootPresContext) {
|
|
|
|
mInitialDOMGeneration = mRootPresContext->GetDOMGeneration();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-15 14:07:51 -07:00
|
|
|
PRBool
|
|
|
|
FrameLayerBuilder::DisplayItemDataEntry::HasContainerLayer()
|
|
|
|
{
|
|
|
|
for (PRUint32 i = 0; i < mData.Length(); ++i) {
|
|
|
|
if (mData[i].mLayer->GetType() == Layer::TYPE_CONTAINER)
|
|
|
|
return PR_TRUE;
|
2010-05-20 20:20:48 -07:00
|
|
|
}
|
2010-07-15 14:07:51 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2010-05-20 20:20:48 -07:00
|
|
|
|
2010-07-15 14:07:51 -07:00
|
|
|
/* static */ void
|
|
|
|
FrameLayerBuilder::InternalDestroyDisplayItemData(nsIFrame* aFrame,
|
|
|
|
void* aPropertyValue,
|
|
|
|
PRBool aRemoveFromFramesWithLayers)
|
|
|
|
{
|
|
|
|
nsRefPtr<LayerManager> managerRef;
|
|
|
|
nsTArray<DisplayItemData>* array =
|
|
|
|
reinterpret_cast<nsTArray<DisplayItemData>*>(&aPropertyValue);
|
|
|
|
NS_ASSERTION(!array->IsEmpty(), "Empty arrays should not be stored");
|
|
|
|
|
|
|
|
if (aRemoveFromFramesWithLayers) {
|
|
|
|
LayerManager* manager = array->ElementAt(0).mLayer->Manager();
|
|
|
|
LayerManagerData* data = static_cast<LayerManagerData*>
|
2010-09-02 02:18:39 -07:00
|
|
|
(manager->GetUserData(&gLayerManagerUserData));
|
2010-07-15 14:07:51 -07:00
|
|
|
NS_ASSERTION(data, "Frame with layer should have been recorded");
|
|
|
|
data->mFramesWithLayers.RemoveEntry(aFrame);
|
|
|
|
if (data->mFramesWithLayers.Count() == 0) {
|
2010-12-07 18:24:05 -08:00
|
|
|
// Destroying our user data will consume a reference from the layer
|
|
|
|
// manager. But don't actually release until we've released all the layers
|
|
|
|
// in the DisplayItemData array below!
|
2010-07-15 14:07:51 -07:00
|
|
|
managerRef = manager;
|
2010-12-07 18:24:05 -08:00
|
|
|
manager->RemoveUserData(&gLayerManagerUserData);
|
2010-07-15 14:07:51 -07:00
|
|
|
}
|
2010-05-20 20:20:48 -07:00
|
|
|
}
|
|
|
|
|
2010-07-15 14:07:51 -07:00
|
|
|
array->~nsTArray<DisplayItemData>();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
FrameLayerBuilder::DestroyDisplayItemData(nsIFrame* aFrame,
|
|
|
|
void* aPropertyValue)
|
|
|
|
{
|
|
|
|
InternalDestroyDisplayItemData(aFrame, aPropertyValue, PR_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-01-19 00:27:54 -08:00
|
|
|
FrameLayerBuilder::DidBeginRetainedLayerTransaction(LayerManager* aManager)
|
2010-07-15 14:07:51 -07:00
|
|
|
{
|
|
|
|
mRetainingManager = aManager;
|
|
|
|
LayerManagerData* data = static_cast<LayerManagerData*>
|
2010-09-02 02:18:39 -07:00
|
|
|
(aManager->GetUserData(&gLayerManagerUserData));
|
2010-07-15 14:07:51 -07:00
|
|
|
if (data) {
|
|
|
|
mInvalidateAllLayers = data->mInvalidateAllLayers;
|
2010-05-20 20:20:48 -07:00
|
|
|
}
|
2010-07-15 14:07:51 -07:00
|
|
|
}
|
2010-05-20 20:20:48 -07:00
|
|
|
|
|
|
|
/**
|
2010-07-15 14:07:51 -07:00
|
|
|
* A helper function to remove the mThebesLayerItems entries for every
|
|
|
|
* layer in aLayer's subtree.
|
2010-05-20 20:20:48 -07:00
|
|
|
*/
|
2010-07-15 14:07:51 -07:00
|
|
|
void
|
|
|
|
FrameLayerBuilder::RemoveThebesItemsForLayerSubtree(Layer* aLayer)
|
|
|
|
{
|
|
|
|
ThebesLayer* thebes = aLayer->AsThebesLayer();
|
|
|
|
if (thebes) {
|
|
|
|
mThebesLayerItems.RemoveEntry(thebes);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Layer* child = aLayer->GetFirstChild(); child;
|
|
|
|
child = child->GetNextSibling()) {
|
|
|
|
RemoveThebesItemsForLayerSubtree(child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FrameLayerBuilder::DidEndTransaction(LayerManager* aManager)
|
|
|
|
{
|
|
|
|
if (aManager != mRetainingManager) {
|
|
|
|
Layer* root = aManager->GetRoot();
|
|
|
|
if (root) {
|
|
|
|
RemoveThebesItemsForLayerSubtree(root);
|
2010-05-20 20:20:48 -07:00
|
|
|
}
|
|
|
|
}
|
2010-07-15 14:08:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FrameLayerBuilder::WillEndTransaction(LayerManager* aManager)
|
|
|
|
{
|
|
|
|
if (aManager != mRetainingManager)
|
|
|
|
return;
|
2010-05-20 20:20:48 -07:00
|
|
|
|
2010-07-15 14:08:11 -07:00
|
|
|
// We need to save the data we'll need to support retaining. We do this
|
|
|
|
// before we paint so that invalidation triggered by painting will
|
|
|
|
// be able to update the ThebesLayerInvalidRegionProperty values
|
|
|
|
// correctly and the NS_FRAME_HAS_CONTAINER_LAYER bits will be set
|
|
|
|
// correctly.
|
2010-07-15 14:07:51 -07:00
|
|
|
LayerManagerData* data = static_cast<LayerManagerData*>
|
2010-09-02 02:18:39 -07:00
|
|
|
(mRetainingManager->GetUserData(&gLayerManagerUserData));
|
2010-07-15 14:07:51 -07:00
|
|
|
if (data) {
|
|
|
|
// Update all the frames that used to have layers.
|
|
|
|
data->mFramesWithLayers.EnumerateEntries(UpdateDisplayItemDataForFrame, this);
|
|
|
|
} else {
|
2010-12-07 18:24:05 -08:00
|
|
|
data = new LayerManagerData(mRetainingManager);
|
2010-09-02 02:18:39 -07:00
|
|
|
mRetainingManager->SetUserData(&gLayerManagerUserData, data);
|
2010-05-20 20:20:48 -07:00
|
|
|
}
|
2010-07-15 14:07:51 -07:00
|
|
|
// Now go through all the frames that didn't have any retained
|
|
|
|
// display items before, and record those retained display items.
|
|
|
|
// This also empties mNewDisplayItemData.
|
|
|
|
mNewDisplayItemData.EnumerateEntries(StoreNewDisplayItemData, data);
|
|
|
|
data->mInvalidateAllLayers = PR_FALSE;
|
2010-05-20 20:20:48 -07:00
|
|
|
|
2010-07-15 14:07:51 -07:00
|
|
|
NS_ASSERTION(data->mFramesWithLayers.Count() > 0,
|
|
|
|
"Some frame must have a layer!");
|
2010-05-20 20:20:48 -07:00
|
|
|
}
|
|
|
|
|
2011-03-10 23:58:29 -08:00
|
|
|
static void
|
|
|
|
SetHasContainerLayer(nsIFrame* aFrame, nsPoint aOffsetToRoot)
|
|
|
|
{
|
|
|
|
aFrame->AddStateBits(NS_FRAME_HAS_CONTAINER_LAYER);
|
|
|
|
for (nsIFrame* f = aFrame;
|
|
|
|
f && !(f->GetStateBits() & NS_FRAME_HAS_CONTAINER_LAYER_DESCENDANT);
|
|
|
|
f = nsLayoutUtils::GetCrossDocParentFrame(f)) {
|
|
|
|
f->AddStateBits(NS_FRAME_HAS_CONTAINER_LAYER_DESCENDANT);
|
|
|
|
}
|
|
|
|
|
|
|
|
FrameProperties props = aFrame->Properties();
|
|
|
|
nsPoint* lastPaintOffset = static_cast<nsPoint*>
|
|
|
|
(props.Get(ThebesLayerLastPaintOffsetProperty()));
|
|
|
|
if (lastPaintOffset) {
|
|
|
|
*lastPaintOffset = aOffsetToRoot;
|
|
|
|
} else {
|
|
|
|
props.Set(ThebesLayerLastPaintOffsetProperty(), new nsPoint(aOffsetToRoot));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
SetNoContainerLayer(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
FrameProperties props = aFrame->Properties();
|
|
|
|
props.Delete(ThebesLayerInvalidRegionProperty());
|
|
|
|
props.Delete(ThebesLayerLastPaintOffsetProperty());
|
|
|
|
aFrame->RemoveStateBits(NS_FRAME_HAS_CONTAINER_LAYER);
|
|
|
|
}
|
|
|
|
|
2010-07-15 14:07:51 -07:00
|
|
|
/* static */ PLDHashOperator
|
|
|
|
FrameLayerBuilder::UpdateDisplayItemDataForFrame(nsPtrHashKey<nsIFrame>* aEntry,
|
|
|
|
void* aUserArg)
|
2010-05-20 20:20:48 -07:00
|
|
|
{
|
2010-07-15 14:07:51 -07:00
|
|
|
FrameLayerBuilder* builder = static_cast<FrameLayerBuilder*>(aUserArg);
|
|
|
|
nsIFrame* f = aEntry->GetKey();
|
|
|
|
FrameProperties props = f->Properties();
|
|
|
|
DisplayItemDataEntry* newDisplayItems =
|
2010-09-02 02:18:39 -07:00
|
|
|
builder ? builder->mNewDisplayItemData.GetEntry(f) : nsnull;
|
2010-07-15 14:07:51 -07:00
|
|
|
if (!newDisplayItems) {
|
|
|
|
// This frame was visible, but isn't anymore.
|
|
|
|
PRBool found;
|
|
|
|
void* prop = props.Remove(DisplayItemDataProperty(), &found);
|
|
|
|
NS_ASSERTION(found, "How can the frame property be missing?");
|
|
|
|
// Pass PR_FALSE to not remove from mFramesWithLayers, we'll remove it
|
|
|
|
// by returning PL_DHASH_REMOVE below.
|
|
|
|
// Note that DestroyDisplayItemData would delete the user data
|
|
|
|
// for the retained layer manager if it removed the last entry from
|
|
|
|
// mFramesWithLayers, but we won't. That's OK because our caller
|
|
|
|
// is DidEndTransaction, which would recreate the user data
|
|
|
|
// anyway.
|
|
|
|
InternalDestroyDisplayItemData(f, prop, PR_FALSE);
|
2011-03-10 23:58:29 -08:00
|
|
|
SetNoContainerLayer(f);
|
2010-07-15 14:07:51 -07:00
|
|
|
return PL_DHASH_REMOVE;
|
|
|
|
}
|
|
|
|
|
2010-08-30 17:46:26 -07:00
|
|
|
if (newDisplayItems->HasContainerLayer()) {
|
|
|
|
// Reset or create the invalid region now so we can start collecting
|
|
|
|
// new dirty areas.
|
2010-09-01 21:43:45 -07:00
|
|
|
// Note that the NS_FRAME_HAS_CONTAINER_LAYER bit is set in
|
|
|
|
// BuildContainerLayerFor, so we don't need to set it here.
|
2010-08-30 17:46:26 -07:00
|
|
|
nsRegion* invalidRegion = static_cast<nsRegion*>
|
|
|
|
(props.Get(ThebesLayerInvalidRegionProperty()));
|
|
|
|
if (invalidRegion) {
|
|
|
|
invalidRegion->SetEmpty();
|
|
|
|
} else {
|
|
|
|
props.Set(ThebesLayerInvalidRegionProperty(), new nsRegion());
|
|
|
|
}
|
|
|
|
} else {
|
2011-03-10 23:58:29 -08:00
|
|
|
SetNoContainerLayer(f);
|
2010-07-15 14:07:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// We need to remove and re-add the DisplayItemDataProperty in
|
|
|
|
// case the nsTArray changes the value of its mHdr.
|
|
|
|
void* propValue = props.Remove(DisplayItemDataProperty());
|
|
|
|
NS_ASSERTION(propValue, "mFramesWithLayers out of sync");
|
|
|
|
PR_STATIC_ASSERT(sizeof(nsTArray<DisplayItemData>) == sizeof(void*));
|
|
|
|
nsTArray<DisplayItemData>* array =
|
|
|
|
reinterpret_cast<nsTArray<DisplayItemData>*>(&propValue);
|
|
|
|
// Steal the list of display item layers
|
|
|
|
array->SwapElements(newDisplayItems->mData);
|
|
|
|
props.Set(DisplayItemDataProperty(), propValue);
|
|
|
|
// Don't need to process this frame again
|
|
|
|
builder->mNewDisplayItemData.RawRemoveEntry(newDisplayItems);
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ PLDHashOperator
|
|
|
|
FrameLayerBuilder::StoreNewDisplayItemData(DisplayItemDataEntry* aEntry,
|
|
|
|
void* aUserArg)
|
|
|
|
{
|
|
|
|
LayerManagerData* data = static_cast<LayerManagerData*>(aUserArg);
|
|
|
|
nsIFrame* f = aEntry->GetKey();
|
2010-09-01 21:43:45 -07:00
|
|
|
FrameProperties props = f->Properties();
|
2010-07-15 14:07:51 -07:00
|
|
|
// Remember that this frame has display items in retained layers
|
|
|
|
NS_ASSERTION(!data->mFramesWithLayers.GetEntry(f),
|
|
|
|
"We shouldn't get here if we're already in mFramesWithLayers");
|
|
|
|
data->mFramesWithLayers.PutEntry(f);
|
2010-09-01 21:43:45 -07:00
|
|
|
NS_ASSERTION(!props.Get(DisplayItemDataProperty()),
|
2010-07-15 14:07:51 -07:00
|
|
|
"mFramesWithLayers out of sync");
|
|
|
|
|
|
|
|
void* propValue;
|
|
|
|
nsTArray<DisplayItemData>* array =
|
|
|
|
new (&propValue) nsTArray<DisplayItemData>();
|
|
|
|
// Steal the list of display item layers
|
|
|
|
array->SwapElements(aEntry->mData);
|
|
|
|
// Save it
|
2010-09-01 21:43:45 -07:00
|
|
|
props.Set(DisplayItemDataProperty(), propValue);
|
2010-07-15 14:07:51 -07:00
|
|
|
|
2010-09-01 21:43:45 -07:00
|
|
|
if (f->GetStateBits() & NS_FRAME_HAS_CONTAINER_LAYER) {
|
|
|
|
props.Set(ThebesLayerInvalidRegionProperty(), new nsRegion());
|
|
|
|
}
|
2010-07-15 14:07:51 -07:00
|
|
|
return PL_DHASH_REMOVE;
|
|
|
|
}
|
|
|
|
|
2011-02-10 00:58:11 -08:00
|
|
|
PRBool
|
|
|
|
FrameLayerBuilder::HasRetainedLayerFor(nsIFrame* aFrame, PRUint32 aDisplayItemKey)
|
|
|
|
{
|
|
|
|
void* propValue = aFrame->Properties().Get(DisplayItemDataProperty());
|
|
|
|
if (!propValue)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
nsTArray<DisplayItemData>* array =
|
|
|
|
(reinterpret_cast<nsTArray<DisplayItemData>*>(&propValue));
|
|
|
|
for (PRUint32 i = 0; i < array->Length(); ++i) {
|
|
|
|
if (array->ElementAt(i).mDisplayItemKey == aDisplayItemKey) {
|
|
|
|
Layer* layer = array->ElementAt(i).mLayer;
|
|
|
|
if (layer->Manager()->GetUserData(&gLayerManagerUserData)) {
|
|
|
|
// All layer managers with our user data are retained layer managers
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2010-07-15 14:07:51 -07:00
|
|
|
Layer*
|
|
|
|
FrameLayerBuilder::GetOldLayerFor(nsIFrame* aFrame, PRUint32 aDisplayItemKey)
|
|
|
|
{
|
|
|
|
// If we need to build a new layer tree, then just refuse to recycle
|
|
|
|
// anything.
|
|
|
|
if (!mRetainingManager || mInvalidateAllLayers)
|
2010-05-20 20:20:48 -07:00
|
|
|
return nsnull;
|
2010-07-15 14:07:51 -07:00
|
|
|
|
|
|
|
void* propValue = aFrame->Properties().Get(DisplayItemDataProperty());
|
|
|
|
if (!propValue)
|
2010-05-20 20:20:48 -07:00
|
|
|
return nsnull;
|
2010-07-15 14:07:51 -07:00
|
|
|
|
|
|
|
nsTArray<DisplayItemData>* array =
|
|
|
|
(reinterpret_cast<nsTArray<DisplayItemData>*>(&propValue));
|
|
|
|
for (PRUint32 i = 0; i < array->Length(); ++i) {
|
|
|
|
if (array->ElementAt(i).mDisplayItemKey == aDisplayItemKey) {
|
|
|
|
Layer* layer = array->ElementAt(i).mLayer;
|
|
|
|
if (layer->Manager() == mRetainingManager)
|
|
|
|
return layer;
|
2010-05-20 20:20:48 -07:00
|
|
|
}
|
|
|
|
}
|
2010-07-15 14:07:51 -07:00
|
|
|
return nsnull;
|
2010-05-20 20:20:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-07-15 14:07:51 -07:00
|
|
|
* Invalidate aRegion in aLayer. aLayer is in the coordinate system
|
|
|
|
* *after* aLayer's transform has been applied, so we need to
|
|
|
|
* apply the inverse of that transform before calling InvalidateRegion.
|
|
|
|
* Currently we assume that the transform is just an integer translation,
|
|
|
|
* since that's all we need for scrolling.
|
2010-05-20 20:20:48 -07:00
|
|
|
*/
|
2010-07-15 14:07:51 -07:00
|
|
|
static void
|
|
|
|
InvalidatePostTransformRegion(ThebesLayer* aLayer, const nsIntRegion& aRegion)
|
|
|
|
{
|
|
|
|
gfxMatrix transform;
|
|
|
|
if (aLayer->GetTransform().Is2D(&transform)) {
|
|
|
|
NS_ASSERTION(!transform.HasNonIntegerTranslation(),
|
|
|
|
"Matrix not just an integer translation?");
|
|
|
|
// Convert the region from the coordinates of the container layer
|
|
|
|
// (relative to the snapped top-left of the display list reference frame)
|
|
|
|
// to the ThebesLayer's own coordinates
|
|
|
|
nsIntRegion rgn = aRegion;
|
|
|
|
rgn.MoveBy(-nsIntPoint(PRInt32(transform.x0), PRInt32(transform.y0)));
|
|
|
|
aLayer->InvalidateRegion(rgn);
|
|
|
|
} else {
|
|
|
|
NS_ERROR("Only 2D transformations currently supported");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-15 14:08:03 -07:00
|
|
|
already_AddRefed<ColorLayer>
|
|
|
|
ContainerState::CreateOrRecycleColorLayer()
|
|
|
|
{
|
|
|
|
nsRefPtr<ColorLayer> layer;
|
|
|
|
if (mNextFreeRecycledColorLayer < mRecycledColorLayers.Length()) {
|
|
|
|
// Recycle a layer
|
|
|
|
layer = mRecycledColorLayers[mNextFreeRecycledColorLayer];
|
|
|
|
++mNextFreeRecycledColorLayer;
|
|
|
|
// Clear clip rect so we don't accidentally stay clipped. We will
|
|
|
|
// reapply any necessary clipping.
|
|
|
|
layer->SetClipRect(nsnull);
|
|
|
|
} else {
|
|
|
|
// Create a new layer
|
|
|
|
layer = mManager->CreateColorLayer();
|
|
|
|
if (!layer)
|
|
|
|
return nsnull;
|
|
|
|
// Mark this layer as being used for Thebes-painting display items
|
2010-09-02 02:18:39 -07:00
|
|
|
layer->SetUserData(&gColorLayerUserData, nsnull);
|
2010-07-15 14:08:03 -07:00
|
|
|
}
|
|
|
|
return layer.forget();
|
|
|
|
}
|
|
|
|
|
2011-01-17 13:47:18 -08:00
|
|
|
already_AddRefed<ImageLayer>
|
|
|
|
ContainerState::CreateOrRecycleImageLayer()
|
|
|
|
{
|
|
|
|
nsRefPtr<ImageLayer> layer;
|
|
|
|
if (mNextFreeRecycledImageLayer < mRecycledImageLayers.Length()) {
|
|
|
|
// Recycle a layer
|
|
|
|
layer = mRecycledImageLayers[mNextFreeRecycledImageLayer];
|
|
|
|
++mNextFreeRecycledImageLayer;
|
|
|
|
// Clear clip rect so we don't accidentally stay clipped. We will
|
|
|
|
// reapply any necessary clipping.
|
|
|
|
layer->SetClipRect(nsnull);
|
|
|
|
} else {
|
|
|
|
// Create a new layer
|
|
|
|
layer = mManager->CreateImageLayer();
|
|
|
|
if (!layer)
|
|
|
|
return nsnull;
|
|
|
|
// Mark this layer as being used for Thebes-painting display items
|
|
|
|
layer->SetUserData(&gImageLayerUserData, nsnull);
|
|
|
|
}
|
|
|
|
return layer.forget();
|
|
|
|
}
|
|
|
|
|
2010-07-15 14:07:51 -07:00
|
|
|
already_AddRefed<ThebesLayer>
|
|
|
|
ContainerState::CreateOrRecycleThebesLayer(nsIFrame* aActiveScrolledRoot)
|
|
|
|
{
|
|
|
|
// We need a new thebes layer
|
|
|
|
nsRefPtr<ThebesLayer> layer;
|
2010-07-15 14:08:03 -07:00
|
|
|
if (mNextFreeRecycledThebesLayer < mRecycledThebesLayers.Length()) {
|
2010-07-15 14:07:51 -07:00
|
|
|
// Recycle a layer
|
|
|
|
layer = mRecycledThebesLayers[mNextFreeRecycledThebesLayer];
|
|
|
|
++mNextFreeRecycledThebesLayer;
|
2010-07-15 14:08:03 -07:00
|
|
|
// Clear clip rect so we don't accidentally stay clipped. We will
|
|
|
|
// reapply any necessary clipping.
|
|
|
|
layer->SetClipRect(nsnull);
|
2010-07-15 14:07:51 -07:00
|
|
|
|
|
|
|
// This gets called on recycled ThebesLayers that are going to be in the
|
|
|
|
// final layer tree, so it's a convenient time to invalidate the
|
|
|
|
// content that changed where we don't know what ThebesLayer it belonged
|
|
|
|
// to, or if we need to invalidate the entire layer, we can do that.
|
|
|
|
// This needs to be done before we update the ThebesLayer to its new
|
|
|
|
// transform. See nsGfxScrollFrame::InvalidateInternal, where
|
|
|
|
// we ensure that mInvalidThebesContent is updated according to the
|
|
|
|
// scroll position as of the most recent paint.
|
|
|
|
if (mInvalidateAllThebesContent) {
|
|
|
|
nsIntRect invalidate = layer->GetValidRegion().GetBounds();
|
|
|
|
layer->InvalidateRegion(invalidate);
|
2010-05-20 20:20:48 -07:00
|
|
|
} else {
|
2010-07-15 14:07:51 -07:00
|
|
|
InvalidatePostTransformRegion(layer, mInvalidThebesContent);
|
|
|
|
}
|
|
|
|
// We do not need to Invalidate these areas in the widget because we
|
2011-02-10 15:21:07 -08:00
|
|
|
// assume the caller of InvalidateThebesLayerContents has ensured
|
2010-07-15 14:07:51 -07:00
|
|
|
// the area is invalidated in the widget.
|
|
|
|
} else {
|
|
|
|
// Create a new thebes layer
|
|
|
|
layer = mManager->CreateThebesLayer();
|
|
|
|
if (!layer)
|
|
|
|
return nsnull;
|
|
|
|
// Mark this layer as being used for Thebes-painting display items
|
2010-09-02 02:18:39 -07:00
|
|
|
layer->SetUserData(&gThebesDisplayItemLayerUserData,
|
|
|
|
new ThebesDisplayItemLayerUserData());
|
2010-07-15 14:07:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set up transform so that 0,0 in the Thebes layer corresponds to the
|
|
|
|
// (pixel-snapped) top-left of the aActiveScrolledRoot.
|
|
|
|
nsPoint offset = mBuilder->ToReferenceFrame(aActiveScrolledRoot);
|
|
|
|
nsIntPoint pixOffset = offset.ToNearestPixels(
|
|
|
|
aActiveScrolledRoot->PresContext()->AppUnitsPerDevPixel());
|
|
|
|
gfxMatrix matrix;
|
|
|
|
matrix.Translate(gfxPoint(pixOffset.x, pixOffset.y));
|
|
|
|
layer->SetTransform(gfx3DMatrix::From2D(matrix));
|
|
|
|
|
|
|
|
return layer.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the appunits per dev pixel for the item's frame. The item must
|
|
|
|
* have a frame because only nsDisplayClip items don't have a frame,
|
|
|
|
* and those items are flattened away by ProcessDisplayItems.
|
|
|
|
*/
|
2010-09-01 21:46:53 -07:00
|
|
|
static PRInt32
|
2010-07-15 14:07:51 -07:00
|
|
|
AppUnitsPerDevPixel(nsDisplayItem* aItem)
|
|
|
|
{
|
2010-08-08 11:49:06 -07:00
|
|
|
// The underlying frame for zoom items is the root frame of the subdocument.
|
|
|
|
// But zoom display items report their bounds etc using the parent document's
|
|
|
|
// APD because zoom items act as a conversion layer between the two different
|
|
|
|
// APDs.
|
|
|
|
if (aItem->GetType() == nsDisplayItem::TYPE_ZOOM) {
|
|
|
|
return static_cast<nsDisplayZoom*>(aItem)->GetParentAppUnitsPerDevPixel();
|
|
|
|
}
|
2010-07-15 14:07:51 -07:00
|
|
|
return aItem->GetUnderlyingFrame()->PresContext()->AppUnitsPerDevPixel();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-02-22 21:38:09 -08:00
|
|
|
* Restrict the visible region of aLayer to the region that is actually visible.
|
|
|
|
* Because we only reduce the visible region here, we don't need to worry
|
|
|
|
* about whether CONTENT_OPAQUE is set; if layer was opauqe in the old
|
|
|
|
* visible region, it will still be opaque in the new one.
|
|
|
|
* @param aItemVisible the visible region of the display item (that is,
|
|
|
|
* after any layer transform has been applied)
|
2010-07-15 14:07:51 -07:00
|
|
|
*/
|
|
|
|
static void
|
2011-02-22 21:38:09 -08:00
|
|
|
RestrictVisibleRegionForLayer(Layer* aLayer, const nsIntRect& aItemVisible)
|
2010-07-15 14:07:51 -07:00
|
|
|
{
|
|
|
|
gfxMatrix transform;
|
2011-02-22 21:38:09 -08:00
|
|
|
if (!aLayer->GetTransform().Is2D(&transform))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// if 'transform' is not invertible, then nothing will be displayed
|
|
|
|
// for the layer, so it doesn't really matter what we do here
|
|
|
|
gfxMatrix inverse = transform;
|
|
|
|
inverse.Invert();
|
|
|
|
gfxRect itemVisible(aItemVisible.x, aItemVisible.y, aItemVisible.width, aItemVisible.height);
|
|
|
|
gfxRect layerVisible = inverse.TransformBounds(itemVisible);
|
|
|
|
layerVisible.RoundOut();
|
|
|
|
|
|
|
|
nsIntRect visibleRect;
|
|
|
|
if (!gfxUtils::GfxRectToIntRect(layerVisible, &visibleRect))
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsIntRegion rgn = aLayer->GetVisibleRegion();
|
|
|
|
if (!visibleRect.Contains(rgn.GetBounds())) {
|
|
|
|
rgn.And(rgn, visibleRect);
|
|
|
|
aLayer->SetVisibleRegion(rgn);
|
2010-07-15 14:07:51 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-02 02:18:39 -07:00
|
|
|
nscolor
|
|
|
|
ContainerState::FindOpaqueBackgroundColorFor(PRInt32 aThebesLayerIndex)
|
|
|
|
{
|
|
|
|
ThebesLayerData* target = mThebesLayerDataStack[aThebesLayerIndex];
|
|
|
|
for (PRInt32 i = aThebesLayerIndex - 1; i >= 0; --i) {
|
|
|
|
ThebesLayerData* candidate = mThebesLayerDataStack[i];
|
|
|
|
nsIntRegion visibleAboveIntersection;
|
|
|
|
visibleAboveIntersection.And(candidate->mVisibleAboveRegion, target->mVisibleRegion);
|
|
|
|
if (!visibleAboveIntersection.IsEmpty()) {
|
|
|
|
// Some non-Thebes content between target and candidate; this is
|
|
|
|
// hopeless
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIntRegion intersection;
|
|
|
|
intersection.And(candidate->mVisibleRegion, target->mVisibleRegion);
|
|
|
|
if (intersection.IsEmpty()) {
|
|
|
|
// The layer doesn't intersect our target, ignore it and move on
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The candidate intersects our target. If any layer has a solid-color
|
|
|
|
// area behind our target, this must be it. Scan its display items.
|
|
|
|
nsPresContext* presContext = mContainerFrame->PresContext();
|
|
|
|
nscoord appUnitsPerDevPixel = presContext->AppUnitsPerDevPixel();
|
|
|
|
nsRect rect =
|
|
|
|
target->mVisibleRegion.GetBounds().ToAppUnits(appUnitsPerDevPixel);
|
|
|
|
return mBuilder->LayerBuilder()->
|
|
|
|
FindOpaqueColorCovering(mBuilder, candidate->mLayer, rect);
|
|
|
|
}
|
|
|
|
return NS_RGBA(0,0,0,0);
|
|
|
|
}
|
|
|
|
|
2011-01-17 13:47:18 -08:00
|
|
|
nsRefPtr<ImageContainer>
|
|
|
|
ContainerState::ThebesLayerData::CanOptimizeImageLayer(LayerManager* aManager)
|
|
|
|
{
|
2011-03-31 14:33:46 -07:00
|
|
|
if (!mImage || !mImageClip.mRoundedClipRects.IsEmpty()) {
|
2011-01-17 13:47:18 -08:00
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mImage->GetContainer(aManager);
|
|
|
|
}
|
|
|
|
|
2010-07-15 14:07:51 -07:00
|
|
|
void
|
|
|
|
ContainerState::PopThebesLayerData()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!mThebesLayerDataStack.IsEmpty(), "Can't pop");
|
|
|
|
|
|
|
|
PRInt32 lastIndex = mThebesLayerDataStack.Length() - 1;
|
|
|
|
ThebesLayerData* data = mThebesLayerDataStack[lastIndex];
|
|
|
|
|
2011-01-17 13:47:18 -08:00
|
|
|
nsRefPtr<Layer> layer;
|
|
|
|
nsRefPtr<ImageContainer> imageContainer = data->CanOptimizeImageLayer(mManager);
|
|
|
|
|
|
|
|
if (data->mIsSolidColorInVisibleRegion || imageContainer) {
|
|
|
|
NS_ASSERTION(!(data->mIsSolidColorInVisibleRegion && imageContainer),
|
|
|
|
"Can't be a solid color as well as an image!");
|
|
|
|
if (imageContainer) {
|
|
|
|
nsRefPtr<ImageLayer> imageLayer = CreateOrRecycleImageLayer();
|
|
|
|
imageLayer->SetContainer(imageContainer);
|
|
|
|
data->mImage->ConfigureLayer(imageLayer);
|
2011-03-31 14:33:46 -07:00
|
|
|
NS_ASSERTION(data->mImageClip.mRoundedClipRects.IsEmpty(),
|
|
|
|
"How did we get rounded clip rects here?");
|
|
|
|
if (data->mImageClip.mHaveClipRect) {
|
|
|
|
nsPresContext* presContext = mContainerFrame->PresContext();
|
|
|
|
nscoord appUnitsPerDevPixel = presContext->AppUnitsPerDevPixel();
|
|
|
|
nsIntRect clip = data->mImageClip.mClipRect.ToNearestPixels(appUnitsPerDevPixel);
|
|
|
|
imageLayer->IntersectClipRect(
|
|
|
|
data->mImageClip.mClipRect.ToNearestPixels(appUnitsPerDevPixel));
|
|
|
|
}
|
2011-01-17 13:47:18 -08:00
|
|
|
layer = imageLayer;
|
|
|
|
} else {
|
|
|
|
nsRefPtr<ColorLayer> colorLayer = CreateOrRecycleColorLayer();
|
|
|
|
colorLayer->SetColor(data->mSolidColor);
|
|
|
|
|
|
|
|
// Copy transform
|
|
|
|
colorLayer->SetTransform(data->mLayer->GetTransform());
|
|
|
|
|
|
|
|
// Clip colorLayer to its visible region, since ColorLayers are
|
|
|
|
// allowed to paint outside the visible region. Here we rely on the
|
|
|
|
// fact that uniform display items fill rectangles; obviously the
|
|
|
|
// area to fill must contain the visible region, and because it's
|
|
|
|
// a rectangle, it must therefore contain the visible region's GetBounds.
|
|
|
|
// Note that the visible region is already clipped appropriately.
|
|
|
|
nsIntRect visibleRect = data->mVisibleRegion.GetBounds();
|
|
|
|
colorLayer->SetClipRect(&visibleRect);
|
|
|
|
|
|
|
|
layer = colorLayer;
|
|
|
|
}
|
2010-07-15 14:08:03 -07:00
|
|
|
|
2011-01-17 13:47:18 -08:00
|
|
|
NS_ASSERTION(!mNewChildLayers.Contains(layer), "Layer already in list???");
|
2010-11-08 18:48:59 -08:00
|
|
|
AutoLayersArray::index_type index = mNewChildLayers.IndexOf(data->mLayer);
|
|
|
|
NS_ASSERTION(index != AutoLayersArray::NoIndex, "Thebes layer not found?");
|
2011-01-17 13:47:18 -08:00
|
|
|
mNewChildLayers.InsertElementAt(index + 1, layer);
|
2010-07-15 14:08:03 -07:00
|
|
|
|
|
|
|
// Hide the ThebesLayer. We leave it in the layer tree so that we
|
|
|
|
// can find and recycle it later.
|
|
|
|
data->mLayer->IntersectClipRect(nsIntRect());
|
|
|
|
data->mLayer->SetVisibleRegion(nsIntRegion());
|
|
|
|
} else {
|
|
|
|
layer = data->mLayer;
|
|
|
|
}
|
|
|
|
|
2010-07-15 14:07:51 -07:00
|
|
|
gfxMatrix transform;
|
2011-01-17 13:47:18 -08:00
|
|
|
if (!layer->GetTransform().Is2D(&transform)) {
|
|
|
|
NS_ERROR("Only 2D transformations currently supported");
|
|
|
|
}
|
|
|
|
|
|
|
|
//ImageLayers are already configured with a visible region
|
|
|
|
if (!imageContainer) {
|
2010-07-15 14:07:51 -07:00
|
|
|
NS_ASSERTION(!transform.HasNonIntegerTranslation(),
|
|
|
|
"Matrix not just an integer translation?");
|
|
|
|
// Convert from relative to the container to relative to the
|
|
|
|
// ThebesLayer itself.
|
|
|
|
nsIntRegion rgn = data->mVisibleRegion;
|
|
|
|
rgn.MoveBy(-nsIntPoint(PRInt32(transform.x0), PRInt32(transform.y0)));
|
2010-07-15 14:08:03 -07:00
|
|
|
layer->SetVisibleRegion(rgn);
|
2010-07-15 14:07:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIntRegion transparentRegion;
|
|
|
|
transparentRegion.Sub(data->mVisibleRegion, data->mOpaqueRegion);
|
2010-09-02 02:18:39 -07:00
|
|
|
PRBool isOpaque = transparentRegion.IsEmpty();
|
|
|
|
// For translucent ThebesLayers, try to find an opaque background
|
|
|
|
// color that covers the entire area beneath it so we can pull that
|
|
|
|
// color into this layer to make it opaque.
|
|
|
|
if (layer == data->mLayer) {
|
|
|
|
nscolor backgroundColor = NS_RGBA(0,0,0,0);
|
|
|
|
if (!isOpaque) {
|
|
|
|
backgroundColor = FindOpaqueBackgroundColorFor(lastIndex);
|
|
|
|
if (NS_GET_A(backgroundColor) == 255) {
|
|
|
|
isOpaque = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Store the background color
|
|
|
|
ThebesDisplayItemLayerUserData* userData =
|
|
|
|
static_cast<ThebesDisplayItemLayerUserData*>
|
|
|
|
(data->mLayer->GetUserData(&gThebesDisplayItemLayerUserData));
|
|
|
|
NS_ASSERTION(userData, "where did our user data go?");
|
|
|
|
if (userData->mForcedBackgroundColor != backgroundColor) {
|
|
|
|
// Invalidate the entire target ThebesLayer since we're changing
|
|
|
|
// the background color
|
|
|
|
data->mLayer->InvalidateRegion(data->mLayer->GetValidRegion());
|
|
|
|
}
|
|
|
|
userData->mForcedBackgroundColor = backgroundColor;
|
|
|
|
}
|
2010-12-19 17:26:14 -08:00
|
|
|
PRUint32 flags;
|
|
|
|
if (isOpaque && !data->mForceTransparentSurface) {
|
|
|
|
flags = Layer::CONTENT_OPAQUE;
|
|
|
|
} else if (data->mNeedComponentAlpha) {
|
|
|
|
flags = Layer::CONTENT_COMPONENT_ALPHA;
|
|
|
|
} else {
|
|
|
|
flags = 0;
|
|
|
|
}
|
2010-09-02 02:18:40 -07:00
|
|
|
layer->SetContentFlags(flags);
|
2010-09-02 02:18:39 -07:00
|
|
|
|
|
|
|
if (lastIndex > 0) {
|
|
|
|
// Since we're going to pop off the last ThebesLayerData, the
|
|
|
|
// mVisibleAboveRegion of the second-to-last item will need to include
|
|
|
|
// the regions of the last item.
|
|
|
|
ThebesLayerData* nextData = mThebesLayerDataStack[lastIndex - 1];
|
|
|
|
nextData->mVisibleAboveRegion.Or(nextData->mVisibleAboveRegion,
|
|
|
|
data->mVisibleAboveRegion);
|
|
|
|
nextData->mVisibleAboveRegion.Or(nextData->mVisibleAboveRegion,
|
|
|
|
data->mVisibleRegion);
|
|
|
|
nextData->mDrawAboveRegion.Or(nextData->mDrawAboveRegion,
|
|
|
|
data->mDrawAboveRegion);
|
|
|
|
nextData->mDrawAboveRegion.Or(nextData->mDrawAboveRegion,
|
|
|
|
data->mDrawRegion);
|
|
|
|
}
|
2010-07-15 14:07:51 -07:00
|
|
|
|
|
|
|
mThebesLayerDataStack.RemoveElementAt(lastIndex);
|
|
|
|
}
|
|
|
|
|
2011-01-02 17:48:09 -08:00
|
|
|
static PRBool
|
|
|
|
SuppressComponentAlpha(nsDisplayListBuilder* aBuilder,
|
2011-01-02 17:48:09 -08:00
|
|
|
nsDisplayItem* aItem,
|
|
|
|
const nsRect& aComponentAlphaBounds)
|
2011-01-02 17:48:09 -08:00
|
|
|
{
|
|
|
|
const nsRegion* windowTransparentRegion = aBuilder->GetFinalTransparentRegion();
|
|
|
|
if (!windowTransparentRegion || windowTransparentRegion->IsEmpty())
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
// Suppress component alpha for items in the toplevel window that are over
|
|
|
|
// the window translucent area
|
|
|
|
nsIFrame* f = aItem->GetUnderlyingFrame();
|
|
|
|
nsIFrame* ref = aBuilder->ReferenceFrame();
|
|
|
|
if (f->PresContext() != ref->PresContext())
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
for (nsIFrame* t = f; t; t = t->GetParent()) {
|
|
|
|
if (t->IsTransformed())
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2011-01-02 17:48:09 -08:00
|
|
|
return windowTransparentRegion->Intersects(aComponentAlphaBounds);
|
2011-01-02 17:48:09 -08:00
|
|
|
}
|
|
|
|
|
2011-01-02 17:48:09 -08:00
|
|
|
static PRBool
|
|
|
|
WindowHasTransparency(nsDisplayListBuilder* aBuilder)
|
|
|
|
{
|
|
|
|
const nsRegion* windowTransparentRegion = aBuilder->GetFinalTransparentRegion();
|
|
|
|
return windowTransparentRegion && !windowTransparentRegion->IsEmpty();
|
|
|
|
}
|
|
|
|
|
2010-07-15 14:07:51 -07:00
|
|
|
void
|
2010-09-02 02:18:39 -07:00
|
|
|
ContainerState::ThebesLayerData::Accumulate(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsDisplayItem* aItem,
|
|
|
|
const nsIntRect& aVisibleRect,
|
2011-01-02 17:48:09 -08:00
|
|
|
const nsIntRect& aDrawRect,
|
|
|
|
const FrameLayerBuilder::Clip& aClip)
|
2010-07-15 14:07:51 -07:00
|
|
|
{
|
2010-09-02 02:18:39 -07:00
|
|
|
nscolor uniformColor;
|
2011-01-16 02:38:45 -08:00
|
|
|
PRBool isUniform = aItem->IsUniform(aBuilder, &uniformColor);
|
|
|
|
// Some display items have to exist (so they can set forceTransparentSurface
|
|
|
|
// below) but don't draw anything. They'll return true for isUniform but
|
|
|
|
// a color with opacity 0.
|
|
|
|
if (!isUniform || NS_GET_A(uniformColor) > 0) {
|
|
|
|
if (isUniform &&
|
|
|
|
aItem->GetBounds(aBuilder).ToInsidePixels(AppUnitsPerDevPixel(aItem)).Contains(aVisibleRect)) {
|
|
|
|
if (mVisibleRegion.IsEmpty()) {
|
|
|
|
// This color is all we have
|
|
|
|
mSolidColor = uniformColor;
|
|
|
|
mIsSolidColorInVisibleRegion = PR_TRUE;
|
|
|
|
} else if (mIsSolidColorInVisibleRegion &&
|
|
|
|
mVisibleRegion.IsEqual(nsIntRegion(aVisibleRect))) {
|
|
|
|
// we can just blend the colors together
|
|
|
|
mSolidColor = NS_ComposeColors(mSolidColor, uniformColor);
|
|
|
|
} else {
|
|
|
|
mIsSolidColorInVisibleRegion = PR_FALSE;
|
|
|
|
}
|
2010-07-15 14:08:03 -07:00
|
|
|
} else {
|
|
|
|
mIsSolidColorInVisibleRegion = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2011-01-16 02:38:45 -08:00
|
|
|
mVisibleRegion.Or(mVisibleRegion, aVisibleRect);
|
|
|
|
mVisibleRegion.SimplifyOutward(4);
|
|
|
|
mDrawRegion.Or(mDrawRegion, aDrawRect);
|
|
|
|
mDrawRegion.SimplifyOutward(4);
|
|
|
|
}
|
2010-09-02 02:18:39 -07:00
|
|
|
|
2011-01-17 13:47:18 -08:00
|
|
|
/* Mark as available for conversion to image layer if this is a nsDisplayImage and
|
|
|
|
* we are the first visible item in the ThebesLayerData object.
|
|
|
|
*/
|
|
|
|
if (aItem->GetType() == nsDisplayItem::TYPE_IMAGE && mVisibleRegion.IsEmpty()) {
|
|
|
|
mImage = static_cast<nsDisplayImage*>(aItem);
|
2011-03-31 14:33:46 -07:00
|
|
|
mImageClip = aClip;
|
2011-01-17 13:47:18 -08:00
|
|
|
} else {
|
|
|
|
mImage = nsnull;
|
|
|
|
}
|
|
|
|
|
2010-10-19 10:02:25 -07:00
|
|
|
PRBool forceTransparentSurface = PR_FALSE;
|
2011-01-02 17:48:09 -08:00
|
|
|
nsRegion opaque = aItem->GetOpaqueRegion(aBuilder, &forceTransparentSurface);
|
|
|
|
if (!opaque.IsEmpty()) {
|
|
|
|
nsRegionRectIterator iter(opaque);
|
|
|
|
nscoord appUnitsPerDevPixel = AppUnitsPerDevPixel(aItem);
|
|
|
|
for (const nsRect* r = iter.Next(); r; r = iter.Next()) {
|
|
|
|
// We don't use SimplifyInward here since it's not defined exactly
|
|
|
|
// what it will discard. For our purposes the most important case
|
|
|
|
// is a large opaque background at the bottom of z-order (e.g.,
|
|
|
|
// a canvas background), so we need to make sure that the first rect
|
|
|
|
// we see doesn't get discarded.
|
2011-01-04 02:35:57 -08:00
|
|
|
nsIntRect rect = aClip.ApproximateIntersect(*r).ToInsidePixels(appUnitsPerDevPixel);
|
2011-01-02 17:48:09 -08:00
|
|
|
nsIntRegion tmp;
|
|
|
|
tmp.Or(mOpaqueRegion, rect);
|
2011-01-02 17:48:09 -08:00
|
|
|
// Opaque display items in chrome documents whose window is partially
|
|
|
|
// transparent are always added to the opaque region. This helps ensure
|
|
|
|
// that we get as much subpixel-AA as possible in the chrome.
|
|
|
|
if (tmp.GetNumRects() <= 4 ||
|
|
|
|
(WindowHasTransparency(aBuilder) &&
|
|
|
|
aItem->GetUnderlyingFrame()->PresContext()->IsChrome())) {
|
2011-01-02 17:48:09 -08:00
|
|
|
mOpaqueRegion = tmp;
|
|
|
|
}
|
2010-07-15 14:08:11 -07:00
|
|
|
}
|
2011-01-02 17:48:09 -08:00
|
|
|
}
|
2011-01-02 17:48:09 -08:00
|
|
|
nsRect componentAlpha = aItem->GetComponentAlphaBounds(aBuilder);
|
|
|
|
componentAlpha.IntersectRect(componentAlpha, aItem->GetVisibleRect());
|
|
|
|
if (!componentAlpha.IsEmpty()) {
|
|
|
|
nscoord appUnitsPerDevPixel = AppUnitsPerDevPixel(aItem);
|
|
|
|
if (!mOpaqueRegion.Contains(componentAlpha.ToOutsidePixels(appUnitsPerDevPixel))) {
|
|
|
|
if (SuppressComponentAlpha(aBuilder, aItem, componentAlpha)) {
|
2011-01-02 17:48:09 -08:00
|
|
|
aItem->DisableComponentAlpha();
|
|
|
|
} else {
|
|
|
|
mNeedComponentAlpha = PR_TRUE;
|
|
|
|
}
|
2010-09-02 02:18:40 -07:00
|
|
|
}
|
2010-07-15 14:07:51 -07:00
|
|
|
}
|
2010-10-19 10:02:25 -07:00
|
|
|
mForceTransparentSurface = mForceTransparentSurface || forceTransparentSurface;
|
2010-07-15 14:07:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<ThebesLayer>
|
2010-09-02 02:18:39 -07:00
|
|
|
ContainerState::FindThebesLayerFor(nsDisplayItem* aItem,
|
|
|
|
const nsIntRect& aVisibleRect,
|
2010-08-01 20:06:58 -07:00
|
|
|
const nsIntRect& aDrawRect,
|
2011-01-02 17:48:09 -08:00
|
|
|
const FrameLayerBuilder::Clip& aClip,
|
2010-09-02 02:18:39 -07:00
|
|
|
nsIFrame* aActiveScrolledRoot)
|
2010-07-15 14:07:51 -07:00
|
|
|
{
|
|
|
|
PRInt32 i;
|
|
|
|
PRInt32 lowestUsableLayerWithScrolledRoot = -1;
|
|
|
|
PRInt32 topmostLayerWithScrolledRoot = -1;
|
|
|
|
for (i = mThebesLayerDataStack.Length() - 1; i >= 0; --i) {
|
|
|
|
ThebesLayerData* data = mThebesLayerDataStack[i];
|
2010-08-01 20:06:58 -07:00
|
|
|
if (data->mDrawAboveRegion.Intersects(aVisibleRect)) {
|
2010-07-15 14:07:51 -07:00
|
|
|
++i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (data->mActiveScrolledRoot == aActiveScrolledRoot) {
|
|
|
|
lowestUsableLayerWithScrolledRoot = i;
|
|
|
|
if (topmostLayerWithScrolledRoot < 0) {
|
|
|
|
topmostLayerWithScrolledRoot = i;
|
2010-05-20 20:20:48 -07:00
|
|
|
}
|
|
|
|
}
|
2010-08-01 20:06:58 -07:00
|
|
|
if (data->mDrawRegion.Intersects(aVisibleRect))
|
2010-07-15 14:07:51 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (topmostLayerWithScrolledRoot < 0) {
|
|
|
|
--i;
|
|
|
|
for (; i >= 0; --i) {
|
|
|
|
ThebesLayerData* data = mThebesLayerDataStack[i];
|
|
|
|
if (data->mActiveScrolledRoot == aActiveScrolledRoot) {
|
|
|
|
topmostLayerWithScrolledRoot = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-05-20 20:20:48 -07:00
|
|
|
|
2010-07-15 14:07:51 -07:00
|
|
|
if (topmostLayerWithScrolledRoot >= 0) {
|
|
|
|
while (PRUint32(topmostLayerWithScrolledRoot + 1) < mThebesLayerDataStack.Length()) {
|
|
|
|
PopThebesLayerData();
|
2010-05-20 20:20:48 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-15 14:07:51 -07:00
|
|
|
nsRefPtr<ThebesLayer> layer;
|
|
|
|
ThebesLayerData* thebesLayerData = nsnull;
|
|
|
|
if (lowestUsableLayerWithScrolledRoot < 0) {
|
|
|
|
layer = CreateOrRecycleThebesLayer(aActiveScrolledRoot);
|
2010-07-15 14:08:03 -07:00
|
|
|
|
|
|
|
NS_ASSERTION(!mNewChildLayers.Contains(layer), "Layer already in list???");
|
|
|
|
mNewChildLayers.AppendElement(layer);
|
|
|
|
|
2010-07-15 14:07:51 -07:00
|
|
|
thebesLayerData = new ThebesLayerData();
|
|
|
|
mThebesLayerDataStack.AppendElement(thebesLayerData);
|
|
|
|
thebesLayerData->mLayer = layer;
|
|
|
|
thebesLayerData->mActiveScrolledRoot = aActiveScrolledRoot;
|
|
|
|
} else {
|
|
|
|
thebesLayerData = mThebesLayerDataStack[lowestUsableLayerWithScrolledRoot];
|
|
|
|
layer = thebesLayerData->mLayer;
|
|
|
|
}
|
|
|
|
|
2011-01-02 17:48:09 -08:00
|
|
|
thebesLayerData->Accumulate(mBuilder, aItem, aVisibleRect, aDrawRect, aClip);
|
2010-07-15 14:07:51 -07:00
|
|
|
return layer.forget();
|
|
|
|
}
|
|
|
|
|
2011-02-10 00:58:11 -08:00
|
|
|
static void
|
|
|
|
PaintInactiveLayer(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsDisplayItem* aItem,
|
|
|
|
gfxContext* aContext)
|
2010-08-02 20:33:24 -07:00
|
|
|
{
|
2011-02-10 00:58:11 -08:00
|
|
|
// This item has an inactive layer. Render it to a ThebesLayer
|
|
|
|
// using a temporary BasicLayerManager.
|
2010-08-02 20:33:24 -07:00
|
|
|
nsRefPtr<BasicLayerManager> tempManager = new BasicLayerManager();
|
2011-02-10 00:58:11 -08:00
|
|
|
tempManager->BeginTransactionWithTarget(aContext);
|
2010-08-02 20:33:24 -07:00
|
|
|
nsRefPtr<Layer> layer = aItem->BuildLayer(aBuilder, tempManager);
|
|
|
|
if (!layer) {
|
|
|
|
tempManager->EndTransaction(nsnull, nsnull);
|
2011-02-10 00:58:11 -08:00
|
|
|
return;
|
2010-08-02 20:33:24 -07:00
|
|
|
}
|
|
|
|
PRInt32 appUnitsPerDevPixel = AppUnitsPerDevPixel(aItem);
|
|
|
|
nsIntRect itemVisibleRect =
|
2011-01-04 02:35:57 -08:00
|
|
|
aItem->GetVisibleRect().ToOutsidePixels(appUnitsPerDevPixel);
|
2011-02-22 21:38:09 -08:00
|
|
|
RestrictVisibleRegionForLayer(layer, itemVisibleRect);
|
2010-08-02 20:33:24 -07:00
|
|
|
|
|
|
|
tempManager->SetRoot(layer);
|
2011-02-20 19:28:00 -08:00
|
|
|
aBuilder->LayerBuilder()->WillEndTransaction(tempManager);
|
2011-02-10 00:58:11 -08:00
|
|
|
tempManager->EndTransaction(FrameLayerBuilder::DrawThebesLayer, aBuilder);
|
2011-02-20 19:28:00 -08:00
|
|
|
aBuilder->LayerBuilder()->DidEndTransaction(tempManager);
|
2010-08-02 20:33:24 -07:00
|
|
|
}
|
|
|
|
|
2010-07-15 14:07:51 -07:00
|
|
|
/*
|
|
|
|
* Iterate through the non-clip items in aList and its descendants.
|
|
|
|
* For each item we compute the effective clip rect. Each item is assigned
|
|
|
|
* to a layer. We invalidate the areas in ThebesLayers where an item
|
|
|
|
* has moved from one ThebesLayer to another. Also,
|
|
|
|
* aState->mInvalidThebesContent is invalidated in every ThebesLayer.
|
|
|
|
* We set the clip rect for items that generated their own layer.
|
|
|
|
* (ThebesLayers don't need a clip rect on the layer, we clip the items
|
|
|
|
* individually when we draw them.)
|
2010-09-09 08:21:46 -07:00
|
|
|
* If we have to clip to a rounded rect, we treat any active layer as
|
|
|
|
* though it's inactive so that we draw it ourselves into the thebes layer.
|
2010-07-15 14:07:51 -07:00
|
|
|
* We set the visible rect for all layers, although the actual setting
|
|
|
|
* of visible rects for some ThebesLayers is deferred until the calling
|
|
|
|
* of ContainerState::Finish.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ContainerState::ProcessDisplayItems(const nsDisplayList& aList,
|
2011-01-26 10:36:11 -08:00
|
|
|
FrameLayerBuilder::Clip& aClip)
|
2010-07-15 14:07:51 -07:00
|
|
|
{
|
2010-08-08 11:49:07 -07:00
|
|
|
PRInt32 appUnitsPerDevPixel =
|
|
|
|
mContainerFrame->PresContext()->AppUnitsPerDevPixel();
|
|
|
|
|
2010-07-15 14:07:51 -07:00
|
|
|
for (nsDisplayItem* item = aList.GetBottom(); item; item = item->GetAbove()) {
|
2010-09-09 08:21:46 -07:00
|
|
|
nsDisplayItem::Type type = item->GetType();
|
|
|
|
if (type == nsDisplayItem::TYPE_CLIP ||
|
|
|
|
type == nsDisplayItem::TYPE_CLIP_ROUNDED_RECT) {
|
|
|
|
FrameLayerBuilder::Clip childClip(aClip, item);
|
|
|
|
ProcessDisplayItems(*item->GetList(), childClip);
|
2010-07-15 14:07:51 -07:00
|
|
|
continue;
|
2010-05-20 20:20:48 -07:00
|
|
|
}
|
|
|
|
|
2010-08-08 11:49:07 -07:00
|
|
|
NS_ASSERTION(appUnitsPerDevPixel == AppUnitsPerDevPixel(item),
|
|
|
|
"items in a container layer should all have the same app units per dev pixel");
|
|
|
|
|
2010-07-15 14:07:51 -07:00
|
|
|
nsIntRect itemVisibleRect =
|
2011-01-04 02:35:57 -08:00
|
|
|
item->GetVisibleRect().ToOutsidePixels(appUnitsPerDevPixel);
|
2010-08-01 20:06:58 -07:00
|
|
|
nsRect itemContent = item->GetBounds(mBuilder);
|
2010-09-09 08:21:46 -07:00
|
|
|
if (aClip.mHaveClipRect) {
|
|
|
|
itemContent.IntersectRect(aClip.mClipRect, itemContent);
|
2010-08-01 20:06:58 -07:00
|
|
|
}
|
2011-02-22 21:38:09 -08:00
|
|
|
mBounds.UnionRect(mBounds, itemContent);
|
2011-01-04 02:35:57 -08:00
|
|
|
nsIntRect itemDrawRect = itemContent.ToOutsidePixels(appUnitsPerDevPixel);
|
2010-07-15 14:08:05 -07:00
|
|
|
nsDisplayItem::LayerState layerState =
|
|
|
|
item->GetLayerState(mBuilder, mManager);
|
|
|
|
|
2010-07-15 14:07:51 -07:00
|
|
|
// Assign the item to a layer
|
2011-03-15 16:20:19 -07:00
|
|
|
if (layerState == LAYER_ACTIVE_FORCE ||
|
|
|
|
layerState == LAYER_ACTIVE && (aClip.mRoundedClipRects.IsEmpty() ||
|
2011-01-26 10:36:11 -08:00
|
|
|
// We can use the visible rect here only because the item has its own
|
|
|
|
// layer, like the comment below.
|
|
|
|
!aClip.IsRectClippedByRoundedCorner(item->GetVisibleRect()))) {
|
2010-07-15 14:08:09 -07:00
|
|
|
// If the item would have its own layer but is invisible, just hide it.
|
|
|
|
// Note that items without their own layers can't be skipped this
|
|
|
|
// way, since their ThebesLayer may decide it wants to draw them
|
|
|
|
// into its buffer even if they're currently covered.
|
|
|
|
if (itemVisibleRect.IsEmpty()) {
|
|
|
|
InvalidateForLayerChange(item, nsnull);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-01-26 10:36:11 -08:00
|
|
|
aClip.RemoveRoundedCorners();
|
|
|
|
|
2010-07-15 14:08:05 -07:00
|
|
|
// Just use its layer.
|
|
|
|
nsRefPtr<Layer> ownLayer = item->BuildLayer(mBuilder, mManager);
|
|
|
|
if (!ownLayer) {
|
|
|
|
InvalidateForLayerChange(item, ownLayer);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update that layer's clip and visible rects.
|
2010-07-15 14:07:51 -07:00
|
|
|
NS_ASSERTION(ownLayer->Manager() == mManager, "Wrong manager");
|
2010-09-02 02:18:39 -07:00
|
|
|
NS_ASSERTION(!ownLayer->HasUserData(&gLayerManagerUserData),
|
2010-07-15 14:07:51 -07:00
|
|
|
"We shouldn't have a FrameLayerBuilder-managed layer here!");
|
|
|
|
// It has its own layer. Update that layer's clip and visible rects.
|
2010-09-09 08:21:46 -07:00
|
|
|
if (aClip.mHaveClipRect) {
|
2010-07-15 14:07:51 -07:00
|
|
|
ownLayer->IntersectClipRect(
|
2010-09-09 08:21:46 -07:00
|
|
|
aClip.mClipRect.ToNearestPixels(appUnitsPerDevPixel));
|
2010-05-20 20:20:48 -07:00
|
|
|
}
|
2010-07-15 14:07:51 -07:00
|
|
|
ThebesLayerData* data = GetTopThebesLayerData();
|
|
|
|
if (data) {
|
|
|
|
data->mVisibleAboveRegion.Or(data->mVisibleAboveRegion, itemVisibleRect);
|
2010-08-01 20:06:58 -07:00
|
|
|
// Add the entire bounds rect to the mDrawAboveRegion.
|
|
|
|
// The visible region may be excluding opaque content above the
|
|
|
|
// item, and we need to ensure that that content is not placed
|
|
|
|
// in a ThebesLayer below the item!
|
|
|
|
data->mDrawAboveRegion.Or(data->mDrawAboveRegion, itemDrawRect);
|
2010-07-15 14:07:51 -07:00
|
|
|
}
|
2011-02-22 21:38:09 -08:00
|
|
|
RestrictVisibleRegionForLayer(ownLayer, itemVisibleRect);
|
2010-07-15 14:07:51 -07:00
|
|
|
ContainerLayer* oldContainer = ownLayer->GetParent();
|
|
|
|
if (oldContainer && oldContainer != mContainerLayer) {
|
|
|
|
oldContainer->RemoveChild(ownLayer);
|
|
|
|
}
|
|
|
|
NS_ASSERTION(!mNewChildLayers.Contains(ownLayer),
|
|
|
|
"Layer already in list???");
|
2010-07-15 14:08:05 -07:00
|
|
|
|
|
|
|
InvalidateForLayerChange(item, ownLayer);
|
|
|
|
|
2010-07-15 14:07:51 -07:00
|
|
|
mNewChildLayers.AppendElement(ownLayer);
|
|
|
|
mBuilder->LayerBuilder()->AddLayerDisplayItem(ownLayer, item);
|
2010-05-20 20:20:48 -07:00
|
|
|
} else {
|
2010-07-15 14:07:51 -07:00
|
|
|
nsIFrame* f = item->GetUnderlyingFrame();
|
|
|
|
nsIFrame* activeScrolledRoot =
|
2010-08-08 11:49:06 -07:00
|
|
|
nsLayoutUtils::GetActiveScrolledRootFor(f, mBuilder->ReferenceFrame());
|
2010-07-15 14:08:06 -07:00
|
|
|
if (item->IsFixedAndCoveringViewport(mBuilder)) {
|
|
|
|
// Make its active scrolled root be the active scrolled root of
|
|
|
|
// the enclosing viewport, since it shouldn't be scrolled by scrolled
|
|
|
|
// frames in its document. InvalidateFixedBackgroundFramesFromList in
|
|
|
|
// nsGfxScrollFrame will not repaint this item when scrolling occurs.
|
|
|
|
nsIFrame* viewportFrame =
|
|
|
|
nsLayoutUtils::GetClosestFrameOfType(f, nsGkAtoms::viewportFrame);
|
|
|
|
NS_ASSERTION(viewportFrame, "no viewport???");
|
|
|
|
activeScrolledRoot =
|
2010-08-08 11:49:06 -07:00
|
|
|
nsLayoutUtils::GetActiveScrolledRootFor(viewportFrame, mBuilder->ReferenceFrame());
|
2010-07-15 14:08:06 -07:00
|
|
|
}
|
2010-07-15 14:07:51 -07:00
|
|
|
|
|
|
|
nsRefPtr<ThebesLayer> thebesLayer =
|
2011-01-02 17:48:09 -08:00
|
|
|
FindThebesLayerFor(item, itemVisibleRect, itemDrawRect, aClip,
|
2010-09-02 02:18:39 -07:00
|
|
|
activeScrolledRoot);
|
2010-07-15 14:08:05 -07:00
|
|
|
|
|
|
|
InvalidateForLayerChange(item, thebesLayer);
|
2010-07-15 14:07:51 -07:00
|
|
|
|
|
|
|
mBuilder->LayerBuilder()->
|
2010-09-09 08:21:46 -07:00
|
|
|
AddThebesDisplayItem(thebesLayer, item, aClip, mContainerFrame,
|
2011-02-10 00:58:11 -08:00
|
|
|
layerState);
|
2010-05-20 20:20:48 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-15 14:08:05 -07:00
|
|
|
void
|
|
|
|
ContainerState::InvalidateForLayerChange(nsDisplayItem* aItem, Layer* aNewLayer)
|
|
|
|
{
|
|
|
|
nsIFrame* f = aItem->GetUnderlyingFrame();
|
|
|
|
NS_ASSERTION(f, "Display items that render using Thebes must have a frame");
|
|
|
|
PRUint32 key = aItem->GetPerFrameKey();
|
|
|
|
NS_ASSERTION(key, "Display items that render using Thebes must have a key");
|
|
|
|
Layer* oldLayer = mBuilder->LayerBuilder()->GetOldLayerFor(f, key);
|
|
|
|
if (!oldLayer) {
|
|
|
|
// Nothing to do here, this item didn't have a layer before
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (aNewLayer != oldLayer) {
|
|
|
|
// The item has changed layers.
|
|
|
|
// Invalidate the bounds in the old layer and new layer.
|
|
|
|
// The bounds might have changed, but we assume that any difference
|
|
|
|
// in the bounds will have been invalidated for all Thebes layers
|
|
|
|
// in the container via regular frame invalidation.
|
|
|
|
nsRect bounds = aItem->GetBounds(mBuilder);
|
|
|
|
PRInt32 appUnitsPerDevPixel = AppUnitsPerDevPixel(aItem);
|
|
|
|
nsIntRect r = bounds.ToOutsidePixels(appUnitsPerDevPixel);
|
|
|
|
|
|
|
|
ThebesLayer* t = oldLayer->AsThebesLayer();
|
|
|
|
if (t) {
|
|
|
|
InvalidatePostTransformRegion(t, r);
|
|
|
|
}
|
|
|
|
if (aNewLayer) {
|
|
|
|
ThebesLayer* newLayer = aNewLayer->AsThebesLayer();
|
|
|
|
if (newLayer) {
|
|
|
|
InvalidatePostTransformRegion(newLayer, r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-08 11:49:07 -07:00
|
|
|
NS_ASSERTION(appUnitsPerDevPixel ==
|
|
|
|
mContainerFrame->PresContext()->AppUnitsPerDevPixel(),
|
|
|
|
"app units per dev pixel should be constant in a container");
|
2010-07-15 14:08:11 -07:00
|
|
|
mContainerFrame->InvalidateWithFlags(
|
|
|
|
bounds - mBuilder->ToReferenceFrame(mContainerFrame),
|
|
|
|
nsIFrame::INVALIDATE_NO_THEBES_LAYERS |
|
|
|
|
nsIFrame::INVALIDATE_EXCLUDE_CURRENT_PAINT);
|
2010-07-15 14:08:05 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-10 00:58:11 -08:00
|
|
|
PRBool
|
|
|
|
FrameLayerBuilder::NeedToInvalidateFixedDisplayItem(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsDisplayItem* aItem)
|
|
|
|
{
|
|
|
|
return !aItem->IsFixedAndCoveringViewport(aBuilder) ||
|
|
|
|
!HasRetainedLayerFor(aItem->GetUnderlyingFrame(), aItem->GetPerFrameKey());
|
|
|
|
}
|
|
|
|
|
2010-07-15 14:07:51 -07:00
|
|
|
void
|
|
|
|
FrameLayerBuilder::AddThebesDisplayItem(ThebesLayer* aLayer,
|
|
|
|
nsDisplayItem* aItem,
|
2010-09-09 08:21:46 -07:00
|
|
|
const Clip& aClip,
|
2010-07-15 14:08:05 -07:00
|
|
|
nsIFrame* aContainerLayerFrame,
|
2011-02-10 00:58:11 -08:00
|
|
|
LayerState aLayerState)
|
2010-07-15 14:07:51 -07:00
|
|
|
{
|
|
|
|
AddLayerDisplayItem(aLayer, aItem);
|
|
|
|
|
|
|
|
ThebesLayerItemsEntry* entry = mThebesLayerItems.PutEntry(aLayer);
|
|
|
|
if (entry) {
|
|
|
|
entry->mContainerLayerFrame = aContainerLayerFrame;
|
|
|
|
NS_ASSERTION(aItem->GetUnderlyingFrame(), "Must have frame");
|
2010-07-15 14:08:05 -07:00
|
|
|
ClippedDisplayItem* cdi =
|
2010-09-09 08:21:46 -07:00
|
|
|
entry->mItems.AppendElement(ClippedDisplayItem(aItem, aClip));
|
2011-02-10 00:58:11 -08:00
|
|
|
cdi->mInactiveLayer = aLayerState != LAYER_NONE;
|
2010-07-15 14:07:51 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FrameLayerBuilder::AddLayerDisplayItem(Layer* aLayer,
|
|
|
|
nsDisplayItem* aItem)
|
|
|
|
{
|
|
|
|
if (aLayer->Manager() != mRetainingManager)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsIFrame* f = aItem->GetUnderlyingFrame();
|
|
|
|
DisplayItemDataEntry* entry = mNewDisplayItemData.PutEntry(f);
|
|
|
|
if (entry) {
|
|
|
|
entry->mData.AppendElement(DisplayItemData(aLayer, aItem->GetPerFrameKey()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-02 02:18:39 -07:00
|
|
|
nscolor
|
|
|
|
FrameLayerBuilder::FindOpaqueColorCovering(nsDisplayListBuilder* aBuilder,
|
|
|
|
ThebesLayer* aLayer,
|
|
|
|
const nsRect& aRect)
|
|
|
|
{
|
|
|
|
ThebesLayerItemsEntry* entry = mThebesLayerItems.GetEntry(aLayer);
|
|
|
|
NS_ASSERTION(entry, "Must know about this layer!");
|
|
|
|
for (PRInt32 i = entry->mItems.Length() - 1; i >= 0; --i) {
|
|
|
|
nsDisplayItem* item = entry->mItems[i].mItem;
|
|
|
|
const nsRect& visible = item->GetVisibleRect();
|
|
|
|
if (!visible.Intersects(aRect))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
nscolor color;
|
|
|
|
if (visible.Contains(aRect) && item->IsUniform(aBuilder, &color) &&
|
|
|
|
NS_GET_A(color) == 255)
|
|
|
|
return color;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return NS_RGBA(0,0,0,0);
|
|
|
|
}
|
|
|
|
|
2010-07-15 14:07:51 -07:00
|
|
|
void
|
2010-07-15 14:08:03 -07:00
|
|
|
ContainerState::CollectOldLayers()
|
2010-07-15 14:07:51 -07:00
|
|
|
{
|
|
|
|
for (Layer* layer = mContainerLayer->GetFirstChild(); layer;
|
|
|
|
layer = layer->GetNextSibling()) {
|
2010-09-02 02:18:39 -07:00
|
|
|
if (layer->HasUserData(&gColorLayerUserData)) {
|
2010-07-15 14:08:03 -07:00
|
|
|
mRecycledColorLayers.AppendElement(static_cast<ColorLayer*>(layer));
|
2011-01-17 13:47:18 -08:00
|
|
|
} else if (layer->HasUserData(&gImageLayerUserData)) {
|
|
|
|
mRecycledImageLayers.AppendElement(static_cast<ImageLayer*>(layer));
|
2010-09-02 02:18:39 -07:00
|
|
|
} else if (layer->HasUserData(&gThebesDisplayItemLayerUserData)) {
|
2010-07-15 14:08:03 -07:00
|
|
|
NS_ASSERTION(layer->AsThebesLayer(), "Wrong layer type");
|
|
|
|
mRecycledThebesLayers.AppendElement(static_cast<ThebesLayer*>(layer));
|
2010-07-15 14:07:51 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-12-19 17:26:14 -08:00
|
|
|
ContainerState::Finish(PRUint32* aTextContentFlags)
|
2010-07-15 14:07:51 -07:00
|
|
|
{
|
|
|
|
while (!mThebesLayerDataStack.IsEmpty()) {
|
|
|
|
PopThebesLayerData();
|
|
|
|
}
|
|
|
|
|
2010-12-19 17:26:14 -08:00
|
|
|
PRUint32 textContentFlags = 0;
|
2010-12-19 17:26:14 -08:00
|
|
|
|
2010-07-15 14:07:51 -07:00
|
|
|
for (PRUint32 i = 0; i <= mNewChildLayers.Length(); ++i) {
|
|
|
|
// An invariant of this loop is that the layers in mNewChildLayers
|
|
|
|
// with index < i are the first i child layers of mContainerLayer.
|
|
|
|
Layer* layer;
|
|
|
|
if (i < mNewChildLayers.Length()) {
|
|
|
|
layer = mNewChildLayers[i];
|
2010-12-19 17:26:14 -08:00
|
|
|
if (!layer->GetVisibleRegion().IsEmpty()) {
|
2010-12-19 17:26:14 -08:00
|
|
|
textContentFlags |= layer->GetContentFlags() & Layer::CONTENT_COMPONENT_ALPHA;
|
2010-12-19 17:26:14 -08:00
|
|
|
}
|
2010-07-15 14:07:51 -07:00
|
|
|
if (!layer->GetParent()) {
|
|
|
|
// This is not currently a child of the container, so just add it
|
|
|
|
// now.
|
2010-07-27 02:20:55 -07:00
|
|
|
Layer* prevChild = i == 0 ? nsnull : mNewChildLayers[i - 1].get();
|
2010-07-15 14:07:51 -07:00
|
|
|
mContainerLayer->InsertAfter(layer, prevChild);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
NS_ASSERTION(layer->GetParent() == mContainerLayer,
|
|
|
|
"Layer shouldn't be the child of some other container");
|
|
|
|
} else {
|
|
|
|
layer = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If layer is non-null, then it's already a child of the container,
|
|
|
|
// so scan forward until we find it, removing the other layers we
|
|
|
|
// don't want here.
|
|
|
|
// If it's null, scan forward until we've removed all the leftover
|
|
|
|
// children.
|
|
|
|
Layer* nextOldChild = i == 0 ? mContainerLayer->GetFirstChild() :
|
|
|
|
mNewChildLayers[i - 1]->GetNextSibling();
|
|
|
|
while (nextOldChild != layer) {
|
|
|
|
Layer* tmp = nextOldChild;
|
|
|
|
nextOldChild = nextOldChild->GetNextSibling();
|
|
|
|
mContainerLayer->RemoveChild(tmp);
|
|
|
|
}
|
|
|
|
// If non-null, 'layer' is now in the right place in the list, so we
|
|
|
|
// can just move on to the next one.
|
|
|
|
}
|
2010-12-19 17:26:14 -08:00
|
|
|
|
|
|
|
*aTextContentFlags = textContentFlags;
|
2010-07-15 14:07:51 -07:00
|
|
|
}
|
2010-05-20 20:20:48 -07:00
|
|
|
|
2010-09-03 13:10:45 -07:00
|
|
|
already_AddRefed<ContainerLayer>
|
2010-07-15 14:07:51 -07:00
|
|
|
FrameLayerBuilder::BuildContainerLayerFor(nsDisplayListBuilder* aBuilder,
|
|
|
|
LayerManager* aManager,
|
|
|
|
nsIFrame* aContainerFrame,
|
|
|
|
nsDisplayItem* aContainerItem,
|
|
|
|
const nsDisplayList& aChildren)
|
|
|
|
{
|
|
|
|
FrameProperties props = aContainerFrame->Properties();
|
|
|
|
PRUint32 containerDisplayItemKey =
|
|
|
|
aContainerItem ? aContainerItem->GetPerFrameKey() : 0;
|
|
|
|
NS_ASSERTION(aContainerFrame, "Container display items here should have a frame");
|
|
|
|
NS_ASSERTION(!aContainerItem ||
|
|
|
|
aContainerItem->GetUnderlyingFrame() == aContainerFrame,
|
|
|
|
"Container display item must match given frame");
|
|
|
|
|
|
|
|
nsRefPtr<ContainerLayer> containerLayer;
|
|
|
|
if (aManager == mRetainingManager) {
|
|
|
|
Layer* oldLayer = GetOldLayerFor(aContainerFrame, containerDisplayItemKey);
|
|
|
|
if (oldLayer) {
|
|
|
|
NS_ASSERTION(oldLayer->Manager() == aManager, "Wrong manager");
|
2010-09-02 02:18:39 -07:00
|
|
|
if (oldLayer->HasUserData(&gThebesDisplayItemLayerUserData)) {
|
2010-07-15 14:08:05 -07:00
|
|
|
// The old layer for this item is actually our ThebesLayer
|
|
|
|
// because we rendered its layer into that ThebesLayer. So we
|
|
|
|
// don't actually have a retained container layer.
|
|
|
|
} else {
|
|
|
|
NS_ASSERTION(oldLayer->GetType() == Layer::TYPE_CONTAINER,
|
|
|
|
"Wrong layer type");
|
|
|
|
containerLayer = static_cast<ContainerLayer*>(oldLayer);
|
|
|
|
// Clear clip rect; the caller will set it if necessary.
|
|
|
|
containerLayer->SetClipRect(nsnull);
|
|
|
|
}
|
2010-07-15 14:07:51 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!containerLayer) {
|
|
|
|
// No suitable existing layer was found.
|
|
|
|
containerLayer = aManager->CreateContainerLayer();
|
|
|
|
if (!containerLayer)
|
|
|
|
return nsnull;
|
|
|
|
}
|
2010-05-20 20:20:48 -07:00
|
|
|
|
2010-07-15 14:07:51 -07:00
|
|
|
ContainerState state(aBuilder, aManager, aContainerFrame, containerLayer);
|
2011-02-22 21:38:09 -08:00
|
|
|
nscoord appUnitsPerDevPixel = aContainerFrame->PresContext()->AppUnitsPerDevPixel();
|
2010-05-20 20:20:48 -07:00
|
|
|
|
2010-07-15 14:07:51 -07:00
|
|
|
if (aManager == mRetainingManager) {
|
|
|
|
DisplayItemDataEntry* entry = mNewDisplayItemData.PutEntry(aContainerFrame);
|
|
|
|
if (entry) {
|
|
|
|
entry->mData.AppendElement(
|
|
|
|
DisplayItemData(containerLayer, containerDisplayItemKey));
|
|
|
|
}
|
|
|
|
|
2011-03-10 23:58:29 -08:00
|
|
|
nsPoint* offsetAtLastPaint = static_cast<nsPoint*>
|
|
|
|
(props.Get(ThebesLayerLastPaintOffsetProperty()));
|
|
|
|
nsPoint currentOffset = aBuilder->ToReferenceFrame(aContainerFrame);
|
|
|
|
|
2010-07-15 14:07:51 -07:00
|
|
|
nsRegion* invalidThebesContent(static_cast<nsRegion*>
|
|
|
|
(props.Get(ThebesLayerInvalidRegionProperty())));
|
|
|
|
if (invalidThebesContent) {
|
2011-03-10 23:58:29 -08:00
|
|
|
nsPoint offset = offsetAtLastPaint ? *offsetAtLastPaint : currentOffset;
|
2010-07-15 14:07:51 -07:00
|
|
|
invalidThebesContent->MoveBy(offset);
|
|
|
|
state.SetInvalidThebesContent(invalidThebesContent->
|
2011-02-22 21:38:09 -08:00
|
|
|
ToOutsidePixels(appUnitsPerDevPixel));
|
2010-08-30 17:46:26 -07:00
|
|
|
// We have to preserve the current contents of invalidThebesContent
|
|
|
|
// because there might be multiple container layers for the same
|
|
|
|
// frame and we need to invalidate the ThebesLayer children of all
|
|
|
|
// of them.
|
2010-07-15 14:07:51 -07:00
|
|
|
invalidThebesContent->MoveBy(-offset);
|
|
|
|
} else {
|
2010-08-30 17:46:26 -07:00
|
|
|
// The region was deleted to indicate that everything should be
|
|
|
|
// invalidated.
|
|
|
|
state.SetInvalidateAllThebesContent();
|
2010-07-15 14:07:51 -07:00
|
|
|
}
|
2011-03-10 23:58:29 -08:00
|
|
|
SetHasContainerLayer(aContainerFrame, currentOffset);
|
2010-05-20 20:20:48 -07:00
|
|
|
}
|
2010-07-15 14:07:51 -07:00
|
|
|
|
2010-09-09 08:21:46 -07:00
|
|
|
Clip clip;
|
|
|
|
state.ProcessDisplayItems(aChildren, clip);
|
2010-07-15 14:07:51 -07:00
|
|
|
|
2010-12-19 17:26:14 -08:00
|
|
|
// Set CONTENT_COMPONENT_ALPHA if any of our children have it.
|
2010-12-19 17:26:14 -08:00
|
|
|
// This is suboptimal ... a child could have text that's over transparent
|
|
|
|
// pixels in its own layer, but over opaque parts of previous siblings.
|
|
|
|
PRUint32 flags;
|
|
|
|
state.Finish(&flags);
|
|
|
|
|
2011-02-22 21:38:09 -08:00
|
|
|
nsRect bounds = state.GetChildrenBounds();
|
|
|
|
NS_ASSERTION(bounds == aChildren.GetBounds(aBuilder), "Wrong bounds");
|
|
|
|
nsIntRect pixBounds = bounds.ToOutsidePixels(appUnitsPerDevPixel);
|
|
|
|
containerLayer->SetVisibleRegion(pixBounds);
|
|
|
|
// Make sure that rounding the visible region out didn't add any area
|
|
|
|
// we won't paint
|
|
|
|
if (aChildren.IsOpaque() && !aChildren.NeedsTransparentSurface() &&
|
|
|
|
bounds.Contains(pixBounds.ToAppUnits(appUnitsPerDevPixel))) {
|
2010-12-19 17:26:14 -08:00
|
|
|
// Clear CONTENT_COMPONENT_ALPHA
|
|
|
|
flags = Layer::CONTENT_OPAQUE;
|
2010-12-19 17:26:14 -08:00
|
|
|
}
|
2010-09-02 02:18:40 -07:00
|
|
|
containerLayer->SetContentFlags(flags);
|
2010-12-19 17:26:14 -08:00
|
|
|
|
2010-08-05 15:11:23 -07:00
|
|
|
return containerLayer.forget();
|
2010-05-20 20:20:48 -07:00
|
|
|
}
|
|
|
|
|
2010-07-15 14:07:46 -07:00
|
|
|
Layer*
|
|
|
|
FrameLayerBuilder::GetLeafLayerFor(nsDisplayListBuilder* aBuilder,
|
|
|
|
LayerManager* aManager,
|
|
|
|
nsDisplayItem* aItem)
|
|
|
|
{
|
2010-07-15 14:07:51 -07:00
|
|
|
if (aManager != mRetainingManager)
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
nsIFrame* f = aItem->GetUnderlyingFrame();
|
|
|
|
NS_ASSERTION(f, "Can only call GetLeafLayerFor on items that have a frame");
|
|
|
|
Layer* layer = GetOldLayerFor(f, aItem->GetPerFrameKey());
|
|
|
|
if (!layer)
|
|
|
|
return nsnull;
|
2010-09-02 02:18:39 -07:00
|
|
|
if (layer->HasUserData(&gThebesDisplayItemLayerUserData)) {
|
2010-07-15 14:07:51 -07:00
|
|
|
// This layer was created to render Thebes-rendered content for this
|
|
|
|
// display item. The display item should not use it for its own
|
|
|
|
// layer rendering.
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
// Clear clip rect; the caller is responsible for setting it.
|
|
|
|
layer->SetClipRect(nsnull);
|
|
|
|
return layer;
|
2010-07-15 14:07:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
FrameLayerBuilder::InvalidateThebesLayerContents(nsIFrame* aFrame,
|
|
|
|
const nsRect& aRect)
|
|
|
|
{
|
2010-07-15 14:07:51 -07:00
|
|
|
nsRegion* invalidThebesContent = static_cast<nsRegion*>
|
|
|
|
(aFrame->Properties().Get(ThebesLayerInvalidRegionProperty()));
|
|
|
|
if (!invalidThebesContent)
|
|
|
|
return;
|
|
|
|
invalidThebesContent->Or(*invalidThebesContent, aRect);
|
|
|
|
invalidThebesContent->SimplifyOutward(20);
|
|
|
|
}
|
|
|
|
|
2010-08-30 17:46:26 -07:00
|
|
|
/**
|
|
|
|
* Returns true if we find a descendant with a container layer
|
|
|
|
*/
|
|
|
|
static PRBool
|
|
|
|
InternalInvalidateThebesLayersInSubtree(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
if (!(aFrame->GetStateBits() & NS_FRAME_HAS_CONTAINER_LAYER_DESCENDANT))
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
PRBool foundContainerLayer = PR_FALSE;
|
|
|
|
if (aFrame->GetStateBits() & NS_FRAME_HAS_CONTAINER_LAYER) {
|
|
|
|
// Delete the invalid region to indicate that all Thebes contents
|
|
|
|
// need to be invalidated
|
|
|
|
aFrame->Properties().Delete(ThebesLayerInvalidRegionProperty());
|
|
|
|
foundContainerLayer = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 listIndex = 0;
|
|
|
|
nsIAtom* childList = nsnull;
|
|
|
|
do {
|
|
|
|
nsIFrame* child = aFrame->GetFirstChild(childList);
|
|
|
|
if (!child && !childList) {
|
2010-08-30 17:49:07 -07:00
|
|
|
nsSubDocumentFrame* subdocumentFrame = do_QueryFrame(aFrame);
|
2010-08-30 17:46:26 -07:00
|
|
|
if (subdocumentFrame) {
|
|
|
|
// Descend into the subdocument
|
|
|
|
child = subdocumentFrame->GetSubdocumentRootFrame();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (child) {
|
|
|
|
if (InternalInvalidateThebesLayersInSubtree(child)) {
|
|
|
|
foundContainerLayer = PR_TRUE;
|
|
|
|
}
|
|
|
|
child = child->GetNextSibling();
|
|
|
|
}
|
|
|
|
childList = aFrame->GetAdditionalChildListName(listIndex++);
|
|
|
|
} while (childList);
|
|
|
|
|
|
|
|
if (!foundContainerLayer) {
|
|
|
|
aFrame->RemoveStateBits(NS_FRAME_HAS_CONTAINER_LAYER_DESCENDANT);
|
|
|
|
}
|
|
|
|
return foundContainerLayer;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
FrameLayerBuilder::InvalidateThebesLayersInSubtree(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
InternalInvalidateThebesLayersInSubtree(aFrame);
|
|
|
|
}
|
|
|
|
|
2010-07-15 14:07:51 -07:00
|
|
|
/* static */ void
|
|
|
|
FrameLayerBuilder::InvalidateAllLayers(LayerManager* aManager)
|
|
|
|
{
|
|
|
|
LayerManagerData* data = static_cast<LayerManagerData*>
|
2010-09-02 02:18:39 -07:00
|
|
|
(aManager->GetUserData(&gLayerManagerUserData));
|
2010-07-15 14:07:51 -07:00
|
|
|
if (data) {
|
|
|
|
data->mInvalidateAllLayers = PR_TRUE;
|
|
|
|
}
|
2010-07-15 14:07:46 -07:00
|
|
|
}
|
|
|
|
|
2010-07-15 14:07:53 -07:00
|
|
|
/* static */
|
2011-03-29 11:31:53 -07:00
|
|
|
PRBool
|
|
|
|
FrameLayerBuilder::HasDedicatedLayer(nsIFrame* aFrame, PRUint32 aDisplayItemKey)
|
2010-07-15 14:07:53 -07:00
|
|
|
{
|
|
|
|
void* propValue = aFrame->Properties().Get(DisplayItemDataProperty());
|
|
|
|
if (!propValue)
|
2011-03-29 11:31:53 -07:00
|
|
|
return PR_FALSE;
|
2010-07-15 14:07:53 -07:00
|
|
|
|
|
|
|
nsTArray<DisplayItemData>* array =
|
|
|
|
(reinterpret_cast<nsTArray<DisplayItemData>*>(&propValue));
|
|
|
|
for (PRUint32 i = 0; i < array->Length(); ++i) {
|
|
|
|
if (array->ElementAt(i).mDisplayItemKey == aDisplayItemKey) {
|
2010-09-02 02:18:39 -07:00
|
|
|
Layer* layer = array->ElementAt(i).mLayer;
|
|
|
|
if (!layer->HasUserData(&gColorLayerUserData) &&
|
2011-01-17 13:47:18 -08:00
|
|
|
!layer->HasUserData(&gImageLayerUserData) &&
|
2010-09-02 02:18:39 -07:00
|
|
|
!layer->HasUserData(&gThebesDisplayItemLayerUserData))
|
2011-03-29 11:31:53 -07:00
|
|
|
return PR_TRUE;
|
2010-07-15 14:07:53 -07:00
|
|
|
}
|
|
|
|
}
|
2011-03-29 11:31:53 -07:00
|
|
|
return PR_FALSE;
|
2010-07-15 14:07:53 -07:00
|
|
|
}
|
|
|
|
|
2010-05-20 20:20:48 -07:00
|
|
|
/* static */ void
|
|
|
|
FrameLayerBuilder::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
|
|
|
nsDisplayListBuilder* builder = static_cast<nsDisplayListBuilder*>
|
|
|
|
(aCallbackData);
|
2010-09-17 12:09:08 -07:00
|
|
|
|
|
|
|
if (builder->LayerBuilder()->CheckDOMModified())
|
|
|
|
return;
|
|
|
|
|
2010-07-15 14:08:10 -07:00
|
|
|
nsTArray<ClippedDisplayItem> items;
|
|
|
|
nsIFrame* containerLayerFrame;
|
|
|
|
{
|
|
|
|
ThebesLayerItemsEntry* entry =
|
|
|
|
builder->LayerBuilder()->mThebesLayerItems.GetEntry(aLayer);
|
|
|
|
NS_ASSERTION(entry, "We shouldn't be drawing into a layer with no items!");
|
|
|
|
items.SwapElements(entry->mItems);
|
|
|
|
containerLayerFrame = entry->mContainerLayerFrame;
|
|
|
|
// Later after this point, due to calls to DidEndTransaction
|
|
|
|
// for temporary layer managers, mThebesLayerItems can change,
|
|
|
|
// so 'entry' could become invalid.
|
|
|
|
}
|
2010-03-03 13:37:04 -08:00
|
|
|
|
2010-09-02 02:18:39 -07:00
|
|
|
ThebesDisplayItemLayerUserData* userData =
|
|
|
|
static_cast<ThebesDisplayItemLayerUserData*>
|
|
|
|
(aLayer->GetUserData(&gThebesDisplayItemLayerUserData));
|
|
|
|
NS_ASSERTION(userData, "where did our user data go?");
|
|
|
|
if (NS_GET_A(userData->mForcedBackgroundColor) > 0) {
|
2011-01-04 02:35:57 -08:00
|
|
|
nsIntRect r = aLayer->GetVisibleRegion().GetBounds();
|
|
|
|
aContext->NewPath();
|
|
|
|
aContext->Rectangle(gfxRect(r.x, r.y, r.width, r.height));
|
2010-09-02 02:18:39 -07:00
|
|
|
aContext->SetColor(gfxRGBA(userData->mForcedBackgroundColor));
|
2011-01-04 02:35:57 -08:00
|
|
|
aContext->Fill();
|
2010-09-02 02:18:39 -07:00
|
|
|
}
|
|
|
|
|
2010-07-15 14:07:51 -07:00
|
|
|
gfxMatrix transform;
|
|
|
|
if (!aLayer->GetTransform().Is2D(&transform)) {
|
|
|
|
NS_ERROR("non-2D transform in our Thebes layer!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
NS_ASSERTION(!transform.HasNonIntegerTranslation(),
|
|
|
|
"Matrix not just an integer translation?");
|
|
|
|
// make the origin of the context coincide with the origin of the
|
|
|
|
// ThebesLayer
|
|
|
|
gfxContextMatrixAutoSaveRestore saveMatrix(aContext);
|
|
|
|
aContext->Translate(-gfxPoint(transform.x0, transform.y0));
|
|
|
|
nsIntPoint offset(PRInt32(transform.x0), PRInt32(transform.y0));
|
2010-05-20 20:20:48 -07:00
|
|
|
|
2010-07-15 14:08:10 -07:00
|
|
|
nsPresContext* presContext = containerLayerFrame->PresContext();
|
2010-09-01 21:46:53 -07:00
|
|
|
PRInt32 appUnitsPerDevPixel = presContext->AppUnitsPerDevPixel();
|
2010-07-15 14:07:51 -07:00
|
|
|
nsRect r = (aRegionToInvalidate.GetBounds() + offset).
|
|
|
|
ToAppUnits(appUnitsPerDevPixel);
|
2010-07-15 14:08:11 -07:00
|
|
|
containerLayerFrame->InvalidateWithFlags(r,
|
|
|
|
nsIFrame::INVALIDATE_NO_THEBES_LAYERS |
|
|
|
|
nsIFrame::INVALIDATE_EXCLUDE_CURRENT_PAINT);
|
2010-05-20 20:20:48 -07:00
|
|
|
|
2010-07-15 14:07:51 -07:00
|
|
|
PRUint32 i;
|
|
|
|
// Update visible regions. We need perform visibility analysis again
|
|
|
|
// because we may be asked to draw into part of a ThebesLayer that
|
|
|
|
// isn't actually visible in the window (e.g., because a ThebesLayer
|
|
|
|
// expanded its visible region to a rectangle internally), in which
|
|
|
|
// case the mVisibleRect stored in the display item may be wrong.
|
|
|
|
nsRegion visible = aRegionToDraw.ToAppUnits(appUnitsPerDevPixel);
|
|
|
|
visible.MoveBy(NSIntPixelsToAppUnits(offset.x, appUnitsPerDevPixel),
|
|
|
|
NSIntPixelsToAppUnits(offset.y, appUnitsPerDevPixel));
|
|
|
|
|
2010-07-15 14:08:10 -07:00
|
|
|
for (i = items.Length(); i > 0; --i) {
|
|
|
|
ClippedDisplayItem* cdi = &items[i - 1];
|
2010-07-15 14:07:51 -07:00
|
|
|
|
2010-08-08 11:49:07 -07:00
|
|
|
NS_ASSERTION(AppUnitsPerDevPixel(cdi->mItem) == appUnitsPerDevPixel,
|
|
|
|
"a thebes layer should contain items only at the same zoom");
|
2010-07-15 14:07:51 -07:00
|
|
|
|
2010-09-09 08:21:46 -07:00
|
|
|
NS_ABORT_IF_FALSE(cdi->mClip.mHaveClipRect ||
|
|
|
|
cdi->mClip.mRoundedClipRects.IsEmpty(),
|
|
|
|
"If we have rounded rects, we must have a clip rect");
|
|
|
|
|
|
|
|
if (!cdi->mClip.mHaveClipRect ||
|
|
|
|
(cdi->mClip.mRoundedClipRects.IsEmpty() &&
|
|
|
|
cdi->mClip.mClipRect.Contains(visible.GetBounds()))) {
|
2010-07-15 14:07:51 -07:00
|
|
|
cdi->mItem->RecomputeVisibility(builder, &visible);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do a little dance to account for the fact that we're clipping
|
|
|
|
// to cdi->mClipRect
|
|
|
|
nsRegion clipped;
|
2010-09-09 08:21:46 -07:00
|
|
|
clipped.And(visible, cdi->mClip.mClipRect);
|
2010-07-15 14:07:51 -07:00
|
|
|
nsRegion finalClipped = clipped;
|
|
|
|
cdi->mItem->RecomputeVisibility(builder, &finalClipped);
|
2010-09-09 08:21:46 -07:00
|
|
|
// If we have rounded clip rects, don't subtract from the visible
|
|
|
|
// region since we aren't displaying everything inside the rect.
|
|
|
|
if (cdi->mClip.mRoundedClipRects.IsEmpty()) {
|
|
|
|
nsRegion removed;
|
|
|
|
removed.Sub(clipped, finalClipped);
|
|
|
|
nsRegion newVisible;
|
|
|
|
newVisible.Sub(visible, removed);
|
|
|
|
// Don't let the visible region get too complex.
|
|
|
|
if (newVisible.GetNumRects() <= 15) {
|
|
|
|
visible = newVisible;
|
|
|
|
}
|
2010-07-15 14:07:51 -07:00
|
|
|
}
|
2011-01-26 10:36:11 -08:00
|
|
|
if (!cdi->mClip.IsRectClippedByRoundedCorner(cdi->mItem->GetVisibleRect())) {
|
|
|
|
cdi->mClip.RemoveRoundedCorners();
|
|
|
|
}
|
2010-07-15 14:07:51 -07:00
|
|
|
}
|
|
|
|
|
2010-08-08 11:49:07 -07:00
|
|
|
nsRefPtr<nsIRenderingContext> rc;
|
|
|
|
nsresult rv =
|
|
|
|
presContext->DeviceContext()->CreateRenderingContextInstance(*getter_AddRefs(rc));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return;
|
|
|
|
rc->Init(presContext->DeviceContext(), aContext);
|
|
|
|
|
2010-09-09 08:21:46 -07:00
|
|
|
Clip currentClip;
|
2010-08-08 11:49:07 -07:00
|
|
|
PRBool setClipRect = PR_FALSE;
|
|
|
|
|
2010-07-15 14:08:10 -07:00
|
|
|
for (i = 0; i < items.Length(); ++i) {
|
|
|
|
ClippedDisplayItem* cdi = &items[i];
|
2010-07-15 14:07:51 -07:00
|
|
|
|
|
|
|
if (cdi->mItem->GetVisibleRect().IsEmpty())
|
|
|
|
continue;
|
|
|
|
|
2010-05-20 20:20:48 -07:00
|
|
|
// If the new desired clip state is different from the current state,
|
|
|
|
// update the clip.
|
2010-09-09 08:21:46 -07:00
|
|
|
if (setClipRect != cdi->mClip.mHaveClipRect ||
|
|
|
|
(cdi->mClip.mHaveClipRect && cdi->mClip != currentClip)) {
|
2010-05-20 20:20:48 -07:00
|
|
|
if (setClipRect) {
|
|
|
|
aContext->Restore();
|
|
|
|
}
|
2010-09-09 08:21:46 -07:00
|
|
|
setClipRect = cdi->mClip.mHaveClipRect;
|
2010-05-20 20:20:48 -07:00
|
|
|
if (setClipRect) {
|
2010-09-09 08:21:46 -07:00
|
|
|
currentClip = cdi->mClip;
|
2010-05-20 20:20:48 -07:00
|
|
|
aContext->Save();
|
2010-09-09 08:21:46 -07:00
|
|
|
currentClip.ApplyTo(aContext, presContext);
|
2010-05-20 20:20:48 -07:00
|
|
|
}
|
|
|
|
}
|
2010-07-15 14:07:51 -07:00
|
|
|
|
2011-02-10 00:58:11 -08:00
|
|
|
if (cdi->mInactiveLayer) {
|
|
|
|
PaintInactiveLayer(builder, cdi->mItem, aContext);
|
2010-07-15 14:08:05 -07:00
|
|
|
} else {
|
|
|
|
cdi->mItem->Paint(builder, rc);
|
2010-05-20 20:20:48 -07:00
|
|
|
}
|
2010-09-17 12:09:08 -07:00
|
|
|
|
|
|
|
if (builder->LayerBuilder()->CheckDOMModified())
|
|
|
|
break;
|
2010-05-20 20:20:48 -07:00
|
|
|
}
|
2010-07-15 14:07:51 -07:00
|
|
|
|
2010-05-20 20:20:48 -07:00
|
|
|
if (setClipRect) {
|
|
|
|
aContext->Restore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-17 12:09:08 -07:00
|
|
|
PRBool
|
|
|
|
FrameLayerBuilder::CheckDOMModified()
|
|
|
|
{
|
2010-09-18 11:43:17 -07:00
|
|
|
if (!mRootPresContext ||
|
2010-09-17 12:09:08 -07:00
|
|
|
mInitialDOMGeneration == mRootPresContext->GetDOMGeneration())
|
|
|
|
return PR_FALSE;
|
|
|
|
if (mDetectedDOMModification) {
|
|
|
|
// Don't spam the console with extra warnings
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
mDetectedDOMModification = PR_TRUE;
|
|
|
|
// Painting is not going to complete properly. There's not much
|
|
|
|
// we can do here though. Invalidating the window to get another repaint
|
|
|
|
// is likely to lead to an infinite repaint loop.
|
|
|
|
NS_WARNING("Detected DOM modification during paint, bailing out!");
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2010-07-15 14:07:51 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
void
|
|
|
|
FrameLayerBuilder::DumpRetainedLayerTree()
|
|
|
|
{
|
|
|
|
if (mRetainingManager) {
|
2010-07-21 11:06:33 -07:00
|
|
|
mRetainingManager->Dump(stderr);
|
2010-07-15 14:07:51 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-09-09 08:21:46 -07:00
|
|
|
FrameLayerBuilder::Clip::Clip(const Clip& aOther, nsDisplayItem* aClipItem)
|
|
|
|
: mRoundedClipRects(aOther.mRoundedClipRects),
|
|
|
|
mHaveClipRect(PR_TRUE)
|
|
|
|
{
|
|
|
|
nsDisplayItem::Type type = aClipItem->GetType();
|
|
|
|
NS_ABORT_IF_FALSE(type == nsDisplayItem::TYPE_CLIP ||
|
|
|
|
type == nsDisplayItem::TYPE_CLIP_ROUNDED_RECT,
|
|
|
|
"unexpected display item type");
|
|
|
|
nsDisplayClip* item = static_cast<nsDisplayClip*>(aClipItem);
|
|
|
|
// Always intersect with mClipRect, even if we're going to add a
|
|
|
|
// rounded rect.
|
|
|
|
if (aOther.mHaveClipRect) {
|
|
|
|
mClipRect.IntersectRect(aOther.mClipRect, item->GetClipRect());
|
|
|
|
} else {
|
|
|
|
mClipRect = item->GetClipRect();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == nsDisplayItem::TYPE_CLIP_ROUNDED_RECT) {
|
|
|
|
RoundedRect *rr = mRoundedClipRects.AppendElement();
|
|
|
|
if (rr) {
|
|
|
|
rr->mRect = item->GetClipRect();
|
|
|
|
static_cast<nsDisplayClipRoundedRect*>(item)->GetRadii(rr->mRadii);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: Optimize away excess rounded rectangles due to the new addition.
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FrameLayerBuilder::Clip::ApplyTo(gfxContext* aContext,
|
|
|
|
nsPresContext* aPresContext)
|
|
|
|
{
|
|
|
|
aContext->NewPath();
|
|
|
|
PRInt32 A2D = aPresContext->AppUnitsPerDevPixel();
|
|
|
|
gfxRect clip = nsLayoutUtils::RectToGfxRect(mClipRect, A2D);
|
|
|
|
aContext->Rectangle(clip, PR_TRUE);
|
|
|
|
aContext->Clip();
|
|
|
|
|
|
|
|
for (PRUint32 i = 0, iEnd = mRoundedClipRects.Length();
|
|
|
|
i < iEnd; ++i) {
|
|
|
|
const Clip::RoundedRect &rr = mRoundedClipRects[i];
|
|
|
|
|
|
|
|
gfxCornerSizes pixelRadii;
|
|
|
|
nsCSSRendering::ComputePixelRadii(rr.mRadii, A2D, &pixelRadii);
|
|
|
|
|
|
|
|
clip = nsLayoutUtils::RectToGfxRect(rr.mRect, A2D);
|
|
|
|
clip.Round();
|
|
|
|
clip.Condition();
|
|
|
|
// REVIEW: This might make clip empty. Is that OK?
|
|
|
|
|
|
|
|
aContext->NewPath();
|
|
|
|
aContext->RoundedRectangle(clip, pixelRadii);
|
|
|
|
aContext->Clip();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-02 17:48:09 -08:00
|
|
|
nsRect
|
|
|
|
FrameLayerBuilder::Clip::ApproximateIntersect(const nsRect& aRect) const
|
|
|
|
{
|
|
|
|
nsRect r = aRect;
|
|
|
|
if (mHaveClipRect) {
|
|
|
|
r.IntersectRect(r, mClipRect);
|
|
|
|
}
|
|
|
|
for (PRUint32 i = 0, iEnd = mRoundedClipRects.Length();
|
|
|
|
i < iEnd; ++i) {
|
|
|
|
const Clip::RoundedRect &rr = mRoundedClipRects[i];
|
|
|
|
nsRegion rgn = nsLayoutUtils::RoundedRectIntersectRect(rr.mRect, rr.mRadii, r);
|
|
|
|
r = rgn.GetLargestRectangle();
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2011-01-26 10:36:11 -08:00
|
|
|
// Test if (aXPoint, aYPoint) is in the ellipse with center (aXCenter, aYCenter)
|
|
|
|
// and radii aXRadius, aYRadius.
|
|
|
|
bool IsInsideEllipse(nscoord aXRadius, nscoord aXCenter, nscoord aXPoint,
|
|
|
|
nscoord aYRadius, nscoord aYCenter, nscoord aYPoint)
|
|
|
|
{
|
|
|
|
float scaledX = float(aXPoint - aXCenter) / float(aXRadius);
|
|
|
|
float scaledY = float(aYPoint - aYCenter) / float(aYRadius);
|
|
|
|
return scaledX * scaledX + scaledY * scaledY < 1.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
FrameLayerBuilder::Clip::IsRectClippedByRoundedCorner(const nsRect& aRect) const
|
|
|
|
{
|
|
|
|
if (mRoundedClipRects.IsEmpty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
nsRect rect;
|
|
|
|
rect.IntersectRect(aRect, NonRoundedIntersection());
|
|
|
|
for (PRUint32 i = 0, iEnd = mRoundedClipRects.Length();
|
|
|
|
i < iEnd; ++i) {
|
|
|
|
const Clip::RoundedRect &rr = mRoundedClipRects[i];
|
|
|
|
// top left
|
|
|
|
if (rect.x < rr.mRect.x + rr.mRadii[NS_CORNER_TOP_LEFT_X] &&
|
|
|
|
rect.y < rr.mRect.y + rr.mRadii[NS_CORNER_TOP_LEFT_Y]) {
|
|
|
|
if (!IsInsideEllipse(rr.mRadii[NS_CORNER_TOP_LEFT_X],
|
|
|
|
rr.mRect.x + rr.mRadii[NS_CORNER_TOP_LEFT_X],
|
|
|
|
rect.x,
|
|
|
|
rr.mRadii[NS_CORNER_TOP_LEFT_Y],
|
|
|
|
rr.mRect.y + rr.mRadii[NS_CORNER_TOP_LEFT_Y],
|
|
|
|
rect.y)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// top right
|
|
|
|
if (rect.XMost() > rr.mRect.XMost() - rr.mRadii[NS_CORNER_TOP_RIGHT_X] &&
|
|
|
|
rect.y < rr.mRect.y + rr.mRadii[NS_CORNER_TOP_RIGHT_Y]) {
|
|
|
|
if (!IsInsideEllipse(rr.mRadii[NS_CORNER_TOP_RIGHT_X],
|
|
|
|
rr.mRect.XMost() - rr.mRadii[NS_CORNER_TOP_RIGHT_X],
|
|
|
|
rect.XMost(),
|
|
|
|
rr.mRadii[NS_CORNER_TOP_RIGHT_Y],
|
|
|
|
rr.mRect.y + rr.mRadii[NS_CORNER_TOP_RIGHT_Y],
|
|
|
|
rect.y)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// bottom left
|
|
|
|
if (rect.x < rr.mRect.x + rr.mRadii[NS_CORNER_BOTTOM_LEFT_X] &&
|
|
|
|
rect.YMost() > rr.mRect.YMost() - rr.mRadii[NS_CORNER_BOTTOM_LEFT_Y]) {
|
|
|
|
if (!IsInsideEllipse(rr.mRadii[NS_CORNER_BOTTOM_LEFT_X],
|
|
|
|
rr.mRect.x + rr.mRadii[NS_CORNER_BOTTOM_LEFT_X],
|
|
|
|
rect.x,
|
|
|
|
rr.mRadii[NS_CORNER_BOTTOM_LEFT_Y],
|
|
|
|
rr.mRect.YMost() - rr.mRadii[NS_CORNER_BOTTOM_LEFT_Y],
|
|
|
|
rect.YMost())) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// bottom right
|
|
|
|
if (rect.XMost() > rr.mRect.XMost() - rr.mRadii[NS_CORNER_BOTTOM_RIGHT_X] &&
|
|
|
|
rect.YMost() > rr.mRect.YMost() - rr.mRadii[NS_CORNER_BOTTOM_RIGHT_Y]) {
|
|
|
|
if (!IsInsideEllipse(rr.mRadii[NS_CORNER_BOTTOM_RIGHT_X],
|
|
|
|
rr.mRect.XMost() - rr.mRadii[NS_CORNER_BOTTOM_RIGHT_X],
|
|
|
|
rect.XMost(),
|
|
|
|
rr.mRadii[NS_CORNER_BOTTOM_RIGHT_Y],
|
|
|
|
rr.mRect.YMost() - rr.mRadii[NS_CORNER_BOTTOM_RIGHT_Y],
|
|
|
|
rect.YMost())) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect
|
|
|
|
FrameLayerBuilder::Clip::NonRoundedIntersection() const
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!mRoundedClipRects.IsEmpty(), "no rounded clip rects?");
|
|
|
|
nsRect result = mClipRect;
|
|
|
|
for (PRUint32 i = 0, iEnd = mRoundedClipRects.Length();
|
|
|
|
i < iEnd; ++i) {
|
|
|
|
result.IntersectRect(result, mRoundedClipRects[i].mRect);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FrameLayerBuilder::Clip::RemoveRoundedCorners()
|
|
|
|
{
|
|
|
|
if (mRoundedClipRects.IsEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
mClipRect = NonRoundedIntersection();
|
|
|
|
mRoundedClipRects.Clear();
|
|
|
|
}
|
|
|
|
|
2010-05-20 20:20:48 -07:00
|
|
|
} // namespace mozilla
|