Update rive-cpp to 2.0 version
[platform/core/uifw/rive-tizen.git] / submodule / skia / src / gpu / ganesh / d3d / GrD3DRenderTarget.h
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
9 #ifndef GrD3DRenderTarget_DEFINED
10 #define GrD3DRenderTarget_DEFINED
11
12 #include "src/gpu/ganesh/GrRenderTarget.h"
13 #include "src/gpu/ganesh/d3d/GrD3DTextureResource.h"
14
15 #include "include/gpu/d3d/GrD3DTypes.h"
16 #include "src/gpu/ganesh/GrGpu.h"
17 #include "src/gpu/ganesh/d3d/GrD3DDescriptorHeap.h"
18 #include "src/gpu/ganesh/d3d/GrD3DResourceProvider.h"
19
20 class GrD3DGpu;
21 class GrD3DRenderTarget;
22
23 struct GrD3DTextureResourceInfo;
24
25 class GrD3DRenderTarget: public GrRenderTarget, public virtual GrD3DTextureResource {
26 public:
27     static sk_sp<GrD3DRenderTarget> MakeWrappedRenderTarget(GrD3DGpu*, SkISize, int sampleCnt,
28                                                             const GrD3DTextureResourceInfo&,
29                                                             sk_sp<GrD3DResourceState>);
30     ~GrD3DRenderTarget() override;
31
32     GrBackendFormat backendFormat() const override { return this->getBackendFormat(); }
33
34     /**
35      * If this render target is multisampled, this returns the MSAA texture for rendering. This
36      * will be different than *this* when we have separate render/resolve images. If not
37      * multisampled returns nullptr.
38      */
39     const GrD3DTextureResource* msaaTextureResource() const;
40     GrD3DTextureResource* msaaTextureResource();
41
42     bool canAttemptStencilAttachment(bool useMSAASurface) const override {
43         SkASSERT(useMSAASurface == (this->numSamples() > 1));
44         return true;
45     }
46
47     GrBackendRenderTarget getBackendRenderTarget() const override;
48
49     D3D12_CPU_DESCRIPTOR_HANDLE colorRenderTargetView() const {
50         return fColorRenderTargetView.fHandle;
51     }
52
53     DXGI_FORMAT stencilDxgiFormat() const;
54
55     // Key used for the program desc
56     void genKey(skgpu::KeyBuilder* b) const;
57
58 protected:
59     GrD3DRenderTarget(GrD3DGpu* gpu,
60                       SkISize dimensions,
61                       const GrD3DTextureResourceInfo& info,
62                       sk_sp<GrD3DResourceState> state,
63                       const GrD3DTextureResourceInfo& msaaInfo,
64                       sk_sp<GrD3DResourceState> msaaState,
65                       const GrD3DDescriptorHeap::CPUHandle& colorRenderTargetView,
66                       const GrD3DDescriptorHeap::CPUHandle& resolveRenderTargetView,
67                       std::string_view label);
68
69     GrD3DRenderTarget(GrD3DGpu* gpu,
70                       SkISize dimensions,
71                       const GrD3DTextureResourceInfo& info,
72                       sk_sp<GrD3DResourceState> state,
73                       const GrD3DDescriptorHeap::CPUHandle& renderTargetView,
74                       std::string_view label);
75
76     void onAbandon() override;
77     void onRelease() override;
78
79     // This accounts for the texture's memory and any MSAA renderbuffer's memory.
80     size_t onGpuMemorySize() const override {
81         int numColorSamples = this->numSamples();
82         if (numColorSamples > 1) {
83             // Add one to account for the resolved VkImage.
84             numColorSamples += 1;
85         }
86         return GrSurface::ComputeSize(this->backendFormat(), this->dimensions(),
87                                       numColorSamples, GrMipmapped::kNo);
88     }
89
90 private:
91     // Extra param to disambiguate from constructor used by subclasses.
92     enum Wrapped { kWrapped };
93     GrD3DRenderTarget(GrD3DGpu* gpu,
94                       SkISize dimensions,
95                       const GrD3DTextureResourceInfo& info,
96                       sk_sp<GrD3DResourceState> state,
97                       const GrD3DTextureResourceInfo& msaaInfo,
98                       sk_sp<GrD3DResourceState> msaaState,
99                       const GrD3DDescriptorHeap::CPUHandle& colorRenderTargetView,
100                       const GrD3DDescriptorHeap::CPUHandle& resolveRenderTargetView,
101                       Wrapped,
102                       std::string_view label);
103
104     GrD3DRenderTarget(GrD3DGpu* gpu,
105                       SkISize dimensions,
106                       const GrD3DTextureResourceInfo& info,
107                       sk_sp<GrD3DResourceState> state,
108                       const GrD3DDescriptorHeap::CPUHandle& renderTargetView,
109                       Wrapped,
110                       std::string_view label);
111
112     GrD3DGpu* getD3DGpu() const;
113
114     bool completeStencilAttachment(GrAttachment* stencil, bool useMSAASurface) override {
115         SkASSERT(useMSAASurface == (this->numSamples() > 1));
116         return true;
117     }
118
119     // In Direct3D we call the release proc after we are finished with the underlying
120     // GrD3DTextureResource::Resource object (which occurs after the GPU finishes all work on it).
121     void onSetRelease(sk_sp<skgpu::RefCntedCallback> releaseHelper) override {
122         // Forward the release proc on to GrD3DTextureResource
123         this->setResourceRelease(std::move(releaseHelper));
124     }
125
126     void releaseInternalObjects();
127
128     std::unique_ptr<GrD3DTextureResource> fMSAATextureResource;
129
130     GrD3DDescriptorHeap::CPUHandle fColorRenderTargetView;
131     GrD3DDescriptorHeap::CPUHandle fResolveRenderTargetView;
132 };
133
134 #endif