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"
22 class IGPUVideoSurfaceManager
{
24 virtual ~IGPUVideoSurfaceManager() = default;
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
;
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
),
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
);
83 GPUVideoTextureData
* GetData() const {
84 if (!mTextureClient
) {
87 TextureData
* data
= mTextureClient
->GetInternalData();
91 return data
->AsGPUVideoTextureData();
95 already_AddRefed
<gfx::SourceSurface
> GetAsSourceSurface() override
{
96 GPUVideoTextureData
* data
= GetData();
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
;
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