2012-08-29 09:47:18 +04:00
|
|
|
/*-*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "LayerTreeInvalidation.h"
|
2015-06-07 12:27:06 +03:00
|
|
|
|
2013-08-12 03:17:23 +04:00
|
|
|
#include <stdint.h> // for uint32_t
|
|
|
|
#include "ImageContainer.h" // for ImageContainer
|
|
|
|
#include "ImageLayers.h" // for ImageLayer, etc
|
|
|
|
#include "Layers.h" // for Layer, ContainerLayer, etc
|
2015-04-12 05:03:00 +03:00
|
|
|
#include "Units.h" // for ParentLayerIntRect
|
2013-08-12 03:17:23 +04:00
|
|
|
#include "gfxColor.h" // for gfxRGBA
|
2013-10-02 01:01:19 +04:00
|
|
|
#include "GraphicsFilter.h" // for GraphicsFilter
|
2013-08-12 03:17:23 +04:00
|
|
|
#include "gfxRect.h" // for gfxRect
|
|
|
|
#include "gfxUtils.h" // for gfxUtils
|
|
|
|
#include "mozilla/gfx/BaseSize.h" // for BaseSize
|
2013-12-20 20:46:29 +04:00
|
|
|
#include "mozilla/gfx/Point.h" // for IntSize
|
2013-08-12 03:17:23 +04:00
|
|
|
#include "mozilla/mozalloc.h" // for operator new, etc
|
|
|
|
#include "nsAutoPtr.h" // for nsRefPtr, nsAutoPtr, etc
|
|
|
|
#include "nsDataHashtable.h" // for nsDataHashtable
|
|
|
|
#include "nsDebug.h" // for NS_ASSERTION
|
|
|
|
#include "nsHashKeys.h" // for nsPtrHashKey
|
|
|
|
#include "nsISupportsImpl.h" // for Layer::AddRef, etc
|
2015-04-21 18:04:57 +03:00
|
|
|
#include "nsRect.h" // for IntRect
|
2013-08-12 03:17:23 +04:00
|
|
|
#include "nsTArray.h" // for nsAutoTArray, nsTArray_Impl
|
2015-06-07 12:27:06 +03:00
|
|
|
#include "mozilla/layers/ImageHost.h"
|
|
|
|
#include "mozilla/layers/LayerManagerComposite.h"
|
2012-08-29 09:47:18 +04:00
|
|
|
|
2014-08-01 16:31:47 +04:00
|
|
|
using namespace mozilla::gfx;
|
|
|
|
|
2012-08-29 09:47:18 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
|
|
|
struct LayerPropertiesBase;
|
2015-02-04 00:39:59 +03:00
|
|
|
UniquePtr<LayerPropertiesBase> CloneLayerTreePropertiesInternal(Layer* aRoot, bool aIsMask = false);
|
2012-08-29 09:47:18 +04:00
|
|
|
|
2015-04-21 18:04:57 +03:00
|
|
|
static IntRect
|
|
|
|
TransformRect(const IntRect& aRect, const Matrix4x4& aTransform)
|
2012-08-29 09:47:18 +04:00
|
|
|
{
|
|
|
|
if (aRect.IsEmpty()) {
|
2015-04-21 18:04:57 +03:00
|
|
|
return IntRect();
|
2012-08-29 09:47:18 +04:00
|
|
|
}
|
|
|
|
|
2014-08-01 16:31:47 +04:00
|
|
|
Rect rect(aRect.x, aRect.y, aRect.width, aRect.height);
|
2012-08-29 09:47:18 +04:00
|
|
|
rect = aTransform.TransformBounds(rect);
|
|
|
|
rect.RoundOut();
|
|
|
|
|
2015-04-21 18:04:57 +03:00
|
|
|
IntRect intRect;
|
2014-08-01 16:31:47 +04:00
|
|
|
if (!gfxUtils::GfxRectToIntRect(ThebesRect(rect), &intRect)) {
|
2015-04-21 18:04:57 +03:00
|
|
|
return IntRect();
|
2012-08-29 09:47:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return intRect;
|
|
|
|
}
|
|
|
|
|
2012-11-12 22:31:15 +04:00
|
|
|
static void
|
2014-08-01 16:31:47 +04:00
|
|
|
AddTransformedRegion(nsIntRegion& aDest, const nsIntRegion& aSource, const Matrix4x4& aTransform)
|
2012-11-12 22:31:15 +04:00
|
|
|
{
|
|
|
|
nsIntRegionRectIterator iter(aSource);
|
2015-04-21 18:04:57 +03:00
|
|
|
const IntRect *r;
|
2012-11-12 22:31:15 +04:00
|
|
|
while ((r = iter.Next())) {
|
|
|
|
aDest.Or(aDest, TransformRect(*r, aTransform));
|
|
|
|
}
|
2014-04-28 08:17:31 +04:00
|
|
|
aDest.SimplifyOutward(20);
|
2012-11-12 22:31:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
AddRegion(nsIntRegion& aDest, const nsIntRegion& aSource)
|
|
|
|
{
|
|
|
|
aDest.Or(aDest, aSource);
|
2014-04-28 08:17:31 +04:00
|
|
|
aDest.SimplifyOutward(20);
|
2012-11-12 22:31:15 +04:00
|
|
|
}
|
|
|
|
|
2012-08-29 09:47:18 +04:00
|
|
|
/**
|
|
|
|
* Walks over this layer, and all descendant layers.
|
|
|
|
* If any of these are a ContainerLayer that reports invalidations to a PresShell,
|
|
|
|
* then report that the entire bounds have changed.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
NotifySubdocumentInvalidationRecursive(Layer* aLayer, NotifySubDocInvalidationFunc aCallback)
|
|
|
|
{
|
|
|
|
aLayer->ClearInvalidRect();
|
|
|
|
ContainerLayer* container = aLayer->AsContainerLayer();
|
|
|
|
|
|
|
|
if (aLayer->GetMaskLayer()) {
|
|
|
|
NotifySubdocumentInvalidationRecursive(aLayer->GetMaskLayer(), aCallback);
|
|
|
|
}
|
2015-06-21 19:27:31 +03:00
|
|
|
for (size_t i = 0; i < aLayer->GetAncestorMaskLayerCount(); i++) {
|
|
|
|
Layer* maskLayer = aLayer->GetAncestorMaskLayerAt(i);
|
|
|
|
NotifySubdocumentInvalidationRecursive(maskLayer, aCallback);
|
|
|
|
}
|
2012-08-29 09:47:18 +04:00
|
|
|
|
|
|
|
if (!container) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Layer* child = container->GetFirstChild(); child; child = child->GetNextSibling()) {
|
|
|
|
NotifySubdocumentInvalidationRecursive(child, aCallback);
|
|
|
|
}
|
|
|
|
|
|
|
|
aCallback(container, container->GetVisibleRegion());
|
|
|
|
}
|
|
|
|
|
|
|
|
struct LayerPropertiesBase : public LayerProperties
|
|
|
|
{
|
2014-08-20 08:55:14 +04:00
|
|
|
explicit LayerPropertiesBase(Layer* aLayer)
|
2012-08-29 09:47:18 +04:00
|
|
|
: mLayer(aLayer)
|
|
|
|
, mMaskLayer(nullptr)
|
2012-10-01 07:38:46 +04:00
|
|
|
, mVisibleRegion(aLayer->GetVisibleRegion())
|
2013-11-21 23:25:16 +04:00
|
|
|
, mInvalidRegion(aLayer->GetInvalidRegion())
|
2014-05-12 23:37:20 +04:00
|
|
|
, mPostXScale(aLayer->GetPostXScale())
|
|
|
|
, mPostYScale(aLayer->GetPostYScale())
|
2014-04-04 05:59:13 +04:00
|
|
|
, mOpacity(aLayer->GetLocalOpacity())
|
2012-08-29 09:47:18 +04:00
|
|
|
, mUseClipRect(!!aLayer->GetClipRect())
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(LayerPropertiesBase);
|
|
|
|
if (aLayer->GetMaskLayer()) {
|
2015-02-04 00:39:59 +03:00
|
|
|
mMaskLayer = CloneLayerTreePropertiesInternal(aLayer->GetMaskLayer(), true);
|
2012-08-29 09:47:18 +04:00
|
|
|
}
|
2015-06-21 19:27:31 +03:00
|
|
|
for (size_t i = 0; i < aLayer->GetAncestorMaskLayerCount(); i++) {
|
|
|
|
Layer* maskLayer = aLayer->GetAncestorMaskLayerAt(i);
|
|
|
|
mAncestorMaskLayers.AppendElement(CloneLayerTreePropertiesInternal(maskLayer, true));
|
|
|
|
}
|
2012-08-29 09:47:18 +04:00
|
|
|
if (mUseClipRect) {
|
|
|
|
mClipRect = *aLayer->GetClipRect();
|
|
|
|
}
|
2014-10-01 22:04:19 +04:00
|
|
|
mTransform = aLayer->GetLocalTransform();
|
2012-08-29 09:47:18 +04:00
|
|
|
}
|
|
|
|
LayerPropertiesBase()
|
|
|
|
: mLayer(nullptr)
|
|
|
|
, mMaskLayer(nullptr)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(LayerPropertiesBase);
|
|
|
|
}
|
|
|
|
~LayerPropertiesBase()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(LayerPropertiesBase);
|
|
|
|
}
|
2015-04-21 18:04:57 +03:00
|
|
|
|
|
|
|
virtual nsIntRegion ComputeDifferences(Layer* aRoot,
|
2014-04-04 05:59:13 +04:00
|
|
|
NotifySubDocInvalidationFunc aCallback,
|
|
|
|
bool* aGeometryChanged);
|
2012-08-29 09:47:18 +04:00
|
|
|
|
2015-04-21 18:04:57 +03:00
|
|
|
virtual void MoveBy(const IntPoint& aOffset);
|
2012-09-17 02:57:22 +04:00
|
|
|
|
2014-04-04 05:59:13 +04:00
|
|
|
nsIntRegion ComputeChange(NotifySubDocInvalidationFunc aCallback,
|
|
|
|
bool& aGeometryChanged)
|
2012-08-29 09:47:18 +04:00
|
|
|
{
|
2015-06-16 02:20:59 +03:00
|
|
|
bool transformChanged = !mTransform.FuzzyEqualsMultiplicative(mLayer->GetLocalTransform()) ||
|
2014-05-12 23:37:20 +04:00
|
|
|
mLayer->GetPostXScale() != mPostXScale ||
|
|
|
|
mLayer->GetPostYScale() != mPostYScale;
|
2015-04-12 05:03:00 +03:00
|
|
|
const Maybe<ParentLayerIntRect>& otherClip = mLayer->GetClipRect();
|
2012-11-12 22:31:15 +04:00
|
|
|
nsIntRegion result;
|
2015-06-21 19:27:31 +03:00
|
|
|
|
|
|
|
bool ancestorMaskChanged = mAncestorMaskLayers.Length() != mLayer->GetAncestorMaskLayerCount();
|
|
|
|
if (!ancestorMaskChanged) {
|
|
|
|
for (size_t i = 0; i < mAncestorMaskLayers.Length(); i++) {
|
|
|
|
if (mLayer->GetAncestorMaskLayerAt(i) != mAncestorMaskLayers[i]->mLayer) {
|
|
|
|
ancestorMaskChanged = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Layer* otherMask = mLayer->GetMaskLayer();
|
2012-08-29 09:47:18 +04:00
|
|
|
if ((mMaskLayer ? mMaskLayer->mLayer : nullptr) != otherMask ||
|
2015-06-21 19:27:31 +03:00
|
|
|
ancestorMaskChanged ||
|
2012-08-29 09:47:18 +04:00
|
|
|
(mUseClipRect != !!otherClip) ||
|
2014-04-04 05:59:13 +04:00
|
|
|
mLayer->GetLocalOpacity() != mOpacity ||
|
2012-08-29 09:47:18 +04:00
|
|
|
transformChanged)
|
|
|
|
{
|
2014-04-04 05:59:13 +04:00
|
|
|
aGeometryChanged = true;
|
2012-08-29 09:47:18 +04:00
|
|
|
result = OldTransformedBounds();
|
2014-06-11 01:46:42 +04:00
|
|
|
AddRegion(result, NewTransformedBounds());
|
2012-08-29 09:47:18 +04:00
|
|
|
|
2014-11-19 01:33:36 +03:00
|
|
|
// We can't bail out early because we need to update mChildrenChanged.
|
2012-08-29 09:47:18 +04:00
|
|
|
}
|
|
|
|
|
2014-04-04 05:59:13 +04:00
|
|
|
AddRegion(result, ComputeChangeInternal(aCallback, aGeometryChanged));
|
2013-09-06 13:29:13 +04:00
|
|
|
AddTransformedRegion(result, mLayer->GetInvalidRegion(), mTransform);
|
2012-08-29 09:47:18 +04:00
|
|
|
|
|
|
|
if (mMaskLayer && otherMask) {
|
2014-04-04 05:59:13 +04:00
|
|
|
AddTransformedRegion(result, mMaskLayer->ComputeChange(aCallback, aGeometryChanged),
|
|
|
|
mTransform);
|
2012-08-29 09:47:18 +04:00
|
|
|
}
|
|
|
|
|
2015-06-21 19:27:31 +03:00
|
|
|
for (size_t i = 0;
|
|
|
|
i < std::min(mAncestorMaskLayers.Length(), mLayer->GetAncestorMaskLayerCount());
|
|
|
|
i++)
|
|
|
|
{
|
|
|
|
AddTransformedRegion(result,
|
|
|
|
mAncestorMaskLayers[i]->ComputeChange(aCallback, aGeometryChanged),
|
|
|
|
mTransform);
|
|
|
|
}
|
|
|
|
|
2012-08-29 09:47:18 +04:00
|
|
|
if (mUseClipRect && otherClip) {
|
|
|
|
if (!mClipRect.IsEqualInterior(*otherClip)) {
|
2014-07-07 23:58:26 +04:00
|
|
|
aGeometryChanged = true;
|
2012-08-29 09:47:18 +04:00
|
|
|
nsIntRegion tmp;
|
2015-04-12 05:03:00 +03:00
|
|
|
tmp.Xor(ParentLayerIntRect::ToUntyped(mClipRect), ParentLayerIntRect::ToUntyped(*otherClip));
|
2012-11-12 22:31:15 +04:00
|
|
|
AddRegion(result, tmp);
|
2012-08-29 09:47:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mLayer->ClearInvalidRect();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-04-21 18:04:57 +03:00
|
|
|
IntRect NewTransformedBounds()
|
2012-08-29 09:47:18 +04:00
|
|
|
{
|
2014-10-01 22:04:19 +04:00
|
|
|
return TransformRect(mLayer->GetVisibleRegion().GetBounds(), mLayer->GetLocalTransform());
|
2012-08-29 09:47:18 +04:00
|
|
|
}
|
|
|
|
|
2015-04-21 18:04:57 +03:00
|
|
|
IntRect OldTransformedBounds()
|
2012-08-29 09:47:18 +04:00
|
|
|
{
|
2012-10-01 07:38:46 +04:00
|
|
|
return TransformRect(mVisibleRegion.GetBounds(), mTransform);
|
2012-08-29 09:47:18 +04:00
|
|
|
}
|
|
|
|
|
2014-04-04 05:59:13 +04:00
|
|
|
virtual nsIntRegion ComputeChangeInternal(NotifySubDocInvalidationFunc aCallback,
|
|
|
|
bool& aGeometryChanged)
|
|
|
|
{
|
2015-04-21 18:04:57 +03:00
|
|
|
return IntRect();
|
2014-04-04 05:59:13 +04:00
|
|
|
}
|
2012-08-29 09:47:18 +04:00
|
|
|
|
|
|
|
nsRefPtr<Layer> mLayer;
|
2014-08-25 19:09:39 +04:00
|
|
|
UniquePtr<LayerPropertiesBase> mMaskLayer;
|
2015-06-21 19:27:31 +03:00
|
|
|
nsTArray<UniquePtr<LayerPropertiesBase>> mAncestorMaskLayers;
|
2012-10-01 07:38:46 +04:00
|
|
|
nsIntRegion mVisibleRegion;
|
2013-11-21 23:25:16 +04:00
|
|
|
nsIntRegion mInvalidRegion;
|
2014-08-01 16:31:47 +04:00
|
|
|
Matrix4x4 mTransform;
|
2014-05-12 23:37:20 +04:00
|
|
|
float mPostXScale;
|
|
|
|
float mPostYScale;
|
2012-08-29 09:47:18 +04:00
|
|
|
float mOpacity;
|
2015-04-12 05:03:00 +03:00
|
|
|
ParentLayerIntRect mClipRect;
|
2012-08-29 09:47:18 +04:00
|
|
|
bool mUseClipRect;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ContainerLayerProperties : public LayerPropertiesBase
|
|
|
|
{
|
2014-08-20 08:55:14 +04:00
|
|
|
explicit ContainerLayerProperties(ContainerLayer* aLayer)
|
2012-08-29 09:47:18 +04:00
|
|
|
: LayerPropertiesBase(aLayer)
|
2014-05-12 23:37:20 +04:00
|
|
|
, mPreXScale(aLayer->GetPreXScale())
|
|
|
|
, mPreYScale(aLayer->GetPreYScale())
|
2012-08-29 09:47:18 +04:00
|
|
|
{
|
|
|
|
for (Layer* child = aLayer->GetFirstChild(); child; child = child->GetNextSibling()) {
|
2014-08-25 19:09:39 +04:00
|
|
|
mChildren.AppendElement(Move(CloneLayerTreePropertiesInternal(child)));
|
2012-08-29 09:47:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-04 05:59:13 +04:00
|
|
|
virtual nsIntRegion ComputeChangeInternal(NotifySubDocInvalidationFunc aCallback,
|
|
|
|
bool& aGeometryChanged)
|
2012-08-29 09:47:18 +04:00
|
|
|
{
|
|
|
|
ContainerLayer* container = mLayer->AsContainerLayer();
|
|
|
|
nsIntRegion result;
|
|
|
|
|
2014-11-19 01:33:36 +03:00
|
|
|
bool childrenChanged = false;
|
|
|
|
|
2014-05-12 23:37:20 +04:00
|
|
|
if (mPreXScale != container->GetPreXScale() ||
|
|
|
|
mPreYScale != container->GetPreYScale()) {
|
|
|
|
aGeometryChanged = true;
|
|
|
|
result = OldTransformedBounds();
|
|
|
|
AddRegion(result, NewTransformedBounds());
|
2014-11-19 01:33:36 +03:00
|
|
|
childrenChanged = true;
|
2014-05-12 23:37:20 +04:00
|
|
|
|
2014-11-19 01:33:36 +03:00
|
|
|
// Can't bail out early, we need to update the child container layers
|
2014-05-12 23:37:20 +04:00
|
|
|
}
|
|
|
|
|
2012-11-21 06:23:57 +04:00
|
|
|
// A low frame rate is especially visible to users when scrolling, so we
|
|
|
|
// particularly want to avoid unnecessary invalidation at that time. For us
|
|
|
|
// here, that means avoiding unnecessary invalidation of child items when
|
|
|
|
// other children are added to or removed from our container layer, since
|
|
|
|
// that may be caused by children being scrolled in or out of view. We are
|
|
|
|
// less concerned with children changing order.
|
|
|
|
// TODO: Consider how we could avoid unnecessary invalidation when children
|
|
|
|
// change order, and whether the overhead would be worth it.
|
|
|
|
|
2013-09-02 12:41:57 +04:00
|
|
|
nsDataHashtable<nsPtrHashKey<Layer>, uint32_t> oldIndexMap(mChildren.Length());
|
2012-11-21 06:23:57 +04:00
|
|
|
for (uint32_t i = 0; i < mChildren.Length(); ++i) {
|
|
|
|
oldIndexMap.Put(mChildren[i]->mLayer, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t i = 0; // cursor into the old child list mChildren
|
2012-08-29 09:47:18 +04:00
|
|
|
for (Layer* child = container->GetFirstChild(); child; child = child->GetNextSibling()) {
|
2012-11-21 06:23:57 +04:00
|
|
|
bool invalidateChildsCurrentArea = false;
|
|
|
|
if (i < mChildren.Length()) {
|
|
|
|
uint32_t childsOldIndex;
|
|
|
|
if (oldIndexMap.Get(child, &childsOldIndex)) {
|
|
|
|
if (childsOldIndex >= i) {
|
|
|
|
// Invalidate the old areas of layers that used to be between the
|
|
|
|
// current |child| and the previous |child| that was also in the
|
|
|
|
// old list mChildren (if any of those children have been reordered
|
|
|
|
// rather than removed, we will invalidate their new area when we
|
|
|
|
// encounter them in the new list):
|
|
|
|
for (uint32_t j = i; j < childsOldIndex; ++j) {
|
|
|
|
AddRegion(result, mChildren[j]->OldTransformedBounds());
|
2014-11-19 01:33:36 +03:00
|
|
|
childrenChanged |= true;
|
2012-11-21 06:23:57 +04:00
|
|
|
}
|
2014-11-19 01:33:36 +03:00
|
|
|
// Invalidate any regions of the child that have changed:
|
|
|
|
nsIntRegion region = mChildren[childsOldIndex]->ComputeChange(aCallback, aGeometryChanged);
|
2012-11-21 06:23:57 +04:00
|
|
|
i = childsOldIndex + 1;
|
2014-11-19 01:33:36 +03:00
|
|
|
if (!region.IsEmpty()) {
|
|
|
|
AddRegion(result, region);
|
|
|
|
childrenChanged |= true;
|
|
|
|
}
|
2012-11-21 06:23:57 +04:00
|
|
|
} else {
|
|
|
|
// We've already seen this child in mChildren (which means it must
|
2014-11-19 01:33:36 +03:00
|
|
|
// have been reordered) and invalidated its old area. We need to
|
2012-11-21 06:23:57 +04:00
|
|
|
// invalidate its new area too:
|
|
|
|
invalidateChildsCurrentArea = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// |child| is new
|
|
|
|
invalidateChildsCurrentArea = true;
|
2012-08-29 09:47:18 +04:00
|
|
|
}
|
2012-11-21 06:23:57 +04:00
|
|
|
} else {
|
|
|
|
// |child| is new, or was reordered to a higher index
|
|
|
|
invalidateChildsCurrentArea = true;
|
|
|
|
}
|
|
|
|
if (invalidateChildsCurrentArea) {
|
2014-07-07 23:58:26 +04:00
|
|
|
aGeometryChanged = true;
|
2014-10-01 22:04:19 +04:00
|
|
|
AddTransformedRegion(result, child->GetVisibleRegion(), child->GetLocalTransform());
|
2012-08-29 09:47:18 +04:00
|
|
|
if (aCallback) {
|
|
|
|
NotifySubdocumentInvalidationRecursive(child, aCallback);
|
|
|
|
} else {
|
|
|
|
ClearInvalidations(child);
|
|
|
|
}
|
|
|
|
}
|
2014-11-19 01:33:36 +03:00
|
|
|
childrenChanged |= invalidateChildsCurrentArea;
|
2012-08-29 09:47:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Process remaining removed children.
|
|
|
|
while (i < mChildren.Length()) {
|
2014-11-19 01:33:36 +03:00
|
|
|
childrenChanged |= true;
|
2012-11-12 22:31:15 +04:00
|
|
|
AddRegion(result, mChildren[i]->OldTransformedBounds());
|
2012-08-29 09:47:18 +04:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aCallback) {
|
|
|
|
aCallback(container, result);
|
|
|
|
}
|
|
|
|
|
2014-11-19 01:33:36 +03:00
|
|
|
if (childrenChanged) {
|
|
|
|
container->SetChildrenChanged(true);
|
|
|
|
}
|
|
|
|
|
2015-07-11 03:06:35 +03:00
|
|
|
result.Transform(mLayer->GetLocalTransform());
|
2014-11-19 01:33:36 +03:00
|
|
|
|
2014-06-02 19:05:01 +04:00
|
|
|
return result;
|
2012-08-29 09:47:18 +04:00
|
|
|
}
|
|
|
|
|
2012-11-21 06:23:57 +04:00
|
|
|
// The old list of children:
|
2014-08-25 19:09:39 +04:00
|
|
|
nsAutoTArray<UniquePtr<LayerPropertiesBase>,1> mChildren;
|
2014-05-12 23:37:20 +04:00
|
|
|
float mPreXScale;
|
|
|
|
float mPreYScale;
|
2012-08-29 09:47:18 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ColorLayerProperties : public LayerPropertiesBase
|
|
|
|
{
|
2014-08-20 08:55:14 +04:00
|
|
|
explicit ColorLayerProperties(ColorLayer *aLayer)
|
2012-08-29 09:47:18 +04:00
|
|
|
: LayerPropertiesBase(aLayer)
|
|
|
|
, mColor(aLayer->GetColor())
|
2014-09-24 01:47:36 +04:00
|
|
|
, mBounds(aLayer->GetBounds())
|
2012-08-29 09:47:18 +04:00
|
|
|
{ }
|
|
|
|
|
2014-04-04 05:59:13 +04:00
|
|
|
virtual nsIntRegion ComputeChangeInternal(NotifySubDocInvalidationFunc aCallback,
|
|
|
|
bool& aGeometryChanged)
|
2012-08-29 09:47:18 +04:00
|
|
|
{
|
|
|
|
ColorLayer* color = static_cast<ColorLayer*>(mLayer.get());
|
|
|
|
|
|
|
|
if (mColor != color->GetColor()) {
|
2014-07-07 23:58:26 +04:00
|
|
|
aGeometryChanged = true;
|
2012-08-29 09:47:18 +04:00
|
|
|
return NewTransformedBounds();
|
|
|
|
}
|
|
|
|
|
2014-09-24 01:47:36 +04:00
|
|
|
nsIntRegion boundsDiff;
|
|
|
|
boundsDiff.Xor(mBounds, color->GetBounds());
|
|
|
|
|
|
|
|
nsIntRegion result;
|
|
|
|
AddTransformedRegion(result, boundsDiff, mTransform);
|
|
|
|
|
|
|
|
return result;
|
2012-08-29 09:47:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxRGBA mColor;
|
2015-04-21 18:04:57 +03:00
|
|
|
IntRect mBounds;
|
2012-08-29 09:47:18 +04:00
|
|
|
};
|
|
|
|
|
2015-06-07 12:27:06 +03:00
|
|
|
static ImageHost* GetImageHost(ImageLayer* aLayer)
|
|
|
|
{
|
|
|
|
LayerComposite* composite = aLayer->AsLayerComposite();
|
|
|
|
if (composite) {
|
|
|
|
return static_cast<ImageHost*>(composite->GetCompositableHost());
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2012-08-29 09:47:18 +04:00
|
|
|
struct ImageLayerProperties : public LayerPropertiesBase
|
|
|
|
{
|
2015-02-04 00:39:59 +03:00
|
|
|
explicit ImageLayerProperties(ImageLayer* aImage, bool aIsMask)
|
2012-08-29 09:47:18 +04:00
|
|
|
: LayerPropertiesBase(aImage)
|
|
|
|
, mContainer(aImage->GetContainer())
|
2015-06-07 12:27:06 +03:00
|
|
|
, mImageHost(GetImageHost(aImage))
|
2012-08-29 09:47:18 +04:00
|
|
|
, mFilter(aImage->GetFilter())
|
|
|
|
, mScaleToSize(aImage->GetScaleToSize())
|
|
|
|
, mScaleMode(aImage->GetScaleMode())
|
2015-08-03 20:36:06 +03:00
|
|
|
, mLastProducerID(-1)
|
|
|
|
, mLastFrameID(-1)
|
2015-02-04 00:39:59 +03:00
|
|
|
, mIsMask(aIsMask)
|
2012-08-29 09:47:18 +04:00
|
|
|
{
|
2015-08-03 20:36:06 +03:00
|
|
|
if (mImageHost) {
|
|
|
|
mLastProducerID = mImageHost->GetLastProducerID();
|
|
|
|
mLastFrameID = mImageHost->GetLastFrameID();
|
|
|
|
}
|
2012-08-29 09:47:18 +04:00
|
|
|
}
|
|
|
|
|
2014-04-04 05:59:13 +04:00
|
|
|
virtual nsIntRegion ComputeChangeInternal(NotifySubDocInvalidationFunc aCallback,
|
|
|
|
bool& aGeometryChanged)
|
2012-08-29 09:47:18 +04:00
|
|
|
{
|
|
|
|
ImageLayer* imageLayer = static_cast<ImageLayer*>(mLayer.get());
|
|
|
|
|
|
|
|
if (!imageLayer->GetVisibleRegion().IsEqual(mVisibleRegion)) {
|
2014-07-07 23:58:26 +04:00
|
|
|
aGeometryChanged = true;
|
2015-04-21 18:04:57 +03:00
|
|
|
IntRect result = NewTransformedBounds();
|
2012-08-29 09:47:18 +04:00
|
|
|
result = result.Union(OldTransformedBounds());
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-02-04 00:39:59 +03:00
|
|
|
ImageContainer* container = imageLayer->GetContainer();
|
2015-06-07 12:27:06 +03:00
|
|
|
ImageHost* host = GetImageHost(imageLayer);
|
2015-02-04 00:39:59 +03:00
|
|
|
if (mContainer != container ||
|
2012-08-29 09:47:18 +04:00
|
|
|
mFilter != imageLayer->GetFilter() ||
|
|
|
|
mScaleToSize != imageLayer->GetScaleToSize() ||
|
2015-06-07 12:27:06 +03:00
|
|
|
mScaleMode != imageLayer->GetScaleMode() ||
|
|
|
|
host != mImageHost ||
|
2015-08-03 20:36:06 +03:00
|
|
|
(host && host->GetProducerID() != mLastProducerID) ||
|
|
|
|
(host && host->GetFrameID() != mLastFrameID)) {
|
2014-07-07 23:58:26 +04:00
|
|
|
aGeometryChanged = true;
|
2015-02-04 00:39:59 +03:00
|
|
|
|
|
|
|
if (mIsMask) {
|
|
|
|
// Mask layers have an empty visible region, so we have to
|
|
|
|
// use the image size instead.
|
2015-06-07 12:27:06 +03:00
|
|
|
IntSize size;
|
|
|
|
if (container) {
|
|
|
|
size = container->GetCurrentSize();
|
|
|
|
}
|
|
|
|
if (host) {
|
|
|
|
size = host->GetImageSize();
|
|
|
|
}
|
2015-04-21 18:04:57 +03:00
|
|
|
IntRect rect(0, 0, size.width, size.height);
|
2015-02-04 00:39:59 +03:00
|
|
|
return TransformRect(rect, mLayer->GetLocalTransform());
|
|
|
|
}
|
2015-06-07 12:27:06 +03:00
|
|
|
return NewTransformedBounds();
|
2012-08-29 09:47:18 +04:00
|
|
|
}
|
|
|
|
|
2015-04-21 18:04:57 +03:00
|
|
|
return IntRect();
|
2012-08-29 09:47:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<ImageContainer> mContainer;
|
2015-06-07 12:27:06 +03:00
|
|
|
nsRefPtr<ImageHost> mImageHost;
|
2013-10-02 01:01:19 +04:00
|
|
|
GraphicsFilter mFilter;
|
2013-12-20 20:46:29 +04:00
|
|
|
gfx::IntSize mScaleToSize;
|
2013-08-20 23:45:30 +04:00
|
|
|
ScaleMode mScaleMode;
|
2015-08-03 20:36:06 +03:00
|
|
|
int32_t mLastProducerID;
|
|
|
|
int32_t mLastFrameID;
|
2015-02-04 00:39:59 +03:00
|
|
|
bool mIsMask;
|
2012-08-29 09:47:18 +04:00
|
|
|
};
|
|
|
|
|
2014-08-25 19:09:39 +04:00
|
|
|
UniquePtr<LayerPropertiesBase>
|
2015-02-04 00:39:59 +03:00
|
|
|
CloneLayerTreePropertiesInternal(Layer* aRoot, bool aIsMask /* = false */)
|
2012-08-29 09:47:18 +04:00
|
|
|
{
|
|
|
|
if (!aRoot) {
|
2014-08-25 19:09:39 +04:00
|
|
|
return MakeUnique<LayerPropertiesBase>();
|
2012-08-29 09:47:18 +04:00
|
|
|
}
|
|
|
|
|
2015-02-04 00:39:59 +03:00
|
|
|
MOZ_ASSERT(!aIsMask || aRoot->GetType() == Layer::TYPE_IMAGE);
|
|
|
|
|
2012-08-29 09:47:18 +04:00
|
|
|
switch (aRoot->GetType()) {
|
2014-02-11 08:00:46 +04:00
|
|
|
case Layer::TYPE_CONTAINER:
|
|
|
|
case Layer::TYPE_REF:
|
2014-08-25 19:09:39 +04:00
|
|
|
return MakeUnique<ContainerLayerProperties>(aRoot->AsContainerLayer());
|
2014-02-11 08:00:46 +04:00
|
|
|
case Layer::TYPE_COLOR:
|
2014-08-25 19:09:39 +04:00
|
|
|
return MakeUnique<ColorLayerProperties>(static_cast<ColorLayer*>(aRoot));
|
2014-02-11 08:00:46 +04:00
|
|
|
case Layer::TYPE_IMAGE:
|
2015-02-04 00:39:59 +03:00
|
|
|
return MakeUnique<ImageLayerProperties>(static_cast<ImageLayer*>(aRoot), aIsMask);
|
2015-06-04 09:13:42 +03:00
|
|
|
case Layer::TYPE_CANVAS:
|
|
|
|
case Layer::TYPE_READBACK:
|
|
|
|
case Layer::TYPE_SHADOW:
|
|
|
|
case Layer::TYPE_PAINTED:
|
2014-08-25 19:09:39 +04:00
|
|
|
return MakeUnique<LayerPropertiesBase>(aRoot);
|
2012-08-29 09:47:18 +04:00
|
|
|
}
|
|
|
|
|
2015-06-04 09:13:42 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("Unexpected root layer type");
|
|
|
|
return MakeUnique<LayerPropertiesBase>(aRoot);
|
2012-08-29 09:47:18 +04:00
|
|
|
}
|
|
|
|
|
2014-08-25 19:09:39 +04:00
|
|
|
/* static */ UniquePtr<LayerProperties>
|
2012-08-29 09:47:18 +04:00
|
|
|
LayerProperties::CloneFrom(Layer* aRoot)
|
|
|
|
{
|
|
|
|
return CloneLayerTreePropertiesInternal(aRoot);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
LayerProperties::ClearInvalidations(Layer *aLayer)
|
|
|
|
{
|
|
|
|
aLayer->ClearInvalidRect();
|
|
|
|
if (aLayer->GetMaskLayer()) {
|
|
|
|
ClearInvalidations(aLayer->GetMaskLayer());
|
|
|
|
}
|
2015-06-21 19:27:31 +03:00
|
|
|
for (size_t i = 0; i < aLayer->GetAncestorMaskLayerCount(); i++) {
|
|
|
|
ClearInvalidations(aLayer->GetAncestorMaskLayerAt(i));
|
|
|
|
}
|
2012-08-29 09:47:18 +04:00
|
|
|
|
|
|
|
ContainerLayer* container = aLayer->AsContainerLayer();
|
|
|
|
if (!container) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Layer* child = container->GetFirstChild(); child; child = child->GetNextSibling()) {
|
|
|
|
ClearInvalidations(child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-12 22:31:15 +04:00
|
|
|
nsIntRegion
|
2014-04-04 05:59:13 +04:00
|
|
|
LayerPropertiesBase::ComputeDifferences(Layer* aRoot, NotifySubDocInvalidationFunc aCallback,
|
|
|
|
bool* aGeometryChanged = nullptr)
|
2012-08-29 09:47:18 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aRoot, "Must have a layer tree to compare against!");
|
|
|
|
if (mLayer != aRoot) {
|
|
|
|
if (aCallback) {
|
|
|
|
NotifySubdocumentInvalidationRecursive(aRoot, aCallback);
|
|
|
|
} else {
|
|
|
|
ClearInvalidations(aRoot);
|
|
|
|
}
|
2015-04-21 18:04:57 +03:00
|
|
|
IntRect result = TransformRect(aRoot->GetVisibleRegion().GetBounds(),
|
2014-10-01 22:04:19 +04:00
|
|
|
aRoot->GetLocalTransform());
|
2012-08-29 09:47:18 +04:00
|
|
|
result = result.Union(OldTransformedBounds());
|
2014-04-04 05:59:13 +04:00
|
|
|
if (aGeometryChanged != nullptr) {
|
|
|
|
*aGeometryChanged = true;
|
|
|
|
}
|
2012-08-29 09:47:18 +04:00
|
|
|
return result;
|
|
|
|
} else {
|
2014-04-04 05:59:13 +04:00
|
|
|
bool geometryChanged = (aGeometryChanged != nullptr) ? *aGeometryChanged : false;
|
|
|
|
nsIntRegion invalid = ComputeChange(aCallback, geometryChanged);
|
|
|
|
if (aGeometryChanged != nullptr) {
|
|
|
|
*aGeometryChanged = geometryChanged;
|
|
|
|
}
|
|
|
|
return invalid;
|
2012-08-29 09:47:18 +04:00
|
|
|
}
|
|
|
|
}
|
2014-08-01 16:31:47 +04:00
|
|
|
|
|
|
|
void
|
2015-04-21 18:04:57 +03:00
|
|
|
LayerPropertiesBase::MoveBy(const IntPoint& aOffset)
|
2012-09-17 02:57:22 +04:00
|
|
|
{
|
2014-10-16 13:51:12 +04:00
|
|
|
mTransform.PostTranslate(aOffset.x, aOffset.y, 0);
|
2012-09-17 02:57:22 +04:00
|
|
|
}
|
2012-08-29 09:47:18 +04:00
|
|
|
|
|
|
|
} // namespace layers
|
|
|
|
} // namespace mozilla
|