commit-bot@chromium.org | a8c0966 | 2013-09-05 18:27:57 +0000 | [diff] [blame] | 1 | #ifndef SkBitmapProcState_utils_DEFINED |
| 2 | #define SkBitmapProcState_utils_DEFINED |
| 3 | |
| 4 | // Helper to ensure that when we shift down, we do it w/o sign-extension |
| 5 | // so the caller doesn't have to manually mask off the top 16 bits |
| 6 | // |
| 7 | static unsigned SK_USHIFT16(unsigned x) { |
| 8 | return x >> 16; |
| 9 | } |
| 10 | |
| 11 | /* |
| 12 | * The decal_ functions require that |
| 13 | * 1. dx > 0 |
| 14 | * 2. [fx, fx+dx, fx+2dx, fx+3dx, ... fx+(count-1)dx] are all <= maxX |
| 15 | * |
| 16 | * In addition, we use SkFractionalInt to keep more fractional precision than |
| 17 | * just SkFixed, so we will abort the decal_ call if dx is very small, since |
| 18 | * the decal_ function just operates on SkFixed. If that were changed, we could |
| 19 | * skip the very_small test here. |
| 20 | */ |
| 21 | static inline bool can_truncate_to_fixed_for_decal(SkFractionalInt frX, |
| 22 | SkFractionalInt frDx, |
| 23 | int count, unsigned max) { |
| 24 | SkFixed dx = SkFractionalIntToFixed(frDx); |
| 25 | |
| 26 | // if decal_ kept SkFractionalInt precision, this would just be dx <= 0 |
| 27 | // I just made up the 1/256. Just don't want to perceive accumulated error |
| 28 | // if we truncate frDx and lose its low bits. |
| 29 | if (dx <= SK_Fixed1 / 256) { |
| 30 | return false; |
| 31 | } |
| 32 | |
| 33 | // We cast to unsigned so we don't have to check for negative values, which |
| 34 | // will now appear as very large positive values, and thus fail our test! |
| 35 | SkFixed fx = SkFractionalIntToFixed(frX); |
| 36 | return (unsigned)SkFixedFloorToInt(fx) <= max && |
| 37 | (unsigned)SkFixedFloorToInt(fx + dx * (count - 1)) < max; |
| 38 | } |
| 39 | |
| 40 | #endif /* #ifndef SkBitmapProcState_utils_DEFINED */ |