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