Bug 1360435 - Update WR bindings for b9f7e2926731f0ed831108456c219cae30a7e4c8. r=kats
authorJerryShih <hshih@mozilla.com>
Fri, 28 Apr 2017 17:00:57 -0400
changeset 357009 14b78eff0a909fa6906dbb0f5ac57271c8761987
parent 357008 efda56c9cb287fcb1bde6f08635779b94333be70
child 357010 647d9f960b055285ea19797ea56d9e6ecd7c48ea
push id31780
push userkwierso@gmail.com
push dateMon, 08 May 2017 20:34:47 +0000
treeherdermozilla-central@bab7046ee2d8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats
bugs1360435
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 1360435 - Update WR bindings for b9f7e2926731f0ed831108456c219cae30a7e4c8. r=kats Update for blob image and yuv image interface changes. The implementation of the blob image renderer is empty now. It will need to be updated in another commit. This also adds wr_dp_push_yuv_*_image() functions in WebRenderAPI. There is no change for |./mach vendor rust|. MozReview-Commit-ID: Kk2rPAmt3vF
gfx/webrender_bindings/WebRenderAPI.cpp
gfx/webrender_bindings/WebRenderAPI.h
gfx/webrender_bindings/src/bindings.rs
gfx/webrender_bindings/webrender_ffi_generated.h
--- a/gfx/webrender_bindings/WebRenderAPI.cpp
+++ b/gfx/webrender_bindings/WebRenderAPI.cpp
@@ -669,16 +669,48 @@ DisplayListBuilder::PushImage(const WrRe
                               const WrSize& aTileSpacing,
                               wr::ImageRendering aFilter,
                               wr::ImageKey aImage)
 {
   wr_dp_push_image(mWrState, aBounds, aClip, aStretchSize, aTileSpacing, aFilter, aImage);
 }
 
 void
+DisplayListBuilder::PushYCbCrPlanarImage(const WrRect& aBounds,
+                                         const WrClipRegion& aClip,
+                                         wr::ImageKey aImageChannel0,
+                                         wr::ImageKey aImageChannel1,
+                                         wr::ImageKey aImageChannel2,
+                                         WrYuvColorSpace aColorSpace)
+{
+  wr_dp_push_yuv_planar_image(mWrState,
+                              aBounds,
+                              aClip,
+                              aImageChannel0,
+                              aImageChannel1,
+                              aImageChannel2,
+                              aColorSpace);
+}
+
+void
+DisplayListBuilder::PushNV12Image(const WrRect& aBounds,
+                                  const WrClipRegion& aClip,
+                                  wr::ImageKey aImageChannel0,
+                                  wr::ImageKey aImageChannel1,
+                                  WrYuvColorSpace aColorSpace)
+{
+  wr_dp_push_yuv_NV12_image(mWrState,
+                            aBounds,
+                            aClip,
+                            aImageChannel0,
+                            aImageChannel1,
+                            aColorSpace);
+}
+
+void
 DisplayListBuilder::PushIFrame(const WrRect& aBounds,
                                const WrClipRegion& aClip,
                                PipelineId aPipeline)
 {
   wr_dp_push_iframe(mWrState, aBounds, aClip, aPipeline);
 }
 
 void
--- a/gfx/webrender_bindings/WebRenderAPI.h
+++ b/gfx/webrender_bindings/WebRenderAPI.h
@@ -192,16 +192,29 @@ public:
 
   void PushImage(const WrRect& aBounds,
                  const WrClipRegion& aClip,
                  const WrSize& aStretchSize,
                  const WrSize& aTileSpacing,
                  wr::ImageRendering aFilter,
                  wr::ImageKey aImage);
 
+  void PushYCbCrPlanarImage(const WrRect& aBounds,
+                            const WrClipRegion& aClip,
+                            wr::ImageKey aImageChannel0,
+                            wr::ImageKey aImageChannel1,
+                            wr::ImageKey aImageChannel2,
+                            WrYuvColorSpace aColorSpace);
+
+  void PushNV12Image(const WrRect& aBounds,
+                     const WrClipRegion& aClip,
+                     wr::ImageKey aImageChannel0,
+                     wr::ImageKey aImageChannel1,
+                     WrYuvColorSpace aColorSpace);
+
   void PushIFrame(const WrRect& aBounds,
                   const WrClipRegion& aClip,
                   wr::PipelineId aPipeline);
 
   void PushBorder(const WrRect& aBounds,
                   const WrClipRegion& aClip,
                   const WrBorderWidths& aWidths,
                   const WrBorderSide& aTop,
--- a/gfx/webrender_bindings/src/bindings.rs
+++ b/gfx/webrender_bindings/src/bindings.rs
@@ -1,13 +1,12 @@
 use std::ffi::CString;
 use std::{mem, slice};
 use std::path::PathBuf;
 use std::os::raw::{c_void, c_char};
-use std::sync::Arc;
 use std::collections::HashMap;
 use gleam::gl;
 
 use webrender_traits::*;
 use webrender::renderer::{Renderer, RendererOptions};
 use webrender::renderer::{ExternalImage, ExternalImageHandler, ExternalImageSource};
 use webrender::{ApiRecordingReceiver, BinaryRecorder};
 use app_units::Au;
@@ -1335,39 +1334,50 @@ pub extern "C" fn wr_dp_push_image(state
          .push_image(bounds.into(),
                      clip.into(),
                      stretch_size.into(),
                      tile_spacing.into(),
                      image_rendering,
                      key);
 }
 
+/// Push a 3 planar yuv image.
 #[no_mangle]
-pub extern "C" fn wr_dp_push_yuv_image(state: &mut WrState,
-                                       bounds: WrRect,
-                                       clip: WrClipRegion,
-                                       image_keys: *const WrImageKey,
-                                       key_num: u8,
-                                       color_space: WrYuvColorSpace) {
+pub extern "C" fn wr_dp_push_yuv_planar_image(state: &mut WrState,
+                                              bounds: WrRect,
+                                              clip: WrClipRegion,
+                                              image_key_0: WrImageKey,
+                                              image_key_1: WrImageKey,
+                                              image_key_2: WrImageKey,
+                                              color_space: WrYuvColorSpace) {
     assert!(unsafe { is_in_main_thread() });
-    assert!(key_num == 3);
-    unsafe {
-        for key_index in 0..key_num {
-            assert!(!image_keys.offset(key_index as isize).is_null());
-        }
-    }
-    let key_slice = make_slice(image_keys, key_num as usize);
 
     state.frame_builder
          .dl_builder
          .push_yuv_image(bounds.into(),
                          clip.into(),
-                         key_slice[0],
-                         key_slice[1],
-                         key_slice[2],
+                         YuvData::PlanarYCbCr(image_key_0, image_key_1, image_key_2),
+                         color_space);
+}
+
+/// PUsh a 2 planar NV12 image.
+#[no_mangle]
+pub extern "C" fn wr_dp_push_yuv_NV12_image(state: &mut WrState,
+                                            bounds: WrRect,
+                                            clip: WrClipRegion,
+                                            image_key_0: WrImageKey,
+                                            image_key_1: WrImageKey,
+                                            color_space: WrYuvColorSpace) {
+    assert!(unsafe { is_in_main_thread() });
+
+    state.frame_builder
+         .dl_builder
+         .push_yuv_image(bounds.into(),
+                         clip.into(),
+                         YuvData::NV12(image_key_0, image_key_1),
                          color_space);
 }
 
 #[no_mangle]
 pub extern "C" fn wr_dp_push_text(state: &mut WrState,
                                   bounds: WrRect,
                                   clip: WrClipRegion,
                                   color: WrColor,
@@ -1621,73 +1631,58 @@ pub unsafe extern "C" fn wr_dp_push_buil
 
     let dl = BuiltDisplayList::from_data(dl_vec, dl_descriptor);
     let aux = AuxiliaryLists::from_data(aux_vec, aux_descriptor);
 
     state.frame_builder.dl_builder.push_built_display_list(dl, aux);
 }
 
 struct Moz2dImageRenderer {
-    images: HashMap<WrImageKey, BlobImageResult>,
+    _images: HashMap<WrImageKey, BlobImageResult>,
 }
 
 impl BlobImageRenderer for Moz2dImageRenderer {
-    fn request_blob_image(&mut self,
-                          key: WrImageKey,
-                          data: Arc<BlobImageData>,
-                          descriptor: &BlobImageDescriptor,
-                          _dirty_rect: Option<DeviceUintRect>) {
-        let result = self.render_blob_image(data, descriptor);
-        self.images.insert(key, result);
+    fn add(&mut self, _key: ImageKey, _data: BlobImageData, _tiling: Option<TileSize>) {
+        // Not implemented yet.
+    }
+
+    fn update(&mut self, _key: ImageKey, _data: BlobImageData) {
+        // Not implemented yet.
+    }
+
+    fn delete(&mut self, _key: ImageKey) {
+        // Not implemented yet.
     }
 
-    fn resolve_blob_image(&mut self,
-                          key: WrImageKey)
-                          -> BlobImageResult {
-        return match self.images.remove(&key) {
-                   Some(result) => result,
-                   None => Err(BlobImageError::InvalidKey),
-               };
+    fn request(&mut self,
+               _key: BlobImageRequest,
+               _descriptor: &BlobImageDescriptor,
+               _dirty_rect: Option<DeviceUintRect>,
+               _images: &ImageStore) {
+        // Not implemented yet.
+    }
+
+    fn resolve(&mut self, _key: BlobImageRequest) -> BlobImageResult {
+        // Not implemented yet.
+        Err(BlobImageError::Other("unimplemented!".to_string()))
     }
 }
 
 impl Moz2dImageRenderer {
     fn new() -> Self {
         Moz2dImageRenderer {
-            images: HashMap::new(),
+            _images: HashMap::new(),
         }
     }
-
-    fn render_blob_image(&mut self,
-                         data: Arc<BlobImageData>,
-                         descriptor: &BlobImageDescriptor)
-                         -> BlobImageResult {
-        let mut output = Vec::with_capacity((descriptor.width * descriptor.height *
-                                             descriptor.format.bytes_per_pixel().unwrap()) as
-                                            usize);
-
-        unsafe {
-            if wr_moz2d_render_cb(WrByteSlice::new(&data[..]),
-                                  descriptor.width,
-                                  descriptor.height,
-                                  descriptor.format,
-                                  MutByteSlice::new(output.as_mut_slice())) {
-                return Ok(RasterizedBlobImage {
-                              width: descriptor.width,
-                              height: descriptor.height,
-                              data: output,
-                          });
-            }
-        }
-
-        Err(BlobImageError::Other("unimplemented!".to_string()))
-    }
 }
 
-extern "C" {
-    // TODO: figure out the API for tiled blob images.
-    fn wr_moz2d_render_cb(blob: WrByteSlice,
-                          width: u32,
-                          height: u32,
-                          format: WrImageFormat,
-                          output: MutByteSlice)
-                          -> bool;
-}
+// TODO: nical
+// Update for the new blob image interface changes.
+//
+// extern "C" {
+//     // TODO: figure out the API for tiled blob images.
+//     fn wr_moz2d_render_cb(blob: WrByteSlice,
+//                           width: u32,
+//                           height: u32,
+//                           format: WrImageFormat,
+//                           output: MutByteSlice)
+//                           -> bool;
+// }
--- a/gfx/webrender_bindings/webrender_ffi_generated.h
+++ b/gfx/webrender_bindings/webrender_ffi_generated.h
@@ -90,18 +90,18 @@ enum class WrRepeatMode : uint32_t {
   Repeat = 1,
   Round = 2,
   Space = 3,
 
   Sentinel /* this must be last for serialization purposes. */
 };
 
 enum class WrYuvColorSpace : uint32_t {
-  Rec601 = 1,
-  Rec709 = 2,
+  Rec601 = 0,
+  Rec709 = 1,
 
   Sentinel /* this must be last for serialization purposes. */
 };
 
 struct WrAPI;
 
 struct WrImageKey {
   uint32_t mNamespace;
@@ -808,21 +808,31 @@ wr_dp_push_text(WrState* state,
     WrColor color,
     WrFontKey font_key,
     const WrGlyphInstance* glyphs,
     uint32_t glyph_count,
     float glyph_size)
 WR_FUNC;
 
 WR_INLINE void
-wr_dp_push_yuv_image(WrState* state,
+wr_dp_push_yuv_NV12_image(WrState* state,
     WrRect bounds,
     WrClipRegion clip,
-    const WrImageKey* image_keys,
-    uint8_t key_num,
+    WrImageKey image_key_0,
+    WrImageKey image_key_1,
+    WrYuvColorSpace color_space)
+WR_FUNC;
+
+WR_INLINE void
+wr_dp_push_yuv_planar_image(WrState* state,
+    WrRect bounds,
+    WrClipRegion clip,
+    WrImageKey image_key_0,
+    WrImageKey image_key_1,
+    WrImageKey image_key_2,
     WrYuvColorSpace color_space)
 WR_FUNC;
 
 WR_INLINE void
 wr_rendered_epochs_delete(WrRenderedEpochs* pipeline_epochs)
 WR_DESTRUCTOR_SAFE_FUNC;
 
 WR_INLINE bool