Bug 1288618 - Part 9: Add a new SurfaceDescriptor type for video decoding in the GPU process. r=nical
☠☠ backed out by 8b6401bcb115 ☠ ☠
authorMatt Woodrow <mwoodrow@mozilla.com>
Wed, 21 Sep 2016 15:36:10 +1200
changeset 314689 8b0adeab93df2ac2b8c1d2a5f5f3ed0958411a7e
parent 314688 95f23366de82e2ce9ce846c65a17ec8fc05fa7ce
child 314690 f8bbdabdb6da5ca1682f2f5656ce49b4b6ac7d2f
push id30732
push usercbook@mozilla.com
push dateWed, 21 Sep 2016 10:04:03 +0000
treeherdermozilla-central@560b2c805bf7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnical
bugs1288618
milestone52.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 1288618 - Part 9: Add a new SurfaceDescriptor type for video decoding in the GPU process. r=nical
gfx/layers/client/GPUVideoTextureClient.cpp
gfx/layers/client/GPUVideoTextureClient.h
gfx/layers/composite/GPUVideoTextureHost.cpp
gfx/layers/composite/GPUVideoTextureHost.h
gfx/layers/composite/TextureHost.cpp
gfx/layers/ipc/LayersSurfaces.ipdlh
gfx/layers/moz.build
new file mode 100644
--- /dev/null
+++ b/gfx/layers/client/GPUVideoTextureClient.cpp
@@ -0,0 +1,51 @@
+/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * 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/. */
+
+#include "GPUVideoTextureClient.h"
+
+namespace mozilla {
+namespace layers {
+
+using namespace gfx;
+
+bool
+GPUVideoTextureData::Serialize(SurfaceDescriptor& aOutDescriptor)
+{
+  aOutDescriptor = mSD;
+  return true;
+}
+
+void
+GPUVideoTextureData::FillInfo(TextureData::Info& aInfo) const
+{
+  aInfo.size = mSize;
+  // TODO: We should probably try do better for this.
+  // layers::Image doesn't expose a format, so it's hard
+  // to figure out in VideoDecoderParent.
+  aInfo.format = SurfaceFormat::B8G8R8X8;
+  aInfo.hasIntermediateBuffer = false;
+  aInfo.hasSynchronization = false;
+  aInfo.supportsMoz2D = false;
+  aInfo.canExposeMappedData = false;
+}
+
+void
+GPUVideoTextureData::Deallocate(ClientIPCAllocator* aAllocator)
+{
+  mSD = SurfaceDescriptorGPUVideo();
+}
+
+void
+GPUVideoTextureData::Forget(ClientIPCAllocator* aAllocator)
+{
+  // We always need to manually deallocate on the client side.
+  // Ideally we'd set up our TextureClient with the DEALLOCATE_CLIENT
+  // flag, but that forces texture destruction to be synchronous.
+  // Instead let's just deallocate from here as well.
+  Deallocate(aAllocator);
+}
+
+} // namespace layers
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/gfx/layers/client/GPUVideoTextureClient.h
@@ -0,0 +1,45 @@
+/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * 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 MOZILLA_GFX_GPUVIDEOTEXTURECLIENT_H
+#define MOZILLA_GFX_GPUVIDEOTEXTURECLIENT_H
+
+#include "mozilla/layers/TextureClient.h"
+
+namespace mozilla {
+namespace layers {
+
+class GPUVideoTextureData : public TextureData
+{
+public:
+  GPUVideoTextureData(const SurfaceDescriptorGPUVideo& aSD,
+                      const gfx::IntSize& aSize)
+    : mSD(aSD)
+    , mSize(aSize)
+  {}
+
+  ~GPUVideoTextureData() {};
+
+  virtual void FillInfo(TextureData::Info& aInfo) const override;
+
+  virtual bool Lock(OpenMode, FenceHandle*) override { return true; };
+
+  virtual void Unlock() override {};
+
+  virtual bool Serialize(SurfaceDescriptor& aOutDescriptor) override;
+
+  virtual void Deallocate(ClientIPCAllocator* aAllocator) override;
+
+  virtual void Forget(ClientIPCAllocator* aAllocator) override;
+
+protected:
+  SurfaceDescriptorGPUVideo mSD;
+  gfx::IntSize mSize;
+};
+
+} // namespace layers
+} // namespace mozilla
+
+#endif // MOZILLA_GFX_GPUVIDEOTEXTURECLIENT_H
new file mode 100644
--- /dev/null
+++ b/gfx/layers/composite/GPUVideoTextureHost.cpp
@@ -0,0 +1,63 @@
+/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * 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/. */
+
+#include "GPUVideoTextureHost.h"
+#include "ImageContainer.h"
+
+namespace mozilla {
+namespace layers {
+
+GPUVideoTextureHost::GPUVideoTextureHost(TextureFlags aFlags,
+                                         const SurfaceDescriptorGPUVideo& aDescriptor)
+  : TextureHost(aFlags)
+{
+  MOZ_COUNT_CTOR(GPUVideoTextureHost);
+}
+
+GPUVideoTextureHost::~GPUVideoTextureHost()
+{
+  MOZ_COUNT_DTOR(GPUVideoTextureHost);
+}
+
+bool
+GPUVideoTextureHost::Lock()
+{
+  if (!mImage || !mCompositor) {
+    return false;
+  }
+
+  if (!mTextureSource) {
+    mTextureSource = mCompositor->CreateTextureSourceForImage(mImage);
+  }
+
+  return !!mTextureSource;
+}
+
+void
+GPUVideoTextureHost::SetCompositor(Compositor* aCompositor)
+{
+  if (mCompositor != aCompositor) {
+    mTextureSource = nullptr;
+    mCompositor = aCompositor;
+  }
+}
+
+gfx::IntSize
+GPUVideoTextureHost::GetSize() const
+{
+  if (!mImage) {
+    return gfx::IntSize();
+  }
+  return mImage->GetSize();
+}
+
+gfx::SurfaceFormat
+GPUVideoTextureHost::GetFormat() const
+{
+  return mTextureSource ? mTextureSource->GetFormat() : gfx::SurfaceFormat::UNKNOWN;
+}
+
+} // namespace layers
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/gfx/layers/composite/GPUVideoTextureHost.h
@@ -0,0 +1,57 @@
+/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * 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 MOZILLA_GFX_GPUVIDEOTEXTUREHOST_H
+#define MOZILLA_GFX_GPUVIDEOTEXTUREHOST_H
+
+#include "mozilla/layers/TextureHost.h"
+
+namespace mozilla {
+namespace layers {
+
+class GPUVideoTextureHost : public TextureHost
+{
+public:
+ GPUVideoTextureHost(TextureFlags aFlags,
+                     const SurfaceDescriptorGPUVideo& aDescriptor);
+  virtual ~GPUVideoTextureHost();
+
+  virtual void DeallocateDeviceData() override {}
+
+  virtual void SetCompositor(Compositor* aCompositor) override;
+
+  virtual Compositor* GetCompositor() override { return mCompositor; }
+
+  virtual bool Lock() override;
+
+  virtual gfx::SurfaceFormat GetFormat() const override;
+
+  virtual bool BindTextureSource(CompositableTextureSourceRef& aTexture) override
+  {
+    aTexture = mTextureSource;
+    return !!aTexture;
+  }
+
+  virtual already_AddRefed<gfx::DataSourceSurface> GetAsSurface() override
+  {
+    return nullptr; // XXX - implement this (for MOZ_DUMP_PAINTING)
+  }
+
+  virtual gfx::IntSize GetSize() const override;
+
+#ifdef MOZ_LAYERS_HAVE_LOG
+  virtual const char* Name() override { return "GPUVideoTextureHost"; }
+#endif
+
+protected:
+  RefPtr<Compositor> mCompositor;
+  RefPtr<TextureSource> mTextureSource;
+  RefPtr<Image> mImage;
+};
+
+} // namespace layers
+} // namespace mozilla
+
+#endif // MOZILLA_GFX_GPUVIDEOTEXTUREHOST_H
--- a/gfx/layers/composite/TextureHost.cpp
+++ b/gfx/layers/composite/TextureHost.cpp
@@ -14,16 +14,17 @@
 #include "mozilla/layers/CompositorBridgeParent.h"
 #include "mozilla/layers/Compositor.h"  // for Compositor
 #include "mozilla/layers/ISurfaceAllocator.h"  // for ISurfaceAllocator
 #include "mozilla/layers/LayersSurfaces.h"  // for SurfaceDescriptor, etc
 #include "mozilla/layers/TextureHostBasic.h"
 #include "mozilla/layers/TextureHostOGL.h"  // for TextureHostOGL
 #include "mozilla/layers/ImageDataSerializer.h"
 #include "mozilla/layers/TextureClient.h"
+#include "mozilla/layers/GPUVideoTextureHost.h"
 #include "nsAString.h"
 #include "mozilla/RefPtr.h"                   // for nsRefPtr
 #include "nsPrintfCString.h"            // for nsPrintfCString
 #include "mozilla/layers/PTextureParent.h"
 #include "mozilla/Unused.h"
 #include <limits>
 #include "../opengl/CompositorOGL.h"
 #include "gfxPrefs.h"
@@ -227,16 +228,17 @@ TextureHost::Create(const SurfaceDescrip
                     ISurfaceAllocator* aDeallocator,
                     LayersBackend aBackend,
                     TextureFlags aFlags)
 {
   switch (aDesc.type()) {
     case SurfaceDescriptor::TSurfaceDescriptorBuffer:
     case SurfaceDescriptor::TSurfaceDescriptorDIB:
     case SurfaceDescriptor::TSurfaceDescriptorFileMapping:
+    case SurfaceDescriptor::TSurfaceDescriptorGPUVideo:
       return CreateBackendIndependentTextureHost(aDesc, aDeallocator, aFlags);
 
     case SurfaceDescriptor::TEGLImageDescriptor:
     case SurfaceDescriptor::TSurfaceTextureDescriptor:
     case SurfaceDescriptor::TSurfaceDescriptorSharedGLTexture:
       return CreateTextureHostOGL(aDesc, aDeallocator, aFlags);
 
     case SurfaceDescriptor::TSurfaceDescriptorGralloc:
@@ -296,16 +298,20 @@ CreateBackendIndependentTextureHost(cons
           break;
         }
         default:
           gfxCriticalError() << "Failed texture host for backend " << (int)data.type();
           MOZ_CRASH("GFX: No texture host for backend");
       }
       break;
     }
+    case SurfaceDescriptor::TSurfaceDescriptorGPUVideo: {
+      result = new GPUVideoTextureHost(aFlags, aDesc.get_SurfaceDescriptorGPUVideo());
+      break;
+    }
 #ifdef XP_WIN
     case SurfaceDescriptor::TSurfaceDescriptorDIB: {
       result = new DIBTextureHost(aFlags, aDesc);
       break;
     }
     case SurfaceDescriptor::TSurfaceDescriptorFileMapping: {
       result = new TextureHostFileMapping(aFlags, aDesc);
       break;
--- a/gfx/layers/ipc/LayersSurfaces.ipdlh
+++ b/gfx/layers/ipc/LayersSurfaces.ipdlh
@@ -93,16 +93,20 @@ struct SurfaceDescriptorSharedGLTexture 
   bool hasAlpha;
 };
 
 struct SurfaceDescriptorGralloc {
   MaybeMagicGrallocBufferHandle buffer;
   bool isOpaque;
 };
 
+struct SurfaceDescriptorGPUVideo {
+  uint64_t handle;
+};
+
 struct RGBDescriptor {
   IntSize size;
   SurfaceFormat format;
   bool hasIntermediateBuffer;
 };
 
 struct YCbCrDescriptor {
   IntSize ySize;
@@ -137,13 +141,14 @@ union SurfaceDescriptor {
   SurfaceDescriptorFileMapping;
   SurfaceDescriptorDXGIYCbCr;
   SurfaceDescriptorX11;
   SurfaceTextureDescriptor;
   EGLImageDescriptor;
   SurfaceDescriptorMacIOSurface;
   SurfaceDescriptorGralloc;
   SurfaceDescriptorSharedGLTexture;
+  SurfaceDescriptorGPUVideo;
   null_t;
 };
 
 } // namespace
 } // namespace
--- a/gfx/layers/moz.build
+++ b/gfx/layers/moz.build
@@ -126,29 +126,31 @@ EXPORTS.mozilla.layers += [
     'basic/MacIOSurfaceTextureHostBasic.h',
     'basic/TextureHostBasic.h',
     'BSPTree.h',
     'BufferTexture.h',
     'client/CanvasClient.h',
     'client/CompositableChild.h',
     'client/CompositableClient.h',
     'client/ContentClient.h',
+    'client/GPUVideoTextureClient.h',
     'client/ImageClient.h',
     'client/SingleTiledContentClient.h',
     'client/TextureClient.h',
     'client/TextureClientPool.h',
     'client/TextureClientRecycleAllocator.h',
     'client/TextureClientSharedSurface.h',
     'client/TiledContentClient.h',
     'composite/AsyncCompositionManager.h',
     'composite/CanvasLayerComposite.h',
     'composite/ColorLayerComposite.h',
     'composite/ContainerLayerComposite.h',
     'composite/ContentHost.h',
     'composite/FrameUniformityData.h',
+    'composite/GPUVideoTextureHost.h',
     'composite/ImageHost.h',
     'composite/ImageLayerComposite.h',
     'composite/LayerManagerComposite.h',
     'composite/PaintedLayerComposite.h',
     'composite/TextureHost.h',
     'composite/TiledContentHost.h',
     'Compositor.h',
     'CompositorTypes.h',
@@ -317,31 +319,33 @@ UNIFIED_SOURCES += [
     'client/ClientContainerLayer.cpp',
     'client/ClientImageLayer.cpp',
     'client/ClientLayerManager.cpp',
     'client/ClientPaintedLayer.cpp',
     'client/ClientTiledPaintedLayer.cpp',
     'client/CompositableChild.cpp',
     'client/CompositableClient.cpp',
     'client/ContentClient.cpp',
+    'client/GPUVideoTextureClient.cpp',
     'client/ImageClient.cpp',
     'client/SingleTiledContentClient.cpp',
     'client/TextureClient.cpp',
     'client/TextureClientPool.cpp',
     'client/TextureClientRecycleAllocator.cpp',
     'client/TextureClientSharedSurface.cpp',
     'client/TiledContentClient.cpp',
     'composite/AsyncCompositionManager.cpp',
     'composite/CanvasLayerComposite.cpp',
     'composite/ColorLayerComposite.cpp',
     'composite/CompositableHost.cpp',
     'composite/ContainerLayerComposite.cpp',
     'composite/ContentHost.cpp',
     'composite/FPSCounter.cpp',
     'composite/FrameUniformityData.cpp',
+    'composite/GPUVideoTextureHost.cpp',
     'composite/ImageHost.cpp',
     'composite/ImageLayerComposite.cpp',
     'composite/LayerManagerComposite.cpp',
     'composite/PaintCounter.cpp',
     'composite/PaintedLayerComposite.cpp',
     'composite/TextRenderer.cpp',
     'composite/TextureHost.cpp',
     'composite/TiledContentHost.cpp',