Bug 1568876 - Make copyRule in the ChangesView fission compatible. r=rcaliman
[gecko.git] / gfx / layers / D3D11ShareHandleImage.h
blob730430185b920b4e5752fe53c9d47eaf341b9493
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_SHARE_HANDLE_IMAGE_H
8 #define GFX_D311_SHARE_HANDLE_IMAGE_H
10 #include "ImageContainer.h"
11 #include "d3d11.h"
12 #include "mozilla/Atomics.h"
13 #include "mozilla/RefPtr.h"
14 #include "mozilla/gfx/Types.h"
15 #include "mozilla/layers/TextureClient.h"
16 #include "mozilla/layers/TextureClientRecycleAllocator.h"
17 #include "mozilla/layers/TextureD3D11.h"
19 namespace mozilla {
20 namespace gl {
21 class GLBlitHelper;
23 namespace layers {
25 class D3D11RecycleAllocator final : public TextureClientRecycleAllocator {
26 public:
27 D3D11RecycleAllocator(KnowsCompositor* aAllocator, ID3D11Device* aDevice,
28 gfx::SurfaceFormat aPreferredFormat);
30 already_AddRefed<TextureClient> CreateOrRecycleClient(
31 gfx::YUVColorSpace aColorSpace, gfx::ColorRange aColorRange,
32 const gfx::IntSize& aSize);
34 void SetPreferredSurfaceFormat(gfx::SurfaceFormat aPreferredFormat);
36 private:
37 const RefPtr<ID3D11Device> mDevice;
38 const bool mCanUseNV12;
39 const bool mCanUseP010;
40 const bool mCanUseP016;
41 /**
42 * Used for checking if CompositorDevice/ContentDevice is updated.
44 RefPtr<ID3D11Device> mImageDevice;
45 gfx::SurfaceFormat mUsableSurfaceFormat;
48 // Image class that wraps a ID3D11Texture2D. This class copies the image
49 // passed into SetData(), so that it can be accessed from other D3D devices.
50 // This class also manages the synchronization of the copy, to ensure the
51 // resource is ready to use.
52 class D3D11ShareHandleImage final : public Image {
53 public:
54 D3D11ShareHandleImage(const gfx::IntSize& aSize, const gfx::IntRect& aRect,
55 gfx::YUVColorSpace aColorSpace,
56 gfx::ColorRange aColorRange);
57 virtual ~D3D11ShareHandleImage() = default;
59 bool AllocateTexture(D3D11RecycleAllocator* aAllocator,
60 ID3D11Device* aDevice);
62 gfx::IntSize GetSize() const override;
63 already_AddRefed<gfx::SourceSurface> GetAsSourceSurface() override;
64 TextureClient* GetTextureClient(KnowsCompositor* aKnowsCompositor) override;
65 gfx::IntRect GetPictureRect() const override { return mPictureRect; }
67 ID3D11Texture2D* GetTexture() const;
69 gfx::YUVColorSpace GetYUVColorSpace() const { return mYUVColorSpace; }
70 gfx::ColorRange GetColorRange() const { return mColorRange; }
72 private:
73 friend class gl::GLBlitHelper;
74 D3D11TextureData* GetData() const {
75 if (!mTextureClient) {
76 return nullptr;
78 return mTextureClient->GetInternalData()->AsD3D11TextureData();
81 gfx::IntSize mSize;
82 gfx::IntRect mPictureRect;
83 gfx::YUVColorSpace mYUVColorSpace;
84 gfx::ColorRange mColorRange;
85 RefPtr<TextureClient> mTextureClient;
86 RefPtr<ID3D11Texture2D> mTexture;
89 } // namespace layers
90 } // namespace mozilla
92 #endif // GFX_D3DSURFACEIMAGE_H