Bug 887791 - Add a TextureClient implementation for MacIOSurface. r=nical, a=bajaj
authorMatt Woodrow <mwoodrow@mozilla.com>
Fri, 01 Nov 2013 14:54:14 +1300
changeset 166387 fbca562c65df9416f6e7c3ba11ae36cd1c5707d9
parent 166386 d23227011e29f79f7791b3c22ca5e3dc8e744a0d
child 166388 d0b0cecee407fc2b1043853c5c4750f75dd22307
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnical, bajaj
bugs887791
milestone27.0a2
Bug 887791 - Add a TextureClient implementation for MacIOSurface. r=nical, a=bajaj
gfx/layers/ipc/LayersSurfaces.ipdlh
gfx/layers/opengl/TextureClientOGL.cpp
gfx/layers/opengl/TextureClientOGL.h
--- a/gfx/layers/ipc/LayersSurfaces.ipdlh
+++ b/gfx/layers/ipc/LayersSurfaces.ipdlh
@@ -46,16 +46,22 @@ struct SurfaceDescriptorDIB {
   uintptr_t surface;
 };
 
 struct SurfaceDescriptorD3D10 {
   WindowsHandle handle;
   bool hasAlpha;
 };
 
+struct SurfaceDescriptorMacIOSurface {
+  uint32_t surface;
+  double scaleFactor;
+  bool hasAlpha;
+};
+
 struct SharedTextureDescriptor {
   SharedTextureShareType shareType;
   SharedTextureHandle handle;
   nsIntSize size;
   bool inverted;
 };
 
 struct BasicShmTileDescriptor {
@@ -171,16 +177,17 @@ union SurfaceDescriptor {
   SurfaceDescriptorShmem;
   SurfaceDescriptorMemory;
   SurfaceDescriptorD3D9;
   SurfaceDescriptorDIB;
   SurfaceDescriptorD3D10;
   SurfaceDescriptorX11;
   SharedTextureDescriptor;
   SurfaceStreamDescriptor;
+  SurfaceDescriptorMacIOSurface;
   NewSurfaceDescriptorGralloc;
   YCbCrImage;                 // XXX - deprecated
   SurfaceDescriptorGralloc;   // XXX - deprecated
   Shmem;                      // XXX - deprecated
   RGBImage;                   // XXX - deprecated
   MemoryImage;                // XXX - deprecated
   null_t;
 };
--- a/gfx/layers/opengl/TextureClientOGL.cpp
+++ b/gfx/layers/opengl/TextureClientOGL.cpp
@@ -61,17 +61,30 @@ SharedTextureClientOGL::InitWith(gl::Sha
 }
 
 bool
 SharedTextureClientOGL::IsAllocated() const
 {
   return mHandle != 0;
 }
 
-
+#ifdef XP_MACOSX
+bool
+MacIOSurfaceTextureClientOGL::ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor)
+{
+  MOZ_ASSERT(IsValid());
+  if (!IsAllocated()) {
+    return false;
+  }
+  aOutDescriptor = SurfaceDescriptorMacIOSurface(mSurface->GetIOSurfaceID(),
+                                                 mSurface->GetContentsScaleFactor(),
+                                                 mSurface->HasAlpha());
+  return true;
+}
+#endif
 
 DeprecatedTextureClientSharedOGL::DeprecatedTextureClientSharedOGL(CompositableForwarder* aForwarder,
                                                const TextureInfo& aTextureInfo)
   : DeprecatedTextureClient(aForwarder, aTextureInfo)
   , mGL(nullptr)
 {
 }
 
--- a/gfx/layers/opengl/TextureClientOGL.h
+++ b/gfx/layers/opengl/TextureClientOGL.h
@@ -8,16 +8,19 @@
 
 #include "GLContextTypes.h"             // for SharedTextureHandle, etc
 #include "gfxTypes.h"
 #include "mozilla/Attributes.h"         // for MOZ_OVERRIDE
 #include "mozilla/gfx/Point.h"          // for IntSize
 #include "mozilla/layers/CompositorTypes.h"
 #include "mozilla/layers/LayersSurfaces.h"  // for SurfaceDescriptor
 #include "mozilla/layers/TextureClient.h"  // for DeprecatedTextureClient, etc
+#ifdef XP_MACOSX
+#include "mozilla/gfx/MacIOSurface.h"
+#endif
 
 namespace mozilla {
 namespace layers {
 
 class CompositableForwarder;
 
 /**
  * A TextureClient implementation to share TextureMemory that is already
@@ -52,16 +55,54 @@ public:
 
 protected:
   gl::SharedTextureHandle mHandle;
   gfx::IntSize mSize;
   gl::SharedTextureShareType mShareType;
   bool mInverted;
 };
 
+#ifdef XP_MACOSX
+class MacIOSurfaceTextureClientOGL : public TextureClient
+{
+public:
+  MacIOSurfaceTextureClientOGL(TextureFlags aFlags)
+    : TextureClient(aFlags)
+  {}
+
+  virtual bool IsAllocated() const MOZ_OVERRIDE { return !!mSurface; }
+
+  virtual bool ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor) MOZ_OVERRIDE;
+
+  void InitWith(MacIOSurface* aSurface)
+  {
+    MOZ_ASSERT(IsValid());
+    MOZ_ASSERT(!IsAllocated());
+    mSurface = aSurface;
+  }
+
+  virtual gfx::IntSize GetSize() const
+  {
+    return gfx::IntSize(mSurface->GetDevicePixelWidth(), mSurface->GetDevicePixelHeight());
+  }
+
+  virtual TextureClientData* DropTextureData() MOZ_OVERRIDE
+  {
+    // MacIOSurface has proper cross-process refcounting so we can just drop
+    // our reference now, and the data will stay alive (at least) until the host
+    // has also been torn down.
+    mSurface = nullptr;
+    MarkInvalid();
+    return nullptr;
+  }
+
+protected:
+  RefPtr<MacIOSurface> mSurface;
+};
+#endif
 
 class DeprecatedTextureClientSharedOGL : public DeprecatedTextureClient
 {
 public:
   DeprecatedTextureClientSharedOGL(CompositableForwarder* aForwarder, const TextureInfo& aTextureInfo);
   ~DeprecatedTextureClientSharedOGL() { ReleaseResources(); }
 
   virtual bool SupportsType(DeprecatedTextureClientType aType) MOZ_OVERRIDE { return aType == TEXTURE_SHARED_GL; }