epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2010 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 10 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 11 | #ifndef GrTypes_DEFINED |
| 12 | #define GrTypes_DEFINED |
| 13 | |
reed@google.com | 9b24d25 | 2011-06-01 20:27:53 +0000 | [diff] [blame] | 14 | #include "SkTypes.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 15 | #include "GrConfig.h" |
| 16 | |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 17 | //////////////////////////////////////////////////////////////////////////////// |
| 18 | |
| 19 | /** |
| 20 | * Defines overloaded bitwise operators to make it easier to use an enum as a |
| 21 | * bitfield. |
| 22 | */ |
| 23 | #define GR_MAKE_BITFIELD_OPS(X) \ |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 24 | inline X operator | (X a, X b) { \ |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 25 | return (X) (+a | +b); \ |
| 26 | } \ |
| 27 | \ |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 28 | inline X operator & (X a, X b) { \ |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 29 | return (X) (+a & +b); \ |
| 30 | } \ |
| 31 | template <typename T> \ |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 32 | inline X operator & (T a, X b) { \ |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 33 | return (X) (+a & +b); \ |
| 34 | } \ |
| 35 | template <typename T> \ |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 36 | inline X operator & (X a, T b) { \ |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 37 | return (X) (+a & +b); \ |
| 38 | } \ |
| 39 | |
bsalomon@google.com | 86c1f71 | 2011-10-12 14:54:26 +0000 | [diff] [blame] | 40 | #define GR_DECL_BITFIELD_OPS_FRIENDS(X) \ |
| 41 | friend X operator | (X a, X b); \ |
| 42 | \ |
| 43 | friend X operator & (X a, X b); \ |
| 44 | \ |
| 45 | template <typename T> \ |
| 46 | friend X operator & (T a, X b); \ |
| 47 | \ |
| 48 | template <typename T> \ |
| 49 | friend X operator & (X a, T b); \ |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 50 | //////////////////////////////////////////////////////////////////////////////// |
| 51 | |
| 52 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 53 | /** |
| 54 | * Macro to round n up to the next multiple of 4, or return it unchanged if |
| 55 | * n is already a multiple of 4 |
| 56 | */ |
reed@google.com | 9b24d25 | 2011-06-01 20:27:53 +0000 | [diff] [blame] | 57 | #define GrALIGN4(n) SkAlign4(n) |
tomhudson@google.com | 01224d5 | 2011-11-28 18:22:01 +0000 | [diff] [blame] | 58 | #define GrIsALIGN4(n) SkIsAlign4(n) |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 59 | |
| 60 | template <typename T> const T& GrMin(const T& a, const T& b) { |
robertphillips@google.com | 07ef911 | 2012-06-04 13:22:14 +0000 | [diff] [blame] | 61 | return (a < b) ? a : b; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | template <typename T> const T& GrMax(const T& a, const T& b) { |
robertphillips@google.com | 07ef911 | 2012-06-04 13:22:14 +0000 | [diff] [blame] | 65 | return (b < a) ? a : b; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | // compile time versions of min/max |
| 69 | #define GR_CT_MAX(a, b) (((b) < (a)) ? (a) : (b)) |
| 70 | #define GR_CT_MIN(a, b) (((b) < (a)) ? (b) : (a)) |
| 71 | |
| 72 | /** |
| 73 | * divide, rounding up |
| 74 | */ |
bsalomon@google.com | 9195836 | 2011-06-13 17:58:13 +0000 | [diff] [blame] | 75 | static inline int32_t GrIDivRoundUp(int x, int y) { |
| 76 | GrAssert(y > 0); |
| 77 | return (x + (y-1)) / y; |
| 78 | } |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 79 | static inline uint32_t GrUIDivRoundUp(uint32_t x, uint32_t y) { |
| 80 | return (x + (y-1)) / y; |
| 81 | } |
bsalomon@google.com | 4da34e3 | 2012-06-19 15:40:27 +0000 | [diff] [blame] | 82 | static inline size_t GrSizeDivRoundUp(size_t x, size_t y) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 83 | return (x + (y-1)) / y; |
| 84 | } |
| 85 | |
bsalomon@google.com | 4da34e3 | 2012-06-19 15:40:27 +0000 | [diff] [blame] | 86 | // compile time, evaluates Y multiple times |
| 87 | #define GR_CT_DIV_ROUND_UP(X, Y) (((X) + ((Y)-1)) / (Y)) |
| 88 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 89 | /** |
| 90 | * align up |
| 91 | */ |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 92 | static inline uint32_t GrUIAlignUp(uint32_t x, uint32_t alignment) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 93 | return GrUIDivRoundUp(x, alignment) * alignment; |
| 94 | } |
bsalomon@google.com | 4da34e3 | 2012-06-19 15:40:27 +0000 | [diff] [blame] | 95 | static inline size_t GrSizeAlignUp(size_t x, size_t alignment) { |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 96 | return GrSizeDivRoundUp(x, alignment) * alignment; |
| 97 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 98 | |
bsalomon@google.com | 4da34e3 | 2012-06-19 15:40:27 +0000 | [diff] [blame] | 99 | // compile time, evaluates A multiple times |
| 100 | #define GR_CT_ALIGN_UP(X, A) (GR_CT_DIV_ROUND_UP((X),(A)) * (A)) |
| 101 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 102 | /** |
| 103 | * amount of pad needed to align up |
| 104 | */ |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 105 | static inline uint32_t GrUIAlignUpPad(uint32_t x, uint32_t alignment) { |
| 106 | return (alignment - x % alignment) % alignment; |
| 107 | } |
bsalomon@google.com | 4da34e3 | 2012-06-19 15:40:27 +0000 | [diff] [blame] | 108 | static inline size_t GrSizeAlignUpPad(size_t x, size_t alignment) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 109 | return (alignment - x % alignment) % alignment; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * align down |
| 114 | */ |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 115 | static inline uint32_t GrUIAlignDown(uint32_t x, uint32_t alignment) { |
| 116 | return (x / alignment) * alignment; |
| 117 | } |
bsalomon@google.com | 5e49732 | 2012-08-28 21:45:26 +0000 | [diff] [blame] | 118 | static inline size_t GrSizeAlignDown(size_t x, uint32_t alignment) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 119 | return (x / alignment) * alignment; |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Count elements in an array |
| 124 | */ |
reed@google.com | 9b24d25 | 2011-06-01 20:27:53 +0000 | [diff] [blame] | 125 | #define GR_ARRAY_COUNT(array) SK_ARRAY_COUNT(array) |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 126 | |
| 127 | //!< allocate a block of memory, will never return NULL |
| 128 | extern void* GrMalloc(size_t bytes); |
| 129 | |
| 130 | //!< free block allocated by GrMalloc. ptr may be NULL |
| 131 | extern void GrFree(void* ptr); |
| 132 | |
| 133 | static inline void Gr_bzero(void* dst, size_t size) { |
| 134 | memset(dst, 0, size); |
| 135 | } |
| 136 | |
| 137 | /////////////////////////////////////////////////////////////////////////////// |
| 138 | |
| 139 | /** |
| 140 | * Return the number of leading zeros in n |
| 141 | */ |
| 142 | extern int Gr_clz(uint32_t n); |
| 143 | |
| 144 | /** |
| 145 | * Return true if n is a power of 2 |
| 146 | */ |
| 147 | static inline bool GrIsPow2(unsigned n) { |
| 148 | return n && 0 == (n & (n - 1)); |
| 149 | } |
| 150 | |
| 151 | /** |
| 152 | * Return the next power of 2 >= n. |
| 153 | */ |
| 154 | static inline uint32_t GrNextPow2(uint32_t n) { |
| 155 | return n ? (1 << (32 - Gr_clz(n - 1))) : 1; |
| 156 | } |
| 157 | |
bsalomon@google.com | b5b3168 | 2011-06-16 18:05:35 +0000 | [diff] [blame] | 158 | static inline int GrNextPow2(int n) { |
| 159 | GrAssert(n >= 0); // this impl only works for non-neg. |
| 160 | return n ? (1 << (32 - Gr_clz(n - 1))) : 1; |
| 161 | } |
| 162 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 163 | /////////////////////////////////////////////////////////////////////////////// |
| 164 | |
| 165 | /** |
| 166 | * 16.16 fixed point type |
| 167 | */ |
| 168 | typedef int32_t GrFixed; |
| 169 | |
| 170 | #if GR_DEBUG |
| 171 | |
| 172 | static inline int16_t GrToS16(intptr_t x) { |
| 173 | GrAssert((int16_t)x == x); |
| 174 | return (int16_t)x; |
| 175 | } |
| 176 | |
| 177 | #else |
| 178 | |
| 179 | #define GrToS16(x) x |
| 180 | |
| 181 | #endif |
| 182 | |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 183 | |
| 184 | /////////////////////////////////////////////////////////////////////////////// |
| 185 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 186 | /** |
bsalomon@google.com | 05ef510 | 2011-05-02 21:14:59 +0000 | [diff] [blame] | 187 | * Possible 3D APIs that may be used by Ganesh. |
| 188 | */ |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame^] | 189 | enum GrBackend { |
| 190 | kOpenGL_GrBackend, |
bsalomon@google.com | 05ef510 | 2011-05-02 21:14:59 +0000 | [diff] [blame] | 191 | }; |
| 192 | |
| 193 | /** |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame^] | 194 | * Backend-specific 3D context handle |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 195 | * GrGLInterface* for OpenGL. If NULL will use the default GL interface. |
bsalomon@google.com | 05ef510 | 2011-05-02 21:14:59 +0000 | [diff] [blame] | 196 | */ |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame^] | 197 | typedef intptr_t GrBackendContext; |
bsalomon@google.com | 05ef510 | 2011-05-02 21:14:59 +0000 | [diff] [blame] | 198 | |
| 199 | /////////////////////////////////////////////////////////////////////////////// |
| 200 | |
| 201 | /** |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 202 | * Type used to describe format of vertices in arrays |
| 203 | * Values are defined in GrDrawTarget |
| 204 | */ |
bsalomon@google.com | 4be283f | 2011-04-19 21:15:09 +0000 | [diff] [blame] | 205 | typedef int GrVertexLayout; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 206 | |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 207 | /** |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 208 | * Geometric primitives used for drawing. |
| 209 | */ |
| 210 | enum GrPrimitiveType { |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 211 | kTriangles_GrPrimitiveType, |
| 212 | kTriangleStrip_GrPrimitiveType, |
| 213 | kTriangleFan_GrPrimitiveType, |
| 214 | kPoints_GrPrimitiveType, |
| 215 | kLines_GrPrimitiveType, // 1 pix wide only |
| 216 | kLineStrip_GrPrimitiveType // 1 pix wide only |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 217 | }; |
| 218 | |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 219 | static inline bool GrIsPrimTypeLines(GrPrimitiveType type) { |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 220 | return kLines_GrPrimitiveType == type || kLineStrip_GrPrimitiveType == type; |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | static inline bool GrIsPrimTypeTris(GrPrimitiveType type) { |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 224 | return kTriangles_GrPrimitiveType == type || |
| 225 | kTriangleStrip_GrPrimitiveType == type || |
| 226 | kTriangleFan_GrPrimitiveType == type; |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 227 | } |
| 228 | |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 229 | /** |
| 230 | * Coeffecients for alpha-blending. |
| 231 | */ |
| 232 | enum GrBlendCoeff { |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 233 | kInvalid_GrBlendCoeff = -1, |
bsalomon@google.com | a4d8fc2 | 2012-05-21 13:21:46 +0000 | [diff] [blame] | 234 | |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 235 | kZero_GrBlendCoeff, //<! 0 |
| 236 | kOne_GrBlendCoeff, //<! 1 |
| 237 | kSC_GrBlendCoeff, //<! src color |
| 238 | kISC_GrBlendCoeff, //<! one minus src color |
| 239 | kDC_GrBlendCoeff, //<! dst color |
| 240 | kIDC_GrBlendCoeff, //<! one minus dst color |
| 241 | kSA_GrBlendCoeff, //<! src alpha |
| 242 | kISA_GrBlendCoeff, //<! one minus src alpha |
| 243 | kDA_GrBlendCoeff, //<! dst alpha |
| 244 | kIDA_GrBlendCoeff, //<! one minus dst alpha |
| 245 | kConstC_GrBlendCoeff, //<! constant color |
| 246 | kIConstC_GrBlendCoeff, //<! one minus constant color |
| 247 | kConstA_GrBlendCoeff, //<! constant color alpha |
| 248 | kIConstA_GrBlendCoeff, //<! one minus constant color alpha |
bsalomon@google.com | 080773c | 2011-03-15 19:09:25 +0000 | [diff] [blame] | 249 | |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 250 | kPublicGrBlendCoeffCount |
bsalomon@google.com | ffca400 | 2011-02-22 20:34:01 +0000 | [diff] [blame] | 251 | }; |
| 252 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 253 | /** |
reed@google.com | 759c16e | 2011-03-15 19:15:15 +0000 | [diff] [blame] | 254 | * Formats for masks, used by the font cache. |
| 255 | * Important that these are 0-based. |
reed@google.com | 98539c6 | 2011-03-15 15:40:16 +0000 | [diff] [blame] | 256 | */ |
| 257 | enum GrMaskFormat { |
caryclark@google.com | 1eeaf0b | 2011-06-22 13:19:43 +0000 | [diff] [blame] | 258 | kA8_GrMaskFormat, //!< 1-byte per pixel |
| 259 | kA565_GrMaskFormat, //!< 2-bytes per pixel |
| 260 | kA888_GrMaskFormat, //!< 4-bytes per pixel |
| 261 | |
| 262 | kCount_GrMaskFormats //!< used to allocate arrays sized for mask formats |
reed@google.com | 98539c6 | 2011-03-15 15:40:16 +0000 | [diff] [blame] | 263 | }; |
| 264 | |
| 265 | /** |
| 266 | * Return the number of bytes-per-pixel for the specified mask format. |
| 267 | */ |
| 268 | static inline int GrMaskFormatBytesPerPixel(GrMaskFormat format) { |
reed@google.com | bbf1226 | 2011-10-04 20:14:57 +0000 | [diff] [blame] | 269 | GrAssert((unsigned)format <= 2); |
| 270 | // kA8 (0) -> 1 |
| 271 | // kA565 (1) -> 2 |
| 272 | // kA888 (2) -> 4 |
| 273 | return 1 << (int)format; |
reed@google.com | 98539c6 | 2011-03-15 15:40:16 +0000 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | /** |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 277 | * Pixel configurations. |
| 278 | */ |
| 279 | enum GrPixelConfig { |
| 280 | kUnknown_GrPixelConfig, |
| 281 | kAlpha_8_GrPixelConfig, |
| 282 | kIndex_8_GrPixelConfig, |
| 283 | kRGB_565_GrPixelConfig, |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 284 | /** |
| 285 | * Premultiplied |
| 286 | */ |
| 287 | kRGBA_4444_GrPixelConfig, |
| 288 | /** |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 289 | * Premultiplied. Byte order is r,g,b,a. |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 290 | */ |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 291 | kRGBA_8888_GrPixelConfig, |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 292 | /** |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 293 | * Premultiplied. Byte order is b,g,r,a. |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 294 | */ |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 295 | kBGRA_8888_GrPixelConfig, |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame] | 296 | |
| 297 | kGrPixelConfigCount |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 298 | }; |
| 299 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 300 | // Aliases for pixel configs that match skia's byte order. |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 301 | #ifndef SK_CPU_LENDIAN |
| 302 | #error "Skia gpu currently assumes little endian" |
| 303 | #endif |
| 304 | #if 24 == SK_A32_SHIFT && 16 == SK_R32_SHIFT && \ |
| 305 | 8 == SK_G32_SHIFT && 0 == SK_B32_SHIFT |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 306 | static const GrPixelConfig kSkia8888_GrPixelConfig = kBGRA_8888_GrPixelConfig; |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 307 | #elif 24 == SK_A32_SHIFT && 16 == SK_B32_SHIFT && \ |
| 308 | 8 == SK_G32_SHIFT && 0 == SK_R32_SHIFT |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 309 | static const GrPixelConfig kSkia8888_GrPixelConfig = kRGBA_8888_GrPixelConfig; |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 310 | #else |
| 311 | #error "SK_*32_SHIFT values must correspond to GL_BGRA or GL_RGBA format." |
| 312 | #endif |
| 313 | |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 314 | // This alias is deprecated and will be removed. |
| 315 | static const GrPixelConfig kSkia8888_PM_GrPixelConfig = kSkia8888_GrPixelConfig; |
| 316 | |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 317 | // Returns true if the pixel config has 8bit r,g,b,a components in that byte |
| 318 | // order |
| 319 | static inline bool GrPixelConfigIsRGBA8888(GrPixelConfig config) { |
| 320 | switch (config) { |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 321 | case kRGBA_8888_GrPixelConfig: |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 322 | return true; |
| 323 | default: |
| 324 | return false; |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | // Returns true if the pixel config has 8bit b,g,r,a components in that byte |
| 329 | // order |
| 330 | static inline bool GrPixelConfigIsBGRA8888(GrPixelConfig config) { |
| 331 | switch (config) { |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 332 | case kBGRA_8888_GrPixelConfig: |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 333 | return true; |
| 334 | default: |
| 335 | return false; |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | // Returns true if the pixel config is 32 bits per pixel |
| 340 | static inline bool GrPixelConfigIs32Bit(GrPixelConfig config) { |
| 341 | switch (config) { |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 342 | case kRGBA_8888_GrPixelConfig: |
| 343 | case kBGRA_8888_GrPixelConfig: |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 344 | return true; |
| 345 | default: |
| 346 | return false; |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | // Takes a config and returns the equivalent config with the R and B order |
| 351 | // swapped if such a config exists. Otherwise, kUnknown_GrPixelConfig |
| 352 | static inline GrPixelConfig GrPixelConfigSwapRAndB(GrPixelConfig config) { |
| 353 | switch (config) { |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 354 | case kBGRA_8888_GrPixelConfig: |
| 355 | return kRGBA_8888_GrPixelConfig; |
| 356 | case kRGBA_8888_GrPixelConfig: |
| 357 | return kBGRA_8888_GrPixelConfig; |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 358 | default: |
| 359 | return kUnknown_GrPixelConfig; |
| 360 | } |
| 361 | } |
| 362 | |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 363 | static inline size_t GrBytesPerPixel(GrPixelConfig config) { |
| 364 | switch (config) { |
| 365 | case kAlpha_8_GrPixelConfig: |
| 366 | case kIndex_8_GrPixelConfig: |
| 367 | return 1; |
| 368 | case kRGB_565_GrPixelConfig: |
| 369 | case kRGBA_4444_GrPixelConfig: |
| 370 | return 2; |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 371 | case kRGBA_8888_GrPixelConfig: |
| 372 | case kBGRA_8888_GrPixelConfig: |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 373 | return 4; |
| 374 | default: |
| 375 | return 0; |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | static inline bool GrPixelConfigIsOpaque(GrPixelConfig config) { |
| 380 | switch (config) { |
| 381 | case kRGB_565_GrPixelConfig: |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 382 | return true; |
| 383 | default: |
| 384 | return false; |
| 385 | } |
| 386 | } |
| 387 | |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 388 | static inline bool GrPixelConfigIsAlphaOnly(GrPixelConfig config) { |
| 389 | switch (config) { |
| 390 | case kAlpha_8_GrPixelConfig: |
| 391 | return true; |
| 392 | default: |
| 393 | return false; |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | /** |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 398 | * Optional bitfield flags that can be passed to createTexture. |
| 399 | */ |
| 400 | enum GrTextureFlags { |
| 401 | kNone_GrTextureFlags = 0x0, |
| 402 | /** |
| 403 | * Creates a texture that can be rendered to as a GrRenderTarget. Use |
| 404 | * GrTexture::asRenderTarget() to access. |
| 405 | */ |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 406 | kRenderTarget_GrTextureFlagBit = 0x1, |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 407 | /** |
| 408 | * By default all render targets have an associated stencil buffer that |
| 409 | * may be required for path filling. This flag overrides stencil buffer |
| 410 | * creation. |
| 411 | * MAKE THIS PRIVATE? |
| 412 | */ |
| 413 | kNoStencil_GrTextureFlagBit = 0x2, |
| 414 | /** |
| 415 | * Hint that the CPU may modify this texture after creation. |
| 416 | */ |
| 417 | kDynamicUpdate_GrTextureFlagBit = 0x4, |
robertphillips@google.com | 15c0fea | 2012-06-22 12:41:43 +0000 | [diff] [blame] | 418 | |
| 419 | kDummy_GrTextureFlagBit, |
| 420 | kLastPublic_GrTextureFlagBit = kDummy_GrTextureFlagBit-1, |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 421 | }; |
| 422 | |
| 423 | GR_MAKE_BITFIELD_OPS(GrTextureFlags) |
| 424 | |
| 425 | enum { |
| 426 | /** |
| 427 | * For Index8 pixel config, the colortable must be 256 entries |
| 428 | */ |
| 429 | kGrColorTableSize = 256 * 4 //sizeof(GrColor) |
| 430 | }; |
| 431 | |
robertphillips@google.com | 5091b70 | 2012-08-09 10:49:39 +0000 | [diff] [blame] | 432 | |
| 433 | /** |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 434 | * Describes a texture to be created. |
| 435 | */ |
| 436 | struct GrTextureDesc { |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 437 | GrTextureDesc() |
robertphillips@google.com | 75b3c96 | 2012-06-07 12:08:45 +0000 | [diff] [blame] | 438 | : fFlags(kNone_GrTextureFlags) |
| 439 | , fWidth(0) |
| 440 | , fHeight(0) |
| 441 | , fConfig(kUnknown_GrPixelConfig) |
robertphillips@google.com | 9c2ea84 | 2012-08-13 17:47:59 +0000 | [diff] [blame] | 442 | , fSampleCnt(0) { |
robertphillips@google.com | 75b3c96 | 2012-06-07 12:08:45 +0000 | [diff] [blame] | 443 | } |
| 444 | |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 445 | GrTextureFlags fFlags; //!< bitfield of TextureFlags |
bsalomon@google.com | 79d2dbe | 2011-06-13 19:28:02 +0000 | [diff] [blame] | 446 | int fWidth; //!< Width of the texture |
| 447 | int fHeight; //!< Height of the texture |
bsalomon@google.com | 78d6cf9 | 2012-01-30 18:09:31 +0000 | [diff] [blame] | 448 | |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 449 | /** |
robertphillips@google.com | 07ef911 | 2012-06-04 13:22:14 +0000 | [diff] [blame] | 450 | * Format of source data of the texture. Not guaranteed to be the same as |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 451 | * internal format used by 3D API. |
| 452 | */ |
bsalomon@google.com | 5bc34f0 | 2011-12-06 14:46:34 +0000 | [diff] [blame] | 453 | GrPixelConfig fConfig; |
bsalomon@google.com | b9014f4 | 2012-03-30 14:22:41 +0000 | [diff] [blame] | 454 | |
bsalomon@google.com | 78d6cf9 | 2012-01-30 18:09:31 +0000 | [diff] [blame] | 455 | /** |
| 456 | * The number of samples per pixel or 0 to disable full scene AA. This only |
| 457 | * applies if the kRenderTarget_GrTextureFlagBit is set. The actual number |
| 458 | * of samples may not exactly match the request. The request will be rounded |
| 459 | * up to the next supported sample count, or down if it is larger than the |
| 460 | * max supportex count. |
| 461 | */ |
robertphillips@google.com | 75b3c96 | 2012-06-07 12:08:45 +0000 | [diff] [blame] | 462 | int fSampleCnt; |
robertphillips@google.com | 9c2ea84 | 2012-08-13 17:47:59 +0000 | [diff] [blame] | 463 | }; |
| 464 | |
| 465 | /** |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 466 | * GrCacheData holds user-provided cache-specific data. It is used in |
robertphillips@google.com | 9c2ea84 | 2012-08-13 17:47:59 +0000 | [diff] [blame] | 467 | * combination with the GrTextureDesc to construct a cache key for texture |
| 468 | * resources. |
| 469 | */ |
| 470 | struct GrCacheData { |
| 471 | /* |
| 472 | * Scratch textures should all have this value as their fClientCacheID |
| 473 | */ |
| 474 | static const uint64_t kScratch_CacheID = 0xBBBBBBBB; |
| 475 | |
| 476 | /** |
| 477 | * Resources in the "scratch" domain can be used by any domain. All |
| 478 | * scratch textures will have this as their domain. |
| 479 | */ |
| 480 | static const uint8_t kScratch_ResourceDomain = 0; |
| 481 | |
| 482 | |
| 483 | // No default constructor is provided since, if you are creating one |
| 484 | // of these, you should definitely have a key (or be using the scratch |
| 485 | // key). |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 486 | GrCacheData(uint64_t key) |
robertphillips@google.com | 9c2ea84 | 2012-08-13 17:47:59 +0000 | [diff] [blame] | 487 | : fClientCacheID(key) |
| 488 | , fResourceDomain(kScratch_ResourceDomain) { |
| 489 | } |
robertphillips@google.com | 75b3c96 | 2012-06-07 12:08:45 +0000 | [diff] [blame] | 490 | |
| 491 | /** |
| 492 | * A user-provided texture ID. It should be unique to the texture data and |
| 493 | * does not need to take into account the width or height. Two textures |
| 494 | * with the same ID but different dimensions will not collide. This field |
| 495 | * is only relevant for textures that will be cached. |
| 496 | */ |
| 497 | uint64_t fClientCacheID; |
robertphillips@google.com | 5091b70 | 2012-08-09 10:49:39 +0000 | [diff] [blame] | 498 | |
| 499 | /** |
| 500 | * Allows cache clients to cluster their textures inside domains (e.g., |
| 501 | * alpha clip masks). Only relevant for cached textures. |
| 502 | */ |
| 503 | uint8_t fResourceDomain; |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 504 | }; |
| 505 | |
| 506 | /** |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 507 | * Clips are composed from these objects. |
| 508 | */ |
| 509 | enum GrClipType { |
| 510 | kRect_ClipType, |
| 511 | kPath_ClipType |
| 512 | }; |
| 513 | |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 514 | /** |
| 515 | * Commands used to describe a path. Each command |
| 516 | * is accompanied by some number of points. |
| 517 | */ |
| 518 | enum GrPathCmd { |
| 519 | kMove_PathCmd, //!< Starts a new subpath at |
| 520 | // at the returned point |
| 521 | // 1 point |
| 522 | kLine_PathCmd, //!< Adds a line segment |
| 523 | // 2 points |
| 524 | kQuadratic_PathCmd, //!< Adds a quadratic segment |
| 525 | // 3 points |
| 526 | kCubic_PathCmd, //!< Adds a cubic segment |
| 527 | // 4 points |
| 528 | kClose_PathCmd, //!< Closes the current subpath |
| 529 | // by connecting a line to the |
| 530 | // starting point. |
| 531 | // 0 points |
| 532 | kEnd_PathCmd //!< Indicates the end of the last subpath |
| 533 | // when iterating |
| 534 | // 0 points. |
| 535 | }; |
| 536 | |
| 537 | /** |
| 538 | * Gets the number of points associated with a path command. |
| 539 | */ |
| 540 | static int inline NumPathCmdPoints(GrPathCmd cmd) { |
| 541 | static const int gNumPoints[] = { |
| 542 | 1, 2, 3, 4, 0, 0 |
| 543 | }; |
| 544 | return gNumPoints[cmd]; |
| 545 | } |
| 546 | |
| 547 | /** |
| 548 | * Path filling rules |
| 549 | */ |
| 550 | enum GrPathFill { |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 551 | kWinding_GrPathFill, |
| 552 | kEvenOdd_GrPathFill, |
| 553 | kInverseWinding_GrPathFill, |
| 554 | kInverseEvenOdd_GrPathFill, |
| 555 | kHairLine_GrPathFill, |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 556 | |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 557 | kGrPathFillCount |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 558 | }; |
| 559 | |
bsalomon@google.com | fa6ac93 | 2011-10-05 19:57:55 +0000 | [diff] [blame] | 560 | static inline GrPathFill GrNonInvertedFill(GrPathFill fill) { |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 561 | static const GrPathFill gNonInvertedFills[] = { |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 562 | kWinding_GrPathFill, // kWinding_GrPathFill |
| 563 | kEvenOdd_GrPathFill, // kEvenOdd_GrPathFill |
| 564 | kWinding_GrPathFill, // kInverseWinding_GrPathFill |
| 565 | kEvenOdd_GrPathFill, // kInverseEvenOdd_GrPathFill |
| 566 | kHairLine_GrPathFill,// kHairLine_GrPathFill |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 567 | }; |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 568 | GR_STATIC_ASSERT(0 == kWinding_GrPathFill); |
| 569 | GR_STATIC_ASSERT(1 == kEvenOdd_GrPathFill); |
| 570 | GR_STATIC_ASSERT(2 == kInverseWinding_GrPathFill); |
| 571 | GR_STATIC_ASSERT(3 == kInverseEvenOdd_GrPathFill); |
| 572 | GR_STATIC_ASSERT(4 == kHairLine_GrPathFill); |
| 573 | GR_STATIC_ASSERT(5 == kGrPathFillCount); |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 574 | return gNonInvertedFills[fill]; |
| 575 | } |
| 576 | |
bsalomon@google.com | fa6ac93 | 2011-10-05 19:57:55 +0000 | [diff] [blame] | 577 | static inline bool GrIsFillInverted(GrPathFill fill) { |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 578 | static const bool gIsFillInverted[] = { |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 579 | false, // kWinding_GrPathFill |
| 580 | false, // kEvenOdd_GrPathFill |
| 581 | true, // kInverseWinding_GrPathFill |
| 582 | true, // kInverseEvenOdd_GrPathFill |
| 583 | false, // kHairLine_GrPathFill |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 584 | }; |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 585 | GR_STATIC_ASSERT(0 == kWinding_GrPathFill); |
| 586 | GR_STATIC_ASSERT(1 == kEvenOdd_GrPathFill); |
| 587 | GR_STATIC_ASSERT(2 == kInverseWinding_GrPathFill); |
| 588 | GR_STATIC_ASSERT(3 == kInverseEvenOdd_GrPathFill); |
| 589 | GR_STATIC_ASSERT(4 == kHairLine_GrPathFill); |
| 590 | GR_STATIC_ASSERT(5 == kGrPathFillCount); |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 591 | return gIsFillInverted[fill]; |
| 592 | } |
| 593 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 594 | /////////////////////////////////////////////////////////////////////////////// |
| 595 | |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 596 | // opaque type for 3D API object handles |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame^] | 597 | typedef intptr_t GrBackendObject; |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 598 | |
| 599 | /** |
| 600 | * Gr can wrap an existing texture created by the client with a GrTexture |
| 601 | * object. The client is responsible for ensuring that the texture lives at |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 602 | * least as long as the GrTexture object wrapping it. We require the client to |
| 603 | * explicitly provide information about the texture, such as width, height, |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 604 | * and pixel config, rather than querying the 3D APIfor these values. We expect |
| 605 | * these to be immutable even if the 3D API doesn't require this (OpenGL). |
| 606 | * |
| 607 | * Textures that are also render targets are supported as well. Gr will manage |
| 608 | * any ancillary 3D API (stencil buffer, FBO id, etc) objects necessary for |
| 609 | * Gr to draw into the render target. To access the render target object |
| 610 | * call GrTexture::asRenderTarget(). |
| 611 | * |
| 612 | * If in addition to the render target flag, the caller also specifies a sample |
| 613 | * count Gr will create an MSAA buffer that resolves into the texture. Gr auto- |
| 614 | * resolves when it reads from the texture. The client can explictly resolve |
| 615 | * using the GrRenderTarget interface. |
robertphillips@google.com | 3271628 | 2012-06-04 12:48:45 +0000 | [diff] [blame] | 616 | * |
| 617 | * Note: These flags currently form a subset of GrTexture's flags. |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 618 | */ |
| 619 | |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame^] | 620 | enum GrBackendTextureFlags { |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 621 | /** |
| 622 | * No flags enabled |
| 623 | */ |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame^] | 624 | kNone_GrBackendTextureFlag = kNone_GrTextureFlags, |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 625 | /** |
| 626 | * Indicates that the texture is also a render target, and thus should have |
| 627 | * a GrRenderTarget object. |
| 628 | * |
| 629 | * D3D (future): client must have created the texture with flags that allow |
| 630 | * it to be used as a render target. |
| 631 | */ |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame^] | 632 | kRenderTarget_GrBackendTextureFlag = kRenderTarget_GrTextureFlagBit, |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 633 | }; |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame^] | 634 | GR_MAKE_BITFIELD_OPS(GrBackendTextureFlags) |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 635 | |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame^] | 636 | struct GrBackendTextureDesc { |
| 637 | GrBackendTextureDesc() { memset(this, 0, sizeof(*this)); } |
| 638 | GrBackendTextureFlags fFlags; |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 639 | int fWidth; //<! width in pixels |
| 640 | int fHeight; //<! height in pixels |
| 641 | GrPixelConfig fConfig; //<! color format |
| 642 | /** |
| 643 | * If the render target flag is set and sample count is greater than 0 |
| 644 | * then Gr will create an MSAA buffer that resolves to the texture. |
| 645 | */ |
| 646 | int fSampleCnt; |
| 647 | /** |
| 648 | * Handle to the 3D API object. |
| 649 | * OpenGL: Texture ID. |
| 650 | */ |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame^] | 651 | GrBackendObject fTextureHandle; |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 652 | }; |
| 653 | |
| 654 | /////////////////////////////////////////////////////////////////////////////// |
| 655 | |
| 656 | /** |
| 657 | * Gr can wrap an existing render target created by the client in the 3D API |
| 658 | * with a GrRenderTarget object. The client is responsible for ensuring that the |
| 659 | * underlying 3D API object lives at least as long as the GrRenderTarget object |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 660 | * wrapping it. We require the client to explicitly provide information about |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 661 | * the target, such as width, height, and pixel config rather than querying the |
| 662 | * 3D API for these values. We expect these properties to be immutable even if |
| 663 | * the 3D API doesn't require this (OpenGL). |
| 664 | */ |
| 665 | |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame^] | 666 | struct GrBackendRenderTargetDesc { |
| 667 | GrBackendRenderTargetDesc() { memset(this, 0, sizeof(*this)); } |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 668 | int fWidth; //<! width in pixels |
| 669 | int fHeight; //<! height in pixels |
| 670 | GrPixelConfig fConfig; //<! color format |
| 671 | /** |
| 672 | * The number of samples per pixel. Gr uses this to influence decisions |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame^] | 673 | * about applying other forms of anti-aliasing. |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 674 | */ |
| 675 | int fSampleCnt; |
| 676 | /** |
| 677 | * Number of bits of stencil per-pixel. |
| 678 | */ |
| 679 | int fStencilBits; |
| 680 | /** |
| 681 | * Handle to the 3D API object. |
| 682 | * OpenGL: FBO ID |
| 683 | */ |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame^] | 684 | GrBackendObject fRenderTargetHandle; |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 685 | }; |
| 686 | |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame^] | 687 | /////////////////////////////////////////////////////////////////////////////// |
| 688 | // Legacy names that will be kept until WebKit can be updated. |
| 689 | |
| 690 | typedef GrBackend GrEngine; |
| 691 | static const GrBackend kOpenGL_Shaders_GrEngine = kOpenGL_GrBackend; |
| 692 | |
| 693 | typedef GrBackendContext GrPlatform3DContext; |
| 694 | |
| 695 | typedef GrBackendObject GrPlatform3DObject; |
| 696 | |
| 697 | typedef GrBackendTextureFlags GrPlatformTextureFlags; |
| 698 | static const GrBackendTextureFlags kNone_GrPlatformTextureFlag = kNone_GrBackendTextureFlag; |
| 699 | static const GrBackendTextureFlags kRenderTarget_GrPlatformTextureFlag = kRenderTarget_GrBackendTextureFlag; |
| 700 | |
| 701 | typedef GrBackendTextureDesc GrPlatformTextureDesc; |
| 702 | |
| 703 | typedef GrBackendRenderTargetDesc GrPlatformRenderTargetDesc; |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 704 | |
| 705 | /////////////////////////////////////////////////////////////////////////////// |
| 706 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 707 | // this is included only to make it easy to use this debugging facility |
| 708 | #include "GrInstanceCounter.h" |
| 709 | |
| 710 | #endif |