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

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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

mercurial