OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
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 #ifndef SkTypes_DEFINED | 10 #ifndef SkTypes_DEFINED |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 | 278 |
279 /** Generic swap function. Classes with efficient swaps should specialize this f
unction to take | 279 /** Generic swap function. Classes with efficient swaps should specialize this f
unction to take |
280 their fast path. This function is used by SkTSort. */ | 280 their fast path. This function is used by SkTSort. */ |
281 template <typename T> inline void SkTSwap(T& a, T& b) { | 281 template <typename T> inline void SkTSwap(T& a, T& b) { |
282 T c(a); | 282 T c(a); |
283 a = b; | 283 a = b; |
284 b = c; | 284 b = c; |
285 } | 285 } |
286 | 286 |
287 static inline int32_t SkAbs32(int32_t value) { | 287 static inline int32_t SkAbs32(int32_t value) { |
288 #ifdef SK_CPU_HAS_CONDITIONAL_INSTR | 288 if (value < 0) { |
289 if (value < 0) | |
290 value = -value; | 289 value = -value; |
| 290 } |
291 return value; | 291 return value; |
292 #else | |
293 int32_t mask = value >> 31; | |
294 return (value ^ mask) - mask; | |
295 #endif | |
296 } | 292 } |
297 | 293 |
298 template <typename T> inline T SkTAbs(T value) { | 294 template <typename T> inline T SkTAbs(T value) { |
299 if (value < 0) { | 295 if (value < 0) { |
300 value = -value; | 296 value = -value; |
301 } | 297 } |
302 return value; | 298 return value; |
303 } | 299 } |
304 | 300 |
305 static inline int32_t SkMax32(int32_t a, int32_t b) { | 301 static inline int32_t SkMax32(int32_t a, int32_t b) { |
(...skipping 14 matching lines...) Expand all Loading... |
320 | 316 |
321 template <typename T> const T& SkTMax(const T& a, const T& b) { | 317 template <typename T> const T& SkTMax(const T& a, const T& b) { |
322 return (b < a) ? a : b; | 318 return (b < a) ? a : b; |
323 } | 319 } |
324 | 320 |
325 static inline int32_t SkSign32(int32_t a) { | 321 static inline int32_t SkSign32(int32_t a) { |
326 return (a >> 31) | ((unsigned) -a >> 31); | 322 return (a >> 31) | ((unsigned) -a >> 31); |
327 } | 323 } |
328 | 324 |
329 static inline int32_t SkFastMin32(int32_t value, int32_t max) { | 325 static inline int32_t SkFastMin32(int32_t value, int32_t max) { |
330 #ifdef SK_CPU_HAS_CONDITIONAL_INSTR | 326 if (value > max) { |
331 if (value > max) | |
332 value = max; | 327 value = max; |
| 328 } |
333 return value; | 329 return value; |
334 #else | |
335 int diff = max - value; | |
336 // clear diff if it is negative (clear if value > max) | |
337 diff &= (diff >> 31); | |
338 return value + diff; | |
339 #endif | |
340 } | 330 } |
341 | 331 |
342 /** Returns signed 32 bit value pinned between min and max, inclusively | 332 /** Returns signed 32 bit value pinned between min and max, inclusively |
343 */ | 333 */ |
344 static inline int32_t SkPin32(int32_t value, int32_t min, int32_t max) { | 334 static inline int32_t SkPin32(int32_t value, int32_t min, int32_t max) { |
345 #ifdef SK_CPU_HAS_CONDITIONAL_INSTR | 335 if (value < min) { |
346 if (value < min) | |
347 value = min; | 336 value = min; |
348 if (value > max) | 337 } |
| 338 if (value > max) { |
349 value = max; | 339 value = max; |
350 #else | 340 } |
351 if (value < min) | |
352 value = min; | |
353 else if (value > max) | |
354 value = max; | |
355 #endif | |
356 return value; | 341 return value; |
357 } | 342 } |
358 | 343 |
359 static inline uint32_t SkSetClearShift(uint32_t bits, bool cond, | 344 static inline uint32_t SkSetClearShift(uint32_t bits, bool cond, |
360 unsigned shift) { | 345 unsigned shift) { |
361 SkASSERT((int)cond == 0 || (int)cond == 1); | 346 SkASSERT((int)cond == 0 || (int)cond == 1); |
362 return (bits & ~(1 << shift)) | ((int)cond << shift); | 347 return (bits & ~(1 << shift)) | ((int)cond << shift); |
363 } | 348 } |
364 | 349 |
365 static inline uint32_t SkSetClearMask(uint32_t bits, bool cond, | 350 static inline uint32_t SkSetClearMask(uint32_t bits, bool cond, |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
613 | 598 |
614 private: | 599 private: |
615 void* fPtr; | 600 void* fPtr; |
616 size_t fSize; // can be larger than the requested size (see kReuse) | 601 size_t fSize; // can be larger than the requested size (see kReuse) |
617 uint32_t fStorage[(kSize + 3) >> 2]; | 602 uint32_t fStorage[(kSize + 3) >> 2]; |
618 }; | 603 }; |
619 | 604 |
620 #endif /* C++ */ | 605 #endif /* C++ */ |
621 | 606 |
622 #endif | 607 #endif |
OLD | NEW |