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