Bug 1343457 - Update external image adding api r=kats
authorsotaro <sotaro.ikeda.g@gmail.com>
Thu, 02 Mar 2017 10:22:40 +0900
changeset 345793 9503f5f64ba0a99e38f6cb16df350805f770945d
parent 345792 9059ef02d91ba49bb3cf3b9cdd4c92bc99a4d4b0
child 345794 6422bc2ab9747390455a1b8a63f34c8965282ff9
push id31446
push userkwierso@gmail.com
push dateFri, 03 Mar 2017 19:24:21 +0000
treeherdermozilla-central@942165e408f0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats
bugs1343457
milestone54.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 1343457 - Update external image adding api r=kats
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
@@ -242,25 +242,40 @@ WebRenderAPI::AddImage(ImageKey key, con
                        Range<uint8_t> aBytes)
 {
   wr_api_add_image(mWrApi,
                    key,
                    &aDescritptor,
                    &aBytes[0], aBytes.length());
 }
 
-ImageKey
-WebRenderAPI::AddExternalImageHandle(gfx::IntSize aSize,
+void
+WebRenderAPI::AddExternalImageHandle(ImageKey key,
+                                     gfx::IntSize aSize,
                                      gfx::SurfaceFormat aFormat,
                                      uint64_t aHandle)
 {
   auto format = SurfaceFormatToWrImageFormat(aFormat).value();
-  return ImageKey(wr_api_add_external_image_texture(mWrApi,
-                                                    aSize.width, aSize.height, format,
-                                                    aHandle));
+  wr_api_add_external_image_handle(mWrApi,
+                                   key,
+                                   aSize.width, aSize.height, format,
+                                   aHandle);
+}
+
+void
+WebRenderAPI::AddExternalImageBuffer(ImageKey key,
+                                     gfx::IntSize aSize,
+                                     gfx::SurfaceFormat aFormat,
+                                     uint64_t aHandle)
+{
+  auto format = SurfaceFormatToWrImageFormat(aFormat).value();
+  wr_api_add_external_image_buffer(mWrApi,
+                                   key,
+                                   aSize.width, aSize.height, format,
+                                   aHandle);
 }
 
 void
 WebRenderAPI::UpdateImageBuffer(ImageKey aKey,
                                 const ImageDescriptor& aDescritptor,
                                 Range<uint8_t> aBytes)
 {
   wr_api_update_image(mWrApi,
--- a/gfx/webrender_bindings/WebRenderAPI.h
+++ b/gfx/webrender_bindings/WebRenderAPI.h
@@ -57,19 +57,25 @@ public:
                           size_t aux_size);
 
   void SetRootPipeline(wr::PipelineId aPipeline);
 
   void AddImage(wr::ImageKey aKey,
                 const ImageDescriptor& aDescriptor,
                 Range<uint8_t> aBytes);
 
-  wr::ImageKey AddExternalImageHandle(gfx::IntSize aSize,
-                                      gfx::SurfaceFormat aFormat,
-                                      uint64_t aHandle);
+  void AddExternalImageHandle(ImageKey key,
+                              gfx::IntSize aSize,
+                              gfx::SurfaceFormat aFormat,
+                              uint64_t aHandle);
+
+  void AddExternalImageBuffer(ImageKey key,
+                              gfx::IntSize aSize,
+                              gfx::SurfaceFormat aFormat,
+                              uint64_t aHandle);
 
   void UpdateImageBuffer(wr::ImageKey aKey,
                          const ImageDescriptor& aDescriptor,
                          Range<uint8_t> aBytes);
 
   void DeleteImage(wr::ImageKey aKey);
 
   void AddRawFont(wr::FontKey aKey, Range<uint8_t> aBytes);
--- a/gfx/webrender_bindings/src/bindings.rs
+++ b/gfx/webrender_bindings/src/bindings.rs
@@ -677,20 +677,33 @@ pub extern fn wr_api_add_image(api: &mut
         image_key,
         descriptor.to_descriptor(),
         ImageData::new(bytes),
         None
     );
 }
 
 #[no_mangle]
-pub extern fn wr_api_add_external_image_texture(api: &mut RenderApi, width: u32, height: u32, format: ImageFormat, external_image_id: u64) -> ImageKey {
+pub extern fn wr_api_add_external_image_handle(api: &mut RenderApi, image_key: ImageKey, width: u32, height: u32, format: ImageFormat, external_image_id: u64) {
     assert!( unsafe { is_in_compositor_thread() });
-    unimplemented!(); // TODO
-    //api.add_image(ImageDescriptor{width:width, height:height, stride:None, format: format, is_opaque: false}, ImageData::External(ExternalImageId(external_image_id)))
+    api.add_image(image_key,
+                  ImageDescriptor{width:width, height:height, stride:None, format: format, is_opaque: false, offset: 0},
+                  ImageData::ExternalHandle(ExternalImageId(external_image_id)),
+                  None
+    );
+}
+
+#[no_mangle]
+pub extern fn wr_api_add_external_image_buffer(api: &mut RenderApi, image_key: ImageKey, width: u32, height: u32, format: ImageFormat, external_image_id: u64) {
+    assert!( unsafe { is_in_compositor_thread() });
+    api.add_image(image_key,
+                  ImageDescriptor{width:width, height:height, stride:None, format: format, is_opaque: false, offset: 0},
+                  ImageData::ExternalBuffer(ExternalImageId(external_image_id)),
+                  None
+    );
 }
 
 #[no_mangle]
 pub extern fn wr_api_update_image(api: &mut RenderApi, key: ImageKey, descriptor: &WrImageDescriptor, bytes: * const u8, size: usize) {
     assert!( unsafe { is_in_compositor_thread() });
     let bytes = unsafe { slice::from_raw_parts(bytes, size).to_owned() };
 
     api.update_image(
--- a/gfx/webrender_bindings/webrender_ffi.h
+++ b/gfx/webrender_bindings/webrender_ffi.h
@@ -433,26 +433,25 @@ WR_FUNC;
 WR_INLINE void
 wr_api_delete(WrAPI* api)
 WR_DESTRUCTOR_SAFE_FUNC;
 
 WR_INLINE void
 wr_api_add_image(WrAPI* api, WrImageKey key, const WrImageDescriptor* descriptor, uint8_t *buffer, size_t buffer_size)
 WR_FUNC;
 
-WR_INLINE WrImageKey
-wr_api_add_external_image_texture(WrAPI* api, uint32_t width, uint32_t height,
-                                  WrImageFormat format, uint64_t external_image_id)
+WR_INLINE void
+wr_api_add_external_image_handle(WrAPI* api, WrImageKey key, uint32_t width, uint32_t height,
+                                 WrImageFormat format, uint64_t external_image_id)
 WR_FUNC;
 
-//TODO(Jerry): handle shmem in WR
-//// WR_INLINE WrImageKey
-//// wr_api_add_external_image_buffer(WrAPI* api, uint32_t width, uint32_t height, uint32_t stride,
-////                                  WrImageFormat format, uint8_t *bytes, size_t size)
-//// WR_FUNC;
+WR_INLINE void
+wr_api_add_external_image_buffer(WrAPI* api, WrImageKey key, uint32_t width, uint32_t height,
+                                 WrImageFormat format, uint64_t external_image_id)
+WR_FUNC;
 
 WR_INLINE void
 wr_api_update_image(WrAPI* api, WrImageKey key,
                     const WrImageDescriptor* descriptor,
                     uint8_t *bytes, size_t size)
 WR_FUNC;
 
 WR_INLINE void