Backed out 3 changesets (bug 1911476) for Doc failure on ExtensionContent.sys . CLOSE...
[gecko.git] / gfx / layers / GPUVideoImage.h
blobb511d55ccc31e73aa979653ad00aed2281b3d1e4
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 {
76 return mTransferFunction;
78 gfx::ColorRange GetColorRange() const { return mColorRange; }
80 Maybe<SurfaceDescriptor> GetDesc() override {
81 return GetDescFromTexClient(mTextureClient);
84 private:
85 GPUVideoTextureData* GetData() const {
86 if (!mTextureClient) {
87 return nullptr;
89 TextureData* data = mTextureClient->GetInternalData();
90 if (!data) {
91 return nullptr;
93 return data->AsGPUVideoTextureData();
96 public:
97 already_AddRefed<gfx::SourceSurface> GetAsSourceSurface() override {
98 GPUVideoTextureData* data = GetData();
99 if (!data) {
100 return nullptr;
102 return data->GetAsSourceSurface();
105 TextureClient* GetTextureClient(KnowsCompositor* aKnowsCompositor) override {
106 MOZ_ASSERT(aKnowsCompositor == ImageBridgeChild::GetSingleton(),
107 "Must only use GPUVideo on ImageBridge");
108 return mTextureClient;
111 private:
112 gfx::IntSize mSize;
113 gfx::ColorDepth mColorDepth;
114 gfx::ColorSpace2 mColorSpace;
115 gfx::YUVColorSpace mYUVColorSpace;
116 RefPtr<TextureClient> mTextureClient;
117 gfx::TransferFunction mTransferFunction;
118 gfx::ColorRange mColorRange;
121 } // namespace layers
122 } // namespace mozilla
124 #endif // GFX_GPU_VIDEO_IMAGE_H