Bug 1543339 - Add D3D11ShareHandleImage support to GLBlitHelper. r=jgilbert
authorJean-Yves Avenard <jyavenard@mozilla.com>
Wed, 10 Apr 2019 20:54:57 +0000
changeset 469148 aa39f59b4c79f1714a94265a0ac1ff6abaf95e98
parent 469147 ee00c85b09c5980f33100ea03b7f09c32f5fce64
child 469149 83ab9bf5138e6e4a4d1ab32fa5ae672593141dfc
push id35856
push usercsabou@mozilla.com
push dateFri, 12 Apr 2019 03:19:48 +0000
treeherdermozilla-central@940684cd1065 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgilbert
bugs1543339
milestone68.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 1543339 - Add D3D11ShareHandleImage support to GLBlitHelper. r=jgilbert Differential Revision: https://phabricator.services.mozilla.com/D26877
gfx/gl/GLBlitHelper.cpp
gfx/gl/GLBlitHelper.h
gfx/gl/GLBlitHelperD3D.cpp
gfx/layers/D3D11ShareHandleImage.cpp
gfx/layers/D3D11ShareHandleImage.h
gfx/layers/d3d11/TextureD3D11.h
--- a/gfx/gl/GLBlitHelper.cpp
+++ b/gfx/gl/GLBlitHelper.cpp
@@ -25,16 +25,21 @@
 #  include "GLLibraryEGL.h"
 #endif
 
 #ifdef XP_MACOSX
 #  include "MacIOSurfaceImage.h"
 #  include "GLContextCGL.h"
 #endif
 
+#ifdef XP_WIN
+#  include "mozilla/layers/D3D11ShareHandleImage.h"
+#  include "mozilla/layers/D3D11YCbCrImage.h"
+#endif
+
 using mozilla::layers::PlanarYCbCrData;
 using mozilla::layers::PlanarYCbCrImage;
 
 namespace mozilla {
 namespace gl {
 
 // --
 
@@ -687,19 +692,22 @@ bool GLBlitHelper::BlitImageToFramebuffe
 #ifdef XP_MACOSX
     case ImageFormat::MAC_IOSURFACE:
       return BlitImage(srcImage->AsMacIOSurfaceImage(), destSize, destOrigin);
 #endif
 #ifdef XP_WIN
     case ImageFormat::GPU_VIDEO:
       return BlitImage(static_cast<layers::GPUVideoImage*>(srcImage), destSize,
                        destOrigin);
+    case ImageFormat::D3D11_SHARE_HANDLE_TEXTURE:
+      return BlitImage(static_cast<layers::D3D11ShareHandleImage*>(srcImage),
+                       destSize, destOrigin);
     case ImageFormat::D3D11_YCBCR_IMAGE:
-      return BlitImage((layers::D3D11YCbCrImage*)srcImage, destSize,
-                       destOrigin);
+      return BlitImage(static_cast<layers::D3D11YCbCrImage*>(srcImage),
+                       destSize, destOrigin);
     case ImageFormat::D3D9_RGB32_TEXTURE:
       return false;  // todo
 #endif
     default:
       gfxCriticalError() << "Unhandled srcImage->GetFormat(): "
                          << uint32_t(srcImage->GetFormat());
       return false;
   }
--- a/gfx/gl/GLBlitHelper.h
+++ b/gfx/gl/GLBlitHelper.h
@@ -17,16 +17,17 @@
 
 #ifdef XP_WIN
 #  include <windows.h>
 #endif
 
 namespace mozilla {
 
 namespace layers {
+class D3D11ShareHandleImage;
 class D3D11YCbCrImage;
 class Image;
 class GPUVideoImage;
 class PlanarYCbCrImage;
 class SurfaceTextureImage;
 class MacIOSurfaceImage;
 class SurfaceDescriptorD3D10;
 class SurfaceDescriptorDXGIYCbCr;
@@ -184,16 +185,18 @@ class GLBlitHelper final {
                               const gfx::IntSize& destSize,
                               OriginPos destOrigin);
 
  private:
 #ifdef XP_WIN
   // GLBlitHelperD3D.cpp:
   bool BlitImage(layers::GPUVideoImage* srcImage, const gfx::IntSize& destSize,
                  OriginPos destOrigin) const;
+  bool BlitImage(layers::D3D11ShareHandleImage* srcImage,
+                 const gfx::IntSize& destSize, OriginPos destOrigin) const;
   bool BlitImage(layers::D3D11YCbCrImage* srcImage,
                  const gfx::IntSize& destSize, OriginPos destOrigin) const;
 
   bool BlitDescriptor(const layers::SurfaceDescriptorD3D10& desc,
                       const gfx::IntSize& destSize, OriginPos destOrigin) const;
 
   bool BlitAngleYCbCr(const WindowsHandle (&handleList)[3],
                       const gfx::IntRect& clipRect, const gfx::IntSize& ySize,
--- a/gfx/gl/GLBlitHelperD3D.cpp
+++ b/gfx/gl/GLBlitHelperD3D.cpp
@@ -8,16 +8,17 @@
 
 #include <d3d11.h>
 
 #include "GLContext.h"
 #include "GLLibraryEGL.h"
 #include "GPUVideoImage.h"
 #include "ScopedGLHelpers.h"
 
+#include "mozilla/layers/D3D11ShareHandleImage.h"
 #include "mozilla/layers/D3D11YCbCrImage.h"
 #include "mozilla/layers/TextureD3D11.h"
 
 namespace mozilla {
 namespace gl {
 
 static EGLStreamKHR StreamFromD3DTexture(ID3D11Texture2D* const texD3D,
                                          const EGLAttrib* const postAttribs) {
@@ -196,16 +197,30 @@ bool GLBlitHelper::BlitImage(layers::GPU
       gfxCriticalError() << "Unhandled subdesc type: "
                          << uint32_t(subdescUnion.type());
       return false;
   }
 }
 
 // -------------------------------------
 
+bool GLBlitHelper::BlitImage(layers::D3D11ShareHandleImage* const srcImage,
+                             const gfx::IntSize& destSize,
+                             const OriginPos destOrigin) const {
+  const auto& data = srcImage->GetData();
+  if (!data) return false;
+
+  layers::SurfaceDescriptorD3D10 desc;
+  if (!data->SerializeSpecific(&desc)) return false;
+
+  return BlitDescriptor(desc, destSize, destOrigin);
+}
+
+// -------------------------------------
+
 bool GLBlitHelper::BlitImage(layers::D3D11YCbCrImage* const srcImage,
                              const gfx::IntSize& destSize,
                              const OriginPos destOrigin) const {
   const auto& data = srcImage->GetData();
   if (!data) return false;
 
   const WindowsHandle handles[3] = {(WindowsHandle)data->mHandles[0],
                                     (WindowsHandle)data->mHandles[1],
--- a/gfx/layers/D3D11ShareHandleImage.cpp
+++ b/gfx/layers/D3D11ShareHandleImage.cpp
@@ -31,18 +31,17 @@ D3D11ShareHandleImage::D3D11ShareHandleI
       mPictureRect(aRect),
       mYUVColorSpace(aColorSpace) {}
 
 bool D3D11ShareHandleImage::AllocateTexture(D3D11RecycleAllocator* aAllocator,
                                             ID3D11Device* aDevice) {
   if (aAllocator) {
     mTextureClient = aAllocator->CreateOrRecycleClient(mYUVColorSpace, mSize);
     if (mTextureClient) {
-      D3D11TextureData* textureData =
-          mTextureClient->GetInternalData()->AsD3D11TextureData();
+      D3D11TextureData* textureData = GetData();
       MOZ_DIAGNOSTIC_ASSERT(textureData, "Wrong TextureDataType");
       mTexture = textureData->GetD3D11Texture();
       return true;
     }
     return false;
   } else {
     MOZ_ASSERT(aDevice);
     CD3D11_TEXTURE2D_DESC newDesc(
--- a/gfx/layers/D3D11ShareHandleImage.h
+++ b/gfx/layers/D3D11ShareHandleImage.h
@@ -12,16 +12,19 @@
 #include "mozilla/Atomics.h"
 #include "mozilla/RefPtr.h"
 #include "mozilla/gfx/Types.h"
 #include "mozilla/layers/TextureClient.h"
 #include "mozilla/layers/TextureClientRecycleAllocator.h"
 #include "mozilla/layers/TextureD3D11.h"
 
 namespace mozilla {
+namespace gl {
+class GLBlitHelper;
+}
 namespace layers {
 
 class D3D11RecycleAllocator final : public TextureClientRecycleAllocator {
  public:
   D3D11RecycleAllocator(KnowsCompositor* aAllocator, ID3D11Device* aDevice,
                         gfx::SurfaceFormat aPreferredFormat);
 
   already_AddRefed<TextureClient> CreateOrRecycleClient(
@@ -59,16 +62,24 @@ class D3D11ShareHandleImage final : publ
   TextureClient* GetTextureClient(KnowsCompositor* aForwarder) override;
   gfx::IntRect GetPictureRect() const override { return mPictureRect; }
 
   ID3D11Texture2D* GetTexture() const;
 
   gfx::YUVColorSpace GetYUVColorSpace() const { return mYUVColorSpace; }
 
  private:
+  friend class gl::GLBlitHelper;
+  D3D11TextureData* GetData() const {
+    if (!mTextureClient) {
+      return nullptr;
+    }
+    return mTextureClient->GetInternalData()->AsD3D11TextureData();
+  }
+
   gfx::IntSize mSize;
   gfx::IntRect mPictureRect;
   gfx::YUVColorSpace mYUVColorSpace;
   RefPtr<TextureClient> mTextureClient;
   RefPtr<ID3D11Texture2D> mTexture;
 };
 
 }  // namespace layers
--- a/gfx/layers/d3d11/TextureD3D11.h
+++ b/gfx/layers/d3d11/TextureD3D11.h
@@ -95,16 +95,17 @@ class D3D11TextureData final : public Te
   D3D11TextureData(ID3D11Texture2D* aTexture, gfx::IntSize aSize,
                    gfx::SurfaceFormat aFormat, TextureAllocationFlags aFlags);
   virtual ~D3D11TextureData();
 
   void GetDXGIResource(IDXGIResource** aOutResource);
 
   bool PrepareDrawTargetInLock(OpenMode aMode);
 
+  friend class gl::GLBlitHelper;
   bool SerializeSpecific(SurfaceDescriptorD3D10* aOutDesc);
 
   static D3D11TextureData* Create(gfx::IntSize aSize,
                                   gfx::SurfaceFormat aFormat,
                                   gfx::SourceSurface* aSurface,
                                   TextureAllocationFlags aAllocFlags,
                                   ID3D11Device* aDevice = nullptr);