1 /*
2 * Copyright 2012 Google Inc.
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 GrGLUtil_DEFINED
9 #define GrGLUtil_DEFINED
10
11 #include "include/gpu/gl/GrGLInterface.h"
12 #include "include/private/GrTypesPriv.h"
13 #include "include/private/SkImageInfoPriv.h"
14 #include "src/gpu/GrDataUtils.h"
15 #include "src/gpu/GrStencilSettings.h"
16 #include "src/gpu/gl/GrGLDefines.h"
17
18 class SkMatrix;
19
20 ////////////////////////////////////////////////////////////////////////////////
21
22 typedef uint32_t GrGLVersion;
23 typedef uint32_t GrGLSLVersion;
24 typedef uint64_t GrGLDriverVersion;
25
26 #define GR_GL_VER(major, minor) ((static_cast<uint32_t>(major) << 16) | \
27 static_cast<uint32_t>(minor))
28 #define GR_GLSL_VER(major, minor) ((static_cast<uint32_t>(major) << 16) | \
29 static_cast<uint32_t>(minor))
30 #define GR_GL_DRIVER_VER(major, minor, point) ((static_cast<uint64_t>(major) << 32) | \
31 (static_cast<uint64_t>(minor) << 16) | \
32 static_cast<uint64_t>(point))
33
34 #define GR_GL_MAJOR_VER(version) (static_cast<uint32_t>(version) >> 16)
35 #define GR_GL_MINOR_VER(version) (static_cast<uint32_t>(version) & 0xFFFF)
36
37 #define GR_GL_INVALID_VER GR_GL_VER(0, 0)
38 #define GR_GLSL_INVALID_VER GR_GLSL_VER(0, 0)
39 #define GR_GL_DRIVER_UNKNOWN_VER GR_GL_DRIVER_VER(0, 0, 0)
40
GrGLFormatChannels(GrGLFormat format)41 static constexpr uint32_t GrGLFormatChannels(GrGLFormat format) {
42 switch (format) {
43 case GrGLFormat::kUnknown: return 0;
44 case GrGLFormat::kRGBA8: return kRGBA_SkColorChannelFlags;
45 case GrGLFormat::kR8: return kRed_SkColorChannelFlag;
46 case GrGLFormat::kALPHA8: return kAlpha_SkColorChannelFlag;
47 case GrGLFormat::kLUMINANCE8: return kGray_SkColorChannelFlag;
48 case GrGLFormat::kLUMINANCE8_ALPHA8: return kGrayAlpha_SkColorChannelFlags;
49 case GrGLFormat::kBGRA8: return kRGBA_SkColorChannelFlags;
50 case GrGLFormat::kRGB565: return kRGB_SkColorChannelFlags;
51 case GrGLFormat::kRGBA16F: return kRGBA_SkColorChannelFlags;
52 case GrGLFormat::kR16F: return kRed_SkColorChannelFlag;
53 case GrGLFormat::kRGB8: return kRGB_SkColorChannelFlags;
54 case GrGLFormat::kRG8: return kRG_SkColorChannelFlags;
55 case GrGLFormat::kRGB10_A2: return kRGBA_SkColorChannelFlags;
56 case GrGLFormat::kRGBA4: return kRGBA_SkColorChannelFlags;
57 case GrGLFormat::kSRGB8_ALPHA8: return kRGBA_SkColorChannelFlags;
58 case GrGLFormat::kCOMPRESSED_ETC1_RGB8: return kRGB_SkColorChannelFlags;
59 case GrGLFormat::kCOMPRESSED_RGB8_ETC2: return kRGB_SkColorChannelFlags;
60 case GrGLFormat::kCOMPRESSED_RGB8_BC1: return kRGB_SkColorChannelFlags;
61 case GrGLFormat::kCOMPRESSED_RGBA8_BC1: return kRGBA_SkColorChannelFlags;
62 case GrGLFormat::kR16: return kRed_SkColorChannelFlag;
63 case GrGLFormat::kRG16: return kRG_SkColorChannelFlags;
64 case GrGLFormat::kRGBA16: return kRGBA_SkColorChannelFlags;
65 case GrGLFormat::kRG16F: return kRG_SkColorChannelFlags;
66 case GrGLFormat::kLUMINANCE16F: return kGray_SkColorChannelFlag;
67 case GrGLFormat::kSTENCIL_INDEX8: return 0;
68 case GrGLFormat::kSTENCIL_INDEX16: return 0;
69 case GrGLFormat::kDEPTH24_STENCIL8: return 0;
70 }
71 SkUNREACHABLE;
72 }
73
74 /**
75 * The Vendor and Renderer enum values are lazily updated as required.
76 */
77 enum class GrGLVendor {
78 kARM,
79 kGoogle,
80 kImagination,
81 kIntel,
82 kQualcomm,
83 kNVIDIA,
84 kATI,
85
86 kOther
87 };
88
89 enum class GrGLRenderer {
90 kTegra_PreK1, // Legacy Tegra architecture (pre-K1).
91 kTegra, // Tegra with the same architecture as NVIDIA desktop GPUs (K1+).
92
93 kPowerVR54x,
94 kPowerVRRogue,
95
96 kAdreno3xx,
97 kAdreno430,
98 kAdreno4xx_other,
99 kAdreno530,
100 kAdreno5xx_other,
101 kAdreno615, // Pixel3a
102 kAdreno620, // Pixel5
103 kAdreno630, // Pixel3
104 kAdreno640, // Pixel4
105
106 kGoogleSwiftShader,
107
108 /** Intel GPU families, ordered by generation **/
109 // 6th gen
110 kIntelSandyBridge,
111
112 // 7th gen
113 kIntelIvyBridge,
114 kIntelValleyView, // aka BayTrail
115 kIntelHaswell,
116
117 // 8th gen
118 kIntelCherryView, // aka Braswell
119 kIntelBroadwell,
120
121 // 9th gen
122 kIntelApolloLake,
123 kIntelSkyLake,
124 kIntelGeminiLake,
125 kIntelKabyLake,
126 kIntelCoffeeLake,
127
128 // 11th gen
129 kIntelIceLake,
130
131 kGalliumLLVM,
132
133 kMali4xx,
134 /** G-3x, G-5x, or G-7x */
135 kMaliG,
136 /** T-6xx, T-7xx, or T-8xx */
137 kMaliT,
138
139 kAMDRadeonHD7xxx, // AMD Radeon HD 7000 Series
140 kAMDRadeonR9M3xx, // AMD Radeon R9 M300 Series
141 kAMDRadeonR9M4xx, // AMD Radeon R9 M400 Series
142 kAMDRadeonPro5xxx, // AMD Radeon Pro 5000 Series
143 kAMDRadeonProVegaxx, // AMD Radeon Pro Vega
144
145 kOther
146 };
147
148 enum class GrGLDriver {
149 kMesa,
150 kChromium,
151 kNVIDIA,
152 kIntel,
153 kSwiftShader,
154 kQualcomm,
155 kAndroidEmulator,
156 kUnknown
157 };
158
159 enum class GrGLANGLEBackend {
160 kUnknown,
161 kD3D9,
162 kD3D11,
163 kOpenGL
164 };
165
166 ////////////////////////////////////////////////////////////////////////////////
167
168 /**
169 * Some drivers want the var-int arg to be zero-initialized on input.
170 */
171 #define GR_GL_INIT_ZERO 0
172 #define GR_GL_GetIntegerv(gl, e, p) \
173 do { \
174 *(p) = GR_GL_INIT_ZERO; \
175 GR_GL_CALL(gl, GetIntegerv(e, p)); \
176 } while (0)
177
178 #define GR_GL_GetFramebufferAttachmentParameteriv(gl, t, a, pname, p) \
179 do { \
180 *(p) = GR_GL_INIT_ZERO; \
181 GR_GL_CALL(gl, GetFramebufferAttachmentParameteriv(t, a, pname, p)); \
182 } while (0)
183
184 #define GR_GL_GetInternalformativ(gl, t, f, n, s, p) \
185 do { \
186 *(p) = GR_GL_INIT_ZERO; \
187 GR_GL_CALL(gl, GetInternalformativ(t, f, n, s, p)); \
188 } while (0)
189
190 #define GR_GL_GetNamedFramebufferAttachmentParameteriv(gl, fb, a, pname, p) \
191 do { \
192 *(p) = GR_GL_INIT_ZERO; \
193 GR_GL_CALL(gl, GetNamedFramebufferAttachmentParameteriv(fb, a, pname, p)); \
194 } while (0)
195
196 #define GR_GL_GetRenderbufferParameteriv(gl, t, pname, p) \
197 do { \
198 *(p) = GR_GL_INIT_ZERO; \
199 GR_GL_CALL(gl, GetRenderbufferParameteriv(t, pname, p)); \
200 } while (0)
201
202 #define GR_GL_GetTexLevelParameteriv(gl, t, l, pname, p) \
203 do { \
204 *(p) = GR_GL_INIT_ZERO; \
205 GR_GL_CALL(gl, GetTexLevelParameteriv(t, l, pname, p)); \
206 } while (0)
207
208 #define GR_GL_GetShaderPrecisionFormat(gl, st, pt, range, precision) \
209 do { \
210 (range)[0] = GR_GL_INIT_ZERO; \
211 (range)[1] = GR_GL_INIT_ZERO; \
212 (*precision) = GR_GL_INIT_ZERO; \
213 GR_GL_CALL(gl, GetShaderPrecisionFormat(st, pt, range, precision)); \
214 } while (0)
215
216 ////////////////////////////////////////////////////////////////////////////////
217
218 GrGLStandard GrGLGetStandardInUseFromString(const char* versionString);
219 GrGLSLVersion GrGLGetVersion(const GrGLInterface*);
220 GrGLSLVersion GrGLGetVersionFromString(const char*);
221
222 struct GrGLDriverInfo {
223 GrGLStandard fStandard = kNone_GrGLStandard;
224 GrGLVersion fVersion = GR_GL_INVALID_VER;
225 GrGLSLVersion fGLSLVersion = GR_GLSL_INVALID_VER;
226 GrGLVendor fVendor = GrGLVendor::kOther;
227 GrGLRenderer fRenderer = GrGLRenderer::kOther;
228 GrGLDriver fDriver = GrGLDriver::kUnknown;
229 GrGLDriverVersion fDriverVersion = GR_GL_DRIVER_UNKNOWN_VER;
230
231 GrGLANGLEBackend fANGLEBackend = GrGLANGLEBackend::kUnknown;
232 GrGLVendor fANGLEVendor = GrGLVendor::kOther;
233 GrGLRenderer fANGLERenderer = GrGLRenderer::kOther;
234 GrGLDriver fANGLEDriver = GrGLDriver::kUnknown;
235 GrGLDriverVersion fANGLEDriverVersion = GR_GL_DRIVER_UNKNOWN_VER;
236 };
237
238 GrGLDriverInfo GrGLGetDriverInfo(const GrGLInterface*);
239
240 /**
241 * Helpers for glGetError()
242 */
243
244 void GrGLCheckErr(const GrGLInterface* gl,
245 const char* location,
246 const char* call);
247
248 ////////////////////////////////////////////////////////////////////////////////
249
250 /**
251 * Macros for using GrGLInterface to make GL calls
252 */
253
254 // Conditionally checks glGetError based on compile-time and run-time flags.
255 #if GR_GL_CHECK_ERROR
256 extern bool gCheckErrorGL;
257 #define GR_GL_CHECK_ERROR_IMPL(IFACE, X) \
258 do { \
259 if (gCheckErrorGL) { \
260 IFACE->checkError(GR_FILE_AND_LINE_STR, #X); \
261 } \
262 } while (false)
263 #else
264 #define GR_GL_CHECK_ERROR_IMPL(IFACE, X) \
265 do { \
266 } while (false)
267 #endif
268
269 // internal macro to conditionally log the gl call using SkDebugf based on
270 // compile-time and run-time flags.
271 #if GR_GL_LOG_CALLS
272 extern bool gLogCallsGL;
273 #define GR_GL_LOG_CALLS_IMPL(X) \
274 if (gLogCallsGL) \
275 SkDebugf(GR_FILE_AND_LINE_STR "GL: " #X "\n")
276 #else
277 #define GR_GL_LOG_CALLS_IMPL(X)
278 #endif
279
280 // makes a GL call on the interface and does any error checking and logging
281 #define GR_GL_CALL(IFACE, X) \
282 do { \
283 GR_GL_CALL_NOERRCHECK(IFACE, X); \
284 GR_GL_CHECK_ERROR_IMPL(IFACE, X); \
285 } while (false)
286
287 // Variant of above that always skips the error check. This is useful when
288 // the caller wants to do its own glGetError() call and examine the error value.
289 #define GR_GL_CALL_NOERRCHECK(IFACE, X) \
290 do { \
291 (IFACE)->fFunctions.f##X; \
292 GR_GL_LOG_CALLS_IMPL(X); \
293 } while (false)
294
295 // same as GR_GL_CALL but stores the return value of the gl call in RET
296 #define GR_GL_CALL_RET(IFACE, RET, X) \
297 do { \
298 GR_GL_CALL_RET_NOERRCHECK(IFACE, RET, X); \
299 GR_GL_CHECK_ERROR_IMPL(IFACE, X); \
300 } while (false)
301
302 // same as GR_GL_CALL_RET but always skips the error check.
303 #define GR_GL_CALL_RET_NOERRCHECK(IFACE, RET, X) \
304 do { \
305 (RET) = (IFACE)->fFunctions.f##X; \
306 GR_GL_LOG_CALLS_IMPL(X); \
307 } while (false)
308
GrGLFormatFromGLEnum(GrGLenum glFormat)309 static constexpr GrGLFormat GrGLFormatFromGLEnum(GrGLenum glFormat) {
310 switch (glFormat) {
311 case GR_GL_RGBA8: return GrGLFormat::kRGBA8;
312 case GR_GL_R8: return GrGLFormat::kR8;
313 case GR_GL_ALPHA8: return GrGLFormat::kALPHA8;
314 case GR_GL_LUMINANCE8: return GrGLFormat::kLUMINANCE8;
315 case GR_GL_LUMINANCE8_ALPHA8: return GrGLFormat::kLUMINANCE8_ALPHA8;
316 case GR_GL_BGRA8: return GrGLFormat::kBGRA8;
317 case GR_GL_RGB565: return GrGLFormat::kRGB565;
318 case GR_GL_RGBA16F: return GrGLFormat::kRGBA16F;
319 case GR_GL_LUMINANCE16F: return GrGLFormat::kLUMINANCE16F;
320 case GR_GL_R16F: return GrGLFormat::kR16F;
321 case GR_GL_RGB8: return GrGLFormat::kRGB8;
322 case GR_GL_RG8: return GrGLFormat::kRG8;
323 case GR_GL_RGB10_A2: return GrGLFormat::kRGB10_A2;
324 case GR_GL_RGBA4: return GrGLFormat::kRGBA4;
325 case GR_GL_SRGB8_ALPHA8: return GrGLFormat::kSRGB8_ALPHA8;
326 case GR_GL_COMPRESSED_ETC1_RGB8: return GrGLFormat::kCOMPRESSED_ETC1_RGB8;
327 case GR_GL_COMPRESSED_RGB8_ETC2: return GrGLFormat::kCOMPRESSED_RGB8_ETC2;
328 case GR_GL_COMPRESSED_RGB_S3TC_DXT1_EXT: return GrGLFormat::kCOMPRESSED_RGB8_BC1;
329 case GR_GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: return GrGLFormat::kCOMPRESSED_RGBA8_BC1;
330 case GR_GL_R16: return GrGLFormat::kR16;
331 case GR_GL_RG16: return GrGLFormat::kRG16;
332 case GR_GL_RGBA16: return GrGLFormat::kRGBA16;
333 case GR_GL_RG16F: return GrGLFormat::kRG16F;
334 case GR_GL_STENCIL_INDEX8: return GrGLFormat::kSTENCIL_INDEX8;
335 case GR_GL_STENCIL_INDEX16: return GrGLFormat::kSTENCIL_INDEX16;
336 case GR_GL_DEPTH24_STENCIL8: return GrGLFormat::kDEPTH24_STENCIL8;
337
338
339 default: return GrGLFormat::kUnknown;
340 }
341 }
342
343 /** Returns either the sized internal format or compressed internal format of the GrGLFormat. */
GrGLFormatToEnum(GrGLFormat format)344 static constexpr GrGLenum GrGLFormatToEnum(GrGLFormat format) {
345 switch (format) {
346 case GrGLFormat::kRGBA8: return GR_GL_RGBA8;
347 case GrGLFormat::kR8: return GR_GL_R8;
348 case GrGLFormat::kALPHA8: return GR_GL_ALPHA8;
349 case GrGLFormat::kLUMINANCE8: return GR_GL_LUMINANCE8;
350 case GrGLFormat::kLUMINANCE8_ALPHA8: return GR_GL_LUMINANCE8_ALPHA8;
351 case GrGLFormat::kBGRA8: return GR_GL_BGRA8;
352 case GrGLFormat::kRGB565: return GR_GL_RGB565;
353 case GrGLFormat::kRGBA16F: return GR_GL_RGBA16F;
354 case GrGLFormat::kLUMINANCE16F: return GR_GL_LUMINANCE16F;
355 case GrGLFormat::kR16F: return GR_GL_R16F;
356 case GrGLFormat::kRGB8: return GR_GL_RGB8;
357 case GrGLFormat::kRG8: return GR_GL_RG8;
358 case GrGLFormat::kRGB10_A2: return GR_GL_RGB10_A2;
359 case GrGLFormat::kRGBA4: return GR_GL_RGBA4;
360 case GrGLFormat::kSRGB8_ALPHA8: return GR_GL_SRGB8_ALPHA8;
361 case GrGLFormat::kCOMPRESSED_ETC1_RGB8: return GR_GL_COMPRESSED_ETC1_RGB8;
362 case GrGLFormat::kCOMPRESSED_RGB8_ETC2: return GR_GL_COMPRESSED_RGB8_ETC2;
363 case GrGLFormat::kCOMPRESSED_RGB8_BC1: return GR_GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
364 case GrGLFormat::kCOMPRESSED_RGBA8_BC1: return GR_GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
365 case GrGLFormat::kR16: return GR_GL_R16;
366 case GrGLFormat::kRG16: return GR_GL_RG16;
367 case GrGLFormat::kRGBA16: return GR_GL_RGBA16;
368 case GrGLFormat::kRG16F: return GR_GL_RG16F;
369 case GrGLFormat::kSTENCIL_INDEX8: return GR_GL_STENCIL_INDEX8;
370 case GrGLFormat::kSTENCIL_INDEX16: return GR_GL_STENCIL_INDEX16;
371 case GrGLFormat::kDEPTH24_STENCIL8: return GR_GL_DEPTH24_STENCIL8;
372 case GrGLFormat::kUnknown: return 0;
373 }
374 SkUNREACHABLE;
375 }
376
GrGLFormatBytesPerBlock(GrGLFormat format)377 static constexpr size_t GrGLFormatBytesPerBlock(GrGLFormat format) {
378 switch (format) {
379 case GrGLFormat::kRGBA8: return 4;
380 case GrGLFormat::kR8: return 1;
381 case GrGLFormat::kALPHA8: return 1;
382 case GrGLFormat::kLUMINANCE8: return 1;
383 case GrGLFormat::kLUMINANCE8_ALPHA8: return 2;
384 case GrGLFormat::kBGRA8: return 4;
385 case GrGLFormat::kRGB565: return 2;
386 case GrGLFormat::kRGBA16F: return 8;
387 case GrGLFormat::kLUMINANCE16F: return 2;
388 case GrGLFormat::kR16F: return 2;
389 // We assume the GPU stores this format 4 byte aligned
390 case GrGLFormat::kRGB8: return 4;
391 case GrGLFormat::kRG8: return 2;
392 case GrGLFormat::kRGB10_A2: return 4;
393 case GrGLFormat::kRGBA4: return 2;
394 case GrGLFormat::kSRGB8_ALPHA8: return 4;
395 case GrGLFormat::kCOMPRESSED_ETC1_RGB8: return 8;
396 case GrGLFormat::kCOMPRESSED_RGB8_ETC2: return 8;
397 case GrGLFormat::kCOMPRESSED_RGB8_BC1: return 8;
398 case GrGLFormat::kCOMPRESSED_RGBA8_BC1: return 8;
399 case GrGLFormat::kR16: return 2;
400 case GrGLFormat::kRG16: return 4;
401 case GrGLFormat::kRGBA16: return 8;
402 case GrGLFormat::kRG16F: return 4;
403 case GrGLFormat::kSTENCIL_INDEX8: return 1;
404 case GrGLFormat::kSTENCIL_INDEX16: return 2;
405 case GrGLFormat::kDEPTH24_STENCIL8: return 4;
406 case GrGLFormat::kUnknown: return 0;
407 }
408 SkUNREACHABLE;
409 }
410
GrGLFormatStencilBits(GrGLFormat format)411 static constexpr int GrGLFormatStencilBits(GrGLFormat format) {
412 switch (format) {
413 case GrGLFormat::kSTENCIL_INDEX8:
414 return 8;
415 case GrGLFormat::kSTENCIL_INDEX16:
416 return 16;
417 case GrGLFormat::kDEPTH24_STENCIL8:
418 return 8;
419 case GrGLFormat::kCOMPRESSED_ETC1_RGB8:
420 case GrGLFormat::kCOMPRESSED_RGB8_ETC2:
421 case GrGLFormat::kCOMPRESSED_RGB8_BC1:
422 case GrGLFormat::kCOMPRESSED_RGBA8_BC1:
423 case GrGLFormat::kRGBA8:
424 case GrGLFormat::kR8:
425 case GrGLFormat::kALPHA8:
426 case GrGLFormat::kLUMINANCE8:
427 case GrGLFormat::kLUMINANCE8_ALPHA8:
428 case GrGLFormat::kBGRA8:
429 case GrGLFormat::kRGB565:
430 case GrGLFormat::kRGBA16F:
431 case GrGLFormat::kR16F:
432 case GrGLFormat::kLUMINANCE16F:
433 case GrGLFormat::kRGB8:
434 case GrGLFormat::kRG8:
435 case GrGLFormat::kRGB10_A2:
436 case GrGLFormat::kRGBA4:
437 case GrGLFormat::kSRGB8_ALPHA8:
438 case GrGLFormat::kR16:
439 case GrGLFormat::kRG16:
440 case GrGLFormat::kRGBA16:
441 case GrGLFormat::kRG16F:
442 case GrGLFormat::kUnknown:
443 return 0;
444 }
445 SkUNREACHABLE;
446 }
447
GrGLFormatIsPackedDepthStencil(GrGLFormat format)448 static constexpr bool GrGLFormatIsPackedDepthStencil(GrGLFormat format) {
449 switch (format) {
450 case GrGLFormat::kDEPTH24_STENCIL8:
451 return true;
452 case GrGLFormat::kCOMPRESSED_ETC1_RGB8:
453 case GrGLFormat::kCOMPRESSED_RGB8_ETC2:
454 case GrGLFormat::kCOMPRESSED_RGB8_BC1:
455 case GrGLFormat::kCOMPRESSED_RGBA8_BC1:
456 case GrGLFormat::kRGBA8:
457 case GrGLFormat::kR8:
458 case GrGLFormat::kALPHA8:
459 case GrGLFormat::kLUMINANCE8:
460 case GrGLFormat::kLUMINANCE8_ALPHA8:
461 case GrGLFormat::kBGRA8:
462 case GrGLFormat::kRGB565:
463 case GrGLFormat::kRGBA16F:
464 case GrGLFormat::kR16F:
465 case GrGLFormat::kLUMINANCE16F:
466 case GrGLFormat::kRGB8:
467 case GrGLFormat::kRG8:
468 case GrGLFormat::kRGB10_A2:
469 case GrGLFormat::kRGBA4:
470 case GrGLFormat::kSRGB8_ALPHA8:
471 case GrGLFormat::kR16:
472 case GrGLFormat::kRG16:
473 case GrGLFormat::kRGBA16:
474 case GrGLFormat::kRG16F:
475 case GrGLFormat::kSTENCIL_INDEX8:
476 case GrGLFormat::kSTENCIL_INDEX16:
477 case GrGLFormat::kUnknown:
478 return false;
479 }
480 SkUNREACHABLE;
481 }
482
GrGLFormatIsSRGB(GrGLFormat format)483 static constexpr bool GrGLFormatIsSRGB(GrGLFormat format) {
484 switch (format) {
485 case GrGLFormat::kSRGB8_ALPHA8:
486 return true;
487 case GrGLFormat::kCOMPRESSED_ETC1_RGB8:
488 case GrGLFormat::kCOMPRESSED_RGB8_ETC2:
489 case GrGLFormat::kCOMPRESSED_RGB8_BC1:
490 case GrGLFormat::kCOMPRESSED_RGBA8_BC1:
491 case GrGLFormat::kRGBA8:
492 case GrGLFormat::kR8:
493 case GrGLFormat::kALPHA8:
494 case GrGLFormat::kLUMINANCE8:
495 case GrGLFormat::kLUMINANCE8_ALPHA8:
496 case GrGLFormat::kBGRA8:
497 case GrGLFormat::kRGB565:
498 case GrGLFormat::kRGBA16F:
499 case GrGLFormat::kR16F:
500 case GrGLFormat::kLUMINANCE16F:
501 case GrGLFormat::kRGB8:
502 case GrGLFormat::kRG8:
503 case GrGLFormat::kRGB10_A2:
504 case GrGLFormat::kRGBA4:
505 case GrGLFormat::kR16:
506 case GrGLFormat::kRG16:
507 case GrGLFormat::kRGBA16:
508 case GrGLFormat::kRG16F:
509 case GrGLFormat::kSTENCIL_INDEX8:
510 case GrGLFormat::kSTENCIL_INDEX16:
511 case GrGLFormat::kDEPTH24_STENCIL8:
512 case GrGLFormat::kUnknown:
513 return false;
514 }
515 SkUNREACHABLE;
516 }
517
518 #if defined(SK_DEBUG) || GR_TEST_UTILS
GrGLFormatToStr(GrGLenum glFormat)519 static constexpr const char* GrGLFormatToStr(GrGLenum glFormat) {
520 switch (glFormat) {
521 case GR_GL_RGBA8: return "RGBA8";
522 case GR_GL_R8: return "R8";
523 case GR_GL_ALPHA8: return "ALPHA8";
524 case GR_GL_LUMINANCE8: return "LUMINANCE8";
525 case GR_GL_LUMINANCE8_ALPHA8: return "LUMINANCE8_ALPHA8";
526 case GR_GL_BGRA8: return "BGRA8";
527 case GR_GL_RGB565: return "RGB565";
528 case GR_GL_RGBA16F: return "RGBA16F";
529 case GR_GL_LUMINANCE16F: return "LUMINANCE16F";
530 case GR_GL_R16F: return "R16F";
531 case GR_GL_RGB8: return "RGB8";
532 case GR_GL_RG8: return "RG8";
533 case GR_GL_RGB10_A2: return "RGB10_A2";
534 case GR_GL_RGBA4: return "RGBA4";
535 case GR_GL_RGBA32F: return "RGBA32F";
536 case GR_GL_SRGB8_ALPHA8: return "SRGB8_ALPHA8";
537 case GR_GL_COMPRESSED_ETC1_RGB8: return "ETC1";
538 case GR_GL_COMPRESSED_RGB8_ETC2: return "ETC2";
539 case GR_GL_COMPRESSED_RGB_S3TC_DXT1_EXT: return "RGB8_BC1";
540 case GR_GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: return "RGBA8_BC1";
541 case GR_GL_R16: return "R16";
542 case GR_GL_RG16: return "RG16";
543 case GR_GL_RGBA16: return "RGBA16";
544 case GR_GL_RG16F: return "RG16F";
545 case GR_GL_STENCIL_INDEX8: return "STENCIL_INDEX8";
546 case GR_GL_STENCIL_INDEX16: return "STENCIL_INDEX16";
547 case GR_GL_DEPTH24_STENCIL8: return "DEPTH24_STENCIL8";
548
549 default: return "Unknown";
550 }
551 }
552 #endif
553
554 GrGLenum GrToGLStencilFunc(GrStencilTest test);
555
556 /**
557 * Returns true if the format is compressed.
558 */
559 bool GrGLFormatIsCompressed(GrGLFormat);
560
561 #endif
562