Home | History | Annotate | Download | only in gpu
      1 /*
      2  * Copyright 2010 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 GrTypes_DEFINED
      9 #define GrTypes_DEFINED
     10 
     11 #include "SkTypes.h"
     12 #include "GrConfig.h"
     13 #include "SkMath.h"
     14 
     15 ////////////////////////////////////////////////////////////////////////////////
     16 
     17 /**
     18  * Defines overloaded bitwise operators to make it easier to use an enum as a
     19  * bitfield.
     20  */
     21 #define GR_MAKE_BITFIELD_OPS(X) \
     22     inline X operator | (X a, X b) { \
     23         return (X) (+a | +b); \
     24     } \
     25     inline X& operator |= (X& a, X b) { \
     26         return (a = a | b); \
     27     } \
     28     \
     29     inline X operator & (X a, X b) { \
     30         return (X) (+a & +b); \
     31     } \
     32     template <typename T> \
     33     inline X operator & (T a, X b) { \
     34         return (X) (+a & +b); \
     35     } \
     36     template <typename T> \
     37     inline X operator & (X a, T b) { \
     38         return (X) (+a & +b); \
     39     } \
     40 
     41 #define GR_DECL_BITFIELD_OPS_FRIENDS(X) \
     42     friend X operator | (X a, X b); \
     43     friend X& operator |= (X& a, X b); \
     44     \
     45     friend X operator & (X a, X b); \
     46     \
     47     template <typename T> \
     48     friend X operator & (T a, X b); \
     49     \
     50     template <typename T> \
     51     friend X operator & (X a, T b); \
     52 ////////////////////////////////////////////////////////////////////////////////
     53 
     54 // compile time versions of min/max
     55 #define GR_CT_MAX(a, b) (((b) < (a)) ? (a) : (b))
     56 #define GR_CT_MIN(a, b) (((b) < (a)) ? (b) : (a))
     57 
     58 /**
     59  *  divide, rounding up
     60  */
     61 static inline int32_t GrIDivRoundUp(int x, int y) {
     62     SkASSERT(y > 0);
     63     return (x + (y-1)) / y;
     64 }
     65 static inline uint32_t GrUIDivRoundUp(uint32_t x, uint32_t y) {
     66     return (x + (y-1)) / y;
     67 }
     68 static inline size_t GrSizeDivRoundUp(size_t x, size_t y) {
     69     return (x + (y-1)) / y;
     70 }
     71 
     72 // compile time, evaluates Y multiple times
     73 #define GR_CT_DIV_ROUND_UP(X, Y) (((X) + ((Y)-1)) / (Y))
     74 
     75 /**
     76  *  align up
     77  */
     78 static inline uint32_t GrUIAlignUp(uint32_t x, uint32_t alignment) {
     79     return GrUIDivRoundUp(x, alignment) * alignment;
     80 }
     81 static inline size_t GrSizeAlignUp(size_t x, size_t alignment) {
     82     return GrSizeDivRoundUp(x, alignment) * alignment;
     83 }
     84 
     85 // compile time, evaluates A multiple times
     86 #define GR_CT_ALIGN_UP(X, A) (GR_CT_DIV_ROUND_UP((X),(A)) * (A))
     87 
     88 /**
     89  * amount of pad needed to align up
     90  */
     91 static inline uint32_t GrUIAlignUpPad(uint32_t x, uint32_t alignment) {
     92     return (alignment - x % alignment) % alignment;
     93 }
     94 static inline size_t GrSizeAlignUpPad(size_t x, size_t alignment) {
     95     return (alignment - x % alignment) % alignment;
     96 }
     97 
     98 /**
     99  *  align down
    100  */
    101 static inline uint32_t GrUIAlignDown(uint32_t x, uint32_t alignment) {
    102     return (x / alignment) * alignment;
    103 }
    104 static inline size_t GrSizeAlignDown(size_t x, uint32_t alignment) {
    105     return (x / alignment) * alignment;
    106 }
    107 
    108 ///////////////////////////////////////////////////////////////////////////////
    109 
    110 /**
    111  *  Return the next power of 2 >= n.
    112  */
    113 static inline uint32_t GrNextPow2(uint32_t n) {
    114     return n ? (1 << (32 - SkCLZ(n - 1))) : 1;
    115 }
    116 
    117 static inline int GrNextPow2(int n) {
    118     SkASSERT(n >= 0); // this impl only works for non-neg.
    119     return n ? (1 << (32 - SkCLZ(n - 1))) : 1;
    120 }
    121 
    122 ///////////////////////////////////////////////////////////////////////////////
    123 
    124 /**
    125  * Possible 3D APIs that may be used by Ganesh.
    126  */
    127 enum GrBackend {
    128     kOpenGL_GrBackend,
    129     kVulkan_GrBackend,
    130 
    131     kLast_GrBackend = kVulkan_GrBackend
    132 };
    133 const int kBackendCount = kLast_GrBackend + 1;
    134 
    135 /**
    136  * Backend-specific 3D context handle
    137  *      GrGLInterface* for OpenGL. If NULL will use the default GL interface.
    138  */
    139 typedef intptr_t GrBackendContext;
    140 
    141 ///////////////////////////////////////////////////////////////////////////////
    142 
    143 /**
    144 * Geometric primitives used for drawing.
    145 */
    146 enum GrPrimitiveType {
    147     kTriangles_GrPrimitiveType,
    148     kTriangleStrip_GrPrimitiveType,
    149     kTriangleFan_GrPrimitiveType,
    150     kPoints_GrPrimitiveType,
    151     kLines_GrPrimitiveType,     // 1 pix wide only
    152     kLineStrip_GrPrimitiveType, // 1 pix wide only
    153     kLast_GrPrimitiveType = kLineStrip_GrPrimitiveType
    154 };
    155 
    156 static inline bool GrIsPrimTypeLines(GrPrimitiveType type) {
    157     return kLines_GrPrimitiveType == type || kLineStrip_GrPrimitiveType == type;
    158 }
    159 
    160 static inline bool GrIsPrimTypeTris(GrPrimitiveType type) {
    161     return kTriangles_GrPrimitiveType == type     ||
    162            kTriangleStrip_GrPrimitiveType == type ||
    163            kTriangleFan_GrPrimitiveType == type;
    164 }
    165 
    166 /**
    167  *  Formats for masks, used by the font cache.
    168  *  Important that these are 0-based.
    169  */
    170 enum GrMaskFormat {
    171     kA8_GrMaskFormat,    //!< 1-byte per pixel
    172     kA565_GrMaskFormat,  //!< 2-bytes per pixel, RGB represent 3-channel LCD coverage
    173     kARGB_GrMaskFormat,  //!< 4-bytes per pixel, color format
    174 
    175     kLast_GrMaskFormat = kARGB_GrMaskFormat
    176 };
    177 static const int kMaskFormatCount = kLast_GrMaskFormat + 1;
    178 
    179 /**
    180  *  Return the number of bytes-per-pixel for the specified mask format.
    181  */
    182 static inline int GrMaskFormatBytesPerPixel(GrMaskFormat format) {
    183     SkASSERT(format < kMaskFormatCount);
    184     // kA8   (0) -> 1
    185     // kA565 (1) -> 2
    186     // kARGB (2) -> 4
    187     static const int sBytesPerPixel[] = { 1, 2, 4 };
    188     static_assert(SK_ARRAY_COUNT(sBytesPerPixel) == kMaskFormatCount, "array_size_mismatch");
    189     static_assert(kA8_GrMaskFormat == 0, "enum_order_dependency");
    190     static_assert(kA565_GrMaskFormat == 1, "enum_order_dependency");
    191     static_assert(kARGB_GrMaskFormat == 2, "enum_order_dependency");
    192 
    193     return sBytesPerPixel[(int) format];
    194 }
    195 
    196 /**
    197  * Pixel configurations.
    198  */
    199 enum GrPixelConfig {
    200     kUnknown_GrPixelConfig,
    201     kAlpha_8_GrPixelConfig,
    202     kIndex_8_GrPixelConfig,
    203     kRGB_565_GrPixelConfig,
    204     /**
    205      * Premultiplied
    206      */
    207     kRGBA_4444_GrPixelConfig,
    208     /**
    209      * Premultiplied. Byte order is r,g,b,a.
    210      */
    211     kRGBA_8888_GrPixelConfig,
    212     /**
    213      * Premultiplied. Byte order is b,g,r,a.
    214      */
    215     kBGRA_8888_GrPixelConfig,
    216     /**
    217      * Premultiplied and sRGB. Byte order is r,g,b,a.
    218      */
    219     kSRGBA_8888_GrPixelConfig,
    220     /**
    221      * ETC1 Compressed Data
    222      */
    223     kETC1_GrPixelConfig,
    224     /**
    225      * LATC/RGTC/3Dc/BC4 Compressed Data
    226      */
    227     kLATC_GrPixelConfig,
    228     /**
    229      * R11 EAC Compressed Data
    230      * (Corresponds to section C.3.5 of the OpenGL 4.4 core profile spec)
    231      */
    232     kR11_EAC_GrPixelConfig,
    233 
    234     /**
    235      * 12x12 ASTC Compressed Data
    236      * ASTC stands for Adaptive Scalable Texture Compression. It is a technique
    237      * that allows for a lot of customization in the compressed representataion
    238      * of a block. The only thing fixed in the representation is the block size,
    239      * which means that a texture that contains ASTC data must be treated as
    240      * having RGBA values. However, there are single-channel encodings which set
    241      * the alpha to opaque and all three RGB channels equal effectively making the
    242      * compression format a single channel such as R11 EAC and LATC.
    243      */
    244     kASTC_12x12_GrPixelConfig,
    245 
    246     /**
    247      * Byte order is r, g, b, a.  This color format is 32 bits per channel
    248      */
    249     kRGBA_float_GrPixelConfig,
    250 
    251     /**
    252      * This color format is a single 16 bit float channel
    253      */
    254     kAlpha_half_GrPixelConfig,
    255 
    256     /**
    257     * Byte order is r, g, b, a.  This color format is 16 bits per channel
    258     */
    259     kRGBA_half_GrPixelConfig,
    260 
    261     kLast_GrPixelConfig = kRGBA_half_GrPixelConfig
    262 };
    263 static const int kGrPixelConfigCnt = kLast_GrPixelConfig + 1;
    264 
    265 // Aliases for pixel configs that match skia's byte order.
    266 #ifndef SK_CPU_LENDIAN
    267     #error "Skia gpu currently assumes little endian"
    268 #endif
    269 #if SK_PMCOLOR_BYTE_ORDER(B,G,R,A)
    270     static const GrPixelConfig kSkia8888_GrPixelConfig = kBGRA_8888_GrPixelConfig;
    271 #elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A)
    272     static const GrPixelConfig kSkia8888_GrPixelConfig = kRGBA_8888_GrPixelConfig;
    273 #else
    274     #error "SK_*32_SHIFT values must correspond to GL_BGRA or GL_RGBA format."
    275 #endif
    276 
    277 // Returns true if the pixel config is a GPU-specific compressed format
    278 // representation.
    279 static inline bool GrPixelConfigIsCompressed(GrPixelConfig config) {
    280     switch (config) {
    281         case kIndex_8_GrPixelConfig:
    282         case kETC1_GrPixelConfig:
    283         case kLATC_GrPixelConfig:
    284         case kR11_EAC_GrPixelConfig:
    285         case kASTC_12x12_GrPixelConfig:
    286             return true;
    287         default:
    288             return false;
    289     }
    290 }
    291 
    292 /** If the pixel config is compressed, return an equivalent uncompressed format. */
    293 static inline GrPixelConfig GrMakePixelConfigUncompressed(GrPixelConfig config) {
    294     switch (config) {
    295         case kIndex_8_GrPixelConfig:
    296         case kETC1_GrPixelConfig:
    297         case kASTC_12x12_GrPixelConfig:
    298             return kRGBA_8888_GrPixelConfig;
    299         case kLATC_GrPixelConfig:
    300         case kR11_EAC_GrPixelConfig:
    301             return kAlpha_8_GrPixelConfig;
    302         default:
    303             SkASSERT(!GrPixelConfigIsCompressed(config));
    304             return config;
    305     }
    306 }
    307 
    308 // Returns true if the pixel config is 32 bits per pixel
    309 static inline bool GrPixelConfigIs8888(GrPixelConfig config) {
    310     switch (config) {
    311         case kRGBA_8888_GrPixelConfig:
    312         case kBGRA_8888_GrPixelConfig:
    313         case kSRGBA_8888_GrPixelConfig:
    314             return true;
    315         default:
    316             return false;
    317     }
    318 }
    319 
    320 // Returns true if the color (non-alpha) components represent sRGB values. It does NOT indicate that
    321 // all three color components are present in the config or anything about their order.
    322 static inline bool GrPixelConfigIsSRGB(GrPixelConfig config) {
    323     switch (config) {
    324         case kSRGBA_8888_GrPixelConfig:
    325             return true;
    326         default:
    327             return false;
    328     }
    329 }
    330 
    331 // Takes a config and returns the equivalent config with the R and B order
    332 // swapped if such a config exists. Otherwise, kUnknown_GrPixelConfig
    333 static inline GrPixelConfig GrPixelConfigSwapRAndB(GrPixelConfig config) {
    334     switch (config) {
    335         case kBGRA_8888_GrPixelConfig:
    336             return kRGBA_8888_GrPixelConfig;
    337         case kRGBA_8888_GrPixelConfig:
    338             return kBGRA_8888_GrPixelConfig;
    339         default:
    340             return kUnknown_GrPixelConfig;
    341     }
    342 }
    343 
    344 static inline size_t GrBytesPerPixel(GrPixelConfig config) {
    345     SkASSERT(!GrPixelConfigIsCompressed(config));
    346     switch (config) {
    347         case kAlpha_8_GrPixelConfig:
    348             return 1;
    349         case kRGB_565_GrPixelConfig:
    350         case kRGBA_4444_GrPixelConfig:
    351         case kAlpha_half_GrPixelConfig:
    352             return 2;
    353         case kRGBA_8888_GrPixelConfig:
    354         case kBGRA_8888_GrPixelConfig:
    355         case kSRGBA_8888_GrPixelConfig:
    356             return 4;
    357         case kRGBA_half_GrPixelConfig:
    358             return 8;
    359         case kRGBA_float_GrPixelConfig:
    360             return 16;
    361         default:
    362             return 0;
    363     }
    364 }
    365 
    366 static inline bool GrPixelConfigIsOpaque(GrPixelConfig config) {
    367     switch (config) {
    368         case kETC1_GrPixelConfig:
    369         case kRGB_565_GrPixelConfig:
    370             return true;
    371         default:
    372             return false;
    373     }
    374 }
    375 
    376 static inline bool GrPixelConfigIsAlphaOnly(GrPixelConfig config) {
    377     switch (config) {
    378         case kR11_EAC_GrPixelConfig:
    379         case kLATC_GrPixelConfig:
    380         case kASTC_12x12_GrPixelConfig:
    381         case kAlpha_8_GrPixelConfig:
    382         case kAlpha_half_GrPixelConfig:
    383             return true;
    384         default:
    385             return false;
    386     }
    387 }
    388 
    389 /**
    390  * Optional bitfield flags that can be set on GrSurfaceDesc (below).
    391  */
    392 enum GrSurfaceFlags {
    393     kNone_GrSurfaceFlags            = 0x0,
    394     /**
    395      * Creates a texture that can be rendered to as a GrRenderTarget. Use
    396      * GrTexture::asRenderTarget() to access.
    397      */
    398     kRenderTarget_GrSurfaceFlag     = 0x1,
    399     /**
    400      * Placeholder for managing zero-copy textures
    401      */
    402     kZeroCopy_GrSurfaceFlag         = 0x2,
    403     /**
    404      * Indicates that all allocations (color buffer, FBO completeness, etc)
    405      * should be verified.
    406      */
    407     kCheckAllocation_GrSurfaceFlag  = 0x4,
    408 };
    409 
    410 GR_MAKE_BITFIELD_OPS(GrSurfaceFlags)
    411 
    412 // opaque type for 3D API object handles
    413 typedef intptr_t GrBackendObject;
    414 
    415 /**
    416  * Some textures will be stored such that the upper and left edges of the content meet at the
    417  * the origin (in texture coord space) and for other textures the lower and left edges meet at
    418  * the origin. kDefault_GrSurfaceOrigin sets textures to TopLeft, and render targets
    419  * to BottomLeft.
    420  */
    421 
    422 enum GrSurfaceOrigin {
    423     kDefault_GrSurfaceOrigin,         // DEPRECATED; to be removed
    424     kTopLeft_GrSurfaceOrigin,
    425     kBottomLeft_GrSurfaceOrigin,
    426 };
    427 
    428 /**
    429  * An container of function pointers which consumers of Skia can fill in and
    430  * pass to Skia. Skia will use these function pointers in place of its backend
    431  * API texture creation function. Either all of the function pointers should be
    432  * filled in, or they should all be nullptr.
    433  */
    434 struct GrTextureStorageAllocator {
    435     GrTextureStorageAllocator()
    436     : fAllocateTextureStorage(nullptr)
    437     , fDeallocateTextureStorage(nullptr) {
    438     }
    439 
    440     enum class Result {
    441         kSucceededAndUploaded,
    442         kSucceededWithoutUpload,
    443         kFailed
    444     };
    445     typedef Result (*AllocateTextureStorageProc)(
    446             void* ctx, GrBackendObject texture, unsigned width,
    447             unsigned height, GrPixelConfig config, const void* srcData, GrSurfaceOrigin);
    448     typedef void (*DeallocateTextureStorageProc)(void* ctx, GrBackendObject texture);
    449 
    450     /*
    451      * Generates and binds a texture to |textureStorageTarget()|. Allocates
    452      * storage for the texture.
    453      *
    454      * In OpenGL, the MIN and MAX filters for the created texture must be
    455      * GL_LINEAR. The WRAP_S and WRAP_T must be GL_CLAMP_TO_EDGE.
    456      *
    457      * If |srcData| is not nullptr, then the implementation of this function
    458      * may attempt to upload the data into the texture. On successful upload,
    459      * or if |srcData| is nullptr, returns kSucceededAndUploaded.
    460      */
    461     AllocateTextureStorageProc fAllocateTextureStorage;
    462 
    463     /*
    464      * Deallocate the storage for the given texture.
    465      *
    466      * Skia does not always destroy its outstanding textures. See
    467      * GrContext::abandonContext() for more details. The consumer of Skia is
    468      * responsible for making sure that all textures are destroyed, even if this
    469      * callback is not invoked.
    470      */
    471     DeallocateTextureStorageProc fDeallocateTextureStorage;
    472 
    473     /*
    474      * The context to use when invoking fAllocateTextureStorage and
    475      * fDeallocateTextureStorage.
    476      */
    477     void* fCtx;
    478 };
    479 
    480 /**
    481  * Describes a surface to be created.
    482  */
    483 struct GrSurfaceDesc {
    484     GrSurfaceDesc()
    485     : fFlags(kNone_GrSurfaceFlags)
    486     , fOrigin(kDefault_GrSurfaceOrigin)
    487     , fWidth(0)
    488     , fHeight(0)
    489     , fConfig(kUnknown_GrPixelConfig)
    490     , fSampleCnt(0) {
    491     }
    492 
    493     GrSurfaceFlags         fFlags;  //!< bitfield of TextureFlags
    494     GrSurfaceOrigin        fOrigin; //!< origin of the texture
    495     int                    fWidth;  //!< Width of the texture
    496     int                    fHeight; //!< Height of the texture
    497 
    498     /**
    499      * Format of source data of the texture. Not guaranteed to be the same as
    500      * internal format used by 3D API.
    501      */
    502     GrPixelConfig          fConfig;
    503 
    504     /**
    505      * The number of samples per pixel or 0 to disable full scene AA. This only
    506      * applies if the kRenderTarget_GrSurfaceFlag is set. The actual number
    507      * of samples may not exactly match the request. The request will be rounded
    508      * up to the next supported sample count, or down if it is larger than the
    509      * max supported count.
    510      */
    511     int                    fSampleCnt;
    512 
    513     /**
    514      * A custom platform-specific allocator to use in place of the backend APIs
    515      * usual texture creation method (e.g. TexImage2D in OpenGL).
    516      */
    517     GrTextureStorageAllocator fTextureStorageAllocator;
    518 };
    519 
    520 // Legacy alias
    521 typedef GrSurfaceDesc GrTextureDesc;
    522 
    523 /**
    524  * Clips are composed from these objects.
    525  */
    526 enum GrClipType {
    527     kRect_ClipType,
    528     kPath_ClipType
    529 };
    530 
    531 ///////////////////////////////////////////////////////////////////////////////
    532 
    533 
    534 /** Ownership rules for external GPU resources imported into Skia. */
    535 enum GrWrapOwnership {
    536     /** Skia will assume the client will keep the resource alive and Skia will not free it. */
    537     kBorrow_GrWrapOwnership,
    538 
    539     /** Skia will assume ownership of the resource and free it. */
    540     kAdopt_GrWrapOwnership,
    541 };
    542 
    543 /**
    544  * Gr can wrap an existing texture created by the client with a GrTexture
    545  * object. The client is responsible for ensuring that the texture lives at
    546  * least as long as the GrTexture object wrapping it. We require the client to
    547  * explicitly provide information about the texture, such as width, height,
    548  * and pixel config, rather than querying the 3D APIfor these values. We expect
    549  * these to be immutable even if the 3D API doesn't require this (OpenGL).
    550  *
    551  * Textures that are also render targets are supported as well. Gr will manage
    552  * any ancillary 3D API (stencil buffer, FBO id, etc) objects necessary for
    553  * Gr to draw into the render target. To access the render target object
    554  * call GrTexture::asRenderTarget().
    555  *
    556  * If in addition to the render target flag, the caller also specifies a sample
    557  * count Gr will create an MSAA buffer that resolves into the texture. Gr auto-
    558  * resolves when it reads from the texture. The client can explictly resolve
    559  * using the GrRenderTarget interface.
    560  *
    561  * Note: These flags currently form a subset of GrTexture's flags.
    562  */
    563 
    564 enum GrBackendTextureFlags {
    565     /**
    566      * No flags enabled
    567      */
    568     kNone_GrBackendTextureFlag             = 0,
    569     /**
    570      * Indicates that the texture is also a render target, and thus should have
    571      * a GrRenderTarget object.
    572      */
    573     kRenderTarget_GrBackendTextureFlag     = kRenderTarget_GrSurfaceFlag,
    574 };
    575 GR_MAKE_BITFIELD_OPS(GrBackendTextureFlags)
    576 
    577 struct GrBackendTextureDesc {
    578     GrBackendTextureDesc() { memset(this, 0, sizeof(*this)); }
    579     GrBackendTextureFlags           fFlags;
    580     GrSurfaceOrigin                 fOrigin;
    581     int                             fWidth;         //<! width in pixels
    582     int                             fHeight;        //<! height in pixels
    583     GrPixelConfig                   fConfig;        //<! color format
    584     /**
    585      * If the render target flag is set and sample count is greater than 0
    586      * then Gr will create an MSAA buffer that resolves to the texture.
    587      */
    588     int                             fSampleCnt;
    589     /**
    590      * Handle to the 3D API object.
    591      * OpenGL: Texture ID.
    592      */
    593     GrBackendObject                 fTextureHandle;
    594 };
    595 
    596 ///////////////////////////////////////////////////////////////////////////////
    597 
    598 /**
    599  * Gr can wrap an existing render target created by the client in the 3D API
    600  * with a GrRenderTarget object. The client is responsible for ensuring that the
    601  * underlying 3D API object lives at least as long as the GrRenderTarget object
    602  * wrapping it. We require the client to explicitly provide information about
    603  * the target, such as width, height, and pixel config rather than querying the
    604  * 3D API for these values. We expect these properties to be immutable even if
    605  * the 3D API doesn't require this (OpenGL).
    606  */
    607 
    608 struct GrBackendRenderTargetDesc {
    609     GrBackendRenderTargetDesc() { memset(this, 0, sizeof(*this)); }
    610     int                             fWidth;         //<! width in pixels
    611     int                             fHeight;        //<! height in pixels
    612     GrPixelConfig                   fConfig;        //<! color format
    613     GrSurfaceOrigin                 fOrigin;        //<! pixel origin
    614     /**
    615      * The number of samples per pixel. Gr uses this to influence decisions
    616      * about applying other forms of anti-aliasing.
    617      */
    618     int                             fSampleCnt;
    619     /**
    620      * Number of bits of stencil per-pixel.
    621      */
    622     int                             fStencilBits;
    623     /**
    624      * Handle to the 3D API object.
    625      * OpenGL: FBO ID
    626      */
    627     GrBackendObject                 fRenderTargetHandle;
    628 };
    629 
    630 /**
    631  * The GrContext's cache of backend context state can be partially invalidated.
    632  * These enums are specific to the GL backend and we'd add a new set for an alternative backend.
    633  */
    634 enum GrGLBackendState {
    635     kRenderTarget_GrGLBackendState     = 1 << 0,
    636     kTextureBinding_GrGLBackendState   = 1 << 1,
    637     // View state stands for scissor and viewport
    638     kView_GrGLBackendState             = 1 << 2,
    639     kBlend_GrGLBackendState            = 1 << 3,
    640     kMSAAEnable_GrGLBackendState       = 1 << 4,
    641     kVertex_GrGLBackendState           = 1 << 5,
    642     kStencil_GrGLBackendState          = 1 << 6,
    643     kPixelStore_GrGLBackendState       = 1 << 7,
    644     kProgram_GrGLBackendState          = 1 << 8,
    645     kFixedFunction_GrGLBackendState    = 1 << 9,
    646     kMisc_GrGLBackendState             = 1 << 10,
    647     kPathRendering_GrGLBackendState    = 1 << 11,
    648     kALL_GrGLBackendState              = 0xffff
    649 };
    650 
    651 /**
    652  * Returns the data size for the given compressed pixel config
    653  */
    654 static inline size_t GrCompressedFormatDataSize(GrPixelConfig config,
    655                                                 int width, int height) {
    656     SkASSERT(GrPixelConfigIsCompressed(config));
    657     static const int kGrIndex8TableSize = 256 * 4; // 4 == sizeof(GrColor)
    658 
    659     switch (config) {
    660         case kIndex_8_GrPixelConfig:
    661             return width * height + kGrIndex8TableSize;
    662         case kR11_EAC_GrPixelConfig:
    663         case kLATC_GrPixelConfig:
    664         case kETC1_GrPixelConfig:
    665             SkASSERT((width & 3) == 0);
    666             SkASSERT((height & 3) == 0);
    667             return (width >> 2) * (height >> 2) * 8;
    668 
    669         case kASTC_12x12_GrPixelConfig:
    670             SkASSERT((width % 12) == 0);
    671             SkASSERT((height % 12) == 0);
    672             return (width / 12) * (height / 12) * 16;
    673 
    674         default:
    675             SkFAIL("Unknown compressed pixel config");
    676             return 4 * width * height;
    677     }
    678 }
    679 
    680 /**
    681  * This value translates to reseting all the context state for any backend.
    682  */
    683 static const uint32_t kAll_GrBackendState = 0xffffffff;
    684 
    685 #endif
    686