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