gfx/skia/trunk/src/core/SkMathPriv.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.

     1 /*
     2  * Copyright 2012 Google Inc.
     3  *
     4  * Use of this source code is governed by a BSD-style license that can be
     5  * found in the LICENSE file.
     6  */
     8 #ifndef SkMathPriv_DEFINED
     9 #define SkMathPriv_DEFINED
    11 #include "SkMath.h"
    13 /** Returns -1 if n < 0, else returns 0
    14  */
    15 #define SkExtractSign(n)    ((int32_t)(n) >> 31)
    17 /** If sign == -1, returns -n, else sign must be 0, and returns n.
    18  Typically used in conjunction with SkExtractSign().
    19  */
    20 static inline int32_t SkApplySign(int32_t n, int32_t sign) {
    21     SkASSERT(sign == 0 || sign == -1);
    22     return (n ^ sign) - sign;
    23 }
    25 /** Return x with the sign of y */
    26 static inline int32_t SkCopySign32(int32_t x, int32_t y) {
    27     return SkApplySign(x, SkExtractSign(x ^ y));
    28 }
    30 /** Given a positive value and a positive max, return the value
    31  pinned against max.
    32  Note: only works as long as max - value doesn't wrap around
    33  @return max if value >= max, else value
    34  */
    35 static inline unsigned SkClampUMax(unsigned value, unsigned max) {
    36     if (value > max) {
    37         value = max;
    38     }
    39     return value;
    40 }
    42 ///////////////////////////////////////////////////////////////////////////////
    44 /** Return a*b/255, truncating away any fractional bits. Only valid if both
    45  a and b are 0..255
    46  */
    47 static inline U8CPU SkMulDiv255Trunc(U8CPU a, U8CPU b) {
    48     SkASSERT((uint8_t)a == a);
    49     SkASSERT((uint8_t)b == b);
    50     unsigned prod = SkMulS16(a, b) + 1;
    51     return (prod + (prod >> 8)) >> 8;
    52 }
    54 /** Return (a*b)/255, taking the ceiling of any fractional bits. Only valid if
    55  both a and b are 0..255. The expected result equals (a * b + 254) / 255.
    56  */
    57 static inline U8CPU SkMulDiv255Ceiling(U8CPU a, U8CPU b) {
    58     SkASSERT((uint8_t)a == a);
    59     SkASSERT((uint8_t)b == b);
    60     unsigned prod = SkMulS16(a, b) + 255;
    61     return (prod + (prod >> 8)) >> 8;
    62 }
    64 /** Just the rounding step in SkDiv255Round: round(value / 255)
    65  */
    66 static inline unsigned SkDiv255Round(unsigned prod) {
    67     prod += 128;
    68     return (prod + (prod >> 8)) >> 8;
    69 }
    71 #endif

mercurial