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