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