Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / skia / include / core / SkColorPriv.h
index 6f23f9b..9db7687 100644 (file)
@@ -306,7 +306,8 @@ static inline void SkBlendRGB16(const uint16_t src[], uint16_t dst[],
     do {
         uint32_t src32 = SkExpand_rgb_16(*src++);
         uint32_t dst32 = SkExpand_rgb_16(*dst);
-        *dst++ = SkCompact_rgb_16(dst32 + ((src32 - dst32) * srcScale >> 5));
+        *dst++ = static_cast<uint16_t>(
+            SkCompact_rgb_16(dst32 + ((src32 - dst32) * srcScale >> 5)));
     } while (--count > 0);
 }
 
@@ -345,17 +346,15 @@ static inline void SkBlendRGB16(const uint16_t src[], uint16_t dst[],
 #define SkB32Assert(b)  SkASSERT((unsigned)(b) <= SK_B32_MASK)
 
 #ifdef SK_DEBUG
-    static inline void SkPMColorAssert(SkPMColor c) {
-        unsigned a = SkGetPackedA32(c);
-        unsigned r = SkGetPackedR32(c);
-        unsigned g = SkGetPackedG32(c);
-        unsigned b = SkGetPackedB32(c);
-
-        SkA32Assert(a);
-        SkASSERT(r <= a);
-        SkASSERT(g <= a);
-        SkASSERT(b <= a);
-    }
+    #define SkPMColorAssert(color_value)                                    \
+        do {                                                                \
+            SkPMColor pm_color_value = (color_value);                       \
+            uint32_t alpha_color_value = SkGetPackedA32(pm_color_value);    \
+            SkA32Assert(alpha_color_value);                                 \
+            SkASSERT(SkGetPackedR32(pm_color_value) <= alpha_color_value);  \
+            SkASSERT(SkGetPackedG32(pm_color_value) <= alpha_color_value);  \
+            SkASSERT(SkGetPackedB32(pm_color_value) <= alpha_color_value);  \
+        } while (false)
 #else
     #define SkPMColorAssert(c)
 #endif
@@ -787,7 +786,7 @@ static inline SkPMColor16 SkPackARGB4444(unsigned a, unsigned r,
                          (g << SK_G4444_SHIFT) | (b << SK_B4444_SHIFT));
 }
 
-static inline U16CPU SkAlphaMulQ4(U16CPU c, unsigned scale) {
+static inline SkPMColor16 SkAlphaMulQ4(SkPMColor16 c, int scale) {
     SkASSERT(scale <= 16);
 
     const unsigned mask = 0xF0F;    //gMask_0F0F;
@@ -797,14 +796,14 @@ static inline U16CPU SkAlphaMulQ4(U16CPU c, unsigned scale) {
     unsigned ag = ((c >> 4) & mask) * scale;
     return (rb & mask) | (ag & ~mask);
 #else
-    c = (c & mask) | ((c & (mask << 4)) << 12);
-    c = c * scale >> 4;
-    return (c & mask) | ((c >> 12) & (mask << 4));
+    unsigned expanded_c = (c & mask) | ((c & (mask << 4)) << 12);
+    unsigned scaled_c = (expanded_c * scale) >> 4;
+    return (scaled_c & mask) | ((scaled_c >> 12) & (mask << 4));
 #endif
 }
 
 /** Expand the SkPMColor16 color into a 32bit value that can be scaled all at
-    once by a value up to 16. Used in conjunction with SkCompact_4444.
+    once by a value up to 16.
 */
 static inline uint32_t SkExpand_4444(U16CPU c) {
     SkASSERT(c == (uint16_t)c);
@@ -813,18 +812,6 @@ static inline uint32_t SkExpand_4444(U16CPU c) {
     return (c & mask) | ((c & ~mask) << 12);
 }
 
-/** Compress an expanded value (from SkExpand_4444) back down to a SkPMColor16.
-    NOTE: this explicitly does not clean the top 16 bits (which may be garbage).
-    It does this for speed, since if it is being written directly to 16bits of
-    memory, the top 16bits will be ignored. Casting the result to uint16_t here
-    would add 2 more instructions, slow us down. It is up to the caller to
-    perform the cast if needed.
-*/
-static inline U16CPU SkCompact_4444(uint32_t c) {
-    const unsigned mask = 0xF0F;    //gMask_0F0F;
-    return (c & mask) | ((c >> 12) & ~mask);
-}
-
 static inline uint16_t SkSrcOver4444To16(SkPMColor16 s, uint16_t d) {
     unsigned sa = SkGetPackedA4444(s);
     unsigned sr = SkR4444ToR565(SkGetPackedR4444(s));
@@ -856,22 +843,6 @@ static inline uint16_t SkBlend4444To16(SkPMColor16 src, uint16_t dst, int scale1
     return SkSrcOver4444To16(SkAlphaMulQ4(src, scale16), dst);
 }
 
-static inline uint16_t SkBlend4444(SkPMColor16 src, SkPMColor16 dst, int scale16) {
-    SkASSERT((unsigned)scale16 <= 16);
-
-    uint32_t src32 = SkExpand_4444(src) * scale16;
-    // the scaled srcAlpha is the bottom byte
-#ifdef SK_DEBUG
-    {
-        unsigned srcA = SkGetPackedA4444(src) * scale16;
-        SkASSERT(srcA == (src32 & 0xFF));
-    }
-#endif
-    unsigned dstScale = SkAlpha255To256(255 - (src32 & 0xFF)) >> 4;
-    uint32_t dst32 = SkExpand_4444(dst) * dstScale;
-    return SkCompact_4444((src32 + dst32) >> 4);
-}
-
 static inline SkPMColor SkPixel4444ToPixel32(U16CPU c) {
     uint32_t d = (SkGetPackedA4444(c) << SK_A32_SHIFT) |
                  (SkGetPackedR4444(c) << SK_R32_SHIFT) |