Bug 1061525 - Part 2: Make MacIOSurfaceTextureHostOGL understand planar MacIOSurfaces. r=jrmuizel
☠☠ backed out by 5ddf7484b5ea ☠ ☠
authorMatt Woodrow <mwoodrow@mozilla.com>
Mon, 03 Aug 2015 17:57:26 -0400
changeset 287648 fae6602192a7e4881246f84b7f7a6f9a69088aeb
parent 287647 5dfbd6e73c7afe11aea5e842100373c9fdf8fc1e
child 287649 b48d13edb48d7cdf118c3b36adc994109713ada9
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1061525
milestone42.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 1061525 - Part 2: Make MacIOSurfaceTextureHostOGL understand planar MacIOSurfaces. r=jrmuizel
gfx/layers/opengl/MacIOSurfaceTextureHostOGL.cpp
gfx/layers/opengl/MacIOSurfaceTextureHostOGL.h
--- a/gfx/layers/opengl/MacIOSurfaceTextureHostOGL.cpp
+++ b/gfx/layers/opengl/MacIOSurfaceTextureHostOGL.cpp
@@ -20,58 +20,69 @@ MacIOSurfaceTextureHostOGL::MacIOSurface
                                          !aDescriptor.isOpaque());
 }
 
 MacIOSurfaceTextureHostOGL::~MacIOSurfaceTextureHostOGL()
 {
   MOZ_COUNT_DTOR(MacIOSurfaceTextureHostOGL);
 }
 
+GLTextureSource*
+MacIOSurfaceTextureHostOGL::CreateTextureSourceForPlane(size_t aPlane)
+{
+  GLuint textureHandle;
+  gl::GLContext* gl = mCompositor->gl();
+  gl->fGenTextures(1, &textureHandle);
+  gl->fBindTexture(LOCAL_GL_TEXTURE_RECTANGLE_ARB, textureHandle);
+  gl->fTexParameteri(LOCAL_GL_TEXTURE_RECTANGLE_ARB, LOCAL_GL_TEXTURE_WRAP_T, LOCAL_GL_CLAMP_TO_EDGE);
+  gl->fTexParameteri(LOCAL_GL_TEXTURE_RECTANGLE_ARB, LOCAL_GL_TEXTURE_WRAP_S, LOCAL_GL_CLAMP_TO_EDGE);
+
+  mSurface->CGLTexImageIOSurface2D(gl::GLContextCGL::Cast(gl)->GetCGLContext(), aPlane);
+
+  return new GLTextureSource(mCompositor, textureHandle, LOCAL_GL_TEXTURE_RECTANGLE_ARB,
+                             gfx::IntSize(mSurface->GetDevicePixelWidth(aPlane),
+                                          mSurface->GetDevicePixelHeight(aPlane)),
+                             // XXX: This isn't really correct (but isn't used), we should be using the
+                             // format of the individual plane, not of the whole buffer.
+                             mSurface->GetFormat());
+}
+
 bool
 MacIOSurfaceTextureHostOGL::Lock()
 {
   if (!mCompositor || !mSurface) {
     return false;
   }
 
   if (!mTextureSource) {
-    GLuint textureHandle;
-    gl::GLContext* gl = mCompositor->gl();
-    gl->fGenTextures(1, &textureHandle);
-    gl->fBindTexture(LOCAL_GL_TEXTURE_RECTANGLE_ARB, textureHandle);
-    gl->fTexParameteri(LOCAL_GL_TEXTURE_RECTANGLE_ARB, LOCAL_GL_TEXTURE_WRAP_T, LOCAL_GL_CLAMP_TO_EDGE);
-    gl->fTexParameteri(LOCAL_GL_TEXTURE_RECTANGLE_ARB, LOCAL_GL_TEXTURE_WRAP_S, LOCAL_GL_CLAMP_TO_EDGE);
-    mSurface->CGLTexImageIOSurface2D(gl::GLContextCGL::Cast(gl)->GetCGLContext());
+    mTextureSource = CreateTextureSourceForPlane(0);
 
-    mTextureSource = new GLTextureSource(mCompositor, textureHandle, LOCAL_GL_TEXTURE_RECTANGLE_ARB,
-                                         gfx::IntSize(mSurface->GetDevicePixelWidth(),
-                                                      mSurface->GetDevicePixelHeight()),
-                                         mSurface->HasAlpha() ? gfx::SurfaceFormat::R8G8B8A8:
-                                                                gfx::SurfaceFormat::R8G8B8X8);
+    RefPtr<TextureSource> prev = mTextureSource;
+    for (size_t i = 1; i < mSurface->GetPlaneCount(); i++) {
+      RefPtr<TextureSource> next = CreateTextureSourceForPlane(i);
+      prev->SetNextSibling(next);
+      prev = next;
+    }
   }
   return true;
 }
 
 void
 MacIOSurfaceTextureHostOGL::SetCompositor(Compositor* aCompositor)
 {
   CompositorOGL* glCompositor = static_cast<CompositorOGL*>(aCompositor);
   mCompositor = glCompositor;
   if (mTextureSource) {
     mTextureSource->SetCompositor(glCompositor);
   }
 }
 
 gfx::SurfaceFormat
 MacIOSurfaceTextureHostOGL::GetFormat() const {
-  if (!mSurface) {
-    return gfx::SurfaceFormat::UNKNOWN;
-  }
-  return mSurface->HasAlpha() ? gfx::SurfaceFormat::R8G8B8A8
-                              : gfx::SurfaceFormat::R8G8B8X8;
+  return mSurface->GetFormat();
 }
 
 gfx::IntSize
 MacIOSurfaceTextureHostOGL::GetSize() const {
   if (!mSurface) {
     return gfx::IntSize();
   }
   return gfx::IntSize(mSurface->GetDevicePixelWidth(),
--- a/gfx/layers/opengl/MacIOSurfaceTextureHostOGL.h
+++ b/gfx/layers/opengl/MacIOSurfaceTextureHostOGL.h
@@ -90,16 +90,18 @@ public:
 
   virtual gfx::IntSize GetSize() const override;
 
 #ifdef MOZ_LAYERS_HAVE_LOG
   virtual const char* Name() override { return "MacIOSurfaceTextureHostOGL"; }
 #endif
 
 protected:
+  GLTextureSource* CreateTextureSourceForPlane(size_t aPlane);
+
   RefPtr<CompositorOGL> mCompositor;
   RefPtr<GLTextureSource> mTextureSource;
   RefPtr<MacIOSurface> mSurface;
 };
 
 } // namespace layers
 } // namespace mozilla