gfx/skia/trunk/src/core/SkBitmapProcState_utils.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/core/SkBitmapProcState_utils.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,40 @@
     1.4 +#ifndef SkBitmapProcState_utils_DEFINED
     1.5 +#define SkBitmapProcState_utils_DEFINED
     1.6 +
     1.7 +// Helper to ensure that when we shift down, we do it w/o sign-extension
     1.8 +// so the caller doesn't have to manually mask off the top 16 bits
     1.9 +//
    1.10 +static unsigned SK_USHIFT16(unsigned x) {
    1.11 +    return x >> 16;
    1.12 +}
    1.13 +
    1.14 +/*
    1.15 + *  The decal_ functions require that
    1.16 + *  1. dx > 0
    1.17 + *  2. [fx, fx+dx, fx+2dx, fx+3dx, ... fx+(count-1)dx] are all <= maxX
    1.18 + *
    1.19 + *  In addition, we use SkFractionalInt to keep more fractional precision than
    1.20 + *  just SkFixed, so we will abort the decal_ call if dx is very small, since
    1.21 + *  the decal_ function just operates on SkFixed. If that were changed, we could
    1.22 + *  skip the very_small test here.
    1.23 + */
    1.24 +static inline bool can_truncate_to_fixed_for_decal(SkFractionalInt frX,
    1.25 +                                                   SkFractionalInt frDx,
    1.26 +                                                   int count, unsigned max) {
    1.27 +    SkFixed dx = SkFractionalIntToFixed(frDx);
    1.28 +
    1.29 +    // if decal_ kept SkFractionalInt precision, this would just be dx <= 0
    1.30 +    // I just made up the 1/256. Just don't want to perceive accumulated error
    1.31 +    // if we truncate frDx and lose its low bits.
    1.32 +    if (dx <= SK_Fixed1 / 256) {
    1.33 +        return false;
    1.34 +    }
    1.35 +
    1.36 +    // We cast to unsigned so we don't have to check for negative values, which
    1.37 +    // will now appear as very large positive values, and thus fail our test!
    1.38 +    SkFixed fx = SkFractionalIntToFixed(frX);
    1.39 +    return (unsigned)SkFixedFloorToInt(fx) <= max &&
    1.40 +           (unsigned)SkFixedFloorToInt(fx + dx * (count - 1)) < max;
    1.41 +}
    1.42 +
    1.43 +#endif /* #ifndef SkBitmapProcState_utils_DEFINED */

mercurial