Bug 989337 - 3/3 - Convert Canvas2D to typed enums and EnumeratedArray, final manual changes - r=Bas
authorBenoit Jacob <bjacob@mozilla.com>
Fri, 25 Apr 2014 22:34:07 -0400
changeset 180733 b00d3a5f4b6fd5ae3beec5ca57691d0f37a875aa
parent 180732 f05cc8c8c16d65a65968777598288bcd7de02a76
child 180734 610d7ccaaa9c9390ff6972f583475ebf3eaaecf5
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersBas
bugs989337
milestone31.0a1
Bug 989337 - 3/3 - Convert Canvas2D to typed enums and EnumeratedArray, final manual changes - r=Bas
content/canvas/src/CanvasRenderingContext2D.cpp
content/canvas/src/CanvasRenderingContext2D.h
--- a/content/canvas/src/CanvasRenderingContext2D.cpp
+++ b/content/canvas/src/CanvasRenderingContext2D.cpp
@@ -161,17 +161,17 @@ public:
 NS_IMPL_ISUPPORTS1(Canvas2dPixelsReporter, nsIMemoryReporter)
 
 class CanvasRadialGradient : public CanvasGradient
 {
 public:
   CanvasRadialGradient(CanvasRenderingContext2D* aContext,
                        const Point &aBeginOrigin, Float aBeginRadius,
                        const Point &aEndOrigin, Float aEndRadius)
-    : CanvasGradient(aContext, RADIAL)
+    : CanvasGradient(aContext, Type::RADIAL)
     , mCenter1(aBeginOrigin)
     , mCenter2(aEndOrigin)
     , mRadius1(aBeginRadius)
     , mRadius2(aEndRadius)
   {
   }
 
   Point mCenter1;
@@ -180,17 +180,17 @@ public:
   Float mRadius2;
 };
 
 class CanvasLinearGradient : public CanvasGradient
 {
 public:
   CanvasLinearGradient(CanvasRenderingContext2D* aContext,
                        const Point &aBegin, const Point &aEnd)
-    : CanvasGradient(aContext, LINEAR)
+    : CanvasGradient(aContext, Type::LINEAR)
     , mBegin(aBegin)
     , mEnd(aEnd)
   {
   }
 
 protected:
   friend class CanvasGeneralPattern;
 
--- a/content/canvas/src/CanvasRenderingContext2D.h
+++ b/content/canvas/src/CanvasRenderingContext2D.h
@@ -19,16 +19,17 @@
 #include "mozilla/dom/CanvasGradient.h"
 #include "mozilla/dom/CanvasRenderingContext2DBinding.h"
 #include "mozilla/dom/CanvasPattern.h"
 #include "mozilla/gfx/Rect.h"
 #include "mozilla/gfx/2D.h"
 #include "gfx2DGlue.h"
 #include "imgIEncoder.h"
 #include "nsLayoutUtils.h"
+#include "mozilla/EnumeratedArray.h"
 
 class nsGlobalWindow;
 class nsXULElement;
 
 namespace mozilla {
 namespace gfx {
 class SourceSurface;
 class SurfaceStream;
@@ -865,16 +866,19 @@ protected:
                      fillRule(mozilla::gfx::FillRule::FILL_WINDING),
                      lineCap(mozilla::gfx::CapStyle::BUTT),
                      lineJoin(mozilla::gfx::JoinStyle::MITER_OR_BEVEL),
                      imageSmoothingEnabled(true)
     { }
 
     ContextState(const ContextState& other)
         : fontGroup(other.fontGroup),
+          gradientStyles(other.gradientStyles),
+          patternStyles(other.patternStyles),
+          colorStyles(other.colorStyles),
           font(other.font),
           textAlign(other.textAlign),
           textBaseline(other.textBaseline),
           shadowColor(other.shadowColor),
           transform(other.transform),
           shadowOffset(other.shadowOffset),
           lineWidth(other.lineWidth),
           miterLimit(other.miterLimit),
@@ -882,23 +886,17 @@ protected:
           shadowBlur(other.shadowBlur),
           dash(other.dash),
           dashOffset(other.dashOffset),
           op(other.op),
           fillRule(other.fillRule),
           lineCap(other.lineCap),
           lineJoin(other.lineJoin),
           imageSmoothingEnabled(other.imageSmoothingEnabled)
-    {
-      for (int i = 0; i < Style::MAX; i++) {
-        colorStyles[i] = other.colorStyles[i];
-        gradientStyles[i] = other.gradientStyles[i];
-        patternStyles[i] = other.patternStyles[i];
-      }
-    }
+    { }
 
     void SetColorStyle(Style whichStyle, nscolor color)
     {
       colorStyles[whichStyle] = color;
       gradientStyles[whichStyle] = nullptr;
       patternStyles[whichStyle] = nullptr;
     }
 
@@ -921,24 +919,24 @@ protected:
     {
       return !(patternStyles[whichStyle] || gradientStyles[whichStyle]);
     }
 
 
     std::vector<mozilla::RefPtr<mozilla::gfx::Path> > clipsPushed;
 
     nsRefPtr<gfxFontGroup> fontGroup;
-    nsRefPtr<CanvasGradient> gradientStyles[Style::MAX];
-    nsRefPtr<CanvasPattern> patternStyles[Style::MAX];
+    EnumeratedArray<Style, Style::MAX, nsRefPtr<CanvasGradient>> gradientStyles;
+    EnumeratedArray<Style, Style::MAX, nsRefPtr<CanvasPattern>> patternStyles;
+    EnumeratedArray<Style, Style::MAX, nscolor> colorStyles;
 
     nsString font;
     TextAlign textAlign;
     TextBaseline textBaseline;
 
-    nscolor colorStyles[Style::MAX];
     nscolor shadowColor;
 
     mozilla::gfx::Matrix transform;
     mozilla::gfx::Point shadowOffset;
     mozilla::gfx::Float lineWidth;
     mozilla::gfx::Float miterLimit;
     mozilla::gfx::Float globalAlpha;
     mozilla::gfx::Float shadowBlur;