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 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 } | 67 } |
68 | 68 |
69 // compile time versions of min/max | 69 // compile time versions of min/max |
70 #define GR_CT_MAX(a, b) (((b) < (a)) ? (a) : (b)) | 70 #define GR_CT_MAX(a, b) (((b) < (a)) ? (a) : (b)) |
71 #define GR_CT_MIN(a, b) (((b) < (a)) ? (b) : (a)) | 71 #define GR_CT_MIN(a, b) (((b) < (a)) ? (b) : (a)) |
72 | 72 |
73 /** | 73 /** |
74 * divide, rounding up | 74 * divide, rounding up |
75 */ | 75 */ |
76 static inline int32_t GrIDivRoundUp(int x, int y) { | 76 static inline int32_t GrIDivRoundUp(int x, int y) { |
77 GrAssert(y > 0); | 77 SkASSERT(y > 0); |
78 return (x + (y-1)) / y; | 78 return (x + (y-1)) / y; |
79 } | 79 } |
80 static inline uint32_t GrUIDivRoundUp(uint32_t x, uint32_t y) { | 80 static inline uint32_t GrUIDivRoundUp(uint32_t x, uint32_t y) { |
81 return (x + (y-1)) / y; | 81 return (x + (y-1)) / y; |
82 } | 82 } |
83 static inline size_t GrSizeDivRoundUp(size_t x, size_t y) { | 83 static inline size_t GrSizeDivRoundUp(size_t x, size_t y) { |
84 return (x + (y-1)) / y; | 84 return (x + (y-1)) / y; |
85 } | 85 } |
86 | 86 |
87 // compile time, evaluates Y multiple times | 87 // compile time, evaluates Y multiple times |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 } | 145 } |
146 | 146 |
147 /** | 147 /** |
148 * Return the next power of 2 >= n. | 148 * Return the next power of 2 >= n. |
149 */ | 149 */ |
150 static inline uint32_t GrNextPow2(uint32_t n) { | 150 static inline uint32_t GrNextPow2(uint32_t n) { |
151 return n ? (1 << (32 - SkCLZ(n - 1))) : 1; | 151 return n ? (1 << (32 - SkCLZ(n - 1))) : 1; |
152 } | 152 } |
153 | 153 |
154 static inline int GrNextPow2(int n) { | 154 static inline int GrNextPow2(int n) { |
155 GrAssert(n >= 0); // this impl only works for non-neg. | 155 SkASSERT(n >= 0); // this impl only works for non-neg. |
156 return n ? (1 << (32 - SkCLZ(n - 1))) : 1; | 156 return n ? (1 << (32 - SkCLZ(n - 1))) : 1; |
157 } | 157 } |
158 | 158 |
159 /////////////////////////////////////////////////////////////////////////////// | 159 /////////////////////////////////////////////////////////////////////////////// |
160 | 160 |
161 /** | 161 /** |
162 * 16.16 fixed point type | 162 * 16.16 fixed point type |
163 */ | 163 */ |
164 typedef int32_t GrFixed; | 164 typedef int32_t GrFixed; |
165 | 165 |
166 #if GR_DEBUG | 166 #if GR_DEBUG |
167 | 167 |
168 static inline int16_t GrToS16(intptr_t x) { | 168 static inline int16_t GrToS16(intptr_t x) { |
169 GrAssert((int16_t)x == x); | 169 SkASSERT((int16_t)x == x); |
170 return (int16_t)x; | 170 return (int16_t)x; |
171 } | 171 } |
172 | 172 |
173 #else | 173 #else |
174 | 174 |
175 #define GrToS16(x) x | 175 #define GrToS16(x) x |
176 | 176 |
177 #endif | 177 #endif |
178 | 178 |
179 | 179 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 kA565_GrMaskFormat, //!< 2-bytes per pixel | 249 kA565_GrMaskFormat, //!< 2-bytes per pixel |
250 kA888_GrMaskFormat, //!< 4-bytes per pixel | 250 kA888_GrMaskFormat, //!< 4-bytes per pixel |
251 | 251 |
252 kCount_GrMaskFormats //!< used to allocate arrays sized for mask formats | 252 kCount_GrMaskFormats //!< used to allocate arrays sized for mask formats |
253 }; | 253 }; |
254 | 254 |
255 /** | 255 /** |
256 * Return the number of bytes-per-pixel for the specified mask format. | 256 * Return the number of bytes-per-pixel for the specified mask format. |
257 */ | 257 */ |
258 static inline int GrMaskFormatBytesPerPixel(GrMaskFormat format) { | 258 static inline int GrMaskFormatBytesPerPixel(GrMaskFormat format) { |
259 GrAssert((unsigned)format <= 2); | 259 SkASSERT((unsigned)format <= 2); |
260 // kA8 (0) -> 1 | 260 // kA8 (0) -> 1 |
261 // kA565 (1) -> 2 | 261 // kA565 (1) -> 2 |
262 // kA888 (2) -> 4 | 262 // kA888 (2) -> 4 |
263 return 1 << (int)format; | 263 return 1 << (int)format; |
264 } | 264 } |
265 | 265 |
266 /** | 266 /** |
267 * Pixel configurations. | 267 * Pixel configurations. |
268 */ | 268 */ |
269 enum GrPixelConfig { | 269 enum GrPixelConfig { |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 | 465 |
466 /** | 466 /** |
467 * A default cache ID is invalid; a set method must be called before the obj
ect is used. | 467 * A default cache ID is invalid; a set method must be called before the obj
ect is used. |
468 */ | 468 */ |
469 GrCacheID() { fDomain = kInvalid_Domain; } | 469 GrCacheID() { fDomain = kInvalid_Domain; } |
470 | 470 |
471 /** | 471 /** |
472 * Initialize the cache ID to a domain and key. | 472 * Initialize the cache ID to a domain and key. |
473 */ | 473 */ |
474 GrCacheID(Domain domain, const Key& key) { | 474 GrCacheID(Domain domain, const Key& key) { |
475 GrAssert(kInvalid_Domain != domain); | 475 SkASSERT(kInvalid_Domain != domain); |
476 this->reset(domain, key); | 476 this->reset(domain, key); |
477 } | 477 } |
478 | 478 |
479 void reset(Domain domain, const Key& key) { | 479 void reset(Domain domain, const Key& key) { |
480 fDomain = domain; | 480 fDomain = domain; |
481 memcpy(&fKey, &key, sizeof(Key)); | 481 memcpy(&fKey, &key, sizeof(Key)); |
482 } | 482 } |
483 | 483 |
484 /** Has this been initialized to a valid domain */ | 484 /** Has this been initialized to a valid domain */ |
485 bool isValid() const { return kInvalid_Domain != fDomain; } | 485 bool isValid() const { return kInvalid_Domain != fDomain; } |
486 | 486 |
487 const Key& getKey() const { GrAssert(this->isValid()); return fKey; } | 487 const Key& getKey() const { SkASSERT(this->isValid()); return fKey; } |
488 Domain getDomain() const { GrAssert(this->isValid()); return fDomain; } | 488 Domain getDomain() const { SkASSERT(this->isValid()); return fDomain; } |
489 | 489 |
490 /** Creates a new unique ID domain. */ | 490 /** Creates a new unique ID domain. */ |
491 static Domain GenerateDomain(); | 491 static Domain GenerateDomain(); |
492 | 492 |
493 private: | 493 private: |
494 Key fKey; | 494 Key fKey; |
495 Domain fDomain; | 495 Domain fDomain; |
496 | 496 |
497 static const Domain kInvalid_Domain = 0; | 497 static const Domain kInvalid_Domain = 0; |
498 }; | 498 }; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 }; | 621 }; |
622 | 622 |
623 /** | 623 /** |
624 * This value translates to reseting all the context state for any backend. | 624 * This value translates to reseting all the context state for any backend. |
625 */ | 625 */ |
626 static const uint32_t kAll_GrBackendState = 0xffffffff; | 626 static const uint32_t kAll_GrBackendState = 0xffffffff; |
627 | 627 |
628 /////////////////////////////////////////////////////////////////////////////// | 628 /////////////////////////////////////////////////////////////////////////////// |
629 | 629 |
630 #endif | 630 #endif |
OLD | NEW |