michael@0: #ifndef SkBitmapProcState_utils_DEFINED michael@0: #define SkBitmapProcState_utils_DEFINED michael@0: michael@0: // Helper to ensure that when we shift down, we do it w/o sign-extension michael@0: // so the caller doesn't have to manually mask off the top 16 bits michael@0: // michael@0: static unsigned SK_USHIFT16(unsigned x) { michael@0: return x >> 16; michael@0: } michael@0: michael@0: /* michael@0: * The decal_ functions require that michael@0: * 1. dx > 0 michael@0: * 2. [fx, fx+dx, fx+2dx, fx+3dx, ... fx+(count-1)dx] are all <= maxX michael@0: * michael@0: * In addition, we use SkFractionalInt to keep more fractional precision than michael@0: * just SkFixed, so we will abort the decal_ call if dx is very small, since michael@0: * the decal_ function just operates on SkFixed. If that were changed, we could michael@0: * skip the very_small test here. michael@0: */ michael@0: static inline bool can_truncate_to_fixed_for_decal(SkFractionalInt frX, michael@0: SkFractionalInt frDx, michael@0: int count, unsigned max) { michael@0: SkFixed dx = SkFractionalIntToFixed(frDx); michael@0: michael@0: // if decal_ kept SkFractionalInt precision, this would just be dx <= 0 michael@0: // I just made up the 1/256. Just don't want to perceive accumulated error michael@0: // if we truncate frDx and lose its low bits. michael@0: if (dx <= SK_Fixed1 / 256) { michael@0: return false; michael@0: } michael@0: michael@0: // We cast to unsigned so we don't have to check for negative values, which michael@0: // will now appear as very large positive values, and thus fail our test! michael@0: SkFixed fx = SkFractionalIntToFixed(frX); michael@0: return (unsigned)SkFixedFloorToInt(fx) <= max && michael@0: (unsigned)SkFixedFloorToInt(fx + dx * (count - 1)) < max; michael@0: } michael@0: michael@0: #endif /* #ifndef SkBitmapProcState_utils_DEFINED */