Bug 860615 - Add CreateSharedHandle to GLContextProvider so we can create one without a GLContext. r=jgilbert
authorMatt Woodrow <mwoodrow@mozilla.com>
Wed, 17 Apr 2013 14:21:06 +1200
changeset 139971 d0dc8a672b3145c3d00ade93d228cae33eb38877
parent 139970 3abd4a5ff41736e064d724186dc07420a1c1f7ef
child 139972 b0bede12278b181dbd8a1748e8c9bbe9dc460a34
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgilbert
bugs860615
milestone23.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 860615 - Add CreateSharedHandle to GLContextProvider so we can create one without a GLContext. r=jgilbert
gfx/gl/GLContext.h
gfx/gl/GLContextProviderCGL.mm
gfx/gl/GLContextProviderEGL.cpp
gfx/gl/GLContextProviderGLX.cpp
gfx/gl/GLContextProviderImpl.h
gfx/gl/GLContextProviderNull.cpp
gfx/gl/GLContextProviderWGL.cpp
--- a/gfx/gl/GLContext.h
+++ b/gfx/gl/GLContext.h
@@ -437,21 +437,16 @@ public:
 
     enum SharedTextureBufferType {
         TextureID
 #ifdef MOZ_WIDGET_ANDROID
         , SurfaceTexture
 #endif
     };
 
-    /**
-     * Create new shared GLContext content handle, must be released by ReleaseSharedHandle.
-     */
-    virtual SharedTextureHandle CreateSharedHandle(SharedTextureShareType shareType)
-    { return 0; }
     /*
      * Create a new shared GLContext content handle, using the passed buffer as a source.
      * Must be released by ReleaseSharedHandle. UpdateSharedHandle will have no effect
      * on handles created with this method, as the caller owns the source (the passed buffer)
      * and is responsible for updating it accordingly.
      */
     virtual SharedTextureHandle CreateSharedHandle(SharedTextureShareType shareType,
                                                    void* buffer,
--- a/gfx/gl/GLContextProviderCGL.mm
+++ b/gfx/gl/GLContextProviderCGL.mm
@@ -409,16 +409,24 @@ GLContextProviderCGL::GetGlobalContext(c
         }
 
         gGlobalContext->SetIsGlobalSharedContext(true);
     }
 
     return gGlobalContext;
 }
 
+SharedTextureHandle
+GLContextProviderCGL::CreateSharedHandle(GLContext::SharedTextureShareType shareType,
+                                         void* buffer,
+                                         GLContext::SharedTextureBufferType bufferType)
+{
+    return 0;
+}
+
 void
 GLContextProviderCGL::Shutdown()
 {
   gGlobalContext = nullptr;
 }
 
 } /* namespace gl */
 } /* namespace mozilla */
--- a/gfx/gl/GLContextProviderEGL.cpp
+++ b/gfx/gl/GLContextProviderEGL.cpp
@@ -660,17 +660,16 @@ public:
 
     static already_AddRefed<GLContextEGL>
     CreateEGLPBufferOffscreenContext(const gfxIntSize& size);
 
     virtual bool HasLockSurface() {
         return sEGLLibrary.HasKHRLockSurface();
     }
 
-    virtual SharedTextureHandle CreateSharedHandle(SharedTextureShareType shareType);
     virtual SharedTextureHandle CreateSharedHandle(SharedTextureShareType shareType,
                                                    void* buffer,
                                                    SharedTextureBufferType bufferType);
     virtual void UpdateSharedHandle(SharedTextureShareType shareType,
                                     SharedTextureHandle sharedHandle);
     virtual void ReleaseSharedHandle(SharedTextureShareType shareType,
                                      SharedTextureHandle sharedHandle);
     virtual bool GetSharedHandleDetails(SharedTextureShareType shareType,
@@ -905,41 +904,16 @@ GLContextEGL::UpdateSharedHandle(SharedT
 
     // Make sure our copy is finished, so that we can be ready to draw
     // in different thread GLContext.  If we have KHR_fence_sync, then
     // we insert a sync object, otherwise we have to do a GuaranteeResolve.
     wrap->MakeSync(this);
 }
 
 SharedTextureHandle
-GLContextEGL::CreateSharedHandle(SharedTextureShareType shareType)
-{
-    if (shareType != SameProcess)
-        return 0;
-
-    if (!mShareWithEGLImage)
-        return 0;
-
-    MakeCurrent();
-    mTemporaryEGLImageTexture = CreateTextureForOffscreen(GetGLFormats(), OffscreenSize());
-
-    EGLTextureWrapper* tex = new EGLTextureWrapper();
-    bool ok = tex->CreateEGLImage(this, mTemporaryEGLImageTexture);
-
-    if (!ok) {
-        NS_ERROR("EGLImage creation for EGLTextureWrapper failed");
-        ReleaseSharedHandle(shareType, (SharedTextureHandle)tex);
-        return 0;
-    }
-
-    // Raw pointer shared across threads
-    return (SharedTextureHandle)tex;
-}
-
-SharedTextureHandle
 GLContextEGL::CreateSharedHandle(SharedTextureShareType shareType,
                                  void* buffer,
                                  SharedTextureBufferType bufferType)
 {
     // Both EGLImage and SurfaceTexture only support same-process currently, but
     // it's possible to make SurfaceTexture work across processes. We should do that.
     if (shareType != SameProcess)
         return 0;
@@ -2359,16 +2333,24 @@ GLContextProviderEGL::CreateOffscreen(co
         return glContext.forget();
 
     if (!glContext->InitOffscreen(size, caps))
         return nullptr;
 
     return glContext.forget();
 }
 
+SharedTextureHandle
+GLContextProviderEGL::CreateSharedHandle(GLContext::SharedTextureShareType shareType,
+                                         void* buffer,
+                                         GLContext::SharedTextureBufferType bufferType)
+{
+  return 0;
+}
+
 // Don't want a global context on Android as 1) share groups across 2 threads fail on many Tegra drivers (bug 759225)
 // and 2) some mobile devices have a very strict limit on global number of GL contexts (bug 754257)
 // and 3) each EGL context eats 750k on B2G (bug 813783)
 GLContext *
 GLContextProviderEGL::GetGlobalContext(const ContextFlags)
 {
     return nullptr;
 }
--- a/gfx/gl/GLContextProviderGLX.cpp
+++ b/gfx/gl/GLContextProviderGLX.cpp
@@ -1410,16 +1410,24 @@ GLContextProviderGLX::CreateOffscreen(co
         return nullptr;
 
     if (!glContext->InitOffscreen(size, caps))
         return nullptr;
 
     return glContext.forget();
 }
 
+SharedTextureHandle
+GLContextProviderGLX::CreateSharedHandle(GLContext::SharedTextureShareType shareType,
+                                         void* buffer,
+                                         GLContext::SharedTextureBufferType bufferType)
+{
+  return 0;
+}
+
 static nsRefPtr<GLContext> gGlobalContext[GLXLibrary::LIBS_MAX];
 // TODO move that out of static initializaion
 static bool gUseContextSharing = getenv("MOZ_DISABLE_CONTEXT_SHARING_GLX") == 0;
 
 GLContext*
 GLContextProviderGLX::GetGlobalContext(const ContextFlags aFlag)
 {
     // TODO: get GLX context sharing to work well with multiple threads
--- a/gfx/gl/GLContextProviderImpl.h
+++ b/gfx/gl/GLContextProviderImpl.h
@@ -63,15 +63,25 @@ public:
                     const SurfaceCaps& caps,
                     ContextFlags flags = GLContext::ContextFlagsNone);
 
     /**
      * Get a pointer to the global context, creating it if it doesn't exist.
      */
     static GLContext*
     GetGlobalContext(ContextFlags flags = GLContext::ContextFlagsNone);
+    
+    /*
+     * Create a new shared GLContext content handle, using the passed buffer as a source.
+     * Must be released by ReleaseSharedHandle. UpdateSharedHandle will have no effect
+     * on handles created with this method, as the caller owns the source (the passed buffer)
+     * and is responsible for updating it accordingly.
+     */
+    static SharedTextureHandle CreateSharedHandle(GLContext::SharedTextureShareType shareType,
+                                                  void* buffer,
+                                                  GLContext::SharedTextureBufferType bufferType);
 
     /**
      * Free any resources held by this Context Provider.
      */
     static void
     Shutdown();
 };
--- a/gfx/gl/GLContextProviderNull.cpp
+++ b/gfx/gl/GLContextProviderNull.cpp
@@ -17,16 +17,24 @@ GLContextProviderNull::CreateForWindow(n
 already_AddRefed<GLContext>
 GLContextProviderNull::CreateOffscreen(const gfxIntSize&,
                                        const SurfaceCaps&,
                                        ContextFlags)
 {
     return nullptr;
 }
 
+SharedTextureHandle
+GLContextProviderNull::CreateSharedHandle(GLContext::SharedTextureShareType shareType,
+                                          void* buffer,
+                                          GLContext::SharedTextureBufferType bufferType)
+{
+  return 0;
+}
+
 GLContext*
 GLContextProviderNull::GetGlobalContext(ContextFlags)
 {
     return nullptr;
 }
 
 void
 GLContextProviderNull::Shutdown()
--- a/gfx/gl/GLContextProviderWGL.cpp
+++ b/gfx/gl/GLContextProviderWGL.cpp
@@ -682,16 +682,24 @@ GLContextProviderWGL::CreateOffscreen(co
     }
 
     if (!glContext->InitOffscreen(size, caps))
         return nullptr;
 
     return glContext.forget();
 }
 
+SharedTextureHandle
+GLContextProviderWGL::CreateSharedHandle(GLContext::SharedTextureShareType shareType,
+                                         void* buffer,
+                                         GLContext::SharedTextureBufferType bufferType)
+{
+  return 0;
+}
+
 static nsRefPtr<GLContextWGL> gGlobalContext[WGLLibrary::LIBS_MAX];
 
 GLContext *
 GLContextProviderWGL::GetGlobalContext(const ContextFlags flags)
 {
     LibType libToUse = WGLLibrary::SelectLibrary(flags);
     
     if (!sWGLLib[libToUse].EnsureInitialized(libToUse == WGLLibrary::MESA_LLVMPIPE_LIB)) {