1 /*
2 * Copyright 2013 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 GrTypesPriv_DEFINED
9 #define GrTypesPriv_DEFINED
10
11 #include <chrono>
12 #include "include/core/SkCanvas.h"
13 #include "include/core/SkImage.h"
14 #include "include/core/SkImageInfo.h"
15 #include "include/core/SkPath.h"
16 #include "include/core/SkRefCnt.h"
17 #include "include/gpu/GrTypes.h"
18 #include "include/private/GrSharedEnums.h"
19 #include "include/private/SkImageInfoPriv.h"
20 #include "include/private/SkWeakRefCnt.h"
21
22 class GrBackendFormat;
23 class GrCaps;
24
25 // The old libstdc++ uses the draft name "monotonic_clock" rather than "steady_clock". This might
26 // not actually be monotonic, depending on how libstdc++ was built. However, this is only currently
27 // used for idle resource purging so it shouldn't cause a correctness problem.
28 #if defined(__GLIBCXX__) && (__GLIBCXX__ < 20130000)
29 using GrStdSteadyClock = std::chrono::monotonic_clock;
30 #else
31 using GrStdSteadyClock = std::chrono::steady_clock;
32 #endif
33
34 /**
35 * Pixel configurations. This type conflates texture formats, CPU pixel formats, and
36 * premultipliedness. We are moving away from it towards SkColorType and backend API (GL, Vulkan)
37 * texture formats in the public API. Right now this mostly refers to texture formats as we're
38 * migrating.
39 */
40 enum GrPixelConfig {
41 kUnknown_GrPixelConfig,
42 kAlpha_8_GrPixelConfig,
43 kAlpha_8_as_Alpha_GrPixelConfig,
44 kAlpha_8_as_Red_GrPixelConfig,
45 kGray_8_GrPixelConfig,
46 kGray_8_as_Lum_GrPixelConfig,
47 kGray_8_as_Red_GrPixelConfig,
48 kRGB_565_GrPixelConfig,
49 kRGBA_4444_GrPixelConfig,
50 kRGBA_8888_GrPixelConfig,
51 kRGB_888_GrPixelConfig,
52 kRGB_888X_GrPixelConfig,
53 kRG_88_GrPixelConfig,
54 kBGRA_8888_GrPixelConfig,
55 kSRGBA_8888_GrPixelConfig,
56 kRGBA_1010102_GrPixelConfig,
57 kRGBA_float_GrPixelConfig,
58 kAlpha_half_GrPixelConfig,
59 kAlpha_half_as_Lum_GrPixelConfig,
60 kAlpha_half_as_Red_GrPixelConfig,
61 kRGBA_half_GrPixelConfig,
62 kRGBA_half_Clamped_GrPixelConfig,
63 kRGB_ETC1_GrPixelConfig,
64 kR_16_GrPixelConfig,
65 kRG_1616_GrPixelConfig,
66
67 // Experimental (for Y416 and mutant P016/P010)
68 kRGBA_16161616_GrPixelConfig,
69 kRG_half_GrPixelConfig,
70 kRGB_ASTC_GrPixelConfig,
71 kLast_GrPixelConfig = kRGB_ASTC_GrPixelConfig
72 };
73 static const int kGrPixelConfigCnt = kLast_GrPixelConfig + 1;
74
75 // Aliases for pixel configs that match skia's byte order.
76 #ifndef SK_CPU_LENDIAN
77 #error "Skia gpu currently assumes little endian"
78 #endif
79 #if SK_PMCOLOR_BYTE_ORDER(B,G,R,A)
80 static const GrPixelConfig kSkia8888_GrPixelConfig = kBGRA_8888_GrPixelConfig;
81 #elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A)
82 static const GrPixelConfig kSkia8888_GrPixelConfig = kRGBA_8888_GrPixelConfig;
83 #else
84 #error "SK_*32_SHIFT values must correspond to GL_BGRA or GL_RGBA format."
85 #endif
86
87 /**
88 * Geometric primitives used for drawing.
89 */
90 enum class GrPrimitiveType {
91 kTriangles,
92 kTriangleStrip,
93 kPoints,
94 kLines, // 1 pix wide only
95 kLineStrip, // 1 pix wide only
96 kLinesAdjacency // requires geometry shader support.
97 };
98 static constexpr int kNumGrPrimitiveTypes = (int)GrPrimitiveType::kLinesAdjacency + 1;
99
GrIsPrimTypeLines(GrPrimitiveType type)100 static constexpr bool GrIsPrimTypeLines(GrPrimitiveType type) {
101 return GrPrimitiveType::kLines == type ||
102 GrPrimitiveType::kLineStrip == type ||
103 GrPrimitiveType::kLinesAdjacency == type;
104 }
105
GrIsPrimTypeTris(GrPrimitiveType type)106 static constexpr bool GrIsPrimTypeTris(GrPrimitiveType type) {
107 return GrPrimitiveType::kTriangles == type || GrPrimitiveType::kTriangleStrip == type;
108 }
109
GrPrimTypeRequiresGeometryShaderSupport(GrPrimitiveType type)110 static constexpr bool GrPrimTypeRequiresGeometryShaderSupport(GrPrimitiveType type) {
111 return GrPrimitiveType::kLinesAdjacency == type;
112 }
113
114 enum class GrPrimitiveRestart : bool {
115 kNo = false,
116 kYes = true
117 };
118
119 /**
120 * Formats for masks, used by the font cache. Important that these are 0-based.
121 */
122 enum GrMaskFormat {
123 kA8_GrMaskFormat, //!< 1-byte per pixel
124 kA565_GrMaskFormat, //!< 2-bytes per pixel, RGB represent 3-channel LCD coverage
125 kARGB_GrMaskFormat, //!< 4-bytes per pixel, color format
126
127 kLast_GrMaskFormat = kARGB_GrMaskFormat
128 };
129 static const int kMaskFormatCount = kLast_GrMaskFormat + 1;
130
131 /**
132 * Return the number of bytes-per-pixel for the specified mask format.
133 */
GrMaskFormatBytesPerPixel(GrMaskFormat format)134 static inline int GrMaskFormatBytesPerPixel(GrMaskFormat format) {
135 SkASSERT(format < kMaskFormatCount);
136 // kA8 (0) -> 1
137 // kA565 (1) -> 2
138 // kARGB (2) -> 4
139 static const int sBytesPerPixel[] = {1, 2, 4};
140 static_assert(SK_ARRAY_COUNT(sBytesPerPixel) == kMaskFormatCount, "array_size_mismatch");
141 static_assert(kA8_GrMaskFormat == 0, "enum_order_dependency");
142 static_assert(kA565_GrMaskFormat == 1, "enum_order_dependency");
143 static_assert(kARGB_GrMaskFormat == 2, "enum_order_dependency");
144
145 return sBytesPerPixel[(int)format];
146 }
147
148 /**
149 * Describes a surface to be created.
150 */
151 struct GrSurfaceDesc {
GrSurfaceDescGrSurfaceDesc152 GrSurfaceDesc() : fWidth(0), fHeight(0), fConfig(kUnknown_GrPixelConfig) {}
153
154 int fWidth; //!< Width of the texture
155 int fHeight; //!< Height of the texture
156
157 /**
158 * Format of source data of the texture. Not guaranteed to be the same as
159 * internal format used by 3D API.
160 */
161 GrPixelConfig fConfig;
162
163 // 4 ids.
164 uint32_t fGrTag[4] { 0, 0, 0, 0 };
165
isGrTagValidGrSurfaceDesc166 bool isGrTagValid() const {
167 // 0, 1, 2, 3: index of array fGrTag.
168 return fGrTag[0] || fGrTag[1] || fGrTag[2] || fGrTag[3];
169 }
170
setGrTagGrSurfaceDesc171 void setGrTag(uint32_t pid, uint32_t tid, uint32_t wid, uint32_t fid) {
172 // 0, 1, 2, 3: index of array fGrTag.
173 fGrTag[0] = pid;
174 fGrTag[1] = tid;
175 fGrTag[2] = wid;
176 fGrTag[3] = fid;
177 }
178 };
179
180 /** Ownership rules for external GPU resources imported into Skia. */
181 enum GrWrapOwnership {
182 /** Skia will assume the client will keep the resource alive and Skia will not free it. */
183 kBorrow_GrWrapOwnership,
184
185 /** Skia will assume ownership of the resource and free it. */
186 kAdopt_GrWrapOwnership,
187 };
188
189 enum class GrWrapCacheable : bool {
190 /**
191 * The wrapped resource will be removed from the cache as soon as it becomes purgeable. It may
192 * still be assigned and found by a unique key, but the presence of the key will not be used to
193 * keep the resource alive when it has no references.
194 */
195 kNo = false,
196 /**
197 * The wrapped resource is allowed to remain in the GrResourceCache when it has no references
198 * but has a unique key. Such resources should only be given unique keys when it is known that
199 * the key will eventually be removed from the resource or invalidated via the message bus.
200 */
201 kYes = true
202 };
203
204 enum class GrBudgetedType : uint8_t {
205 /** The resource is budgeted and is subject to purging under budget pressure. */
206 kBudgeted,
207 /**
208 * The resource is unbudgeted and is purged as soon as it has no refs regardless of whether
209 * it has a unique or scratch key.
210 */
211 kUnbudgetedUncacheable,
212 /**
213 * The resource is unbudgeted and is allowed to remain in the cache with no refs if it
214 * has a unique key. Scratch keys are ignored.
215 */
216 kUnbudgetedCacheable,
217 };
218
219 /**
220 * Clips are composed from these objects.
221 */
222 enum GrClipType {
223 kRect_ClipType,
224 kPath_ClipType
225 };
226
227 enum class GrScissorTest : bool {
228 kDisabled = false,
229 kEnabled = true
230 };
231
232 struct GrMipLevel {
233 const void* fPixels = nullptr;
234 size_t fRowBytes = 0;
235 };
236
237 /**
238 * This enum is used to specify the load operation to be used when an opList/GrGpuCommandBuffer
239 * begins execution.
240 */
241 enum class GrLoadOp {
242 kLoad,
243 kClear,
244 kDiscard,
245 };
246
247 /**
248 * This enum is used to specify the store operation to be used when an opList/GrGpuCommandBuffer
249 * ends execution.
250 */
251 enum class GrStoreOp {
252 kStore,
253 kDiscard,
254 };
255
256 /**
257 * Used to control antialiasing in draw calls.
258 */
259 enum class GrAA : bool {
260 kNo = false,
261 kYes = true
262 };
263
264 enum class GrFillRule : bool {
265 kNonzero,
266 kEvenOdd
267 };
268
GrFillRuleForSkPath(const SkPath & path)269 inline GrFillRule GrFillRuleForSkPath(const SkPath& path) {
270 switch (path.getFillType()) {
271 case SkPath::kWinding_FillType:
272 case SkPath::kInverseWinding_FillType:
273 return GrFillRule::kNonzero;
274 case SkPath::kEvenOdd_FillType:
275 case SkPath::kInverseEvenOdd_FillType:
276 return GrFillRule::kEvenOdd;
277 }
278 SkUNREACHABLE;
279 }
280
281 /** This enum indicates the type of antialiasing to be performed. */
282 enum class GrAAType : unsigned {
283 /** No antialiasing */
284 kNone,
285 /** Use fragment shader code or mixed samples to blend with a fractional pixel coverage. */
286 kCoverage,
287 /** Use normal MSAA. */
288 kMSAA
289 };
290
GrAATypeIsHW(GrAAType type)291 static constexpr bool GrAATypeIsHW(GrAAType type) {
292 switch (type) {
293 case GrAAType::kNone:
294 return false;
295 case GrAAType::kCoverage:
296 return false;
297 case GrAAType::kMSAA:
298 return true;
299 }
300 SkUNREACHABLE;
301 }
302
303 /**
304 * Some pixel configs are inherently clamped to [0,1], some are allowed to go outside that range,
305 * and some are FP but manually clamped in the XP.
306 */
307 enum class GrClampType {
308 kAuto, // Normalized, fixed-point configs
309 kManual, // Clamped FP configs
310 kNone, // Normal (unclamped) FP configs
311 };
312
313 /**
314 * A number of rectangle/quadrilateral drawing APIs can control anti-aliasing on a per edge basis.
315 * These masks specify which edges are AA'ed. The intent for this is to support tiling with seamless
316 * boundaries, where the inner edges are non-AA and the outer edges are AA. Regular draws (where AA
317 * is specified by GrAA) is almost equivalent to kNone or kAll, with the exception of how MSAA is
318 * handled.
319 *
320 * When tiling and there is MSAA, mixed edge rectangles are processed with MSAA, so in order for the
321 * tiled edges to remain seamless, inner tiles with kNone must also be processed with MSAA. In
322 * regular drawing, however, kNone should disable MSAA (if it's supported) to match the expected
323 * appearance.
324 *
325 * Therefore, APIs that use per-edge AA flags also take a GrAA value so that they can differentiate
326 * between the regular and tiling use case behaviors. Tiling operations should always pass
327 * GrAA::kYes while regular options should pass GrAA based on the SkPaint's anti-alias state.
328 */
329 enum class GrQuadAAFlags {
330 kLeft = SkCanvas::kLeft_QuadAAFlag,
331 kTop = SkCanvas::kTop_QuadAAFlag,
332 kRight = SkCanvas::kRight_QuadAAFlag,
333 kBottom = SkCanvas::kBottom_QuadAAFlag,
334
335 kNone = SkCanvas::kNone_QuadAAFlags,
336 kAll = SkCanvas::kAll_QuadAAFlags
337 };
338
GR_MAKE_BITFIELD_CLASS_OPS(GrQuadAAFlags)339 GR_MAKE_BITFIELD_CLASS_OPS(GrQuadAAFlags)
340
341 static inline GrQuadAAFlags SkToGrQuadAAFlags(unsigned flags) {
342 return static_cast<GrQuadAAFlags>(flags);
343 }
344
345 /**
346 * Types of shader-language-specific boxed variables we can create.
347 */
348 enum GrSLType {
349 kVoid_GrSLType,
350 kBool_GrSLType,
351 kByte_GrSLType,
352 kByte2_GrSLType,
353 kByte3_GrSLType,
354 kByte4_GrSLType,
355 kUByte_GrSLType,
356 kUByte2_GrSLType,
357 kUByte3_GrSLType,
358 kUByte4_GrSLType,
359 kShort_GrSLType,
360 kShort2_GrSLType,
361 kShort3_GrSLType,
362 kShort4_GrSLType,
363 kUShort_GrSLType,
364 kUShort2_GrSLType,
365 kUShort3_GrSLType,
366 kUShort4_GrSLType,
367 kFloat_GrSLType,
368 kFloat2_GrSLType,
369 kFloat3_GrSLType,
370 kFloat4_GrSLType,
371 kFloat2x2_GrSLType,
372 kFloat3x3_GrSLType,
373 kFloat4x4_GrSLType,
374 kHalf_GrSLType,
375 kHalf2_GrSLType,
376 kHalf3_GrSLType,
377 kHalf4_GrSLType,
378 kHalf2x2_GrSLType,
379 kHalf3x3_GrSLType,
380 kHalf4x4_GrSLType,
381 kInt_GrSLType,
382 kInt2_GrSLType,
383 kInt3_GrSLType,
384 kInt4_GrSLType,
385 kUint_GrSLType,
386 kUint2_GrSLType,
387 kTexture2DSampler_GrSLType,
388 kTextureExternalSampler_GrSLType,
389 kTexture2DRectSampler_GrSLType,
390 kTexture2D_GrSLType,
391 kSampler_GrSLType,
392
393 kLast_GrSLType = kSampler_GrSLType
394 };
395 static const int kGrSLTypeCount = kLast_GrSLType + 1;
396
397 /**
398 * The type of texture. Backends other than GL currently only use the 2D value but the type must
399 * still be known at the API-neutral layer as it used to determine whether MIP maps, renderability,
400 * and sampling parameters are legal for proxies that will be instantiated with wrapped textures.
401 */
402 enum class GrTextureType {
403 kNone,
404 k2D,
405 /* Rectangle uses unnormalized texture coordinates. */
406 kRectangle,
407 kExternal
408 };
409
410 enum GrShaderType {
411 kVertex_GrShaderType,
412 kGeometry_GrShaderType,
413 kFragment_GrShaderType,
414
415 kLastkFragment_GrShaderType = kFragment_GrShaderType
416 };
417 static const int kGrShaderTypeCount = kLastkFragment_GrShaderType + 1;
418
419 enum GrShaderFlags {
420 kNone_GrShaderFlags = 0,
421 kVertex_GrShaderFlag = 1 << kVertex_GrShaderType,
422 kGeometry_GrShaderFlag = 1 << kGeometry_GrShaderType,
423 kFragment_GrShaderFlag = 1 << kFragment_GrShaderType
424 };
GR_MAKE_BITFIELD_OPS(GrShaderFlags)425 GR_MAKE_BITFIELD_OPS(GrShaderFlags)
426
427 /** Is the shading language type float (including vectors/matrices)? */
428 static constexpr bool GrSLTypeIsFloatType(GrSLType type) {
429 switch (type) {
430 case kFloat_GrSLType:
431 case kFloat2_GrSLType:
432 case kFloat3_GrSLType:
433 case kFloat4_GrSLType:
434 case kFloat2x2_GrSLType:
435 case kFloat3x3_GrSLType:
436 case kFloat4x4_GrSLType:
437 case kHalf_GrSLType:
438 case kHalf2_GrSLType:
439 case kHalf3_GrSLType:
440 case kHalf4_GrSLType:
441 case kHalf2x2_GrSLType:
442 case kHalf3x3_GrSLType:
443 case kHalf4x4_GrSLType:
444 return true;
445
446 case kVoid_GrSLType:
447 case kTexture2DSampler_GrSLType:
448 case kTextureExternalSampler_GrSLType:
449 case kTexture2DRectSampler_GrSLType:
450 case kBool_GrSLType:
451 case kByte_GrSLType:
452 case kByte2_GrSLType:
453 case kByte3_GrSLType:
454 case kByte4_GrSLType:
455 case kUByte_GrSLType:
456 case kUByte2_GrSLType:
457 case kUByte3_GrSLType:
458 case kUByte4_GrSLType:
459 case kShort_GrSLType:
460 case kShort2_GrSLType:
461 case kShort3_GrSLType:
462 case kShort4_GrSLType:
463 case kUShort_GrSLType:
464 case kUShort2_GrSLType:
465 case kUShort3_GrSLType:
466 case kUShort4_GrSLType:
467 case kInt_GrSLType:
468 case kInt2_GrSLType:
469 case kInt3_GrSLType:
470 case kInt4_GrSLType:
471 case kUint_GrSLType:
472 case kUint2_GrSLType:
473 case kTexture2D_GrSLType:
474 case kSampler_GrSLType:
475 return false;
476 }
477 SkUNREACHABLE;
478 }
479
480 /** If the type represents a single value or vector return the vector length, else -1. */
GrSLTypeVecLength(GrSLType type)481 static constexpr int GrSLTypeVecLength(GrSLType type) {
482 switch (type) {
483 case kFloat_GrSLType:
484 case kHalf_GrSLType:
485 case kBool_GrSLType:
486 case kByte_GrSLType:
487 case kUByte_GrSLType:
488 case kShort_GrSLType:
489 case kUShort_GrSLType:
490 case kInt_GrSLType:
491 case kUint_GrSLType:
492 return 1;
493
494 case kFloat2_GrSLType:
495 case kHalf2_GrSLType:
496 case kByte2_GrSLType:
497 case kUByte2_GrSLType:
498 case kShort2_GrSLType:
499 case kUShort2_GrSLType:
500 case kInt2_GrSLType:
501 case kUint2_GrSLType:
502 return 2;
503
504 case kFloat3_GrSLType:
505 case kHalf3_GrSLType:
506 case kByte3_GrSLType:
507 case kUByte3_GrSLType:
508 case kShort3_GrSLType:
509 case kUShort3_GrSLType:
510 case kInt3_GrSLType:
511 return 3;
512
513 case kFloat4_GrSLType:
514 case kHalf4_GrSLType:
515 case kByte4_GrSLType:
516 case kUByte4_GrSLType:
517 case kShort4_GrSLType:
518 case kUShort4_GrSLType:
519 case kInt4_GrSLType:
520 return 4;
521
522 case kFloat2x2_GrSLType:
523 case kFloat3x3_GrSLType:
524 case kFloat4x4_GrSLType:
525 case kHalf2x2_GrSLType:
526 case kHalf3x3_GrSLType:
527 case kHalf4x4_GrSLType:
528 case kVoid_GrSLType:
529 case kTexture2DSampler_GrSLType:
530 case kTextureExternalSampler_GrSLType:
531 case kTexture2DRectSampler_GrSLType:
532 case kTexture2D_GrSLType:
533 case kSampler_GrSLType:
534 return -1;
535 }
536 SkUNREACHABLE;
537 }
538
GrSLCombinedSamplerTypeForTextureType(GrTextureType type)539 static inline GrSLType GrSLCombinedSamplerTypeForTextureType(GrTextureType type) {
540 switch (type) {
541 case GrTextureType::k2D:
542 return kTexture2DSampler_GrSLType;
543 case GrTextureType::kRectangle:
544 return kTexture2DRectSampler_GrSLType;
545 case GrTextureType::kExternal:
546 return kTextureExternalSampler_GrSLType;
547 default:
548 SK_ABORT("Unexpected texture type");
549 }
550 }
551
552 /** Rectangle and external textures only support the clamp wrap mode and do not support
553 * MIP maps.
554 */
GrTextureTypeHasRestrictedSampling(GrTextureType type)555 static inline bool GrTextureTypeHasRestrictedSampling(GrTextureType type) {
556 switch (type) {
557 case GrTextureType::k2D:
558 return false;
559 case GrTextureType::kRectangle:
560 return true;
561 case GrTextureType::kExternal:
562 return true;
563 default:
564 SK_ABORT("Unexpected texture type");
565 }
566 }
567
GrSLTypeIsCombinedSamplerType(GrSLType type)568 static constexpr bool GrSLTypeIsCombinedSamplerType(GrSLType type) {
569 switch (type) {
570 case kTexture2DSampler_GrSLType:
571 case kTextureExternalSampler_GrSLType:
572 case kTexture2DRectSampler_GrSLType:
573 return true;
574
575 case kVoid_GrSLType:
576 case kFloat_GrSLType:
577 case kFloat2_GrSLType:
578 case kFloat3_GrSLType:
579 case kFloat4_GrSLType:
580 case kFloat2x2_GrSLType:
581 case kFloat3x3_GrSLType:
582 case kFloat4x4_GrSLType:
583 case kHalf_GrSLType:
584 case kHalf2_GrSLType:
585 case kHalf3_GrSLType:
586 case kHalf4_GrSLType:
587 case kHalf2x2_GrSLType:
588 case kHalf3x3_GrSLType:
589 case kHalf4x4_GrSLType:
590 case kInt_GrSLType:
591 case kInt2_GrSLType:
592 case kInt3_GrSLType:
593 case kInt4_GrSLType:
594 case kUint_GrSLType:
595 case kUint2_GrSLType:
596 case kBool_GrSLType:
597 case kByte_GrSLType:
598 case kByte2_GrSLType:
599 case kByte3_GrSLType:
600 case kByte4_GrSLType:
601 case kUByte_GrSLType:
602 case kUByte2_GrSLType:
603 case kUByte3_GrSLType:
604 case kUByte4_GrSLType:
605 case kShort_GrSLType:
606 case kShort2_GrSLType:
607 case kShort3_GrSLType:
608 case kShort4_GrSLType:
609 case kUShort_GrSLType:
610 case kUShort2_GrSLType:
611 case kUShort3_GrSLType:
612 case kUShort4_GrSLType:
613 case kTexture2D_GrSLType:
614 case kSampler_GrSLType:
615 return false;
616 }
617 SkUNREACHABLE;
618 }
619
620 //////////////////////////////////////////////////////////////////////////////
621
622 /**
623 * Types used to describe format of vertices in arrays.
624 */
625 enum GrVertexAttribType {
626 kFloat_GrVertexAttribType = 0,
627 kFloat2_GrVertexAttribType,
628 kFloat3_GrVertexAttribType,
629 kFloat4_GrVertexAttribType,
630 kHalf_GrVertexAttribType,
631 kHalf2_GrVertexAttribType,
632 kHalf3_GrVertexAttribType,
633 kHalf4_GrVertexAttribType,
634
635 kInt2_GrVertexAttribType, // vector of 2 32-bit ints
636 kInt3_GrVertexAttribType, // vector of 3 32-bit ints
637 kInt4_GrVertexAttribType, // vector of 4 32-bit ints
638
639
640 kByte_GrVertexAttribType, // signed byte
641 kByte2_GrVertexAttribType, // vector of 2 8-bit signed bytes
642 kByte3_GrVertexAttribType, // vector of 3 8-bit signed bytes
643 kByte4_GrVertexAttribType, // vector of 4 8-bit signed bytes
644 kUByte_GrVertexAttribType, // unsigned byte
645 kUByte2_GrVertexAttribType, // vector of 2 8-bit unsigned bytes
646 kUByte3_GrVertexAttribType, // vector of 3 8-bit unsigned bytes
647 kUByte4_GrVertexAttribType, // vector of 4 8-bit unsigned bytes
648
649 kUByte_norm_GrVertexAttribType, // unsigned byte, e.g. coverage, 0 -> 0.0f, 255 -> 1.0f.
650 kUByte4_norm_GrVertexAttribType, // vector of 4 unsigned bytes, e.g. colors, 0 -> 0.0f,
651 // 255 -> 1.0f.
652
653 kShort2_GrVertexAttribType, // vector of 2 16-bit shorts.
654 kShort4_GrVertexAttribType, // vector of 4 16-bit shorts.
655
656 kUShort2_GrVertexAttribType, // vector of 2 unsigned shorts. 0 -> 0, 65535 -> 65535.
657 kUShort2_norm_GrVertexAttribType, // vector of 2 unsigned shorts. 0 -> 0.0f, 65535 -> 1.0f.
658
659 kInt_GrVertexAttribType,
660 kUint_GrVertexAttribType,
661
662 kUShort_norm_GrVertexAttribType,
663
664 // Experimental (for Y416)
665 kUShort4_norm_GrVertexAttribType, // vector of 4 unsigned shorts. 0 -> 0.0f, 65535 -> 1.0f.
666
667 kLast_GrVertexAttribType = kUShort4_norm_GrVertexAttribType
668 };
669 static const int kGrVertexAttribTypeCount = kLast_GrVertexAttribType + 1;
670
671 //////////////////////////////////////////////////////////////////////////////
672
673 static const int kGrClipEdgeTypeCnt = (int) GrClipEdgeType::kLast + 1;
674
GrProcessorEdgeTypeIsFill(const GrClipEdgeType edgeType)675 static constexpr bool GrProcessorEdgeTypeIsFill(const GrClipEdgeType edgeType) {
676 return (GrClipEdgeType::kFillAA == edgeType || GrClipEdgeType::kFillBW == edgeType);
677 }
678
GrProcessorEdgeTypeIsInverseFill(const GrClipEdgeType edgeType)679 static constexpr bool GrProcessorEdgeTypeIsInverseFill(const GrClipEdgeType edgeType) {
680 return (GrClipEdgeType::kInverseFillAA == edgeType ||
681 GrClipEdgeType::kInverseFillBW == edgeType);
682 }
683
GrProcessorEdgeTypeIsAA(const GrClipEdgeType edgeType)684 static constexpr bool GrProcessorEdgeTypeIsAA(const GrClipEdgeType edgeType) {
685 return (GrClipEdgeType::kFillBW != edgeType &&
686 GrClipEdgeType::kInverseFillBW != edgeType);
687 }
688
GrInvertProcessorEdgeType(const GrClipEdgeType edgeType)689 static inline GrClipEdgeType GrInvertProcessorEdgeType(const GrClipEdgeType edgeType) {
690 switch (edgeType) {
691 case GrClipEdgeType::kFillBW:
692 return GrClipEdgeType::kInverseFillBW;
693 case GrClipEdgeType::kFillAA:
694 return GrClipEdgeType::kInverseFillAA;
695 case GrClipEdgeType::kInverseFillBW:
696 return GrClipEdgeType::kFillBW;
697 case GrClipEdgeType::kInverseFillAA:
698 return GrClipEdgeType::kFillAA;
699 case GrClipEdgeType::kHairlineAA:
700 SK_ABORT("Hairline fill isn't invertible.");
701 }
702 return GrClipEdgeType::kFillAA; // suppress warning.
703 }
704
705 /**
706 * Indicates the type of pending IO operations that can be recorded for gpu resources.
707 */
708 enum GrIOType {
709 kRead_GrIOType,
710 kWrite_GrIOType,
711 kRW_GrIOType
712 };
713
714 /**
715 * Indicates the type of data that a GPU buffer will be used for.
716 */
717 enum class GrGpuBufferType {
718 kVertex,
719 kIndex,
720 kXferCpuToGpu,
721 kXferGpuToCpu,
722 };
723 static const int kGrGpuBufferTypeCount = static_cast<int>(GrGpuBufferType::kXferGpuToCpu) + 1;
724
725 /**
726 * Provides a performance hint regarding the frequency at which a data store will be accessed.
727 */
728 enum GrAccessPattern {
729 /** Data store will be respecified repeatedly and used many times. */
730 kDynamic_GrAccessPattern,
731 /** Data store will be specified once and used many times. (Thus disqualified from caching.) */
732 kStatic_GrAccessPattern,
733 /** Data store will be specified once and used at most a few times. (Also can't be cached.) */
734 kStream_GrAccessPattern,
735
736 kLast_GrAccessPattern = kStream_GrAccessPattern
737 };
738
739 // Flags shared between the GrSurface & GrSurfaceProxy class hierarchies
740 enum class GrInternalSurfaceFlags {
741 kNone = 0,
742
743 // Surface-level
744 // Texture-level
745
746 // Means the pixels in the texture are read-only. Cannot also be a GrRenderTarget[Proxy].
747 kReadOnly = 1 << 0,
748
749 kTextureMask = kReadOnly,
750
751 // RT-level
752
753 // This flag is for use with GL only. It tells us that the internal render target wraps FBO 0.
754 kGLRTFBOIDIs0 = 1 << 2,
755
756 kRenderTargetMask = kGLRTFBOIDIs0,
757 };
758 GR_MAKE_BITFIELD_CLASS_OPS(GrInternalSurfaceFlags)
759
760 #ifdef SK_DEBUG
761 // Takes a pointer to a GrCaps, and will suppress prints if required
762 #define GrCapsDebugf(caps, ...) if (!(caps)->suppressPrints()) SkDebugf(__VA_ARGS__)
763 #else
764 #define GrCapsDebugf(caps, ...) do {} while (0)
765 #endif
766
767 /**
768 * Specifies if the holder owns the backend, OpenGL or Vulkan, object.
769 */
770 enum class GrBackendObjectOwnership : bool {
771 /** Holder does not destroy the backend object. */
772 kBorrowed = false,
773 /** Holder destroys the backend object. */
774 kOwned = true
775 };
776
777 template <typename T>
unique_ptr_address_as_pointer_address(std::unique_ptr<T> const * up)778 T* const* unique_ptr_address_as_pointer_address(std::unique_ptr<T> const* up) {
779 static_assert(sizeof(T*) == sizeof(std::unique_ptr<T>), "unique_ptr not expected size.");
780 return reinterpret_cast<T* const*>(up);
781 }
782
783 /*
784 * Object for CPU-GPU synchronization
785 */
786 typedef uint64_t GrFence;
787
788 /**
789 * Used to include or exclude specific GPU path renderers for testing purposes.
790 */
791 enum class GpuPathRenderers {
792 kNone = 0, // Always use software masks and/or GrDefaultPathRenderer.
793 kDashLine = 1 << 0,
794 kStencilAndCover = 1 << 1,
795 kCoverageCounting = 1 << 2,
796 kAAHairline = 1 << 3,
797 kAAConvex = 1 << 4,
798 kAALinearizing = 1 << 5,
799 kSmall = 1 << 6,
800 kTessellating = 1 << 7,
801
802 kAll = (kTessellating | (kTessellating - 1)),
803 kDefault = kAll & ~kCoverageCounting
804
805 };
806
807 /**
808 * Used to describe the current state of Mips on a GrTexture
809 */
810 enum class GrMipMapsStatus {
811 kNotAllocated, // Mips have not been allocated
812 kDirty, // Mips are allocated but the full mip tree does not have valid data
813 kValid, // All levels fully allocated and have valid data in them
814 };
815
816 GR_MAKE_BITFIELD_CLASS_OPS(GpuPathRenderers)
817
818 /**
819 * Describes whether pixel data encoding should be converted to/from linear/sRGB encoding.
820 */
821 enum class GrSRGBConversion {
822 kNone,
823 kSRGBToLinear,
824 kLinearToSRGB,
825 };
826
827 /**
828 * Utility functions for GrPixelConfig
829 */
830
GrPixelConfigIsSRGB(GrPixelConfig config)831 static constexpr bool GrPixelConfigIsSRGB(GrPixelConfig config) {
832 switch (config) {
833 case kSRGBA_8888_GrPixelConfig:
834 return true;
835 case kUnknown_GrPixelConfig:
836 case kAlpha_8_GrPixelConfig:
837 case kAlpha_8_as_Alpha_GrPixelConfig:
838 case kAlpha_8_as_Red_GrPixelConfig:
839 case kGray_8_GrPixelConfig:
840 case kGray_8_as_Lum_GrPixelConfig:
841 case kGray_8_as_Red_GrPixelConfig:
842 case kRGB_565_GrPixelConfig:
843 case kRGBA_4444_GrPixelConfig:
844 case kRGB_888_GrPixelConfig:
845 case kRGB_888X_GrPixelConfig:
846 case kRG_88_GrPixelConfig:
847 case kRGBA_8888_GrPixelConfig:
848 case kBGRA_8888_GrPixelConfig:
849 case kRGBA_1010102_GrPixelConfig:
850 case kRGBA_float_GrPixelConfig:
851 case kAlpha_half_GrPixelConfig:
852 case kAlpha_half_as_Lum_GrPixelConfig:
853 case kAlpha_half_as_Red_GrPixelConfig:
854 case kRGBA_half_GrPixelConfig:
855 case kRGBA_half_Clamped_GrPixelConfig:
856 case kRGB_ETC1_GrPixelConfig:
857 case kRGB_ASTC_GrPixelConfig:
858 case kR_16_GrPixelConfig:
859 case kRG_1616_GrPixelConfig:
860 // Experimental (for Y416 and mutant P016/P010)
861 case kRGBA_16161616_GrPixelConfig:
862 case kRG_half_GrPixelConfig:
863 return false;
864 }
865 SkUNREACHABLE;
866 }
867
GrCompressionTypePixelConfig(SkImage::CompressionType compression)868 static constexpr GrPixelConfig GrCompressionTypePixelConfig(SkImage::CompressionType compression) {
869 switch (compression) {
870 case SkImage::kETC1_CompressionType: return kRGB_ETC1_GrPixelConfig;
871 case SkImage::kASTC_CompressionType: return kRGB_ASTC_GrPixelConfig;
872 }
873 SkUNREACHABLE;
874 }
875
GrBytesPerPixel(GrPixelConfig config)876 static constexpr size_t GrBytesPerPixel(GrPixelConfig config) {
877 switch (config) {
878 case kAlpha_8_GrPixelConfig:
879 case kAlpha_8_as_Alpha_GrPixelConfig:
880 case kAlpha_8_as_Red_GrPixelConfig:
881 case kGray_8_GrPixelConfig:
882 case kGray_8_as_Lum_GrPixelConfig:
883 case kGray_8_as_Red_GrPixelConfig:
884 return 1;
885 case kRGB_565_GrPixelConfig:
886 case kRGBA_4444_GrPixelConfig:
887 case kRG_88_GrPixelConfig:
888 case kAlpha_half_GrPixelConfig:
889 case kAlpha_half_as_Lum_GrPixelConfig:
890 case kAlpha_half_as_Red_GrPixelConfig:
891 case kR_16_GrPixelConfig:
892 return 2;
893 case kRGBA_8888_GrPixelConfig:
894 case kRGB_888_GrPixelConfig: // Assuming GPUs store this 4-byte aligned.
895 case kRGB_888X_GrPixelConfig:
896 case kBGRA_8888_GrPixelConfig:
897 case kSRGBA_8888_GrPixelConfig:
898 case kRGBA_1010102_GrPixelConfig:
899 case kRG_1616_GrPixelConfig:
900 return 4;
901 case kRGBA_half_GrPixelConfig:
902 case kRGBA_half_Clamped_GrPixelConfig:
903 return 8;
904 case kRGBA_float_GrPixelConfig:
905 return 16;
906 case kUnknown_GrPixelConfig:
907 case kRGB_ETC1_GrPixelConfig:
908 case kRGB_ASTC_GrPixelConfig:
909 return 0;
910
911 // Experimental (for Y416 and mutant P016/P010)
912 case kRGBA_16161616_GrPixelConfig:
913 return 8;
914 case kRG_half_GrPixelConfig:
915 return 4;
916 }
917 SkUNREACHABLE;
918 }
919
GrPixelConfigIsOpaque(GrPixelConfig config)920 static constexpr bool GrPixelConfigIsOpaque(GrPixelConfig config) {
921 switch (config) {
922 case kRGB_565_GrPixelConfig:
923 case kRGB_888_GrPixelConfig:
924 case kRGB_888X_GrPixelConfig:
925 case kRG_88_GrPixelConfig:
926 case kGray_8_GrPixelConfig:
927 case kGray_8_as_Lum_GrPixelConfig:
928 case kGray_8_as_Red_GrPixelConfig:
929 case kRGB_ETC1_GrPixelConfig:
930 case kRGB_ASTC_GrPixelConfig:
931 case kR_16_GrPixelConfig:
932 case kRG_1616_GrPixelConfig:
933 case kRG_half_GrPixelConfig: // Experimental (for mutant P016/P010)
934 return true;
935 case kAlpha_8_GrPixelConfig:
936 case kAlpha_8_as_Alpha_GrPixelConfig:
937 case kAlpha_8_as_Red_GrPixelConfig:
938 case kRGBA_4444_GrPixelConfig:
939 case kAlpha_half_GrPixelConfig:
940 case kAlpha_half_as_Lum_GrPixelConfig:
941 case kAlpha_half_as_Red_GrPixelConfig:
942 case kRGBA_8888_GrPixelConfig:
943 case kBGRA_8888_GrPixelConfig:
944 case kSRGBA_8888_GrPixelConfig:
945 case kRGBA_1010102_GrPixelConfig:
946 case kRGBA_half_GrPixelConfig:
947 case kRGBA_half_Clamped_GrPixelConfig:
948 case kRGBA_float_GrPixelConfig:
949 case kRGBA_16161616_GrPixelConfig: // Experimental (for Y416)
950 case kUnknown_GrPixelConfig:
951 return false;
952 }
953 SkUNREACHABLE;
954 }
955
GrPixelConfigIsAlphaOnly(GrPixelConfig config)956 static constexpr bool GrPixelConfigIsAlphaOnly(GrPixelConfig config) {
957 switch (config) {
958 case kAlpha_8_GrPixelConfig:
959 case kAlpha_8_as_Alpha_GrPixelConfig:
960 case kAlpha_8_as_Red_GrPixelConfig:
961 case kAlpha_half_GrPixelConfig:
962 case kAlpha_half_as_Lum_GrPixelConfig:
963 case kAlpha_half_as_Red_GrPixelConfig:
964 return true;
965 case kUnknown_GrPixelConfig:
966 case kGray_8_GrPixelConfig:
967 case kGray_8_as_Lum_GrPixelConfig:
968 case kGray_8_as_Red_GrPixelConfig:
969 case kRGB_565_GrPixelConfig:
970 case kRGBA_4444_GrPixelConfig:
971 case kRGBA_8888_GrPixelConfig:
972 case kRGB_888_GrPixelConfig:
973 case kRGB_888X_GrPixelConfig:
974 case kRG_88_GrPixelConfig:
975 case kBGRA_8888_GrPixelConfig:
976 case kSRGBA_8888_GrPixelConfig:
977 case kRGBA_1010102_GrPixelConfig:
978 case kRGBA_float_GrPixelConfig:
979 case kRGBA_half_GrPixelConfig:
980 case kRGBA_half_Clamped_GrPixelConfig:
981 case kRGB_ETC1_GrPixelConfig:
982 case kRGB_ASTC_GrPixelConfig:
983 case kR_16_GrPixelConfig:
984 case kRG_1616_GrPixelConfig:
985 // Experimental (for Y416 and mutant P016/P010)
986 case kRGBA_16161616_GrPixelConfig:
987 case kRG_half_GrPixelConfig:
988 return false;
989 }
990 SkUNREACHABLE;
991 }
992
GrPixelConfigIsFloatingPoint(GrPixelConfig config)993 static constexpr bool GrPixelConfigIsFloatingPoint(GrPixelConfig config) {
994 switch (config) {
995 case kUnknown_GrPixelConfig:
996 case kAlpha_8_GrPixelConfig:
997 case kAlpha_8_as_Alpha_GrPixelConfig:
998 case kAlpha_8_as_Red_GrPixelConfig:
999 case kGray_8_GrPixelConfig:
1000 case kGray_8_as_Lum_GrPixelConfig:
1001 case kGray_8_as_Red_GrPixelConfig:
1002 case kRGB_565_GrPixelConfig:
1003 case kRGBA_4444_GrPixelConfig:
1004 case kRGB_888_GrPixelConfig:
1005 case kRGB_888X_GrPixelConfig:
1006 case kRG_88_GrPixelConfig:
1007 case kRGBA_8888_GrPixelConfig:
1008 case kBGRA_8888_GrPixelConfig:
1009 case kSRGBA_8888_GrPixelConfig:
1010 case kRGBA_1010102_GrPixelConfig:
1011 case kRGB_ETC1_GrPixelConfig:
1012 case kRGB_ASTC_GrPixelConfig:
1013 case kR_16_GrPixelConfig:
1014 case kRG_1616_GrPixelConfig:
1015 case kRGBA_16161616_GrPixelConfig: // Experimental (for Y416)
1016 return false;
1017 case kRGBA_float_GrPixelConfig:
1018 case kAlpha_half_GrPixelConfig:
1019 case kAlpha_half_as_Lum_GrPixelConfig:
1020 case kAlpha_half_as_Red_GrPixelConfig:
1021 case kRGBA_half_GrPixelConfig:
1022 case kRGBA_half_Clamped_GrPixelConfig:
1023 case kRG_half_GrPixelConfig: // Experimental (for mutant P016/P010)
1024 return true;
1025 }
1026 SkUNREACHABLE;
1027 }
1028
GrPixelConfigClampType(GrPixelConfig config)1029 static constexpr GrClampType GrPixelConfigClampType(GrPixelConfig config) {
1030 if (!GrPixelConfigIsFloatingPoint(config)) {
1031 return GrClampType::kAuto;
1032 }
1033 return kRGBA_half_Clamped_GrPixelConfig == config ? GrClampType::kManual : GrClampType::kNone;
1034 }
1035
1036 /**
1037 * Returns true if the pixel config is a GPU-specific compressed format
1038 * representation.
1039 */
GrPixelConfigIsCompressed(GrPixelConfig config)1040 static constexpr bool GrPixelConfigIsCompressed(GrPixelConfig config) {
1041 switch (config) {
1042 case kRGB_ETC1_GrPixelConfig:
1043 return true;
1044 case kRGB_ASTC_GrPixelConfig:
1045 return true;
1046 default:
1047 return false;
1048 }
1049 SkUNREACHABLE;
1050 }
1051
1052 /**
1053 * If the pixel config is compressed, return an equivalent uncompressed format.
1054 */
GrMakePixelConfigUncompressed(GrPixelConfig config)1055 static constexpr GrPixelConfig GrMakePixelConfigUncompressed(GrPixelConfig config) {
1056 switch (config) {
1057 case kRGB_ETC1_GrPixelConfig:
1058 return kRGBA_8888_GrPixelConfig;
1059 case kRGB_ASTC_GrPixelConfig:
1060 return kRGBA_8888_GrPixelConfig;
1061 default:
1062 return config;
1063 }
1064 SkUNREACHABLE;
1065 }
1066
1067 /**
1068 * Returns the data size for the given compressed pixel config
1069 */
GrCompressedFormatDataSize(GrPixelConfig config,int width,int height)1070 static inline size_t GrCompressedFormatDataSize(GrPixelConfig config,
1071 int width, int height) {
1072 SkASSERT(GrPixelConfigIsCompressed(config));
1073
1074 switch (config) {
1075 case kRGB_ETC1_GrPixelConfig:
1076 SkASSERT((width & 3) == 0);
1077 SkASSERT((height & 3) == 0);
1078 return (width >> 2) * (height >> 2) * 8;
1079 case kRGB_ASTC_GrPixelConfig:
1080 SkASSERT((width & 3) == 0);
1081 SkASSERT((height & 3) == 0);
1082 return (width >> 2) * (height >> 2) * 8;
1083
1084 default:
1085 SK_ABORT("Unknown compressed pixel config");
1086 }
1087
1088 SK_ABORT("Invalid pixel config");
1089 }
1090
1091 /**
1092 * Like SkColorType this describes a layout of pixel data in CPU memory. It specifies the channels,
1093 * their type, and width. This exists so that the GPU backend can have private types that have no
1094 * analog in the public facing SkColorType enum and omit types not implemented in the GPU backend.
1095 * It does not refer to a texture format and the mapping to texture formats may be many-to-many.
1096 * It does not specify the sRGB encoding of the stored values. The components are listed in order of
1097 * where they appear in memory. In other words the first component listed is in the low bits and
1098 * the last component in the high bits.
1099 */
1100 enum class GrColorType {
1101 kUnknown,
1102 kAlpha_8,
1103 kBGR_565,
1104 kABGR_4444, // This name differs from SkColorType. kARGB_4444_SkColorType is misnamed.
1105 kRGBA_8888,
1106 kRGBA_8888_SRGB,
1107 kRGB_888x,
1108 kRG_88,
1109 kBGRA_8888,
1110 kRGBA_1010102,
1111 kGray_8,
1112 kAlpha_F16,
1113 kRGBA_F16,
1114 kRGBA_F16_Clamped,
1115 kRGBA_F32,
1116
1117 // Unusual formats that come up after reading back in cases where we are reassigning the meaning
1118 // of a texture format's channels to use for a particular color format but have to read back the
1119 // data to a full RGBA quadruple. (e.g. using a R8 texture format as A8 color type but the API
1120 // only supports reading to RGBA8.) None of these have SkColorType equivalents.
1121 kAlpha_8xxx,
1122 kAlpha_F32xxx,
1123 kGray_8xxx,
1124
1125 kR_16, // Not in SkColorType
1126 kRG_1616, // Not in SkColorType
1127
1128 // Experimental (for Y416 and mutant P016/P010)
1129 kRGBA_16161616, // Not in SkColorType
1130 kRG_F16, // Not in SkColorType
1131
1132 kLast = kRG_F16
1133 };
1134
1135 static const int kGrColorTypeCnt = static_cast<int>(GrColorType::kLast) + 1;
1136
GrColorTypeToSkColorType(GrColorType ct)1137 static constexpr SkColorType GrColorTypeToSkColorType(GrColorType ct) {
1138 switch (ct) {
1139 case GrColorType::kUnknown: return kUnknown_SkColorType;
1140 case GrColorType::kAlpha_8: return kAlpha_8_SkColorType;
1141 case GrColorType::kBGR_565: return kRGB_565_SkColorType;
1142 case GrColorType::kABGR_4444: return kARGB_4444_SkColorType;
1143 case GrColorType::kRGBA_8888: return kRGBA_8888_SkColorType;
1144 // Once we a kRGBA_8888_SRGB_SkColorType we should return that here.
1145 case GrColorType::kRGBA_8888_SRGB: return kRGBA_8888_SkColorType;
1146 case GrColorType::kRGB_888x: return kRGB_888x_SkColorType;
1147 case GrColorType::kRG_88: return kUnknown_SkColorType;
1148 case GrColorType::kBGRA_8888: return kBGRA_8888_SkColorType;
1149 case GrColorType::kRGBA_1010102: return kRGBA_1010102_SkColorType;
1150 case GrColorType::kGray_8: return kGray_8_SkColorType;
1151 case GrColorType::kAlpha_F16: return kUnknown_SkColorType;
1152 case GrColorType::kRGBA_F16: return kRGBA_F16_SkColorType;
1153 case GrColorType::kRGBA_F16_Clamped: return kRGBA_F16Norm_SkColorType;
1154 case GrColorType::kRGBA_F32: return kRGBA_F32_SkColorType;
1155 case GrColorType::kAlpha_8xxx: return kUnknown_SkColorType;
1156 case GrColorType::kAlpha_F32xxx: return kUnknown_SkColorType;
1157 case GrColorType::kGray_8xxx: return kUnknown_SkColorType;
1158 case GrColorType::kR_16: return kUnknown_SkColorType;
1159 case GrColorType::kRG_1616: return kUnknown_SkColorType;
1160 // Experimental (for Y416 and mutant P016/P010)
1161 case GrColorType::kRGBA_16161616: return kUnknown_SkColorType;
1162 case GrColorType::kRG_F16: return kUnknown_SkColorType;
1163 }
1164 SkUNREACHABLE;
1165 }
1166
SkColorTypeToGrColorType(SkColorType ct)1167 static constexpr GrColorType SkColorTypeToGrColorType(SkColorType ct) {
1168 switch (ct) {
1169 case kUnknown_SkColorType: return GrColorType::kUnknown;
1170 case kAlpha_8_SkColorType: return GrColorType::kAlpha_8;
1171 case kRGB_565_SkColorType: return GrColorType::kBGR_565;
1172 case kARGB_4444_SkColorType: return GrColorType::kABGR_4444;
1173 case kRGBA_8888_SkColorType: return GrColorType::kRGBA_8888;
1174 case kRGB_888x_SkColorType: return GrColorType::kRGB_888x;
1175 case kBGRA_8888_SkColorType: return GrColorType::kBGRA_8888;
1176 case kGray_8_SkColorType: return GrColorType::kGray_8;
1177 case kRGBA_F16Norm_SkColorType: return GrColorType::kRGBA_F16_Clamped;
1178 case kRGBA_F16_SkColorType: return GrColorType::kRGBA_F16;
1179 case kRGBA_1010102_SkColorType: return GrColorType::kRGBA_1010102;
1180 case kRGB_101010x_SkColorType: return GrColorType::kUnknown;
1181 case kRGBA_F32_SkColorType: return GrColorType::kRGBA_F32;
1182 }
1183 SkUNREACHABLE;
1184 }
1185
1186 // This is a temporary means of mapping an SkColorType and format to a
1187 // GrColorType::kRGBA_8888_SRGB. Once we have an SRGB SkColorType this can go away.
1188 GrColorType SkColorTypeAndFormatToGrColorType(const GrCaps* caps,
1189 SkColorType skCT,
1190 const GrBackendFormat& format);
1191
GrColorTypeComponentFlags(GrColorType ct)1192 static constexpr uint32_t GrColorTypeComponentFlags(GrColorType ct) {
1193 switch (ct) {
1194 case GrColorType::kUnknown: return 0;
1195 case GrColorType::kAlpha_8: return kAlpha_SkColorTypeComponentFlag;
1196 case GrColorType::kBGR_565: return kRGB_SkColorTypeComponentFlags;
1197 case GrColorType::kABGR_4444: return kRGBA_SkColorTypeComponentFlags;
1198 case GrColorType::kRGBA_8888: return kRGBA_SkColorTypeComponentFlags;
1199 case GrColorType::kRGBA_8888_SRGB: return kRGBA_SkColorTypeComponentFlags;
1200 case GrColorType::kRGB_888x: return kRGB_SkColorTypeComponentFlags;
1201 case GrColorType::kRG_88: return kRed_SkColorTypeComponentFlag |
1202 kGreen_SkColorTypeComponentFlag;
1203 case GrColorType::kBGRA_8888: return kRGBA_SkColorTypeComponentFlags;
1204 case GrColorType::kRGBA_1010102: return kRGBA_SkColorTypeComponentFlags;
1205 case GrColorType::kGray_8: return kGray_SkColorTypeComponentFlag;
1206 case GrColorType::kAlpha_F16: return kAlpha_SkColorTypeComponentFlag;
1207 case GrColorType::kRGBA_F16: return kRGBA_SkColorTypeComponentFlags;
1208 case GrColorType::kRGBA_F16_Clamped: return kRGBA_SkColorTypeComponentFlags;
1209 case GrColorType::kRGBA_F32: return kRGBA_SkColorTypeComponentFlags;
1210 case GrColorType::kAlpha_8xxx: return kAlpha_SkColorTypeComponentFlag;
1211 case GrColorType::kAlpha_F32xxx: return kAlpha_SkColorTypeComponentFlag;
1212 case GrColorType::kGray_8xxx: return kGray_SkColorTypeComponentFlag;
1213 case GrColorType::kR_16: return kRed_SkColorTypeComponentFlag;
1214 case GrColorType::kRG_1616: return kRed_SkColorTypeComponentFlag |
1215 kGreen_SkColorTypeComponentFlag;
1216 // Experimental (for Y416 and mutant P016/P010)
1217 case GrColorType::kRGBA_16161616: return kRGBA_SkColorTypeComponentFlags;
1218 case GrColorType::kRG_F16: return kRed_SkColorTypeComponentFlag |
1219 kGreen_SkColorTypeComponentFlag;
1220 }
1221 SkUNREACHABLE;
1222 }
1223
1224 /**
1225 * Describes the encoding of channel data in a GrColorType.
1226 */
1227 enum class GrColorTypeEncoding {
1228 kUnorm,
1229 kSRGBUnorm,
1230 // kSnorm,
1231 kFloat,
1232 // kSint
1233 // kUint
1234 };
1235
1236 /**
1237 * Describes a GrColorType by how many bits are used for each color component and how they are
1238 * encoded. Currently all the non-zero channels share a single GrColorTypeEncoding. This could be
1239 * expanded to store separate encodings and to indicate which bits belong to which components.
1240 */
1241 struct GrColorTypeDesc {
1242 public:
MakeRGBAGrColorTypeDesc1243 static constexpr GrColorTypeDesc MakeRGBA(int rgba, GrColorTypeEncoding e) {
1244 return {rgba, rgba, rgba, rgba, 0, e};
1245 }
1246
MakeRGBAGrColorTypeDesc1247 static constexpr GrColorTypeDesc MakeRGBA(int rgb, int a, GrColorTypeEncoding e) {
1248 return {rgb, rgb, rgb, a, 0, e};
1249 }
1250
MakeRGBGrColorTypeDesc1251 static constexpr GrColorTypeDesc MakeRGB(int rgb, GrColorTypeEncoding e) {
1252 return {rgb, rgb, rgb, 0, 0, e};
1253 }
1254
MakeRGBGrColorTypeDesc1255 static constexpr GrColorTypeDesc MakeRGB(int r, int g, int b, GrColorTypeEncoding e) {
1256 return {r, g, b, 0, 0, e};
1257 }
1258
MakeAlphaGrColorTypeDesc1259 static constexpr GrColorTypeDesc MakeAlpha(int a, GrColorTypeEncoding e) {
1260 return {0, 0, 0, a, 0, e};
1261 }
1262
MakeRGrColorTypeDesc1263 static constexpr GrColorTypeDesc MakeR(int r, GrColorTypeEncoding e) {
1264 return {r, 0, 0, 0, 0, e};
1265 }
1266
MakeRGGrColorTypeDesc1267 static constexpr GrColorTypeDesc MakeRG(int rg, GrColorTypeEncoding e) {
1268 return {rg, rg, 0, 0, 0, e};
1269 }
1270
MakeGrayGrColorTypeDesc1271 static constexpr GrColorTypeDesc MakeGray(int grayBits, GrColorTypeEncoding e) {
1272 return {0, 0, 0, 0, grayBits, e};
1273 }
1274
MakeInvalidGrColorTypeDesc1275 static constexpr GrColorTypeDesc MakeInvalid() { return {}; }
1276
rGrColorTypeDesc1277 constexpr int r() const { return fRBits; }
gGrColorTypeDesc1278 constexpr int g() const { return fGBits; }
bGrColorTypeDesc1279 constexpr int b() const { return fBBits; }
aGrColorTypeDesc1280 constexpr int a() const { return fABits; }
1281 constexpr int operator[](int c) const {
1282 switch (c) {
1283 case 0: return this->r();
1284 case 1: return this->g();
1285 case 2: return this->b();
1286 case 3: return this->a();
1287 }
1288 SkUNREACHABLE;
1289 }
1290
grayGrColorTypeDesc1291 constexpr int gray() const { return fGrayBits; }
1292
encodingGrColorTypeDesc1293 constexpr GrColorTypeEncoding encoding() const { return fEncoding; }
1294
1295 private:
1296 int fRBits = 0;
1297 int fGBits = 0;
1298 int fBBits = 0;
1299 int fABits = 0;
1300 int fGrayBits = 0;
1301 GrColorTypeEncoding fEncoding = GrColorTypeEncoding::kUnorm;
1302
1303 constexpr GrColorTypeDesc() = default;
1304
GrColorTypeDescGrColorTypeDesc1305 constexpr GrColorTypeDesc(int r, int g, int b, int a, int gray, GrColorTypeEncoding encoding)
1306 : fRBits(r), fGBits(g), fBBits(b), fABits(a), fGrayBits(gray), fEncoding(encoding) {
1307 SkASSERT(r >= 0 && g >= 0 && b >= 0 && a >= 0 && gray >= 0);
1308 SkASSERT(!gray || (!r && !g && !b));
1309 SkASSERT(r || g || b || a || gray);
1310 }
1311 };
1312
GrGetColorTypeDesc(GrColorType ct)1313 static constexpr GrColorTypeDesc GrGetColorTypeDesc(GrColorType ct) {
1314 switch (ct) {
1315 case GrColorType::kUnknown:
1316 return GrColorTypeDesc::MakeInvalid();
1317 case GrColorType::kAlpha_8:
1318 return GrColorTypeDesc::MakeAlpha(8, GrColorTypeEncoding::kUnorm);
1319 case GrColorType::kBGR_565:
1320 return GrColorTypeDesc::MakeRGB(5, 6, 5, GrColorTypeEncoding::kUnorm);
1321 case GrColorType::kABGR_4444:
1322 return GrColorTypeDesc::MakeRGBA(4, GrColorTypeEncoding::kUnorm);
1323 case GrColorType::kRGBA_8888:
1324 return GrColorTypeDesc::MakeRGBA(8, GrColorTypeEncoding::kUnorm);
1325 case GrColorType::kRGBA_8888_SRGB:
1326 return GrColorTypeDesc::MakeRGBA(8, GrColorTypeEncoding::kSRGBUnorm);
1327 case GrColorType::kRGB_888x:
1328 return GrColorTypeDesc::MakeRGB(8, GrColorTypeEncoding::kUnorm);
1329 case GrColorType::kRG_88:
1330 return GrColorTypeDesc::MakeRG(8, GrColorTypeEncoding::kUnorm);
1331 case GrColorType::kBGRA_8888:
1332 return GrColorTypeDesc::MakeRGBA(8, GrColorTypeEncoding::kUnorm);
1333 case GrColorType::kRGBA_1010102:
1334 return GrColorTypeDesc::MakeRGBA(10, 2, GrColorTypeEncoding::kUnorm);
1335 case GrColorType::kGray_8:
1336 return GrColorTypeDesc::MakeGray(8, GrColorTypeEncoding::kUnorm);
1337 case GrColorType::kAlpha_F16:
1338 return GrColorTypeDesc::MakeAlpha(16, GrColorTypeEncoding::kFloat);
1339 case GrColorType::kRGBA_F16:
1340 return GrColorTypeDesc::MakeRGBA(16, GrColorTypeEncoding::kFloat);
1341 case GrColorType::kRGBA_F16_Clamped:
1342 return GrColorTypeDesc::MakeRGBA(16, GrColorTypeEncoding::kFloat);
1343 case GrColorType::kRGBA_F32:
1344 return GrColorTypeDesc::MakeRGBA(32, GrColorTypeEncoding::kFloat);
1345 case GrColorType::kAlpha_8xxx:
1346 return GrColorTypeDesc::MakeAlpha(8, GrColorTypeEncoding::kUnorm);
1347 case GrColorType::kAlpha_F32xxx:
1348 return GrColorTypeDesc::MakeAlpha(32, GrColorTypeEncoding::kFloat);
1349 case GrColorType::kGray_8xxx:
1350 return GrColorTypeDesc::MakeGray(8, GrColorTypeEncoding::kUnorm);
1351 case GrColorType::kR_16:
1352 return GrColorTypeDesc::MakeR(16, GrColorTypeEncoding::kUnorm);
1353 case GrColorType::kRG_1616:
1354 return GrColorTypeDesc::MakeRG(16, GrColorTypeEncoding::kUnorm);
1355 case GrColorType::kRGBA_16161616:
1356 return GrColorTypeDesc::MakeRGBA(16, GrColorTypeEncoding::kUnorm);
1357 case GrColorType::kRG_F16:
1358 return GrColorTypeDesc::MakeRG(16, GrColorTypeEncoding::kFloat);
1359 }
1360 SkUNREACHABLE;
1361 }
1362
GrColorTypeClampType(GrColorType colorType)1363 static constexpr GrClampType GrColorTypeClampType(GrColorType colorType) {
1364 if (GrGetColorTypeDesc(colorType).encoding() == GrColorTypeEncoding::kUnorm ||
1365 GrGetColorTypeDesc(colorType).encoding() == GrColorTypeEncoding::kSRGBUnorm) {
1366 return GrClampType::kAuto;
1367 }
1368 return GrColorType::kRGBA_F16_Clamped == colorType ? GrClampType::kManual : GrClampType::kNone;
1369 }
1370
1371 // Consider a color type "wider" than n if it has more than n bits for any its representable
1372 // channels.
GrColorTypeIsWiderThan(GrColorType colorType,int n)1373 static constexpr bool GrColorTypeIsWiderThan(GrColorType colorType, int n) {
1374 SkASSERT(n > 0);
1375 auto desc = GrGetColorTypeDesc(colorType);
1376 return (desc.r() && desc.r() > n )||
1377 (desc.g() && desc.g() > n) ||
1378 (desc.b() && desc.b() > n) ||
1379 (desc.a() && desc.a() > n) ||
1380 (desc.gray() && desc.gray() > n);
1381 }
1382
GrColorTypeIsAlphaOnly(GrColorType ct)1383 static constexpr bool GrColorTypeIsAlphaOnly(GrColorType ct) {
1384 return kAlpha_SkColorTypeComponentFlag == GrColorTypeComponentFlags(ct);
1385 }
1386
GrColorTypeHasAlpha(GrColorType ct)1387 static constexpr bool GrColorTypeHasAlpha(GrColorType ct) {
1388 return kAlpha_SkColorTypeComponentFlag & GrColorTypeComponentFlags(ct);
1389 }
1390
GrColorTypeBytesPerPixel(GrColorType ct)1391 static constexpr size_t GrColorTypeBytesPerPixel(GrColorType ct) {
1392 switch (ct) {
1393 case GrColorType::kUnknown: return 0;
1394 case GrColorType::kAlpha_8: return 1;
1395 case GrColorType::kBGR_565: return 2;
1396 case GrColorType::kABGR_4444: return 2;
1397 case GrColorType::kRGBA_8888: return 4;
1398 case GrColorType::kRGBA_8888_SRGB: return 4;
1399 case GrColorType::kRGB_888x: return 4;
1400 case GrColorType::kRG_88: return 2;
1401 case GrColorType::kBGRA_8888: return 4;
1402 case GrColorType::kRGBA_1010102: return 4;
1403 case GrColorType::kGray_8: return 1;
1404 case GrColorType::kAlpha_F16: return 2;
1405 case GrColorType::kRGBA_F16: return 8;
1406 case GrColorType::kRGBA_F16_Clamped: return 8;
1407 case GrColorType::kRGBA_F32: return 16;
1408 case GrColorType::kAlpha_8xxx: return 4;
1409 case GrColorType::kAlpha_F32xxx: return 16;
1410 case GrColorType::kGray_8xxx: return 4;
1411 case GrColorType::kR_16: return 2;
1412 case GrColorType::kRG_1616: return 4;
1413 // Experimental (for Y416 and mutant P016/P010)
1414 case GrColorType::kRGBA_16161616: return 8;
1415 case GrColorType::kRG_F16: return 4;
1416 }
1417 SkUNREACHABLE;
1418 }
1419
GrPixelConfigToColorType(GrPixelConfig config)1420 static constexpr GrColorType GrPixelConfigToColorType(GrPixelConfig config) {
1421 switch (config) {
1422 case kUnknown_GrPixelConfig:
1423 return GrColorType::kUnknown;
1424 case kAlpha_8_GrPixelConfig:
1425 return GrColorType::kAlpha_8;
1426 case kGray_8_GrPixelConfig:
1427 return GrColorType::kGray_8;
1428 case kRGB_565_GrPixelConfig:
1429 return GrColorType::kBGR_565;
1430 case kRGBA_4444_GrPixelConfig:
1431 return GrColorType::kABGR_4444;
1432 case kRGBA_8888_GrPixelConfig:
1433 return GrColorType::kRGBA_8888;
1434 case kRGB_888_GrPixelConfig:
1435 return GrColorType::kRGB_888x;
1436 case kRGB_888X_GrPixelConfig:
1437 return GrColorType::kRGB_888x;
1438 case kRG_88_GrPixelConfig:
1439 return GrColorType::kRG_88;
1440 case kBGRA_8888_GrPixelConfig:
1441 return GrColorType::kBGRA_8888;
1442 case kSRGBA_8888_GrPixelConfig:
1443 return GrColorType::kRGBA_8888_SRGB;
1444 case kRGBA_1010102_GrPixelConfig:
1445 return GrColorType::kRGBA_1010102;
1446 case kRGBA_float_GrPixelConfig:
1447 return GrColorType::kRGBA_F32;
1448 case kAlpha_half_GrPixelConfig:
1449 return GrColorType::kAlpha_F16;
1450 case kRGBA_half_GrPixelConfig:
1451 return GrColorType::kRGBA_F16;
1452 case kRGBA_half_Clamped_GrPixelConfig:
1453 return GrColorType::kRGBA_F16_Clamped;
1454 case kRGB_ETC1_GrPixelConfig:
1455 // We may need a roughly equivalent color type for a compressed texture. This should be
1456 // the logical format for decompressing the data into.
1457 return GrColorType::kRGB_888x;
1458 case kRGB_ASTC_GrPixelConfig:
1459 return GrColorType::kRGB_888x;
1460 case kAlpha_8_as_Alpha_GrPixelConfig:
1461 return GrColorType::kAlpha_8;
1462 case kAlpha_8_as_Red_GrPixelConfig:
1463 return GrColorType::kAlpha_8;
1464 case kAlpha_half_as_Lum_GrPixelConfig: // fall through
1465 case kAlpha_half_as_Red_GrPixelConfig:
1466 return GrColorType::kAlpha_F16;
1467 case kGray_8_as_Lum_GrPixelConfig:
1468 return GrColorType::kGray_8;
1469 case kGray_8_as_Red_GrPixelConfig:
1470 return GrColorType::kGray_8;
1471 case kR_16_GrPixelConfig:
1472 return GrColorType::kR_16;
1473 case kRG_1616_GrPixelConfig:
1474 return GrColorType::kRG_1616;
1475
1476 // Experimental (for Y416 and mutant P016/P010)
1477 case kRGBA_16161616_GrPixelConfig:
1478 return GrColorType::kRGBA_16161616;
1479 case kRG_half_GrPixelConfig:
1480 return GrColorType::kRG_F16;
1481 }
1482 SkUNREACHABLE;
1483 }
1484
GrColorTypeToPixelConfig(GrColorType colorType)1485 static constexpr GrPixelConfig GrColorTypeToPixelConfig(GrColorType colorType) {
1486 switch (colorType) {
1487 case GrColorType::kUnknown: return kUnknown_GrPixelConfig;
1488 case GrColorType::kAlpha_8: return kAlpha_8_GrPixelConfig;
1489 case GrColorType::kGray_8: return kGray_8_GrPixelConfig;
1490 case GrColorType::kBGR_565: return kRGB_565_GrPixelConfig;
1491 case GrColorType::kABGR_4444: return kRGBA_4444_GrPixelConfig;
1492 case GrColorType::kRGBA_8888: return kRGBA_8888_GrPixelConfig;
1493 case GrColorType::kRGBA_8888_SRGB: return kSRGBA_8888_GrPixelConfig;
1494 case GrColorType::kRGB_888x: return kRGB_888_GrPixelConfig;
1495 case GrColorType::kRG_88: return kRG_88_GrPixelConfig;
1496 case GrColorType::kBGRA_8888: return kBGRA_8888_GrPixelConfig;
1497 case GrColorType::kRGBA_1010102: return kRGBA_1010102_GrPixelConfig;
1498 case GrColorType::kRGBA_F32: return kRGBA_float_GrPixelConfig;
1499 case GrColorType::kAlpha_F16: return kAlpha_half_GrPixelConfig;
1500 case GrColorType::kRGBA_F16: return kRGBA_half_GrPixelConfig;
1501 case GrColorType::kRGBA_F16_Clamped: return kRGBA_half_Clamped_GrPixelConfig;
1502 case GrColorType::kAlpha_8xxx: return kUnknown_GrPixelConfig;
1503 case GrColorType::kAlpha_F32xxx: return kUnknown_GrPixelConfig;
1504 case GrColorType::kGray_8xxx: return kUnknown_GrPixelConfig;
1505 case GrColorType::kR_16: return kR_16_GrPixelConfig;
1506 case GrColorType::kRG_1616: return kRG_1616_GrPixelConfig;
1507
1508 // Experimental (for Y416 and mutant P016/P010)
1509 case GrColorType::kRGBA_16161616: return kRGBA_16161616_GrPixelConfig;
1510 case GrColorType::kRG_F16: return kRG_half_GrPixelConfig;
1511 }
1512 SkUNREACHABLE;
1513 }
1514
1515 /**
1516 * Ref-counted object that calls a callback from its destructor.
1517 */
1518 class GrRefCntedCallback : public SkRefCnt {
1519 public:
1520 using Context = void*;
1521 using Callback = void (*)(Context);
1522
GrRefCntedCallback(Callback proc,Context ctx)1523 GrRefCntedCallback(Callback proc, Context ctx) : fReleaseProc(proc), fReleaseCtx(ctx) {
1524 SkASSERT(proc);
1525 }
~GrRefCntedCallback()1526 ~GrRefCntedCallback() override { fReleaseProc ? fReleaseProc(fReleaseCtx) : void(); }
1527
context()1528 Context context() const { return fReleaseCtx; }
1529
1530 private:
1531 Callback fReleaseProc;
1532 Context fReleaseCtx;
1533 };
1534
1535 /**
1536 * Indicates "resolutions" that need to be done on a texture before it can be sampled from.
1537 */
1538 enum class GrTextureResolveFlags {
1539 kNone = 0,
1540 kMipMaps = 1 << 0, // Regenerate all mipmap levels.
1541 // TODO: kMSAA = 1 << 1 // Blit the MSAA render buffer into a standard texture.
1542 };
1543
GR_MAKE_BITFIELD_CLASS_OPS(GrTextureResolveFlags)1544 GR_MAKE_BITFIELD_CLASS_OPS(GrTextureResolveFlags)
1545
1546 #if GR_TEST_UTILS || defined(SK_ENABLE_DUMP_GPU)
1547 static constexpr const char* GrBackendApiToStr(GrBackendApi api) {
1548 switch (api) {
1549 case GrBackendApi::kMetal: return "Metal";
1550 case GrBackendApi::kDawn: return "Dawn";
1551 case GrBackendApi::kOpenGL: return "OpenGL";
1552 case GrBackendApi::kVulkan: return "Vulkan";
1553 case GrBackendApi::kMock: return "Mock";
1554 }
1555 SkUNREACHABLE;
1556 }
1557
GrPixelConfigToStr(GrPixelConfig config)1558 static constexpr const char* GrPixelConfigToStr(GrPixelConfig config) {
1559 switch (config) {
1560 case kUnknown_GrPixelConfig: return "Unknown";
1561 case kAlpha_8_GrPixelConfig: return "Alpha8";
1562 case kAlpha_8_as_Alpha_GrPixelConfig: return "Alpha8_asAlpha";
1563 case kAlpha_8_as_Red_GrPixelConfig: return "Alpha8_asRed";
1564 case kGray_8_GrPixelConfig: return "Gray8";
1565 case kGray_8_as_Lum_GrPixelConfig: return "Gray8_asLum";
1566 case kGray_8_as_Red_GrPixelConfig: return "Gray8_asRed";
1567 case kRGB_565_GrPixelConfig: return "RGB565";
1568 case kRGBA_4444_GrPixelConfig: return "RGBA444";
1569 case kRGBA_8888_GrPixelConfig: return "RGBA8888";
1570 case kRGB_888_GrPixelConfig: return "RGB888";
1571 case kRGB_888X_GrPixelConfig: return "RGB888X";
1572 case kRG_88_GrPixelConfig: return "RG88";
1573 case kBGRA_8888_GrPixelConfig: return "BGRA8888";
1574 case kSRGBA_8888_GrPixelConfig: return "SRGBA8888";
1575 case kRGBA_1010102_GrPixelConfig: return "RGBA1010102";
1576 case kRGBA_float_GrPixelConfig: return "RGBAFloat";
1577 case kAlpha_half_GrPixelConfig: return "AlphaHalf";
1578 case kAlpha_half_as_Lum_GrPixelConfig: return "AlphaHalf_asLum";
1579 case kAlpha_half_as_Red_GrPixelConfig: return "AlphaHalf_asRed";
1580 case kRGBA_half_GrPixelConfig: return "RGBAHalf";
1581 case kRGBA_half_Clamped_GrPixelConfig: return "RGBAHalfClamped";
1582 case kRGB_ETC1_GrPixelConfig: return "RGBETC1";
1583 case kRGB_ASTC_GrPixelConfig: return "RGBASTC";
1584 case kR_16_GrPixelConfig: return "R16";
1585 case kRG_1616_GrPixelConfig: return "RG1616";
1586 case kRGBA_16161616_GrPixelConfig: return "RGBA16161616";
1587 case kRG_half_GrPixelConfig: return "RGHalf";
1588 }
1589 SkUNREACHABLE;
1590 }
1591
GrColorTypeToStr(GrColorType ct)1592 static constexpr const char* GrColorTypeToStr(GrColorType ct) {
1593 switch (ct) {
1594 case GrColorType::kUnknown: return "kUnknown";
1595 case GrColorType::kAlpha_8: return "kAlpha_8";
1596 case GrColorType::kBGR_565: return "kRGB_565";
1597 case GrColorType::kABGR_4444: return "kARGB_4444";
1598 case GrColorType::kRGBA_8888: return "kRGBA_8888";
1599 case GrColorType::kRGBA_8888_SRGB: return "kRGBA_8888_SRGB";
1600 case GrColorType::kRGB_888x: return "kRGB_888x";
1601 case GrColorType::kRG_88: return "kRG_88";
1602 case GrColorType::kBGRA_8888: return "kBGRA_8888";
1603 case GrColorType::kRGBA_1010102: return "kRGBA_1010102";
1604 case GrColorType::kGray_8: return "kGray_8";
1605 case GrColorType::kAlpha_F16: return "kAlpha_F16";
1606 case GrColorType::kRGBA_F16: return "kRGBA_F16";
1607 case GrColorType::kRGBA_F16_Clamped: return "kRGBA_F16_Clamped";
1608 case GrColorType::kRGBA_F32: return "kRGBA_F32";
1609 case GrColorType::kAlpha_8xxx: return "kAlpha_8xxx";
1610 case GrColorType::kAlpha_F32xxx: return "kAlpha_F32xxx";
1611 case GrColorType::kGray_8xxx: return "kGray_8xxx";
1612 case GrColorType::kR_16: return "kR_16";
1613 case GrColorType::kRG_1616: return "kRG_1616";
1614 case GrColorType::kRGBA_16161616: return "kRGBA_16161616";
1615 case GrColorType::kRG_F16: return "kRG_F16";
1616 }
1617 SkUNREACHABLE;
1618 }
1619 #endif
1620
1621 #endif
1622