Bug 1860298 [wpt PR 42668] - [FedCM] Check "same origin with ancestors" for subresour...
[gecko.git] / gfx / layers / D3D11TextureIMFSampleImage.h
blob4077d386aa8b4c6cd89a182b52fc20bdbbfe7d99
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;
18 struct IMFSample;
20 namespace mozilla {
21 namespace gl {
22 class GLBlitHelper;
24 namespace layers {
26 class IMFSampleWrapper : public SupportsThreadSafeWeakPtr<IMFSampleWrapper> {
27 public:
28 MOZ_DECLARE_REFCOUNTED_TYPENAME(IMFSampleWrapper)
30 static RefPtr<IMFSampleWrapper> Create(IMFSample* aVideoSample);
31 virtual ~IMFSampleWrapper();
32 void ClearVideoSample();
34 protected:
35 explicit IMFSampleWrapper(IMFSample* aVideoSample);
37 RefPtr<IMFSample> mVideoSample;
40 class IMFSampleUsageInfo final {
41 public:
42 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(IMFSampleUsageInfo)
44 IMFSampleUsageInfo() = default;
46 bool SupportsZeroCopyNV12Texture() { return mSupportsZeroCopyNV12Texture; }
47 void DisableZeroCopyNV12Texture() { mSupportsZeroCopyNV12Texture = false; }
49 protected:
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 {
58 public:
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; }
79 private:
80 friend class gl::GLBlitHelper;
81 D3D11TextureData* GetData() const {
82 if (!mTextureClient) {
83 return nullptr;
85 return mTextureClient->GetInternalData()->AsD3D11TextureData();
88 // When ref of IMFSample is held, its ID3D11Texture2D is not reused by
89 // IMFTransform.
90 RefPtr<IMFSampleWrapper> mVideoSample;
91 RefPtr<ID3D11Texture2D> mTexture;
93 public:
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;
100 private:
101 RefPtr<TextureClient> mTextureClient;
104 } // namespace layers
105 } // namespace mozilla
107 #endif // GFX_D311_TEXTURE_IMF_SAMPLE_IMAGE_H