Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / skia / include / gpu / GrColor.h
index cf7e7df..183781a 100644 (file)
 #include "GrTypes.h"
 
 /**
- *  GrColor is 4 bytes for R, G, B, A, in a compile-time specific order. The
- *  components are stored premultiplied.
+ * GrColor is 4 bytes for R, G, B, A, in a specific order defined below. The components are stored
+ * premultiplied.
  */
 typedef uint32_t GrColor;
 
-
 // shift amount to assign a component to a GrColor int
 // These shift values are chosen for compatibility with GL attrib arrays
 // ES doesn't allow BGRA vertex attrib order so if they were not in this order
-// we'd have to swizzle in shaders. Note the assumption that the cpu is little
-// endian.
-#define GrColor_SHIFT_R     0
-#define GrColor_SHIFT_G     8
-#define GrColor_SHIFT_B     16
-#define GrColor_SHIFT_A     24
+// we'd have to swizzle in shaders.
+#ifdef SK_CPU_BENDIAN
+    #define GrColor_SHIFT_R     24
+    #define GrColor_SHIFT_G     16
+    #define GrColor_SHIFT_B     8
+    #define GrColor_SHIFT_A     0
+#else
+    #define GrColor_SHIFT_R     0
+    #define GrColor_SHIFT_G     8
+    #define GrColor_SHIFT_B     16
+    #define GrColor_SHIFT_A     24
+#endif
 
 /**
  *  Pack 4 components (RGBA) into a GrColor int
@@ -58,6 +63,22 @@ static inline GrColor GrColorPackRGBA(unsigned r, unsigned g,
  */
 #define GrColor_ILLEGAL     (~(0xFF << GrColor_SHIFT_A))
 
+/**
+ * Assert in debug builds that a GrColor is premultiplied.
+ */
+static inline void GrColorIsPMAssert(GrColor c) {
+#ifdef SK_DEBUG
+    unsigned a = GrColorUnpackA(c);
+    unsigned r = GrColorUnpackR(c);
+    unsigned g = GrColorUnpackG(c);
+    unsigned b = GrColorUnpackB(c);
+
+    SkASSERT(r <= a);
+    SkASSERT(g <= a);
+    SkASSERT(b <= a);
+#endif
+}
+
 /** Converts a GrColor to an rgba array of GrGLfloat */
 static inline void GrColorToRGBAFloat(GrColor color, float rgba[4]) {
     static const float ONE_OVER_255 = 1.f / 255.f;
@@ -96,7 +117,7 @@ static inline char GrColorComponentFlagToChar(GrColorComponentFlags component) {
         case kA_GrColorComponentFlag:
             return 'a';
         default:
-            GrCrash("Invalid color component flag.");
+            SkFAIL("Invalid color component flag.");
             return '\0';
     }
 }