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