Bug 1000640 - Update Gralloc and ANGLE ShSurf backends. - r=mattwoodrow
☠☠ backed out by 6b72f1fad830 ☠ ☠
authorJeff Gilbert <jgilbert@mozilla.com>
Wed, 04 Jun 2014 15:20:25 -0700
changeset 188111 d1b96309bb9d285edd4b8a9f0a44497897b7077c
parent 188110 11bb536cdede64953b6cd61e1375fedd09d8a8ed
child 188112 c4681bf6680c705654252c2eaad7852df8a1d81e
push id44751
push usermwoodrow@mozilla.com
push dateWed, 11 Jun 2014 15:43:29 +0000
treeherdermozilla-inbound@dacd814d3bb0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow
bugs1000640
milestone33.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 1000640 - Update Gralloc and ANGLE ShSurf backends. - r=mattwoodrow
gfx/gl/SharedSurfaceANGLE.cpp
gfx/gl/SharedSurfaceANGLE.h
gfx/gl/SharedSurfaceGralloc.cpp
gfx/gl/SharedSurfaceGralloc.h
gfx/gl/moz.build
gfx/layers/d3d10/CanvasLayerD3D10.cpp
--- a/gfx/gl/SharedSurfaceANGLE.cpp
+++ b/gfx/gl/SharedSurfaceANGLE.cpp
@@ -9,30 +9,29 @@
 
 namespace mozilla {
 namespace gl {
 
 using namespace mozilla::gfx;
 
 SurfaceFactory_ANGLEShareHandle*
 SurfaceFactory_ANGLEShareHandle::Create(GLContext* gl,
-                                        ID3D10Device1* d3d,
                                         const SurfaceCaps& caps)
 {
     GLLibraryEGL* egl = &sEGLLibrary;
     if (!egl)
         return nullptr;
 
     if (!egl->IsExtensionSupported(
             GLLibraryEGL::ANGLE_surface_d3d_texture_2d_share_handle))
     {
         return nullptr;
     }
 
-    return new SurfaceFactory_ANGLEShareHandle(gl, egl, d3d, caps);
+    return new SurfaceFactory_ANGLEShareHandle(gl, egl, caps);
 }
 
 EGLDisplay
 SharedSurface_ANGLEShareHandle::Display()
 {
     return mEGL->Display();
 }
 
@@ -166,114 +165,76 @@ ChooseConfig(GLContext* gl,
 
     if (gl->DebugMode()) {
         egl->DumpEGLConfig(config);
     }
 
     return config;
 }
 
-
 // Returns EGL_NO_SURFACE on error.
-static EGLSurface CreatePBufferSurface(GLLibraryEGL* egl,
-                                       EGLDisplay display,
-                                       EGLConfig config,
-                                       const gfx::IntSize& size)
+static EGLSurface
+CreatePBufferSurface(GLLibraryEGL* egl,
+                     EGLDisplay display,
+                     EGLConfig config,
+                     const gfx::IntSize& size)
 {
     EGLint attribs[] = {
         LOCAL_EGL_WIDTH, size.width,
         LOCAL_EGL_HEIGHT, size.height,
         LOCAL_EGL_NONE
     };
 
     EGLSurface surface = egl->fCreatePbufferSurface(display, config, attribs);
 
     return surface;
 }
 
 SharedSurface_ANGLEShareHandle*
-SharedSurface_ANGLEShareHandle::Create(GLContext* gl, ID3D10Device1* d3d,
+SharedSurface_ANGLEShareHandle::Create(GLContext* gl,
                                        EGLContext context, EGLConfig config,
                                        const gfx::IntSize& size, bool hasAlpha)
 {
     GLLibraryEGL* egl = &sEGLLibrary;
     MOZ_ASSERT(egl);
     MOZ_ASSERT(egl->IsExtensionSupported(
                GLLibraryEGL::ANGLE_surface_d3d_texture_2d_share_handle));
 
     if (!context || !config)
         return nullptr;
 
     EGLDisplay display = egl->Display();
     EGLSurface pbuffer = CreatePBufferSurface(egl, display, config, size);
     if (!pbuffer)
         return nullptr;
 
-
     // Declare everything before 'goto's.
     HANDLE shareHandle = nullptr;
-    nsRefPtr<ID3D10Texture2D> texture;
-    nsRefPtr<ID3D10ShaderResourceView> srv;
-
-    // On failure, goto CleanUpIfFailed.
-    // If |failed|, CleanUpIfFailed will clean up and return null.
-    bool failed = true;
-    HRESULT hr;
-
-    // Off to the races!
-    if (!egl->fQuerySurfacePointerANGLE(
-            display,
-            pbuffer,
-            LOCAL_EGL_D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE,
-            &shareHandle))
-    {
-        NS_ERROR("Failed to grab ShareHandle for PBuffer!");
-        goto CleanUpIfFailed;
-    }
-
-    // Ok, we have a valid PBuffer with ShareHandle.
-    // Let's attach it to D3D.
-    hr = d3d->OpenSharedResource(shareHandle,
-                                 __uuidof(ID3D10Texture2D),
-                                 getter_AddRefs(texture));
-    if (FAILED(hr)) {
-        NS_ERROR("Failed to open shared resource!");
-        goto CleanUpIfFailed;
-    }
-
-    hr = d3d->CreateShaderResourceView(texture, nullptr, getter_AddRefs(srv));
-    if (FAILED(hr)) {
-        NS_ERROR("Failed to create SRV!");
-        goto CleanUpIfFailed;
-    }
-
-    failed = false;
-
-CleanUpIfFailed:
-    if (failed) {
-        NS_WARNING("CleanUpIfFailed");
+    bool ok = egl->fQuerySurfacePointerANGLE(display,
+                                             pbuffer,
+                                             LOCAL_EGL_D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE,
+                                             &shareHandle);
+    if (!ok) {
         egl->fDestroySurface(egl->Display(), pbuffer);
         return nullptr;
     }
 
     return new SharedSurface_ANGLEShareHandle(gl, egl,
                                               size, hasAlpha,
                                               context, pbuffer,
-                                              texture, srv);
+                                              shareHandle);
 }
 
 
 SurfaceFactory_ANGLEShareHandle::SurfaceFactory_ANGLEShareHandle(GLContext* gl,
                                                                  GLLibraryEGL* egl,
-                                                                 ID3D10Device1* d3d,
                                                                  const SurfaceCaps& caps)
     : SurfaceFactory_GL(gl, SharedSurfaceType::EGLSurfaceANGLE, caps)
     , mProdGL(gl)
     , mEGL(egl)
-    , mConsD3D(d3d)
 {
     mConfig = ChooseConfig(mProdGL, mEGL, mReadCaps);
     mContext = GLContextEGL::Cast(mProdGL)->GetEGLContext();
     MOZ_ASSERT(mConfig && mContext);
 }
 
 } /* namespace gl */
 } /* namespace mozilla */
--- a/gfx/gl/SharedSurfaceANGLE.h
+++ b/gfx/gl/SharedSurfaceANGLE.h
@@ -7,108 +7,101 @@
 #define SHARED_SURFACE_ANGLE_H_
 
 #include "SharedSurfaceGL.h"
 #include "SurfaceFactory.h"
 #include "GLLibraryEGL.h"
 #include "SurfaceTypes.h"
 
 #include <windows.h>
-#include <d3d10_1.h>
 
 namespace mozilla {
 namespace gl {
 
 class GLContext;
 
 class SharedSurface_ANGLEShareHandle
     : public SharedSurface_GL
 {
 public:
-    static SharedSurface_ANGLEShareHandle* Create(GLContext* gl, ID3D10Device1* d3d,
+    static SharedSurface_ANGLEShareHandle* Create(GLContext* gl,
                                                   EGLContext context, EGLConfig config,
                                                   const gfx::IntSize& size,
                                                   bool hasAlpha);
 
     static SharedSurface_ANGLEShareHandle* Cast(SharedSurface* surf) {
         MOZ_ASSERT(surf->Type() == SharedSurfaceType::EGLSurfaceANGLE);
 
         return (SharedSurface_ANGLEShareHandle*)surf;
     }
 
 protected:
     GLLibraryEGL* const mEGL;
     const EGLContext mContext;
     const EGLSurface mPBuffer;
-    nsRefPtr<ID3D10Texture2D> mTexture;
-    nsRefPtr<ID3D10ShaderResourceView> mSRV;
+    const HANDLE mShareHandle;
 
     SharedSurface_ANGLEShareHandle(GLContext* gl,
                                    GLLibraryEGL* egl,
                                    const gfx::IntSize& size,
                                    bool hasAlpha,
                                    EGLContext context,
                                    EGLSurface pbuffer,
-                                   ID3D10Texture2D* texture,
-                                   ID3D10ShaderResourceView* srv)
+                                   HANDLE shareHandle)
         : SharedSurface_GL(SharedSurfaceType::EGLSurfaceANGLE,
                            AttachmentType::Screen,
                            gl,
                            size,
                            hasAlpha)
         , mEGL(egl)
         , mContext(context)
         , mPBuffer(pbuffer)
-        , mTexture(texture)
-        , mSRV(srv)
+        , mShareHandle(shareHandle)
     {}
 
     EGLDisplay Display();
 
 public:
     virtual ~SharedSurface_ANGLEShareHandle();
 
     virtual void LockProdImpl() MOZ_OVERRIDE;
     virtual void UnlockProdImpl() MOZ_OVERRIDE;
 
     virtual void Fence() MOZ_OVERRIDE;
     virtual bool WaitSync() MOZ_OVERRIDE;
 
     // Implementation-specific functions below:
-    ID3D10ShaderResourceView* GetSRV() {
-        return mSRV;
+    HANDLE GetShareHandle() {
+        return mShareHandle;
     }
 };
 
 
 
 class SurfaceFactory_ANGLEShareHandle
     : public SurfaceFactory_GL
 {
 protected:
     GLContext* const mProdGL;
     GLLibraryEGL* const mEGL;
-    nsRefPtr<ID3D10Device1> mConsD3D;
     EGLContext mContext;
     EGLConfig mConfig;
 
 public:
     static SurfaceFactory_ANGLEShareHandle* Create(GLContext* gl,
-                                                   ID3D10Device1* d3d,
                                                    const SurfaceCaps& caps);
 
 protected:
     SurfaceFactory_ANGLEShareHandle(GLContext* gl,
                                     GLLibraryEGL* egl,
-                                    ID3D10Device1* d3d,
                                     const SurfaceCaps& caps);
 
     virtual SharedSurface* CreateShared(const gfx::IntSize& size) MOZ_OVERRIDE {
         bool hasAlpha = mReadCaps.alpha;
-        return SharedSurface_ANGLEShareHandle::Create(mProdGL, mConsD3D,
+        return SharedSurface_ANGLEShareHandle::Create(mProdGL,
                                                       mContext, mConfig,
                                                       size, hasAlpha);
     }
 };
 
 } /* namespace gfx */
 } /* namespace mozilla */
 
--- a/gfx/gl/SharedSurfaceGralloc.cpp
+++ b/gfx/gl/SharedSurfaceGralloc.cpp
@@ -114,16 +114,37 @@ SharedSurface_Gralloc::Create(GLContext*
     SharedSurface_Gralloc *surf = new SharedSurface_Gralloc(prodGL, size, hasAlpha, egl, allocator, grallocTC, prodTex);
 
     DEBUG_PRINT("SharedSurface_Gralloc::Create: success -- surface %p, GraphicBuffer %p.\n", surf, buffer.get());
 
     return surf;
 }
 
 
+SharedSurface_Gralloc::SharedSurface_Gralloc(GLContext* prodGL,
+                                             const gfx::IntSize& size,
+                                             bool hasAlpha,
+                                             GLLibraryEGL* egl,
+                                             layers::ISurfaceAllocator* allocator,
+                                             layers::GrallocTextureClientOGL* textureClient,
+                                             GLuint prodTex)
+    : SharedSurface_GL(SharedSurfaceType::Gralloc,
+                       AttachmentType::GLTexture,
+                       prodGL,
+                       size,
+                       hasAlpha)
+    , mEGL(egl)
+    , mSync(0)
+    , mAllocator(allocator)
+    , mTextureClient(textureClient)
+    , mProdTex(prodTex)
+{
+}
+
+
 bool
 SharedSurface_Gralloc::HasExtensions(GLLibraryEGL* egl, GLContext* gl)
 {
     return egl->HasKHRImageBase() &&
            gl->IsExtensionSupported(GLContext::OES_EGL_image);
 }
 
 SharedSurface_Gralloc::~SharedSurface_Gralloc()
--- a/gfx/gl/SharedSurfaceGralloc.h
+++ b/gfx/gl/SharedSurfaceGralloc.h
@@ -2,23 +2,22 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef SHARED_SURFACE_GRALLOC_H_
 #define SHARED_SURFACE_GRALLOC_H_
 
 #include "SharedSurfaceGL.h"
-#include "mozilla/layers/ISurfaceAllocator.h"
 #include "mozilla/layers/LayersSurfaces.h"
-#include "mozilla/layers/TextureClient.h"
 
 namespace mozilla {
 namespace layers {
 class ISurfaceAllocator;
+class GrallocTextureClientOGL;
 }
 
 namespace gl {
 class GLContext;
 class GLLibraryEGL;
 
 class SharedSurface_Gralloc
     : public SharedSurface_GL
@@ -35,37 +34,26 @@ public:
 
         return (SharedSurface_Gralloc*)surf;
     }
 
 protected:
     GLLibraryEGL* const mEGL;
     EGLSync mSync;
     RefPtr<layers::ISurfaceAllocator> mAllocator;
-    RefPtr<layers::TextureClient> mTextureClient;
+    RefPtr<layers::GrallocTextureClientOGL> mTextureClient;
     const GLuint mProdTex;
 
     SharedSurface_Gralloc(GLContext* prodGL,
                           const gfx::IntSize& size,
                           bool hasAlpha,
                           GLLibraryEGL* egl,
                           layers::ISurfaceAllocator* allocator,
-                          layers::TextureClient* textureClient,
-                          GLuint prodTex)
-        : SharedSurface_GL(SharedSurfaceType::Gralloc,
-                           AttachmentType::GLTexture,
-                           prodGL,
-                           size,
-                           hasAlpha)
-        , mEGL(egl)
-        , mSync(0)
-        , mAllocator(allocator)
-        , mTextureClient(textureClient)
-        , mProdTex(prodTex)
-    {}
+                          layers::GrallocTextureClientOGL* textureClient,
+                          GLuint prodTex);
 
     static bool HasExtensions(GLLibraryEGL* egl, GLContext* gl);
 
 public:
     virtual ~SharedSurface_Gralloc();
 
     virtual void Fence() MOZ_OVERRIDE;
     virtual bool WaitSync() MOZ_OVERRIDE;
@@ -74,17 +62,17 @@ public:
 
     virtual void LockProdImpl() MOZ_OVERRIDE {}
     virtual void UnlockProdImpl() MOZ_OVERRIDE {}
 
     virtual GLuint ProdTexture() MOZ_OVERRIDE {
         return mProdTex;
     }
 
-    layers::TextureClient* GetTextureClient() {
+    layers::GrallocTextureClientOGL* GetTextureClient() {
         return mTextureClient;
     }
 };
 
 class SurfaceFactory_Gralloc
     : public SurfaceFactory_GL
 {
 protected:
--- a/gfx/gl/moz.build
+++ b/gfx/gl/moz.build
@@ -62,17 +62,17 @@ if CONFIG['MOZ_X11']:
         'GLContextGLX.h',
         'GLXLibrary.h',
     ]
 
 # Win32 is a special snowflake, for ANGLE
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows':
     EXPORTS += [
         'GLContextWGL.h',
-        'SharedSurfaceANGLE.h',
+        'SharedSurfaceANGLE.h', # Needs <windows.h> for `HANDLE`.
         'WGLLibrary.h',
     ]
     UNIFIED_SOURCES += [
         'GLContextProviderEGL.cpp',
         'SharedSurfaceANGLE.cpp',
     ]
 if CONFIG['MOZ_ENABLE_SKIA_GPU']:
     EXPORTS += ['SkiaGLGlue.h']
--- a/gfx/layers/d3d10/CanvasLayerD3D10.cpp
+++ b/gfx/layers/d3d10/CanvasLayerD3D10.cpp
@@ -50,17 +50,16 @@ CanvasLayerD3D10::Initialize(const Data&
     SurfaceStreamType streamType =
         SurfaceStream::ChooseGLStreamType(SurfaceStream::MainThread,
                                           screen->PreserveBuffer());
 
     SurfaceFactory_GL* factory = nullptr;
     if (!gfxPrefs::WebGLForceLayersReadback()) {
       if (mGLContext->IsANGLE()) {
         factory = SurfaceFactory_ANGLEShareHandle::Create(mGLContext,
-                                                          device(),
                                                           screen->Caps());
       }
     }
 
     if (factory) {
       screen->Morph(factory, streamType);
     }
   } else if (aData.mDrawTarget) {
@@ -125,18 +124,30 @@ CanvasLayerD3D10::UpdateSurface()
     SharedSurface_GL* surf = mGLContext->RequestFrame();
     if (!surf) {
       return;
     }
 
     switch (surf->Type()) {
       case SharedSurfaceType::EGLSurfaceANGLE: {
         SharedSurface_ANGLEShareHandle* shareSurf = SharedSurface_ANGLEShareHandle::Cast(surf);
+        HANDLE shareHandle = shareSurf->GetShareHandle();
 
-        mSRView = shareSurf->GetSRV();
+        HRESULT hr = device()->OpenSharedResource(shareHandle,
+                                                  __uuidof(ID3D10Texture2D),
+                                                  getter_AddRefs(mTexture));
+        if (FAILED(hr))
+          return;
+
+        hr = device()->CreateShaderResourceView(mTexture,
+                                                nullptr,
+                                                getter_AddRefs(mSRView));
+        if (FAILED(hr))
+          return;
+
         return;
       }
       case SharedSurfaceType::Basic: {
         SharedSurface_Basic* shareSurf = SharedSurface_Basic::Cast(surf);
         // WebGL reads entire surface.
         D3D10_MAPPED_TEXTURE2D map;
 
         HRESULT hr = mTexture->Map(0, D3D10_MAP_WRITE_DISCARD, 0, &map);