Bug 1395098 - Apply folded alpha to text when using advanced layers r=jrmuizel
authorAlexis Beingessner <a.beingessner@gmail.com>
Wed, 30 Aug 2017 13:18:09 -0400
changeset 377877 7663f58bcf9696d17563197e3de9883f11a75231
parent 377876 a2656d6b44fc975ced04cf2678defc230edcb2dc
child 377878 abe144dae14efda63507947d8bb96deaadb51fe1
push id50080
push userryanvm@gmail.com
push dateThu, 31 Aug 2017 04:10:17 +0000
treeherderautoland@7663f58bcf96 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1395098
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1395098 - Apply folded alpha to text when using advanced layers r=jrmuizel MozReview-Commit-ID: 6crHThEP6Ha
layout/generic/nsTextFrame.cpp
--- a/layout/generic/nsTextFrame.cpp
+++ b/layout/generic/nsTextFrame.cpp
@@ -5263,18 +5263,24 @@ nsDisplayText::CreateWebRenderCommands(m
     aBuilder.PushTextShadow(wrBoundsRect, wrClipRect, shadow);
   }
 
   for (const wr::Line& decoration: mTextDrawer->GetBeforeDecorations()) {
     aBuilder.PushLine(wrClipRect, decoration);
   }
 
   for (const mozilla::layout::TextRunFragment& text: mTextDrawer->GetText()) {
+    // 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,
-                                     text.color, aSc, boundsRect, clipRect);
+                                     color, aSc, boundsRect, clipRect);
   }
 
   for (const wr::Line& decoration: mTextDrawer->GetAfterDecorations()) {
     aBuilder.PushLine(wrClipRect, decoration);
   }
 
   for (size_t i = 0; i < mTextDrawer->GetShadows().Length(); ++i) {
     aBuilder.PopTextShadow();
@@ -5310,17 +5316,21 @@ nsDisplayText::BuildLayer(nsDisplayListB
   allGlyphs.SetCapacity(mTextDrawer->GetText().Length());
   for (const mozilla::layout::TextRunFragment& text : mTextDrawer->GetText()) {
     if (!font) {
       font = text.font;
     }
 
     GlyphArray* glyphs = allGlyphs.AppendElement();
     glyphs->glyphs() = text.glyphs;
-    glyphs->color() = text.color;
+
+    // Apply folded alpha (only applies to glyphs)
+    auto color = text.color;
+    color.a *= mOpacity;
+    glyphs->color() = color;
   }
 
   MOZ_ASSERT(font);
 
   layer->SetGlyphs(Move(allGlyphs));
   layer->SetScaledFont(font);
 
   auto A2D = mFrame->PresContext()->AppUnitsPerDevPixel();