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"
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"
25 class D3D11RecycleAllocator final
: public TextureClientRecycleAllocator
{
27 D3D11RecycleAllocator(KnowsCompositor
* aAllocator
, ID3D11Device
* aDevice
,
28 gfx::SurfaceFormat aPreferredFormat
);
30 already_AddRefed
<TextureClient
> CreateOrRecycleClient(
31 gfx::ColorSpace2 aColorSpace
, gfx::ColorRange aColorRange
,
32 const gfx::IntSize
& aSize
);
34 void SetPreferredSurfaceFormat(gfx::SurfaceFormat aPreferredFormat
);
35 gfx::SurfaceFormat
GetUsableSurfaceFormat() const {
36 return mUsableSurfaceFormat
;
39 RefPtr
<ID3D11Texture2D
> GetStagingTextureNV12(gfx::IntSize aSize
);
41 void SetSyncObject(RefPtr
<SyncObjectClient
>& aSyncObject
) {
42 mSyncObject
= aSyncObject
;
45 RefPtr
<SyncObjectClient
> GetSyncObject() { return mSyncObject
; }
47 const RefPtr
<ID3D11Device
> mDevice
;
48 const bool mCanUseNV12
;
49 const bool mCanUseP010
;
50 const bool mCanUseP016
;
54 * Used for checking if CompositorDevice/ContentDevice is updated.
56 RefPtr
<ID3D11Device
> mImageDevice
;
57 gfx::SurfaceFormat mUsableSurfaceFormat
;
59 RefPtr
<ID3D11Texture2D
> mStagingTexture
;
60 gfx::IntSize mStagingTextureSize
;
62 RefPtr
<SyncObjectClient
> mSyncObject
;
65 // Image class that wraps a ID3D11Texture2D. This class copies the image
66 // passed into SetData(), so that it can be accessed from other D3D devices.
67 // This class also manages the synchronization of the copy, to ensure the
68 // resource is ready to use.
69 class D3D11ShareHandleImage final
: public Image
{
71 static RefPtr
<D3D11ShareHandleImage
> MaybeCreateNV12ImageAndSetData(
72 KnowsCompositor
* aAllocator
, ImageContainer
* aContainer
,
73 const PlanarYCbCrData
& aData
);
75 D3D11ShareHandleImage(const gfx::IntSize
& aSize
, const gfx::IntRect
& aRect
,
76 gfx::ColorSpace2 aColorSpace
,
77 gfx::ColorRange aColorRange
);
78 virtual ~D3D11ShareHandleImage() = default;
80 bool AllocateTexture(D3D11RecycleAllocator
* aAllocator
,
81 ID3D11Device
* aDevice
);
83 gfx::IntSize
GetSize() const override
;
84 already_AddRefed
<gfx::SourceSurface
> GetAsSourceSurface() override
;
85 nsresult
BuildSurfaceDescriptorBuffer(
86 SurfaceDescriptorBuffer
& aSdBuffer
, BuildSdbFlags aFlags
,
87 const std::function
<MemoryOrShmem(uint32_t)>& aAllocate
) override
;
88 TextureClient
* GetTextureClient(KnowsCompositor
* aKnowsCompositor
) override
;
89 gfx::IntRect
GetPictureRect() const override
{ return mPictureRect
; }
91 ID3D11Texture2D
* GetTexture() const;
93 gfx::ColorRange
GetColorRange() const { return mColorRange
; }
96 friend class gl::GLBlitHelper
;
97 D3D11TextureData
* GetData() const {
98 if (!mTextureClient
) {
101 return mTextureClient
->GetInternalData()->AsD3D11TextureData();
105 gfx::IntRect mPictureRect
;
108 const gfx::ColorSpace2 mColorSpace
;
111 gfx::ColorRange mColorRange
;
112 RefPtr
<TextureClient
> mTextureClient
;
113 RefPtr
<ID3D11Texture2D
> mTexture
;
116 } // namespace layers
117 } // namespace mozilla
119 #endif // GFX_D3DSURFACEIMAGE_H