Backed out changeset d1b96309bb9d (bug 1000640)
authorEd Morley <emorley@mozilla.com>
Wed, 11 Jun 2014 17:07:14 +0100
changeset 188123 6b72f1fad830bb78ecc0aeace41e371b29593584
parent 188122 2515e665defedf975e43a547ca6824802912a8f2
child 188124 634de90c950f2d8c74494b2e5d0671646ae070aa
push id44756
push useremorley@mozilla.com
push dateWed, 11 Jun 2014 16:07:59 +0000
treeherdermozilla-inbound@3cf701c3b021 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1000640
milestone33.0a1
backs outd1b96309bb9d285edd4b8a9f0a44497897b7077c
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
Backed out changeset d1b96309bb9d (bug 1000640)
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,29 +9,30 @@
 
 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, caps);
+    return new SurfaceFactory_ANGLEShareHandle(gl, egl, d3d, caps);
 }
 
 EGLDisplay
 SharedSurface_ANGLEShareHandle::Display()
 {
     return mEGL->Display();
 }
 
@@ -165,76 +166,114 @@ 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,
+SharedSurface_ANGLEShareHandle::Create(GLContext* gl, ID3D10Device1* d3d,
                                        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;
-    bool ok = egl->fQuerySurfacePointerANGLE(display,
-                                             pbuffer,
-                                             LOCAL_EGL_D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE,
-                                             &shareHandle);
-    if (!ok) {
+    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");
         egl->fDestroySurface(egl->Display(), pbuffer);
         return nullptr;
     }
 
     return new SharedSurface_ANGLEShareHandle(gl, egl,
                                               size, hasAlpha,
                                               context, pbuffer,
-                                              shareHandle);
+                                              texture, srv);
 }
 
 
 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,101 +7,108 @@
 #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,
+    static SharedSurface_ANGLEShareHandle* Create(GLContext* gl, ID3D10Device1* d3d,
                                                   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;
-    const HANDLE mShareHandle;
+    nsRefPtr<ID3D10Texture2D> mTexture;
+    nsRefPtr<ID3D10ShaderResourceView> mSRV;
 
     SharedSurface_ANGLEShareHandle(GLContext* gl,
                                    GLLibraryEGL* egl,
                                    const gfx::IntSize& size,
                                    bool hasAlpha,
                                    EGLContext context,
                                    EGLSurface pbuffer,
-                                   HANDLE shareHandle)
+                                   ID3D10Texture2D* texture,
+                                   ID3D10ShaderResourceView* srv)
         : SharedSurface_GL(SharedSurfaceType::EGLSurfaceANGLE,
                            AttachmentType::Screen,
                            gl,
                            size,
                            hasAlpha)
         , mEGL(egl)
         , mContext(context)
         , mPBuffer(pbuffer)
-        , mShareHandle(shareHandle)
+        , mTexture(texture)
+        , mSRV(srv)
     {}
 
     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:
-    HANDLE GetShareHandle() {
-        return mShareHandle;
+    ID3D10ShaderResourceView* GetSRV() {
+        return mSRV;
     }
 };
 
 
 
 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,
+        return SharedSurface_ANGLEShareHandle::Create(mProdGL, mConsD3D,
                                                       mContext, mConfig,
                                                       size, hasAlpha);
     }
 };
 
 } /* namespace gfx */
 } /* namespace mozilla */
 
--- a/gfx/gl/SharedSurfaceGralloc.cpp
+++ b/gfx/gl/SharedSurfaceGralloc.cpp
@@ -114,37 +114,16 @@ 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,22 +2,23 @@
 /* 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
@@ -34,26 +35,37 @@ public:
 
         return (SharedSurface_Gralloc*)surf;
     }
 
 protected:
     GLLibraryEGL* const mEGL;
     EGLSync mSync;
     RefPtr<layers::ISurfaceAllocator> mAllocator;
-    RefPtr<layers::GrallocTextureClientOGL> mTextureClient;
+    RefPtr<layers::TextureClient> mTextureClient;
     const GLuint mProdTex;
 
     SharedSurface_Gralloc(GLContext* prodGL,
                           const gfx::IntSize& size,
                           bool hasAlpha,
                           GLLibraryEGL* egl,
                           layers::ISurfaceAllocator* allocator,
-                          layers::GrallocTextureClientOGL* textureClient,
-                          GLuint prodTex);
+                          layers::TextureClient* textureClient,
+                          GLuint prodTex)
+        : SharedSurface_GL(SharedSurfaceType::Gralloc,
+                           AttachmentType::GLTexture,
+                           prodGL,
+                           size,
+                           hasAlpha)
+        , mEGL(egl)
+        , mSync(0)
+        , mAllocator(allocator)
+        , mTextureClient(textureClient)
+        , mProdTex(prodTex)
+    {}
 
     static bool HasExtensions(GLLibraryEGL* egl, GLContext* gl);
 
 public:
     virtual ~SharedSurface_Gralloc();
 
     virtual void Fence() MOZ_OVERRIDE;
     virtual bool WaitSync() MOZ_OVERRIDE;
@@ -62,17 +74,17 @@ public:
 
     virtual void LockProdImpl() MOZ_OVERRIDE {}
     virtual void UnlockProdImpl() MOZ_OVERRIDE {}
 
     virtual GLuint ProdTexture() MOZ_OVERRIDE {
         return mProdTex;
     }
 
-    layers::GrallocTextureClientOGL* GetTextureClient() {
+    layers::TextureClient* 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', # Needs <windows.h> for `HANDLE`.
+        'SharedSurfaceANGLE.h',
         '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,16 +50,17 @@ 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) {
@@ -124,30 +125,18 @@ 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();
 
-        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;
-
+        mSRView = shareSurf->GetSRV();
         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);