/src/skia/include/private/chromium/GrSurfaceCharacterization.h
Line | Count | Source (jump to first uncovered line) |
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/GrBackendSurface.h" |
20 | | #include "include/gpu/GrContextThreadSafeProxy.h" |
21 | | #include "include/gpu/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 | 28 | , fSurfaceProps() {} |
55 | | |
56 | 0 | GrSurfaceCharacterization(GrSurfaceCharacterization&&) = default; |
57 | 0 | GrSurfaceCharacterization& operator=(GrSurfaceCharacterization&&) = default; |
58 | | |
59 | 0 | GrSurfaceCharacterization(const GrSurfaceCharacterization&) = default; |
60 | | GrSurfaceCharacterization& operator=(const GrSurfaceCharacterization& other) = default; |
61 | | bool operator==(const GrSurfaceCharacterization& other) const; |
62 | 0 | bool operator!=(const GrSurfaceCharacterization& other) const { |
63 | 0 | return !(*this == other); |
64 | 0 | } |
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 | 0 | GrContextThreadSafeProxy* contextInfo() const { return fContextInfo.get(); } |
90 | 0 | sk_sp<GrContextThreadSafeProxy> refContextInfo() const { return fContextInfo; } |
91 | 0 | size_t cacheMaxResourceBytes() const { return fCacheMaxResourceBytes; } |
92 | | |
93 | 0 | bool isValid() const { return kUnknown_SkColorType != fImageInfo.colorType(); } |
94 | | |
95 | 0 | const SkImageInfo& imageInfo() const { return fImageInfo; } |
96 | 0 | const GrBackendFormat& backendFormat() const { return fBackendFormat; } |
97 | 0 | GrSurfaceOrigin origin() const { return fOrigin; } |
98 | 0 | SkISize dimensions() const { return fImageInfo.dimensions(); } |
99 | 0 | int width() const { return fImageInfo.width(); } |
100 | 0 | int height() const { return fImageInfo.height(); } |
101 | 0 | SkColorType colorType() const { return fImageInfo.colorType(); } |
102 | 0 | int sampleCount() const { return fSampleCnt; } |
103 | 0 | bool isTextureable() const { return Textureable::kYes == fIsTextureable; } |
104 | 0 | bool isMipMapped() const { return skgpu::Mipmapped::kYes == fIsMipmapped; } |
105 | 0 | bool usesGLFBO0() const { return UsesGLFBO0::kYes == fUsesGLFBO0; } |
106 | 0 | bool vkRTSupportsInputAttachment() const { |
107 | 0 | return VkRTSupportsInputAttachment::kYes == fVkRTSupportsInputAttachment; |
108 | 0 | } |
109 | 0 | bool vulkanSecondaryCBCompatible() const { |
110 | 0 | return VulkanSecondaryCBCompatible::kYes == fVulkanSecondaryCBCompatible; |
111 | 0 | } |
112 | 0 | skgpu::Protected isProtected() const { return fIsProtected; } |
113 | 0 | SkColorSpace* colorSpace() const { return fImageInfo.colorSpace(); } |
114 | 0 | sk_sp<SkColorSpace> refColorSpace() const { return fImageInfo.refColorSpace(); } |
115 | 0 | 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 | 0 | , fSurfaceProps(surfaceProps) { |
153 | 0 | if (fSurfaceProps.flags() & SkSurfaceProps::kDynamicMSAA_Flag) { |
154 | | // Dynamic MSAA is not currently supported with DDL. |
155 | 0 | *this = {}; |
156 | 0 | } |
157 | 0 | SkDEBUGCODE(this->validate()); |
158 | 0 | } Unexecuted instantiation: GrSurfaceCharacterization::GrSurfaceCharacterization(sk_sp<GrContextThreadSafeProxy>, unsigned long, SkImageInfo const&, GrBackendFormat const&, GrSurfaceOrigin, int, GrSurfaceCharacterization::Textureable, skgpu::Mipmapped, GrSurfaceCharacterization::UsesGLFBO0, GrSurfaceCharacterization::VkRTSupportsInputAttachment, GrSurfaceCharacterization::VulkanSecondaryCBCompatible, skgpu::Protected, SkSurfaceProps const&) Unexecuted instantiation: GrSurfaceCharacterization::GrSurfaceCharacterization(sk_sp<GrContextThreadSafeProxy>, unsigned long, SkImageInfo const&, GrBackendFormat const&, GrSurfaceOrigin, int, GrSurfaceCharacterization::Textureable, skgpu::Mipmapped, GrSurfaceCharacterization::UsesGLFBO0, GrSurfaceCharacterization::VkRTSupportsInputAttachment, GrSurfaceCharacterization::VulkanSecondaryCBCompatible, skgpu::Protected, SkSurfaceProps const&) |
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 | 0 | const SkSurfaceProps& surfaceProps) { |
173 | 0 | if (surfaceProps.flags() & SkSurfaceProps::kDynamicMSAA_Flag) { |
174 | | // Dynamic MSAA is not currently supported with DDL. |
175 | 0 | *this = {}; |
176 | 0 | } else { |
177 | 0 | fContextInfo = std::move(contextInfo); |
178 | 0 | fCacheMaxResourceBytes = cacheMaxResourceBytes; |
179 | |
|
180 | 0 | fImageInfo = ii; |
181 | 0 | fBackendFormat = std::move(backendFormat); |
182 | 0 | fOrigin = origin; |
183 | 0 | fSampleCnt = sampleCnt; |
184 | 0 | fIsTextureable = isTextureable; |
185 | 0 | fIsMipmapped = isMipmapped; |
186 | 0 | fUsesGLFBO0 = usesGLFBO0; |
187 | 0 | fVkRTSupportsInputAttachment = vkRTSupportsInputAttachment; |
188 | 0 | fVulkanSecondaryCBCompatible = vulkanSecondaryCBCompatible; |
189 | 0 | fIsProtected = isProtected; |
190 | 0 | fSurfaceProps = surfaceProps; |
191 | 0 | } |
192 | 0 | SkDEBUGCODE(this->validate()); |
193 | 0 | } Unexecuted instantiation: GrSurfaceCharacterization::set(sk_sp<GrContextThreadSafeProxy>, unsigned long, SkImageInfo const&, GrBackendFormat const&, GrSurfaceOrigin, int, GrSurfaceCharacterization::Textureable, skgpu::Mipmapped, GrSurfaceCharacterization::UsesGLFBO0, GrSurfaceCharacterization::VkRTSupportsInputAttachment, GrSurfaceCharacterization::VulkanSecondaryCBCompatible, skgpu::Protected, SkSurfaceProps const&) Unexecuted instantiation: GrSurfaceCharacterization::set(sk_sp<GrContextThreadSafeProxy>, unsigned long, SkImageInfo const&, GrBackendFormat const&, GrSurfaceOrigin, int, GrSurfaceCharacterization::Textureable, skgpu::Mipmapped, GrSurfaceCharacterization::UsesGLFBO0, GrSurfaceCharacterization::VkRTSupportsInputAttachment, GrSurfaceCharacterization::VulkanSecondaryCBCompatible, skgpu::Protected, SkSurfaceProps const&) |
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 |