Title: [149710] trunk/Source/WebCore
Revision
149710
Author
benja...@webkit.org
Date
2013-05-07 20:18:12 -0700 (Tue, 07 May 2013)

Log Message

Make CanvasStyle's CMYKAValues allocated on the heap and move the pointer in the union.
https://bugs.webkit.org/show_bug.cgi?id=115764

Patch by Benjamin Poulain <bpoul...@apple.com> on 2013-05-07
Reviewed by Andreas Kling.

CMYKA input is uncommon enough that we should not pay the price for
every CanvasStyle.
Make those values heap allocated and put the pointer in the union. Since
the RGBA32 values are needed for CMYKA, a RGBA32 value is added to the structure.

* html/canvas/CanvasStyle.cpp:
(WebCore::CanvasStyle::CanvasStyle):
(WebCore::CanvasStyle::~CanvasStyle):
(WebCore::CanvasStyle::isEquivalentColor):
(WebCore::CanvasStyle::isEquivalentCMYKA):
(WebCore::CanvasStyle::applyStrokeColor):
(WebCore::CanvasStyle::applyFillColor):
* html/canvas/CanvasStyle.h:
(CanvasStyle):
(CMYKAValues):
(WebCore::CanvasStyle::CMYKAValues::CMYKAValues):
(WebCore::CanvasStyle::color):
(WebCore):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (149709 => 149710)


--- trunk/Source/WebCore/ChangeLog	2013-05-08 02:41:08 UTC (rev 149709)
+++ trunk/Source/WebCore/ChangeLog	2013-05-08 03:18:12 UTC (rev 149710)
@@ -1,3 +1,29 @@
+2013-05-07  Benjamin Poulain  <bpoul...@apple.com>
+
+        Make CanvasStyle's CMYKAValues allocated on the heap and move the pointer in the union.
+        https://bugs.webkit.org/show_bug.cgi?id=115764
+
+        Reviewed by Andreas Kling.
+
+        CMYKA input is uncommon enough that we should not pay the price for
+        every CanvasStyle.
+        Make those values heap allocated and put the pointer in the union. Since
+        the RGBA32 values are needed for CMYKA, a RGBA32 value is added to the structure.
+
+        * html/canvas/CanvasStyle.cpp:
+        (WebCore::CanvasStyle::CanvasStyle):
+        (WebCore::CanvasStyle::~CanvasStyle):
+        (WebCore::CanvasStyle::isEquivalentColor):
+        (WebCore::CanvasStyle::isEquivalentCMYKA):
+        (WebCore::CanvasStyle::applyStrokeColor):
+        (WebCore::CanvasStyle::applyFillColor):
+        * html/canvas/CanvasStyle.h:
+        (CanvasStyle):
+        (CMYKAValues):
+        (WebCore::CanvasStyle::CMYKAValues::CMYKAValues):
+        (WebCore::CanvasStyle::color):
+        (WebCore):
+
 2013-05-07  Darin Adler  <da...@apple.com>
 
         Use OwnPtr instead of deleteAllValues for requests in PluginView

Modified: trunk/Source/WebCore/html/canvas/CanvasStyle.cpp (149709 => 149710)


--- trunk/Source/WebCore/html/canvas/CanvasStyle.cpp	2013-05-08 02:41:08 UTC (rev 149709)
+++ trunk/Source/WebCore/html/canvas/CanvasStyle.cpp	2013-05-08 03:18:12 UTC (rev 149710)
@@ -118,8 +118,7 @@
 
 CanvasStyle::CanvasStyle(float c, float m, float y, float k, float a)
     : m_type(CMYKA)
-    , m_rgba(makeRGBAFromCMYKA(c, m, y, k, a))
-    , m_cmyka(c, m, y, k, a)
+    , m_cmyka(new CMYKAValues(makeRGBAFromCMYKA(c, m, y, k, a), c, m, y, k, a))
 {
 }
 
@@ -141,6 +140,8 @@
         m_gradient->deref();
     else if (m_type == ImagePattern)
         m_pattern->deref();
+    else if (m_type == CMYKA)
+        delete m_cmyka;
 }
 
 PassRefPtr<CanvasStyle> CanvasStyle::createFromString(const String& color, Document* document)
@@ -200,11 +201,11 @@
     case RGBA:
         return m_rgba == other.m_rgba;
     case CMYKA:
-        return m_cmyka.c == other.m_cmyka.c
-            && m_cmyka.m == other.m_cmyka.m
-            && m_cmyka.y == other.m_cmyka.y
-            && m_cmyka.k == other.m_cmyka.k
-            && m_cmyka.a == other.m_cmyka.a;
+        return m_cmyka->c == other.m_cmyka->c
+            && m_cmyka->m == other.m_cmyka->m
+            && m_cmyka->y == other.m_cmyka->y
+            && m_cmyka->k == other.m_cmyka->k
+            && m_cmyka->a == other.m_cmyka->a;
     case Gradient:
     case ImagePattern:
     case CurrentColor:
@@ -229,11 +230,11 @@
     if (m_type != CMYKA)
         return false;
 
-    return c == m_cmyka.c
-        && m == m_cmyka.m
-        && y == m_cmyka.y
-        && k == m_cmyka.k
-        && a == m_cmyka.a;
+    return c == m_cmyka->c
+        && m == m_cmyka->m
+        && y == m_cmyka->y
+        && k == m_cmyka->k
+        && a == m_cmyka->a;
 }
 
 void CanvasStyle::applyStrokeColor(GraphicsContext* context)
@@ -248,15 +249,15 @@
         // FIXME: Do this through platform-independent GraphicsContext API.
         // We'll need a fancier Color abstraction to support CMYKA correctly
 #if USE(CG)
-        CGContextSetCMYKStrokeColor(context->platformContext(), m_cmyka.c, m_cmyka.m, m_cmyka.y, m_cmyka.k, m_cmyka.a);
+        CGContextSetCMYKStrokeColor(context->platformContext(), m_cmyka->c, m_cmyka->m, m_cmyka->y, m_cmyka->k, m_cmyka->a);
 #elif PLATFORM(QT)
         QPen currentPen = context->platformContext()->pen();
         QColor clr;
-        clr.setCmykF(m_cmyka.c, m_cmyka.m, m_cmyka.y, m_cmyka.k, m_cmyka.a);
+        clr.setCmykF(m_cmyka->c, m_cmyka->m, m_cmyka->y, m_cmyka->k, m_cmyka->a);
         currentPen.setColor(clr);
         context->platformContext()->setPen(currentPen);
 #else
-        context->setStrokeColor(m_rgba, ColorSpaceDeviceRGB);
+        context->setStrokeColor(m_cmyka->rgba, ColorSpaceDeviceRGB);
 #endif
         break;
     }
@@ -285,15 +286,15 @@
         // FIXME: Do this through platform-independent GraphicsContext API.
         // We'll need a fancier Color abstraction to support CMYKA correctly
 #if USE(CG)
-        CGContextSetCMYKFillColor(context->platformContext(), m_cmyka.c, m_cmyka.m, m_cmyka.y, m_cmyka.k, m_cmyka.a);
+        CGContextSetCMYKFillColor(context->platformContext(), m_cmyka->c, m_cmyka->m, m_cmyka->y, m_cmyka->k, m_cmyka->a);
 #elif PLATFORM(QT)
         QBrush currentBrush = context->platformContext()->brush();
         QColor clr;
-        clr.setCmykF(m_cmyka.c, m_cmyka.m, m_cmyka.y, m_cmyka.k, m_cmyka.a);
+        clr.setCmykF(m_cmyka->c, m_cmyka->m, m_cmyka->y, m_cmyka->k, m_cmyka->a);
         currentBrush.setColor(clr);
         context->platformContext()->setBrush(currentBrush);
 #else
-        context->setFillColor(m_rgba, ColorSpaceDeviceRGB);
+        context->setFillColor(m_cmyka->rgba, ColorSpaceDeviceRGB);
 #endif
         break;
     }

Modified: trunk/Source/WebCore/html/canvas/CanvasStyle.h (149709 => 149710)


--- trunk/Source/WebCore/html/canvas/CanvasStyle.h	2013-05-08 02:41:08 UTC (rev 149709)
+++ trunk/Source/WebCore/html/canvas/CanvasStyle.h	2013-05-08 03:18:12 UTC (rev 149710)
@@ -59,7 +59,7 @@
         bool hasOverrideAlpha() const { return m_type == CurrentColorWithOverrideAlpha; }
         float overrideAlpha() const { ASSERT(m_type == CurrentColorWithOverrideAlpha); return m_overrideAlpha; }
 
-        String color() const { ASSERT(m_type == RGBA || m_type == CMYKA); return Color(m_rgba).serialized(); }
+        String color() const;
         CanvasGradient* canvasGradient() const;
         CanvasPattern* canvasPattern() const;
 
@@ -72,6 +72,19 @@
 
     private:
         enum Type { RGBA, CMYKA, Gradient, ImagePattern, CurrentColor, CurrentColorWithOverrideAlpha };
+        struct CMYKAValues {
+            WTF_MAKE_FAST_ALLOCATED;
+            WTF_MAKE_NONCOPYABLE(CMYKAValues);
+        public:
+            CMYKAValues() : rgba(0), c(0), m(0), y(0), k(0), a(0) { }
+            CMYKAValues(RGBA32 rgba, float cyan, float magenta, float yellow, float black, float alpha) : rgba(rgba), c(cyan), m(magenta), y(yellow), k(black), a(alpha) { }
+            RGBA32 rgba;
+            float c;
+            float m;
+            float y;
+            float k;
+            float a;
+        };
 
         CanvasStyle(Type, float overrideAlpha = 0);
         CanvasStyle(RGBA32 rgba);
@@ -88,17 +101,8 @@
             float m_overrideAlpha;
             CanvasGradient* m_gradient;
             CanvasPattern* m_pattern;
+            CMYKAValues* m_cmyka;
         };
-
-        struct CMYKAValues {
-            CMYKAValues() : c(0), m(0), y(0), k(0), a(0) { }
-            CMYKAValues(float cyan, float magenta, float yellow, float black, float alpha) : c(cyan), m(magenta), y(yellow), k(black), a(alpha) { }
-            float c;
-            float m;
-            float y;
-            float k;
-            float a;
-        } m_cmyka;
     };
 
     RGBA32 currentColor(HTMLCanvasElement*);
@@ -118,6 +122,14 @@
         return 0;
     }
 
+    inline String CanvasStyle::color() const
+    {
+        ASSERT(m_type == RGBA || m_type == CMYKA);
+        if (m_type == RGBA)
+            return Color(m_rgba).serialized();
+        return Color(m_cmyka->rgba).serialized();
+    }
+
 } // namespace WebCore
 
 #endif
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to