Bug 1347062 - P5: use texture handle directly with webrender. r=nical,sotaro
authorJerryShih <hshih@mozilla.com>
Fri, 31 Mar 2017 22:29:15 +0800
changeset 555319 34976aba2753770c95f045a7bbd7b6b9389c6dbd
parent 555318 66e555be3167455e8f99ef8678b320d53d94c9d6
child 555320 d71e6ed7d1b8edb03647f4f323e9943ead7af69c
push id52214
push userkgupta@mozilla.com
push dateTue, 04 Apr 2017 02:58:29 +0000
reviewersnical, sotaro
bugs1347062
milestone55.0a1
Bug 1347062 - P5: use texture handle directly with webrender. r=nical,sotaro MozReview-Commit-ID: 1XLiFcpFEeu
gfx/layers/wr/WebRenderBridgeParent.cpp
gfx/webrender_bindings/RendererOGL.cpp
gfx/webrender_bindings/WebRenderTypes.h
--- a/gfx/layers/wr/WebRenderBridgeParent.cpp
+++ b/gfx/layers/wr/WebRenderBridgeParent.cpp
@@ -339,25 +339,37 @@ WebRenderBridgeParent::ProcessWebRenderC
         // XXX select Texture for video in CompositeToTarget().
         TextureHost* texture = host->GetAsTextureHost();
         if (!texture) {
           NS_ERROR("TextureHost does not exist");
           break;
         }
         WebRenderTextureHost* wrTexture = texture->AsWebRenderTextureHost();
         if (wrTexture) {
-          // XXX handling YUV
-          gfx::SurfaceFormat format =
-            wrTexture->GetFormat() == SurfaceFormat::YUV ? SurfaceFormat::B8G8R8A8 : wrTexture->GetFormat();
-          wr::ImageDescriptor descriptor(wrTexture->GetSize(), wrTexture->GetRGBStride(), format);
-          mApi->AddExternalImageBuffer(key,
-                                       descriptor,
-                                       wrTexture->GetExternalImageKey());
-          mCompositableHolder->HoldExternalImage(mPipelineId, aEpoch, texture->AsWebRenderTextureHost());
-          keysToDelete.push_back(key);
+          if (wrTexture->IsWrappingNativeHandle()) {
+            // XXX only for MacIOSurface right now.
+            // XXX remove the redundant codes for both native handle and yuv case.
+            wr::ImageDescriptor descriptor(wrTexture->GetSize(), wrTexture->GetReadFormat());
+            mApi->AddExternalImageHandle(key,
+                                         descriptor,
+                                         wrTexture->GetExternalImageKey());
+            mCompositableHolder->HoldExternalImage(mPipelineId, aEpoch, texture->AsWebRenderTextureHost());
+            keysToDelete.push_back(key);
+          } else {
+            // XXX handling YUV
+            gfx::SurfaceFormat format =
+              wrTexture->GetFormat() == SurfaceFormat::YUV ? SurfaceFormat::B8G8R8A8 : wrTexture->GetFormat();
+            wr::ImageDescriptor descriptor(wrTexture->GetSize(), wrTexture->GetRGBStride(), format);
+            mApi->AddExternalImageBuffer(key,
+                                         descriptor,
+                                         wrTexture->GetExternalImageKey());
+            mCompositableHolder->HoldExternalImage(mPipelineId, aEpoch, texture->AsWebRenderTextureHost());
+            keysToDelete.push_back(key);
+          }
+
           break;
         }
         RefPtr<DataSourceSurface> dSurf = host->GetAsSurface();
         if (!dSurf) {
           break;
         }
 
         DataSourceSurface::MappedSurface map;
--- a/gfx/webrender_bindings/RendererOGL.cpp
+++ b/gfx/webrender_bindings/RendererOGL.cpp
@@ -4,30 +4,47 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "RendererOGL.h"
 #include "GLContext.h"
 #include "GLContextProvider.h"
 #include "mozilla/gfx/Logging.h"
 #include "mozilla/layers/CompositorBridgeParent.h"
 #include "mozilla/layers/CompositorThread.h"
-#include "mozilla/webrender/RenderTextureHost.h"
+#include "mozilla/webrender/RenderBufferTextureHost.h"
+#include "mozilla/webrender/RenderTextureHostOGL.h"
 #include "mozilla/widget/CompositorWidget.h"
 
 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();
+
+  if (texture->AsBufferTextureHost()) {
+    RenderBufferTextureHost* bufferTexture = texture->AsBufferTextureHost();
+    MOZ_ASSERT(bufferTexture);
+    bufferTexture->Lock();
 
-  return RawDataToWrExternalImage(texture->GetDataForRender(), texture->GetBufferSizeForRender());
+    return RawDataToWrExternalImage(bufferTexture->GetDataForRender(),
+                                    bufferTexture->GetBufferSizeForRender());
+  } else {
+    // texture handle case
+    RenderTextureHostOGL* textureOGL = texture->AsTextureHostOGL();
+    MOZ_ASSERT(textureOGL);
+    gfx::IntSize size = textureOGL->GetSize();
+    textureOGL->SetGLContext(renderer->mGL);
+    textureOGL->Lock();
+
+    return NativeTextureToWrExternalImage(textureOGL->GetGLHandle(),
+                                          0, 0,
+                                          size.width, size.height);
+  }
 }
 
 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
@@ -39,16 +39,19 @@ inline Epoch NewEpoch(uint32_t aEpoch) {
   Epoch e;
   e.mHandle = aEpoch;
   return e;
 }
 
 inline Maybe<WrImageFormat>
 SurfaceFormatToWrImageFormat(gfx::SurfaceFormat aFormat) {
   switch (aFormat) {
+    case gfx::SurfaceFormat::R8G8B8X8:
+      // TODO: use RGBA + opaque flag
+      return Some(WrImageFormat::RGBA8);
     case gfx::SurfaceFormat::B8G8R8X8:
       // TODO: WebRender will have a BGRA + opaque flag for this but does not
       // have it yet (cf. issue #732).
     case gfx::SurfaceFormat::B8G8R8A8:
       return Some(WrImageFormat::RGBA8);
     case gfx::SurfaceFormat::B8G8R8:
       return Some(WrImageFormat::RGB8);
     case gfx::SurfaceFormat::A8: