Bug 1504924 - Avoid nsIFrame::IsSelected() call in nsDisplayText::CanApplyOpacity() r=mats
authorMiko Mynttinen <mikokm@gmail.com>
Mon, 26 Nov 2018 16:06:00 +0000
changeset 447993 61c3a6ce72a0de3582d7a5bd08b173facdfba901
parent 447992 ef8fb4300e67a3857a65a2c9aa2528f65c6a07cb
child 447994 c4cd222f9e583b7453b9076e57d6f21af2b76c3e
push id35102
push userccoroiu@mozilla.com
push dateMon, 26 Nov 2018 21:58:00 +0000
treeherdermozilla-central@f38d34679027 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmats
bugs1504924
milestone65.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 1504924 - Avoid nsIFrame::IsSelected() call in nsDisplayText::CanApplyOpacity() r=mats Differential Revision: https://phabricator.services.mozilla.com/D12750
layout/generic/nsTextFrame.cpp
layout/painting/nsDisplayList.h
--- a/layout/generic/nsTextFrame.cpp
+++ b/layout/generic/nsTextFrame.cpp
@@ -4981,21 +4981,21 @@ public:
   void ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder,
                                  const nsDisplayItemGeometry* aGeometry,
                                  nsRegion *aInvalidRegion) const final;
 
   void RenderToContext(gfxContext* aCtx, nsDisplayListBuilder* aBuilder, bool aIsRecording = false);
 
   bool CanApplyOpacity() const final
   {
-    nsTextFrame* f = static_cast<nsTextFrame*>(mFrame);
-    if (f->IsSelected()) {
+    if (IsSelected()) {
       return false;
     }
 
+    nsTextFrame* f = static_cast<nsTextFrame*>(mFrame);
     const nsStyleText* textStyle = f->StyleText();
     if (textStyle->mTextShadow) {
       return false;
     }
 
     nsTextFrame::TextDecorations decorations;
     f->GetTextDecorations(f->PresContext(), nsTextFrame::eResolvedColors, decorations);
     if (decorations.HasDecorationLines()) {
@@ -6978,22 +6978,22 @@ nsTextFrame::PaintText(const PaintTextPa
   // *reference* context and rendering context might have some transform
   // in it
   // XXX get the block and line passed to us somehow! This is slow!
   gfxSkipCharsIterator iter = EnsureTextRun(nsTextFrame::eInflated);
   if (!mTextRun)
     return;
 
   PropertyProvider provider(this, iter, nsTextFrame::eInflated);
-  if (aItem.mIsFrameSelected.isNothing()) {
-    aItem.mIsFrameSelected.emplace(IsSelected());
-  }
+
+  const bool isSelected = aItem.IsSelected();
+
   // Trim trailing whitespace, unless we're painting a selection highlight,
   // which should include trailing spaces if present (bug 1146754).
-  provider.InitializeForDisplay(!aItem.mIsFrameSelected.value());
+  provider.InitializeForDisplay(!isSelected);
 
   const bool reversed = mTextRun->IsInlineReversed();
   const bool verticalRun = mTextRun->IsVertical();
   WritingMode wm = GetWritingMode();
   const float frameWidth = GetSize().width;
   const float frameHeight = GetSize().height;
   gfx::Point textBaselinePt;
   if (verticalRun) {
@@ -7027,17 +7027,17 @@ nsTextFrame::PaintText(const PaintTextPa
     textBaselinePt.x += reversed ? -snappedEndEdge : snappedStartEdge;
   }
   nsCharClipDisplayItem::ClipEdges clipEdges(aItem, snappedStartEdge,
                                              snappedEndEdge);
   nsTextPaintStyle textPaintStyle(this);
   textPaintStyle.SetResolveColors(!aParams.callbacks);
 
   // Fork off to the (slower) paint-with-selection path if necessary.
-  if (aItem.mIsFrameSelected.value() &&
+  if (isSelected &&
       (aParams.IsPaintBGColor() || ShouldDrawSelection(this->GetParent()))) {
     MOZ_ASSERT(aOpacity == 1.0f, "We don't support opacity with selections!");
     gfxSkipCharsIterator tmp(provider.GetStart());
     Range contentRange(
       uint32_t(tmp.ConvertSkippedToOriginal(startOffset)),
       uint32_t(tmp.ConvertSkippedToOriginal(startOffset + maxLength)));
     PaintTextSelectionParams params(aParams);
     params.textBaselinePt = textBaselinePt;
--- a/layout/painting/nsDisplayList.h
+++ b/layout/painting/nsDisplayList.h
@@ -7762,16 +7762,25 @@ public:
   {
     DisplayItemType t = aItem->GetType();
     return (t == DisplayItemType::TYPE_TEXT ||
             t == DisplayItemType::TYPE_SVG_CHAR_CLIP)
              ? static_cast<nsCharClipDisplayItem*>(aItem)
              : nullptr;
   }
 
+  bool IsSelected() const
+  {
+    if (mIsFrameSelected.isNothing()) {
+      mIsFrameSelected.emplace(mFrame->IsSelected());
+    }
+
+    return mIsFrameSelected.value();
+  }
+
   // Lengths measured from the visual inline start and end sides
   // (i.e. left and right respectively in horizontal writing modes,
   // regardless of bidi directionality; top and bottom in vertical modes).
   nscoord mVisIStartEdge;
   nscoord mVisIEndEdge;
   // Cached result of mFrame->IsSelected().  Only initialized when needed.
   mutable mozilla::Maybe<bool> mIsFrameSelected;
 };