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_D311_TEXTURE_IMF_SAMPLE_IMAGE_H
8 #define GFX_D311_TEXTURE_IMF_SAMPLE_IMAGE_H
10 #include "ImageContainer.h"
11 #include "mozilla/RefPtr.h"
12 #include "mozilla/gfx/Types.h"
13 #include "mozilla/layers/TextureClient.h"
14 #include "mozilla/layers/TextureD3D11.h"
15 #include "mozilla/ThreadSafeWeakPtr.h"
17 struct ID3D11Texture2D
;
26 class IMFSampleWrapper
: public SupportsThreadSafeWeakPtr
<IMFSampleWrapper
> {
28 MOZ_DECLARE_REFCOUNTED_TYPENAME(IMFSampleWrapper
)
30 static RefPtr
<IMFSampleWrapper
> Create(IMFSample
* aVideoSample
);
31 virtual ~IMFSampleWrapper();
32 void ClearVideoSample();
35 explicit IMFSampleWrapper(IMFSample
* aVideoSample
);
37 RefPtr
<IMFSample
> mVideoSample
;
40 class IMFSampleUsageInfo final
{
42 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(IMFSampleUsageInfo
)
44 IMFSampleUsageInfo() = default;
46 bool SupportsZeroCopyNV12Texture() { return mSupportsZeroCopyNV12Texture
; }
47 void DisableZeroCopyNV12Texture() { mSupportsZeroCopyNV12Texture
= false; }
50 ~IMFSampleUsageInfo() = default;
52 Atomic
<bool> mSupportsZeroCopyNV12Texture
{true};
55 // Image class that wraps ID3D11Texture2D of IMFSample
56 // Expected to be used in GPU process.
57 class D3D11TextureIMFSampleImage final
: public Image
{
59 D3D11TextureIMFSampleImage(IMFSample
* aVideoSample
, ID3D11Texture2D
* aTexture
,
60 uint32_t aArrayIndex
, const gfx::IntSize
& aSize
,
61 const gfx::IntRect
& aRect
,
62 gfx::ColorSpace2 aColorSpace
,
63 gfx::ColorRange aColorRange
);
64 virtual ~D3D11TextureIMFSampleImage() = default;
66 void AllocateTextureClient(KnowsCompositor
* aKnowsCompositor
,
67 RefPtr
<IMFSampleUsageInfo
> aUsageInfo
);
69 gfx::IntSize
GetSize() const override
;
70 already_AddRefed
<gfx::SourceSurface
> GetAsSourceSurface() override
;
71 nsresult
BuildSurfaceDescriptorBuffer(
72 SurfaceDescriptorBuffer
& aSdBuffer
, BuildSdbFlags aFlags
,
73 const std::function
<MemoryOrShmem(uint32_t)>& aAllocate
) override
;
74 TextureClient
* GetTextureClient(KnowsCompositor
* aKnowsCompositor
) override
;
75 gfx::IntRect
GetPictureRect() const override
{ return mPictureRect
; }
77 ID3D11Texture2D
* GetTexture() const;
78 RefPtr
<IMFSampleWrapper
> GetIMFSampleWrapper();
80 gfx::ColorRange
GetColorRange() const { return mColorRange
; }
83 friend class gl::GLBlitHelper
;
84 D3D11TextureData
* GetData() const {
85 if (!mTextureClient
) {
88 return mTextureClient
->GetInternalData()->AsD3D11TextureData();
91 // When ref of IMFSample is held, its ID3D11Texture2D is not reused by
93 RefPtr
<IMFSampleWrapper
> mVideoSample
;
94 RefPtr
<ID3D11Texture2D
> mTexture
;
97 const uint32_t mArrayIndex
;
98 const gfx::IntSize mSize
;
99 const gfx::IntRect mPictureRect
;
100 const gfx::ColorSpace2 mColorSpace
;
101 const gfx::ColorRange mColorRange
;
104 RefPtr
<TextureClient
> mTextureClient
;
107 } // namespace layers
108 } // namespace mozilla
110 #endif // GFX_D311_TEXTURE_IMF_SAMPLE_IMAGE_H