Skip to content

Commit

Permalink
Bug 1143522 - Convert Layer::mClipRect to ParentLayerIntRect. r=botond
Browse files Browse the repository at this point in the history
Change interface of getter/setter for mClipRect,
also necessary modification for codes that use these resources.

* * *
Bundle mUseClipRect and mClipRect as Maybe<ParentLayerIntRect> mClipRect

--HG--
extra : rebase_source : ca0c60404a28b7418df88104b863760033289910
  • Loading branch information
TheKK committed Apr 12, 2015
1 parent 3066d09 commit f17daf9
Show file tree
Hide file tree
Showing 18 changed files with 151 additions and 120 deletions.
6 changes: 6 additions & 0 deletions gfx/2d/Rect.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ struct IntRectTyped :
yMost += this->height;
return !xMost.isValid() || !yMost.isValid();
}

// This is here only to keep IPDL-generated code happy. DO NOT USE.
bool operator==(const IntRectTyped<units>& aRect) const
{
return IntRectTyped<units>::IsEqualEdges(aRect);
}
};
typedef IntRectTyped<UnknownUnits> IntRect;

Expand Down
6 changes: 4 additions & 2 deletions gfx/layers/LayerMetricsWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,15 +341,17 @@ class MOZ_STACK_CLASS LayerMetricsWrapper {
return region;
}

const nsIntRect* GetClipRect() const
const Maybe<ParentLayerIntRect>& GetClipRect() const
{
MOZ_ASSERT(IsValid());

static const Maybe<ParentLayerIntRect> sNoClipRect = Nothing();

if (AtBottomLayer()) {
return mLayer->GetClipRect();
}

return nullptr;
return sNoClipRect;
}

EventRegionsOverride GetEventRegionsOverride() const
Expand Down
7 changes: 4 additions & 3 deletions gfx/layers/LayerTreeInvalidation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "ImageContainer.h" // for ImageContainer
#include "ImageLayers.h" // for ImageLayer, etc
#include "Layers.h" // for Layer, ContainerLayer, etc
#include "Units.h" // for ParentLayerIntRect
#include "gfxColor.h" // for gfxRGBA
#include "GraphicsFilter.h" // for GraphicsFilter
#include "gfxRect.h" // for gfxRect
Expand Down Expand Up @@ -140,7 +141,7 @@ struct LayerPropertiesBase : public LayerProperties
mLayer->GetPostXScale() != mPostXScale ||
mLayer->GetPostYScale() != mPostYScale;
Layer* otherMask = mLayer->GetMaskLayer();
const nsIntRect* otherClip = mLayer->GetClipRect();
const Maybe<ParentLayerIntRect>& otherClip = mLayer->GetClipRect();
nsIntRegion result;
if ((mMaskLayer ? mMaskLayer->mLayer : nullptr) != otherMask ||
(mUseClipRect != !!otherClip) ||
Expand All @@ -166,7 +167,7 @@ struct LayerPropertiesBase : public LayerProperties
if (!mClipRect.IsEqualInterior(*otherClip)) {
aGeometryChanged = true;
nsIntRegion tmp;
tmp.Xor(mClipRect, *otherClip);
tmp.Xor(ParentLayerIntRect::ToUntyped(mClipRect), ParentLayerIntRect::ToUntyped(*otherClip));
AddRegion(result, tmp);
}
}
Expand Down Expand Up @@ -199,7 +200,7 @@ struct LayerPropertiesBase : public LayerProperties
float mPostXScale;
float mPostYScale;
float mOpacity;
nsIntRect mClipRect;
ParentLayerIntRect mClipRect;
bool mUseClipRect;
};

Expand Down
32 changes: 18 additions & 14 deletions gfx/layers/Layers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "LayerSorter.h" // for SortLayersBy3DZOrder
#include "LayersLogging.h" // for AppendToString
#include "ReadbackLayer.h" // for ReadbackLayer
#include "UnitTransforms.h" // for ViewAs
#include "gfxPlatform.h" // for gfxPlatform
#include "gfxPrefs.h"
#include "gfxUtils.h" // for gfxUtils, etc
Expand Down Expand Up @@ -201,7 +202,6 @@ Layer::Layer(LayerManager* aManager, void* aImplData) :
mMixBlendMode(CompositionOp::OP_OVER),
mForceIsolatedGroup(false),
mContentFlags(0),
mUseClipRect(false),
mUseTileSourceRect(false),
mIsFixedPosition(false),
mMargins(0, 0, 0, 0),
Expand Down Expand Up @@ -547,7 +547,7 @@ Layer::CanUseOpaqueSurface()

// NB: eventually these methods will be defined unconditionally, and
// can be moved into Layers.h
const nsIntRect*
const Maybe<ParentLayerIntRect>&
Layer::GetEffectiveClipRect()
{
if (LayerComposite* shadow = AsLayerComposite()) {
Expand Down Expand Up @@ -673,7 +673,9 @@ Layer::CalculateScissorRect(const RenderTargetIntRect& aCurrentScissorRect)
return currentClip;
}

const RenderTargetIntRect clipRect = RenderTargetPixel::FromUntyped(*GetEffectiveClipRect());
const RenderTargetIntRect clipRect =
ViewAs<RenderTargetPixel>(*GetEffectiveClipRect(),
PixelCastJustification::RenderTargetIsParentLayerForRoot);
if (clipRect.IsEmpty()) {
// We might have a non-translation transform in the container so we can't
// use the code path below.
Expand All @@ -694,7 +696,7 @@ Layer::CalculateScissorRect(const RenderTargetIntRect& aCurrentScissorRect)
if (!gfxUtils::GfxRectToIntRect(trScissor, &tmp)) {
return RenderTargetIntRect(currentClip.TopLeft(), RenderTargetIntSize(0, 0));
}
scissor = RenderTargetPixel::FromUntyped(tmp);
scissor = ViewAs<RenderTargetPixel>(tmp);

// Find the nearest ancestor with an intermediate surface
do {
Expand Down Expand Up @@ -884,7 +886,7 @@ Layer::GetVisibleRegionRelativeToRootLayer(nsIntRegion& aResult,
// If the parent layer clips its lower layers, clip the visible region
// we're accumulating.
if (layer->GetEffectiveClipRect()) {
aResult.AndWith(*layer->GetEffectiveClipRect());
aResult.AndWith(ParentLayerIntRect::ToUntyped(*layer->GetEffectiveClipRect()));
}

// Now we need to walk across the list of siblings for this parent layer,
Expand Down Expand Up @@ -1099,7 +1101,7 @@ ContainerLayer::HasMultipleChildren()
{
uint32_t count = 0;
for (Layer* child = GetFirstChild(); child; child = child->GetNextSibling()) {
const nsIntRect *clipRect = child->GetEffectiveClipRect();
const Maybe<ParentLayerIntRect>& clipRect = child->GetEffectiveClipRect();
if (clipRect && clipRect->IsEmpty())
continue;
if (child->GetVisibleRegion().IsEmpty())
Expand Down Expand Up @@ -1166,7 +1168,7 @@ ContainerLayer::DefaultComputeEffectiveTransforms(const Matrix4x4& aTransformToS
gfx::ThebesMatrix(contTransform).HasNonIntegerTranslation()) {
#endif
for (Layer* child = GetFirstChild(); child; child = child->GetNextSibling()) {
const nsIntRect *clipRect = child->GetEffectiveClipRect();
const Maybe<ParentLayerIntRect>& clipRect = child->GetEffectiveClipRect();
/* We can't (easily) forward our transform to children with a non-empty clip
* rect since it would need to be adjusted for the transform. See
* the calculations performed by CalculateScissorRect above.
Expand Down Expand Up @@ -1565,8 +1567,8 @@ Layer::PrintInfo(std::stringstream& aStream, const char* aPrefix)

layers::PrintInfo(aStream, AsLayerComposite());

if (mUseClipRect) {
AppendToString(aStream, mClipRect, " [clip=", "]");
if (mClipRect) {
AppendToString(aStream, *mClipRect, " [clip=", "]");
}
if (1.0 != mPostXScale || 1.0 != mPostYScale) {
aStream << nsPrintfCString(" [postScale=%g, %g]", mPostXScale, mPostYScale).get();
Expand Down Expand Up @@ -1650,8 +1652,10 @@ DumpTransform(layerscope::LayersPacket::Layer::Matrix* aLayerMatrix, const Matri
}

// The static helper function sets the nsIntRect into the packet
template <typename T, typename Sub, typename Point, typename SizeT, typename MarginT>
static void
DumpRect(layerscope::LayersPacket::Layer::Rect* aLayerRect, const nsIntRect& aRect)
DumpRect(layerscope::LayersPacket::Layer::Rect* aLayerRect,
const BaseRect<T, Sub, Point, SizeT, MarginT>& aRect)
{
aLayerRect->set_x(aRect.x);
aLayerRect->set_y(aRect.y);
Expand Down Expand Up @@ -1682,7 +1686,7 @@ Layer::DumpPacket(layerscope::LayersPacket* aPacket, const void* aParent)
// Shadow
if (LayerComposite* lc = AsLayerComposite()) {
LayersPacket::Layer::Shadow* s = layer->mutable_shadow();
if (const nsIntRect* clipRect = lc->GetShadowClipRect()) {
if (const Maybe<ParentLayerIntRect>& clipRect = lc->GetShadowClipRect()) {
DumpRect(s->mutable_clip(), *clipRect);
}
if (!lc->GetShadowTransform().IsIdentity()) {
Expand All @@ -1693,8 +1697,8 @@ Layer::DumpPacket(layerscope::LayersPacket* aPacket, const void* aParent)
}
}
// Clip
if (mUseClipRect) {
DumpRect(layer->mutable_clip(), mClipRect);
if (mClipRect) {
DumpRect(layer->mutable_clip(), *mClipRect);
}
// Transform
if (!mTransform.IsIdentity()) {
Expand Down Expand Up @@ -2047,7 +2051,7 @@ PrintInfo(std::stringstream& aStream, LayerComposite* aLayerComposite)
if (!aLayerComposite) {
return;
}
if (const nsIntRect* clipRect = aLayerComposite->GetShadowClipRect()) {
if (const Maybe<ParentLayerIntRect>& clipRect = aLayerComposite->GetShadowClipRect()) {
AppendToString(aStream, *clipRect, " [shadow-clip=", "]");
}
if (!aLayerComposite->GetShadowTransform().IsIdentity()) {
Expand Down
27 changes: 13 additions & 14 deletions gfx/layers/Layers.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <stdio.h> // for FILE
#include <sys/types.h> // for int32_t, int64_t
#include "FrameMetrics.h" // for FrameMetrics
#include "Units.h" // for LayerMargin, LayerPoint
#include "Units.h" // for LayerMargin, LayerPoint, ParentLayerIntRect
#include "gfxContext.h" // for GraphicsOperator
#include "gfxTypes.h"
#include "gfxColor.h" // for gfxRGBA
Expand All @@ -21,6 +21,7 @@
#include "mozilla/Assertions.h" // for MOZ_ASSERT_HELPER2, etc
#include "mozilla/DebugOnly.h" // for DebugOnly
#include "mozilla/EventForwards.h" // for nsPaintEvent
#include "mozilla/Maybe.h" // for Maybe
#include "mozilla/RefPtr.h" // for TemporaryRef
#include "mozilla/StyleAnimationValue.h" // for StyleAnimationValue, etc
#include "mozilla/TimeStamp.h" // for TimeStamp, TimeDuration
Expand Down Expand Up @@ -990,29 +991,28 @@ class Layer {
* in device pixels.
* If aRect is null no clipping will be performed.
*/
void SetClipRect(const nsIntRect* aRect)
void SetClipRect(const Maybe<ParentLayerIntRect>& aRect)
{
if (mUseClipRect) {
if (mClipRect) {
if (!aRect) {
MOZ_LAYERS_LOG_IF_SHADOWABLE(this, ("Layer::Mutated(%p) ClipRect was %d,%d,%d,%d is <none>", this,
mClipRect.x, mClipRect.y, mClipRect.width, mClipRect.height));
mUseClipRect = false;
mClipRect->x, mClipRect->y, mClipRect->width, mClipRect->height));
mClipRect.reset();
Mutated();
} else {
if (!aRect->IsEqualEdges(mClipRect)) {
if (!aRect->IsEqualEdges(*mClipRect)) {
MOZ_LAYERS_LOG_IF_SHADOWABLE(this, ("Layer::Mutated(%p) ClipRect was %d,%d,%d,%d is %d,%d,%d,%d", this,
mClipRect.x, mClipRect.y, mClipRect.width, mClipRect.height,
mClipRect->x, mClipRect->y, mClipRect->width, mClipRect->height,
aRect->x, aRect->y, aRect->width, aRect->height));
mClipRect = *aRect;
mClipRect = aRect;
Mutated();
}
}
} else {
if (aRect) {
MOZ_LAYERS_LOG_IF_SHADOWABLE(this, ("Layer::Mutated(%p) ClipRect was <none> is %d,%d,%d,%d", this,
aRect->x, aRect->y, aRect->width, aRect->height));
mUseClipRect = true;
mClipRect = *aRect;
mClipRect = aRect;
Mutated();
}
}
Expand Down Expand Up @@ -1227,7 +1227,7 @@ class Layer {
// These getters can be used anytime.
float GetOpacity() { return mOpacity; }
gfx::CompositionOp GetMixBlendMode() const { return mMixBlendMode; }
const nsIntRect* GetClipRect() { return mUseClipRect ? &mClipRect : nullptr; }
const Maybe<ParentLayerIntRect>& GetClipRect() const { return mClipRect; }
uint32_t GetContentFlags() { return mContentFlags; }
const nsIntRect& GetLayerBounds() const { return mLayerBounds; }
const nsIntRegion& GetVisibleRegion() const { return mVisibleRegion; }
Expand Down Expand Up @@ -1418,7 +1418,7 @@ class Layer {
// These getters can be used anytime. They return the effective
// values that should be used when drawing this layer to screen,
// accounting for this layer possibly being a shadow.
const nsIntRect* GetEffectiveClipRect();
const Maybe<ParentLayerIntRect>& GetEffectiveClipRect();
const nsIntRegion& GetEffectiveVisibleRegion();

/**
Expand Down Expand Up @@ -1700,12 +1700,11 @@ class Layer {
float mOpacity;
gfx::CompositionOp mMixBlendMode;
bool mForceIsolatedGroup;
nsIntRect mClipRect;
Maybe<ParentLayerIntRect> mClipRect;
nsIntRect mTileSourceRect;
nsIntRegion mInvalidRegion;
nsTArray<nsRefPtr<AsyncPanZoomController> > mApzcs;
uint32_t mContentFlags;
bool mUseClipRect;
bool mUseTileSourceRect;
bool mIsFixedPosition;
LayerPoint mAnchor;
Expand Down
6 changes: 4 additions & 2 deletions gfx/layers/ReadbackProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <sys/types.h> // for int32_t
#include "Layers.h" // for Layer, PaintedLayer, etc
#include "ReadbackLayer.h" // for ReadbackLayer, ReadbackSink
#include "UnitTransforms.h" // for ViewAs
#include "Units.h" // for ParentLayerIntRect
#include "gfxColor.h" // for gfxRGBA
#include "gfxContext.h" // for gfxContext
#include "gfxUtils.h"
Expand Down Expand Up @@ -76,8 +78,8 @@ FindBackgroundLayer(ReadbackLayer* aLayer, nsIntPoint* aOffset)
return nullptr;

// cliprects are post-transform
const nsIntRect* clipRect = l->GetEffectiveClipRect();
if (clipRect && !clipRect->Contains(nsIntRect(transformOffset, aLayer->GetSize())))
const Maybe<ParentLayerIntRect>& clipRect = l->GetEffectiveClipRect();
if (clipRect && !clipRect->Contains(ViewAs<ParentLayerPixel>(nsIntRect(transformOffset, aLayer->GetSize()))))
return nullptr;

Layer::LayerType type = l->GetType();
Expand Down
5 changes: 3 additions & 2 deletions gfx/layers/apz/src/APZCTreeManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "gfxPrefs.h" // for gfxPrefs
#include "OverscrollHandoffState.h" // for OverscrollHandoffState
#include "LayersLogging.h" // for Stringify
#include "Units.h" // for ParentlayerPixel

#define ENABLE_APZCTM_LOGGING 0
// #define ENABLE_APZCTM_LOGGING 1
Expand Down Expand Up @@ -202,7 +203,7 @@ ComputeClipRegion(GeckoContentController* aController,
{
ParentLayerIntRegion clipRegion;
if (aLayer.GetClipRect()) {
clipRegion = ViewAs<ParentLayerPixel>(*aLayer.GetClipRect());
clipRegion = *aLayer.GetClipRect();
} else {
// if there is no clip on this layer (which should only happen for the
// root scrollable layer in a process, or for some of the LayerMetrics
Expand Down Expand Up @@ -334,7 +335,7 @@ APZCTreeManager::PrepareNodeForLayer(const LayerMetricsWrapper& aLayer,
node = RecycleOrCreateNode(aState, nullptr);
AttachNodeToTree(node, aParent, aNextSibling);
node->SetHitTestData(GetEventRegions(aLayer), aLayer.GetTransform(),
aLayer.GetClipRect() ? Some(ParentLayerIntRegion(ViewAs<ParentLayerPixel>(*aLayer.GetClipRect()))) : Nothing(),
aLayer.GetClipRect() ? Some(ParentLayerIntRegion(*aLayer.GetClipRect())) : Nothing(),
GetEventRegionsOverride(aParent, aLayer));
return node;
}
Expand Down
2 changes: 1 addition & 1 deletion gfx/layers/basic/BasicContainerLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ BasicContainerLayer::ChildrenPartitionVisibleRegion(const nsIntRect& aInRect)
childRegion.MoveBy(int32_t(childTransform._31), int32_t(childTransform._32));
childRegion.And(childRegion, rect);
if (l->GetClipRect()) {
childRegion.And(childRegion, *l->GetClipRect() + offset);
childRegion.And(childRegion, ParentLayerIntRect::ToUntyped(*l->GetClipRect()) + offset);
}
nsIntRegion intersection;
intersection.And(covered, childRegion);
Expand Down
10 changes: 5 additions & 5 deletions gfx/layers/basic/BasicLayerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,9 @@ MarkLayersHidden(Layer* aLayer, const nsIntRect& aClipRect,
}

{
const nsIntRect* clipRect = aLayer->GetEffectiveClipRect();
const Maybe<ParentLayerIntRect>& clipRect = aLayer->GetEffectiveClipRect();
if (clipRect) {
nsIntRect cr = *clipRect;
nsIntRect cr = ParentLayerIntRect::ToUntyped(*clipRect);
// clipRect is in the container's coordinate system. Get it into the
// global coordinate system.
if (aLayer->GetParent()) {
Expand Down Expand Up @@ -404,9 +404,9 @@ ApplyDoubleBuffering(Layer* aLayer, const nsIntRect& aVisibleRect)
nsIntRect newVisibleRect(aVisibleRect);

{
const nsIntRect* clipRect = aLayer->GetEffectiveClipRect();
const Maybe<ParentLayerIntRect>& clipRect = aLayer->GetEffectiveClipRect();
if (clipRect) {
nsIntRect cr = *clipRect;
nsIntRect cr = ParentLayerIntRect::ToUntyped(*clipRect);
// clipRect is in the container's coordinate system. Get it into the
// global coordinate system.
if (aLayer->GetParent()) {
Expand Down Expand Up @@ -865,7 +865,7 @@ BasicLayerManager::PaintLayer(gfxContext* aTarget,

RenderTraceScope trace("BasicLayerManager::PaintLayer", "707070");

const nsIntRect* clipRect = aLayer->GetEffectiveClipRect();
const Maybe<ParentLayerIntRect>& clipRect = aLayer->GetEffectiveClipRect();
BasicContainerLayer* container =
static_cast<BasicContainerLayer*>(aLayer->AsContainerLayer());
bool needsGroup = container && container->UseIntermediateSurface();
Expand Down
Loading

0 comments on commit f17daf9

Please sign in to comment.