Bug 1347062 - P1: add WrExternalImage binding utility function. r=nical,sotaro
authorJerryShih <hshih@mozilla.com>
Fri, 31 Mar 2017 22:29:14 +0800
changeset 555315 f9813e4134ae48d65dc30ba70b5229c3bb7b16ff
parent 555314 ae507bf1bc4498d7d05c8fb6dededed8df2a5f92
child 555316 4b54605f1dcdeb67f5678f3dc1b4e822090344ec
push id52214
push userkgupta@mozilla.com
push dateTue, 04 Apr 2017 02:58:29 +0000
reviewersnical, sotaro
bugs1347062
milestone55.0a1
Bug 1347062 - P1: add WrExternalImage binding utility function. r=nical,sotaro MozReview-Commit-ID: 4oJvybXRuTX
gfx/webrender_bindings/RendererOGL.cpp
gfx/webrender_bindings/WebRenderTypes.h
gfx/webrender_bindings/src/bindings.rs
gfx/webrender_bindings/webrender_ffi.h
--- a/gfx/webrender_bindings/RendererOGL.cpp
+++ b/gfx/webrender_bindings/RendererOGL.cpp
@@ -16,18 +16,18 @@ namespace mozilla {
 namespace wr {
 
 WrExternalImage LockExternalImage(void* aObj, WrExternalImageId aId)
 {
   RendererOGL* renderer = reinterpret_cast<RendererOGL*>(aObj);
   RenderTextureHost* texture = renderer->GetRenderTexture(aId.id);
   MOZ_ASSERT(texture);
   texture->Lock();
-  return WrExternalImage { WrExternalImageIdType::RawData, 0.0f, 0.0f, 0.0f, 0.0f, 0,
-                           texture->GetDataForRender(), texture->GetBufferSizeForRender() };
+
+  return RawDataToWrExternalImage(texture->GetDataForRender(), texture->GetBufferSizeForRender());
 }
 
 void UnlockExternalImage(void* aObj, WrExternalImageId aId)
 {
   RendererOGL* renderer = reinterpret_cast<RendererOGL*>(aObj);
   RenderTextureHost* texture = renderer->GetRenderTexture(aId.id);
   MOZ_ASSERT(texture);
   texture->Unlock();
--- a/gfx/webrender_bindings/WebRenderTypes.h
+++ b/gfx/webrender_bindings/WebRenderTypes.h
@@ -345,16 +345,37 @@ static inline WrComplexClipRegion ToWrCo
 
 static inline WrExternalImageId ToWrExternalImageId(uint64_t aID)
 {
   WrExternalImageId id;
   id.id = aID;
   return id;
 }
 
+static inline WrExternalImage RawDataToWrExternalImage(const uint8_t* aBuff,
+                                                       size_t size)
+{
+  return WrExternalImage {
+    WrExternalImageIdType::RawData,
+    0, 0.0f, 0.0f, 0.0f, 0.0f,
+    aBuff, size
+  };
+}
+
+static inline WrExternalImage NativeTextureToWrExternalImage(uint8_t aHandle,
+                                                             float u0, float v0,
+                                                             float u1, float v1)
+{
+  return WrExternalImage {
+    WrExternalImageIdType::NativeTexture,
+    aHandle, u0, v0, u1, v1,
+    nullptr, 0
+  };
+}
+
 struct VecU8 {
   WrVecU8 inner;
   VecU8() {
     inner.data = nullptr;
     inner.capacity = 0;
   }
   VecU8(VecU8&) = delete;
   VecU8(VecU8&& src) {
--- a/gfx/webrender_bindings/src/bindings.rs
+++ b/gfx/webrender_bindings/src/bindings.rs
@@ -429,26 +429,25 @@ enum WrExternalImageType {
     NativeTexture,
     RawData,
 }
 
 #[repr(C)]
 struct WrExternalImageStruct {
     image_type: WrExternalImageType,
 
-    // Texture coordinate
+    // external texture handle
+    handle: u32,
+    // external texture coordinate
     u0: f32,
     v0: f32,
     u1: f32,
     v1: f32,
 
-    // external buffer handle
-    handle: u32,
-
-    // handle RawData.
+    // external image buffer
     buff: *const u8,
     size: usize,
 }
 
 type LockExternalImageCallback = fn(*mut c_void, ExternalImageId) -> WrExternalImageStruct;
 type UnlockExternalImageCallback = fn(*mut c_void, ExternalImageId);
 type ReleaseExternalImageCallback = fn(*mut c_void, ExternalImageId);
 
--- a/gfx/webrender_bindings/webrender_ffi.h
+++ b/gfx/webrender_bindings/webrender_ffi.h
@@ -408,25 +408,24 @@ struct WrExternalImageId
 {
   WrImageIdType id;
 };
 
 struct WrExternalImage
 {
   WrExternalImageIdType type;
 
-  // Texture coordinate
+  // external texture handle
+  uint32_t handle;
+  // external texture coordinate
   float u0, v0;
   float u1, v1;
 
-  // external buffer handle
-  uint32_t handle;
-
-  // handle RawData.
-  uint8_t* buff;
+  // external image buffer
+  const uint8_t* buff;
   size_t size;
 };
 
 typedef WrExternalImage (*LockExternalImageCallback)(void*, WrExternalImageId);
 typedef void (*UnlockExternalImageCallback)(void*, WrExternalImageId);
 typedef void (*ReleaseExternalImageCallback)(void*, WrExternalImageId);
 
 struct WrExternalImageHandler