Chromium Code Reviews| Index: include/core/SkColorPriv.h |
| diff --git a/include/core/SkColorPriv.h b/include/core/SkColorPriv.h |
| index 7a74c4a034b24a079504fd790a92bcd67014f73f..de2b6489403debc6385859425606fcbd5d5de6e1 100644 |
| --- a/include/core/SkColorPriv.h |
| +++ b/include/core/SkColorPriv.h |
| @@ -1,4 +1,3 @@ |
| - |
| /* |
| * Copyright 2006 The Android Open Source Project |
| * |
| @@ -6,7 +5,6 @@ |
| * found in the LICENSE file. |
| */ |
| - |
| #ifndef SkColorPriv_DEFINED |
| #define SkColorPriv_DEFINED |
| @@ -18,6 +16,80 @@ |
| #include "SkColor.h" |
| #include "SkMath.h" |
| +////////////////////////////////////////////////////////////////////////////// |
| + |
| +#define SkASSERT_IS_BYTE(x) SkASSERT(0 == ((x) & 0xFF)) |
|
bsalomon
2014/03/19 12:36:48
Isn't this asserting that the lower 8 are zero?
reed1
2014/03/19 17:59:58
Doh!
|
| + |
| +/* |
| + * Skia's 32bit backend only supports 1 sizzle order at a time (compile-time). |
| + * This is specified by 4 defines SK_A32_SHIFT, SK_R32_SHIFT, ... for G and B. |
| + * |
| + * For easier compatibility with Skia's GPU backend, we further restrict these |
| + * to either (in memory-byte-order) RGBA or BGRA. Note that this "order" does |
| + * not directly correspond to the same shift-order, since we have to take endianess |
| + * into account. |
| + * |
| + * Here we enforce this constraint. |
| + */ |
| + |
| +#ifdef SK_CPU_BENDIAN |
| + #define SK_RGBA_R32_SHIFT 24 |
| + #define SK_RGBA_G32_SHIFT 16 |
| + #define SK_RGBA_B32_SHIFT 8 |
| + #define SK_RGBA_A32_SHIFT 0 |
| + |
| + #define SK_BGRA_B32_SHIFT 24 |
| + #define SK_BGRA_G32_SHIFT 16 |
| + #define SK_BGRA_R32_SHIFT 8 |
| + #define SK_BGRA_A32_SHIFT 0 |
| +#else |
| + #define SK_RGBA_R32_SHIFT 0 |
| + #define SK_RGBA_G32_SHIFT 8 |
| + #define SK_RGBA_B32_SHIFT 16 |
| + #define SK_RGBA_A32_SHIFT 24 |
| + |
| + #define SK_BGRA_B32_SHIFT 0 |
| + #define SK_BGRA_G32_SHIFT 8 |
| + #define SK_BGRA_R32_SHIFT 16 |
| + #define SK_BGRA_A32_SHIFT 24 |
| +#endif |
| + |
| +// Now we check that we are in a support shift-order |
| + |
| +#if SK_A32_SHIFT == SK_RGBA_A32_SHIFT && \ |
| + SK_R32_SHIFT == SK_RGBA_R32_SHIFT && \ |
| + SK_G32_SHIFT == SK_RGBA_G32_SHIFT && \ |
| + SK_B32_SHIFT == SK_RGBA_B32_SHIFT |
| + #define SK_PMCOLOR_IS_RGBA |
|
bsalomon
2014/03/19 12:36:48
It'd be nice to allow the user (SkUserConfig.h, gy
reed1
2014/03/19 17:59:58
I can try adding checks now that if they've specif
|
| +#elif SK_A32_SHIFT == SK_BGRA_A32_SHIFT && \ |
| + SK_R32_SHIFT == SK_BGRA_R32_SHIFT && \ |
| + SK_G32_SHIFT == SK_BGRA_G32_SHIFT && \ |
| + SK_B32_SHIFT == SK_BGRA_B32_SHIFT |
| + #define SK_PMCOLOR_IS_BGRA |
| +#else |
| + #error "need 32bit packing to be either RGBA or BGRA" |
| +#endif |
| + |
| +static inline uint32_t SkPackARGB_as_RGBA(U8CPU a, U8CPU r, U8CPU g, U8CPU b) { |
| + SkASSERT_IS_BYTE(a); |
| + SkASSERT_IS_BYTE(r); |
| + SkASSERT_IS_BYTE(g); |
| + SkASSERT_IS_BYTE(b); |
| + return (a << SK_RGBA_A32_SHIFT) | (r << SK_RGBA_R32_SHIFT) | |
| + (g << SK_RGBA_G32_SHIFT) | (b << SK_RGBA_B32_SHIFT); |
| +} |
| + |
| +static inline uint32_t SkPackARGB_as_BGRA(U8CPU a, U8CPU r, U8CPU g, U8CPU b) { |
| + SkASSERT_IS_BYTE(a); |
| + SkASSERT_IS_BYTE(r); |
| + SkASSERT_IS_BYTE(g); |
| + SkASSERT_IS_BYTE(b); |
| + return (a << SK_BGRA_A32_SHIFT) | (r << SK_BGRA_R32_SHIFT) | |
| + (g << SK_BGRA_G32_SHIFT) | (b << SK_BGRA_B32_SHIFT); |
| +} |
| + |
| +////////////////////////////////////////////////////////////////////////////// |
| + |
| ///@{ |
| /** See ITU-R Recommendation BT.709 at http://www.itu.int/rec/R-REC-BT.709/ .*/ |
| #define SK_ITU_BT709_LUM_COEFF_R (0.2126f) |
| @@ -239,6 +311,16 @@ static inline SkPMColor SkPackARGB32(U8CPU a, U8CPU r, U8CPU g, U8CPU b) { |
| (g << SK_G32_SHIFT) | (b << SK_B32_SHIFT); |
| } |
| +static inline uint32_t SkPackPMColor_as_RGBA(SkPMColor c) { |
| + return SkPackARGB_as_RGBA(SkGetPackedA32(c), SkGetPackedR32(c), |
| + SkGetPackedG32(c), SkGetPackedB32(c)); |
| +} |
| + |
| +static inline uint32_t SkPackPMColor_as_BGRA(SkPMColor c) { |
| + return SkPackARGB_as_BGRA(SkGetPackedA32(c), SkGetPackedR32(c), |
| + SkGetPackedG32(c), SkGetPackedB32(c)); |
| +} |
| + |
| /** |
| * Abstract 4-byte interpolation, implemented on top of SkPMColor |
| * utility functions. Third parameter controls blending of the first two: |