Bug 1400382 - Factor out text WebRenderCommand code to TextDrawTarget. r?jrmuizel
MozReview-Commit-ID: EQtFvLQCT2U
--- a/layout/generic/TextDrawTarget.h
+++ b/layout/generic/TextDrawTarget.h
@@ -2,17 +2,20 @@
/* 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/. */
#ifndef TextDrawTarget_h
#define TextDrawTarget_h
#include "mozilla/gfx/2D.h"
-#include "mozilla/webrender/WebRenderApi.h"
+#include "mozilla/layers/WebRenderLayerManager.h"
+#include "mozilla/layers/WebRenderBridgeChild.h"
+#include "mozilla/webrender/WebRenderAPI.h"
+#include "mozilla/layers/StackingContextHelper.h"
namespace mozilla {
namespace layout {
using namespace gfx;
// This is used by all Advanced Layers users, so we use plain gfx types
struct TextRunFragment {
@@ -295,16 +298,84 @@ public:
// Must have an actual font (i.e. actual text)
if (!font) {
return false;
}
return true;
}
+ void
+ CreateWebRenderCommands(mozilla::wr::DisplayListBuilder& aBuilder,
+ const layers::StackingContextHelper& aSc,
+ layers::WebRenderLayerManager* aManager,
+ nsDisplayItem* aItem,
+ nsRect& aBounds) {
+
+ // Drawing order: selections,
+ // shadows,
+ // underline, overline, [grouped in one array]
+ // text, emphasisText, [grouped in one array]
+ // lineThrough
+
+ // Compute clip/bounds
+ auto appUnitsPerDevPixel = aItem->Frame()->PresContext()->AppUnitsPerDevPixel();
+ LayoutDeviceRect layoutBoundsRect = LayoutDeviceRect::FromAppUnits(
+ aBounds, appUnitsPerDevPixel);
+ LayoutDeviceRect layoutClipRect = layoutBoundsRect;
+ auto clip = aItem->GetClip();
+ if (clip.HasClip()) {
+ layoutClipRect = LayoutDeviceRect::FromAppUnits(
+ clip.GetClipRect(), appUnitsPerDevPixel);
+ }
+
+ LayerRect boundsRect = LayerRect::FromUnknownRect(layoutBoundsRect.ToUnknownRect());
+ LayerRect clipRect = LayerRect::FromUnknownRect(layoutClipRect.ToUnknownRect());
+
+ bool backfaceVisible = !aItem->BackfaceIsHidden();
+
+ wr::LayoutRect wrBoundsRect = aSc.ToRelativeLayoutRect(boundsRect);
+ wr::LayoutRect wrClipRect = aSc.ToRelativeLayoutRect(clipRect);
+
+
+ // Create commands
+ for (auto& part : GetParts()) {
+ if (part.selection) {
+ auto selection = part.selection.value();
+ aBuilder.PushRect(selection.rect, wrClipRect, backfaceVisible, selection.color);
+ }
+ }
+
+ for (auto& part : GetParts()) {
+ // WR takes the shadows in CSS-order (reverse of rendering order),
+ // because the drawing of a shadow actually occurs when it's popped.
+ for (const wr::TextShadow& shadow : part.shadows) {
+ aBuilder.PushTextShadow(wrBoundsRect, wrClipRect, backfaceVisible, shadow);
+ }
+
+ for (const wr::Line& decoration : part.beforeDecorations) {
+ aBuilder.PushLine(wrClipRect, backfaceVisible, decoration);
+ }
+
+ for (const mozilla::layout::TextRunFragment& text : part.text) {
+ aManager->WrBridge()->PushGlyphs(aBuilder, text.glyphs, text.font,
+ text.color, aSc, boundsRect, clipRect,
+ backfaceVisible);
+ }
+
+ for (const wr::Line& decoration : part.afterDecorations) {
+ aBuilder.PushLine(wrClipRect, backfaceVisible, decoration);
+ }
+
+ for (size_t i = 0; i < part.shadows.Length(); ++i) {
+ aBuilder.PopTextShadow();
+ }
+ }
+}
+
private:
// The part of the text we're currently drawing (glyphs, underlines, etc.)
Phase mCurrentlyDrawing;
// Which chunk of mParts is actively being populated
SelectedTextRunFragment* mCurrentPart;
--- a/layout/generic/nsTextFrame.cpp
+++ b/layout/generic/nsTextFrame.cpp
@@ -5187,68 +5187,17 @@ nsDisplayText::CreateWebRenderCommands(m
return false;
}
}
if (mBounds.IsEmpty()) {
return true;
}
- auto appUnitsPerDevPixel = mFrame->PresContext()->AppUnitsPerDevPixel();
- LayoutDeviceRect layoutBoundsRect = LayoutDeviceRect::FromAppUnits(
- mBounds, appUnitsPerDevPixel);
- LayoutDeviceRect layoutClipRect = layoutBoundsRect;
- if (GetClip().HasClip()) {
- layoutClipRect = LayoutDeviceRect::FromAppUnits(
- GetClip().GetClipRect(), appUnitsPerDevPixel);
- }
-
- LayerRect boundsRect = LayerRect::FromUnknownRect(layoutBoundsRect.ToUnknownRect());
- LayerRect clipRect = LayerRect::FromUnknownRect(layoutClipRect.ToUnknownRect());
- wr::LayoutRect wrClipRect = aSc.ToRelativeLayoutRect(clipRect); // wr::ToLayoutRect(clipRect);
- wr::LayoutRect wrBoundsRect = aSc.ToRelativeLayoutRect(boundsRect); //wr::ToLayoutRect(boundsRect);
- bool backfaceVisible = !BackfaceIsHidden();
-
- // Drawing order: selections, shadows,
- // underline, overline, [grouped in one array]
- // text, emphasisText, [grouped in one array]
- // lineThrough
-
- for (auto& part : mTextDrawer->GetParts()) {
- if (part.selection) {
- auto selection = part.selection.value();
- aBuilder.PushRect(selection.rect, wrClipRect, backfaceVisible, selection.color);
- }
- }
-
- for (auto& part : mTextDrawer->GetParts()) {
- // WR takes the shadows in CSS-order (reverse of rendering order),
- // because the drawing of a shadow actually occurs when it's popped.
- for (const wr::TextShadow& shadow : part.shadows) {
- aBuilder.PushTextShadow(wrBoundsRect, wrClipRect, backfaceVisible, shadow);
- }
-
- for (const wr::Line& decoration : part.beforeDecorations) {
- aBuilder.PushLine(wrClipRect, backfaceVisible, decoration);
- }
-
- for (const mozilla::layout::TextRunFragment& text : part.text) {
- aManager->WrBridge()->PushGlyphs(aBuilder, text.glyphs, text.font,
- text.color, aSc, boundsRect, clipRect,
- backfaceVisible);
- }
-
- for (const wr::Line& decoration : part.afterDecorations) {
- aBuilder.PushLine(wrClipRect, backfaceVisible, decoration);
- }
-
- for (size_t i = 0; i < part.shadows.Length(); ++i) {
- aBuilder.PopTextShadow();
- }
- }
+ mTextDrawer->CreateWebRenderCommands(aBuilder, aSc, aManager, this, mBounds);
return true;
}
already_AddRefed<layers::Layer>
nsDisplayText::BuildLayer(nsDisplayListBuilder* aBuilder,
LayerManager* aManager,
const ContainerLayerParameters& aContainerParameters)
--- a/layout/generic/nsTextFrame.h
+++ b/layout/generic/nsTextFrame.h
@@ -15,17 +15,16 @@
#include "nsGenericDOMDataNode.h"
#include "nsSplittableFrame.h"
#include "nsLineBox.h"
#include "gfxSkipChars.h"
#include "gfxTextRun.h"
#include "nsDisplayList.h"
#include "JustificationUtils.h"
#include "RubyUtils.h"
-#include "TextDrawTarget.h"
// Undo the windows.h damage
#if defined(XP_WIN) && defined(DrawText)
#undef DrawText
#endif
class nsTextPaintStyle;
class PropertyProvider;
@@ -44,17 +43,16 @@ class nsTextFrame : public nsFrame
typedef mozilla::LayoutDeviceRect LayoutDeviceRect;
typedef mozilla::SelectionTypeMask SelectionTypeMask;
typedef mozilla::SelectionType SelectionType;
typedef mozilla::TextRangeStyle TextRangeStyle;
typedef mozilla::gfx::DrawTarget DrawTarget;
typedef mozilla::gfx::Point Point;
typedef mozilla::gfx::Rect Rect;
typedef mozilla::gfx::Size Size;
- typedef mozilla::layout::TextDrawTarget TextDrawTarget;
typedef gfxTextRun::Range Range;
public:
explicit nsTextFrame(nsStyleContext* aContext, ClassID aID = kClassID)
: nsFrame(aContext, aID)
, mNextContinuation(nullptr)
, mContentOffset(0)
, mContentLengthHint(0)