Bug 1288618 - Part 10: Add a new layers::Image type for GPUVideo. r?nical draft
authorMatt Woodrow <mwoodrow@mozilla.com>
Thu, 15 Sep 2016 14:24:23 +1200
changeset 413863 d2c6d73d63ffb8dfbb810330af32f3806ead2935
parent 413862 8af89c48cbd71fae0ed8c5e3a0c55c18325419a9
child 413864 4520e760fbe5bd8496b3352bac5e812e5ccc5f32
push id29543
push usermwoodrow@mozilla.com
push dateThu, 15 Sep 2016 02:36:28 +0000
reviewersnical
bugs1288618
milestone51.0a1
Bug 1288618 - Part 10: Add a new layers::Image type for GPUVideo. r?nical * * * [mq]: gpu-image MozReview-Commit-ID: 3adchbEI5vM
gfx/layers/GPUVideoImage.h
gfx/layers/ImageTypes.h
gfx/layers/moz.build
new file mode 100644
--- /dev/null
+++ b/gfx/layers/GPUVideoImage.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 GFX_GPU_VIDEO_IMAGE_H
+#define GFX_GPU_VIDEO_IMAGE_H
+
+#include "mozilla/RefPtr.h"
+#include "ImageContainer.h"
+#include "mozilla/layers/GPUVideoTextureClient.h"
+#include "mozilla/layers/CompositableClient.h"
+#include "mozilla/layers/ImageBridgeChild.h"
+
+namespace mozilla {
+namespace layers {
+
+// Image class that refers to a decoded video frame within
+// the GPU process.
+class GPUVideoImage final : public Image {
+public:
+  GPUVideoImage(const SurfaceDescriptorGPUVideo& aSD,
+                const gfx::IntSize& aSize)
+    : Image(nullptr, ImageFormat::GPU_VIDEO)
+    , mSize(aSize)
+  {
+    // Create the TextureClient immediately since the GPUVideoTextureData
+    // is responsible for deallocating the SurfaceDescriptor.
+    mTextureClient =
+      TextureClient::CreateWithData(new GPUVideoTextureData(aSD, aSize),
+                                    TextureFlags::DEFAULT,
+                                    ImageBridgeChild::GetSingleton().get());
+  }
+
+  ~GPUVideoImage() override {}
+
+  gfx::IntSize GetSize() override { return mSize; }
+
+  // TODO: We really want to be able to support this, but it's complex, since we need to readback
+  // in the other process and send it across.
+  virtual already_AddRefed<gfx::SourceSurface> GetAsSourceSurface() override { return nullptr; }
+
+  virtual TextureClient* GetTextureClient(CompositableClient* aClient) override
+  {
+    MOZ_ASSERT(aClient->GetForwarder() == ImageBridgeChild::GetSingleton(), "Must only use GPUVideo on ImageBridge");
+    return mTextureClient;
+  }
+
+private:
+  gfx::IntSize mSize;
+  RefPtr<TextureClient> mTextureClient;
+};
+
+} // namepace layers
+} // namespace mozilla
+
+#endif // GFX_GPU_VIDEO_IMAGE_H
--- a/gfx/layers/ImageTypes.h
+++ b/gfx/layers/ImageTypes.h
@@ -92,17 +92,23 @@ enum class ImageFormat {
   /**
    * A share handle to a ID3D11Texture2D.
    */
   D3D11_SHARE_HANDLE_TEXTURE,
 
   /**
    * A wrapper around a drawable TextureClient.
    */
-  TEXTURE_WRAPPER
+  TEXTURE_WRAPPER,
+
+  /**
+   * An opaque handle that refers to an Image stored in the GPU
+   * process.
+   */
+  GPU_VIDEO
 };
 
 enum class StereoMode {
   MONO,
   LEFT_RIGHT,
   RIGHT_LEFT,
   BOTTOM_TOP,
   TOP_BOTTOM,
--- a/gfx/layers/moz.build
+++ b/gfx/layers/moz.build
@@ -20,16 +20,17 @@ EXPORTS += [
     'client/ClientTiledPaintedLayer.h',
     'composite/CompositableHost.h',
     'composite/ImageHost.h',
     'CompositorTypes.h',
     'CopyableCanvasLayer.h',
     'D3D9SurfaceImage.h',
     'FrameMetrics.h',
     'GLImages.h',
+    'GPUVideoImage.h',
     'GrallocImages.h',
     'ImageContainer.h',
     'ImageLayers.h',
     'ImageTypes.h',
     'IMFYCbCrImage.h',
     'ipc/ThreadSafeRefcountingWithMainThreadDestruction.h',
     'Layers.h',
     'LayerScope.h',