Bug 1360246 - Remove the RelativeToParent functions by propagating StackingContextHelper chains. r=nical

The only remaining callers of RelativeToParent() are in
StackingContextHelper itself, which we can remove now by having the SCH
take a parent SCH and use it instead of RelativeToParent(). This patch
implements this change.

This makes a failing test pass, because of how preserve-3d container
layers work. Specifically, preserve-3d container layers render their
descendants in z-order, not in tree order. If those children were assuming
that their parent had already pushed a stacking context, that assumption
may have been false because the parent might have not yet been rendered
because of z-ordering. By using the StackingContextHelper chain instead
of the layer tree ancestry, we fix the stacking-context-relative coordinates
being used in the descendant subtree of preserve-3d container layers.

MozReview-Commit-ID: HzZvBuAlMdB
This commit is contained in:
Kartikaya Gupta 2017-05-03 08:48:08 -04:00
Родитель 989470c342
Коммит 48e0e2221d
13 изменённых файлов: 26 добавлений и 36 удалений

Просмотреть файл

@ -17,30 +17,32 @@ StackingContextHelper::StackingContextHelper()
// mOrigin remains at 0,0 // mOrigin remains at 0,0
} }
StackingContextHelper::StackingContextHelper(wr::DisplayListBuilder& aBuilder, StackingContextHelper::StackingContextHelper(const StackingContextHelper& aParentSC,
wr::DisplayListBuilder& aBuilder,
WebRenderLayer* aLayer, WebRenderLayer* aLayer,
const Maybe<gfx::Matrix4x4>& aTransform) const Maybe<gfx::Matrix4x4>& aTransform)
: mBuilder(&aBuilder) : mBuilder(&aBuilder)
{ {
LayerRect scBounds = aLayer->RelativeToParent(aLayer->BoundsForStackingContext()); LayerRect scBounds = aLayer->BoundsForStackingContext();
Layer* layer = aLayer->GetLayer(); Layer* layer = aLayer->GetLayer();
gfx::Matrix4x4 transform = aTransform.valueOr(layer->GetTransform()); gfx::Matrix4x4 transform = aTransform.valueOr(layer->GetTransform());
mBuilder->PushStackingContext(wr::ToWrRect(scBounds), mBuilder->PushStackingContext(aParentSC.ToRelativeWrRect(scBounds),
1.0f, 1.0f,
transform, transform,
wr::ToWrMixBlendMode(layer->GetMixBlendMode())); wr::ToWrMixBlendMode(layer->GetMixBlendMode()));
mOrigin = aLayer->Bounds().TopLeft(); mOrigin = aLayer->Bounds().TopLeft();
} }
StackingContextHelper::StackingContextHelper(wr::DisplayListBuilder& aBuilder, StackingContextHelper::StackingContextHelper(const StackingContextHelper& aParentSC,
wr::DisplayListBuilder& aBuilder,
WebRenderLayer* aLayer, WebRenderLayer* aLayer,
uint64_t aAnimationsId, uint64_t aAnimationsId,
float* aOpacityPtr, float* aOpacityPtr,
gfx::Matrix4x4* aTransformPtr) gfx::Matrix4x4* aTransformPtr)
: mBuilder(&aBuilder) : mBuilder(&aBuilder)
{ {
LayerRect scBounds = aLayer->RelativeToParent(aLayer->BoundsForStackingContext()); LayerRect scBounds = aLayer->BoundsForStackingContext();
mBuilder->PushStackingContext(wr::ToWrRect(scBounds), mBuilder->PushStackingContext(aParentSC.ToRelativeWrRect(scBounds),
aAnimationsId, aAnimationsId,
aOpacityPtr, aOpacityPtr,
aTransformPtr, aTransformPtr,

Просмотреть файл

@ -28,12 +28,14 @@ public:
// the transform if provided, otherwise takes the transform from the layer. // the transform if provided, otherwise takes the transform from the layer.
// It also takes the mix-blend-mode and bounds from the layer, and uses 1.0 // It also takes the mix-blend-mode and bounds from the layer, and uses 1.0
// for the opacity. // for the opacity.
StackingContextHelper(wr::DisplayListBuilder& aBuilder, StackingContextHelper(const StackingContextHelper& aParentSC,
wr::DisplayListBuilder& aBuilder,
WebRenderLayer* aLayer, WebRenderLayer* aLayer,
const Maybe<gfx::Matrix4x4>& aTransform = Nothing()); const Maybe<gfx::Matrix4x4>& aTransform = Nothing());
// Alternate constructor which invokes the version of PushStackingContext // Alternate constructor which invokes the version of PushStackingContext
// for animations. // for animations.
StackingContextHelper(wr::DisplayListBuilder& aBuilder, StackingContextHelper(const StackingContextHelper& aParentSC,
wr::DisplayListBuilder& aBuilder,
WebRenderLayer* aLayer, WebRenderLayer* aLayer,
uint64_t aAnimationsId, uint64_t aAnimationsId,
float* aOpacityPtr, float* aOpacityPtr,

Просмотреть файл

@ -62,7 +62,7 @@ WebRenderCanvasLayer::RenderLayer(wr::DisplayListBuilder& aBuilder,
transform = Some(GetTransform().PreTranslate(0, mBounds.height, 0).PreScale(1, -1, 1)); transform = Some(GetTransform().PreTranslate(0, mBounds.height, 0).PreScale(1, -1, 1));
} }
StackingContextHelper sc(aBuilder, this, transform); StackingContextHelper sc(aSc, aBuilder, this, transform);
LayerRect rect(0, 0, mBounds.width, mBounds.height); LayerRect rect(0, 0, mBounds.width, mBounds.height);
DumpLayerInfo("CanvasLayer", rect); DumpLayerInfo("CanvasLayer", rect);

Просмотреть файл

@ -21,7 +21,7 @@ void
WebRenderColorLayer::RenderLayer(wr::DisplayListBuilder& aBuilder, WebRenderColorLayer::RenderLayer(wr::DisplayListBuilder& aBuilder,
const StackingContextHelper& aSc) const StackingContextHelper& aSc)
{ {
StackingContextHelper sc(aBuilder, this); StackingContextHelper sc(aSc, aBuilder, this);
LayerRect rect = Bounds(); LayerRect rect = Bounds();
DumpLayerInfo("ColorLayer", rect); DumpLayerInfo("ColorLayer", rect);

Просмотреть файл

@ -88,7 +88,7 @@ WebRenderContainerLayer::RenderLayer(wr::DisplayListBuilder& aBuilder,
WrBridge()->AddWebRenderParentCommand(anim); WrBridge()->AddWebRenderParentCommand(anim);
} }
StackingContextHelper sc(aBuilder, this, animationsId, opacityForSC, transformForSC); StackingContextHelper sc(aSc, aBuilder, this, animationsId, opacityForSC, transformForSC);
LayerRect rect = Bounds(); LayerRect rect = Bounds();
DumpLayerInfo("ContainerLayer", rect); DumpLayerInfo("ContainerLayer", rect);

Просмотреть файл

@ -165,7 +165,7 @@ WebRenderImageLayer::RenderLayer(wr::DisplayListBuilder& aBuilder,
return; return;
} }
StackingContextHelper sc(aBuilder, this); StackingContextHelper sc(aSc, aBuilder, this);
LayerRect rect(0, 0, size.width, size.height); LayerRect rect(0, 0, size.width, size.height);
if (mScaleMode != ScaleMode::SCALE_NONE) { if (mScaleMode != ScaleMode::SCALE_NONE) {

Просмотреть файл

@ -51,19 +51,6 @@ WebRenderLayer::ParentBounds()
return LayerRect(); return LayerRect();
} }
LayerRect
WebRenderLayer::RelativeToParent(const LayerRect& aRect)
{
return aRect - ParentBounds().TopLeft();
}
LayerRect
WebRenderLayer::RelativeToParent(const LayoutDeviceRect& aRect)
{
return RelativeToParent(ViewAs<LayerPixel>(
aRect, PixelCastJustification::WebRenderHasUnitResolution));
}
gfx::Rect gfx::Rect
WebRenderLayer::TransformedVisibleBoundsRelativeToParent() WebRenderLayer::TransformedVisibleBoundsRelativeToParent()
{ {

Просмотреть файл

@ -48,9 +48,6 @@ public:
WebRenderBridgeChild* WrBridge(); WebRenderBridgeChild* WrBridge();
WrImageKey GetImageKey(); WrImageKey GetImageKey();
LayerRect RelativeToParent(const LayerRect& aRect);
LayerRect RelativeToParent(const LayoutDeviceRect& aRect);
LayerRect Bounds(); LayerRect Bounds();
LayerRect BoundsForStackingContext(); LayerRect BoundsForStackingContext();
protected: protected:

Просмотреть файл

@ -89,9 +89,10 @@ WebRenderPaintedLayer::UpdateImageClient()
} }
void void
WebRenderPaintedLayer::CreateWebRenderDisplayList(wr::DisplayListBuilder& aBuilder) WebRenderPaintedLayer::CreateWebRenderDisplayList(wr::DisplayListBuilder& aBuilder,
const StackingContextHelper& aSc)
{ {
StackingContextHelper sc(aBuilder, this); StackingContextHelper sc(aSc, aBuilder, this);
LayerRect rect = Bounds(); LayerRect rect = Bounds();
DumpLayerInfo("PaintedLayer", rect); DumpLayerInfo("PaintedLayer", rect);
@ -145,7 +146,7 @@ WebRenderPaintedLayer::RenderLayer(wr::DisplayListBuilder& aBuilder,
MOZ_ASSERT(GetInvalidRegion().IsEmpty()); MOZ_ASSERT(GetInvalidRegion().IsEmpty());
} }
CreateWebRenderDisplayList(aBuilder); CreateWebRenderDisplayList(aBuilder, aSc);
} }
} // namespace layers } // namespace layers

Просмотреть файл

@ -55,7 +55,8 @@ public:
private: private:
bool SetupExternalImages(); bool SetupExternalImages();
bool UpdateImageClient(); bool UpdateImageClient();
void CreateWebRenderDisplayList(wr::DisplayListBuilder& aBuilder); void CreateWebRenderDisplayList(wr::DisplayListBuilder& aBuilder,
const StackingContextHelper& aSc);
}; };
} // namespace layers } // namespace layers

Просмотреть файл

@ -22,7 +22,7 @@ using namespace mozilla::gfx;
void void
WebRenderPaintedLayerBlob::RenderLayer(wr::DisplayListBuilder& aBuilder, WebRenderPaintedLayerBlob::RenderLayer(wr::DisplayListBuilder& aBuilder,
const StackingContextHelper& aHelper) const StackingContextHelper& aSc)
{ {
LayerIntRegion visibleRegion = GetVisibleRegion(); LayerIntRegion visibleRegion = GetVisibleRegion();
LayerIntRect bounds = visibleRegion.GetBounds(); LayerIntRect bounds = visibleRegion.GetBounds();
@ -78,7 +78,7 @@ WebRenderPaintedLayerBlob::RenderLayer(wr::DisplayListBuilder& aBuilder,
DebugOnly<bool> ok = recorder->CopyRecording((char*)bytes.AsSlice().begin().get(), bytes.AsSlice().length()); DebugOnly<bool> ok = recorder->CopyRecording((char*)bytes.AsSlice().begin().get(), bytes.AsSlice().length());
MOZ_ASSERT(ok); MOZ_ASSERT(ok);
StackingContextHelper sc(aBuilder, this); StackingContextHelper sc(aSc, aBuilder, this);
LayerRect rect = Bounds(); LayerRect rect = Bounds();
DumpLayerInfo("PaintedLayer", rect); DumpLayerInfo("PaintedLayer", rect);

Просмотреть файл

@ -48,7 +48,7 @@ public:
Layer* GetLayer() override { return this; } Layer* GetLayer() override { return this; }
void RenderLayer(wr::DisplayListBuilder& aBuilder, void RenderLayer(wr::DisplayListBuilder& aBuilder,
const StackingContextHelper& aHelper) override; const StackingContextHelper& aSc) override;
private: private:
RefPtr<ImageContainer> mImageContainer; RefPtr<ImageContainer> mImageContainer;
RefPtr<ImageClient> mImageClient; RefPtr<ImageClient> mImageClient;

Просмотреть файл

@ -46,7 +46,7 @@ fuzzy-if(winWidget&&!layersGPUAccelerated,1,61) == perspective-origin-3a.html pe
== perspective-origin-4a.html perspective-origin-4-ref.html == perspective-origin-4a.html perspective-origin-4-ref.html
fails-if(webrender) == perspective-zindex.html green-rect.html fails-if(webrender) == perspective-zindex.html green-rect.html
fails-if(webrender) == perspective-zindex-2.html green-rect.html fails-if(webrender) == perspective-zindex-2.html green-rect.html
fails-if(webrender) fails-if(stylo) != sorting-1a.html sorting-1-ref.html fails-if(stylo) != sorting-1a.html sorting-1-ref.html
# Parallel planes, different z depth # Parallel planes, different z depth
fails-if(webrender) == sorting-2a.html sorting-2-ref.html fails-if(webrender) == sorting-2a.html sorting-2-ref.html
# Parallel planes, same z depth (shouldn't be sorted!) # Parallel planes, same z depth (shouldn't be sorted!)