Bug 1400382 - Defer TextDrawTarget analysis until GetLayerState. r?jrmuizel draft
authorAlexis Beingessner <a.beingessner@gmail.com>
Wed, 20 Sep 2017 20:11:12 -0400
changeset 669341 a828f93091fcf333ef0906ad9ea7b8ba80614164
parent 668408 b14c75b83d0226333b1240466ea9f07cfb206ff3
child 669342 6f3c0768e5ac153a1c3756e26ac7cc5aef08b610
push id81300
push userbmo:a.beingessner@gmail.com
push dateFri, 22 Sep 2017 22:26:15 +0000
reviewersjrmuizel
bugs1400382
milestone58.0a1
Bug 1400382 - Defer TextDrawTarget analysis until GetLayerState. r?jrmuizel This ensures the mutations TextOverflow does have already occured when we compute contents. This also reverts my previous folded opacity patch, as this also handles that case. MozReview-Commit-ID: 6A4F98GGHyL
layout/generic/nsTextFrame.cpp
--- a/layout/generic/nsTextFrame.cpp
+++ b/layout/generic/nsTextFrame.cpp
@@ -5117,38 +5117,41 @@ nsDisplayText::nsDisplayText(nsDisplayLi
   : nsCharClipDisplayItem(aBuilder, aFrame)
   , mOpacity(1.0f)
 {
   MOZ_COUNT_CTOR(nsDisplayText);
   mIsFrameSelected = aIsSelected;
   mBounds = mFrame->GetVisualOverflowRectRelativeToSelf() + ToReferenceFrame();
     // Bug 748228
   mBounds.Inflate(mFrame->PresContext()->AppUnitsPerDevPixel());
-
-  if (gfxPrefs::LayersAllowTextLayers() &&
-      CanUseAdvancedLayer(aBuilder->GetWidgetLayerManager())) {
-    mTextDrawer = new TextDrawTarget();
-    RefPtr<gfxContext> captureCtx = gfxContext::CreateOrNull(mTextDrawer);
-
-    // TODO: Paint() checks mDisableSubpixelAA, we should too.
-    RenderToContext(captureCtx, mTextDrawer, aBuilder, true);
-
-    if (!mTextDrawer->CanSerializeFonts()) {
-      mTextDrawer = nullptr;
-    }
-  }
 }
 
 LayerState
 nsDisplayText::GetLayerState(nsDisplayListBuilder* aBuilder,
                              LayerManager* aManager,
                              const ContainerLayerParameters& aParameters)
 {
-  // Basic things that all advanced backends need
+
+  // Are we doing text layers or webrender?
+  if (!(gfxPrefs::LayersAllowTextLayers() &&
+      CanUseAdvancedLayer(aBuilder->GetWidgetLayerManager()))) {
+    return mozilla::LAYER_NONE;
+  }
+
+  // If we haven't yet, compute the layout/style of the text by running
+  // the painting algorithm with a TextDrawTarget (doesn't actually paint).
   if (!mTextDrawer) {
+    mTextDrawer = new TextDrawTarget();
+    RefPtr<gfxContext> captureCtx = gfxContext::CreateOrNull(mTextDrawer);
+
+    // TODO: Paint() checks mDisableSubpixelAA, we should too.
+    RenderToContext(captureCtx, mTextDrawer, aBuilder, true);
+  }
+
+  if (!mTextDrawer->CanSerializeFonts()) {
     return mozilla::LAYER_NONE;
   }
 
   // If we're using the webrender backend, then we're good to go!
   if (aManager->GetBackendType() == layers::LayersBackend::LAYERS_WR) {
     return mozilla::LAYER_ACTIVE;
   }
 
@@ -5223,24 +5226,18 @@ nsDisplayText::CreateWebRenderCommands(m
       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) {
-      // mOpacity is set after we do our analysis, so we need to apply it here.
-      // mOpacity is only non-trivial when we have "pure" text, so we don't
-      // ever need to apply it to shadows or decorations.
-      auto color = text.color;
-      color.a *= mOpacity;
-
       aManager->WrBridge()->PushGlyphs(aBuilder, text.glyphs, text.font,
-                                       color, aSc, boundsRect, clipRect,
+                                       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) {
@@ -5284,21 +5281,17 @@ nsDisplayText::BuildLayer(nsDisplayListB
   for (auto& part : mTextDrawer->GetParts()) {
     for (const mozilla::layout::TextRunFragment& text : part.text) {
       if (!font) {
         font = text.font;
       }
 
       GlyphArray* glyphs = allGlyphs.AppendElement();
       glyphs->glyphs() = text.glyphs;
-
-      // Apply folded alpha (only applies to glyphs)
-      auto color = text.color;
-      color.a *= mOpacity;
-      glyphs->color() = color;
+      glyphs->color() = text.color;
     }
   }
 
   MOZ_ASSERT(font);
 
   layer->SetGlyphs(Move(allGlyphs));
   layer->SetScaledFont(font);