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*/
34class SK_API GrSurfaceCharacterization {
35public:
36 enum class Textureable : bool { kNo = false, kYes = true };
37 enum class MipMapped : bool { kNo = false, kYes = true };
38 enum class UsesGLFBO0 : bool { kNo = false, kYes = true };
39 // This flag indicates that the backing VkImage for this Vulkan surface will have the
40 // VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT set. This bit allows skia to handle advanced blends
41 // more optimally in a shader by being able to directly read the dst values.
42 enum class VkRTSupportsInputAttachment : bool { kNo = false, kYes = true };
43 // This flag indicates if the surface is wrapping a raw Vulkan secondary command buffer.
44 enum class VulkanSecondaryCBCompatible : bool { kNo = false, kYes = true };
45
46 GrSurfaceCharacterization()
47 : fCacheMaxResourceBytes(0)
48 , fOrigin(kBottomLeft_GrSurfaceOrigin)
49 , fSampleCnt(0)
50 , fIsTextureable(Textureable::kYes)
51 , fIsMipMapped(MipMapped::kYes)
52 , fUsesGLFBO0(UsesGLFBO0::kNo)
53 , fVulkanSecondaryCBCompatible(VulkanSecondaryCBCompatible::kNo)
54 , fIsProtected(GrProtected::kNo)
55 , fSurfaceProps(0, kUnknown_SkPixelGeometry) {
56 }
57
58 GrSurfaceCharacterization(GrSurfaceCharacterization&&) = default;
59 GrSurfaceCharacterization& operator=(GrSurfaceCharacterization&&) = default;
60
61 GrSurfaceCharacterization(const GrSurfaceCharacterization&) = default;
62 GrSurfaceCharacterization& operator=(const GrSurfaceCharacterization& other) = default;
63 bool operator==(const GrSurfaceCharacterization& other) const;
64 bool operator!=(const GrSurfaceCharacterization& other) const {
65 return !(*this == other);
66 }
67
68 /*
69 * Return a new surface characterization with the only difference being a different width
70 * and height
71 */
72 GrSurfaceCharacterization createResized(int width, int height) const;
73
74 /*
75 * Return a new surface characterization with only a replaced color space
76 */
77 GrSurfaceCharacterization createColorSpace(sk_sp<SkColorSpace>) const;
78
79 /*
80 * Return a new surface characterization with the backend format replaced. A colorType
81 * must also be supplied to indicate the interpretation of the new format.
82 */
83 GrSurfaceCharacterization createBackendFormat(SkColorType colorType,
84 const GrBackendFormat& backendFormat) const;
85
86 /*
87 * Return a new surface characterization with just a different use of FBO0 (in GL)
88 */
89 GrSurfaceCharacterization createFBO0(bool usesGLFBO0) const;
90
91 GrContextThreadSafeProxy* contextInfo() const { return fContextInfo.get(); }
92 sk_sp<GrContextThreadSafeProxy> refContextInfo() const { return fContextInfo; }
93 size_t cacheMaxResourceBytes() const { return fCacheMaxResourceBytes; }
94
95 bool isValid() const { return kUnknown_SkColorType != fImageInfo.colorType(); }
96
97 const SkImageInfo& imageInfo() const { return fImageInfo; }
98 const GrBackendFormat& backendFormat() const { return fBackendFormat; }
99 GrSurfaceOrigin origin() const { return fOrigin; }
100 SkISize dimensions() const { return fImageInfo.dimensions(); }
101 int width() const { return fImageInfo.width(); }
102 int height() const { return fImageInfo.height(); }
103 SkColorType colorType() const { return fImageInfo.colorType(); }
104 int sampleCount() const { return fSampleCnt; }
105 bool isTextureable() const { return Textureable::kYes == fIsTextureable; }
106 bool isMipMapped() const { return MipMapped::kYes == fIsMipMapped; }
107 bool usesGLFBO0() const { return UsesGLFBO0::kYes == fUsesGLFBO0; }
108 bool vkRTSupportsInputAttachment() const {
109 return VkRTSupportsInputAttachment::kYes == fVkRTSupportsInputAttachment;
110 }
111 bool vulkanSecondaryCBCompatible() const {
112 return VulkanSecondaryCBCompatible::kYes == fVulkanSecondaryCBCompatible;
113 }
114 GrProtected isProtected() const { return fIsProtected; }
115 SkColorSpace* colorSpace() const { return fImageInfo.colorSpace(); }
116 sk_sp<SkColorSpace> refColorSpace() const { return fImageInfo.refColorSpace(); }
117 const SkSurfaceProps& surfaceProps()const { return fSurfaceProps; }
118
119 // Is the provided backend texture compatible with this surface characterization?
120 bool isCompatible(const GrBackendTexture&) const;
121
122private:
123 friend class SkSurface_Ganesh; // for 'set' & 'config'
124 friend class GrVkSecondaryCBDrawContext; // for 'set' & 'config'
125 friend class GrContextThreadSafeProxy; // for private ctor
126 friend class GrDeferredDisplayListRecorder; // for 'config'
127 friend class SkSurface; // for 'config'
128
129 SkDEBUGCODE(void validate() const;)
130
131 GrSurfaceCharacterization(sk_sp<GrContextThreadSafeProxy> contextInfo,
132 size_t cacheMaxResourceBytes,
133 const SkImageInfo& ii,
134 const GrBackendFormat& backendFormat,
135 GrSurfaceOrigin origin,
136 int sampleCnt,
137 Textureable isTextureable,
138 MipMapped isMipMapped,
139 UsesGLFBO0 usesGLFBO0,
140 VkRTSupportsInputAttachment vkRTSupportsInputAttachment,
141 VulkanSecondaryCBCompatible vulkanSecondaryCBCompatible,
142 GrProtected isProtected,
143 const SkSurfaceProps& surfaceProps)
144 : fContextInfo(std::move(contextInfo))
145 , fCacheMaxResourceBytes(cacheMaxResourceBytes)
146 , fImageInfo(ii)
147 , fBackendFormat(std::move(backendFormat))
148 , fOrigin(origin)
149 , fSampleCnt(sampleCnt)
150 , fIsTextureable(isTextureable)
151 , fIsMipMapped(isMipMapped)
152 , fUsesGLFBO0(usesGLFBO0)
153 , fVkRTSupportsInputAttachment(vkRTSupportsInputAttachment)
154 , fVulkanSecondaryCBCompatible(vulkanSecondaryCBCompatible)
155 , fIsProtected(isProtected)
156 , fSurfaceProps(surfaceProps) {
157 if (fSurfaceProps.flags() & SkSurfaceProps::kDynamicMSAA_Flag) {
158 // Dynamic MSAA is not currently supported with DDL.
159 *this = {};
160 }
161 SkDEBUGCODE(this->validate());
162 }
163
164 void set(sk_sp<GrContextThreadSafeProxy> contextInfo,
165 size_t cacheMaxResourceBytes,
166 const SkImageInfo& ii,
167 const GrBackendFormat& backendFormat,
168 GrSurfaceOrigin origin,
169 int sampleCnt,
170 Textureable isTextureable,
171 MipMapped isMipMapped,
172 UsesGLFBO0 usesGLFBO0,
173 VkRTSupportsInputAttachment vkRTSupportsInputAttachment,
174 VulkanSecondaryCBCompatible vulkanSecondaryCBCompatible,
175 GrProtected isProtected,
176 const SkSurfaceProps& surfaceProps) {
177 if (surfaceProps.flags() & SkSurfaceProps::kDynamicMSAA_Flag) {
178 // Dynamic MSAA is not currently supported with DDL.
179 *this = {};
180 } else {
181 fContextInfo = contextInfo;
182 fCacheMaxResourceBytes = cacheMaxResourceBytes;
183
184 fImageInfo = ii;
185 fBackendFormat = std::move(backendFormat);
186 fOrigin = origin;
187 fSampleCnt = sampleCnt;
188 fIsTextureable = isTextureable;
189 fIsMipMapped = isMipMapped;
190 fUsesGLFBO0 = usesGLFBO0;
191 fVkRTSupportsInputAttachment = vkRTSupportsInputAttachment;
192 fVulkanSecondaryCBCompatible = vulkanSecondaryCBCompatible;
193 fIsProtected = isProtected;
194 fSurfaceProps = surfaceProps;
195 }
196 SkDEBUGCODE(this->validate());
197 }
198
199 sk_sp<GrContextThreadSafeProxy> fContextInfo;
200 size_t fCacheMaxResourceBytes;
201
202 SkImageInfo fImageInfo;
203 GrBackendFormat fBackendFormat;
204 GrSurfaceOrigin fOrigin;
205 int fSampleCnt;
206 Textureable fIsTextureable;
207 MipMapped fIsMipMapped;
208 UsesGLFBO0 fUsesGLFBO0;
209 VkRTSupportsInputAttachment fVkRTSupportsInputAttachment;
210 VulkanSecondaryCBCompatible fVulkanSecondaryCBCompatible;
211 GrProtected fIsProtected;
212 SkSurfaceProps fSurfaceProps;
213};
214
215#endif
216

Provided by KDAB

Privacy Policy
Learn more about Flutter for embedded and desktop on industrialflutter.com

source code of flutter_engine/third_party/skia/include/private/chromium/GrSurfaceCharacterization.h