| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2010 Google Inc. | 3 * Copyright 2010 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 | 10 |
| 11 #ifndef GrTypes_DEFINED | 11 #ifndef GrTypes_DEFINED |
| 12 #define GrTypes_DEFINED | 12 #define GrTypes_DEFINED |
| 13 | 13 |
| 14 #include "SkTypes.h" | 14 #include "SkTypes.h" |
| 15 #include "GrConfig.h" | 15 #include "GrConfig.h" |
| 16 #include "SkMath.h" | 16 #include "SkMath.h" |
| 17 | 17 |
| 18 //#define SK_SUPPORT_LEGACY_GRTYPES |
| 19 |
| 18 //////////////////////////////////////////////////////////////////////////////// | 20 //////////////////////////////////////////////////////////////////////////////// |
| 19 | 21 |
| 20 /** | 22 /** |
| 21 * Defines overloaded bitwise operators to make it easier to use an enum as a | 23 * Defines overloaded bitwise operators to make it easier to use an enum as a |
| 22 * bitfield. | 24 * bitfield. |
| 23 */ | 25 */ |
| 24 #define GR_MAKE_BITFIELD_OPS(X) \ | 26 #define GR_MAKE_BITFIELD_OPS(X) \ |
| 25 inline X operator | (X a, X b) { \ | 27 inline X operator | (X a, X b) { \ |
| 26 return (X) (+a | +b); \ | 28 return (X) (+a | +b); \ |
| 27 } \ | 29 } \ |
| (...skipping 15 matching lines...) Expand all Loading... |
| 43 \ | 45 \ |
| 44 friend X operator & (X a, X b); \ | 46 friend X operator & (X a, X b); \ |
| 45 \ | 47 \ |
| 46 template <typename T> \ | 48 template <typename T> \ |
| 47 friend X operator & (T a, X b); \ | 49 friend X operator & (T a, X b); \ |
| 48 \ | 50 \ |
| 49 template <typename T> \ | 51 template <typename T> \ |
| 50 friend X operator & (X a, T b); \ | 52 friend X operator & (X a, T b); \ |
| 51 //////////////////////////////////////////////////////////////////////////////// | 53 //////////////////////////////////////////////////////////////////////////////// |
| 52 | 54 |
| 55 #ifdef SK_SUPPORT_LEGACY_GRTYPES |
| 53 | 56 |
| 54 /** | 57 /** |
| 55 * Macro to round n up to the next multiple of 4, or return it unchanged if | 58 * Macro to round n up to the next multiple of 4, or return it unchanged if |
| 56 * n is already a multiple of 4 | 59 * n is already a multiple of 4 |
| 57 */ | 60 */ |
| 58 #define GrALIGN4(n) SkAlign4(n) | 61 #define GrALIGN4(n) SkAlign4(n) |
| 59 #define GrIsALIGN4(n) SkIsAlign4(n) | 62 #define GrIsALIGN4(n) SkIsAlign4(n) |
| 60 | 63 |
| 61 template <typename T> const T& GrMin(const T& a, const T& b) { | 64 template <typename T> const T& GrMin(const T& a, const T& b) { |
| 62 return (a < b) ? a : b; | 65 return (a < b) ? a : b; |
| 63 } | 66 } |
| 64 | 67 |
| 65 template <typename T> const T& GrMax(const T& a, const T& b) { | 68 template <typename T> const T& GrMax(const T& a, const T& b) { |
| 66 return (b < a) ? a : b; | 69 return (b < a) ? a : b; |
| 67 } | 70 } |
| 68 | 71 |
| 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 |
| 69 // compile time versions of min/max | 97 // compile time versions of min/max |
| 70 #define GR_CT_MAX(a, b) (((b) < (a)) ? (a) : (b)) | 98 #define GR_CT_MAX(a, b) (((b) < (a)) ? (a) : (b)) |
| 71 #define GR_CT_MIN(a, b) (((b) < (a)) ? (b) : (a)) | 99 #define GR_CT_MIN(a, b) (((b) < (a)) ? (b) : (a)) |
| 72 | 100 |
| 73 /** | 101 /** |
| 74 * divide, rounding up | 102 * divide, rounding up |
| 75 */ | 103 */ |
| 76 static inline int32_t GrIDivRoundUp(int x, int y) { | 104 static inline int32_t GrIDivRoundUp(int x, int y) { |
| 77 SkASSERT(y > 0); | 105 SkASSERT(y > 0); |
| 78 return (x + (y-1)) / y; | 106 return (x + (y-1)) / y; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 /** | 141 /** |
| 114 * align down | 142 * align down |
| 115 */ | 143 */ |
| 116 static inline uint32_t GrUIAlignDown(uint32_t x, uint32_t alignment) { | 144 static inline uint32_t GrUIAlignDown(uint32_t x, uint32_t alignment) { |
| 117 return (x / alignment) * alignment; | 145 return (x / alignment) * alignment; |
| 118 } | 146 } |
| 119 static inline size_t GrSizeAlignDown(size_t x, uint32_t alignment) { | 147 static inline size_t GrSizeAlignDown(size_t x, uint32_t alignment) { |
| 120 return (x / alignment) * alignment; | 148 return (x / alignment) * alignment; |
| 121 } | 149 } |
| 122 | 150 |
| 123 /** | |
| 124 * Count elements in an array | |
| 125 */ | |
| 126 #define GR_ARRAY_COUNT(array) SK_ARRAY_COUNT(array) | |
| 127 | |
| 128 /////////////////////////////////////////////////////////////////////////////// | 151 /////////////////////////////////////////////////////////////////////////////// |
| 129 | 152 |
| 130 /** | 153 /** |
| 131 * Return true if n is a power of 2 | 154 * Return true if n is a power of 2 |
| 132 */ | 155 */ |
| 133 static inline bool GrIsPow2(unsigned n) { | 156 static inline bool GrIsPow2(unsigned n) { |
| 134 return n && 0 == (n & (n - 1)); | 157 return n && 0 == (n & (n - 1)); |
| 135 } | 158 } |
| 136 | 159 |
| 137 /** | 160 /** |
| 138 * Return the next power of 2 >= n. | 161 * Return the next power of 2 >= n. |
| 139 */ | 162 */ |
| 140 static inline uint32_t GrNextPow2(uint32_t n) { | 163 static inline uint32_t GrNextPow2(uint32_t n) { |
| 141 return n ? (1 << (32 - SkCLZ(n - 1))) : 1; | 164 return n ? (1 << (32 - SkCLZ(n - 1))) : 1; |
| 142 } | 165 } |
| 143 | 166 |
| 144 static inline int GrNextPow2(int n) { | 167 static inline int GrNextPow2(int n) { |
| 145 SkASSERT(n >= 0); // this impl only works for non-neg. | 168 SkASSERT(n >= 0); // this impl only works for non-neg. |
| 146 return n ? (1 << (32 - SkCLZ(n - 1))) : 1; | 169 return n ? (1 << (32 - SkCLZ(n - 1))) : 1; |
| 147 } | 170 } |
| 148 | 171 |
| 149 /////////////////////////////////////////////////////////////////////////////// | 172 /////////////////////////////////////////////////////////////////////////////// |
| 150 | 173 |
| 151 /** | 174 /** |
| 152 * 16.16 fixed point type | |
| 153 */ | |
| 154 typedef int32_t GrFixed; | |
| 155 | |
| 156 #ifdef SK_DEBUG | |
| 157 | |
| 158 static inline int16_t GrToS16(intptr_t x) { | |
| 159 SkASSERT((int16_t)x == x); | |
| 160 return (int16_t)x; | |
| 161 } | |
| 162 | |
| 163 #else | |
| 164 | |
| 165 #define GrToS16(x) x | |
| 166 | |
| 167 #endif | |
| 168 | |
| 169 | |
| 170 /////////////////////////////////////////////////////////////////////////////// | |
| 171 | |
| 172 /** | |
| 173 * Possible 3D APIs that may be used by Ganesh. | 175 * Possible 3D APIs that may be used by Ganesh. |
| 174 */ | 176 */ |
| 175 enum GrBackend { | 177 enum GrBackend { |
| 176 kOpenGL_GrBackend, | 178 kOpenGL_GrBackend, |
| 177 }; | 179 }; |
| 178 | 180 |
| 179 /** | 181 /** |
| 180 * Backend-specific 3D context handle | 182 * Backend-specific 3D context handle |
| 181 * GrGLInterface* for OpenGL. If NULL will use the default GL interface. | 183 * GrGLInterface* for OpenGL. If NULL will use the default GL interface. |
| 182 */ | 184 */ |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 }; | 620 }; |
| 619 | 621 |
| 620 /** | 622 /** |
| 621 * This value translates to reseting all the context state for any backend. | 623 * This value translates to reseting all the context state for any backend. |
| 622 */ | 624 */ |
| 623 static const uint32_t kAll_GrBackendState = 0xffffffff; | 625 static const uint32_t kAll_GrBackendState = 0xffffffff; |
| 624 | 626 |
| 625 /////////////////////////////////////////////////////////////////////////////// | 627 /////////////////////////////////////////////////////////////////////////////// |
| 626 | 628 |
| 627 #endif | 629 #endif |
| OLD | NEW |