Bug 1395098 - Apply folded alpha to text when using advanced layers r=jrmuizel draft
authorAlexis Beingessner <a.beingessner@gmail.com>
Wed, 30 Aug 2017 13:18:09 -0400
changeset 656042 40b400966f7fdd2951628284b39d2f75b4fa9219
parent 654351 e2efa420beb1a578c7350ba925c82230da6b1267
child 728990 5acc26f2997282a1ab47818287b2137d8e998d65
push id77043
push userbmo:a.beingessner@gmail.com
push dateWed, 30 Aug 2017 17:21:06 +0000
reviewersjrmuizel
bugs1395098
milestone57.0a1
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();