1 2 /* 3 * Copyright 2010 Google Inc. 4 * 5 * Use of this source code is governed by a BSD-style license that can be 6 * found in the LICENSE file. 7 */ 8 9 10 11 #ifndef GrTypes_DEFINED 12 #define GrTypes_DEFINED 13 14 #include "SkTypes.h" 15 #include "GrConfig.h" 16 #include "SkMath.h" 17 18 //#define SK_SUPPORT_LEGACY_GRTYPES 19 20 //////////////////////////////////////////////////////////////////////////////// 21 22 /** 23 * Defines overloaded bitwise operators to make it easier to use an enum as a 24 * bitfield. 25 */ 26 #define GR_MAKE_BITFIELD_OPS(X) \ 27 inline X operator | (X a, X b) { \ 28 return (X) (+a | +b); \ 29 } \ 30 \ 31 inline X operator & (X a, X b) { \ 32 return (X) (+a & +b); \ 33 } \ 34 template <typename T> \ 35 inline X operator & (T a, X b) { \ 36 return (X) (+a & +b); \ 37 } \ 38 template <typename T> \ 39 inline X operator & (X a, T b) { \ 40 return (X) (+a & +b); \ 41 } \ 42 43 #define GR_DECL_BITFIELD_OPS_FRIENDS(X) \ 44 friend X operator | (X a, X b); \ 45 \ 46 friend X operator & (X a, X b); \ 47 \ 48 template <typename T> \ 49 friend X operator & (T a, X b); \ 50 \ 51 template <typename T> \ 52 friend X operator & (X a, T b); \ 53 //////////////////////////////////////////////////////////////////////////////// 54 55 #ifdef SK_SUPPORT_LEGACY_GRTYPES 56 57 /** 58 * Macro to round n up to the next multiple of 4, or return it unchanged if 59 * n is already a multiple of 4 60 */ 61 #define GrALIGN4(n) SkAlign4(n) 62 #define GrIsALIGN4(n) SkIsAlign4(n) 63 64 template <typename T> const T& GrMin(const T& a, const T& b) { 65 return (a < b) ? a : b; 66 } 67 68 template <typename T> const T& GrMax(const T& a, const T& b) { 69 return (b < a) ? a : b; 70 } 71 72 /** 73 * Count elements in an array 74 */ 75 #define GR_ARRAY_COUNT(array) SK_ARRAY_COUNT(array) 76 77 /** 78 * 16.16 fixed point type 79 */ 80 typedef int32_t GrFixed; 81 82 #ifdef SK_DEBUG 83 84 static inline int16_t GrToS16(intptr_t x) { 85 SkASSERT((int16_t)x == x); 86 return (int16_t)x; 87 } 88 89 #else 90 91 #define GrToS16(x) x 92 93 #endif 94 95 #endif 96 97 // compile time versions of min/max 98 #define GR_CT_MAX(a, b) (((b) < (a)) ? (a) : (b)) 99 #define GR_CT_MIN(a, b) (((b) < (a)) ? (b) : (a)) 100 101 /** 102 * divide, rounding up 103 */ 104 static inline int32_t GrIDivRoundUp(int x, int y) { 105 SkASSERT(y > 0); 106 return (x + (y-1)) / y; 107 } 108 static inline uint32_t GrUIDivRoundUp(uint32_t x, uint32_t y) { 109 return (x + (y-1)) / y; 110 } 111 static inline size_t GrSizeDivRoundUp(size_t x, size_t y) { 112 return (x + (y-1)) / y; 113 } 114 115 // compile time, evaluates Y multiple times 116 #define GR_CT_DIV_ROUND_UP(X, Y) (((X) + ((Y)-1)) / (Y)) 117 118 /** 119 * align up 120 */ 121 static inline uint32_t GrUIAlignUp(uint32_t x, uint32_t alignment) { 122 return GrUIDivRoundUp(x, alignment) * alignment; 123 } 124 static inline size_t GrSizeAlignUp(size_t x, size_t alignment) { 125 return GrSizeDivRoundUp(x, alignment) * alignment; 126 } 127 128 // compile time, evaluates A multiple times 129 #define GR_CT_ALIGN_UP(X, A) (GR_CT_DIV_ROUND_UP((X),(A)) * (A)) 130 131 /** 132 * amount of pad needed to align up 133 */ 134 static inline uint32_t GrUIAlignUpPad(uint32_t x, uint32_t alignment) { 135 return (alignment - x % alignment) % alignment; 136 } 137 static inline size_t GrSizeAlignUpPad(size_t x, size_t alignment) { 138 return (alignment - x % alignment) % alignment; 139 } 140 141 /** 142 * align down 143 */ 144 static inline uint32_t GrUIAlignDown(uint32_t x, uint32_t alignment) { 145 return (x / alignment) * alignment; 146 } 147 static inline size_t GrSizeAlignDown(size_t x, uint32_t alignment) { 148 return (x / alignment) * alignment; 149 } 150 151 /////////////////////////////////////////////////////////////////////////////// 152 153 /** 154 * Return the next power of 2 >= n. 155 */ 156 static inline uint32_t GrNextPow2(uint32_t n) { 157 return n ? (1 << (32 - SkCLZ(n - 1))) : 1; 158 } 159 160 static inline int GrNextPow2(int n) { 161 SkASSERT(n >= 0); // this impl only works for non-neg. 162 return n ? (1 << (32 - SkCLZ(n - 1))) : 1; 163 } 164 165 /////////////////////////////////////////////////////////////////////////////// 166 167 /** 168 * Possible 3D APIs that may be used by Ganesh. 169 */ 170 enum GrBackend { 171 kOpenGL_GrBackend, 172 }; 173 174 /** 175 * Backend-specific 3D context handle 176 * GrGLInterface* for OpenGL. If NULL will use the default GL interface. 177 */ 178 typedef intptr_t GrBackendContext; 179 180 /////////////////////////////////////////////////////////////////////////////// 181 182 /** 183 * Geometric primitives used for drawing. 184 */ 185 enum GrPrimitiveType { 186 kTriangles_GrPrimitiveType, 187 kTriangleStrip_GrPrimitiveType, 188 kTriangleFan_GrPrimitiveType, 189 kPoints_GrPrimitiveType, 190 kLines_GrPrimitiveType, // 1 pix wide only 191 kLineStrip_GrPrimitiveType // 1 pix wide only 192 }; 193 194 static inline bool GrIsPrimTypeLines(GrPrimitiveType type) { 195 return kLines_GrPrimitiveType == type || kLineStrip_GrPrimitiveType == type; 196 } 197 198 static inline bool GrIsPrimTypeTris(GrPrimitiveType type) { 199 return kTriangles_GrPrimitiveType == type || 200 kTriangleStrip_GrPrimitiveType == type || 201 kTriangleFan_GrPrimitiveType == type; 202 } 203 204 /** 205 * Coeffecients for alpha-blending. 206 */ 207 enum GrBlendCoeff { 208 kInvalid_GrBlendCoeff = -1, 209 210 kZero_GrBlendCoeff, //<! 0 211 kOne_GrBlendCoeff, //<! 1 212 kSC_GrBlendCoeff, //<! src color 213 kISC_GrBlendCoeff, //<! one minus src color 214 kDC_GrBlendCoeff, //<! dst color 215 kIDC_GrBlendCoeff, //<! one minus dst color 216 kSA_GrBlendCoeff, //<! src alpha 217 kISA_GrBlendCoeff, //<! one minus src alpha 218 kDA_GrBlendCoeff, //<! dst alpha 219 kIDA_GrBlendCoeff, //<! one minus dst alpha 220 kConstC_GrBlendCoeff, //<! constant color 221 kIConstC_GrBlendCoeff, //<! one minus constant color 222 kConstA_GrBlendCoeff, //<! constant color alpha 223 kIConstA_GrBlendCoeff, //<! one minus constant color alpha 224 225 kPublicGrBlendCoeffCount 226 }; 227 228 /** 229 * Formats for masks, used by the font cache. 230 * Important that these are 0-based. 231 */ 232 enum GrMaskFormat { 233 kA8_GrMaskFormat, //!< 1-byte per pixel 234 kA565_GrMaskFormat, //!< 2-bytes per pixel 235 kA888_GrMaskFormat, //!< 4-bytes per pixel 236 kARGB_GrMaskFormat, //!< 4-bytes per pixel, color format 237 238 kLast_GrMaskFormat = kARGB_GrMaskFormat 239 }; 240 static const int kMaskFormatCount = kLast_GrMaskFormat + 1; 241 242 /** 243 * Return the number of bytes-per-pixel for the specified mask format. 244 */ 245 static inline int GrMaskFormatBytesPerPixel(GrMaskFormat format) { 246 SkASSERT((unsigned)format <= 3); 247 // kA8 (0) -> 1 248 // kA565 (1) -> 2 249 // kA888 (2) -> 4 250 // kARGB (3) -> 4 251 static const int sBytesPerPixel[] = { 1, 2, 4, 4 }; 252 SK_COMPILE_ASSERT(SK_ARRAY_COUNT(sBytesPerPixel) == kMaskFormatCount, array_size_mismatch); 253 254 return sBytesPerPixel[(int) format]; 255 } 256 257 /** 258 * Pixel configurations. 259 */ 260 enum GrPixelConfig { 261 kUnknown_GrPixelConfig, 262 kAlpha_8_GrPixelConfig, 263 kIndex_8_GrPixelConfig, 264 kRGB_565_GrPixelConfig, 265 /** 266 * Premultiplied 267 */ 268 kRGBA_4444_GrPixelConfig, 269 /** 270 * Premultiplied. Byte order is r,g,b,a. 271 */ 272 kRGBA_8888_GrPixelConfig, 273 /** 274 * Premultiplied. Byte order is b,g,r,a. 275 */ 276 kBGRA_8888_GrPixelConfig, 277 /** 278 * ETC1 Compressed Data 279 */ 280 kETC1_GrPixelConfig, 281 /** 282 * LATC/RGTC/3Dc/BC4 Compressed Data 283 */ 284 kLATC_GrPixelConfig, 285 /** 286 * R11 EAC Compressed Data 287 * (Corresponds to section C.3.5 of the OpenGL 4.4 core profile spec) 288 */ 289 kR11_EAC_GrPixelConfig, 290 291 /** 292 * 12x12 ASTC Compressed Data 293 * ASTC stands for Adaptive Scalable Texture Compression. It is a technique 294 * that allows for a lot of customization in the compressed representataion 295 * of a block. The only thing fixed in the representation is the block size, 296 * which means that a texture that contains ASTC data must be treated as 297 * having RGBA values. However, there are single-channel encodings which set 298 * the alpha to opaque and all three RGB channels equal effectively making the 299 * compression format a single channel such as R11 EAC and LATC. 300 */ 301 kASTC_12x12_GrPixelConfig, 302 303 /** 304 * Byte order is r, g, b, a. This color format is 32 bits per channel 305 */ 306 kRGBA_float_GrPixelConfig, 307 kLast_GrPixelConfig = kRGBA_float_GrPixelConfig 308 }; 309 static const int kGrPixelConfigCnt = kLast_GrPixelConfig + 1; 310 311 // Aliases for pixel configs that match skia's byte order. 312 #ifndef SK_CPU_LENDIAN 313 #error "Skia gpu currently assumes little endian" 314 #endif 315 #if SK_PMCOLOR_BYTE_ORDER(B,G,R,A) 316 static const GrPixelConfig kSkia8888_GrPixelConfig = kBGRA_8888_GrPixelConfig; 317 #elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A) 318 static const GrPixelConfig kSkia8888_GrPixelConfig = kRGBA_8888_GrPixelConfig; 319 #else 320 #error "SK_*32_SHIFT values must correspond to GL_BGRA or GL_RGBA format." 321 #endif 322 323 // Returns true if the pixel config is a GPU-specific compressed format 324 // representation. 325 static inline bool GrPixelConfigIsCompressed(GrPixelConfig config) { 326 switch (config) { 327 case kIndex_8_GrPixelConfig: 328 case kETC1_GrPixelConfig: 329 case kLATC_GrPixelConfig: 330 case kR11_EAC_GrPixelConfig: 331 case kASTC_12x12_GrPixelConfig: 332 return true; 333 default: 334 return false; 335 } 336 } 337 338 // Returns true if the pixel config is 32 bits per pixel 339 static inline bool GrPixelConfigIs8888(GrPixelConfig config) { 340 switch (config) { 341 case kRGBA_8888_GrPixelConfig: 342 case kBGRA_8888_GrPixelConfig: 343 return true; 344 default: 345 return false; 346 } 347 } 348 349 // Takes a config and returns the equivalent config with the R and B order 350 // swapped if such a config exists. Otherwise, kUnknown_GrPixelConfig 351 static inline GrPixelConfig GrPixelConfigSwapRAndB(GrPixelConfig config) { 352 switch (config) { 353 case kBGRA_8888_GrPixelConfig: 354 return kRGBA_8888_GrPixelConfig; 355 case kRGBA_8888_GrPixelConfig: 356 return kBGRA_8888_GrPixelConfig; 357 default: 358 return kUnknown_GrPixelConfig; 359 } 360 } 361 362 static inline size_t GrBytesPerPixel(GrPixelConfig config) { 363 SkASSERT(!GrPixelConfigIsCompressed(config)); 364 switch (config) { 365 case kAlpha_8_GrPixelConfig: 366 return 1; 367 case kRGB_565_GrPixelConfig: 368 case kRGBA_4444_GrPixelConfig: 369 return 2; 370 case kRGBA_8888_GrPixelConfig: 371 case kBGRA_8888_GrPixelConfig: 372 return 4; 373 case kRGBA_float_GrPixelConfig: 374 return 16; 375 default: 376 return 0; 377 } 378 } 379 380 static inline size_t GrUnpackAlignment(GrPixelConfig config) { 381 SkASSERT(!GrPixelConfigIsCompressed(config)); 382 switch (config) { 383 case kAlpha_8_GrPixelConfig: 384 return 1; 385 case kRGB_565_GrPixelConfig: 386 case kRGBA_4444_GrPixelConfig: 387 return 2; 388 case kRGBA_8888_GrPixelConfig: 389 case kBGRA_8888_GrPixelConfig: 390 case kRGBA_float_GrPixelConfig: 391 return 4; 392 default: 393 return 0; 394 } 395 } 396 397 static inline bool GrPixelConfigIsOpaque(GrPixelConfig config) { 398 switch (config) { 399 case kETC1_GrPixelConfig: 400 case kRGB_565_GrPixelConfig: 401 return true; 402 default: 403 return false; 404 } 405 } 406 407 static inline bool GrPixelConfigIsAlphaOnly(GrPixelConfig config) { 408 switch (config) { 409 case kR11_EAC_GrPixelConfig: 410 case kLATC_GrPixelConfig: 411 case kASTC_12x12_GrPixelConfig: 412 case kAlpha_8_GrPixelConfig: 413 return true; 414 default: 415 return false; 416 } 417 } 418 419 /** 420 * Optional bitfield flags that can be passed to createTexture. 421 */ 422 enum GrTextureFlags { 423 kNone_GrTextureFlags = 0x0, 424 /** 425 * Creates a texture that can be rendered to as a GrRenderTarget. Use 426 * GrTexture::asRenderTarget() to access. 427 */ 428 kRenderTarget_GrTextureFlagBit = 0x1, 429 /** 430 * By default all render targets have an associated stencil buffer that 431 * may be required for path filling. This flag overrides stencil buffer 432 * creation. 433 * MAKE THIS PRIVATE? 434 */ 435 kNoStencil_GrTextureFlagBit = 0x2, 436 /** 437 * Hint that the CPU may modify this texture after creation. 438 */ 439 kDynamicUpdate_GrTextureFlagBit = 0x4, 440 /** 441 * Indicates that all allocations (color buffer, FBO completeness, etc) 442 * should be verified. 443 */ 444 kCheckAllocation_GrTextureFlagBit = 0x8, 445 446 kDummy_GrTextureFlagBit, 447 kLastPublic_GrTextureFlagBit = kDummy_GrTextureFlagBit-1, 448 }; 449 450 GR_MAKE_BITFIELD_OPS(GrTextureFlags) 451 452 /** 453 * Some textures will be stored such that the upper and left edges of the content meet at the 454 * the origin (in texture coord space) and for other textures the lower and left edges meet at 455 * the origin. kDefault_GrSurfaceOrigin sets textures to TopLeft, and render targets 456 * to BottomLeft. 457 */ 458 459 enum GrSurfaceOrigin { 460 kDefault_GrSurfaceOrigin, // DEPRECATED; to be removed 461 kTopLeft_GrSurfaceOrigin, 462 kBottomLeft_GrSurfaceOrigin, 463 }; 464 465 /** 466 * Describes a texture to be created. 467 */ 468 struct GrTextureDesc { 469 GrTextureDesc() 470 : fFlags(kNone_GrTextureFlags) 471 , fOrigin(kDefault_GrSurfaceOrigin) 472 , fWidth(0) 473 , fHeight(0) 474 , fConfig(kUnknown_GrPixelConfig) 475 , fSampleCnt(0) { 476 } 477 478 GrTextureFlags fFlags; //!< bitfield of TextureFlags 479 GrSurfaceOrigin fOrigin; //!< origin of the texture 480 int fWidth; //!< Width of the texture 481 int fHeight; //!< Height of the texture 482 483 /** 484 * Format of source data of the texture. Not guaranteed to be the same as 485 * internal format used by 3D API. 486 */ 487 GrPixelConfig fConfig; 488 489 /** 490 * The number of samples per pixel or 0 to disable full scene AA. This only 491 * applies if the kRenderTarget_GrTextureFlagBit is set. The actual number 492 * of samples may not exactly match the request. The request will be rounded 493 * up to the next supported sample count, or down if it is larger than the 494 * max supported count. 495 */ 496 int fSampleCnt; 497 }; 498 499 /** 500 * GrCacheID is used create and find cached GrResources (e.g. GrTextures). The ID has two parts: 501 * the domain and the key. Domains simply allow multiple clients to use 0-based indices as their 502 * cache key without colliding. The key uniquely identifies a GrResource within the domain. 503 * Users of the cache must obtain a domain via GenerateDomain(). 504 */ 505 struct GrCacheID { 506 public: 507 typedef uint8_t Domain; 508 509 struct Key { 510 union { 511 uint8_t fData8[16]; 512 uint32_t fData32[4]; 513 uint64_t fData64[2]; 514 }; 515 }; 516 517 /** 518 * A default cache ID is invalid; a set method must be called before the object is used. 519 */ 520 GrCacheID() { fDomain = kInvalid_Domain; } 521 522 /** 523 * Initialize the cache ID to a domain and key. 524 */ 525 GrCacheID(Domain domain, const Key& key) { 526 SkASSERT(kInvalid_Domain != domain); 527 this->reset(domain, key); 528 } 529 530 void reset(Domain domain, const Key& key) { 531 fDomain = domain; 532 memcpy(&fKey, &key, sizeof(Key)); 533 } 534 535 /** Has this been initialized to a valid domain */ 536 bool isValid() const { return kInvalid_Domain != fDomain; } 537 538 const Key& getKey() const { SkASSERT(this->isValid()); return fKey; } 539 Domain getDomain() const { SkASSERT(this->isValid()); return fDomain; } 540 541 /** Creates a new unique ID domain. */ 542 static Domain GenerateDomain(); 543 544 private: 545 Key fKey; 546 Domain fDomain; 547 548 static const Domain kInvalid_Domain = 0; 549 }; 550 551 /** 552 * Clips are composed from these objects. 553 */ 554 enum GrClipType { 555 kRect_ClipType, 556 kPath_ClipType 557 }; 558 559 /////////////////////////////////////////////////////////////////////////////// 560 561 // opaque type for 3D API object handles 562 typedef intptr_t GrBackendObject; 563 564 /** 565 * Gr can wrap an existing texture created by the client with a GrTexture 566 * object. The client is responsible for ensuring that the texture lives at 567 * least as long as the GrTexture object wrapping it. We require the client to 568 * explicitly provide information about the texture, such as width, height, 569 * and pixel config, rather than querying the 3D APIfor these values. We expect 570 * these to be immutable even if the 3D API doesn't require this (OpenGL). 571 * 572 * Textures that are also render targets are supported as well. Gr will manage 573 * any ancillary 3D API (stencil buffer, FBO id, etc) objects necessary for 574 * Gr to draw into the render target. To access the render target object 575 * call GrTexture::asRenderTarget(). 576 * 577 * If in addition to the render target flag, the caller also specifies a sample 578 * count Gr will create an MSAA buffer that resolves into the texture. Gr auto- 579 * resolves when it reads from the texture. The client can explictly resolve 580 * using the GrRenderTarget interface. 581 * 582 * Note: These flags currently form a subset of GrTexture's flags. 583 */ 584 585 enum GrBackendTextureFlags { 586 /** 587 * No flags enabled 588 */ 589 kNone_GrBackendTextureFlag = kNone_GrTextureFlags, 590 /** 591 * Indicates that the texture is also a render target, and thus should have 592 * a GrRenderTarget object. 593 * 594 * D3D (future): client must have created the texture with flags that allow 595 * it to be used as a render target. 596 */ 597 kRenderTarget_GrBackendTextureFlag = kRenderTarget_GrTextureFlagBit, 598 }; 599 GR_MAKE_BITFIELD_OPS(GrBackendTextureFlags) 600 601 struct GrBackendTextureDesc { 602 GrBackendTextureDesc() { memset(this, 0, sizeof(*this)); } 603 GrBackendTextureFlags fFlags; 604 GrSurfaceOrigin fOrigin; 605 int fWidth; //<! width in pixels 606 int fHeight; //<! height in pixels 607 GrPixelConfig fConfig; //<! color format 608 /** 609 * If the render target flag is set and sample count is greater than 0 610 * then Gr will create an MSAA buffer that resolves to the texture. 611 */ 612 int fSampleCnt; 613 /** 614 * Handle to the 3D API object. 615 * OpenGL: Texture ID. 616 */ 617 GrBackendObject fTextureHandle; 618 }; 619 620 /////////////////////////////////////////////////////////////////////////////// 621 622 /** 623 * Gr can wrap an existing render target created by the client in the 3D API 624 * with a GrRenderTarget object. The client is responsible for ensuring that the 625 * underlying 3D API object lives at least as long as the GrRenderTarget object 626 * wrapping it. We require the client to explicitly provide information about 627 * the target, such as width, height, and pixel config rather than querying the 628 * 3D API for these values. We expect these properties to be immutable even if 629 * the 3D API doesn't require this (OpenGL). 630 */ 631 632 struct GrBackendRenderTargetDesc { 633 GrBackendRenderTargetDesc() { memset(this, 0, sizeof(*this)); } 634 int fWidth; //<! width in pixels 635 int fHeight; //<! height in pixels 636 GrPixelConfig fConfig; //<! color format 637 GrSurfaceOrigin fOrigin; //<! pixel origin 638 /** 639 * The number of samples per pixel. Gr uses this to influence decisions 640 * about applying other forms of anti-aliasing. 641 */ 642 int fSampleCnt; 643 /** 644 * Number of bits of stencil per-pixel. 645 */ 646 int fStencilBits; 647 /** 648 * Handle to the 3D API object. 649 * OpenGL: FBO ID 650 */ 651 GrBackendObject fRenderTargetHandle; 652 }; 653 654 /** 655 * The GrContext's cache of backend context state can be partially invalidated. 656 * These enums are specific to the GL backend and we'd add a new set for an alternative backend. 657 */ 658 enum GrGLBackendState { 659 kRenderTarget_GrGLBackendState = 1 << 0, 660 kTextureBinding_GrGLBackendState = 1 << 1, 661 // View state stands for scissor and viewport 662 kView_GrGLBackendState = 1 << 2, 663 kBlend_GrGLBackendState = 1 << 3, 664 kMSAAEnable_GrGLBackendState = 1 << 4, 665 kVertex_GrGLBackendState = 1 << 5, 666 kStencil_GrGLBackendState = 1 << 6, 667 kPixelStore_GrGLBackendState = 1 << 7, 668 kProgram_GrGLBackendState = 1 << 8, 669 kFixedFunction_GrGLBackendState = 1 << 9, 670 kMisc_GrGLBackendState = 1 << 10, 671 kPathRendering_GrGLBackendState = 1 << 11, 672 kALL_GrGLBackendState = 0xffff 673 }; 674 675 /** 676 * Returns the data size for the given compressed pixel config 677 */ 678 static inline size_t GrCompressedFormatDataSize(GrPixelConfig config, 679 int width, int height) { 680 SkASSERT(GrPixelConfigIsCompressed(config)); 681 static const int kGrIndex8TableSize = 256 * 4; // 4 == sizeof(GrColor) 682 683 switch (config) { 684 case kIndex_8_GrPixelConfig: 685 return width * height + kGrIndex8TableSize; 686 case kR11_EAC_GrPixelConfig: 687 case kLATC_GrPixelConfig: 688 case kETC1_GrPixelConfig: 689 SkASSERT((width & 3) == 0); 690 SkASSERT((height & 3) == 0); 691 return (width >> 2) * (height >> 2) * 8; 692 693 case kASTC_12x12_GrPixelConfig: 694 SkASSERT((width % 12) == 0); 695 SkASSERT((height % 12) == 0); 696 return (width / 12) * (height / 12) * 16; 697 698 default: 699 SkFAIL("Unknown compressed pixel config"); 700 return 4 * width * height; 701 } 702 } 703 704 /** 705 * This value translates to reseting all the context state for any backend. 706 */ 707 static const uint32_t kAll_GrBackendState = 0xffffffff; 708 709 /////////////////////////////////////////////////////////////////////////////// 710 711 #if GR_ALWAYS_ALLOCATE_ON_HEAP 712 #define GrAutoMallocBaseType SkAutoMalloc 713 #else 714 #define GrAutoMallocBaseType SkAutoSMalloc<S> 715 #endif 716 717 template <size_t S> class GrAutoMalloc : public GrAutoMallocBaseType { 718 public: 719 GrAutoMalloc() : INHERITED() {} 720 explicit GrAutoMalloc(size_t size) : INHERITED(size) {} 721 virtual ~GrAutoMalloc() {} 722 private: 723 typedef GrAutoMallocBaseType INHERITED; 724 }; 725 726 #undef GrAutoMallocBaseType 727 #endif 728