Flutter Engine
The Flutter Engine
GrSurfaceCharacterization.h
Go to the documentation of this file.
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
15#include "include/core/SkSize.h"
21#include "include/gpu/GrTypes.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*/
35public:
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
46 : fCacheMaxResourceBytes(0)
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
58
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 */
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; }
107 return VkRTSupportsInputAttachment::kYes == fVkRTSupportsInputAttachment;
108 }
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
117private:
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
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
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
GrSurfaceOrigin
Definition: GrTypes.h:147
@ kBottomLeft_GrSurfaceOrigin
Definition: GrTypes.h:149
#define SK_API
Definition: SkAPI.h:35
SkColorType
Definition: SkColorType.h:19
@ kUnknown_SkColorType
uninitialized
Definition: SkColorType.h:20
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
@ kYes
Do pre-clip the geometry before applying the (perspective) matrix.
@ kNo
Don't pre-clip the geometry before applying the (perspective) matrix.
SkDEBUGCODE(SK_SPI) SkThreadID SkGetThreadID()
sk_sp< GrContextThreadSafeProxy > refContextInfo() const
GrSurfaceOrigin origin() const
sk_sp< SkColorSpace > refColorSpace() const
GrSurfaceCharacterization & operator=(const GrSurfaceCharacterization &other)=default
GrSurfaceCharacterization(const GrSurfaceCharacterization &)=default
bool operator!=(const GrSurfaceCharacterization &other) const
GrSurfaceCharacterization & operator=(GrSurfaceCharacterization &&)=default
GrContextThreadSafeProxy * contextInfo() const
const SkImageInfo & imageInfo() const
const GrBackendFormat & backendFormat() const
GrSurfaceCharacterization(GrSurfaceCharacterization &&)=default
const SkSurfaceProps & surfaceProps() const
skgpu::Protected isProtected() const
uint32_t flags() const
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not set
Definition: switches.h:76
bool operator==(C p1, const scoped_nsprotocol< C > &p2)
Definition: GpuTools.h:21
Mipmapped
Definition: GpuTypes.h:53
Protected
Definition: GpuTypes.h:61
Definition: ref_ptr.h:256
int32_t height
int32_t width
Definition: SkSize.h:16