Debian Codegraph @

include/private/chromium/GrSurfaceCharacterization.h

raw
1 /*
2 * Copyright 2023 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 GrSurfaceCharacterization_DEFINED
9 #define GrSurfaceCharacterization_DEFINED
10
11 #include "include/core/SkColorSpace.h" // IWYU pragma: keep
12 #include "include/core/SkColorType.h"
13 #include "include/core/SkImageInfo.h"
14 #include "include/core/SkRefCnt.h"
15 #include "include/core/SkSize.h"
16 #include "include/core/SkSurfaceProps.h"
17 #include "include/core/SkTypes.h"
18 #include "include/gpu/GpuTypes.h"
19 #include "include/gpu/ganesh/GrBackendSurface.h"
20 #include "include/gpu/ganesh/GrContextThreadSafeProxy.h"
21 #include "include/gpu/ganesh/GrTypes.h"
22 #include "include/private/base/SkDebug.h"
23
24 #include <cstddef>
25 #include <utility>
26
27 /** \class GrSurfaceCharacterization
28 A surface characterization contains all the information Ganesh requires to makes its internal
29 rendering decisions. When passed into a GrDeferredDisplayListRecorder it will copy the
30 data and pass it on to the GrDeferredDisplayList if/when it is created. Note that both of
31 those objects (the Recorder and the DisplayList) will take a ref on the
32 GrContextThreadSafeProxy and SkColorSpace objects.
33 */
34 class SK_API GrSurfaceCharacterization {
35 public:
36 enum class Textureable : bool { kNo = false, kYes = true };
37 enum class UsesGLFBO0 : bool { kNo = false, kYes = true };
38 // This flag indicates that the backing VkImage for this Vulkan surface will have the
39 // VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set. This bit allows skia to handle advanced blends
40 // more optimally in a shader by being able to directly read the dst values.
41 enum class VkRTSupportsInputAttachment : bool { kNo = false, kYes = true };
42 // This flag indicates if the surface is wrapping a raw Vulkan secondary command buffer.
43 enum class VulkanSecondaryCBCompatible : bool { kNo = false, kYes = true };
44
45 GrSurfaceCharacterization()
46 : fCacheMaxResourceBytes(0)
47 , fOrigin(kBottomLeft_GrSurfaceOrigin)
48 , fSampleCnt(0)
49 , fIsTextureable(Textureable::kYes)
50 , fIsMipmapped(skgpu::Mipmapped::kYes)
51 , fUsesGLFBO0(UsesGLFBO0::kNo)
52 , fVulkanSecondaryCBCompatible(VulkanSecondaryCBCompatible::kNo)
53 , fIsProtected(skgpu::Protected::kNo)
54 , fSurfaceProps() {}
55
56 GrSurfaceCharacterization(GrSurfaceCharacterization&&) = default;
57 GrSurfaceCharacterization& operator=(GrSurfaceCharacterization&&) = default;
58
59 GrSurfaceCharacterization(const GrSurfaceCharacterization&) = default;
60 GrSurfaceCharacterization& operator=(const GrSurfaceCharacterization& other) = default;
61 bool operator==(const GrSurfaceCharacterization& other) const;
62 bool operator!=(const GrSurfaceCharacterization& other) const {
63 return !(*this == other);
64 }
65
66 /*
67 * Return a new surface characterization with the only difference being a different width
68 * and height
69 */
70 GrSurfaceCharacterization createResized(int width, int height) const;
71
72 /*
73 * Return a new surface characterization with only a replaced color space
74 */
75 GrSurfaceCharacterization createColorSpace(sk_sp<SkColorSpace>) const;
76
77 /*
78 * Return a new surface characterization with the backend format replaced. A colorType
79 * must also be supplied to indicate the interpretation of the new format.
80 */
81 GrSurfaceCharacterization createBackendFormat(SkColorType colorType,
82 const GrBackendFormat& backendFormat) const;
83
84 /*
85 * Return a new surface characterization with just a different use of FBO0 (in GL)
86 */
87 GrSurfaceCharacterization createFBO0(bool usesGLFBO0) const;
88
89 GrContextThreadSafeProxy* contextInfo() const { return fContextInfo.get(); }
90 sk_sp<GrContextThreadSafeProxy> refContextInfo() const { return fContextInfo; }
91 size_t cacheMaxResourceBytes() const { return fCacheMaxResourceBytes; }
92
93 bool isValid() const { return kUnknown_SkColorType != fImageInfo.colorType(); }
94
95 const SkImageInfo& imageInfo() const { return fImageInfo; }
96 const GrBackendFormat& backendFormat() const { return fBackendFormat; }
97 GrSurfaceOrigin origin() const { return fOrigin; }
98 SkISize dimensions() const { return fImageInfo.dimensions(); }
99 int width() const { return fImageInfo.width(); }
100 int height() const { return fImageInfo.height(); }
101 SkColorType colorType() const { return fImageInfo.colorType(); }
102 int sampleCount() const { return fSampleCnt; }
103 bool isTextureable() const { return Textureable::kYes == fIsTextureable; }
104 bool isMipMapped() const { return skgpu::Mipmapped::kYes == fIsMipmapped; }
105 bool usesGLFBO0() const { return UsesGLFBO0::kYes == fUsesGLFBO0; }
106 bool vkRTSupportsInputAttachment() const {
107 return VkRTSupportsInputAttachment::kYes == fVkRTSupportsInputAttachment;
108 }
109 bool vulkanSecondaryCBCompatible() const {
110 return VulkanSecondaryCBCompatible::kYes == fVulkanSecondaryCBCompatible;
111 }
112 skgpu::Protected isProtected() const { return fIsProtected; }
113 SkColorSpace* colorSpace() const { return fImageInfo.colorSpace(); }
114 sk_sp<SkColorSpace> refColorSpace() const { return fImageInfo.refColorSpace(); }
115 const SkSurfaceProps& surfaceProps()const { return fSurfaceProps; }
116
117 private:
118 friend class SkSurface_Ganesh; // for 'set' & 'config'
119 friend class GrVkSecondaryCBDrawContext; // for 'set' & 'config'
120 friend class GrContextThreadSafeProxy; // for private ctor
121 friend class GrVkContextThreadSafeProxy; // for private ctor
122 friend class GrDeferredDisplayListRecorder; // for 'config'
123 friend class SkSurface; // for 'config'
124
125 SkDEBUGCODE(void validate() const;)
126
127 GrSurfaceCharacterization(sk_sp<GrContextThreadSafeProxy> contextInfo,
128 size_t cacheMaxResourceBytes,
129 const SkImageInfo& ii,
130 const GrBackendFormat& backendFormat,
131 GrSurfaceOrigin origin,
132 int sampleCnt,
133 Textureable isTextureable,
134 skgpu::Mipmapped isMipmapped,
135 UsesGLFBO0 usesGLFBO0,
136 VkRTSupportsInputAttachment vkRTSupportsInputAttachment,
137 VulkanSecondaryCBCompatible vulkanSecondaryCBCompatible,
138 skgpu::Protected isProtected,
139 const SkSurfaceProps& surfaceProps)
140 : fContextInfo(std::move(contextInfo))
141 , fCacheMaxResourceBytes(cacheMaxResourceBytes)
142 , fImageInfo(ii)
143 , fBackendFormat(std::move(backendFormat))
144 , fOrigin(origin)
145 , fSampleCnt(sampleCnt)
146 , fIsTextureable(isTextureable)
147 , fIsMipmapped(isMipmapped)
148 , fUsesGLFBO0(usesGLFBO0)
149 , fVkRTSupportsInputAttachment(vkRTSupportsInputAttachment)
150 , fVulkanSecondaryCBCompatible(vulkanSecondaryCBCompatible)
151 , fIsProtected(isProtected)
152 , fSurfaceProps(surfaceProps) {
153 if (fSurfaceProps.flags() & SkSurfaceProps::kDynamicMSAA_Flag) {
154 // Dynamic MSAA is not currently supported with DDL.
155 *this = {};
156 }
157 SkDEBUGCODE(this->validate());
158 }
159
160 void set(sk_sp<GrContextThreadSafeProxy> contextInfo,
161 size_t cacheMaxResourceBytes,
162 const SkImageInfo& ii,
163 const GrBackendFormat& backendFormat,
164 GrSurfaceOrigin origin,
165 int sampleCnt,
166 Textureable isTextureable,
167 skgpu::Mipmapped isMipmapped,
168 UsesGLFBO0 usesGLFBO0,
169 VkRTSupportsInputAttachment vkRTSupportsInputAttachment,
170 VulkanSecondaryCBCompatible vulkanSecondaryCBCompatible,
171 skgpu::Protected isProtected,
172 const SkSurfaceProps& surfaceProps) {
173 if (surfaceProps.flags() & SkSurfaceProps::kDynamicMSAA_Flag) {
174 // Dynamic MSAA is not currently supported with DDL.
175 *this = {};
176 } else {
177 fContextInfo = std::move(contextInfo);
178 fCacheMaxResourceBytes = cacheMaxResourceBytes;
179
180 fImageInfo = ii;
181 fBackendFormat = std::move(backendFormat);
182 fOrigin = origin;
183 fSampleCnt = sampleCnt;
184 fIsTextureable = isTextureable;
185 fIsMipmapped = isMipmapped;
186 fUsesGLFBO0 = usesGLFBO0;
187 fVkRTSupportsInputAttachment = vkRTSupportsInputAttachment;
188 fVulkanSecondaryCBCompatible = vulkanSecondaryCBCompatible;
189 fIsProtected = isProtected;
190 fSurfaceProps = surfaceProps;
191 }
192 SkDEBUGCODE(this->validate());
193 }
194
195 sk_sp<GrContextThreadSafeProxy> fContextInfo;
196 size_t fCacheMaxResourceBytes;
197
198 SkImageInfo fImageInfo;
199 GrBackendFormat fBackendFormat;
200 GrSurfaceOrigin fOrigin;
201 int fSampleCnt;
202 Textureable fIsTextureable;
203 skgpu::Mipmapped fIsMipmapped;
204 UsesGLFBO0 fUsesGLFBO0;
205 VkRTSupportsInputAttachment fVkRTSupportsInputAttachment;
206 VulkanSecondaryCBCompatible fVulkanSecondaryCBCompatible;
207 skgpu::Protected fIsProtected;
208 SkSurfaceProps fSurfaceProps;
209 };
210
211 #endif