aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/core/SkColor.h
diff options
context:
space:
mode:
authorGravatar agl@chromium.org <agl@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2010-07-28 17:10:30 +0000
committerGravatar agl@chromium.org <agl@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2010-07-28 17:10:30 +0000
commitc9c9ebbc29b62e7d3b06ff18023b09faeb49d618 (patch)
tree813e8d47380c89a4ce74877b02b0513cd42a9997 /include/core/SkColor.h
parent0afaf9b563c79ddafbceec5389806061b0989916 (diff)
Make SKColorSetARGB() a macro when not building debug.
This allows GCC to avoid generating static initializers for code that uses it. Patch by: Dave Moore http://codereview.appspot.com/1883043/show git-svn-id: http://skia.googlecode.com/svn/trunk@592 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include/core/SkColor.h')
-rw-r--r--include/core/SkColor.h19
1 files changed, 18 insertions, 1 deletions
diff --git a/include/core/SkColor.h b/include/core/SkColor.h
index c97a8ec4d1..c17068f4d8 100644
--- a/include/core/SkColor.h
+++ b/include/core/SkColor.h
@@ -36,13 +36,30 @@ typedef uint32_t SkColor;
/** Return a SkColor value from 8 bit component values
*/
-static inline SkColor SkColorSetARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
+static inline SkColor SkColorSetARGBInline(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
{
SkASSERT(a <= 255 && r <= 255 && g <= 255 && b <= 255);
return (a << 24) | (r << 16) | (g << 8) | (b << 0);
}
+#define SkColorSetARGBMacro(a, r, g, b) \
+ static_cast<SkColor>( \
+ (static_cast<U8CPU>(a) << 24) | \
+ (static_cast<U8CPU>(r) << 16) | \
+ (static_cast<U8CPU>(g) << 8) | \
+ (static_cast<U8CPU>(b) << 0))
+
+/** gcc will generate static initializers for code of this form:
+ * static const SkColor kMyColor = SkColorSetARGB(0xFF, 0x01, 0x02, 0x03)
+ * if SkColorSetARGB() is a static inline, but not if it's a macro.
+ */
+#if defined(NDEBUG)
+#define SkColorSetARGB(a, r, g, b) SkColorSetARGBMacro(a, r, g, b)
+#else
+#define SkColorSetARGB(a, r, g, b) SkColorSetARGBInline(a, r, g, b)
+#endif
+
/** Return a SkColor value from 8 bit component values, with an implied value
of 0xFF for alpha (fully opaque)
*/