Update configs. IGNORE BROKEN CHANGESETS CLOSED TREE NO BUG a=release ba=release
[gecko.git] / gfx / layers / GPUVideoImage.h
bloba9bbb5950d160b39eccf72b526931ce906e25f0d
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef GFX_GPU_VIDEO_IMAGE_H
8 #define GFX_GPU_VIDEO_IMAGE_H
10 #include "mozilla/RefPtr.h"
11 #include "ImageContainer.h"
12 #include "mozilla/layers/GPUVideoTextureClient.h"
13 #include "mozilla/layers/CompositableClient.h"
14 #include "mozilla/layers/ImageBridgeChild.h"
16 namespace mozilla {
17 namespace gl {
18 class GLBlitHelper;
20 namespace layers {
22 class IGPUVideoSurfaceManager {
23 protected:
24 virtual ~IGPUVideoSurfaceManager() = default;
26 public:
27 NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING
29 virtual already_AddRefed<gfx::SourceSurface> Readback(
30 const SurfaceDescriptorGPUVideo& aSD) = 0;
31 virtual void DeallocateSurfaceDescriptor(
32 const SurfaceDescriptorGPUVideo& aSD) = 0;
35 // Represents an animated Image that is known to the GPU process.
36 class GPUVideoImage final : public Image {
37 friend class gl::GLBlitHelper;
39 public:
40 GPUVideoImage(IGPUVideoSurfaceManager* aManager,
41 const SurfaceDescriptorGPUVideo& aSD, const gfx::IntSize& aSize,
42 const gfx::ColorDepth& aColorDepth,
43 gfx::YUVColorSpace aYUVColorSpace,
44 gfx::ColorSpace2 aColorPrimaries,
45 gfx::TransferFunction aTransferFunction,
46 gfx::ColorRange aColorRange)
47 : Image(nullptr, ImageFormat::GPU_VIDEO),
48 mSize(aSize),
49 mColorDepth(aColorDepth),
50 mColorSpace(aColorPrimaries),
51 mYUVColorSpace(aYUVColorSpace),
52 mTransferFunction(aTransferFunction),
53 mColorRange(aColorRange) {
54 // Create the TextureClient immediately since the GPUVideoTextureData
55 // is responsible for deallocating the SurfaceDescriptor.
57 // Use the RECYCLE texture flag, since it's likely that our 'real'
58 // TextureData (in the decoder thread of the GPU process) is using
59 // it too, and we want to make sure we don't send the delete message
60 // until we've stopped being used on the compositor.
61 mTextureClient = TextureClient::CreateWithData(
62 new GPUVideoTextureData(aManager, aSD, aSize), TextureFlags::RECYCLE,
63 ImageBridgeChild::GetSingleton().get());
66 virtual ~GPUVideoImage() = default;
68 GPUVideoImage* AsGPUVideoImage() override { return this; }
70 gfx::IntSize GetSize() const override { return mSize; }
72 gfx::ColorDepth GetColorDepth() const override { return mColorDepth; }
73 gfx::ColorSpace2 GetColorPrimaries() const { return mColorSpace; }
74 gfx::YUVColorSpace GetYUVColorSpace() const { return mYUVColorSpace; }
75 gfx::TransferFunction GetTransferFunction() const { return mTransferFunction; }
76 gfx::ColorRange GetColorRange() const { return mColorRange; }
78 Maybe<SurfaceDescriptor> GetDesc() override {
79 return GetDescFromTexClient(mTextureClient);
82 private:
83 GPUVideoTextureData* GetData() const {
84 if (!mTextureClient) {
85 return nullptr;
87 TextureData* data = mTextureClient->GetInternalData();
88 if (!data) {
89 return nullptr;
91 return data->AsGPUVideoTextureData();
94 public:
95 already_AddRefed<gfx::SourceSurface> GetAsSourceSurface() override {
96 GPUVideoTextureData* data = GetData();
97 if (!data) {
98 return nullptr;
100 return data->GetAsSourceSurface();
103 TextureClient* GetTextureClient(KnowsCompositor* aKnowsCompositor) override {
104 MOZ_ASSERT(aKnowsCompositor == ImageBridgeChild::GetSingleton(),
105 "Must only use GPUVideo on ImageBridge");
106 return mTextureClient;
109 private:
110 gfx::IntSize mSize;
111 gfx::ColorDepth mColorDepth;
112 gfx::ColorSpace2 mColorSpace;
113 gfx::YUVColorSpace mYUVColorSpace;
114 RefPtr<TextureClient> mTextureClient;
115 gfx::TransferFunction mTransferFunction;
116 gfx::ColorRange mColorRange;
119 } // namespace layers
120 } // namespace mozilla
122 #endif // GFX_GPU_VIDEO_IMAGE_H