Bug 1346702 - Part1. Create border renderer in nsDisplayBorder::GetLayerState. r=mchang
authorEthan Lin <ethlin@mozilla.com>
Wed, 15 Mar 2017 14:37:50 +0800
changeset 349162 3a6924086fdba282c6e2db549d8d6b07dc5e31ab
parent 349161 563b634aec444d5028658e24c85805eff63cd279
child 349163 864a80a4fc138a38f1875ecbf166b2eb817f12b7
push id31546
push userkwierso@gmail.com
push dateThu, 23 Mar 2017 17:37:25 +0000
treeherdermozilla-central@200182ef1156 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmchang
bugs1346702
milestone55.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 1346702 - Part1. Create border renderer in nsDisplayBorder::GetLayerState. r=mchang
layout/painting/nsDisplayList.cpp
layout/painting/nsDisplayList.h
--- a/layout/painting/nsDisplayList.cpp
+++ b/layout/painting/nsDisplayList.cpp
@@ -4552,41 +4552,31 @@ nsDisplayBorder::GetLayerState(nsDisplay
                                          mFrame,
                                          nsRect(),
                                          nsRect(offset, mFrame->GetSize()),
                                          mFrame->StyleContext(),
                                          mFrame->GetSkipSides());
 
   const nsStyleBorder *styleBorder = mFrame->StyleContext()->StyleBorder();
   const nsStyleImage* image = &styleBorder->mBorderImageSource;
+  mBorderRenderer = Nothing();
   mBorderImageRenderer = Nothing();
   if ((!image || image->GetType() != eStyleImageType_Image) && !br) {
     return LAYER_NONE;
   }
 
   LayersBackend backend = aManager->GetBackendType();
   if (backend == layers::LayersBackend::LAYERS_WR) {
     if (br) {
       bool hasCompositeColors;
       br->AllBordersSolid(&hasCompositeColors);
       if (hasCompositeColors) {
         return LAYER_NONE;
       }
-
-      NS_FOR_CSS_SIDES(i) {
-        mColors[i] = ToDeviceColor(br->mBorderColors[i]);
-        mWidths[i] = br->mBorderWidths[i];
-        mBorderStyles[i] = br->mBorderStyles[i];
-      }
-
-      NS_FOR_CSS_FULL_CORNERS(corner) {
-        mCorners[corner] = LayerSize(br->mBorderRadii[corner].width, br->mBorderRadii[corner].height);
-      }
-
-      mRect = ViewAs<LayerPixel>(br->mOuterRect);
+      mBorderRenderer = br;
     } else {
       if (styleBorder->mBorderImageRepeatH == NS_STYLE_BORDER_IMAGE_REPEAT_ROUND ||
           styleBorder->mBorderImageRepeatH == NS_STYLE_BORDER_IMAGE_REPEAT_SPACE ||
           styleBorder->mBorderImageRepeatV == NS_STYLE_BORDER_IMAGE_REPEAT_ROUND ||
           styleBorder->mBorderImageRepeatV == NS_STYLE_BORDER_IMAGE_REPEAT_SPACE) {
         // WebRender not supports this currently
         return LAYER_NONE;
       }
@@ -4658,38 +4648,16 @@ already_AddRefed<Layer>
 nsDisplayBorder::BuildLayer(nsDisplayListBuilder* aBuilder,
                             LayerManager* aManager,
                             const ContainerLayerParameters& aContainerParameters)
 {
   return BuildDisplayItemLayer(aBuilder, aManager, aContainerParameters);
 }
 
 void
-nsDisplayBorder::CreateBorderWebRenderCommands(mozilla::wr::DisplayListBuilder& aBuilder,
-                                               WebRenderDisplayItemLayer* aLayer)
-{
-  nsPoint offset = ToReferenceFrame();
-  Maybe<nsCSSBorderRenderer> br =
-    nsCSSRendering::CreateBorderRenderer(mFrame->PresContext(),
-                                         nullptr,
-                                         mFrame,
-                                         nsRect(),
-                                         nsRect(offset, mFrame->GetSize()),
-                                         mFrame->StyleContext(),
-                                         mFrame->GetSkipSides());
-
-  if (!br) {
-    NS_WARNING("Could not create border renderer during nsDisplayButtonBorder");
-    return;
-  }
-
-  br->CreateWebRenderCommands(aBuilder, aLayer);
-}
-
-void
 nsDisplayBorder::CreateBorderImageWebRenderCommands(mozilla::wr::DisplayListBuilder& aBuilder,
                                                     nsTArray<WebRenderParentCommand>& aParentCommands,
                                                     WebRenderDisplayItemLayer* aLayer)
 {
   // Only support border-image currently
   MOZ_ASSERT(mBorderImageRenderer);
   if (!mBorderImageRenderer->mImageRenderer.IsReady()) {
     return;
@@ -4748,20 +4716,22 @@ nsDisplayBorder::CreateBorderImageWebRen
                            wr::ToWrRepeatMode(mBorderImageRenderer->mRepeatModeVertical));
 }
 
 void
 nsDisplayBorder::CreateWebRenderCommands(wr::DisplayListBuilder& aBuilder,
                                          nsTArray<WebRenderParentCommand>& aParentCommands,
                                          WebRenderDisplayItemLayer* aLayer)
 {
+  MOZ_ASSERT(mBorderImageRenderer || mBorderRenderer);
+
   if (mBorderImageRenderer) {
     CreateBorderImageWebRenderCommands(aBuilder, aParentCommands, aLayer);
-  } else {
-    CreateBorderWebRenderCommands(aBuilder, aLayer);
+  } else if (mBorderRenderer) {
+    mBorderRenderer->CreateWebRenderCommands(aBuilder, aLayer);
   }
 }
 
 void
 nsDisplayBorder::Paint(nsDisplayListBuilder* aBuilder,
                        nsRenderingContext* aCtx) {
   nsPoint offset = ToReferenceFrame();
 
--- a/layout/painting/nsDisplayList.h
+++ b/layout/painting/nsDisplayList.h
@@ -2875,27 +2875,25 @@ public:
     *aSnap = true;
     return CalculateBounds(*mFrame->StyleBorder());
   }
 
 protected:
   void CreateBorderImageWebRenderCommands(mozilla::wr::DisplayListBuilder& aBuilder,
                                           nsTArray<WebRenderParentCommand>& aParentCommands,
                                           WebRenderDisplayItemLayer* aLayer);
-  void CreateBorderWebRenderCommands(mozilla::wr::DisplayListBuilder& aBuilder,
-                                    WebRenderDisplayItemLayer* aLayer);
   nsRegion CalculateBounds(const nsStyleBorder& aStyleBorder);
 
   mozilla::Array<mozilla::gfx::Color, 4> mColors;
   mozilla::Array<mozilla::LayerCoord, 4> mWidths;
   mozilla::Array<mozilla::LayerSize, 4> mCorners;
   mozilla::Array<uint8_t, 4> mBorderStyles;
   mozilla::LayerRect mRect;
 
-  // For border image
+  mozilla::Maybe<nsCSSBorderRenderer> mBorderRenderer;
   mozilla::Maybe<nsCSSBorderImageRenderer> mBorderImageRenderer;
 
   nsRect mBounds;
 };
 
 /**
  * A simple display item that just renders a solid color across the
  * specified bounds. For canvas frames (in the CSS sense) we split off the