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/SkImage.h"
13 #include "include/core/SkImageInfo.h"
14 #include "include/core/SkPath.h"
15 #include "include/core/SkRefCnt.h"
16 #include "include/gpu/GrTypes.h"
17 #include "include/private/SkImageInfoPriv.h"
18 #include "include/private/SkMacros.h"
19
20 class GrBackendFormat;
21 class GrCaps;
22 class GrSurfaceProxy;
23
24 // The old libstdc++ uses the draft name "monotonic_clock" rather than "steady_clock". This might
25 // not actually be monotonic, depending on how libstdc++ was built. However, this is only currently
26 // used for idle resource purging so it shouldn't cause a correctness problem.
27 #if defined(__GLIBCXX__) && (__GLIBCXX__ < 20130000)
28 using GrStdSteadyClock = std::chrono::monotonic_clock;
29 #else
30 using GrStdSteadyClock = std::chrono::steady_clock;
31 #endif
32
33 /**
34 * divide, rounding up
35 */
36
GrSizeDivRoundUp(size_t x,size_t y)37 static inline constexpr size_t GrSizeDivRoundUp(size_t x, size_t y) { return (x + (y - 1)) / y; }
38
39 /**
40 * Geometric primitives used for drawing.
41 */
42 enum class GrPrimitiveType : uint8_t {
43 kTriangles,
44 kTriangleStrip,
45 kPoints,
46 kLines, // 1 pix wide only
47 kLineStrip, // 1 pix wide only
48 kPatches,
49 kPath
50 };
51 static constexpr int kNumGrPrimitiveTypes = (int)GrPrimitiveType::kPath + 1;
52
GrIsPrimTypeLines(GrPrimitiveType type)53 static constexpr bool GrIsPrimTypeLines(GrPrimitiveType type) {
54 return GrPrimitiveType::kLines == type || GrPrimitiveType::kLineStrip == type;
55 }
56
57 enum class GrPrimitiveRestart : bool {
58 kNo = false,
59 kYes = true
60 };
61
62 /**
63 * Should a created surface be texturable?
64 */
65 enum class GrTexturable : bool {
66 kNo = false,
67 kYes = true
68 };
69
70 // A DDL recorder has its own proxy provider and proxy cache. This enum indicates if
71 // a given proxy provider is one of these special ones.
72 enum class GrDDLProvider : bool {
73 kNo = false,
74 kYes = true
75 };
76
77 /**
78 * Formats for masks, used by the font cache. Important that these are 0-based.
79 */
80 enum GrMaskFormat {
81 kA8_GrMaskFormat, //!< 1-byte per pixel
82 kA565_GrMaskFormat, //!< 2-bytes per pixel, RGB represent 3-channel LCD coverage
83 kARGB_GrMaskFormat, //!< 4-bytes per pixel, color format
84
85 kLast_GrMaskFormat = kARGB_GrMaskFormat
86 };
87 static const int kMaskFormatCount = kLast_GrMaskFormat + 1;
88
89 /**
90 * Return the number of bytes-per-pixel for the specified mask format.
91 */
GrMaskFormatBytesPerPixel(GrMaskFormat format)92 inline constexpr int GrMaskFormatBytesPerPixel(GrMaskFormat format) {
93 SkASSERT(format < kMaskFormatCount);
94 // kA8 (0) -> 1
95 // kA565 (1) -> 2
96 // kARGB (2) -> 4
97 static_assert(kA8_GrMaskFormat == 0, "enum_order_dependency");
98 static_assert(kA565_GrMaskFormat == 1, "enum_order_dependency");
99 static_assert(kARGB_GrMaskFormat == 2, "enum_order_dependency");
100
101 return SkTo<int>(1u << format);
102 }
103
104 /** Ownership rules for external GPU resources imported into Skia. */
105 enum GrWrapOwnership {
106 /** Skia will assume the client will keep the resource alive and Skia will not free it. */
107 kBorrow_GrWrapOwnership,
108
109 /** Skia will assume ownership of the resource and free it. */
110 kAdopt_GrWrapOwnership,
111 };
112
113 enum class GrWrapCacheable : bool {
114 /**
115 * The wrapped resource will be removed from the cache as soon as it becomes purgeable. It may
116 * still be assigned and found by a unique key, but the presence of the key will not be used to
117 * keep the resource alive when it has no references.
118 */
119 kNo = false,
120 /**
121 * The wrapped resource is allowed to remain in the GrResourceCache when it has no references
122 * but has a unique key. Such resources should only be given unique keys when it is known that
123 * the key will eventually be removed from the resource or invalidated via the message bus.
124 */
125 kYes = true
126 };
127
128 enum class GrBudgetedType : uint8_t {
129 /** The resource is budgeted and is subject to purging under budget pressure. */
130 kBudgeted,
131 /**
132 * The resource is unbudgeted and is purged as soon as it has no refs regardless of whether
133 * it has a unique or scratch key.
134 */
135 kUnbudgetedUncacheable,
136 /**
137 * The resource is unbudgeted and is allowed to remain in the cache with no refs if it
138 * has a unique key. Scratch keys are ignored.
139 */
140 kUnbudgetedCacheable,
141 };
142
143 enum class GrScissorTest : bool {
144 kDisabled = false,
145 kEnabled = true
146 };
147
148 /*
149 * Used to say whether texture is backed by memory.
150 */
151 enum class GrMemoryless : bool {
152 /**
153 * The texture will be allocated normally and will affect memory budgets.
154 */
155 kNo = false,
156 /**
157 * The texture will be not use GPU memory and will not affect memory budgets.
158 */
159 kYes = true
160 };
161
162 struct GrMipLevel {
163 const void* fPixels = nullptr;
164 size_t fRowBytes = 0;
165 // This may be used to keep fPixels from being freed while a GrMipLevel exists.
166 sk_sp<SkData> fOptionalStorage;
167 };
168
169 enum class GrSemaphoreWrapType {
170 kWillSignal,
171 kWillWait,
172 };
173
174 /**
175 * This enum is used to specify the load operation to be used when an OpsTask/GrOpsRenderPass
176 * begins execution.
177 */
178 enum class GrLoadOp {
179 kLoad,
180 kClear,
181 kDiscard,
182 };
183
184 /**
185 * This enum is used to specify the store operation to be used when an OpsTask/GrOpsRenderPass
186 * ends execution.
187 */
188 enum class GrStoreOp {
189 kStore,
190 kDiscard,
191 };
192
193 /**
194 * Used to control antialiasing in draw calls.
195 */
196 enum class GrAA : bool {
197 kNo = false,
198 kYes = true
199 };
200
201 enum class GrFillRule : bool {
202 kNonzero,
203 kEvenOdd
204 };
205
GrFillRuleForPathFillType(SkPathFillType fillType)206 inline GrFillRule GrFillRuleForPathFillType(SkPathFillType fillType) {
207 switch (fillType) {
208 case SkPathFillType::kWinding:
209 case SkPathFillType::kInverseWinding:
210 return GrFillRule::kNonzero;
211 case SkPathFillType::kEvenOdd:
212 case SkPathFillType::kInverseEvenOdd:
213 return GrFillRule::kEvenOdd;
214 }
215 SkUNREACHABLE;
216 }
217
GrFillRuleForSkPath(const SkPath & path)218 inline GrFillRule GrFillRuleForSkPath(const SkPath& path) {
219 return GrFillRuleForPathFillType(path.getFillType());
220 }
221
222 /** This enum indicates the type of antialiasing to be performed. */
223 enum class GrAAType : unsigned {
224 /** No antialiasing */
225 kNone,
226 /** Use fragment shader code to blend with a fractional pixel coverage. */
227 kCoverage,
228 /** Use normal MSAA. */
229 kMSAA,
230
231 kLast = kMSAA
232 };
233 static const int kGrAATypeCount = static_cast<int>(GrAAType::kLast) + 1;
234
GrAATypeIsHW(GrAAType type)235 static constexpr bool GrAATypeIsHW(GrAAType type) {
236 switch (type) {
237 case GrAAType::kNone:
238 return false;
239 case GrAAType::kCoverage:
240 return false;
241 case GrAAType::kMSAA:
242 return true;
243 }
244 SkUNREACHABLE;
245 }
246
247 /**
248 * Some pixel configs are inherently clamped to [0,1], some are allowed to go outside that range,
249 * and some are FP but manually clamped in the XP.
250 */
251 enum class GrClampType {
252 kAuto, // Normalized, fixed-point configs
253 kManual, // Clamped FP configs
254 kNone, // Normal (unclamped) FP configs
255 };
256
257 /**
258 * A number of rectangle/quadrilateral drawing APIs can control anti-aliasing on a per edge basis.
259 * These masks specify which edges are AA'ed. The intent for this is to support tiling with seamless
260 * boundaries, where the inner edges are non-AA and the outer edges are AA. Regular draws (where AA
261 * is specified by GrAA) is almost equivalent to kNone or kAll, with the exception of how MSAA is
262 * handled.
263 *
264 * When tiling and there is MSAA, mixed edge rectangles are processed with MSAA, so in order for the
265 * tiled edges to remain seamless, inner tiles with kNone must also be processed with MSAA. In
266 * regular drawing, however, kNone should disable MSAA (if it's supported) to match the expected
267 * appearance.
268 *
269 * Therefore, APIs that use per-edge AA flags also take a GrAA value so that they can differentiate
270 * between the regular and tiling use case behaviors. Tiling operations should always pass
271 * GrAA::kYes while regular options should pass GrAA based on the SkPaint's anti-alias state.
272 *
273 * These values are identical to SkCanvas::QuadAAFlags.
274 */
275 enum class GrQuadAAFlags {
276 kLeft = 0b0001,
277 kTop = 0b0010,
278 kRight = 0b0100,
279 kBottom = 0b1000,
280
281 kNone = 0b0000,
282 kAll = 0b1111,
283 };
284
GR_MAKE_BITFIELD_CLASS_OPS(GrQuadAAFlags)285 GR_MAKE_BITFIELD_CLASS_OPS(GrQuadAAFlags)
286
287 static inline GrQuadAAFlags SkToGrQuadAAFlags(unsigned flags) {
288 return static_cast<GrQuadAAFlags>(flags);
289 }
290
291 /**
292 * The type of texture. Backends other than GL currently only use the 2D value but the type must
293 * still be known at the API-neutral layer as it used to determine whether MIP maps, renderability,
294 * and sampling parameters are legal for proxies that will be instantiated with wrapped textures.
295 */
296 enum class GrTextureType {
297 kNone,
298 k2D,
299 /* Rectangle uses unnormalized texture coordinates. */
300 kRectangle,
301 kExternal
302 };
303
304 enum GrShaderType {
305 kVertex_GrShaderType,
306 kFragment_GrShaderType,
307
308 kLastkFragment_GrShaderType = kFragment_GrShaderType
309 };
310 static const int kGrShaderTypeCount = kLastkFragment_GrShaderType + 1;
311
312 enum GrShaderFlags {
313 kNone_GrShaderFlags = 0,
314 kVertex_GrShaderFlag = 1 << 0,
315 kTessControl_GrShaderFlag = 1 << 1,
316 kTessEvaluation_GrShaderFlag = 1 << 2,
317 kFragment_GrShaderFlag = 1 << 3
318 };
SK_MAKE_BITFIELD_OPS(GrShaderFlags)319 SK_MAKE_BITFIELD_OPS(GrShaderFlags)
320
321 /** Rectangle and external textures only support the clamp wrap mode and do not support
322 * MIP maps.
323 */
324 static inline bool GrTextureTypeHasRestrictedSampling(GrTextureType type) {
325 switch (type) {
326 case GrTextureType::k2D:
327 return false;
328 case GrTextureType::kRectangle:
329 return true;
330 case GrTextureType::kExternal:
331 return true;
332 default:
333 SK_ABORT("Unexpected texture type");
334 }
335 }
336
337 //////////////////////////////////////////////////////////////////////////////
338
339 /**
340 * Types used to describe format of vertices in arrays.
341 */
342 enum GrVertexAttribType {
343 kFloat_GrVertexAttribType = 0,
344 kFloat2_GrVertexAttribType,
345 kFloat3_GrVertexAttribType,
346 kFloat4_GrVertexAttribType,
347 kHalf_GrVertexAttribType,
348 kHalf2_GrVertexAttribType,
349 kHalf4_GrVertexAttribType,
350
351 kInt2_GrVertexAttribType, // vector of 2 32-bit ints
352 kInt3_GrVertexAttribType, // vector of 3 32-bit ints
353 kInt4_GrVertexAttribType, // vector of 4 32-bit ints
354
355
356 kByte_GrVertexAttribType, // signed byte
357 kByte2_GrVertexAttribType, // vector of 2 8-bit signed bytes
358 kByte4_GrVertexAttribType, // vector of 4 8-bit signed bytes
359 kUByte_GrVertexAttribType, // unsigned byte
360 kUByte2_GrVertexAttribType, // vector of 2 8-bit unsigned bytes
361 kUByte4_GrVertexAttribType, // vector of 4 8-bit unsigned bytes
362
363 kUByte_norm_GrVertexAttribType, // unsigned byte, e.g. coverage, 0 -> 0.0f, 255 -> 1.0f.
364 kUByte4_norm_GrVertexAttribType, // vector of 4 unsigned bytes, e.g. colors, 0 -> 0.0f,
365 // 255 -> 1.0f.
366
367 kShort2_GrVertexAttribType, // vector of 2 16-bit shorts.
368 kShort4_GrVertexAttribType, // vector of 4 16-bit shorts.
369
370 kUShort2_GrVertexAttribType, // vector of 2 unsigned shorts. 0 -> 0, 65535 -> 65535.
371 kUShort2_norm_GrVertexAttribType, // vector of 2 unsigned shorts. 0 -> 0.0f, 65535 -> 1.0f.
372
373 kInt_GrVertexAttribType,
374 kUInt_GrVertexAttribType,
375
376 kUShort_norm_GrVertexAttribType,
377
378 kUShort4_norm_GrVertexAttribType, // vector of 4 unsigned shorts. 0 -> 0.0f, 65535 -> 1.0f.
379
380 kLast_GrVertexAttribType = kUShort4_norm_GrVertexAttribType
381 };
382 static const int kGrVertexAttribTypeCount = kLast_GrVertexAttribType + 1;
383
384 //////////////////////////////////////////////////////////////////////////////
385
386 /**
387 * We have coverage effects that clip rendering to the edge of some geometric primitive.
388 * This enum specifies how that clipping is performed. Not all factories that take a
389 * GrClipEdgeType will succeed with all values and it is up to the caller to verify success.
390 */
391 enum class GrClipEdgeType {
392 kFillBW,
393 kFillAA,
394 kInverseFillBW,
395 kInverseFillAA,
396
397 kLast = kInverseFillAA
398 };
399 static const int kGrClipEdgeTypeCnt = (int) GrClipEdgeType::kLast + 1;
400
GrClipEdgeTypeIsFill(const GrClipEdgeType edgeType)401 static constexpr bool GrClipEdgeTypeIsFill(const GrClipEdgeType edgeType) {
402 return (GrClipEdgeType::kFillAA == edgeType || GrClipEdgeType::kFillBW == edgeType);
403 }
404
GrClipEdgeTypeIsInverseFill(const GrClipEdgeType edgeType)405 static constexpr bool GrClipEdgeTypeIsInverseFill(const GrClipEdgeType edgeType) {
406 return (GrClipEdgeType::kInverseFillAA == edgeType ||
407 GrClipEdgeType::kInverseFillBW == edgeType);
408 }
409
GrClipEdgeTypeIsAA(const GrClipEdgeType edgeType)410 static constexpr bool GrClipEdgeTypeIsAA(const GrClipEdgeType edgeType) {
411 return (GrClipEdgeType::kFillBW != edgeType &&
412 GrClipEdgeType::kInverseFillBW != edgeType);
413 }
414
GrInvertClipEdgeType(const GrClipEdgeType edgeType)415 static inline GrClipEdgeType GrInvertClipEdgeType(const GrClipEdgeType edgeType) {
416 switch (edgeType) {
417 case GrClipEdgeType::kFillBW:
418 return GrClipEdgeType::kInverseFillBW;
419 case GrClipEdgeType::kFillAA:
420 return GrClipEdgeType::kInverseFillAA;
421 case GrClipEdgeType::kInverseFillBW:
422 return GrClipEdgeType::kFillBW;
423 case GrClipEdgeType::kInverseFillAA:
424 return GrClipEdgeType::kFillAA;
425 }
426 SkUNREACHABLE;
427 }
428
429 /**
430 * Indicates the type of pending IO operations that can be recorded for gpu resources.
431 */
432 enum GrIOType {
433 kRead_GrIOType,
434 kWrite_GrIOType,
435 kRW_GrIOType
436 };
437
438 /**
439 * Indicates the type of data that a GPU buffer will be used for.
440 */
441 enum class GrGpuBufferType {
442 kVertex,
443 kIndex,
444 kDrawIndirect,
445 kXferCpuToGpu,
446 kXferGpuToCpu,
447 kUniform,
448 };
449 static const int kGrGpuBufferTypeCount = static_cast<int>(GrGpuBufferType::kUniform) + 1;
450
451 /**
452 * Provides a performance hint regarding the frequency at which a data store will be accessed.
453 */
454 enum GrAccessPattern {
455 /** Data store will be respecified repeatedly and used many times. */
456 kDynamic_GrAccessPattern,
457 /** Data store will be specified once and used many times. (Thus disqualified from caching.) */
458 kStatic_GrAccessPattern,
459 /** Data store will be specified once and used at most a few times. (Also can't be cached.) */
460 kStream_GrAccessPattern,
461
462 kLast_GrAccessPattern = kStream_GrAccessPattern
463 };
464
465 // Flags shared between the GrSurface & GrSurfaceProxy class hierarchies
466 enum class GrInternalSurfaceFlags {
467 kNone = 0,
468
469 // Texture-level
470
471 // Means the pixels in the texture are read-only. Cannot also be a GrRenderTarget[Proxy].
472 kReadOnly = 1 << 0,
473
474 // RT-level
475
476 // This flag is for use with GL only. It tells us that the internal render target wraps FBO 0.
477 kGLRTFBOIDIs0 = 1 << 1,
478
479 // This means the render target is multisampled, and internally holds a non-msaa texture for
480 // resolving into. The render target resolves itself by blitting into this internal texture.
481 // (asTexture() might or might not return the internal texture, but if it does, we always
482 // resolve the render target before accessing this texture's data.)
483 kRequiresManualMSAAResolve = 1 << 2,
484
485 // This means the pixels in the render target are write-only. This is used for Dawn and Metal
486 // swap chain targets which can be rendered to, but not read or copied.
487 kFramebufferOnly = 1 << 3,
488
489 // This is a Vulkan only flag. If set the surface can be used as an input attachment in a
490 // shader. This is used for doing in shader blending where we want to sample from the same
491 // image we are drawing to.
492 kVkRTSupportsInputAttachment = 1 << 4,
493 };
494
495 GR_MAKE_BITFIELD_CLASS_OPS(GrInternalSurfaceFlags)
496
497 // 'GR_MAKE_BITFIELD_CLASS_OPS' defines the & operator on GrInternalSurfaceFlags to return bool.
498 // We want to find the bitwise & with these masks, so we declare them as ints.
499 constexpr static int kGrInternalTextureFlagsMask = static_cast<int>(
500 GrInternalSurfaceFlags::kReadOnly);
501
502 // We don't include kVkRTSupportsInputAttachment in this mask since we check it manually. We don't
503 // require that both the surface and proxy have matching values for this flag. Instead we require
504 // if the proxy has it set then the surface must also have it set. All other flags listed here must
505 // match on the proxy and surface.
506 // TODO: Add back kFramebufferOnly flag here once we update SkSurfaceCharacterization to take it
507 // as a flag. skbug.com/10672
508 constexpr static int kGrInternalRenderTargetFlagsMask = static_cast<int>(
509 GrInternalSurfaceFlags::kGLRTFBOIDIs0 |
510 GrInternalSurfaceFlags::kRequiresManualMSAAResolve/* |
511 GrInternalSurfaceFlags::kFramebufferOnly*/);
512
513 constexpr static int kGrInternalTextureRenderTargetFlagsMask =
514 kGrInternalTextureFlagsMask | kGrInternalRenderTargetFlagsMask;
515
516 #ifdef SK_DEBUG
517 // Takes a pointer to a GrCaps, and will suppress prints if required
518 #define GrCapsDebugf(caps, ...) if (!(caps)->suppressPrints()) SkDebugf(__VA_ARGS__)
519 #else
520 #define GrCapsDebugf(caps, ...) do {} while (0)
521 #endif
522
523 /**
524 * Specifies if the holder owns the backend, OpenGL or Vulkan, object.
525 */
526 enum class GrBackendObjectOwnership : bool {
527 /** Holder does not destroy the backend object. */
528 kBorrowed = false,
529 /** Holder destroys the backend object. */
530 kOwned = true
531 };
532
533 /*
534 * Object for CPU-GPU synchronization
535 */
536 typedef uint64_t GrFence;
537
538 /**
539 * Used to include or exclude specific GPU path renderers for testing purposes.
540 */
541 enum class GpuPathRenderers {
542 kNone = 0, // Always use software masks and/or DefaultPathRenderer.
543 kDashLine = 1 << 0,
544 kAtlas = 1 << 1,
545 kTessellation = 1 << 2,
546 kCoverageCounting = 1 << 3,
547 kAAHairline = 1 << 4,
548 kAAConvex = 1 << 5,
549 kAALinearizing = 1 << 6,
550 kSmall = 1 << 7,
551 kTriangulating = 1 << 8,
552 kDefault = ((1 << 9) - 1) // All path renderers.
553 };
554
555 /**
556 * Used to describe the current state of Mips on a GrTexture
557 */
558 enum class GrMipmapStatus {
559 kNotAllocated, // Mips have not been allocated
560 kDirty, // Mips are allocated but the full mip tree does not have valid data
561 kValid, // All levels fully allocated and have valid data in them
562 };
563
564 GR_MAKE_BITFIELD_CLASS_OPS(GpuPathRenderers)
565
566 /**
567 * Like SkColorType this describes a layout of pixel data in CPU memory. It specifies the channels,
568 * their type, and width. This exists so that the GPU backend can have private types that have no
569 * analog in the public facing SkColorType enum and omit types not implemented in the GPU backend.
570 * It does not refer to a texture format and the mapping to texture formats may be many-to-many.
571 * It does not specify the sRGB encoding of the stored values. The components are listed in order of
572 * where they appear in memory. In other words the first component listed is in the low bits and
573 * the last component in the high bits.
574 */
575 enum class GrColorType {
576 kUnknown,
577 kAlpha_8,
578 kBGR_565,
579 kABGR_4444, // This name differs from SkColorType. kARGB_4444_SkColorType is misnamed.
580 kRGBA_8888,
581 kRGBA_8888_SRGB,
582 kRGB_888x,
583 kRG_88,
584 kBGRA_8888,
585 kRGBA_1010102,
586 kBGRA_1010102,
587 kGray_8,
588 kGrayAlpha_88,
589 kAlpha_F16,
590 kRGBA_F16,
591 kRGBA_F16_Clamped,
592 kRGBA_F32,
593
594 kAlpha_16,
595 kRG_1616,
596 kRG_F16,
597 kRGBA_16161616,
598
599 // Unusual types that come up after reading back in cases where we are reassigning the meaning
600 // of a texture format's channels to use for a particular color format but have to read back the
601 // data to a full RGBA quadruple. (e.g. using a R8 texture format as A8 color type but the API
602 // only supports reading to RGBA8.) None of these have SkColorType equivalents.
603 kAlpha_8xxx,
604 kAlpha_F32xxx,
605 kGray_8xxx,
606 kR_8xxx,
607
608 // Types used to initialize backend textures.
609 kRGB_888,
610 kR_8,
611 kR_16,
612 kR_F16,
613 kGray_F16,
614 kBGRA_4444,
615 kARGB_4444,
616
617 kLast = kARGB_4444
618 };
619
620 static const int kGrColorTypeCnt = static_cast<int>(GrColorType::kLast) + 1;
621
GrColorTypeToSkColorType(GrColorType ct)622 static constexpr SkColorType GrColorTypeToSkColorType(GrColorType ct) {
623 switch (ct) {
624 case GrColorType::kUnknown: return kUnknown_SkColorType;
625 case GrColorType::kAlpha_8: return kAlpha_8_SkColorType;
626 case GrColorType::kBGR_565: return kRGB_565_SkColorType;
627 case GrColorType::kABGR_4444: return kARGB_4444_SkColorType;
628 case GrColorType::kRGBA_8888: return kRGBA_8888_SkColorType;
629 case GrColorType::kRGBA_8888_SRGB: return kSRGBA_8888_SkColorType;
630 case GrColorType::kRGB_888x: return kRGB_888x_SkColorType;
631 case GrColorType::kRG_88: return kR8G8_unorm_SkColorType;
632 case GrColorType::kBGRA_8888: return kBGRA_8888_SkColorType;
633 case GrColorType::kRGBA_1010102: return kRGBA_1010102_SkColorType;
634 case GrColorType::kBGRA_1010102: return kBGRA_1010102_SkColorType;
635 case GrColorType::kGray_8: return kGray_8_SkColorType;
636 case GrColorType::kGrayAlpha_88: return kUnknown_SkColorType;
637 case GrColorType::kAlpha_F16: return kA16_float_SkColorType;
638 case GrColorType::kRGBA_F16: return kRGBA_F16_SkColorType;
639 case GrColorType::kRGBA_F16_Clamped: return kRGBA_F16Norm_SkColorType;
640 case GrColorType::kRGBA_F32: return kRGBA_F32_SkColorType;
641 case GrColorType::kAlpha_8xxx: return kUnknown_SkColorType;
642 case GrColorType::kAlpha_F32xxx: return kUnknown_SkColorType;
643 case GrColorType::kGray_8xxx: return kUnknown_SkColorType;
644 case GrColorType::kR_8xxx: return kUnknown_SkColorType;
645 case GrColorType::kAlpha_16: return kA16_unorm_SkColorType;
646 case GrColorType::kRG_1616: return kR16G16_unorm_SkColorType;
647 case GrColorType::kRGBA_16161616: return kR16G16B16A16_unorm_SkColorType;
648 case GrColorType::kRG_F16: return kR16G16_float_SkColorType;
649 case GrColorType::kRGB_888: return kUnknown_SkColorType;
650 case GrColorType::kR_8: return kR8_unorm_SkColorType;
651 case GrColorType::kR_16: return kUnknown_SkColorType;
652 case GrColorType::kR_F16: return kUnknown_SkColorType;
653 case GrColorType::kGray_F16: return kUnknown_SkColorType;
654 case GrColorType::kARGB_4444: return kUnknown_SkColorType;
655 case GrColorType::kBGRA_4444: return kUnknown_SkColorType;
656 }
657 SkUNREACHABLE;
658 }
659
SkColorTypeToGrColorType(SkColorType ct)660 static constexpr GrColorType SkColorTypeToGrColorType(SkColorType ct) {
661 switch (ct) {
662 case kUnknown_SkColorType: return GrColorType::kUnknown;
663 case kAlpha_8_SkColorType: return GrColorType::kAlpha_8;
664 case kRGB_565_SkColorType: return GrColorType::kBGR_565;
665 case kARGB_4444_SkColorType: return GrColorType::kABGR_4444;
666 case kRGBA_8888_SkColorType: return GrColorType::kRGBA_8888;
667 case kSRGBA_8888_SkColorType: return GrColorType::kRGBA_8888_SRGB;
668 case kRGB_888x_SkColorType: return GrColorType::kRGB_888x;
669 case kBGRA_8888_SkColorType: return GrColorType::kBGRA_8888;
670 case kGray_8_SkColorType: return GrColorType::kGray_8;
671 case kRGBA_F16Norm_SkColorType: return GrColorType::kRGBA_F16_Clamped;
672 case kRGBA_F16_SkColorType: return GrColorType::kRGBA_F16;
673 case kRGBA_1010102_SkColorType: return GrColorType::kRGBA_1010102;
674 case kRGB_101010x_SkColorType: return GrColorType::kUnknown;
675 case kBGRA_1010102_SkColorType: return GrColorType::kBGRA_1010102;
676 case kBGR_101010x_SkColorType: return GrColorType::kUnknown;
677 case kRGBA_F32_SkColorType: return GrColorType::kRGBA_F32;
678 case kR8G8_unorm_SkColorType: return GrColorType::kRG_88;
679 case kA16_unorm_SkColorType: return GrColorType::kAlpha_16;
680 case kR16G16_unorm_SkColorType: return GrColorType::kRG_1616;
681 case kA16_float_SkColorType: return GrColorType::kAlpha_F16;
682 case kR16G16_float_SkColorType: return GrColorType::kRG_F16;
683 case kR16G16B16A16_unorm_SkColorType: return GrColorType::kRGBA_16161616;
684 case kR8_unorm_SkColorType: return GrColorType::kR_8;
685 }
686 SkUNREACHABLE;
687 }
688
GrColorTypeChannelFlags(GrColorType ct)689 static constexpr uint32_t GrColorTypeChannelFlags(GrColorType ct) {
690 switch (ct) {
691 case GrColorType::kUnknown: return 0;
692 case GrColorType::kAlpha_8: return kAlpha_SkColorChannelFlag;
693 case GrColorType::kBGR_565: return kRGB_SkColorChannelFlags;
694 case GrColorType::kABGR_4444: return kRGBA_SkColorChannelFlags;
695 case GrColorType::kRGBA_8888: return kRGBA_SkColorChannelFlags;
696 case GrColorType::kRGBA_8888_SRGB: return kRGBA_SkColorChannelFlags;
697 case GrColorType::kRGB_888x: return kRGB_SkColorChannelFlags;
698 case GrColorType::kRG_88: return kRG_SkColorChannelFlags;
699 case GrColorType::kBGRA_8888: return kRGBA_SkColorChannelFlags;
700 case GrColorType::kRGBA_1010102: return kRGBA_SkColorChannelFlags;
701 case GrColorType::kBGRA_1010102: return kRGBA_SkColorChannelFlags;
702 case GrColorType::kGray_8: return kGray_SkColorChannelFlag;
703 case GrColorType::kGrayAlpha_88: return kGrayAlpha_SkColorChannelFlags;
704 case GrColorType::kAlpha_F16: return kAlpha_SkColorChannelFlag;
705 case GrColorType::kRGBA_F16: return kRGBA_SkColorChannelFlags;
706 case GrColorType::kRGBA_F16_Clamped: return kRGBA_SkColorChannelFlags;
707 case GrColorType::kRGBA_F32: return kRGBA_SkColorChannelFlags;
708 case GrColorType::kAlpha_8xxx: return kAlpha_SkColorChannelFlag;
709 case GrColorType::kAlpha_F32xxx: return kAlpha_SkColorChannelFlag;
710 case GrColorType::kGray_8xxx: return kGray_SkColorChannelFlag;
711 case GrColorType::kR_8xxx: return kRed_SkColorChannelFlag;
712 case GrColorType::kAlpha_16: return kAlpha_SkColorChannelFlag;
713 case GrColorType::kRG_1616: return kRG_SkColorChannelFlags;
714 case GrColorType::kRGBA_16161616: return kRGBA_SkColorChannelFlags;
715 case GrColorType::kRG_F16: return kRG_SkColorChannelFlags;
716 case GrColorType::kRGB_888: return kRGB_SkColorChannelFlags;
717 case GrColorType::kR_8: return kRed_SkColorChannelFlag;
718 case GrColorType::kR_16: return kRed_SkColorChannelFlag;
719 case GrColorType::kR_F16: return kRed_SkColorChannelFlag;
720 case GrColorType::kGray_F16: return kGray_SkColorChannelFlag;
721 case GrColorType::kARGB_4444: return kRGBA_SkColorChannelFlags;
722 case GrColorType::kBGRA_4444: return kRGBA_SkColorChannelFlags;
723 }
724 SkUNREACHABLE;
725 }
726
727 /**
728 * Describes the encoding of channel data in a GrColorType.
729 */
730 enum class GrColorTypeEncoding {
731 kUnorm,
732 kSRGBUnorm,
733 // kSnorm,
734 kFloat,
735 // kSint
736 // kUint
737 };
738
739 /**
740 * Describes a GrColorType by how many bits are used for each color component and how they are
741 * encoded. Currently all the non-zero channels share a single GrColorTypeEncoding. This could be
742 * expanded to store separate encodings and to indicate which bits belong to which components.
743 */
744 class GrColorFormatDesc {
745 public:
MakeRGBA(int rgba,GrColorTypeEncoding e)746 static constexpr GrColorFormatDesc MakeRGBA(int rgba, GrColorTypeEncoding e) {
747 return {rgba, rgba, rgba, rgba, 0, e};
748 }
749
MakeRGBA(int rgb,int a,GrColorTypeEncoding e)750 static constexpr GrColorFormatDesc MakeRGBA(int rgb, int a, GrColorTypeEncoding e) {
751 return {rgb, rgb, rgb, a, 0, e};
752 }
753
MakeRGB(int rgb,GrColorTypeEncoding e)754 static constexpr GrColorFormatDesc MakeRGB(int rgb, GrColorTypeEncoding e) {
755 return {rgb, rgb, rgb, 0, 0, e};
756 }
757
MakeRGB(int r,int g,int b,GrColorTypeEncoding e)758 static constexpr GrColorFormatDesc MakeRGB(int r, int g, int b, GrColorTypeEncoding e) {
759 return {r, g, b, 0, 0, e};
760 }
761
MakeAlpha(int a,GrColorTypeEncoding e)762 static constexpr GrColorFormatDesc MakeAlpha(int a, GrColorTypeEncoding e) {
763 return {0, 0, 0, a, 0, e};
764 }
765
MakeR(int r,GrColorTypeEncoding e)766 static constexpr GrColorFormatDesc MakeR(int r, GrColorTypeEncoding e) {
767 return {r, 0, 0, 0, 0, e};
768 }
769
MakeRG(int rg,GrColorTypeEncoding e)770 static constexpr GrColorFormatDesc MakeRG(int rg, GrColorTypeEncoding e) {
771 return {rg, rg, 0, 0, 0, e};
772 }
773
MakeGray(int grayBits,GrColorTypeEncoding e)774 static constexpr GrColorFormatDesc MakeGray(int grayBits, GrColorTypeEncoding e) {
775 return {0, 0, 0, 0, grayBits, e};
776 }
777
MakeGrayAlpha(int grayAlpha,GrColorTypeEncoding e)778 static constexpr GrColorFormatDesc MakeGrayAlpha(int grayAlpha, GrColorTypeEncoding e) {
779 return {0, 0, 0, 0, grayAlpha, e};
780 }
781
MakeInvalid()782 static constexpr GrColorFormatDesc MakeInvalid() { return {}; }
783
r()784 constexpr int r() const { return fRBits; }
g()785 constexpr int g() const { return fGBits; }
b()786 constexpr int b() const { return fBBits; }
a()787 constexpr int a() const { return fABits; }
788 constexpr int operator[](int c) const {
789 switch (c) {
790 case 0: return this->r();
791 case 1: return this->g();
792 case 2: return this->b();
793 case 3: return this->a();
794 }
795 SkUNREACHABLE;
796 }
797
gray()798 constexpr int gray() const { return fGrayBits; }
799
encoding()800 constexpr GrColorTypeEncoding encoding() const { return fEncoding; }
801
802 private:
803 int fRBits = 0;
804 int fGBits = 0;
805 int fBBits = 0;
806 int fABits = 0;
807 int fGrayBits = 0;
808 GrColorTypeEncoding fEncoding = GrColorTypeEncoding::kUnorm;
809
810 constexpr GrColorFormatDesc() = default;
811
GrColorFormatDesc(int r,int g,int b,int a,int gray,GrColorTypeEncoding encoding)812 constexpr GrColorFormatDesc(int r, int g, int b, int a, int gray, GrColorTypeEncoding encoding)
813 : fRBits(r), fGBits(g), fBBits(b), fABits(a), fGrayBits(gray), fEncoding(encoding) {
814 SkASSERT(r >= 0 && g >= 0 && b >= 0 && a >= 0 && gray >= 0);
815 SkASSERT(!gray || (!r && !g && !b));
816 SkASSERT(r || g || b || a || gray);
817 }
818 };
819
GrGetColorTypeDesc(GrColorType ct)820 static constexpr GrColorFormatDesc GrGetColorTypeDesc(GrColorType ct) {
821 switch (ct) {
822 case GrColorType::kUnknown:
823 return GrColorFormatDesc::MakeInvalid();
824 case GrColorType::kAlpha_8:
825 return GrColorFormatDesc::MakeAlpha(8, GrColorTypeEncoding::kUnorm);
826 case GrColorType::kBGR_565:
827 return GrColorFormatDesc::MakeRGB(5, 6, 5, GrColorTypeEncoding::kUnorm);
828 case GrColorType::kABGR_4444:
829 return GrColorFormatDesc::MakeRGBA(4, GrColorTypeEncoding::kUnorm);
830 case GrColorType::kRGBA_8888:
831 return GrColorFormatDesc::MakeRGBA(8, GrColorTypeEncoding::kUnorm);
832 case GrColorType::kRGBA_8888_SRGB:
833 return GrColorFormatDesc::MakeRGBA(8, GrColorTypeEncoding::kSRGBUnorm);
834 case GrColorType::kRGB_888x:
835 return GrColorFormatDesc::MakeRGB(8, GrColorTypeEncoding::kUnorm);
836 case GrColorType::kRG_88:
837 return GrColorFormatDesc::MakeRG(8, GrColorTypeEncoding::kUnorm);
838 case GrColorType::kBGRA_8888:
839 return GrColorFormatDesc::MakeRGBA(8, GrColorTypeEncoding::kUnorm);
840 case GrColorType::kRGBA_1010102:
841 return GrColorFormatDesc::MakeRGBA(10, 2, GrColorTypeEncoding::kUnorm);
842 case GrColorType::kBGRA_1010102:
843 return GrColorFormatDesc::MakeRGBA(10, 2, GrColorTypeEncoding::kUnorm);
844 case GrColorType::kGray_8:
845 return GrColorFormatDesc::MakeGray(8, GrColorTypeEncoding::kUnorm);
846 case GrColorType::kGrayAlpha_88:
847 return GrColorFormatDesc::MakeGrayAlpha(8, GrColorTypeEncoding::kUnorm);
848 case GrColorType::kAlpha_F16:
849 return GrColorFormatDesc::MakeAlpha(16, GrColorTypeEncoding::kFloat);
850 case GrColorType::kRGBA_F16:
851 return GrColorFormatDesc::MakeRGBA(16, GrColorTypeEncoding::kFloat);
852 case GrColorType::kRGBA_F16_Clamped:
853 return GrColorFormatDesc::MakeRGBA(16, GrColorTypeEncoding::kFloat);
854 case GrColorType::kRGBA_F32:
855 return GrColorFormatDesc::MakeRGBA(32, GrColorTypeEncoding::kFloat);
856 case GrColorType::kAlpha_8xxx:
857 return GrColorFormatDesc::MakeAlpha(8, GrColorTypeEncoding::kUnorm);
858 case GrColorType::kAlpha_F32xxx:
859 return GrColorFormatDesc::MakeAlpha(32, GrColorTypeEncoding::kFloat);
860 case GrColorType::kGray_8xxx:
861 return GrColorFormatDesc::MakeGray(8, GrColorTypeEncoding::kUnorm);
862 case GrColorType::kR_8xxx:
863 return GrColorFormatDesc::MakeR(8, GrColorTypeEncoding::kUnorm);
864 case GrColorType::kAlpha_16:
865 return GrColorFormatDesc::MakeAlpha(16, GrColorTypeEncoding::kUnorm);
866 case GrColorType::kRG_1616:
867 return GrColorFormatDesc::MakeRG(16, GrColorTypeEncoding::kUnorm);
868 case GrColorType::kRGBA_16161616:
869 return GrColorFormatDesc::MakeRGBA(16, GrColorTypeEncoding::kUnorm);
870 case GrColorType::kRG_F16:
871 return GrColorFormatDesc::MakeRG(16, GrColorTypeEncoding::kFloat);
872 case GrColorType::kRGB_888:
873 return GrColorFormatDesc::MakeRGB(8, GrColorTypeEncoding::kUnorm);
874 case GrColorType::kR_8:
875 return GrColorFormatDesc::MakeR(8, GrColorTypeEncoding::kUnorm);
876 case GrColorType::kR_16:
877 return GrColorFormatDesc::MakeR(16, GrColorTypeEncoding::kUnorm);
878 case GrColorType::kR_F16:
879 return GrColorFormatDesc::MakeR(16, GrColorTypeEncoding::kFloat);
880 case GrColorType::kGray_F16:
881 return GrColorFormatDesc::MakeGray(16, GrColorTypeEncoding::kFloat);
882 case GrColorType::kARGB_4444:
883 return GrColorFormatDesc::MakeRGBA(4, GrColorTypeEncoding::kUnorm);
884 case GrColorType::kBGRA_4444:
885 return GrColorFormatDesc::MakeRGBA(4, GrColorTypeEncoding::kUnorm);
886 }
887 SkUNREACHABLE;
888 }
889
GrColorTypeClampType(GrColorType colorType)890 static constexpr GrClampType GrColorTypeClampType(GrColorType colorType) {
891 if (GrGetColorTypeDesc(colorType).encoding() == GrColorTypeEncoding::kUnorm ||
892 GrGetColorTypeDesc(colorType).encoding() == GrColorTypeEncoding::kSRGBUnorm) {
893 return GrClampType::kAuto;
894 }
895 return GrColorType::kRGBA_F16_Clamped == colorType ? GrClampType::kManual : GrClampType::kNone;
896 }
897
898 // Consider a color type "wider" than n if it has more than n bits for any its representable
899 // channels.
GrColorTypeIsWiderThan(GrColorType colorType,int n)900 static constexpr bool GrColorTypeIsWiderThan(GrColorType colorType, int n) {
901 SkASSERT(n > 0);
902 auto desc = GrGetColorTypeDesc(colorType);
903 return (desc.r() && desc.r() > n )||
904 (desc.g() && desc.g() > n) ||
905 (desc.b() && desc.b() > n) ||
906 (desc.a() && desc.a() > n) ||
907 (desc.gray() && desc.gray() > n);
908 }
909
GrColorTypeIsAlphaOnly(GrColorType ct)910 static constexpr bool GrColorTypeIsAlphaOnly(GrColorType ct) {
911 return GrColorTypeChannelFlags(ct) == kAlpha_SkColorChannelFlag;
912 }
913
GrColorTypeHasAlpha(GrColorType ct)914 static constexpr bool GrColorTypeHasAlpha(GrColorType ct) {
915 return GrColorTypeChannelFlags(ct) & kAlpha_SkColorChannelFlag;
916 }
917
GrColorTypeBytesPerPixel(GrColorType ct)918 static constexpr size_t GrColorTypeBytesPerPixel(GrColorType ct) {
919 switch (ct) {
920 case GrColorType::kUnknown: return 0;
921 case GrColorType::kAlpha_8: return 1;
922 case GrColorType::kBGR_565: return 2;
923 case GrColorType::kABGR_4444: return 2;
924 case GrColorType::kRGBA_8888: return 4;
925 case GrColorType::kRGBA_8888_SRGB: return 4;
926 case GrColorType::kRGB_888x: return 4;
927 case GrColorType::kRG_88: return 2;
928 case GrColorType::kBGRA_8888: return 4;
929 case GrColorType::kRGBA_1010102: return 4;
930 case GrColorType::kBGRA_1010102: return 4;
931 case GrColorType::kGray_8: return 1;
932 case GrColorType::kGrayAlpha_88: return 2;
933 case GrColorType::kAlpha_F16: return 2;
934 case GrColorType::kRGBA_F16: return 8;
935 case GrColorType::kRGBA_F16_Clamped: return 8;
936 case GrColorType::kRGBA_F32: return 16;
937 case GrColorType::kAlpha_8xxx: return 4;
938 case GrColorType::kAlpha_F32xxx: return 16;
939 case GrColorType::kGray_8xxx: return 4;
940 case GrColorType::kR_8xxx: return 4;
941 case GrColorType::kAlpha_16: return 2;
942 case GrColorType::kRG_1616: return 4;
943 case GrColorType::kRGBA_16161616: return 8;
944 case GrColorType::kRG_F16: return 4;
945 case GrColorType::kRGB_888: return 3;
946 case GrColorType::kR_8: return 1;
947 case GrColorType::kR_16: return 2;
948 case GrColorType::kR_F16: return 2;
949 case GrColorType::kGray_F16: return 2;
950 case GrColorType::kARGB_4444: return 2;
951 case GrColorType::kBGRA_4444: return 2;
952 }
953 SkUNREACHABLE;
954 }
955
956 // In general we try to not mix CompressionType and ColorType, but currently SkImage still requires
957 // an SkColorType even for CompressedTypes so we need some conversion.
GrCompressionTypeToSkColorType(SkImage::CompressionType compression)958 static constexpr SkColorType GrCompressionTypeToSkColorType(SkImage::CompressionType compression) {
959 switch (compression) {
960 case SkImage::CompressionType::kNone: return kUnknown_SkColorType;
961 case SkImage::CompressionType::kETC2_RGB8_UNORM: return kRGB_888x_SkColorType;
962 case SkImage::CompressionType::kBC1_RGB8_UNORM: return kRGB_888x_SkColorType;
963 case SkImage::CompressionType::kBC1_RGBA8_UNORM: return kRGBA_8888_SkColorType;
964 }
965
966 SkUNREACHABLE;
967 }
968
GrMaskFormatToColorType(GrMaskFormat format)969 static constexpr GrColorType GrMaskFormatToColorType(GrMaskFormat format) {
970 switch (format) {
971 case kA8_GrMaskFormat:
972 return GrColorType::kAlpha_8;
973 case kA565_GrMaskFormat:
974 return GrColorType::kBGR_565;
975 case kARGB_GrMaskFormat:
976 return GrColorType::kRGBA_8888;
977 }
978 SkUNREACHABLE;
979 }
980
981 /**
982 * Ref-counted object that calls a callback from its destructor.
983 */
984 class GrRefCntedCallback : public SkNVRefCnt<GrRefCntedCallback> {
985 public:
986 using Context = void*;
987 using Callback = void (*)(Context);
988
Make(Callback proc,Context ctx)989 static sk_sp<GrRefCntedCallback> Make(Callback proc, Context ctx) {
990 if (!proc) {
991 return nullptr;
992 }
993 return sk_sp<GrRefCntedCallback>(new GrRefCntedCallback(proc, ctx));
994 }
995
~GrRefCntedCallback()996 ~GrRefCntedCallback() { fReleaseProc(fReleaseCtx); }
997
context()998 Context context() const { return fReleaseCtx; }
999
1000 private:
GrRefCntedCallback(Callback proc,Context ctx)1001 GrRefCntedCallback(Callback proc, Context ctx) : fReleaseProc(proc), fReleaseCtx(ctx) {}
1002 GrRefCntedCallback(const GrRefCntedCallback&) = delete;
1003 GrRefCntedCallback(GrRefCntedCallback&&) = delete;
1004 GrRefCntedCallback& operator=(const GrRefCntedCallback&) = delete;
1005 GrRefCntedCallback& operator=(GrRefCntedCallback&&) = delete;
1006
1007 Callback fReleaseProc;
1008 Context fReleaseCtx;
1009 };
1010
1011 enum class GrDstSampleFlags {
1012 kNone = 0,
1013 kRequiresTextureBarrier = 1 << 0,
1014 kAsInputAttachment = 1 << 1,
1015 };
1016 GR_MAKE_BITFIELD_CLASS_OPS(GrDstSampleFlags)
1017
1018 using GrVisitProxyFunc = std::function<void(GrSurfaceProxy*, GrMipmapped)>;
1019
1020 #if defined(SK_DEBUG) || GR_TEST_UTILS || defined(SK_ENABLE_DUMP_GPU)
GrBackendApiToStr(GrBackendApi api)1021 static constexpr const char* GrBackendApiToStr(GrBackendApi api) {
1022 switch (api) {
1023 case GrBackendApi::kOpenGL: return "OpenGL";
1024 case GrBackendApi::kVulkan: return "Vulkan";
1025 case GrBackendApi::kMetal: return "Metal";
1026 case GrBackendApi::kDirect3D: return "Direct3D";
1027 case GrBackendApi::kDawn: return "Dawn";
1028 case GrBackendApi::kMock: return "Mock";
1029 }
1030 SkUNREACHABLE;
1031 }
1032
GrColorTypeToStr(GrColorType ct)1033 static constexpr const char* GrColorTypeToStr(GrColorType ct) {
1034 switch (ct) {
1035 case GrColorType::kUnknown: return "kUnknown";
1036 case GrColorType::kAlpha_8: return "kAlpha_8";
1037 case GrColorType::kBGR_565: return "kRGB_565";
1038 case GrColorType::kABGR_4444: return "kABGR_4444";
1039 case GrColorType::kRGBA_8888: return "kRGBA_8888";
1040 case GrColorType::kRGBA_8888_SRGB: return "kRGBA_8888_SRGB";
1041 case GrColorType::kRGB_888x: return "kRGB_888x";
1042 case GrColorType::kRG_88: return "kRG_88";
1043 case GrColorType::kBGRA_8888: return "kBGRA_8888";
1044 case GrColorType::kRGBA_1010102: return "kRGBA_1010102";
1045 case GrColorType::kBGRA_1010102: return "kBGRA_1010102";
1046 case GrColorType::kGray_8: return "kGray_8";
1047 case GrColorType::kGrayAlpha_88: return "kGrayAlpha_88";
1048 case GrColorType::kAlpha_F16: return "kAlpha_F16";
1049 case GrColorType::kRGBA_F16: return "kRGBA_F16";
1050 case GrColorType::kRGBA_F16_Clamped: return "kRGBA_F16_Clamped";
1051 case GrColorType::kRGBA_F32: return "kRGBA_F32";
1052 case GrColorType::kAlpha_8xxx: return "kAlpha_8xxx";
1053 case GrColorType::kAlpha_F32xxx: return "kAlpha_F32xxx";
1054 case GrColorType::kGray_8xxx: return "kGray_8xxx";
1055 case GrColorType::kR_8xxx: return "kR_8xxx";
1056 case GrColorType::kAlpha_16: return "kAlpha_16";
1057 case GrColorType::kRG_1616: return "kRG_1616";
1058 case GrColorType::kRGBA_16161616: return "kRGBA_16161616";
1059 case GrColorType::kRG_F16: return "kRG_F16";
1060 case GrColorType::kRGB_888: return "kRGB_888";
1061 case GrColorType::kR_8: return "kR_8";
1062 case GrColorType::kR_16: return "kR_16";
1063 case GrColorType::kR_F16: return "kR_F16";
1064 case GrColorType::kGray_F16: return "kGray_F16";
1065 case GrColorType::kARGB_4444: return "kARGB_4444";
1066 case GrColorType::kBGRA_4444: return "kBGRA_4444";
1067 }
1068 SkUNREACHABLE;
1069 }
1070
GrCompressionTypeToStr(SkImage::CompressionType compression)1071 static constexpr const char* GrCompressionTypeToStr(SkImage::CompressionType compression) {
1072 switch (compression) {
1073 case SkImage::CompressionType::kNone: return "kNone";
1074 case SkImage::CompressionType::kETC2_RGB8_UNORM: return "kETC2_RGB8_UNORM";
1075 case SkImage::CompressionType::kBC1_RGB8_UNORM: return "kBC1_RGB8_UNORM";
1076 case SkImage::CompressionType::kBC1_RGBA8_UNORM: return "kBC1_RGBA8_UNORM";
1077 }
1078 SkUNREACHABLE;
1079 }
1080
GrSurfaceOriginToStr(GrSurfaceOrigin origin)1081 static constexpr const char* GrSurfaceOriginToStr(GrSurfaceOrigin origin) {
1082 switch (origin) {
1083 case kTopLeft_GrSurfaceOrigin: return "kTopLeft";
1084 case kBottomLeft_GrSurfaceOrigin: return "kBottomLeft";
1085 }
1086 SkUNREACHABLE;
1087 }
1088 #endif
1089
1090 #endif
1091