8 #ifndef GrTypes_DEFINED
9 #define GrTypes_DEFINED
21 #define GR_MAKE_BITFIELD_OPS(X) \
22 inline X operator |(X a, X b) { \
23 return (X) (+a | +b); \
25 inline X& operator |=(X& a, X b) { \
28 inline X operator &(X a, X b) { \
29 return (X) (+a & +b); \
31 inline X& operator &=(X& a, X b) { \
34 template <typename T> \
35 inline X operator &(T a, X b) { \
36 return (X) (+a & +b); \
38 template <typename T> \
39 inline X operator &(X a, T b) { \
40 return (X) (+a & +b); \
43 #define GR_DECL_BITFIELD_OPS_FRIENDS(X) \
44 friend X operator |(X a, X b); \
45 friend X& operator |=(X& a, X b); \
47 friend X operator &(X a, X b); \
48 friend X& operator &=(X& a, X b); \
50 template <typename T> \
51 friend X operator &(T a, X b); \
53 template <typename T> \
54 friend X operator &(X a, T b); \
62 constexpr
explicit GrTFlagsMask(TFlags value) : GrTFlagsMask(static_cast<int>(value)) {}
63 constexpr
explicit GrTFlagsMask(
int value) : fValue(value) {}
64 constexpr
int value()
const {
return fValue; }
93 return static_cast<TFlags
>(a.value() &
static_cast<int>(b));
96 return static_cast<TFlags
>(
static_cast<int>(a) & b.value());
106 #define GR_MAKE_BITFIELD_CLASS_OPS(X) \
107 constexpr GrTFlagsMask<X> operator~(X a) { \
108 return GrTFlagsMask<X>(~static_cast<int>(a)); \
110 constexpr X operator|(X a, X b) { \
111 return static_cast<X>(static_cast<int>(a) | static_cast<int>(b)); \
113 inline X& operator|=(X& a, X b) { \
114 return (a = a | b); \
116 constexpr bool operator&(X a, X b) { \
117 return SkToBool(static_cast<int>(a) & static_cast<int>(b)); \
120 #define GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(X) \
121 friend constexpr GrTFlagsMask<X> operator ~(X); \
122 friend constexpr X operator |(X, X); \
123 friend X& operator |=(X&, X); \
124 friend constexpr bool operator &(X, X);
129 #define GR_CT_MAX(a, b) (((b) < (a)) ? (a) : (b))
130 #define GR_CT_MIN(a, b) (((b) < (a)) ? (b) : (a))
135 static inline int32_t GrIDivRoundUp(
int x,
int y) {
137 return (x + (y-1)) / y;
139 static inline uint32_t GrUIDivRoundUp(uint32_t x, uint32_t y) {
140 return (x + (y-1)) / y;
142 static inline size_t GrSizeDivRoundUp(
size_t x,
size_t y) {
143 return (x + (y-1)) / y;
147 #define GR_CT_DIV_ROUND_UP(X, Y) (((X) + ((Y)-1)) / (Y))
152 static inline uint32_t GrUIAlignUp(uint32_t x, uint32_t alignment) {
153 return GrUIDivRoundUp(x, alignment) * alignment;
155 static inline size_t GrSizeAlignUp(
size_t x,
size_t alignment) {
156 return GrSizeDivRoundUp(x, alignment) * alignment;
160 #define GR_CT_ALIGN_UP(X, A) (GR_CT_DIV_ROUND_UP((X),(A)) * (A))
165 static inline uint32_t GrUIAlignUpPad(uint32_t x, uint32_t alignment) {
166 return (alignment - x % alignment) % alignment;
168 static inline size_t GrSizeAlignUpPad(
size_t x,
size_t alignment) {
169 return (alignment - x % alignment) % alignment;
175 static inline uint32_t GrUIAlignDown(uint32_t x, uint32_t alignment) {
176 return (x / alignment) * alignment;
178 static inline size_t GrSizeAlignDown(
size_t x, uint32_t alignment) {
179 return (x / alignment) * alignment;
192 kLast_GrBackend = kVulkan_GrBackend
194 const int kBackendCount = kLast_GrBackend + 1;
201 typedef intptr_t GrBackendContext;
213 static inline GrAA GrBoolToAA(
bool aa) {
return aa ? GrAA::kYes : GrAA::kNo; }
220 enum class GrPrimitiveType {
229 static constexpr
int kNumGrPrimitiveTypes = (int) GrPrimitiveType::kLinesAdjacency + 1;
231 static constexpr
bool GrIsPrimTypeLines(GrPrimitiveType type) {
232 return GrPrimitiveType::kLines == type ||
233 GrPrimitiveType::kLineStrip == type ||
234 GrPrimitiveType::kLinesAdjacency == type;
237 static constexpr
bool GrIsPrimTypeTris(GrPrimitiveType type) {
238 return GrPrimitiveType::kTriangles == type ||
239 GrPrimitiveType::kTriangleStrip == type ||
240 GrPrimitiveType::kTriangleFan == type;
243 static constexpr
bool GrPrimTypeRequiresGeometryShaderSupport(GrPrimitiveType type) {
244 return GrPrimitiveType::kLinesAdjacency == type;
256 kLast_GrMaskFormat = kARGB_GrMaskFormat
258 static const int kMaskFormatCount = kLast_GrMaskFormat + 1;
263 static inline int GrMaskFormatBytesPerPixel(GrMaskFormat format) {
264 SkASSERT(format < kMaskFormatCount);
268 static const int sBytesPerPixel[] = { 1, 2, 4 };
269 static_assert(SK_ARRAY_COUNT(sBytesPerPixel) == kMaskFormatCount,
"array_size_mismatch");
270 static_assert(kA8_GrMaskFormat == 0,
"enum_order_dependency");
271 static_assert(kA565_GrMaskFormat == 1,
"enum_order_dependency");
272 static_assert(kARGB_GrMaskFormat == 2,
"enum_order_dependency");
274 return sBytesPerPixel[(int) format];
281 kUnknown_GrPixelConfig,
282 kAlpha_8_GrPixelConfig,
283 kGray_8_GrPixelConfig,
284 kRGB_565_GrPixelConfig,
288 kRGBA_4444_GrPixelConfig,
292 kRGBA_8888_GrPixelConfig,
296 kBGRA_8888_GrPixelConfig,
300 kSRGBA_8888_GrPixelConfig,
304 kSBGRA_8888_GrPixelConfig,
308 kRGBA_8888_sint_GrPixelConfig,
313 kRGBA_float_GrPixelConfig,
317 kRG_float_GrPixelConfig,
322 kAlpha_half_GrPixelConfig,
327 kRGBA_half_GrPixelConfig,
329 kLast_GrPixelConfig = kRGBA_half_GrPixelConfig
331 static const int kGrPixelConfigCnt = kLast_GrPixelConfig + 1;
334 #ifndef SK_CPU_LENDIAN
335 #error "Skia gpu currently assumes little endian"
337 #if SK_PMCOLOR_BYTE_ORDER(B,G,R,A)
338 static const GrPixelConfig kSkia8888_GrPixelConfig = kBGRA_8888_GrPixelConfig;
339 #elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A)
340 static const GrPixelConfig kSkia8888_GrPixelConfig = kRGBA_8888_GrPixelConfig;
342 #error "SK_*32_SHIFT values must correspond to GL_BGRA or GL_RGBA format."
346 static inline bool GrPixelConfigIs8888Unorm(GrPixelConfig config) {
348 case kRGBA_8888_GrPixelConfig:
349 case kBGRA_8888_GrPixelConfig:
350 case kSRGBA_8888_GrPixelConfig:
351 case kSBGRA_8888_GrPixelConfig:
353 case kUnknown_GrPixelConfig:
354 case kAlpha_8_GrPixelConfig:
355 case kGray_8_GrPixelConfig:
356 case kRGB_565_GrPixelConfig:
357 case kRGBA_4444_GrPixelConfig:
358 case kRGBA_8888_sint_GrPixelConfig:
359 case kRGBA_float_GrPixelConfig:
360 case kRG_float_GrPixelConfig:
361 case kAlpha_half_GrPixelConfig:
362 case kRGBA_half_GrPixelConfig:
365 SkFAIL(
"Invalid pixel config");
371 static inline bool GrPixelConfigIsSRGB(GrPixelConfig config) {
373 case kSRGBA_8888_GrPixelConfig:
374 case kSBGRA_8888_GrPixelConfig:
376 case kUnknown_GrPixelConfig:
377 case kAlpha_8_GrPixelConfig:
378 case kGray_8_GrPixelConfig:
379 case kRGB_565_GrPixelConfig:
380 case kRGBA_4444_GrPixelConfig:
381 case kRGBA_8888_GrPixelConfig:
382 case kBGRA_8888_GrPixelConfig:
383 case kRGBA_8888_sint_GrPixelConfig:
384 case kRGBA_float_GrPixelConfig:
385 case kRG_float_GrPixelConfig:
386 case kAlpha_half_GrPixelConfig:
387 case kRGBA_half_GrPixelConfig:
390 SkFAIL(
"Invalid pixel config");
396 static inline GrPixelConfig GrPixelConfigSwapRAndB(GrPixelConfig config) {
398 case kBGRA_8888_GrPixelConfig:
399 return kRGBA_8888_GrPixelConfig;
400 case kRGBA_8888_GrPixelConfig:
401 return kBGRA_8888_GrPixelConfig;
402 case kSBGRA_8888_GrPixelConfig:
403 return kSRGBA_8888_GrPixelConfig;
404 case kSRGBA_8888_GrPixelConfig:
405 return kSBGRA_8888_GrPixelConfig;
406 case kUnknown_GrPixelConfig:
407 case kAlpha_8_GrPixelConfig:
408 case kGray_8_GrPixelConfig:
409 case kRGB_565_GrPixelConfig:
410 case kRGBA_4444_GrPixelConfig:
411 case kRGBA_8888_sint_GrPixelConfig:
412 case kRGBA_float_GrPixelConfig:
413 case kRG_float_GrPixelConfig:
414 case kAlpha_half_GrPixelConfig:
415 case kRGBA_half_GrPixelConfig:
416 return kUnknown_GrPixelConfig;
418 SkFAIL(
"Invalid pixel config");
419 return kUnknown_GrPixelConfig;
422 static inline size_t GrBytesPerPixel(GrPixelConfig config) {
424 case kAlpha_8_GrPixelConfig:
425 case kGray_8_GrPixelConfig:
427 case kRGB_565_GrPixelConfig:
428 case kRGBA_4444_GrPixelConfig:
429 case kAlpha_half_GrPixelConfig:
431 case kRGBA_8888_GrPixelConfig:
432 case kBGRA_8888_GrPixelConfig:
433 case kSRGBA_8888_GrPixelConfig:
434 case kSBGRA_8888_GrPixelConfig:
435 case kRGBA_8888_sint_GrPixelConfig:
437 case kRGBA_half_GrPixelConfig:
439 case kRGBA_float_GrPixelConfig:
441 case kRG_float_GrPixelConfig:
443 case kUnknown_GrPixelConfig:
446 SkFAIL(
"Invalid pixel config");
450 static inline bool GrPixelConfigIsOpaque(GrPixelConfig config) {
452 case kRGB_565_GrPixelConfig:
453 case kGray_8_GrPixelConfig:
454 case kRG_float_GrPixelConfig:
456 case kAlpha_8_GrPixelConfig:
457 case kRGBA_4444_GrPixelConfig:
458 case kAlpha_half_GrPixelConfig:
459 case kRGBA_8888_GrPixelConfig:
460 case kBGRA_8888_GrPixelConfig:
461 case kSRGBA_8888_GrPixelConfig:
462 case kSBGRA_8888_GrPixelConfig:
463 case kRGBA_8888_sint_GrPixelConfig:
464 case kRGBA_half_GrPixelConfig:
465 case kRGBA_float_GrPixelConfig:
466 case kUnknown_GrPixelConfig:
469 SkFAIL(
"Invalid pixel config");
473 static inline bool GrPixelConfigIsAlphaOnly(GrPixelConfig config) {
475 case kAlpha_8_GrPixelConfig:
476 case kAlpha_half_GrPixelConfig:
478 case kUnknown_GrPixelConfig:
479 case kGray_8_GrPixelConfig:
480 case kRGB_565_GrPixelConfig:
481 case kRGBA_4444_GrPixelConfig:
482 case kRGBA_8888_GrPixelConfig:
483 case kBGRA_8888_GrPixelConfig:
484 case kSRGBA_8888_GrPixelConfig:
485 case kSBGRA_8888_GrPixelConfig:
486 case kRGBA_8888_sint_GrPixelConfig:
487 case kRGBA_float_GrPixelConfig:
488 case kRG_float_GrPixelConfig:
489 case kRGBA_half_GrPixelConfig:
492 SkFAIL(
"Invalid pixel config.");
496 static inline bool GrPixelConfigIsFloatingPoint(GrPixelConfig config) {
498 case kRGBA_float_GrPixelConfig:
499 case kRG_float_GrPixelConfig:
500 case kAlpha_half_GrPixelConfig:
501 case kRGBA_half_GrPixelConfig:
503 case kUnknown_GrPixelConfig:
504 case kAlpha_8_GrPixelConfig:
505 case kGray_8_GrPixelConfig:
506 case kRGB_565_GrPixelConfig:
507 case kRGBA_4444_GrPixelConfig:
508 case kRGBA_8888_GrPixelConfig:
509 case kBGRA_8888_GrPixelConfig:
510 case kSRGBA_8888_GrPixelConfig:
511 case kSBGRA_8888_GrPixelConfig:
512 case kRGBA_8888_sint_GrPixelConfig:
515 SkFAIL(
"Invalid pixel config");
519 static inline bool GrPixelConfigIsSint(GrPixelConfig config) {
520 return config == kRGBA_8888_sint_GrPixelConfig;
523 static inline bool GrPixelConfigIsUnorm(GrPixelConfig config) {
525 case kAlpha_8_GrPixelConfig:
526 case kGray_8_GrPixelConfig:
527 case kRGB_565_GrPixelConfig:
528 case kRGBA_4444_GrPixelConfig:
529 case kRGBA_8888_GrPixelConfig:
530 case kBGRA_8888_GrPixelConfig:
531 case kSRGBA_8888_GrPixelConfig:
532 case kSBGRA_8888_GrPixelConfig:
534 case kUnknown_GrPixelConfig:
535 case kAlpha_half_GrPixelConfig:
536 case kRGBA_8888_sint_GrPixelConfig:
537 case kRGBA_float_GrPixelConfig:
538 case kRG_float_GrPixelConfig:
539 case kRGBA_half_GrPixelConfig:
542 SkFAIL(
"Invalid pixel config.");
549 enum GrSurfaceFlags {
550 kNone_GrSurfaceFlags = 0x0,
555 kRenderTarget_GrSurfaceFlag = 0x1,
560 kPerformInitialClear_GrSurfaceFlag = 0x2
563 GR_MAKE_BITFIELD_OPS(GrSurfaceFlags)
566 typedef intptr_t GrBackendObject;
575 enum GrSurfaceOrigin {
576 kDefault_GrSurfaceOrigin,
577 kTopLeft_GrSurfaceOrigin,
578 kBottomLeft_GrSurfaceOrigin,
591 :
fFlags(kNone_GrSurfaceFlags)
592 ,
fOrigin(kDefault_GrSurfaceOrigin)
595 ,
fConfig(kUnknown_GrPixelConfig)
637 enum GrWrapOwnership {
639 kBorrow_GrWrapOwnership,
642 kAdopt_GrWrapOwnership,
666 enum GrBackendTextureFlags {
670 kNone_GrBackendTextureFlag = 0,
675 kRenderTarget_GrBackendTextureFlag = kRenderTarget_GrSurfaceFlag,
677 GR_MAKE_BITFIELD_OPS(GrBackendTextureFlags)
680 GrBackendTextureDesc() { memset(
this, 0,
sizeof(*
this)); }
681 GrBackendTextureFlags fFlags;
682 GrSurfaceOrigin fOrigin;
685 GrPixelConfig fConfig;
715 GrPixelConfig fConfig;
716 GrSurfaceOrigin fOrigin;
738 enum GrGLBackendState {
739 kRenderTarget_GrGLBackendState = 1 << 0,
740 kTextureBinding_GrGLBackendState = 1 << 1,
742 kView_GrGLBackendState = 1 << 2,
743 kBlend_GrGLBackendState = 1 << 3,
744 kMSAAEnable_GrGLBackendState = 1 << 4,
745 kVertex_GrGLBackendState = 1 << 5,
746 kStencil_GrGLBackendState = 1 << 6,
747 kPixelStore_GrGLBackendState = 1 << 7,
748 kProgram_GrGLBackendState = 1 << 8,
749 kFixedFunction_GrGLBackendState = 1 << 9,
750 kMisc_GrGLBackendState = 1 << 10,
751 kPathRendering_GrGLBackendState = 1 << 11,
752 kALL_GrGLBackendState = 0xffff
758 static const uint32_t kAll_GrBackendState = 0xffffffff;
int fWidth
Width of the texture.
Definition: GrTypes.h:602
Definition: GrTypes.h:679
int fSampleCnt
The number of samples per pixel.
Definition: GrTypes.h:721
GrBackendObject fTextureHandle
Handle to the 3D API object.
Definition: GrTypes.h:696
Describes a surface to be created.
Definition: GrTypes.h:589
int fHeight
Height of the texture.
Definition: GrTypes.h:603
Wraps a C++11 enum that we use as a bitfield, and enables a limited amount of masking with type safet...
Definition: GrTypes.h:60
Gr can wrap an existing render target created by the client in the 3D API with a GrRenderTarget objec...
Definition: GrTypes.h:711
int fStencilBits
Number of bits of stencil per-pixel.
Definition: GrTypes.h:725
GrPixelConfig fConfig
Format of source data of the texture.
Definition: GrTypes.h:609
Definition: GrTypes.h:581
bool fIsMipMapped
Indicates if the texture has mipmaps.
Definition: GrTypes.h:619
int fSampleCnt
The number of samples per pixel or 0 to disable full scene AA.
Definition: GrTypes.h:618
int fSampleCnt
If the render target flag is set and sample count is greater than 0 then Gr will create an MSAA buffe...
Definition: GrTypes.h:690
GrBackendObject fRenderTargetHandle
Handle to the 3D API object.
Definition: GrTypes.h:731
GrSurfaceOrigin fOrigin
origin of the texture
Definition: GrTypes.h:601
GrSurfaceFlags fFlags
bitfield of TextureFlags
Definition: GrTypes.h:600