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 "GrSharedEnums.h" 13#include "GrTypes.h" 14#include "SkImageInfo.h" 15#include "SkRefCnt.h" 16 17class GrCaps; 18 19// The old libstdc++ uses the draft name "monotonic_clock" rather than "steady_clock". This might 20// not actually be monotonic, depending on how libstdc++ was built. However, this is only currently 21// used for idle resource purging so it shouldn't cause a correctness problem. 22#if defined(__GLIBCXX__) && (__GLIBCXX__ < 20130000) 23using GrStdSteadyClock = std::chrono::monotonic_clock; 24#else 25using GrStdSteadyClock = std::chrono::steady_clock; 26#endif 27 28/** This enum is used to specify the load operation to be used when an 29 * opList/GrGpuCommandBuffer begins execution. 30 */ 31enum class GrLoadOp { 32 kLoad, 33 kClear, 34 kDiscard, 35}; 36 37/** This enum is used to specify the store operation to be used when an 38 * opList/GrGpuCommandBuffer ends execution. 39 */ 40enum class GrStoreOp { 41 kStore, 42 kDiscard, 43}; 44 45/** This enum indicates the type of antialiasing to be performed. */ 46enum class GrAAType : unsigned { 47 /** No antialiasing */ 48 kNone, 49 /** Use fragment shader code to compute a fractional pixel coverage. */ 50 kCoverage, 51 /** Use normal MSAA. */ 52 kMSAA, 53 /** 54 * Use "mixed samples" MSAA such that the stencil buffer is multisampled but the color buffer is 55 * not. 56 */ 57 kMixedSamples 58}; 59 60static inline bool GrAATypeIsHW(GrAAType type) { 61 switch (type) { 62 case GrAAType::kNone: 63 return false; 64 case GrAAType::kCoverage: 65 return false; 66 case GrAAType::kMSAA: 67 return true; 68 case GrAAType::kMixedSamples: 69 return true; 70 } 71 SK_ABORT("Unknown AA Type"); 72 return false; 73} 74 75/** The type of full scene antialiasing supported by a render target. */ 76enum class GrFSAAType { 77 /** No FSAA */ 78 kNone, 79 /** Regular MSAA where each attachment has the same sample count. */ 80 kUnifiedMSAA, 81 /** One color sample, N stencil samples. */ 82 kMixedSamples, 83}; 84 85/** 86 * Not all drawing code paths support using mixed samples when available and instead use 87 * coverage-based aa. 88 */ 89enum class GrAllowMixedSamples : bool { kNo = false, kYes = true }; 90 91GrAAType GrChooseAAType(GrAA, GrFSAAType, GrAllowMixedSamples, const GrCaps&); 92 93/** 94 * Some pixel configs are inherently clamped to [0,1], while others can hold values outside of that 95 * range. This is important for blending - the latter category may require manual clamping. 96 */ 97enum class GrPixelConfigIsClamped : bool { 98 kNo = false, // F16 or F32 99 kYes = true, // Any UNORM type 100}; 101 102/** 103 * Types of shader-language-specific boxed variables we can create. (Currently only GrGLShaderVars, 104 * but should be applicable to other shader languages.) 105 */ 106enum GrSLType { 107 kVoid_GrSLType, 108 kBool_GrSLType, 109 kShort_GrSLType, 110 kShort2_GrSLType, 111 kShort3_GrSLType, 112 kShort4_GrSLType, 113 kUShort_GrSLType, 114 kUShort2_GrSLType, 115 kUShort3_GrSLType, 116 kUShort4_GrSLType, 117 kFloat_GrSLType, 118 kFloat2_GrSLType, 119 kFloat3_GrSLType, 120 kFloat4_GrSLType, 121 kFloat2x2_GrSLType, 122 kFloat3x3_GrSLType, 123 kFloat4x4_GrSLType, 124 kHalf_GrSLType, 125 kHalf2_GrSLType, 126 kHalf3_GrSLType, 127 kHalf4_GrSLType, 128 kHalf2x2_GrSLType, 129 kHalf3x3_GrSLType, 130 kHalf4x4_GrSLType, 131 kInt_GrSLType, 132 kInt2_GrSLType, 133 kInt3_GrSLType, 134 kInt4_GrSLType, 135 kUint_GrSLType, 136 kUint2_GrSLType, 137 kTexture2DSampler_GrSLType, 138 kTextureExternalSampler_GrSLType, 139 kTexture2DRectSampler_GrSLType, 140 kBufferSampler_GrSLType, 141 kTexture2D_GrSLType, 142 kSampler_GrSLType, 143}; 144 145enum GrShaderType { 146 kVertex_GrShaderType, 147 kGeometry_GrShaderType, 148 kFragment_GrShaderType, 149 150 kLastkFragment_GrShaderType = kFragment_GrShaderType 151}; 152static const int kGrShaderTypeCount = kLastkFragment_GrShaderType + 1; 153 154enum GrShaderFlags { 155 kNone_GrShaderFlags = 0, 156 kVertex_GrShaderFlag = 1 << kVertex_GrShaderType, 157 kGeometry_GrShaderFlag = 1 << kGeometry_GrShaderType, 158 kFragment_GrShaderFlag = 1 << kFragment_GrShaderType 159}; 160GR_MAKE_BITFIELD_OPS(GrShaderFlags); 161 162/** 163 * Precisions of shader language variables. Not all shading languages support precisions or actually 164 * vary the internal precision based on the qualifiers. These currently only apply to float types ( 165 * including float vectors and matrices). 166 */ 167enum GrSLPrecision { 168 kLow_GrSLPrecision, 169 kMedium_GrSLPrecision, 170 kHigh_GrSLPrecision, 171 172 // Default precision is a special tag that means "whatever the default for the program/type 173 // combination is". In other words, it maps to the empty string in shader code. There are some 174 // scenarios where kDefault is not allowed (as the default precision for a program, or for 175 // varyings, for example). 176 kDefault_GrSLPrecision, 177 178 // We only consider the "real" precisions here 179 kLast_GrSLPrecision = kHigh_GrSLPrecision, 180}; 181 182static const int kGrSLPrecisionCount = kLast_GrSLPrecision + 1; 183 184/** Is the shading language type float (including vectors/matrices)? */ 185static inline bool GrSLTypeIsFloatType(GrSLType type) { 186 switch (type) { 187 case kFloat_GrSLType: 188 case kFloat2_GrSLType: 189 case kFloat3_GrSLType: 190 case kFloat4_GrSLType: 191 case kFloat2x2_GrSLType: 192 case kFloat3x3_GrSLType: 193 case kFloat4x4_GrSLType: 194 case kHalf_GrSLType: 195 case kHalf2_GrSLType: 196 case kHalf3_GrSLType: 197 case kHalf4_GrSLType: 198 case kHalf2x2_GrSLType: 199 case kHalf3x3_GrSLType: 200 case kHalf4x4_GrSLType: 201 return true; 202 203 case kVoid_GrSLType: 204 case kTexture2DSampler_GrSLType: 205 case kTextureExternalSampler_GrSLType: 206 case kTexture2DRectSampler_GrSLType: 207 case kBufferSampler_GrSLType: 208 case kBool_GrSLType: 209 case kShort_GrSLType: 210 case kShort2_GrSLType: 211 case kShort3_GrSLType: 212 case kShort4_GrSLType: 213 case kUShort_GrSLType: 214 case kUShort2_GrSLType: 215 case kUShort3_GrSLType: 216 case kUShort4_GrSLType: 217 case kInt_GrSLType: 218 case kInt2_GrSLType: 219 case kInt3_GrSLType: 220 case kInt4_GrSLType: 221 case kUint_GrSLType: 222 case kUint2_GrSLType: 223 case kTexture2D_GrSLType: 224 case kSampler_GrSLType: 225 return false; 226 } 227 SK_ABORT("Unexpected type"); 228 return false; 229} 230 231/** If the type represents a single value or vector return the vector length, else -1. */ 232static inline int GrSLTypeVecLength(GrSLType type) { 233 switch (type) { 234 case kFloat_GrSLType: 235 case kHalf_GrSLType: 236 case kBool_GrSLType: 237 case kShort_GrSLType: 238 case kUShort_GrSLType: 239 case kInt_GrSLType: 240 case kUint_GrSLType: 241 return 1; 242 243 case kFloat2_GrSLType: 244 case kHalf2_GrSLType: 245 case kShort2_GrSLType: 246 case kUShort2_GrSLType: 247 case kInt2_GrSLType: 248 case kUint2_GrSLType: 249 return 2; 250 251 case kFloat3_GrSLType: 252 case kHalf3_GrSLType: 253 case kShort3_GrSLType: 254 case kUShort3_GrSLType: 255 case kInt3_GrSLType: 256 return 3; 257 258 case kFloat4_GrSLType: 259 case kHalf4_GrSLType: 260 case kShort4_GrSLType: 261 case kUShort4_GrSLType: 262 case kInt4_GrSLType: 263 return 4; 264 265 case kFloat2x2_GrSLType: 266 case kFloat3x3_GrSLType: 267 case kFloat4x4_GrSLType: 268 case kHalf2x2_GrSLType: 269 case kHalf3x3_GrSLType: 270 case kHalf4x4_GrSLType: 271 case kVoid_GrSLType: 272 case kTexture2DSampler_GrSLType: 273 case kTextureExternalSampler_GrSLType: 274 case kTexture2DRectSampler_GrSLType: 275 case kBufferSampler_GrSLType: 276 case kTexture2D_GrSLType: 277 case kSampler_GrSLType: 278 return -1; 279 } 280 SK_ABORT("Unexpected type"); 281 return -1; 282} 283 284static inline bool GrSLTypeIs2DCombinedSamplerType(GrSLType type) { 285 switch (type) { 286 case kTexture2DSampler_GrSLType: 287 case kTextureExternalSampler_GrSLType: 288 case kTexture2DRectSampler_GrSLType: 289 return true; 290 291 case kVoid_GrSLType: 292 case kFloat_GrSLType: 293 case kFloat2_GrSLType: 294 case kFloat3_GrSLType: 295 case kFloat4_GrSLType: 296 case kFloat2x2_GrSLType: 297 case kFloat3x3_GrSLType: 298 case kFloat4x4_GrSLType: 299 case kHalf_GrSLType: 300 case kHalf2_GrSLType: 301 case kHalf3_GrSLType: 302 case kHalf4_GrSLType: 303 case kHalf2x2_GrSLType: 304 case kHalf3x3_GrSLType: 305 case kHalf4x4_GrSLType: 306 case kInt_GrSLType: 307 case kInt2_GrSLType: 308 case kInt3_GrSLType: 309 case kInt4_GrSLType: 310 case kUint_GrSLType: 311 case kUint2_GrSLType: 312 case kBufferSampler_GrSLType: 313 case kBool_GrSLType: 314 case kShort_GrSLType: 315 case kShort2_GrSLType: 316 case kShort3_GrSLType: 317 case kShort4_GrSLType: 318 case kUShort_GrSLType: 319 case kUShort2_GrSLType: 320 case kUShort3_GrSLType: 321 case kUShort4_GrSLType: 322 case kTexture2D_GrSLType: 323 case kSampler_GrSLType: 324 return false; 325 } 326 SK_ABORT("Unexpected type"); 327 return false; 328} 329 330static inline bool GrSLTypeIsCombinedSamplerType(GrSLType type) { 331 switch (type) { 332 case kTexture2DSampler_GrSLType: 333 case kTextureExternalSampler_GrSLType: 334 case kTexture2DRectSampler_GrSLType: 335 case kBufferSampler_GrSLType: 336 return true; 337 338 case kVoid_GrSLType: 339 case kFloat_GrSLType: 340 case kFloat2_GrSLType: 341 case kFloat3_GrSLType: 342 case kFloat4_GrSLType: 343 case kFloat2x2_GrSLType: 344 case kFloat3x3_GrSLType: 345 case kFloat4x4_GrSLType: 346 case kHalf_GrSLType: 347 case kHalf2_GrSLType: 348 case kHalf3_GrSLType: 349 case kHalf4_GrSLType: 350 case kHalf2x2_GrSLType: 351 case kHalf3x3_GrSLType: 352 case kHalf4x4_GrSLType: 353 case kInt_GrSLType: 354 case kInt2_GrSLType: 355 case kInt3_GrSLType: 356 case kInt4_GrSLType: 357 case kUint_GrSLType: 358 case kUint2_GrSLType: 359 case kBool_GrSLType: 360 case kShort_GrSLType: 361 case kShort2_GrSLType: 362 case kShort3_GrSLType: 363 case kShort4_GrSLType: 364 case kUShort_GrSLType: 365 case kUShort2_GrSLType: 366 case kUShort3_GrSLType: 367 case kUShort4_GrSLType: 368 case kTexture2D_GrSLType: 369 case kSampler_GrSLType: 370 return false; 371 } 372 SK_ABORT("Unexpected type"); 373 return false; 374} 375 376static inline bool GrSLTypeAcceptsPrecision(GrSLType type) { 377 switch (type) { 378 case kTexture2DSampler_GrSLType: 379 case kTextureExternalSampler_GrSLType: 380 case kTexture2DRectSampler_GrSLType: 381 case kBufferSampler_GrSLType: 382 case kTexture2D_GrSLType: 383 case kSampler_GrSLType: 384 return true; 385 386 case kVoid_GrSLType: 387 case kBool_GrSLType: 388 case kShort_GrSLType: 389 case kShort2_GrSLType: 390 case kShort3_GrSLType: 391 case kShort4_GrSLType: 392 case kUShort_GrSLType: 393 case kUShort2_GrSLType: 394 case kUShort3_GrSLType: 395 case kUShort4_GrSLType: 396 case kFloat_GrSLType: 397 case kFloat2_GrSLType: 398 case kFloat3_GrSLType: 399 case kFloat4_GrSLType: 400 case kFloat2x2_GrSLType: 401 case kFloat3x3_GrSLType: 402 case kFloat4x4_GrSLType: 403 case kHalf_GrSLType: 404 case kHalf2_GrSLType: 405 case kHalf3_GrSLType: 406 case kHalf4_GrSLType: 407 case kHalf2x2_GrSLType: 408 case kHalf3x3_GrSLType: 409 case kHalf4x4_GrSLType: 410 case kInt_GrSLType: 411 case kInt2_GrSLType: 412 case kInt3_GrSLType: 413 case kInt4_GrSLType: 414 case kUint_GrSLType: 415 case kUint2_GrSLType: 416 return false; 417 } 418 SK_ABORT("Unexpected type"); 419 return false; 420} 421 422// temporarily accepting (but ignoring) precision modifiers on the new types; this will be killed 423// in a future CL 424static inline bool GrSLTypeTemporarilyAcceptsPrecision(GrSLType type) { 425 switch (type) { 426 case kShort_GrSLType: 427 case kUShort_GrSLType: 428 case kFloat_GrSLType: 429 case kFloat2_GrSLType: 430 case kFloat3_GrSLType: 431 case kFloat4_GrSLType: 432 case kFloat2x2_GrSLType: 433 case kFloat3x3_GrSLType: 434 case kFloat4x4_GrSLType: 435 case kHalf_GrSLType: 436 case kHalf2_GrSLType: 437 case kHalf3_GrSLType: 438 case kHalf4_GrSLType: 439 case kHalf2x2_GrSLType: 440 case kHalf3x3_GrSLType: 441 case kHalf4x4_GrSLType: 442 case kInt_GrSLType: 443 case kInt2_GrSLType: 444 case kInt3_GrSLType: 445 case kInt4_GrSLType: 446 case kUint_GrSLType: 447 case kUint2_GrSLType: 448 case kTexture2DSampler_GrSLType: 449 case kTextureExternalSampler_GrSLType: 450 case kTexture2DRectSampler_GrSLType: 451 case kBufferSampler_GrSLType: 452 case kTexture2D_GrSLType: 453 case kSampler_GrSLType: 454 return true; 455 456 case kVoid_GrSLType: 457 case kBool_GrSLType: 458 case kShort2_GrSLType: 459 case kShort3_GrSLType: 460 case kShort4_GrSLType: 461 case kUShort2_GrSLType: 462 case kUShort3_GrSLType: 463 case kUShort4_GrSLType: 464 return false; 465 } 466 SK_ABORT("Unexpected type"); 467 return false; 468} 469 470////////////////////////////////////////////////////////////////////////////// 471 472/** 473 * Types used to describe format of vertices in arrays. 474 */ 475enum GrVertexAttribType { 476 kFloat_GrVertexAttribType = 0, 477 kFloat2_GrVertexAttribType, 478 kFloat3_GrVertexAttribType, 479 kFloat4_GrVertexAttribType, 480 kHalf_GrVertexAttribType, 481 kHalf2_GrVertexAttribType, 482 kHalf3_GrVertexAttribType, 483 kHalf4_GrVertexAttribType, 484 485 kInt2_GrVertexAttribType, // vector of 2 32-bit ints 486 kInt3_GrVertexAttribType, // vector of 3 32-bit ints 487 kInt4_GrVertexAttribType, // vector of 4 32-bit ints 488 489 kUByte_norm_GrVertexAttribType, // unsigned byte, e.g. coverage, 0 -> 0.0f, 255 -> 1.0f. 490 kUByte4_norm_GrVertexAttribType, // vector of 4 unsigned bytes, e.g. colors, 0 -> 0.0f, 491 // 255 -> 1.0f. 492 493 kShort2_GrVertexAttribType, // vector of 2 16-bit shorts. 494 kUShort2_GrVertexAttribType, // vector of 2 unsigned shorts. 0 -> 0, 65535 -> 65535. 495 kUShort2_norm_GrVertexAttribType, // vector of 2 unsigned shorts. 0 -> 0.0f, 65535 -> 1.0f. 496 497 kInt_GrVertexAttribType, 498 kUint_GrVertexAttribType, 499 500 kLast_GrVertexAttribType = kUint_GrVertexAttribType 501}; 502static const int kGrVertexAttribTypeCount = kLast_GrVertexAttribType + 1; 503 504/** 505 * Returns the size of the attrib type in bytes. 506 */ 507static inline size_t GrVertexAttribTypeSize(GrVertexAttribType type) { 508 switch (type) { 509 case kFloat_GrVertexAttribType: 510 return sizeof(float); 511 case kFloat2_GrVertexAttribType: 512 return 2 * sizeof(float); 513 case kFloat3_GrVertexAttribType: 514 return 3 * sizeof(float); 515 case kFloat4_GrVertexAttribType: 516 return 4 * sizeof(float); 517 case kHalf_GrVertexAttribType: 518 return sizeof(float); 519 case kHalf2_GrVertexAttribType: 520 return 2 * sizeof(float); 521 case kHalf3_GrVertexAttribType: 522 return 3 * sizeof(float); 523 case kHalf4_GrVertexAttribType: 524 return 4 * sizeof(float); 525 case kInt2_GrVertexAttribType: 526 return 2 * sizeof(int32_t); 527 case kInt3_GrVertexAttribType: 528 return 3 * sizeof(int32_t); 529 case kInt4_GrVertexAttribType: 530 return 4 * sizeof(int32_t); 531 case kUByte_norm_GrVertexAttribType: 532 return 1 * sizeof(char); 533 case kUByte4_norm_GrVertexAttribType: 534 return 4 * sizeof(char); 535 case kShort2_GrVertexAttribType: 536 return 2 * sizeof(int16_t); 537 case kUShort2_GrVertexAttribType: // fall through 538 case kUShort2_norm_GrVertexAttribType: 539 return 2 * sizeof(uint16_t); 540 case kInt_GrVertexAttribType: 541 return sizeof(int32_t); 542 case kUint_GrVertexAttribType: 543 return sizeof(uint32_t); 544 } 545 SK_ABORT("Unexpected attribute type"); 546 return 0; 547} 548 549/** 550 * converts a GrVertexAttribType to a GrSLType 551 */ 552static inline GrSLType GrVertexAttribTypeToSLType(GrVertexAttribType type) { 553 switch (type) { 554 case kShort2_GrVertexAttribType: 555 return kShort2_GrSLType; 556 case kUShort2_GrVertexAttribType: 557 return kUShort2_GrSLType; 558 case kUShort2_norm_GrVertexAttribType: 559 return kFloat2_GrSLType; 560 case kUByte_norm_GrVertexAttribType: // fall through 561 case kFloat_GrVertexAttribType: 562 return kFloat_GrSLType; 563 case kFloat2_GrVertexAttribType: 564 return kFloat2_GrSLType; 565 case kFloat3_GrVertexAttribType: 566 return kFloat3_GrSLType; 567 case kFloat4_GrVertexAttribType: 568 return kFloat4_GrSLType; 569 case kHalf_GrVertexAttribType: 570 return kHalf_GrSLType; 571 case kHalf2_GrVertexAttribType: 572 return kHalf2_GrSLType; 573 case kHalf3_GrVertexAttribType: 574 return kHalf3_GrSLType; 575 case kHalf4_GrVertexAttribType: 576 case kUByte4_norm_GrVertexAttribType: 577 return kHalf4_GrSLType; 578 case kInt2_GrVertexAttribType: 579 return kInt2_GrSLType; 580 case kInt3_GrVertexAttribType: 581 return kInt3_GrSLType; 582 case kInt4_GrVertexAttribType: 583 return kInt4_GrSLType; 584 case kInt_GrVertexAttribType: 585 return kInt_GrSLType; 586 case kUint_GrVertexAttribType: 587 return kUint_GrSLType; 588 } 589 SK_ABORT("Unsupported type conversion"); 590 return kVoid_GrSLType; 591} 592 593////////////////////////////////////////////////////////////////////////////// 594 595static const int kGrClipEdgeTypeCnt = (int) GrClipEdgeType::kLast + 1; 596 597static inline bool GrProcessorEdgeTypeIsFill(const GrClipEdgeType edgeType) { 598 return (GrClipEdgeType::kFillAA == edgeType || GrClipEdgeType::kFillBW == edgeType); 599} 600 601static inline bool GrProcessorEdgeTypeIsInverseFill(const GrClipEdgeType edgeType) { 602 return (GrClipEdgeType::kInverseFillAA == edgeType || 603 GrClipEdgeType::kInverseFillBW == edgeType); 604} 605 606static inline bool GrProcessorEdgeTypeIsAA(const GrClipEdgeType edgeType) { 607 return (GrClipEdgeType::kFillBW != edgeType && 608 GrClipEdgeType::kInverseFillBW != edgeType); 609} 610 611static inline GrClipEdgeType GrInvertProcessorEdgeType(const GrClipEdgeType edgeType) { 612 switch (edgeType) { 613 case GrClipEdgeType::kFillBW: 614 return GrClipEdgeType::kInverseFillBW; 615 case GrClipEdgeType::kFillAA: 616 return GrClipEdgeType::kInverseFillAA; 617 case GrClipEdgeType::kInverseFillBW: 618 return GrClipEdgeType::kFillBW; 619 case GrClipEdgeType::kInverseFillAA: 620 return GrClipEdgeType::kFillAA; 621 case GrClipEdgeType::kHairlineAA: 622 SK_ABORT("Hairline fill isn't invertible."); 623 } 624 return GrClipEdgeType::kFillAA; // suppress warning. 625} 626 627/** 628 * Indicates the type of pending IO operations that can be recorded for gpu resources. 629 */ 630enum GrIOType { 631 kRead_GrIOType, 632 kWrite_GrIOType, 633 kRW_GrIOType 634}; 635 636/** 637 * Indicates the type of data that a GPU buffer will be used for. 638 */ 639enum GrBufferType { 640 kVertex_GrBufferType, 641 kIndex_GrBufferType, 642 kTexel_GrBufferType, 643 kDrawIndirect_GrBufferType, 644 kXferCpuToGpu_GrBufferType, 645 kXferGpuToCpu_GrBufferType, 646 647 kLast_GrBufferType = kXferGpuToCpu_GrBufferType 648}; 649static const int kGrBufferTypeCount = kLast_GrBufferType + 1; 650 651static inline bool GrBufferTypeIsVertexOrIndex(GrBufferType type) { 652 SkASSERT(type >= 0 && type < kGrBufferTypeCount); 653 return type <= kIndex_GrBufferType; 654 655 GR_STATIC_ASSERT(0 == kVertex_GrBufferType); 656 GR_STATIC_ASSERT(1 == kIndex_GrBufferType); 657} 658 659/** 660 * Provides a performance hint regarding the frequency at which a data store will be accessed. 661 */ 662enum GrAccessPattern { 663 /** Data store will be respecified repeatedly and used many times. */ 664 kDynamic_GrAccessPattern, 665 /** Data store will be specified once and used many times. (Thus disqualified from caching.) */ 666 kStatic_GrAccessPattern, 667 /** Data store will be specified once and used at most a few times. (Also can't be cached.) */ 668 kStream_GrAccessPattern, 669 670 kLast_GrAccessPattern = kStream_GrAccessPattern 671}; 672 673// Flags shared between GrRenderTarget and GrRenderTargetProxy 674enum class GrRenderTargetFlags { 675 kNone = 0, 676 677 // For internal resources: 678 // this is enabled whenever MSAA is enabled and GrCaps reports mixed samples are supported 679 // For wrapped resources: 680 // this is disabled for FBO0 681 // but, otherwise, is enabled whenever MSAA is enabled and GrCaps reports mixed samples 682 // are supported 683 kMixedSampled = 1 << 0, 684 685 // For internal resources: 686 // this is enabled whenever GrCaps reports window rect support 687 // For wrapped resources1 688 // this is disabled for FBO0 689 // but, otherwise, is enabled whenever GrCaps reports window rect support 690 kWindowRectsSupport = 1 << 1 691}; 692GR_MAKE_BITFIELD_CLASS_OPS(GrRenderTargetFlags) 693 694#ifdef SK_DEBUG 695// Takes a pointer to a GrCaps, and will suppress prints if required 696#define GrCapsDebugf(caps, ...) \ 697 if (!(caps)->suppressPrints()) { \ 698 SkDebugf(__VA_ARGS__); \ 699 } 700#else 701#define GrCapsDebugf(caps, ...) 702#endif 703 704/** 705 * Specifies if the holder owns the backend, OpenGL or Vulkan, object. 706 */ 707enum class GrBackendObjectOwnership : bool { 708 /** Holder does not destroy the backend object. */ 709 kBorrowed = false, 710 /** Holder destroys the backend object. */ 711 kOwned = true 712}; 713 714template <typename T> 715T* const* unique_ptr_address_as_pointer_address(std::unique_ptr<T> const* up) { 716 static_assert(sizeof(T*) == sizeof(std::unique_ptr<T>), "unique_ptr not expected size."); 717 return reinterpret_cast<T* const*>(up); 718} 719 720/* 721 * Object for CPU-GPU synchronization 722 */ 723typedef uint64_t GrFence; 724 725/** 726 * Used to include or exclude specific GPU path renderers for testing purposes. 727 */ 728enum class GpuPathRenderers { 729 kNone = 0, // Always use sofware masks and/or GrDefaultPathRenderer. 730 kDashLine = 1 << 0, 731 kStencilAndCover = 1 << 1, 732 kMSAA = 1 << 2, 733 kAAConvex = 1 << 3, 734 kAALinearizing = 1 << 4, 735 kSmall = 1 << 5, 736 kCoverageCounting = 1 << 6, 737 kTessellating = 1 << 7, 738 739 kAll = (kTessellating | (kTessellating - 1)), 740 kDefault = kAll 741}; 742 743/** 744 * Used to describe the current state of Mips on a GrTexture 745 */ 746enum class GrMipMapsStatus { 747 kNotAllocated, // Mips have not been allocated 748 kDirty, // Mips are allocated but the full mip tree does not have valid data 749 kValid, // All levels fully allocated and have valid data in them 750}; 751 752GR_MAKE_BITFIELD_CLASS_OPS(GpuPathRenderers) 753 754/** 755 * We want to extend the GrPixelConfig enum to add cases for dealing with alpha_8 which is 756 * internally either alpha8 or red8. Also for Gray_8 which can be luminance_8 or red_8. 757 */ 758static constexpr GrPixelConfig kAlpha_8_as_Alpha_GrPixelConfig = kPrivateConfig1_GrPixelConfig; 759static constexpr GrPixelConfig kAlpha_8_as_Red_GrPixelConfig = kPrivateConfig2_GrPixelConfig; 760static constexpr GrPixelConfig kAlpha_half_as_Red_GrPixelConfig = kPrivateConfig3_GrPixelConfig; 761static constexpr GrPixelConfig kGray_8_as_Lum_GrPixelConfig = kPrivateConfig4_GrPixelConfig; 762static constexpr GrPixelConfig kGray_8_as_Red_GrPixelConfig = kPrivateConfig5_GrPixelConfig; 763 764/** 765 * Refers to the encoding of a GPU buffer as it will be interpreted by the GPU when sampling and 766 * blending. 767 */ 768enum class GrSRGBEncoded : bool { kNo = false, kYes = true }; 769 770/** 771 * Describes whether pixel data encoding should be converted to/from linear/sRGB encoding. 772 */ 773enum class GrSRGBConversion { 774 kNone, 775 kSRGBToLinear, 776 kLinearToSRGB, 777}; 778 779/** 780 * Utility functions for GrPixelConfig 781 */ 782 783// Returns whether the config's color channels are sRGB encoded. 784static inline GrSRGBEncoded GrPixelConfigIsSRGBEncoded(GrPixelConfig config) { 785 switch (config) { 786 case kSRGBA_8888_GrPixelConfig: 787 case kSBGRA_8888_GrPixelConfig: 788 return GrSRGBEncoded::kYes; 789 case kUnknown_GrPixelConfig: 790 case kAlpha_8_GrPixelConfig: 791 case kAlpha_8_as_Alpha_GrPixelConfig: 792 case kAlpha_8_as_Red_GrPixelConfig: 793 case kGray_8_GrPixelConfig: 794 case kGray_8_as_Lum_GrPixelConfig: 795 case kGray_8_as_Red_GrPixelConfig: 796 case kRGB_565_GrPixelConfig: 797 case kRGBA_4444_GrPixelConfig: 798 case kRGBA_8888_GrPixelConfig: 799 case kBGRA_8888_GrPixelConfig: 800 case kRGBA_1010102_GrPixelConfig: 801 case kRGBA_float_GrPixelConfig: 802 case kRG_float_GrPixelConfig: 803 case kAlpha_half_GrPixelConfig: 804 case kAlpha_half_as_Red_GrPixelConfig: 805 case kRGBA_half_GrPixelConfig: 806 return GrSRGBEncoded::kNo; 807 } 808 SK_ABORT("Invalid pixel config"); 809 return GrSRGBEncoded::kNo; 810} 811 812static inline bool GrPixelConfigIsSRGB(GrPixelConfig config) { 813 return GrSRGBEncoded::kYes == GrPixelConfigIsSRGBEncoded(config); 814} 815// Takes a config and returns the equivalent config with the R and B order 816// swapped if such a config exists. Otherwise, kUnknown_GrPixelConfig 817static inline GrPixelConfig GrPixelConfigSwapRAndB(GrPixelConfig config) { 818 switch (config) { 819 case kBGRA_8888_GrPixelConfig: 820 return kRGBA_8888_GrPixelConfig; 821 case kRGBA_8888_GrPixelConfig: 822 return kBGRA_8888_GrPixelConfig; 823 case kSBGRA_8888_GrPixelConfig: 824 return kSRGBA_8888_GrPixelConfig; 825 case kSRGBA_8888_GrPixelConfig: 826 return kSBGRA_8888_GrPixelConfig; 827 case kUnknown_GrPixelConfig: 828 case kAlpha_8_GrPixelConfig: 829 case kAlpha_8_as_Alpha_GrPixelConfig: 830 case kAlpha_8_as_Red_GrPixelConfig: 831 case kGray_8_GrPixelConfig: 832 case kGray_8_as_Lum_GrPixelConfig: 833 case kGray_8_as_Red_GrPixelConfig: 834 case kRGB_565_GrPixelConfig: 835 case kRGBA_4444_GrPixelConfig: 836 case kRGBA_1010102_GrPixelConfig: 837 case kRGBA_float_GrPixelConfig: 838 case kRG_float_GrPixelConfig: 839 case kAlpha_half_GrPixelConfig: 840 case kAlpha_half_as_Red_GrPixelConfig: 841 case kRGBA_half_GrPixelConfig: 842 return kUnknown_GrPixelConfig; 843 } 844 SK_ABORT("Invalid pixel config"); 845 return kUnknown_GrPixelConfig; 846} 847 848static inline size_t GrBytesPerPixel(GrPixelConfig config) { 849 switch (config) { 850 case kAlpha_8_GrPixelConfig: 851 case kAlpha_8_as_Alpha_GrPixelConfig: 852 case kAlpha_8_as_Red_GrPixelConfig: 853 case kGray_8_GrPixelConfig: 854 case kGray_8_as_Lum_GrPixelConfig: 855 case kGray_8_as_Red_GrPixelConfig: 856 return 1; 857 case kRGB_565_GrPixelConfig: 858 case kRGBA_4444_GrPixelConfig: 859 case kAlpha_half_GrPixelConfig: 860 case kAlpha_half_as_Red_GrPixelConfig: 861 return 2; 862 case kRGBA_8888_GrPixelConfig: 863 case kBGRA_8888_GrPixelConfig: 864 case kSRGBA_8888_GrPixelConfig: 865 case kSBGRA_8888_GrPixelConfig: 866 case kRGBA_1010102_GrPixelConfig: 867 return 4; 868 case kRGBA_half_GrPixelConfig: 869 return 8; 870 case kRGBA_float_GrPixelConfig: 871 return 16; 872 case kRG_float_GrPixelConfig: 873 return 8; 874 case kUnknown_GrPixelConfig: 875 return 0; 876 } 877 SK_ABORT("Invalid pixel config"); 878 return 0; 879} 880 881static inline bool GrPixelConfigIsOpaque(GrPixelConfig config) { 882 switch (config) { 883 case kRGB_565_GrPixelConfig: 884 case kGray_8_GrPixelConfig: 885 case kGray_8_as_Lum_GrPixelConfig: 886 case kGray_8_as_Red_GrPixelConfig: 887 case kRG_float_GrPixelConfig: 888 return true; 889 case kAlpha_8_GrPixelConfig: 890 case kAlpha_8_as_Alpha_GrPixelConfig: 891 case kAlpha_8_as_Red_GrPixelConfig: 892 case kRGBA_4444_GrPixelConfig: 893 case kAlpha_half_GrPixelConfig: 894 case kAlpha_half_as_Red_GrPixelConfig: 895 case kRGBA_8888_GrPixelConfig: 896 case kBGRA_8888_GrPixelConfig: 897 case kSRGBA_8888_GrPixelConfig: 898 case kSBGRA_8888_GrPixelConfig: 899 case kRGBA_1010102_GrPixelConfig: 900 case kRGBA_half_GrPixelConfig: 901 case kRGBA_float_GrPixelConfig: 902 case kUnknown_GrPixelConfig: 903 return false; 904 } 905 SK_ABORT("Invalid pixel config"); 906 return false; 907} 908 909static inline bool GrPixelConfigIsAlphaOnly(GrPixelConfig config) { 910 switch (config) { 911 case kAlpha_8_GrPixelConfig: 912 case kAlpha_8_as_Alpha_GrPixelConfig: 913 case kAlpha_8_as_Red_GrPixelConfig: 914 case kAlpha_half_GrPixelConfig: 915 case kAlpha_half_as_Red_GrPixelConfig: 916 return true; 917 case kUnknown_GrPixelConfig: 918 case kGray_8_GrPixelConfig: 919 case kGray_8_as_Lum_GrPixelConfig: 920 case kGray_8_as_Red_GrPixelConfig: 921 case kRGB_565_GrPixelConfig: 922 case kRGBA_4444_GrPixelConfig: 923 case kRGBA_8888_GrPixelConfig: 924 case kBGRA_8888_GrPixelConfig: 925 case kSRGBA_8888_GrPixelConfig: 926 case kSBGRA_8888_GrPixelConfig: 927 case kRGBA_1010102_GrPixelConfig: 928 case kRGBA_float_GrPixelConfig: 929 case kRG_float_GrPixelConfig: 930 case kRGBA_half_GrPixelConfig: 931 return false; 932 } 933 SK_ABORT("Invalid pixel config."); 934 return false; 935} 936 937static inline bool GrPixelConfigIsFloatingPoint(GrPixelConfig config) { 938 switch (config) { 939 case kRGBA_float_GrPixelConfig: 940 case kRG_float_GrPixelConfig: 941 case kAlpha_half_GrPixelConfig: 942 case kAlpha_half_as_Red_GrPixelConfig: 943 case kRGBA_half_GrPixelConfig: 944 return true; 945 case kUnknown_GrPixelConfig: 946 case kAlpha_8_GrPixelConfig: 947 case kAlpha_8_as_Alpha_GrPixelConfig: 948 case kAlpha_8_as_Red_GrPixelConfig: 949 case kGray_8_GrPixelConfig: 950 case kGray_8_as_Lum_GrPixelConfig: 951 case kGray_8_as_Red_GrPixelConfig: 952 case kRGB_565_GrPixelConfig: 953 case kRGBA_4444_GrPixelConfig: 954 case kRGBA_8888_GrPixelConfig: 955 case kBGRA_8888_GrPixelConfig: 956 case kSRGBA_8888_GrPixelConfig: 957 case kSBGRA_8888_GrPixelConfig: 958 case kRGBA_1010102_GrPixelConfig: 959 return false; 960 } 961 SK_ABORT("Invalid pixel config"); 962 return false; 963} 964 965static inline bool GrPixelConfigIsUnorm(GrPixelConfig config) { 966 switch (config) { 967 case kAlpha_8_GrPixelConfig: 968 case kAlpha_8_as_Alpha_GrPixelConfig: 969 case kAlpha_8_as_Red_GrPixelConfig: 970 case kGray_8_GrPixelConfig: 971 case kGray_8_as_Lum_GrPixelConfig: 972 case kGray_8_as_Red_GrPixelConfig: 973 case kRGB_565_GrPixelConfig: 974 case kRGBA_4444_GrPixelConfig: 975 case kRGBA_8888_GrPixelConfig: 976 case kBGRA_8888_GrPixelConfig: 977 case kSRGBA_8888_GrPixelConfig: 978 case kSBGRA_8888_GrPixelConfig: 979 case kRGBA_1010102_GrPixelConfig: 980 return true; 981 case kUnknown_GrPixelConfig: 982 case kAlpha_half_GrPixelConfig: 983 case kAlpha_half_as_Red_GrPixelConfig: 984 case kRGBA_float_GrPixelConfig: 985 case kRG_float_GrPixelConfig: 986 case kRGBA_half_GrPixelConfig: 987 return false; 988 } 989 SK_ABORT("Invalid pixel config."); 990 return false; 991} 992 993/** 994 * Precision qualifier that should be used with a sampler. 995 */ 996static inline GrSLPrecision GrSLSamplerPrecision(GrPixelConfig config) { 997 switch (config) { 998 case kUnknown_GrPixelConfig: 999 case kAlpha_8_GrPixelConfig: 1000 case kAlpha_8_as_Alpha_GrPixelConfig: 1001 case kAlpha_8_as_Red_GrPixelConfig: 1002 case kGray_8_GrPixelConfig: 1003 case kGray_8_as_Lum_GrPixelConfig: 1004 case kGray_8_as_Red_GrPixelConfig: 1005 case kRGB_565_GrPixelConfig: 1006 case kRGBA_4444_GrPixelConfig: 1007 case kRGBA_8888_GrPixelConfig: 1008 case kBGRA_8888_GrPixelConfig: 1009 case kSRGBA_8888_GrPixelConfig: 1010 case kSBGRA_8888_GrPixelConfig: 1011 return kLow_GrSLPrecision; 1012 case kRGBA_float_GrPixelConfig: 1013 case kRG_float_GrPixelConfig: 1014 return kHigh_GrSLPrecision; 1015 case kAlpha_half_GrPixelConfig: 1016 case kAlpha_half_as_Red_GrPixelConfig: 1017 case kRGBA_half_GrPixelConfig: 1018 case kRGBA_1010102_GrPixelConfig: 1019 return kMedium_GrSLPrecision; 1020 } 1021 SK_ABORT("Unexpected type"); 1022 return kHigh_GrSLPrecision; 1023} 1024 1025static inline GrPixelConfigIsClamped GrGetPixelConfigIsClamped(GrPixelConfig config) { 1026 return GrPixelConfigIsFloatingPoint(config) ? GrPixelConfigIsClamped::kNo 1027 : GrPixelConfigIsClamped::kYes; 1028} 1029 1030/** 1031 * Like SkColorType this describes a layout of pixel data in CPU memory. It specifies the channels, 1032 * their type, and width. This exists so that the GPU backend can have private types that have no 1033 * analog in the public facing SkColorType enum and omit types not implemented in the GPU backend. 1034 * It does not refer to a texture format and the mapping to texture formats may be many-to-many. 1035 * It does not specify the sRGB encding of the stored values. 1036 */ 1037enum class GrColorType { 1038 kUnknown, 1039 kAlpha_8, 1040 kRGB_565, 1041 kABGR_4444, // This name differs from SkColorType. kARGB_4444_SkColorType is misnamed. 1042 kRGBA_8888, 1043 kBGRA_8888, 1044 kRGBA_1010102, 1045 kGray_8, 1046 kAlpha_F16, 1047 kRGBA_F16, 1048 kRG_F32, 1049 kRGBA_F32, 1050}; 1051 1052static inline SkColorType GrColorTypeToSkColorType(GrColorType ct) { 1053 switch (ct) { 1054 case GrColorType::kUnknown: return kUnknown_SkColorType; 1055 case GrColorType::kAlpha_8: return kAlpha_8_SkColorType; 1056 case GrColorType::kRGB_565: return kRGB_565_SkColorType; 1057 case GrColorType::kABGR_4444: return kARGB_4444_SkColorType; 1058 case GrColorType::kRGBA_8888: return kRGBA_8888_SkColorType; 1059 case GrColorType::kBGRA_8888: return kBGRA_8888_SkColorType; 1060 case GrColorType::kRGBA_1010102: return kRGBA_1010102_SkColorType; 1061 case GrColorType::kGray_8: return kGray_8_SkColorType; 1062 case GrColorType::kAlpha_F16: return kUnknown_SkColorType; 1063 case GrColorType::kRGBA_F16: return kRGBA_F16_SkColorType; 1064 case GrColorType::kRG_F32: return kUnknown_SkColorType; 1065 case GrColorType::kRGBA_F32: return kUnknown_SkColorType; 1066 } 1067 SK_ABORT("Invalid GrColorType"); 1068 return kUnknown_SkColorType; 1069} 1070 1071static inline GrColorType SkColorTypeToGrColorType(SkColorType ct) { 1072 switch (ct) { 1073 case kUnknown_SkColorType: return GrColorType::kUnknown; 1074 case kAlpha_8_SkColorType: return GrColorType::kAlpha_8; 1075 case kRGB_565_SkColorType: return GrColorType::kRGB_565; 1076 case kARGB_4444_SkColorType: return GrColorType::kABGR_4444; 1077 case kRGBA_8888_SkColorType: return GrColorType::kRGBA_8888; 1078 case kBGRA_8888_SkColorType: return GrColorType::kBGRA_8888; 1079 case kRGB_888x_SkColorType: return GrColorType::kUnknown; 1080 case kGray_8_SkColorType: return GrColorType::kGray_8; 1081 case kRGBA_F16_SkColorType: return GrColorType::kRGBA_F16; 1082 case kRGBA_1010102_SkColorType: return GrColorType::kRGBA_1010102; 1083 case kRGB_101010x_SkColorType: return GrColorType::kUnknown; 1084 } 1085 SK_ABORT("Invalid SkColorType"); 1086 return GrColorType::kUnknown; 1087} 1088 1089static inline int GrColorTypeBytesPerPixel(GrColorType ct) { 1090 switch (ct) { 1091 case GrColorType::kUnknown: return 0; 1092 case GrColorType::kAlpha_8: return 1; 1093 case GrColorType::kRGB_565: return 2; 1094 case GrColorType::kABGR_4444: return 2; 1095 case GrColorType::kRGBA_8888: return 4; 1096 case GrColorType::kBGRA_8888: return 4; 1097 case GrColorType::kRGBA_1010102: return 4; 1098 case GrColorType::kGray_8: return 1; 1099 case GrColorType::kAlpha_F16: return 2; 1100 case GrColorType::kRGBA_F16: return 8; 1101 case GrColorType::kRG_F32: return 8; 1102 case GrColorType::kRGBA_F32: return 16; 1103 } 1104 SK_ABORT("Invalid GrColorType"); 1105 return 0; 1106} 1107 1108static inline int GrColorTypeIsAlphaOnly(GrColorType ct) { 1109 switch (ct) { 1110 case GrColorType::kUnknown: return false; 1111 case GrColorType::kAlpha_8: return true; 1112 case GrColorType::kRGB_565: return false; 1113 case GrColorType::kABGR_4444: return false; 1114 case GrColorType::kRGBA_8888: return false; 1115 case GrColorType::kBGRA_8888: return false; 1116 case GrColorType::kRGBA_1010102: return false; 1117 case GrColorType::kGray_8: return false; 1118 case GrColorType::kAlpha_F16: return true; 1119 case GrColorType::kRGBA_F16: return false; 1120 case GrColorType::kRG_F32: return false; 1121 case GrColorType::kRGBA_F32: return false; 1122 } 1123 SK_ABORT("Invalid GrColorType"); 1124 return false; 1125} 1126 1127static inline GrColorType GrPixelConfigToColorTypeAndEncoding(GrPixelConfig config, 1128 GrSRGBEncoded* srgbEncoded) { 1129 SkASSERT(srgbEncoded); 1130 switch (config) { 1131 case kUnknown_GrPixelConfig: 1132 return GrColorType::kUnknown; 1133 case kAlpha_8_GrPixelConfig: 1134 *srgbEncoded = GrSRGBEncoded::kNo; 1135 return GrColorType::kAlpha_8; 1136 case kGray_8_GrPixelConfig: 1137 *srgbEncoded = GrSRGBEncoded::kNo; 1138 return GrColorType::kGray_8; 1139 case kRGB_565_GrPixelConfig: 1140 *srgbEncoded = GrSRGBEncoded::kNo; 1141 return GrColorType::kRGB_565; 1142 case kRGBA_4444_GrPixelConfig: 1143 *srgbEncoded = GrSRGBEncoded::kNo; 1144 return GrColorType::kABGR_4444; 1145 case kRGBA_8888_GrPixelConfig: 1146 *srgbEncoded = GrSRGBEncoded::kNo; 1147 return GrColorType::kRGBA_8888; 1148 case kBGRA_8888_GrPixelConfig: 1149 *srgbEncoded = GrSRGBEncoded::kNo; 1150 return GrColorType::kBGRA_8888; 1151 case kSRGBA_8888_GrPixelConfig: 1152 *srgbEncoded = GrSRGBEncoded::kYes; 1153 return GrColorType::kRGBA_8888; 1154 case kSBGRA_8888_GrPixelConfig: 1155 *srgbEncoded = GrSRGBEncoded::kYes; 1156 return GrColorType::kBGRA_8888; 1157 case kRGBA_1010102_GrPixelConfig: 1158 *srgbEncoded = GrSRGBEncoded::kNo; 1159 return GrColorType::kRGBA_1010102; 1160 case kRGBA_float_GrPixelConfig: 1161 *srgbEncoded = GrSRGBEncoded::kNo; 1162 return GrColorType::kRGBA_F32; 1163 case kRG_float_GrPixelConfig: 1164 *srgbEncoded = GrSRGBEncoded::kNo; 1165 return GrColorType::kRG_F32; 1166 case kAlpha_half_GrPixelConfig: 1167 *srgbEncoded = GrSRGBEncoded::kNo; 1168 return GrColorType::kAlpha_F16; 1169 case kRGBA_half_GrPixelConfig: 1170 *srgbEncoded = GrSRGBEncoded::kNo; 1171 return GrColorType::kRGBA_F16; 1172 case kAlpha_8_as_Alpha_GrPixelConfig: 1173 *srgbEncoded = GrSRGBEncoded::kNo; 1174 return GrColorType::kAlpha_8; 1175 case kAlpha_8_as_Red_GrPixelConfig: 1176 *srgbEncoded = GrSRGBEncoded::kNo; 1177 return GrColorType::kAlpha_8; 1178 case kAlpha_half_as_Red_GrPixelConfig: 1179 *srgbEncoded = GrSRGBEncoded::kNo; 1180 return GrColorType::kAlpha_F16; 1181 case kGray_8_as_Lum_GrPixelConfig: 1182 *srgbEncoded = GrSRGBEncoded::kNo; 1183 return GrColorType::kGray_8; 1184 case kGray_8_as_Red_GrPixelConfig: 1185 *srgbEncoded = GrSRGBEncoded::kNo; 1186 return GrColorType::kGray_8; 1187 } 1188 SK_ABORT("Invalid GrPixelConfig"); 1189 return GrColorType::kUnknown; 1190} 1191 1192static inline GrColorType GrPixelConfigToColorType(GrPixelConfig config) { 1193 GrSRGBEncoded bogusEncoded; 1194 return GrPixelConfigToColorTypeAndEncoding(config, &bogusEncoded); 1195} 1196 1197static inline GrPixelConfig GrColorTypeToPixelConfig(GrColorType config, 1198 GrSRGBEncoded srgbEncoded) { 1199 switch (config) { 1200 case GrColorType::kUnknown: 1201 return kUnknown_GrPixelConfig; 1202 case GrColorType::kAlpha_8: 1203 return (GrSRGBEncoded::kYes == srgbEncoded) ? kUnknown_GrPixelConfig 1204 : kAlpha_8_GrPixelConfig; 1205 1206 case GrColorType::kGray_8: 1207 return (GrSRGBEncoded::kYes == srgbEncoded) ? kUnknown_GrPixelConfig 1208 : kGray_8_GrPixelConfig; 1209 1210 case GrColorType::kRGB_565: 1211 return (GrSRGBEncoded::kYes == srgbEncoded) ? kUnknown_GrPixelConfig 1212 : kRGB_565_GrPixelConfig; 1213 1214 case GrColorType::kABGR_4444: 1215 return (GrSRGBEncoded::kYes == srgbEncoded) ? kUnknown_GrPixelConfig 1216 : kRGBA_4444_GrPixelConfig; 1217 1218 case GrColorType::kRGBA_8888: 1219 return (GrSRGBEncoded::kYes == srgbEncoded) ? kSRGBA_8888_GrPixelConfig 1220 : kRGBA_8888_GrPixelConfig; 1221 1222 case GrColorType::kBGRA_8888: 1223 return (GrSRGBEncoded::kYes == srgbEncoded) ? kSBGRA_8888_GrPixelConfig 1224 : kBGRA_8888_GrPixelConfig; 1225 1226 case GrColorType::kRGBA_1010102: 1227 return (GrSRGBEncoded::kYes == srgbEncoded) ? kUnknown_GrPixelConfig 1228 : kRGBA_1010102_GrPixelConfig; 1229 1230 case GrColorType::kRGBA_F32: 1231 return (GrSRGBEncoded::kYes == srgbEncoded) ? kUnknown_GrPixelConfig 1232 : kRGBA_float_GrPixelConfig; 1233 1234 case GrColorType::kRG_F32: 1235 return (GrSRGBEncoded::kYes == srgbEncoded) ? kUnknown_GrPixelConfig 1236 : kRG_float_GrPixelConfig; 1237 1238 case GrColorType::kAlpha_F16: 1239 return (GrSRGBEncoded::kYes == srgbEncoded) ? kUnknown_GrPixelConfig 1240 : kAlpha_half_GrPixelConfig; 1241 1242 case GrColorType::kRGBA_F16: 1243 return (GrSRGBEncoded::kYes == srgbEncoded) ? kUnknown_GrPixelConfig 1244 : kRGBA_half_GrPixelConfig; 1245 } 1246 SK_ABORT("Invalid GrColorType"); 1247 return kUnknown_GrPixelConfig; 1248} 1249 1250class GrReleaseProcHelper : public SkRefCnt { 1251public: 1252 // These match the definitions in SkImage, from whence they came 1253 typedef void* ReleaseCtx; 1254 typedef void (*ReleaseProc)(ReleaseCtx); 1255 1256 GrReleaseProcHelper(ReleaseProc proc, ReleaseCtx ctx) : fReleaseProc(proc), fReleaseCtx(ctx) {} 1257 ~GrReleaseProcHelper() override { 1258 fReleaseProc(fReleaseCtx); 1259 } 1260 1261private: 1262 ReleaseProc fReleaseProc; 1263 ReleaseCtx fReleaseCtx; 1264}; 1265 1266#endif 1267