Bug 1407938 - Part2. Extract paint function for filter and svg wrapper. r=jrmuizel
authorEthan Lin <ethlin@mozilla.com>
Mon, 16 Oct 2017 16:26:15 +0800
changeset 389397 6552b096baf08377ec1fcb7a5759dbf5972de211
parent 389396 0eeb0113f966beaaca20d5c26de849fe0847f406
child 389398 763e524b44f635d687bdcac8b9466fc776e3a874
push id96855
push userarchaeopteryx@coole-files.de
push dateTue, 31 Oct 2017 23:40:37 +0000
treeherdermozilla-inbound@285362745f60 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1407938
milestone58.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 1407938 - Part2. Extract paint function for filter and svg wrapper. r=jrmuizel MozReview-Commit-ID: CQpBdZapFH2
gfx/layers/wr/WebRenderCommandBuilder.cpp
--- a/gfx/layers/wr/WebRenderCommandBuilder.cpp
+++ b/gfx/layers/wr/WebRenderCommandBuilder.cpp
@@ -340,16 +340,61 @@ WebRenderCommandBuilder::PushImage(nsDis
   auto r = aSc.ToRelativeLayoutRect(aRect);
   gfx::SamplingFilter sampleFilter = nsLayoutUtils::GetSamplingFilterForFrame(aItem->Frame());
   aBuilder.PushImage(r, r, !aItem->BackfaceIsHidden(), wr::ToImageRendering(sampleFilter), key.value());
 
   return true;
 }
 
 static void
+PaintByLayer(nsDisplayItem* aItem,
+             nsDisplayListBuilder* aDisplayListBuilder,
+             RefPtr<BasicLayerManager>& aManager,
+             gfxContext* aContext,
+             const std::function<void()>& aPaintFunc)
+{
+  if (aManager == nullptr) {
+    aManager = new BasicLayerManager(BasicLayerManager::BLM_INACTIVE);
+  }
+
+  FrameLayerBuilder* layerBuilder = new FrameLayerBuilder();
+  layerBuilder->Init(aDisplayListBuilder, aManager, nullptr, true);
+  layerBuilder->DidBeginRetainedLayerTransaction(aManager);
+
+  aManager->BeginTransactionWithTarget(aContext);
+
+  ContainerLayerParameters param;
+  RefPtr<Layer> layer = aItem->BuildLayer(aDisplayListBuilder, aManager, param);
+  if (layer) {
+    UniquePtr<LayerProperties> props;
+    props = Move(LayerProperties::CloneFrom(aManager->GetRoot()));
+
+    aManager->SetRoot(layer);
+    layerBuilder->WillEndTransaction();
+
+    aPaintFunc();
+  }
+
+#ifdef MOZ_DUMP_PAINTING
+  if (gfxUtils::DumpDisplayList() || gfxEnv::DumpPaint()) {
+    fprintf_stderr(gfxUtils::sDumpPaintFile, "Basic layer tree for painting contents of display item %s(%p):\n", aItem->Name(), aItem->Frame());
+    std::stringstream stream;
+    aManager->Dump(stream, "", gfxEnv::DumpPaintToFile());
+    fprint_stderr(gfxUtils::sDumpPaintFile, stream);  // not a typo, fprint_stderr declared in LayersLogging.h
+  }
+#endif
+
+  if (aManager->InTransaction()) {
+    aManager->AbortTransaction();
+  }
+
+  aManager->SetTarget(nullptr);
+}
+
+static void
 PaintItemByDrawTarget(nsDisplayItem* aItem,
                       gfx::DrawTarget* aDT,
                       const LayerRect& aImageRect,
                       const LayoutDevicePoint& aOffset,
                       nsDisplayListBuilder* aDisplayListBuilder,
                       RefPtr<BasicLayerManager>& aManager,
                       WebRenderLayerManager* aWrManager,
                       const gfx::Size& aScale)
@@ -363,88 +408,31 @@ PaintItemByDrawTarget(nsDisplayItem* aIt
   context->SetMatrix(context->CurrentMatrix().PreScale(aScale.width, aScale.height).PreTranslate(-aOffset.x, -aOffset.y));
 
   switch (aItem->GetType()) {
   case DisplayItemType::TYPE_MASK:
     static_cast<nsDisplayMask*>(aItem)->PaintMask(aDisplayListBuilder, context);
     break;
   case DisplayItemType::TYPE_SVG_WRAPPER:
     {
-      if (aManager == nullptr) {
-        aManager = new BasicLayerManager(BasicLayerManager::BLM_INACTIVE);
-      }
-
-      FrameLayerBuilder* layerBuilder = new FrameLayerBuilder();
-      layerBuilder->Init(aDisplayListBuilder, aManager, nullptr, true);
-      layerBuilder->DidBeginRetainedLayerTransaction(aManager);
-
-      aManager->BeginTransactionWithTarget(context);
-
-      ContainerLayerParameters param;
-      RefPtr<Layer> layer =
-        static_cast<nsDisplayFilter*>(aItem)->BuildLayer(aDisplayListBuilder,
-                                                         aManager, param);
-      if (layer) {
-        UniquePtr<LayerProperties> props;
-        props = Move(LayerProperties::CloneFrom(aManager->GetRoot()));
-        aManager->SetRoot(layer);
-        layerBuilder->WillEndTransaction();
+      PaintByLayer(aItem, aDisplayListBuilder, aManager, context, [&]() {
         aManager->EndTransaction(FrameLayerBuilder::DrawPaintedLayer, aDisplayListBuilder);
-      }
-
-      if (aManager->InTransaction()) {
-        aManager->AbortTransaction();
-      }
-      aManager->SetTarget(nullptr);
+      });
       break;
     }
 
   case DisplayItemType::TYPE_FILTER:
     {
-      if (aManager == nullptr) {
-        aManager = new BasicLayerManager(BasicLayerManager::BLM_INACTIVE);
-      }
-
-      FrameLayerBuilder* layerBuilder = new FrameLayerBuilder();
-      layerBuilder->Init(aDisplayListBuilder, aManager, nullptr, true);
-      layerBuilder->DidBeginRetainedLayerTransaction(aManager);
-
-      aManager->BeginTransactionWithTarget(context);
-
-      ContainerLayerParameters param;
-      RefPtr<Layer> layer =
-        static_cast<nsDisplayFilter*>(aItem)->BuildLayer(aDisplayListBuilder,
-                                                         aManager, param);
-
-      if (layer) {
-        UniquePtr<LayerProperties> props;
-        props = Move(LayerProperties::CloneFrom(aManager->GetRoot()));
-
-        aManager->SetRoot(layer);
-        layerBuilder->WillEndTransaction();
-
+      PaintByLayer(aItem, aDisplayListBuilder, aManager, context, [&]() {
         static_cast<nsDisplayFilter*>(aItem)->PaintAsLayer(aDisplayListBuilder,
                                                            context, aManager);
-      }
-
-#ifdef MOZ_DUMP_PAINTING
-      if (gfxUtils::DumpDisplayList() || gfxEnv::DumpPaint()) {
-        fprintf_stderr(gfxUtils::sDumpPaintFile, "Basic layer tree for painting contents of display item %s(%p):\n", aItem->Name(), aItem->Frame());
-        std::stringstream stream;
-        aManager->Dump(stream, "", gfxEnv::DumpPaintToFile());
-        fprint_stderr(gfxUtils::sDumpPaintFile, stream);  // not a typo, fprint_stderr declared in LayersLogging.h
-      }
-#endif
-
-      if (aManager->InTransaction()) {
-        aManager->AbortTransaction();
-      }
-      aManager->SetTarget(nullptr);
+      });
       break;
     }
+
   default:
     aItem->Paint(aDisplayListBuilder, context);
     break;
   }
 
   if (gfxPrefs::WebRenderHighlightPaintedLayers()) {
     aDT->SetTransform(gfx::Matrix());
     aDT->FillRect(gfx::Rect(0, 0, aImageRect.Width(), aImageRect.Height()), gfx::ColorPattern(gfx::Color(1.0, 0.0, 0.0, 0.5)));