GrTypes.h revision c43649962221c348d656d425a3fa9b29c78231d4
1ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com/* 3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2010 Google Inc. 4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * 5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be 6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file. 7ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 8ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 9ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 10ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com 11ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#ifndef GrTypes_DEFINED 12ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#define GrTypes_DEFINED 13ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 149b24d25c6b7ddde5788444f17fa3bfad19096f37reed@google.com#include "SkTypes.h" 15ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#include "GrConfig.h" 16ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 17fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com//////////////////////////////////////////////////////////////////////////////// 18fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com 19fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com/** 20fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com * Defines overloaded bitwise operators to make it easier to use an enum as a 21fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com * bitfield. 22fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com */ 23fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com#define GR_MAKE_BITFIELD_OPS(X) \ 2486c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com inline X operator | (X a, X b) { \ 25fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com return (X) (+a | +b); \ 26fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com } \ 27fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com \ 2886c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com inline X operator & (X a, X b) { \ 29fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com return (X) (+a & +b); \ 30fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com } \ 31fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com template <typename T> \ 3286c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com inline X operator & (T a, X b) { \ 33fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com return (X) (+a & +b); \ 34fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com } \ 35fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com template <typename T> \ 3686c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com inline X operator & (X a, T b) { \ 37fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com return (X) (+a & +b); \ 38fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com } \ 39fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com 4086c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com#define GR_DECL_BITFIELD_OPS_FRIENDS(X) \ 4186c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com friend X operator | (X a, X b); \ 4286c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com \ 4386c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com friend X operator & (X a, X b); \ 4486c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com \ 4586c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com template <typename T> \ 4686c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com friend X operator & (T a, X b); \ 4786c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com \ 4886c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com template <typename T> \ 4986c1f71625970610e768d3bf26c933db2cd685babsalomon@google.com friend X operator & (X a, T b); \ 50fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com//////////////////////////////////////////////////////////////////////////////// 51fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com 52fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com 53ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com/** 54ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Macro to round n up to the next multiple of 4, or return it unchanged if 55ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * n is already a multiple of 4 56ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 579b24d25c6b7ddde5788444f17fa3bfad19096f37reed@google.com#define GrALIGN4(n) SkAlign4(n) 58ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#define GrIsALIGN4(n) (((n) & 3) == 0) 59ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 60ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.comtemplate <typename T> const T& GrMin(const T& a, const T& b) { 61ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com return (a < b) ? a : b; 62ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com} 63ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 64ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.comtemplate <typename T> const T& GrMax(const T& a, const T& b) { 65ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com return (b < a) ? a : b; 66ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com} 67ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 68ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com// compile time versions of min/max 69ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#define GR_CT_MAX(a, b) (((b) < (a)) ? (a) : (b)) 70ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#define GR_CT_MIN(a, b) (((b) < (a)) ? (b) : (a)) 71ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 72ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com/** 73ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * divide, rounding up 74ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 75919583674bd5daeb60327c0bc1ce8aaa80d54e13bsalomon@google.comstatic inline int32_t GrIDivRoundUp(int x, int y) { 76919583674bd5daeb60327c0bc1ce8aaa80d54e13bsalomon@google.com GrAssert(y > 0); 77919583674bd5daeb60327c0bc1ce8aaa80d54e13bsalomon@google.com return (x + (y-1)) / y; 78919583674bd5daeb60327c0bc1ce8aaa80d54e13bsalomon@google.com} 791c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.comstatic inline uint32_t GrUIDivRoundUp(uint32_t x, uint32_t y) { 801c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com return (x + (y-1)) / y; 811c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com} 821c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.comstatic inline size_t GrSizeDivRoundUp(size_t x, uint32_t y) { 83ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com return (x + (y-1)) / y; 84ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com} 85ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 86ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com/** 87ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * align up 88ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 891c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.comstatic inline uint32_t GrUIAlignUp(uint32_t x, uint32_t alignment) { 90ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com return GrUIDivRoundUp(x, alignment) * alignment; 91ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com} 921c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.comstatic inline uint32_t GrSizeAlignUp(size_t x, uint32_t alignment) { 931c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com return GrSizeDivRoundUp(x, alignment) * alignment; 941c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com} 95ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 96ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com/** 97ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * amount of pad needed to align up 98ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 991c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.comstatic inline uint32_t GrUIAlignUpPad(uint32_t x, uint32_t alignment) { 1001c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com return (alignment - x % alignment) % alignment; 1011c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com} 1021c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.comstatic inline size_t GrSizeAlignUpPad(size_t x, uint32_t alignment) { 103ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com return (alignment - x % alignment) % alignment; 104ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com} 105ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 106ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com/** 107ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * align down 108ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 1091c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.comstatic inline uint32_t GrUIAlignDown(uint32_t x, uint32_t alignment) { 1101c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com return (x / alignment) * alignment; 1111c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com} 1121c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.comstatic inline uint32_t GrSizeAlignDown(size_t x, uint32_t alignment) { 113ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com return (x / alignment) * alignment; 114ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com} 115ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 116ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com/** 117ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Count elements in an array 118ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 1199b24d25c6b7ddde5788444f17fa3bfad19096f37reed@google.com#define GR_ARRAY_COUNT(array) SK_ARRAY_COUNT(array) 120ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 121ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com//!< allocate a block of memory, will never return NULL 122ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.comextern void* GrMalloc(size_t bytes); 123ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 124ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com//!< free block allocated by GrMalloc. ptr may be NULL 125ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.comextern void GrFree(void* ptr); 126ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 127ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.comstatic inline void Gr_bzero(void* dst, size_t size) { 128ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com memset(dst, 0, size); 129ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com} 130ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 131ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com/////////////////////////////////////////////////////////////////////////////// 132ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 133ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com/** 134ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Return the number of leading zeros in n 135ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 136ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.comextern int Gr_clz(uint32_t n); 137ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 138ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com/** 139ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Return true if n is a power of 2 140ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 141ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.comstatic inline bool GrIsPow2(unsigned n) { 142ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com return n && 0 == (n & (n - 1)); 143ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com} 144ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 145ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com/** 146ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Return the next power of 2 >= n. 147ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 148ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.comstatic inline uint32_t GrNextPow2(uint32_t n) { 149ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com return n ? (1 << (32 - Gr_clz(n - 1))) : 1; 150ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com} 151ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 152b5b3168a645802f66233234a06dd5a3764f18018bsalomon@google.comstatic inline int GrNextPow2(int n) { 153b5b3168a645802f66233234a06dd5a3764f18018bsalomon@google.com GrAssert(n >= 0); // this impl only works for non-neg. 154b5b3168a645802f66233234a06dd5a3764f18018bsalomon@google.com return n ? (1 << (32 - Gr_clz(n - 1))) : 1; 155b5b3168a645802f66233234a06dd5a3764f18018bsalomon@google.com} 156b5b3168a645802f66233234a06dd5a3764f18018bsalomon@google.com 157ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com/////////////////////////////////////////////////////////////////////////////// 158ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 159ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com/** 160ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * 16.16 fixed point type 161ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 162ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.comtypedef int32_t GrFixed; 163ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 164ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#if GR_DEBUG 165ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 166ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.comstatic inline int16_t GrToS16(intptr_t x) { 167ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com GrAssert((int16_t)x == x); 168ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com return (int16_t)x; 169ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com} 170ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 171ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#else 172ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 173ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#define GrToS16(x) x 174ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 175ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#endif 176ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 1775877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com 1785877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com/////////////////////////////////////////////////////////////////////////////// 17905ef510389950e1ae8dcba40e41e001db771b12dbsalomon@google.com 18005ef510389950e1ae8dcba40e41e001db771b12dbsalomon@google.com/** 18105ef510389950e1ae8dcba40e41e001db771b12dbsalomon@google.com * Possible 3D APIs that may be used by Ganesh. 18205ef510389950e1ae8dcba40e41e001db771b12dbsalomon@google.com */ 18305ef510389950e1ae8dcba40e41e001db771b12dbsalomon@google.comenum GrEngine { 18405ef510389950e1ae8dcba40e41e001db771b12dbsalomon@google.com kOpenGL_Shaders_GrEngine, 18505ef510389950e1ae8dcba40e41e001db771b12dbsalomon@google.com kOpenGL_Fixed_GrEngine, 18605ef510389950e1ae8dcba40e41e001db771b12dbsalomon@google.com}; 18705ef510389950e1ae8dcba40e41e001db771b12dbsalomon@google.com 18805ef510389950e1ae8dcba40e41e001db771b12dbsalomon@google.com/** 18905ef510389950e1ae8dcba40e41e001db771b12dbsalomon@google.com * Engine-specific 3D context handle 1900b77d6892b067ad402c9678b0226bff70599fbe2bsalomon@google.com * GrGLInterface* for OpenGL. If NULL will use the default GL interface. 19105ef510389950e1ae8dcba40e41e001db771b12dbsalomon@google.com */ 19205ef510389950e1ae8dcba40e41e001db771b12dbsalomon@google.comtypedef intptr_t GrPlatform3DContext; 19305ef510389950e1ae8dcba40e41e001db771b12dbsalomon@google.com 19405ef510389950e1ae8dcba40e41e001db771b12dbsalomon@google.com/////////////////////////////////////////////////////////////////////////////// 1955877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com 196ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com/** 197ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Type used to describe format of vertices in arrays 198ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com * Values are defined in GrDrawTarget 199ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 2004be283f3a82895530d1b70372cd48ddb1c663fd8bsalomon@google.comtypedef int GrVertexLayout; 201ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 202ffca400ef6f96a280c3e2c09210f950af64a1f24bsalomon@google.com/** 203ffca400ef6f96a280c3e2c09210f950af64a1f24bsalomon@google.com* Geometric primitives used for drawing. 204ffca400ef6f96a280c3e2c09210f950af64a1f24bsalomon@google.com*/ 205ffca400ef6f96a280c3e2c09210f950af64a1f24bsalomon@google.comenum GrPrimitiveType { 206ffca400ef6f96a280c3e2c09210f950af64a1f24bsalomon@google.com kTriangles_PrimitiveType, 207ffca400ef6f96a280c3e2c09210f950af64a1f24bsalomon@google.com kTriangleStrip_PrimitiveType, 208ffca400ef6f96a280c3e2c09210f950af64a1f24bsalomon@google.com kTriangleFan_PrimitiveType, 209ffca400ef6f96a280c3e2c09210f950af64a1f24bsalomon@google.com kPoints_PrimitiveType, 210471d471dcd7422e5dd9c822c1092b2ba4721dcfebsalomon@google.com kLines_PrimitiveType, // 1 pix wide only 211471d471dcd7422e5dd9c822c1092b2ba4721dcfebsalomon@google.com kLineStrip_PrimitiveType // 1 pix wide only 212ffca400ef6f96a280c3e2c09210f950af64a1f24bsalomon@google.com}; 213ffca400ef6f96a280c3e2c09210f950af64a1f24bsalomon@google.com 2140650e811b537f21a3a9d09a953960626cf5cfce4bsalomon@google.comstatic inline bool GrIsPrimTypeLines(GrPrimitiveType type) { 2150650e811b537f21a3a9d09a953960626cf5cfce4bsalomon@google.com return kLines_PrimitiveType == type || kLineStrip_PrimitiveType == type; 2160650e811b537f21a3a9d09a953960626cf5cfce4bsalomon@google.com} 2170650e811b537f21a3a9d09a953960626cf5cfce4bsalomon@google.com 2180650e811b537f21a3a9d09a953960626cf5cfce4bsalomon@google.comstatic inline bool GrIsPrimTypeTris(GrPrimitiveType type) { 2190650e811b537f21a3a9d09a953960626cf5cfce4bsalomon@google.com return kTriangles_PrimitiveType == type || 2200650e811b537f21a3a9d09a953960626cf5cfce4bsalomon@google.com kTriangleStrip_PrimitiveType == type || 2210650e811b537f21a3a9d09a953960626cf5cfce4bsalomon@google.com kTriangleFan_PrimitiveType == type; 2220650e811b537f21a3a9d09a953960626cf5cfce4bsalomon@google.com} 2230650e811b537f21a3a9d09a953960626cf5cfce4bsalomon@google.com 224ffca400ef6f96a280c3e2c09210f950af64a1f24bsalomon@google.com/** 225ffca400ef6f96a280c3e2c09210f950af64a1f24bsalomon@google.com * Coeffecients for alpha-blending. 226ffca400ef6f96a280c3e2c09210f950af64a1f24bsalomon@google.com */ 227ffca400ef6f96a280c3e2c09210f950af64a1f24bsalomon@google.comenum GrBlendCoeff { 228ffca400ef6f96a280c3e2c09210f950af64a1f24bsalomon@google.com kZero_BlendCoeff, //<! 0 229ffca400ef6f96a280c3e2c09210f950af64a1f24bsalomon@google.com kOne_BlendCoeff, //<! 1 230ffca400ef6f96a280c3e2c09210f950af64a1f24bsalomon@google.com kSC_BlendCoeff, //<! src color 231ffca400ef6f96a280c3e2c09210f950af64a1f24bsalomon@google.com kISC_BlendCoeff, //<! one minus src color 232ffca400ef6f96a280c3e2c09210f950af64a1f24bsalomon@google.com kDC_BlendCoeff, //<! dst color 233ffca400ef6f96a280c3e2c09210f950af64a1f24bsalomon@google.com kIDC_BlendCoeff, //<! one minus dst color 234ffca400ef6f96a280c3e2c09210f950af64a1f24bsalomon@google.com kSA_BlendCoeff, //<! src alpha 235ffca400ef6f96a280c3e2c09210f950af64a1f24bsalomon@google.com kISA_BlendCoeff, //<! one minus src alpha 236ffca400ef6f96a280c3e2c09210f950af64a1f24bsalomon@google.com kDA_BlendCoeff, //<! dst alpha 237ffca400ef6f96a280c3e2c09210f950af64a1f24bsalomon@google.com kIDA_BlendCoeff, //<! one minus dst alpha 238080773ca79cbdc230730d295441255e9254d76a6bsalomon@google.com kConstC_BlendCoeff, //<! constant color 239080773ca79cbdc230730d295441255e9254d76a6bsalomon@google.com kIConstC_BlendCoeff, //<! one minus constant color 240080773ca79cbdc230730d295441255e9254d76a6bsalomon@google.com kConstA_BlendCoeff, //<! constant color alpha 241080773ca79cbdc230730d295441255e9254d76a6bsalomon@google.com kIConstA_BlendCoeff, //<! one minus constant color alpha 242080773ca79cbdc230730d295441255e9254d76a6bsalomon@google.com 243271cffc77bd2fcb3458559e509634442517ca1e9bsalomon@google.com kPublicBlendCoeffCount 244ffca400ef6f96a280c3e2c09210f950af64a1f24bsalomon@google.com}; 245ffca400ef6f96a280c3e2c09210f950af64a1f24bsalomon@google.com 246d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com/** 247759c16e20dc42577226c8805bfea92d8bacb14d8reed@google.com * Formats for masks, used by the font cache. 248759c16e20dc42577226c8805bfea92d8bacb14d8reed@google.com * Important that these are 0-based. 24998539c607b05f7e25406ae873bf1b24154a36a6freed@google.com */ 25098539c607b05f7e25406ae873bf1b24154a36a6freed@google.comenum GrMaskFormat { 2511eeaf0ba2381f84ffd889f56303cbe0d1886bb21caryclark@google.com kA8_GrMaskFormat, //!< 1-byte per pixel 2521eeaf0ba2381f84ffd889f56303cbe0d1886bb21caryclark@google.com kA565_GrMaskFormat, //!< 2-bytes per pixel 2531eeaf0ba2381f84ffd889f56303cbe0d1886bb21caryclark@google.com kA888_GrMaskFormat, //!< 4-bytes per pixel 2541eeaf0ba2381f84ffd889f56303cbe0d1886bb21caryclark@google.com 2551eeaf0ba2381f84ffd889f56303cbe0d1886bb21caryclark@google.com kCount_GrMaskFormats //!< used to allocate arrays sized for mask formats 25698539c607b05f7e25406ae873bf1b24154a36a6freed@google.com}; 25798539c607b05f7e25406ae873bf1b24154a36a6freed@google.com 25898539c607b05f7e25406ae873bf1b24154a36a6freed@google.com/** 25998539c607b05f7e25406ae873bf1b24154a36a6freed@google.com * Return the number of bytes-per-pixel for the specified mask format. 26098539c607b05f7e25406ae873bf1b24154a36a6freed@google.com */ 26198539c607b05f7e25406ae873bf1b24154a36a6freed@google.comstatic inline int GrMaskFormatBytesPerPixel(GrMaskFormat format) { 262bbf1226530d1a4e521e40c982f127fd49dbeb6a0reed@google.com GrAssert((unsigned)format <= 2); 263bbf1226530d1a4e521e40c982f127fd49dbeb6a0reed@google.com // kA8 (0) -> 1 264bbf1226530d1a4e521e40c982f127fd49dbeb6a0reed@google.com // kA565 (1) -> 2 265bbf1226530d1a4e521e40c982f127fd49dbeb6a0reed@google.com // kA888 (2) -> 4 266bbf1226530d1a4e521e40c982f127fd49dbeb6a0reed@google.com return 1 << (int)format; 26798539c607b05f7e25406ae873bf1b24154a36a6freed@google.com} 26898539c607b05f7e25406ae873bf1b24154a36a6freed@google.com 26998539c607b05f7e25406ae873bf1b24154a36a6freed@google.com/** 270669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com * Pixel configurations. 271c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com * Unpremultiplied configs are intended for conversion out from skia. They are 272c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com * not supported as input (e.g. drawBitmap or a bitmap shader). 273669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com */ 274669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.comenum GrPixelConfig { 275669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com kUnknown_GrPixelConfig, 276669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com kAlpha_8_GrPixelConfig, 277669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com kIndex_8_GrPixelConfig, 278669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com kRGB_565_GrPixelConfig, 279c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com /** 280c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com * Premultiplied 281c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com */ 282c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com kRGBA_4444_GrPixelConfig, 283c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com /** 284c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com * Premultiplied. Byte order is r,g,b,a 285c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com */ 286c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com kRGBA_8888_PM_GrPixelConfig, 287c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com /** 288c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com * Unpremultiplied. Byte order is r,g,b,a 289c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com */ 290c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com kRGBA_8888_UPM_GrPixelConfig, 291c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com /** 292c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com * Premultiplied. Byte order is b,g,r,a 293c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com */ 294c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com kBGRA_8888_PM_GrPixelConfig, 295c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com /** 296c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com * Unpremultiplied. Byte order is b,g,r,a 297c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com */ 298c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com kBGRA_8888_UPM_GrPixelConfig, 299669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com}; 300669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com 301c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com// Aliases for pixel configs that match skia's byte order 302c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com#ifndef SK_CPU_LENDIAN 303c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com #error "Skia gpu currently assumes little endian" 304c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com#endif 305c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com#if 24 == SK_A32_SHIFT && 16 == SK_R32_SHIFT && \ 306c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com 8 == SK_G32_SHIFT && 0 == SK_B32_SHIFT 307c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com static const GrPixelConfig kSkia8888_PM_GrPixelConfig = kBGRA_8888_PM_GrPixelConfig; 308c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com static const GrPixelConfig kSkia8888_UPM_GrPixelConfig = kBGRA_8888_UPM_GrPixelConfig; 309c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com#elif 24 == SK_A32_SHIFT && 16 == SK_B32_SHIFT && \ 310c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com 8 == SK_G32_SHIFT && 0 == SK_R32_SHIFT 311c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com static const GrPixelConfig kSkia8888_PM_GrPixelConfig = kRGBA_8888_PM_GrPixelConfig; 312c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com static const GrPixelConfig kSkia8888_UPM_GrPixelConfig = kRGBA_8888_UPM_GrPixelConfig; 313c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com#else 314c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com #error "SK_*32_SHIFT values must correspond to GL_BGRA or GL_RGBA format." 315c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com#endif 316c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com 317c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com// WebKit is relying on this old name for the native skia PM config. This will 318c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com// be deleted ASAP because it is so similar to kRGBA_PM_8888_GrPixelConfig but 319c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com// has a different interpretation when skia is compiled BGRA. 320c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.comstatic const GrPixelConfig kRGBA_8888_GrPixelConfig = kSkia8888_PM_GrPixelConfig; 321c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com 322669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.comstatic inline size_t GrBytesPerPixel(GrPixelConfig config) { 323669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com switch (config) { 324669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com case kAlpha_8_GrPixelConfig: 325669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com case kIndex_8_GrPixelConfig: 326669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com return 1; 327669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com case kRGB_565_GrPixelConfig: 328669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com case kRGBA_4444_GrPixelConfig: 329669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com return 2; 330c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com case kRGBA_8888_PM_GrPixelConfig: 331c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com case kRGBA_8888_UPM_GrPixelConfig: 332c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com case kBGRA_8888_PM_GrPixelConfig: 333c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com case kBGRA_8888_UPM_GrPixelConfig: 334669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com return 4; 335669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com default: 336669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com return 0; 337669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com } 338669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com} 339669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com 340669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.comstatic inline bool GrPixelConfigIsOpaque(GrPixelConfig config) { 341669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com switch (config) { 342669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com case kRGB_565_GrPixelConfig: 343c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com return true; 344c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com default: 345c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com return false; 346c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com } 347c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com} 348c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com 349c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com/** 350c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com * Premultiplied alpha is the usual for skia. Therefore, configs that are 351c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com * ambiguous (alpha-only or color-only) are considered premultiplied. 352c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com */ 353c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.comstatic inline bool GrPixelConfigIsUnpremultiplied(GrPixelConfig config) { 354c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com switch (config) { 355c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com case kRGBA_8888_UPM_GrPixelConfig: 356c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com case kBGRA_8888_UPM_GrPixelConfig: 357669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com return true; 358669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com default: 359669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com return false; 360669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com } 361669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com} 362669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com 363669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.comstatic inline bool GrPixelConfigIsAlphaOnly(GrPixelConfig config) { 364669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com switch (config) { 365669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com case kAlpha_8_GrPixelConfig: 366669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com return true; 367669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com default: 368669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com return false; 369669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com } 370669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com} 371669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com 372669fdc4ed8ed461a141cb97d0afdd9ef72a82be1bsalomon@google.com/** 373fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com * Used to control the level of antialiasing available for a rendertarget. 374fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com * Anti-alias quality levels depend on the underlying API/GPU capabilities. 375fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com */ 376fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.comenum GrAALevels { 377fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com kNone_GrAALevel, //<! No antialiasing available. 378fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com kLow_GrAALevel, //<! Low quality antialiased rendering. Actual 379fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com // interpretation is platform-dependent. 380fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com kMed_GrAALevel, //<! Medium quality antialiased rendering. Actual 381fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com // interpretation is platform-dependent. 382fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com kHigh_GrAALevel, //<! High quality antialiased rendering. Actual 383fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com // interpretation is platform-dependent. 384fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com}; 385fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com 386fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com/** 387fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com * Optional bitfield flags that can be passed to createTexture. 388fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com */ 389fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.comenum GrTextureFlags { 390fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com kNone_GrTextureFlags = 0x0, 391fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com /** 392fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com * Creates a texture that can be rendered to as a GrRenderTarget. Use 393fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com * GrTexture::asRenderTarget() to access. 394fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com */ 395fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com kRenderTarget_GrTextureFlagBit = 0x1, 396fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com /** 397fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com * By default all render targets have an associated stencil buffer that 398fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com * may be required for path filling. This flag overrides stencil buffer 399fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com * creation. 400fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com * MAKE THIS PRIVATE? 401fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com */ 402fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com kNoStencil_GrTextureFlagBit = 0x2, 403fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com /** 404fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com * Hint that the CPU may modify this texture after creation. 405fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com */ 406fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com kDynamicUpdate_GrTextureFlagBit = 0x4, 407fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com}; 408fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com 409fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.comGR_MAKE_BITFIELD_OPS(GrTextureFlags) 410fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com 411fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.comenum { 412fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com /** 413fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com * For Index8 pixel config, the colortable must be 256 entries 414fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com */ 415fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com kGrColorTableSize = 256 * 4 //sizeof(GrColor) 416fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com}; 417fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com 418fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com/** 419fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com * Describes a texture to be created. 420fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com */ 421fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.comstruct GrTextureDesc { 422fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com GrTextureFlags fFlags; //!< bitfield of TextureFlags 423fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com /** 424fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com * The level of antialiasing available for a rendertarget texture. Only used 425fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com * fFlags contains kRenderTarget_GrTextureFlag. 426fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com */ 427fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com GrAALevels fAALevel; 42879d2dbed5a08e0d3f65646d52b4bb884cd0af9b5bsalomon@google.com int fWidth; //!< Width of the texture 42979d2dbed5a08e0d3f65646d52b4bb884cd0af9b5bsalomon@google.com int fHeight; //!< Height of the texture 430fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com /** 431fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com * Format of source data of the texture. Not guaraunteed to be the same as 432fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com * internal format used by 3D API. 433fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com */ 43464c4fe4113424bcfab8b3e0c7049887fda5ab4ffbsalomon@google.com // This union exists because WebKit uses the deprecated name fFormat. Once 43564c4fe4113424bcfab8b3e0c7049887fda5ab4ffbsalomon@google.com // WebKit has been changed fFormat will be dropped. 43664c4fe4113424bcfab8b3e0c7049887fda5ab4ffbsalomon@google.com union { 43764c4fe4113424bcfab8b3e0c7049887fda5ab4ffbsalomon@google.com GrPixelConfig fFormat; 43864c4fe4113424bcfab8b3e0c7049887fda5ab4ffbsalomon@google.com GrPixelConfig fConfig; 43964c4fe4113424bcfab8b3e0c7049887fda5ab4ffbsalomon@google.com }; 440fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com}; 441fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com 442fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.com/** 443d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com * Set Operations used to construct clips. 444d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com */ 445d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.comenum GrSetOp { 446d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com kReplace_SetOp, 447d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com kIntersect_SetOp, 448d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com kUnion_SetOp, 449d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com kXor_SetOp, 450d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com kDifference_SetOp, 451d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com kReverseDifference_SetOp, 452d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com}; 453d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com 454d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com/** 455d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com * Clips are composed from these objects. 456d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com */ 457d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.comenum GrClipType { 458d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com kRect_ClipType, 459d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com kPath_ClipType 460d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com}; 461d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com 4625aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com/** 4635aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com * Commands used to describe a path. Each command 4645aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com * is accompanied by some number of points. 4655aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com */ 4665aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.comenum GrPathCmd { 4675aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com kMove_PathCmd, //!< Starts a new subpath at 4685aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com // at the returned point 4695aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com // 1 point 4705aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com kLine_PathCmd, //!< Adds a line segment 4715aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com // 2 points 4725aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com kQuadratic_PathCmd, //!< Adds a quadratic segment 4735aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com // 3 points 4745aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com kCubic_PathCmd, //!< Adds a cubic segment 4755aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com // 4 points 4765aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com kClose_PathCmd, //!< Closes the current subpath 4775aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com // by connecting a line to the 4785aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com // starting point. 4795aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com // 0 points 4805aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com kEnd_PathCmd //!< Indicates the end of the last subpath 4815aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com // when iterating 4825aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com // 0 points. 4835aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com}; 4845aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com 4855aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com/** 4865aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com * Gets the number of points associated with a path command. 4875aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com */ 4885aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.comstatic int inline NumPathCmdPoints(GrPathCmd cmd) { 4895aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com static const int gNumPoints[] = { 4905aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com 1, 2, 3, 4, 0, 0 4915aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com }; 4925aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com return gNumPoints[cmd]; 4935aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com} 4945aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com 4955aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com/** 4965aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com * Path filling rules 4975aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com */ 4985aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.comenum GrPathFill { 4995aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com kWinding_PathFill, 5005aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com kEvenOdd_PathFill, 5015aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com kInverseWinding_PathFill, 5025aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com kInverseEvenOdd_PathFill, 5035aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com kHairLine_PathFill, 5045aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com 5055aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com kPathFillCount 5065aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com}; 5075aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com 508fa6ac938e64fe11b442d05fe8a90ddac2d1951f9bsalomon@google.comstatic inline GrPathFill GrNonInvertedFill(GrPathFill fill) { 5095aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com static const GrPathFill gNonInvertedFills[] = { 5105aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com kWinding_PathFill, // kWinding_PathFill 5115aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com kEvenOdd_PathFill, // kEvenOdd_PathFill 5125aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com kWinding_PathFill, // kInverseWinding_PathFill 5135aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com kEvenOdd_PathFill, // kInverseEvenOdd_PathFill 5145aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com kHairLine_PathFill,// kHairLine_PathFill 5155aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com }; 5165aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com GR_STATIC_ASSERT(0 == kWinding_PathFill); 5175aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com GR_STATIC_ASSERT(1 == kEvenOdd_PathFill); 5185aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com GR_STATIC_ASSERT(2 == kInverseWinding_PathFill); 5195aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com GR_STATIC_ASSERT(3 == kInverseEvenOdd_PathFill); 5205aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com GR_STATIC_ASSERT(4 == kHairLine_PathFill); 5215aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com GR_STATIC_ASSERT(5 == kPathFillCount); 5225aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com return gNonInvertedFills[fill]; 5235aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com} 5245aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com 525fa6ac938e64fe11b442d05fe8a90ddac2d1951f9bsalomon@google.comstatic inline bool GrIsFillInverted(GrPathFill fill) { 5265aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com static const bool gIsFillInverted[] = { 5275aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com false, // kWinding_PathFill 5285aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com false, // kEvenOdd_PathFill 5295aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com true, // kInverseWinding_PathFill 5305aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com true, // kInverseEvenOdd_PathFill 5315aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com false, // kHairLine_PathFill 5325aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com }; 5335aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com GR_STATIC_ASSERT(0 == kWinding_PathFill); 5345aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com GR_STATIC_ASSERT(1 == kEvenOdd_PathFill); 5355aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com GR_STATIC_ASSERT(2 == kInverseWinding_PathFill); 5365aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com GR_STATIC_ASSERT(3 == kInverseEvenOdd_PathFill); 5375aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com GR_STATIC_ASSERT(4 == kHairLine_PathFill); 5385aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com GR_STATIC_ASSERT(5 == kPathFillCount); 5395aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com return gIsFillInverted[fill]; 5405aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com} 5415aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com 5425aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com/** 5435aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com * Hints provided about a path's convexity (or lack thereof). 5445aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com */ 5455aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.comenum GrConvexHint { 5465aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com kNone_ConvexHint, //<! No hint about convexity 5475aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com // of the path 5485aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com kConvex_ConvexHint, //<! Path is one convex piece 5495aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com kNonOverlappingConvexPieces_ConvexHint, //<! Multiple convex pieces, 5505aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com // pieces are known to be 5515aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com // disjoint 5525aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com kSameWindingConvexPieces_ConvexHint, //<! Multiple convex pieces, 5535aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com // may or may not intersect, 5545aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com // either all wind cw or all 5555aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com // wind ccw. 5565aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com kConcave_ConvexHint //<! Path is known to be 5575aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com // concave 5585aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com}; 5595aaa69e4339e229adfb05e96084a8ec0a590238bbsalomon@google.com 560ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com/////////////////////////////////////////////////////////////////////////////// 561ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 562e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com// opaque type for 3D API object handles 563e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.comtypedef intptr_t GrPlatform3DObject; 564e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com 565e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com/** 566e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * Gr can wrap an existing texture created by the client with a GrTexture 567e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * object. The client is responsible for ensuring that the texture lives at 568e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * least as long as the GrTexture object wrapping it. We require the client to 569e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * explicitly provide information about the texture, such as width, height, 570e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * and pixel config, rather than querying the 3D APIfor these values. We expect 571e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * these to be immutable even if the 3D API doesn't require this (OpenGL). 572e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * 573e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * Textures that are also render targets are supported as well. Gr will manage 574e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * any ancillary 3D API (stencil buffer, FBO id, etc) objects necessary for 575e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * Gr to draw into the render target. To access the render target object 576e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * call GrTexture::asRenderTarget(). 577e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * 578e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * If in addition to the render target flag, the caller also specifies a sample 579e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * count Gr will create an MSAA buffer that resolves into the texture. Gr auto- 580e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * resolves when it reads from the texture. The client can explictly resolve 581e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * using the GrRenderTarget interface. 582e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com */ 583e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com 584e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.comenum GrPlatformTextureFlags { 585e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com /** 586e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * No flags enabled 587e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com */ 588e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com kNone_GrPlatformTextureFlag = 0x0, 589e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com /** 590e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * Indicates that the texture is also a render target, and thus should have 591e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * a GrRenderTarget object. 592e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * 593e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * D3D (future): client must have created the texture with flags that allow 594e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * it to be used as a render target. 595e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com */ 596e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com kRenderTarget_GrPlatformTextureFlag = 0x1, 597e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com}; 598e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.comGR_MAKE_BITFIELD_OPS(GrPlatformTextureFlags) 599e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com 600e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.comstruct GrPlatformTextureDesc { 601e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com GrPlatformTextureDesc() { memset(this, 0, sizeof(*this)); } 602e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com GrPlatformTextureFlags fFlags; 603e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com int fWidth; //<! width in pixels 604e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com int fHeight; //<! height in pixels 605e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com GrPixelConfig fConfig; //<! color format 606e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com /** 607e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * If the render target flag is set and sample count is greater than 0 608e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * then Gr will create an MSAA buffer that resolves to the texture. 609e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com */ 610e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com int fSampleCnt; 611e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com /** 612e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * Handle to the 3D API object. 613e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * OpenGL: Texture ID. 614e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com */ 615e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com GrPlatform3DObject fTextureHandle; 616e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com}; 617e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com 618e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com/////////////////////////////////////////////////////////////////////////////// 619e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com 620e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com/** 621e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * Gr can wrap an existing render target created by the client in the 3D API 622e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * with a GrRenderTarget object. The client is responsible for ensuring that the 623e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * underlying 3D API object lives at least as long as the GrRenderTarget object 624e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * wrapping it. We require the client to explicitly provide information about 625e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * the target, such as width, height, and pixel config rather than querying the 626e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * 3D API for these values. We expect these properties to be immutable even if 627e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * the 3D API doesn't require this (OpenGL). 628e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com */ 629e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com 630e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.comstruct GrPlatformRenderTargetDesc { 631e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com GrPlatformRenderTargetDesc() { memset(this, 0, sizeof(*this)); } 632e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com int fWidth; //<! width in pixels 633e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com int fHeight; //<! height in pixels 634e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com GrPixelConfig fConfig; //<! color format 635e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com /** 636e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * The number of samples per pixel. Gr uses this to influence decisions 637e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * about applying other forms of antialiasing. 638e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com */ 639e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com int fSampleCnt; 640e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com /** 641e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * Number of bits of stencil per-pixel. 642e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com */ 643e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com int fStencilBits; 644e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com /** 645e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * Handle to the 3D API object. 646e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com * OpenGL: FBO ID 647e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com */ 648e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com GrPlatform3DObject fRenderTargetHandle; 649e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com}; 650e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com 651e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com/////////////////////////////////////////////////////////////////////////////// 652e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com// DEPRECATED. createPlatformSurface is replaced by createPlatformTexture 653e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com// and createPlatformRenderTarget. These enums and structs will be removed. 654e269f210bdae0288643afaf8a579b22d3f6d5bebbsalomon@google.com 6555877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.comenum GrPlatformSurfaceType { 6565877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com /** 6575877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * Specifies that the object being created is a render target. 6585877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com */ 6595877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com kRenderTarget_GrPlatformSurfaceType, 6605877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com /** 6615877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * Specifies that the object being created is a texture. 6625877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com */ 6635877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com kTexture_GrPlatformSurfaceType, 6645877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com /** 6655877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * Specifies that the object being created is a texture and a render 6665877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * target. 6675877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com */ 6685877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com kTextureRenderTarget_GrPlatformSurfaceType, 6695877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com}; 6705877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com 6715877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.comenum GrPlatformRenderTargetFlags { 6725877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com kNone_GrPlatformRenderTargetFlagBit = 0x0, 6735bfc21761e0ce41206acac4c5008fc0f24debd44bsalomon@google.com 6745877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com /** 6755877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * Gives permission to Gr to perform the downsample-resolve of a 6765877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * multisampled render target. If this is not set then read pixel 6775877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * operations may fail. If the object is both a texture and render target 6785877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * then this *must* be set. Otherwise, if the client wants do its own 6795877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * resolves it must create separate GrRenderTarget and GrTexture objects 6805877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * and insert appropriate flushes and resolves betweeen data hazards. 6815877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * GrRenderTarget has a flagForResolve() 6825877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com */ 6835877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com kGrCanResolve_GrPlatformRenderTargetFlagBit = 0x2, 6845877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com}; 6855877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com 686fea37b5e532dfe776269253afb9951e763c3b205bsalomon@google.comGR_MAKE_BITFIELD_OPS(GrPlatformRenderTargetFlags) 6875877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com 6885877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.comstruct GrPlatformSurfaceDesc { 6895877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com GrPlatformSurfaceType fSurfaceType; // type of surface to create 6905877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com /** 6915877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * Flags for kRenderTarget and kTextureRenderTarget surface types 6925877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com */ 6935877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com GrPlatformRenderTargetFlags fRenderTargetFlags; 6945877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com 6955877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com int fWidth; // width in pixels 6965877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com int fHeight; // height in pixels 6975877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com GrPixelConfig fConfig; // color format 6985877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com /** 6995877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * Number of per sample stencil buffer. Only relevant if kIsRenderTarget is 7005877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * set in fFlags. 7015877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com */ 7025877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com int fStencilBits; 7035bfc21761e0ce41206acac4c5008fc0f24debd44bsalomon@google.com 7045bfc21761e0ce41206acac4c5008fc0f24debd44bsalomon@google.com /** 7055bfc21761e0ce41206acac4c5008fc0f24debd44bsalomon@google.com * Number of samples per-pixel. Only relevant if kIsRenderTarget is set in 7065bfc21761e0ce41206acac4c5008fc0f24debd44bsalomon@google.com * fFlags. 7075bfc21761e0ce41206acac4c5008fc0f24debd44bsalomon@google.com */ 7085bfc21761e0ce41206acac4c5008fc0f24debd44bsalomon@google.com int fSampleCnt; 7095bfc21761e0ce41206acac4c5008fc0f24debd44bsalomon@google.com 7105877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com /** 7115877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * Texture object in 3D API. Only relevant if fSurfaceType is kTexture or 7125877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * kTextureRenderTarget. 7135877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * GL: this is a texture object (glGenTextures) 7145877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com */ 7155877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com GrPlatform3DObject fPlatformTexture; 7165877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com /** 7175877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * Render target object in 3D API. Only relevant if fSurfaceType is 7185877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * kRenderTarget or kTextureRenderTarget 7195877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * GL: this is a FBO object (glGenFramebuffers) 7205877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com */ 7215877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com GrPlatform3DObject fPlatformRenderTarget; 7225877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com /** 7235877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * 3D API object used as destination of resolve. Only relevant if 7245877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * fSurfaceType is kRenderTarget or kTextureRenderTarget and 7255877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * kGrCanResolve is set in fRenderTargetFlags. 7265877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * fFlags. 7275877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * GL: this is a FBO object (glGenFramebuffers) 7285877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com */ 7295877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com GrPlatform3DObject fPlatformResolveDestination; 7305877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com 7315877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com void reset() { memset(this, 0, sizeof(GrPlatformSurfaceDesc)); } 7325877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com}; 7335877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com 7345877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com/** 7355877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * Example of how to wrap render-to-texture-with-MSAA GL objects with a GrPlatformSurace 7365877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * 7375877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * GLint colorBufferID; 7385877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * glGenRenderbuffers(1, &colorID); 7395877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * glBindRenderbuffer(GL_RENDERBUFFER, colorBufferID); 7405877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * glRenderbufferStorageMultisample(GL_RENDERBUFFER, S, GL_RGBA, W, H); 7415877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * 7425877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * GLint stencilBufferID; 7435877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * glGenRenderBuffers(1, &stencilBufferID); 7445877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * glBindRenderbuffer(GL_RENDERBUFFER, stencilBufferID); 7455877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * glRenderbufferStorageMultisample(GL_RENDERBUFFER, S, GL_STENCIL_INDEX8, W, H); 7465877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * 7475877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * GLint drawFBOID; 7485877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * glGenFramebuffers(1, &drawFBOID); 7495877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * glBindFramebuffer(GL_FRAMEBUFFER, drawFBOID); 7505877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, colorBufferID); 7515877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, stencilBufferID); 7525877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * 7535877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * GLint textureID; 7545877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * glGenTextures(1, &textureID); 7555877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * glBindTexture(GL_TEXTURE_2D, textureID); 7565877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, W, H, ...); 7575877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * 7585877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * GLint readFBOID; 7595877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * glGenFramebuffers(1, &readFBOID); 7605877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * glBindFramebuffer(GL_FRAMEBUFFER, readFBOID); 7615877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, textureID, 0); 7625877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * 7635877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * GrPlatformSurfaceDesc renderTargetTextureDesc; 7645877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * renderTargetTextureDesc.fSurfaceType = kTextureRenderTarget_GrPlatformSurfaceType; 7655bfc21761e0ce41206acac4c5008fc0f24debd44bsalomon@google.com * renderTargetTextureDesc.fRenderTargetFlags = kGrCanResolve_GrPlatformRenderTargetFlagBit; 7665877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * renderTargetTextureDesc.fWidth = W; 7675877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * renderTargetTextureDesc.fHeight = H; 768c43649962221c348d656d425a3fa9b29c78231d4bsalomon@google.com * renderTargetTextureDesc.fConfig = kSkia8888_PM_GrPixelConfig 7695877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * renderTargetTextureDesc.fStencilBits = 8; 7705bfc21761e0ce41206acac4c5008fc0f24debd44bsalomon@google.com * renderTargetTextureDesc.fSampleCnt = S; 7715877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * renderTargetTextureDesc.fPlatformTexture = textureID; 7725877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * renderTargetTextureDesc.fPlatformRenderTarget = drawFBOID; 7735877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * renderTargetTextureDesc.fPlatformResolveDestination = readFBOID; 7745877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * 7755877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com * GrTexture* texture = static_cast<GrTexture*>(grContext->createPlatrformSurface(renderTargetTextureDesc)); 7765877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com */ 7775877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com 7785877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com 7795877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com/////////////////////////////////////////////////////////////////////////////// 7805877ffd5ea71a3ea70096d5c11c843798defa690bsalomon@google.com 781ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com// this is included only to make it easy to use this debugging facility 782ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#include "GrInstanceCounter.h" 783ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 784ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#endif 785