Bug 1360246 - Clean up WebRenderTextLayer::RenderLayer. r=nical

This uses the StackingContextHelper and typed helper functions in
WebRenderLayer to simplify WebRenderTextLayer::RenderLayer. It also
removes the implicit assumption in WebRenderTextLayer that the parent
layer pushed a stacking context, which is an assumption we will
probably break in the future.

MozReview-Commit-ID: CARoGVQd56i
This commit is contained in:
Kartikaya Gupta 2017-05-03 08:48:07 -04:00
Родитель 9c0fee2d43
Коммит 55a7794c28
8 изменённых файлов: 37 добавлений и 36 удалений

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

@ -60,5 +60,11 @@ StackingContextHelper::ToRelativeWrRect(const LayerRect& aRect) const
return wr::ToWrRect(aRect - mOrigin);
}
WrPoint
StackingContextHelper::ToRelativeWrPoint(const LayerPoint& aPoint) const
{
return wr::ToWrPoint(aPoint - mOrigin);
}
} // namespace layers
} // namespace mozilla

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

@ -53,6 +53,8 @@ public:
// things that are pushed inside the stacking context need to be relative
// to the stacking context.
WrRect ToRelativeWrRect(const LayerRect& aRect) const;
// Same but for points
WrPoint ToRelativeWrPoint(const LayerPoint& aPoint) const;
private:
wr::DisplayListBuilder* mBuilder;

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

@ -10,6 +10,7 @@
#include "mozilla/layers/CompositableClient.h"
#include "mozilla/layers/CompositorBridgeChild.h"
#include "mozilla/layers/ImageDataSerializer.h"
#include "mozilla/layers/StackingContextHelper.h"
#include "mozilla/layers/PTextureChild.h"
#include "mozilla/webrender/WebRenderAPI.h"
@ -178,8 +179,8 @@ WriteFontFileData(const uint8_t* aData, uint32_t aLength, uint32_t aIndex,
void
WebRenderBridgeChild::PushGlyphs(wr::DisplayListBuilder& aBuilder, const nsTArray<GlyphArray>& aGlyphs,
gfx::ScaledFont* aFont, const LayerPoint& aOffset, const gfx::Rect& aBounds,
const gfx::Rect& aClip)
gfx::ScaledFont* aFont, const StackingContextHelper& aSc,
const LayerRect& aBounds, const LayerRect& aClip)
{
MOZ_ASSERT(aFont);
MOZ_ASSERT(!aGlyphs.IsEmpty());
@ -187,7 +188,7 @@ WebRenderBridgeChild::PushGlyphs(wr::DisplayListBuilder& aBuilder, const nsTArra
WrFontKey key = GetFontKeyForScaledFont(aFont);
MOZ_ASSERT(key.mNamespace && key.mHandle);
WrClipRegion clipRegion = aBuilder.BuildClipRegion(wr::ToWrRect(aClip));
WrClipRegion clipRegion = aBuilder.BuildClipRegion(aSc.ToRelativeWrRect(aClip));
for (size_t i = 0; i < aGlyphs.Length(); i++) {
GlyphArray glyph_array = aGlyphs[i];
@ -198,10 +199,10 @@ WebRenderBridgeChild::PushGlyphs(wr::DisplayListBuilder& aBuilder, const nsTArra
for (size_t j = 0; j < glyphs.Length(); j++) {
wr_glyph_instances[j].index = glyphs[j].mIndex;
wr_glyph_instances[j].point.x = glyphs[j].mPosition.x - aOffset.x;
wr_glyph_instances[j].point.y = glyphs[j].mPosition.y - aOffset.y;
wr_glyph_instances[j].point = aSc.ToRelativeWrPoint(
LayerPoint::FromUnknownPoint(glyphs[j].mPosition));
}
aBuilder.PushText(wr::ToWrRect(aBounds),
aBuilder.PushText(aSc.ToRelativeWrRect(aBounds),
clipRegion,
glyph_array.color().value(),
key,

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

@ -24,6 +24,7 @@ namespace layers {
class CompositableClient;
class CompositorBridgeChild;
class StackingContextHelper;
class TextureForwarder;
class UnscaledFontHashKey : public PLDHashEntryHdr
@ -92,8 +93,8 @@ public:
}
void PushGlyphs(wr::DisplayListBuilder& aBuilder, const nsTArray<GlyphArray>& aGlyphs,
gfx::ScaledFont* aFont, const LayerPoint& aOffset, const gfx::Rect& aBounds,
const gfx::Rect& aClip);
gfx::ScaledFont* aFont, const StackingContextHelper& aSc,
const LayerRect& aBounds, const LayerRect& aClip);
wr::FontKey GetFontKeyForScaledFont(gfx::ScaledFont* aScaledFont);

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

@ -64,12 +64,6 @@ WebRenderLayer::RelativeToParent(const LayoutDeviceRect& aRect)
aRect, PixelCastJustification::WebRenderHasUnitResolution));
}
LayerPoint
WebRenderLayer::GetOffsetToParent()
{
return ParentBounds().TopLeft();
}
gfx::Rect
WebRenderLayer::TransformedVisibleBoundsRelativeToParent()
{

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

@ -50,7 +50,6 @@ public:
LayerRect RelativeToParent(const LayerRect& aRect);
LayerRect RelativeToParent(const LayoutDeviceRect& aRect);
LayerPoint GetOffsetToParent();
LayerRect Bounds();
LayerRect BoundsForStackingContext();

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

@ -25,24 +25,21 @@ WebRenderTextLayer::RenderLayer(wr::DisplayListBuilder& aBuilder,
return;
}
gfx::Rect rect = GetTransform().TransformBounds(IntRectToRect(mBounds))
- ParentBounds().ToUnknownRect().TopLeft();
gfx::Rect clip;
if (GetClipRect().isSome()) {
clip = IntRectToRect(GetClipRect().ref().ToUnknownRect())
- ParentBounds().ToUnknownRect().TopLeft();
} else {
clip = rect;
}
LayerRect rect = LayerRect::FromUnknownRect(
// I am not 100% sure this is correct, but it probably is. Because:
// the bounds are in layer space, and when gecko composites layers it
// applies the transform to the layer before compositing. However with
// WebRender compositing, we don't pass the transform on this layer to
// WR, so WR has no way of knowing about the transformed bounds unless
// we apply it here. The glyphs that we push to WR should already be
// taking the transform into account.
GetTransform().TransformBounds(IntRectToRect(mBounds))
);
DumpLayerInfo("TextLayer", rect);
if (gfxPrefs::LayersDump()) {
printf_stderr("TextLayer %p using rect=%s, clip=%s\n",
this->GetLayer(),
Stringify(rect).c_str(),
Stringify(clip).c_str());
}
LayerRect clipRect = ClipRect().valueOr(rect);
WrBridge()->PushGlyphs(aBuilder, mGlyphs, mFont, GetOffsetToParent(), rect, clip);
WrBridge()->PushGlyphs(aBuilder, mGlyphs, mFont, aSc, rect, clipRect);
}
} // namespace layers

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

@ -30,6 +30,7 @@
#include "nsCounterManager.h"
#include "nsBidiUtils.h"
#include "CounterStyleManager.h"
#include "UnitTransforms.h"
#include "imgIContainer.h"
#include "ImageLayers.h"
@ -504,12 +505,12 @@ BulletRenderer::CreateWebRenderCommandsForText(nsDisplayItem* aItem,
nsDisplayListBuilder* builder = layer->GetDisplayListBuilder();
const int32_t appUnitsPerDevPixel = aItem->Frame()->PresContext()->AppUnitsPerDevPixel();
bool dummy;
LayoutDeviceRect destRect = LayoutDeviceRect::FromAppUnits(
aItem->GetBounds(builder, &dummy), appUnitsPerDevPixel);
gfx::Rect destRectTransformed = aLayer->RelativeToParent(destRect).ToUnknownRect();
LayerRect destRect = ViewAs<LayerPixel>(
LayoutDeviceRect::FromAppUnits(
aItem->GetBounds(builder, &dummy), appUnitsPerDevPixel),
PixelCastJustification::WebRenderHasUnitResolution);
layer->WrBridge()->PushGlyphs(aBuilder, mGlyphs, mFont, aLayer->GetOffsetToParent(),
destRectTransformed, destRectTransformed);
layer->WrBridge()->PushGlyphs(aBuilder, mGlyphs, mFont, aSc, destRect, destRect);
}
class nsDisplayBullet final : public nsDisplayItem {