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 TextureClient
* GetTextureClient(KnowsCompositor
* aKnowsCompositor
) override
;
72 gfx::IntRect
GetPictureRect() const override
{ return mPictureRect
; }
74 ID3D11Texture2D
* GetTexture() const;
75 RefPtr
<IMFSampleWrapper
> GetIMFSampleWrapper();
77 gfx::ColorRange
GetColorRange() const { return mColorRange
; }
80 friend class gl::GLBlitHelper
;
81 D3D11TextureData
* GetData() const {
82 if (!mTextureClient
) {
85 return mTextureClient
->GetInternalData()->AsD3D11TextureData();
88 // When ref of IMFSample is held, its ID3D11Texture2D is not reused by
90 RefPtr
<IMFSampleWrapper
> mVideoSample
;
91 RefPtr
<ID3D11Texture2D
> mTexture
;
94 const uint32_t mArrayIndex
;
95 const gfx::IntSize mSize
;
96 const gfx::IntRect mPictureRect
;
97 const gfx::ColorSpace2 mColorSpace
;
98 const gfx::ColorRange mColorRange
;
101 RefPtr
<TextureClient
> mTextureClient
;
104 } // namespace layers
105 } // namespace mozilla
107 #endif // GFX_D311_TEXTURE_IMF_SAMPLE_IMAGE_H