Bug 1339683 - Move the function definition out of class for readability. r=mattwoodrow
authorMorris Tseng <mtseng@mozilla.com>
Mon, 20 Feb 2017 10:22:58 +0800
changeset 373022 0cd4548db0f2a87bc377fe6c2a493028b5c97a81
parent 373021 06746b37e4b100c725ead704aaecc08244b7f1d2
child 373023 4ffd45a1bb75e7fa122cd9df0ba6af1eceb9ae19
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow
bugs1339683
milestone54.0a1
Bug 1339683 - Move the function definition out of class for readability. r=mattwoodrow MozReview-Commit-ID: Ed1ItJYWxYG
layout/generic/nsBulletFrame.cpp
--- a/layout/generic/nsBulletFrame.cpp
+++ b/layout/generic/nsBulletFrame.cpp
@@ -222,91 +222,22 @@ public:
   {
     MOZ_ASSERT(IsTextType());
   }
 
   already_AddRefed<layers::Layer>
   BuildLayer(nsDisplayListBuilder* aBuilder,
              layers::LayerManager* aManager,
              const ContainerLayerParameters& aContainerParameters,
-             nsDisplayItem* aItem)
-  {
-    RefPtr<layers::Layer> oldLayer =
-      (aManager->GetLayerBuilder()->GetLeafLayerFor(aBuilder, aItem));
-    RefPtr<layers::Layer> layer;
-    nsPoint offset(aContainerParameters.mOffset.x, aContainerParameters.mOffset.y);
-
-    if (IsImageType()) {
-      layer = BuildLayerForImage(oldLayer, aBuilder, aManager, aItem);
-      offset = offset + mDest.TopLeft();
-    } else if (IsPathType()) {
-      layer = BuildLayerForPath(oldLayer, aBuilder, aManager, aItem);
-    } else {
-      MOZ_ASSERT(IsTextType());
-      layer = BuildLayerForText(oldLayer, aBuilder, aManager, aItem);
-    }
-
-    if (layer) {
-      layer->SetBaseTransform(gfx::Matrix4x4::Translation(offset.x, offset.y, 0));
-    }
-
-    return layer.forget();
-  }
+             nsDisplayItem* aItem);
 
   DrawResult
   Paint(nsRenderingContext& aRenderingContext, nsPoint aPt,
         const nsRect& aDirtyRect, uint32_t aFlags,
-        bool aDisableSubpixelAA, nsIFrame* aFrame)
-  {
-    if (IsImageType()) {
-      SamplingFilter filter = nsLayoutUtils::GetSamplingFilterForFrame(aFrame);
-      return nsLayoutUtils::DrawSingleImage(*aRenderingContext.ThebesContext(),
-                                            aFrame->PresContext(), mImage, filter,
-                                            mDest, aDirtyRect,
-                                            /* no SVGImageContext */ Nothing(),
-                                            aFlags);
-    }
-
-    if (IsPathType()) {
-      DrawTarget* drawTarget = aRenderingContext.GetDrawTarget();
-      switch (mListStyleType) {
-      case NS_STYLE_LIST_STYLE_CIRCLE:
-        MOZ_ASSERT(mPath);
-        drawTarget->Stroke(mPath, ColorPattern(ToDeviceColor(mColor)));
-        break;
-      case NS_STYLE_LIST_STYLE_DISC:
-      case NS_STYLE_LIST_STYLE_SQUARE:
-      case NS_STYLE_LIST_STYLE_DISCLOSURE_CLOSED:
-      case NS_STYLE_LIST_STYLE_DISCLOSURE_OPEN:
-        MOZ_ASSERT(mPath);
-        drawTarget->Fill(mPath, ColorPattern(ToDeviceColor(mColor)));
-        break;
-      default:
-        MOZ_CRASH("unreachable");
-      }
-    }
-
-    if (IsTextType()) {
-      DrawTarget* drawTarget = aRenderingContext.GetDrawTarget();
-      DrawTargetAutoDisableSubpixelAntialiasing
-        disable(drawTarget, aDisableSubpixelAA);
-
-      aRenderingContext.ThebesContext()->SetColor(
-        Color::FromABGR(mColor));
-
-      nsPresContext* presContext = aFrame->PresContext();
-      if (!presContext->BidiEnabled() && HasRTLChars(mText)) {
-        presContext->SetBidiEnabled();
-      }
-      nsLayoutUtils::DrawString(aFrame, *mFontMetrics, &aRenderingContext,
-                                mText.get(), mText.Length(), mPoint);
-    }
-
-    return DrawResult::SUCCESS;
-  }
+        bool aDisableSubpixelAA, nsIFrame* aFrame);
 
   bool
   IsImageType() const
   {
     return mListStyleType == NS_STYLE_LIST_STYLE_NONE && mImage;
   }
 
   bool
@@ -328,142 +259,36 @@ public:
            mListStyleType != NS_STYLE_LIST_STYLE_CIRCLE &&
            mListStyleType != NS_STYLE_LIST_STYLE_SQUARE &&
            mListStyleType != NS_STYLE_LIST_STYLE_DISCLOSURE_OPEN &&
            mListStyleType != NS_STYLE_LIST_STYLE_DISCLOSURE_CLOSED &&
            !mText.IsEmpty();
   }
 
   bool
-  BuildGlyphForText(nsDisplayItem* aItem, bool disableSubpixelAA)
-  {
-    MOZ_ASSERT(IsTextType());
-
-    RefPtr<DrawTargetCapture> capture =
-      gfxPlatform::GetPlatform()->ScreenReferenceDrawTarget()->CreateCaptureDT(IntSize());
-    RefPtr<gfxContext> captureCtx = gfxContext::CreateOrNull(capture);
-    nsRenderingContext ctx(captureCtx);
-
-    {
-      DrawTargetAutoDisableSubpixelAntialiasing
-        disable(capture, disableSubpixelAA);
-
-      ctx.ThebesContext()->SetColor(
-        Color::FromABGR(mColor));
-
-      nsPresContext* presContext = aItem->Frame()->PresContext();
-      if (!presContext->BidiEnabled() && HasRTLChars(mText)) {
-        presContext->SetBidiEnabled();
-      }
-      nsLayoutUtils::DrawString(aItem->Frame(), *mFontMetrics, &ctx,
-                                mText.get(), mText.Length(), mPoint);
-    }
-
-    layers::GlyphArray* g = mGlyphs.AppendElement();
-    std::vector<Glyph> glyphs;
-    Color color;
-    if (!capture->ContainsOnlyColoredGlyphs(mFont, color, glyphs)) {
-      mFont = nullptr;
-      mGlyphs.Clear();
-      return false;
-    }
-
-    g->glyphs().SetLength(glyphs.size());
-    PodCopy(g->glyphs().Elements(), glyphs.data(), glyphs.size());
-    g->color() = color;
-
-    return true;
-  }
+  BuildGlyphForText(nsDisplayItem* aItem, bool disableSubpixelAA);
 
 private:
   already_AddRefed<layers::Layer>
   BuildLayerForImage(layers::Layer* aOldLayer,
                      nsDisplayListBuilder* aBuilder,
                      layers::LayerManager* aManager,
-                     nsDisplayItem* aItem)
-  {
-    MOZ_ASSERT(IsImageType());
-
-    uint32_t flags = imgIContainer::FLAG_NONE;
-    if (aBuilder->ShouldSyncDecodeImages()) {
-      flags |= imgIContainer::FLAG_SYNC_DECODE;
-    }
-
-    RefPtr<layers::ImageContainer> container =
-      mImage->GetImageContainer(aManager, flags);
-    if (!container) {
-      return nullptr;
-    }
-
-    RefPtr<layers::ImageLayer> layer;
-    if (aOldLayer && aOldLayer->GetType() == layers::Layer::TYPE_IMAGE) {
-      layer = static_cast<layers::ImageLayer*>(aOldLayer);
-    } else {
-      layer = aManager->CreateImageLayer();
-      if (!layer) {
-        return nullptr;
-      }
-    }
-
-    layer->SetContainer(container);
-    int32_t imageWidth;
-    int32_t imageHeight;
-    mImage->GetWidth(&imageWidth);
-    mImage->GetHeight(&imageHeight);
-    if (imageWidth > 0 && imageHeight > 0) {
-      // We're actually using the ImageContainer. Let our frame know that it
-      // should consider itself to have painted successfully.
-      nsDisplayBulletGeometry::UpdateDrawResult(aItem,
-                                                image::DrawResult::SUCCESS);
-    }
-
-    return layer.forget();
-  }
+                     nsDisplayItem* aItem);
 
   already_AddRefed<layers::Layer>
   BuildLayerForPath(layers::Layer* aOldLayer,
                     nsDisplayListBuilder* aBuilder,
                     layers::LayerManager* aManager,
-                    nsDisplayItem* aItem)
-  {
-    MOZ_ASSERT(IsPathType());
-
-    // Not supported yet.
-    return nullptr;
-  }
+                    nsDisplayItem* aItem);
 
   already_AddRefed<layers::Layer>
   BuildLayerForText(layers::Layer* aOldLayer,
                     nsDisplayListBuilder* aBuilder,
                     layers::LayerManager* aManager,
-                    nsDisplayItem* aItem)
-  {
-    MOZ_ASSERT(IsTextType());
-    MOZ_ASSERT(mFont);
-    MOZ_ASSERT(!mGlyphs.IsEmpty());
-
-    RefPtr<layers::TextLayer> layer;
-    if (aOldLayer && aOldLayer->GetType() == layers::Layer::TYPE_TEXT) {
-      layer = static_cast<layers::TextLayer*>(aOldLayer);
-    } else {
-      layer = aManager->CreateTextLayer();
-      if (!layer) {
-        return nullptr;
-      }
-    }
-
-    layer->SetGlyphs(Move(mGlyphs));
-    layer->SetScaledFont(mFont);
-    auto A2D = aItem->Frame()->PresContext()->AppUnitsPerDevPixel();
-    bool dummy;
-    const LayoutDeviceIntRect destBounds =
-      LayoutDeviceIntRect::FromAppUnitsToOutside(aItem->GetBounds(aBuilder, &dummy), A2D);
-    layer->SetBounds(IntRect(destBounds.x, destBounds.y, destBounds.width, destBounds.height));
-    return layer.forget();
-  }
+                    nsDisplayItem* aItem);
 
 private:
   // mImage and mDest are the properties for list-style-image.
   // mImage is the image content and mDest is the image position.
   RefPtr<imgIContainer> mImage;
   nsRect mDest;
 
   // mColor indicate the color of list-style. Both text and path type would use this memeber.
@@ -480,16 +305,223 @@ private:
   nsPoint mPoint;
   RefPtr<ScaledFont> mFont;
   nsTArray<layers::GlyphArray> mGlyphs;
 
   // Store the type of list-style-type.
   int32_t mListStyleType;
 };
 
+already_AddRefed<layers::Layer>
+BulletRenderer::BuildLayer(nsDisplayListBuilder* aBuilder,
+                           layers::LayerManager* aManager,
+                           const ContainerLayerParameters& aContainerParameters,
+                           nsDisplayItem* aItem)
+{
+  RefPtr<layers::Layer> oldLayer =
+    (aManager->GetLayerBuilder()->GetLeafLayerFor(aBuilder, aItem));
+  RefPtr<layers::Layer> layer;
+  nsPoint offset(aContainerParameters.mOffset.x, aContainerParameters.mOffset.y);
+
+  if (IsImageType()) {
+    layer = BuildLayerForImage(oldLayer, aBuilder, aManager, aItem);
+    offset = offset + mDest.TopLeft();
+  } else if (IsPathType()) {
+    layer = BuildLayerForPath(oldLayer, aBuilder, aManager, aItem);
+  } else {
+    MOZ_ASSERT(IsTextType());
+    layer = BuildLayerForText(oldLayer, aBuilder, aManager, aItem);
+  }
+
+  if (layer) {
+    layer->SetBaseTransform(gfx::Matrix4x4::Translation(offset.x, offset.y, 0));
+  }
+
+  return layer.forget();
+}
+
+DrawResult
+BulletRenderer::Paint(nsRenderingContext& aRenderingContext, nsPoint aPt,
+                      const nsRect& aDirtyRect, uint32_t aFlags,
+                      bool aDisableSubpixelAA, nsIFrame* aFrame)
+{
+  if (IsImageType()) {
+    SamplingFilter filter = nsLayoutUtils::GetSamplingFilterForFrame(aFrame);
+    return nsLayoutUtils::DrawSingleImage(*aRenderingContext.ThebesContext(),
+                                          aFrame->PresContext(), mImage, filter,
+                                          mDest, aDirtyRect,
+                                          /* no SVGImageContext */ Nothing(),
+                                          aFlags);
+  }
+
+  if (IsPathType()) {
+    DrawTarget* drawTarget = aRenderingContext.GetDrawTarget();
+    switch (mListStyleType) {
+    case NS_STYLE_LIST_STYLE_CIRCLE:
+      MOZ_ASSERT(mPath);
+      drawTarget->Stroke(mPath, ColorPattern(ToDeviceColor(mColor)));
+      break;
+    case NS_STYLE_LIST_STYLE_DISC:
+    case NS_STYLE_LIST_STYLE_SQUARE:
+    case NS_STYLE_LIST_STYLE_DISCLOSURE_CLOSED:
+    case NS_STYLE_LIST_STYLE_DISCLOSURE_OPEN:
+      MOZ_ASSERT(mPath);
+      drawTarget->Fill(mPath, ColorPattern(ToDeviceColor(mColor)));
+      break;
+    default:
+      MOZ_CRASH("unreachable");
+    }
+  }
+
+  if (IsTextType()) {
+    DrawTarget* drawTarget = aRenderingContext.GetDrawTarget();
+    DrawTargetAutoDisableSubpixelAntialiasing
+      disable(drawTarget, aDisableSubpixelAA);
+
+    aRenderingContext.ThebesContext()->SetColor(
+      Color::FromABGR(mColor));
+
+    nsPresContext* presContext = aFrame->PresContext();
+    if (!presContext->BidiEnabled() && HasRTLChars(mText)) {
+      presContext->SetBidiEnabled();
+    }
+    nsLayoutUtils::DrawString(aFrame, *mFontMetrics, &aRenderingContext,
+                              mText.get(), mText.Length(), mPoint);
+  }
+
+  return DrawResult::SUCCESS;
+}
+
+bool
+BulletRenderer::BuildGlyphForText(nsDisplayItem* aItem, bool disableSubpixelAA)
+{
+  MOZ_ASSERT(IsTextType());
+
+  RefPtr<DrawTargetCapture> capture =
+    gfxPlatform::GetPlatform()->ScreenReferenceDrawTarget()->CreateCaptureDT(IntSize());
+  RefPtr<gfxContext> captureCtx = gfxContext::CreateOrNull(capture);
+  nsRenderingContext ctx(captureCtx);
+
+  {
+    DrawTargetAutoDisableSubpixelAntialiasing
+      disable(capture, disableSubpixelAA);
+
+    ctx.ThebesContext()->SetColor(
+      Color::FromABGR(mColor));
+
+    nsPresContext* presContext = aItem->Frame()->PresContext();
+    if (!presContext->BidiEnabled() && HasRTLChars(mText)) {
+      presContext->SetBidiEnabled();
+    }
+    nsLayoutUtils::DrawString(aItem->Frame(), *mFontMetrics, &ctx,
+                              mText.get(), mText.Length(), mPoint);
+  }
+
+  layers::GlyphArray* g = mGlyphs.AppendElement();
+  std::vector<Glyph> glyphs;
+  Color color;
+  if (!capture->ContainsOnlyColoredGlyphs(mFont, color, glyphs)) {
+    mFont = nullptr;
+    mGlyphs.Clear();
+    return false;
+  }
+
+  g->glyphs().SetLength(glyphs.size());
+  PodCopy(g->glyphs().Elements(), glyphs.data(), glyphs.size());
+  g->color() = color;
+
+  return true;
+}
+
+already_AddRefed<layers::Layer>
+BulletRenderer::BuildLayerForImage(layers::Layer* aOldLayer,
+                                   nsDisplayListBuilder* aBuilder,
+                                   layers::LayerManager* aManager,
+                                   nsDisplayItem* aItem)
+{
+  MOZ_ASSERT(IsImageType());
+
+  uint32_t flags = imgIContainer::FLAG_NONE;
+  if (aBuilder->ShouldSyncDecodeImages()) {
+    flags |= imgIContainer::FLAG_SYNC_DECODE;
+  }
+
+  RefPtr<layers::ImageContainer> container =
+    mImage->GetImageContainer(aManager, flags);
+  if (!container) {
+    return nullptr;
+  }
+
+  RefPtr<layers::ImageLayer> layer;
+  if (aOldLayer && aOldLayer->GetType() == layers::Layer::TYPE_IMAGE) {
+    layer = static_cast<layers::ImageLayer*>(aOldLayer);
+  } else {
+    layer = aManager->CreateImageLayer();
+    if (!layer) {
+      return nullptr;
+    }
+  }
+
+  layer->SetContainer(container);
+  int32_t imageWidth;
+  int32_t imageHeight;
+  mImage->GetWidth(&imageWidth);
+  mImage->GetHeight(&imageHeight);
+  if (imageWidth > 0 && imageHeight > 0) {
+    // We're actually using the ImageContainer. Let our frame know that it
+    // should consider itself to have painted successfully.
+    nsDisplayBulletGeometry::UpdateDrawResult(aItem,
+                                              image::DrawResult::SUCCESS);
+  }
+
+  return layer.forget();
+}
+
+already_AddRefed<layers::Layer>
+BulletRenderer::BuildLayerForPath(layers::Layer* aOldLayer,
+                                  nsDisplayListBuilder* aBuilder,
+                                  layers::LayerManager* aManager,
+                                  nsDisplayItem* aItem)
+{
+  MOZ_ASSERT(IsPathType());
+
+  // Not supported yet.
+  return nullptr;
+}
+
+already_AddRefed<layers::Layer>
+BulletRenderer::BuildLayerForText(layers::Layer* aOldLayer,
+                                  nsDisplayListBuilder* aBuilder,
+                                  layers::LayerManager* aManager,
+                                  nsDisplayItem* aItem)
+{
+  MOZ_ASSERT(IsTextType());
+  MOZ_ASSERT(mFont);
+  MOZ_ASSERT(!mGlyphs.IsEmpty());
+
+  RefPtr<layers::TextLayer> layer;
+  if (aOldLayer && aOldLayer->GetType() == layers::Layer::TYPE_TEXT) {
+    layer = static_cast<layers::TextLayer*>(aOldLayer);
+  } else {
+    layer = aManager->CreateTextLayer();
+    if (!layer) {
+      return nullptr;
+    }
+  }
+
+  layer->SetGlyphs(Move(mGlyphs));
+  layer->SetScaledFont(mFont);
+  auto A2D = aItem->Frame()->PresContext()->AppUnitsPerDevPixel();
+  bool dummy;
+  const LayoutDeviceIntRect destBounds =
+    LayoutDeviceIntRect::FromAppUnitsToOutside(aItem->GetBounds(aBuilder, &dummy), A2D);
+  layer->SetBounds(IntRect(destBounds.x, destBounds.y, destBounds.width, destBounds.height));
+  return layer.forget();
+}
+
 class nsDisplayBullet final : public nsDisplayItem {
 public:
   nsDisplayBullet(nsDisplayListBuilder* aBuilder, nsBulletFrame* aFrame)
     : nsDisplayItem(aBuilder, aFrame)
     , mDisableSubpixelAA(false)
   {
     MOZ_COUNT_CTOR(nsDisplayBullet);
   }