Backed out changeset 62ed9ebaa426 (bug 1933152) for causing bc failures @browser_ext_...
[gecko.git] / gfx / layers / D3D11TextureIMFSampleImage.h
blobf6882ecf418d3553969d1ff3c7675b5a63aedf4c
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 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; }
82 private:
83 friend class gl::GLBlitHelper;
84 D3D11TextureData* GetData() const {
85 if (!mTextureClient) {
86 return nullptr;
88 return mTextureClient->GetInternalData()->AsD3D11TextureData();
91 // When ref of IMFSample is held, its ID3D11Texture2D is not reused by
92 // IMFTransform.
93 RefPtr<IMFSampleWrapper> mVideoSample;
94 RefPtr<ID3D11Texture2D> mTexture;
96 public:
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;
103 private:
104 RefPtr<TextureClient> mTextureClient;
107 } // namespace layers
108 } // namespace mozilla
110 #endif // GFX_D311_TEXTURE_IMF_SAMPLE_IMAGE_H