Bug 1393383 - Update webrender binding code to support non-uniform border radius r=kats
authorChih-Yi Leu <subsevenx2001@gmail.com>
Tue, 24 Oct 2017 14:44:29 +0800
changeset 685706 f1f825dbd4cf5804c944bad7dae2d2c4d3e1678d
parent 685705 a59e00e80ba49ba45aeaa4524b991395775ee285
child 685707 2d9463ac3b6024350c5622b6dd1bbff8ac3d9b64
push id86016
push userkgupta@mozilla.com
push dateWed, 25 Oct 2017 01:53:44 +0000
reviewerskats
bugs1393383
milestone58.0a1
Bug 1393383 - Update webrender binding code to support non-uniform border radius r=kats MozReview-Commit-ID: 9YIPRJ9Mzfi
gfx/webrender_bindings/WebRenderAPI.cpp
gfx/webrender_bindings/WebRenderAPI.h
gfx/webrender_bindings/src/bindings.rs
gfx/webrender_bindings/webrender_ffi_generated.h
layout/forms/nsButtonFrameRenderer.cpp
layout/painting/nsDisplayList.cpp
--- a/gfx/webrender_bindings/WebRenderAPI.cpp
+++ b/gfx/webrender_bindings/WebRenderAPI.cpp
@@ -1099,17 +1099,17 @@ void
 DisplayListBuilder::PushBoxShadow(const wr::LayoutRect& aRect,
                                   const wr::LayoutRect& aClip,
                                   bool aIsBackfaceVisible,
                                   const wr::LayoutRect& aBoxBounds,
                                   const wr::LayoutVector2D& aOffset,
                                   const wr::ColorF& aColor,
                                   const float& aBlurRadius,
                                   const float& aSpreadRadius,
-                                  const float& aBorderRadius,
+                                  const wr::BorderRadius& aBorderRadius,
                                   const wr::BoxShadowClipMode& aClipMode)
 {
   wr_dp_push_box_shadow(mWrState, aRect, aClip, aIsBackfaceVisible,
                         aBoxBounds, aOffset, aColor,
                         aBlurRadius, aSpreadRadius, aBorderRadius,
                         aClipMode);
 }
 
--- a/gfx/webrender_bindings/WebRenderAPI.h
+++ b/gfx/webrender_bindings/WebRenderAPI.h
@@ -383,17 +383,17 @@ public:
   void PushBoxShadow(const wr::LayoutRect& aRect,
                      const wr::LayoutRect& aClip,
                      bool aIsBackfaceVisible,
                      const wr::LayoutRect& aBoxBounds,
                      const wr::LayoutVector2D& aOffset,
                      const wr::ColorF& aColor,
                      const float& aBlurRadius,
                      const float& aSpreadRadius,
-                     const float& aBorderRadius,
+                     const wr::BorderRadius& aBorderRadius,
                      const wr::BoxShadowClipMode& aClipMode);
 
   // Returns the clip id that was most recently pushed with PushClip and that
   // has not yet been popped with PopClip. Return Nothing() if the clip stack
   // is empty.
   Maybe<wr::WrClipId> TopmostClipId();
   // Same as TopmostClipId() but for scroll layers.
   layers::FrameMetrics::ViewID TopmostScrollId();
--- a/gfx/webrender_bindings/src/bindings.rs
+++ b/gfx/webrender_bindings/src/bindings.rs
@@ -1713,31 +1713,31 @@ pub extern "C" fn wr_dp_push_box_shadow(
                                         rect: LayoutRect,
                                         clip: LayoutRect,
                                         is_backface_visible: bool,
                                         box_bounds: LayoutRect,
                                         offset: LayoutVector2D,
                                         color: ColorF,
                                         blur_radius: f32,
                                         spread_radius: f32,
-                                        border_radius: f32,
+                                        border_radius: BorderRadius,
                                         clip_mode: BoxShadowClipMode) {
     debug_assert!(unsafe { is_in_main_thread() });
 
     let mut prim_info = LayoutPrimitiveInfo::with_clip_rect(rect, clip.into());
     prim_info.is_backface_visible = is_backface_visible;
     state.frame_builder
          .dl_builder
          .push_box_shadow(&prim_info,
                           box_bounds,
                           offset,
                           color,
                           blur_radius,
                           spread_radius,
-                          BorderRadius::uniform(border_radius),
+                          border_radius,
                           clip_mode);
 }
 
 #[no_mangle]
 pub unsafe extern "C" fn wr_api_finalize_builder(state: &mut WrState,
                                                  content_size: &mut LayoutSize,
                                                  dl_descriptor: &mut BuiltDisplayListDescriptor,
                                                  dl_data: &mut WrVecU8) {
--- a/gfx/webrender_bindings/webrender_ffi_generated.h
+++ b/gfx/webrender_bindings/webrender_ffi_generated.h
@@ -1048,17 +1048,17 @@ void wr_dp_push_box_shadow(WrState *aSta
                            LayoutRect aRect,
                            LayoutRect aClip,
                            bool aIsBackfaceVisible,
                            LayoutRect aBoxBounds,
                            LayoutVector2D aOffset,
                            ColorF aColor,
                            float aBlurRadius,
                            float aSpreadRadius,
-                           float aBorderRadius,
+                           BorderRadius aBorderRadius,
                            BoxShadowClipMode aClipMode)
 WR_FUNC;
 
 WR_INLINE
 void wr_dp_push_clip(WrState *aState,
                      uint64_t aClipId)
 WR_FUNC;
 
--- a/layout/forms/nsButtonFrameRenderer.cpp
+++ b/layout/forms/nsButtonFrameRenderer.cpp
@@ -155,24 +155,16 @@ nsDisplayButtonBoxShadowOuter::CanBuildW
     nsCSSRendering::GetShadowRect(borderRect, nativeTheme, mFrame);
 
   if (hasBorderRadius) {
     nscoord twipsRadii[8];
     nsSize sz = frameRect.Size();
     hasBorderRadius = mFrame->GetBorderRadii(sz, sz, Sides(), twipsRadii);
   }
 
-  if (hasBorderRadius) {
-    nsCSSRendering::RectCornerRadii borderRadii;
-    nsCSSRendering::GetBorderRadii(frameRect, borderRect, mFrame, borderRadii);
-    if (!borderRadii.AreRadiiSame()) {
-      return false;
-    }
-  }
-
   return true;
 }
 
 LayerState
 nsDisplayButtonBoxShadowOuter::GetLayerState(
   nsDisplayListBuilder* aBuilder,
   LayerManager* aManager,
   const ContainerLayerParameters& aParameters)
@@ -214,24 +206,31 @@ nsDisplayButtonBoxShadowOuter::CreateWeb
 
   LayoutDeviceRect clipRect =
     LayoutDeviceRect::FromAppUnits(mVisibleRect, appUnitsPerDevPixel);
   wr::LayoutRect deviceClipRect = aSc.ToRelativeLayoutRect(clipRect);
 
   bool hasBorderRadius;
   Unused << nsCSSRendering::HasBoxShadowNativeTheme(mFrame, hasBorderRadius);
 
-  float borderRadius = 0.0;
+  LayoutDeviceSize zeroSize;
+  wr::BorderRadius borderRadius = wr::ToBorderRadius(zeroSize, zeroSize,
+                                                     zeroSize, zeroSize);
   if (hasBorderRadius) {
     mozilla::gfx::RectCornerRadii borderRadii;
     hasBorderRadius = nsCSSRendering::GetBorderRadii(
       shadowRect, shadowRect, mFrame, borderRadii);
-    // TODO: support non-uniform border radius.
-    MOZ_ASSERT(borderRadii.AreRadiiSame());
-    borderRadius = hasBorderRadius ? borderRadii.TopLeft().width : 0.0;
+    if (hasBorderRadius) {
+      borderRadius = wr::ToBorderRadius(
+        LayoutDeviceSize::FromUnknownSize(borderRadii.TopLeft()),
+        LayoutDeviceSize::FromUnknownSize(borderRadii.TopRight()),
+        LayoutDeviceSize::FromUnknownSize(borderRadii.BottomLeft()),
+        LayoutDeviceSize::FromUnknownSize(borderRadii.BottomRight()));
+    }
+
   }
 
   nsCSSShadowArray* shadows = mFrame->StyleEffects()->mBoxShadow;
   MOZ_ASSERT(shadows);
 
   for (uint32_t i = shadows->Length(); i > 0; i--) {
     nsCSSShadowItem* shadow = shadows->ShadowAt(i - 1);
     if (shadow->mInset) {
--- a/layout/painting/nsDisplayList.cpp
+++ b/layout/painting/nsDisplayList.cpp
@@ -5625,17 +5625,16 @@ nsDisplayBoxShadowOuter::CreateWebRender
                                                     mFrame);
 
   RectCornerRadii borderRadii;
   if (hasBorderRadius) {
     hasBorderRadius = nsCSSRendering::GetBorderRadii(frameRect,
                                                      borderRect,
                                                      mFrame,
                                                      borderRadii);
-    MOZ_ASSERT(borderRadii.AreRadiiSame());
   }
 
   // Everything here is in app units, change to device units.
   for (uint32_t i = 0; i < rects.Length(); ++i) {
     LayoutDeviceRect clipRect = LayoutDeviceRect::FromAppUnits(
         rects[i], appUnitsPerDevPixel);
     nsCSSShadowArray* shadows = mFrame->StyleEffects()->mBoxShadow;
     MOZ_ASSERT(shadows);
@@ -5658,19 +5657,27 @@ nsDisplayBoxShadowOuter::CreateWebRender
           nsPoint(shadow->mXOffset, shadow->mYOffset),
           appUnitsPerDevPixel);
 
       LayoutDeviceRect deviceBox = LayoutDeviceRect::FromAppUnits(
           shadowRect, appUnitsPerDevPixel);
       wr::LayoutRect deviceBoxRect = aSc.ToRelativeLayoutRect(deviceBox);
       wr::LayoutRect deviceClipRect = aSc.ToRelativeLayoutRect(clipRect);
 
-      // TODO: support non-uniform border radius.
-      float borderRadius = hasBorderRadius ? borderRadii.TopLeft().width
-                                           : 0.0;
+      LayoutDeviceSize zeroSize;
+      wr::BorderRadius borderRadius = wr::ToBorderRadius(zeroSize, zeroSize,
+                                                         zeroSize, zeroSize);
+      if (hasBorderRadius) {
+        borderRadius = wr::ToBorderRadius(
+          LayoutDeviceSize::FromUnknownSize(borderRadii.TopLeft()),
+          LayoutDeviceSize::FromUnknownSize(borderRadii.TopRight()),
+          LayoutDeviceSize::FromUnknownSize(borderRadii.BottomLeft()),
+          LayoutDeviceSize::FromUnknownSize(borderRadii.BottomRight()));
+      }
+
       float spreadRadius = float(shadow->mSpread) / float(appUnitsPerDevPixel);
 
       aBuilder.PushBoxShadow(deviceBoxRect,
                              deviceClipRect,
                              !BackfaceIsHidden(),
                              deviceBoxRect,
                              wr::ToLayoutVector2D(shadowOffset),
                              wr::ToColorF(shadowColor),
@@ -5830,18 +5837,22 @@ nsDisplayBoxShadowInner::CreateInsetBoxS
       wr::LayoutRect deviceClipRect = aSc.ToRelativeLayoutRect(clipRect);
       Color shadowColor = nsCSSRendering::GetShadowColor(shadowItem, aFrame, 1.0);
 
       LayoutDevicePoint shadowOffset = LayoutDevicePoint::FromAppUnits(
           nsPoint(shadowItem->mXOffset, shadowItem->mYOffset),
           appUnitsPerDevPixel);
 
       float blurRadius = float(shadowItem->mRadius) / float(appUnitsPerDevPixel);
-      // TODO: WR doesn't support non-uniform border radii
-      float borderRadius = innerRadii.TopLeft().width;
+
+      wr::BorderRadius borderRadius = wr::ToBorderRadius(
+        LayoutDeviceSize::FromUnknownSize(innerRadii.TopLeft()),
+        LayoutDeviceSize::FromUnknownSize(innerRadii.TopRight()),
+        LayoutDeviceSize::FromUnknownSize(innerRadii.BottomLeft()),
+        LayoutDeviceSize::FromUnknownSize(innerRadii.BottomRight()));
       // NOTE: Any spread radius > 0 will render nothing. WR Bug.
       float spreadRadius = float(shadowItem->mSpread) / float(appUnitsPerDevPixel);
 
       aBuilder.PushBoxShadow(wr::ToLayoutRect(deviceBoxRect),
                              deviceClipRect,
                              !aFrame->BackfaceIsHidden(),
                              wr::ToLayoutRect(deviceBoxRect),
                              wr::ToLayoutVector2D(shadowOffset),