Bug 1362049 - The BufferTextureHost::AddWRImage() and MacIOSurfaceTextureHostOGL::AddWRImage() implementations. v3. r=nical
authorJerryShih <hshih@mozilla.com>
Thu, 18 May 2017 22:59:07 +0800
changeset 359342 f7cb82a21940b531024684266e4657c18410b6d4
parent 359341 5828e739a454b13b0cb1cdcac6d80b5f55c0e91e
child 359343 c74b9d026772b929b60ebc9faf241ed72b83f40d
push id31852
push userkwierso@gmail.com
push dateFri, 19 May 2017 21:47:27 +0000
treeherdermozilla-central@979f11deabd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnical
bugs1362049
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 1362049 - The BufferTextureHost::AddWRImage() and MacIOSurfaceTextureHostOGL::AddWRImage() implementations. v3. r=nical MozReview-Commit-ID: JJlqFwidliQ
gfx/layers/composite/TextureHost.cpp
gfx/layers/opengl/MacIOSurfaceTextureHostOGL.cpp
--- a/gfx/layers/composite/TextureHost.cpp
+++ b/gfx/layers/composite/TextureHost.cpp
@@ -556,17 +556,35 @@ BufferTextureHost::Unlock()
   mLocked = false;
 }
 
 void
 BufferTextureHost::AddWRImage(wr::WebRenderAPI* aAPI,
                               const wr::ImageKey& aImageKey,
                               const wr::ExternalImageId& aExtID)
 {
-  MOZ_ASSERT_UNREACHABLE("No AddWRImage() implementation for this BufferTextureHost type.");
+  // XXX handling YUV
+  gfx::SurfaceFormat wrFormat =
+      (GetFormat() == gfx::SurfaceFormat::YUV) ? gfx::SurfaceFormat::B8G8R8A8
+                                               : GetFormat();
+  gfx::SurfaceFormat format = GetFormat();
+  uint32_t wrStride = 0;
+
+  if (format == gfx::SurfaceFormat::YUV) {
+    // XXX this stride is used until yuv image rendering by webrender is used.
+    // Software converted RGB buffers strides are aliened to 16
+    wrStride = gfx::GetAlignedStride<16>(GetSize().width, BytesPerPixel(gfx::SurfaceFormat::B8G8R8A8));
+  } else {
+    wrStride = ImageDataSerializer::ComputeRGBStride(format, GetSize().width);
+  }
+
+  wr::ImageDescriptor descriptor(GetSize(), wrStride, wrFormat);
+  aAPI->AddExternalImageBuffer(aImageKey,
+                               descriptor,
+                               aExtID);
 }
 
 void
 TextureHost::DeserializeReadLock(const ReadLockDescriptor& aDesc,
                                  ISurfaceAllocator* aAllocator)
 {
   RefPtr<TextureReadLock> lock = TextureReadLock::Deserialize(aDesc, aAllocator);
   if (!lock) {
--- a/gfx/layers/opengl/MacIOSurfaceTextureHostOGL.cpp
+++ b/gfx/layers/opengl/MacIOSurfaceTextureHostOGL.cpp
@@ -114,13 +114,62 @@ MacIOSurfaceTextureHostOGL::gl() const
   return mProvider ? mProvider->GetGLContext() : nullptr;
 }
 
 void
 MacIOSurfaceTextureHostOGL::AddWRImage(wr::WebRenderAPI* aAPI,
                                        const wr::ImageKey& aImageKey,
                                        const wr::ExternalImageId& aExtID)
 {
-  MOZ_ASSERT_UNREACHABLE("No AddWRImage() implementation for this MacIOSurfaceTextureHostOGL type.");
+  MOZ_ASSERT(mSurface);
+
+  switch (GetFormat()) {
+    case gfx::SurfaceFormat::R8G8B8X8:
+    case gfx::SurfaceFormat::R8G8B8A8: {
+      MOZ_ASSERT(mSurface->GetPlaneCount() == 0);
+      wr::ImageDescriptor descriptor(GetSize(), GetFormat());
+      aAPI->AddExternalImage(aImageKey,
+                             descriptor,
+                             aExtID,
+                             WrExternalImageBufferType::TextureRectHandle,
+                             0);
+      break;
+    }
+    case gfx::SurfaceFormat::YUV422: {
+      // This is the special buffer format. The buffer contents could be a
+      // converted RGB interleaving data or a YCbCr interleaving data depending
+      // on the different platform setting. (e.g. It will be RGB at OpenGL 2.1
+      // and YCbCr at OpenGL 3.1)
+      MOZ_ASSERT(mSurface->GetPlaneCount() == 0);
+      wr::ImageDescriptor descriptor(GetSize(), gfx::SurfaceFormat::R8G8B8X8);
+      aAPI->AddExternalImage(aImageKey,
+                             descriptor,
+                             aExtID,
+                             WrExternalImageBufferType::TextureRectHandle,
+                             0);
+      break;
+    }
+    case gfx::SurfaceFormat::NV12: {
+      MOZ_ASSERT(mSurface->GetPlaneCount() == 2);
+      wr::ImageDescriptor descriptor0(gfx::IntSize(mSurface->GetDevicePixelWidth(0), mSurface->GetDevicePixelHeight(0)),
+                                      gfx::SurfaceFormat::A8);
+      wr::ImageDescriptor descriptor1(gfx::IntSize(mSurface->GetDevicePixelWidth(1), mSurface->GetDevicePixelHeight(1)),
+                                      gfx::SurfaceFormat::R8G8);
+      aAPI->AddExternalImage(aImageKey,
+                             descriptor0,
+                             aExtID,
+                             WrExternalImageBufferType::TextureRectHandle,
+                             0);
+      aAPI->AddExternalImage(aImageKey,
+                             descriptor1,
+                             aExtID,
+                             WrExternalImageBufferType::TextureRectHandle,
+                             1);
+      break;
+    }
+    default: {
+      MOZ_ASSERT_UNREACHABLE("unexpected to be called");
+    }
+  }
 }
 
 } // namespace layers
 } // namespace mozilla