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