Bug 1347469 - Add bindings for gradient border. r=kats draft
authorMorris Tseng <mtseng@mozilla.com>
Thu, 09 Mar 2017 14:17:48 +0800
changeset 554245 92b85f86cc21c9bc876f887e8e48f6935ca34ce5
parent 554244 6b6847ceb7c9137107eb43ca4b75bb66736e01b3
child 554246 71b8bd0c87f103758058b4c1c53564c01e289a41
push id51878
push userbmo:mtseng@mozilla.com
push dateFri, 31 Mar 2017 08:53:32 +0000
reviewerskats
bugs1347469
milestone55.0a1
Bug 1347469 - Add bindings for gradient border. r=kats MozReview-Commit-ID: H6OwWaeBYWY
gfx/webrender_bindings/WebRenderAPI.cpp
gfx/webrender_bindings/WebRenderAPI.h
gfx/webrender_bindings/src/bindings.rs
gfx/webrender_bindings/webrender_ffi.h
--- a/gfx/webrender_bindings/WebRenderAPI.cpp
+++ b/gfx/webrender_bindings/WebRenderAPI.cpp
@@ -579,16 +579,50 @@ DisplayListBuilder::PushBorderImage(cons
                                     const WrRepeatMode& aRepeatVertical)
 {
   wr_dp_push_border_image(mWrState, aBounds, aClip,
                           aWidths, aImage, aPatch, aOutset,
                           aRepeatHorizontal, aRepeatVertical);
 }
 
 void
+DisplayListBuilder::PushBorderGradient(const WrRect& aBounds,
+                                       const WrClipRegion& aClip,
+                                       const WrBorderWidths& aWidths,
+                                       const WrPoint& aStartPoint,
+                                       const WrPoint& aEndPoint,
+                                       const nsTArray<WrGradientStop>& aStops,
+                                       wr::GradientExtendMode aExtendMode,
+                                       const WrSideOffsets2Df32& aOutset)
+{
+  wr_dp_push_border_gradient(mWrState, aBounds, aClip,
+                             aWidths, aStartPoint, aEndPoint,
+                             aStops.Elements(), aStops.Length(),
+                             aExtendMode, aOutset);
+}
+
+void
+DisplayListBuilder::PushBorderRadialGradient(const WrRect& aBounds,
+                                             const WrClipRegion& aClip,
+                                             const WrBorderWidths& aWidths,
+                                             const WrPoint& aStartCenter,
+                                             const WrPoint& aEndCenter,
+                                             float aStartRadius,
+                                             float aEndRadius,
+                                             const nsTArray<WrGradientStop>& aStops,
+                                             wr::GradientExtendMode aExtendMode,
+                                             const WrSideOffsets2Df32& aOutset)
+{
+  wr_dp_push_border_radial_gradient(
+    mWrState, aBounds, aClip, aWidths, aStartCenter, aEndCenter,
+    aStartRadius, aEndRadius, aStops.Elements(), aStops.Length(),
+    aExtendMode, aOutset);
+}
+
+void
 DisplayListBuilder::PushText(const WrRect& aBounds,
                              const WrClipRegion& aClip,
                              const gfx::Color& aColor,
                              wr::FontKey aFontKey,
                              Range<const WrGlyphInstance> aGlyphBuffer,
                              float aGlyphSize)
 {
   wr_dp_push_text(mWrState, aBounds, aClip,
--- a/gfx/webrender_bindings/WebRenderAPI.h
+++ b/gfx/webrender_bindings/WebRenderAPI.h
@@ -195,16 +195,36 @@ public:
                        const WrClipRegion& aClip,
                        const WrBorderWidths& aWidths,
                        wr::ImageKey aImage,
                        const WrNinePatchDescriptor& aPatch,
                        const WrSideOffsets2Df32& aOutset,
                        const WrRepeatMode& aRepeatHorizontal,
                        const WrRepeatMode& aRepeatVertical);
 
+  void PushBorderGradient(const WrRect& aBounds,
+                          const WrClipRegion& aClip,
+                          const WrBorderWidths& aWidths,
+                          const WrPoint& aStartPoint,
+                          const WrPoint& aEndPoint,
+                          const nsTArray<WrGradientStop>& aStops,
+                          wr::GradientExtendMode aExtendMode,
+                          const WrSideOffsets2Df32& aOutset);
+
+  void PushBorderRadialGradient(const WrRect& aBounds,
+                                const WrClipRegion& aClip,
+                                const WrBorderWidths& aWidths,
+                                const WrPoint& aStartCenter,
+                                const WrPoint& aEndCenter,
+                                float aStartRadius,
+                                float aEndRadius,
+                                const nsTArray<WrGradientStop>& aStops,
+                                wr::GradientExtendMode aExtendMode,
+                                const WrSideOffsets2Df32& aOutset);
+
   void PushText(const WrRect& aBounds,
                 const WrClipRegion& aClip,
                 const gfx::Color& aColor,
                 wr::FontKey aFontKey,
                 Range<const WrGlyphInstance> aGlyphBuffer,
                 float aGlyphSize);
 
   void PushBoxShadow(const WrRect& aRect,
--- a/gfx/webrender_bindings/src/bindings.rs
+++ b/gfx/webrender_bindings/src/bindings.rs
@@ -6,23 +6,23 @@ use std::sync::Arc;
 use std::collections::HashMap;
 use gleam::gl;
 
 use webrender_traits::{AuxiliaryLists, AuxiliaryListsDescriptor, BorderDetails, BorderRadius};
 use webrender_traits::{BorderSide, BorderStyle, BorderWidths, BoxShadowClipMode, BuiltDisplayList};
 use webrender_traits::{BuiltDisplayListDescriptor, ClipRegion, ColorF, ComplexClipRegion};
 use webrender_traits::{DeviceUintPoint, DeviceUintRect, DeviceUintSize, Epoch, ExtendMode};
 use webrender_traits::{ExternalEvent, ExternalImageId, FilterOp, FontKey, GlyphInstance};
-use webrender_traits::{GradientStop, IdNamespace, ImageBorder, ImageData, ImageDescriptor};
+use webrender_traits::{GradientBorder, GradientStop, IdNamespace, ImageBorder, ImageData, ImageDescriptor};
 use webrender_traits::{ImageFormat, ImageKey, ImageMask, ImageRendering, ItemRange, LayerPixel};
 use webrender_traits::{LayoutPoint, LayoutRect, LayoutSize, LayoutTransform, MixBlendMode};
 use webrender_traits::{BlobImageData, BlobImageRenderer, BlobImageResult, BlobImageError};
 use webrender_traits::{BlobImageDescriptor, RasterizedBlobImage};
-use webrender_traits::{NinePatchDescriptor, NormalBorder, PipelineId, PropertyBinding, RenderApi};
-use webrender_traits::RepeatMode;
+use webrender_traits::{NinePatchDescriptor, NormalBorder, PipelineId, PropertyBinding, RadialGradientBorder};
+use webrender_traits::{RenderApi, RepeatMode};
 use webrender::renderer::{Renderer, RendererOptions};
 use webrender::renderer::{ExternalImage, ExternalImageHandler, ExternalImageSource};
 use webrender::{ApiRecordingReceiver, BinaryRecorder};
 use app_units::Au;
 use euclid::{TypedPoint2D, SideOffsets2D};
 
 extern crate webrender_traits;
 
@@ -1253,16 +1253,63 @@ pub extern "C" fn wr_dp_push_border_imag
     state.frame_builder.dl_builder.push_border(
                                     rect.to_rect(),
                                     clip.to_clip_region(),
                                     widths.to_border_widths(),
                                     border_details);
 }
 
 #[no_mangle]
+pub extern "C" fn wr_dp_push_border_gradient(state: &mut WrState, rect: WrRect, clip: WrRect,
+                                             widths: WrBorderWidths,
+                                             start_point: WrPoint, end_point: WrPoint,
+                                             stops: * const WrGradientStop, stops_count: usize,
+                                             extend_mode: WrGradientExtendMode,
+                                             outset: WrSideOffsets2D<f32>) {
+    assert!( unsafe { is_in_main_thread() });
+    let stops = WrGradientStop::to_gradient_stops(unsafe { slice::from_raw_parts(stops, stops_count) });
+    let clip_region = state.frame_builder.dl_builder.new_clip_region(&clip.to_rect(), Vec::new(), None);
+    let border_details = BorderDetails::Gradient(GradientBorder {
+        gradient: state.frame_builder.dl_builder.create_gradient(
+                      start_point.to_point(), end_point.to_point(),
+                      stops, extend_mode.to_gradient_extend_mode()),
+        outset: outset.to_side_offsets_2d(),
+    });
+    state.frame_builder.dl_builder.push_border(
+                                    rect.to_rect(),
+                                    clip_region,
+                                    widths.to_border_widths(),
+                                    border_details);
+}
+
+#[no_mangle]
+pub extern "C" fn wr_dp_push_border_radial_gradient(state: &mut WrState, rect: WrRect, clip: WrRect,
+                                                    widths: WrBorderWidths,
+                                                    start_center: WrPoint, end_center: WrPoint,
+                                                    start_radius: f32, end_radius: f32,
+                                                    stops: * const WrGradientStop, stops_count: usize,
+                                                    extend_mode: WrGradientExtendMode,
+                                                    outset: WrSideOffsets2D<f32>) {
+    assert!( unsafe { is_in_main_thread() });
+    let stops = WrGradientStop::to_gradient_stops(unsafe { slice::from_raw_parts(stops, stops_count) });
+    let clip_region = state.frame_builder.dl_builder.new_clip_region(&clip.to_rect(), Vec::new(), None);
+    let border_details = BorderDetails::RadialGradient(RadialGradientBorder {
+        gradient: state.frame_builder.dl_builder.create_radial_gradient(
+                      start_center.to_point(), start_radius, end_center.to_point(), end_radius,
+                      stops, extend_mode.to_gradient_extend_mode()),
+        outset: outset.to_side_offsets_2d(),
+    });
+    state.frame_builder.dl_builder.push_border(
+                                    rect.to_rect(),
+                                    clip_region,
+                                    widths.to_border_widths(),
+                                    border_details);
+}
+
+#[no_mangle]
 pub extern "C" fn wr_dp_push_linear_gradient(state: &mut WrState,
                                              rect: WrRect,
                                              clip: WrClipRegion,
                                              start_point: WrPoint,
                                              end_point: WrPoint,
                                              stops: *const WrGradientStop,
                                              stops_count: usize,
                                              extend_mode: WrGradientExtendMode) {
--- a/gfx/webrender_bindings/webrender_ffi.h
+++ b/gfx/webrender_bindings/webrender_ffi.h
@@ -680,16 +680,35 @@ WR_INLINE void
 wr_dp_push_border_image(WrState* wrState, WrRect bounds, WrClipRegion clip,
                         WrBorderWidths widths,
                         WrImageKey image, WrNinePatchDescriptor patch, WrSideOffsets2Df32 outset,
                         WrRepeatMode repeat_horizontal,
                         WrRepeatMode repeat_vertical)
 WR_FUNC;
 
 WR_INLINE void
+wr_dp_push_border_gradient(WrState* wrState, WrRect bounds, WrClipRegion clip,
+                           WrBorderWidths widths,
+                           WrPoint startPoint, WrPoint endPoint,
+                           const WrGradientStop* stops, size_t stopsCount,
+                           WrGradientExtendMode extendMode,
+                           WrSideOffsets2Df32 outset)
+WR_FUNC;
+
+WR_INLINE void
+wr_dp_push_border_radial_gradient(WrState* wrState, WrRect bounds, WrClipRegion clip,
+                                  WrBorderWidths widths,
+                                  WrPoint startCenter, WrPoint endCenter,
+                                  float startRadius, float endRadius,
+                                  const WrGradientStop* stops, size_t stopsCount,
+                                  WrGradientExtendMode extendMode,
+                                  WrSideOffsets2Df32 outset)
+WR_FUNC;
+
+WR_INLINE void
 wr_dp_push_linear_gradient(WrState* wrState, WrRect bounds, WrClipRegion clip,
                            WrPoint startPoint, WrPoint endPoint,
                            const WrGradientStop* stops, size_t stopsCount,
                            WrGradientExtendMode extendMode)
 WR_FUNC;
 
 WR_INLINE void
 wr_dp_push_radial_gradient(WrState* wrState, WrRect bounds, WrClipRegion clip,