Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
GrD3DTextureResource.h
Go to the documentation of this file.
1/*
2 * Copyright 2020 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef GrD3DTextureResource_DEFINED
9#define GrD3DTextureResource_DEFINED
10
17
18class GrD3DGpu;
19
21private:
22 class Resource;
23
24public:
26 : fInfo(info)
27 , fState(std::move(state))
28 , fResource(new Resource(fInfo.fResource, info.fAlloc)) {
29 // gr_cp will implicitly ref the ID3D12Resource for us, so we don't need to worry about
30 // whether it's borrowed or not
31 }
32 virtual ~GrD3DTextureResource();
33
34 ID3D12Resource* d3dResource() const {
35 SkASSERT(fResource);
36 return fInfo.fResource.get();
37 }
38 DXGI_FORMAT dxgiFormat() const { return fInfo.fFormat; }
40 return GrBackendFormat::MakeDxgi(this->dxgiFormat());
41 }
43 SkASSERT(fResource);
44 return fResource;
45 }
46 uint32_t mipLevels() const { return fInfo.fLevelCount; }
47
49
50 D3D12_RESOURCE_STATES currentState() const {
51 return fState->getResourceState();
52 }
53
54 void setResourceState(const GrD3DGpu* gpu, D3D12_RESOURCE_STATES newResourceState,
55 unsigned int subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES);
56
57 // Changes the layout to present
58 void prepareForPresent(GrD3DGpu* gpu);
59
60 unsigned int sampleQualityPattern() const { return fInfo.fSampleQualityPattern; }
61
62 // This simply updates our tracking of the resourceState and does not actually do any gpu work.
63 // Externally, primarily used for implicit changes in resourceState due to certain GPU commands.
64 void updateResourceState(D3D12_RESOURCE_STATES newState) {
65 SkASSERT(fResource);
66 fState->setResourceState(newState);
67 }
68
69 static bool InitTextureResourceInfo(GrD3DGpu* gpu, const D3D12_RESOURCE_DESC& desc,
70 D3D12_RESOURCE_STATES initialState, GrProtected,
71 D3D12_CLEAR_VALUE*, GrD3DTextureResourceInfo*);
72 static std::pair<GrD3DTextureResourceInfo, sk_sp<GrD3DResourceState>> CreateMSAA(
73 GrD3DGpu* gpu, SkISize dimensions, int sampleCnt, const GrD3DTextureResourceInfo& info,
74 SkColor4f clearColor);
75
77
78protected:
79 void releaseResource(GrD3DGpu* gpu);
80
83
84private:
85 class Resource : public GrTextureResource {
86 public:
87 explicit Resource()
88 : fResource(nullptr)
89 , fAlloc(nullptr) {
90 }
91
92 Resource(const gr_cp<ID3D12Resource>& textureResource,
93 const sk_sp<GrD3DAlloc>& alloc)
94 : fResource(textureResource)
95 , fAlloc(alloc) {
96 }
97
98 ~Resource() override {}
99
100#ifdef SK_TRACE_MANAGED_RESOURCES
101 void dumpInfo() const override {
102 SkDebugf("GrD3DTextureResource: %p (%d refs)\n", fResource.get(), this->getRefCnt());
103 }
104#endif
105
106 private:
107 void freeGPUData() const override;
108
109 mutable gr_cp<ID3D12Resource> fResource;
110 mutable sk_sp<GrD3DAlloc> fAlloc;
111
113 };
114
115 sk_sp<Resource> fResource;
116
117 friend class GrD3DRenderTarget;
118};
119
120#endif
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
#define SkASSERT(cond)
Definition SkAssert.h:116
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
#define INHERITED(method,...)
void setResourceState(D3D12_RESOURCE_STATES state)
D3D12_RESOURCE_STATES getResourceState() const
DXGI_FORMAT dxgiFormat() const
GrD3DTextureResourceInfo fInfo
void prepareForPresent(GrD3DGpu *gpu)
void setResourceState(const GrD3DGpu *gpu, D3D12_RESOURCE_STATES newResourceState, unsigned int subresource=D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES)
void updateResourceState(D3D12_RESOURCE_STATES newState)
ID3D12Resource * d3dResource() const
GrBackendFormat getBackendFormat() const
D3D12_RESOURCE_STATES currentState() const
void setResourceRelease(sk_sp< GrSurface::RefCntedReleaseProc > releaseHelper)
void releaseResource(GrD3DGpu *gpu)
sk_sp< GrD3DResourceState > grD3DResourceState() const
static bool InitTextureResourceInfo(GrD3DGpu *gpu, const D3D12_RESOURCE_DESC &desc, D3D12_RESOURCE_STATES initialState, GrProtected, D3D12_CLEAR_VALUE *, GrD3DTextureResourceInfo *)
sk_sp< Resource > resource() const
sk_sp< GrD3DResourceState > fState
GrD3DTextureResource(const GrD3DTextureResourceInfo &info, sk_sp< GrD3DResourceState > state)
static std::pair< GrD3DTextureResourceInfo, sk_sp< GrD3DResourceState > > CreateMSAA(GrD3DGpu *gpu, SkISize dimensions, int sampleCnt, const GrD3DTextureResourceInfo &info, SkColor4f clearColor)
unsigned int sampleQualityPattern() const
T * get() const
Definition GrD3DTypes.h:108
AtkStateType state
Protected
Definition GpuTypes.h:61
Definition ref_ptr.h:256
unsigned int fSampleQualityPattern
Definition GrD3DTypes.h:186
gr_cp< ID3D12Resource > fResource
Definition GrD3DTypes.h:180