Bug 958375 - 1/9 - Make SurfaceType a typed enum - r=Bas
authorBenoit Jacob <bjacob@mozilla.com>
Fri, 10 Jan 2014 13:55:24 -0500
changeset 180000 1e18486ef2ced20749a013cc5b98e1c7c43d6310
parent 179999 c2dd397d92c408c053e605add12066512d014b6f
child 180001 ebce0a5cf1acd398265d1bb3556d984138b1cb6f
push idunknown
push userunknown
push dateunknown
reviewersBas
bugs958375
milestone29.0a1
Bug 958375 - 1/9 - Make SurfaceType a typed enum - r=Bas Specifically: r=Bas for manual changes f=Bas for automatic changes See attachments on the bug for the specific breakdown.
gfx/2d/2D.h
gfx/2d/DataSourceSurface.cpp
gfx/2d/DataSourceSurfaceWrapper.h
gfx/2d/DrawTargetCG.cpp
gfx/2d/DrawTargetCairo.cpp
gfx/2d/DrawTargetD2D.cpp
gfx/2d/DrawTargetD2D1.cpp
gfx/2d/DrawTargetDual.cpp
gfx/2d/DrawTargetRecording.cpp
gfx/2d/DrawTargetSkia.cpp
gfx/2d/FilterNodeD2D1.cpp
gfx/2d/SourceSurfaceCG.cpp
gfx/2d/SourceSurfaceCG.h
gfx/2d/SourceSurfaceCairo.cpp
gfx/2d/SourceSurfaceCairo.h
gfx/2d/SourceSurfaceD2D.h
gfx/2d/SourceSurfaceD2D1.h
gfx/2d/SourceSurfaceD2DTarget.h
gfx/2d/SourceSurfaceDual.h
gfx/2d/SourceSurfaceRawData.h
gfx/2d/SourceSurfaceSkia.h
gfx/2d/Types.h
--- a/gfx/2d/2D.h
+++ b/gfx/2d/2D.h
@@ -332,17 +332,17 @@ public:
    * DataSourceSurface's data can be accessed directly.
    */
   virtual TemporaryRef<DataSourceSurface> GetDataSurface() = 0;
 };
 
 class DataSourceSurface : public SourceSurface
 {
 public:
-  virtual SurfaceType GetType() const { return SURFACE_DATA; }
+  virtual SurfaceType GetType() const { return SurfaceType::DATA; }
   /*
    * Get the raw bitmap data of the surface.
    * Can return null if there was OOM allocating surface data.
    */
   virtual uint8_t *GetData() = 0;
 
   /*
    * Stride of the surface, distance in bytes between the start of the image
@@ -354,17 +354,17 @@ public:
   /*
    * This function is called after modifying the data on the source surface
    * directly through the data pointer.
    */
   virtual void MarkDirty() {}
 
   /*
    * Returns a DataSourceSurface with the same data as this one, but
-   * guaranteed to have surface->GetType() == SURFACE_DATA.
+   * guaranteed to have surface->GetType() == SurfaceType::DATA.
    */
   virtual TemporaryRef<DataSourceSurface> GetDataSurface();
 };
 
 /* This is an abstract object that accepts path segments. */
 class PathSink : public RefCounted<PathSink>
 {
 public:
--- a/gfx/2d/DataSourceSurface.cpp
+++ b/gfx/2d/DataSourceSurface.cpp
@@ -8,17 +8,17 @@
 
 namespace mozilla {
 namespace gfx {
 
 TemporaryRef<DataSourceSurface>
 DataSourceSurface::GetDataSurface()
 {
   RefPtr<DataSourceSurface> temp;
-  if (GetType() == SURFACE_DATA) {
+  if (GetType() == SurfaceType::DATA) {
     temp = this;
   } else {
     temp = new DataSourceSurfaceWrapper(this);
   }
   return temp;
 }
 
 }
--- a/gfx/2d/DataSourceSurfaceWrapper.h
+++ b/gfx/2d/DataSourceSurfaceWrapper.h
@@ -7,25 +7,25 @@
 #define MOZILLA_GFX_DATASOURCESURFACEWRAPPER_H_
 
 #include "2D.h"
 
 namespace mozilla {
 namespace gfx {
 
 // Wraps a DataSourceSurface and forwards all methods except for GetType(),
-// from which it always returns SURFACE_DATA.
+// from which it always returns SurfaceType::DATA.
 class DataSourceSurfaceWrapper : public DataSourceSurface
 {
 public:
   DataSourceSurfaceWrapper(DataSourceSurface *aSurface)
    : mSurface(aSurface)
   {}
 
-  virtual SurfaceType GetType() const MOZ_OVERRIDE { return SURFACE_DATA; }
+  virtual SurfaceType GetType() const MOZ_OVERRIDE { return SurfaceType::DATA; }
 
   virtual uint8_t *GetData() MOZ_OVERRIDE { return mSurface->GetData(); }
   virtual int32_t Stride() MOZ_OVERRIDE { return mSurface->Stride(); }
   virtual IntSize GetSize() const MOZ_OVERRIDE { return mSurface->GetSize(); }
   virtual SurfaceFormat GetFormat() const MOZ_OVERRIDE { return mSurface->GetFormat(); }
   virtual bool IsValid() const MOZ_OVERRIDE { return mSurface->IsValid(); }
   virtual void MarkDirty() { mSurface->MarkDirty(); }
 
--- a/gfx/2d/DrawTargetCG.cpp
+++ b/gfx/2d/DrawTargetCG.cpp
@@ -210,22 +210,22 @@ DrawTargetCG::CreateSourceSurfaceFromDat
 }
 
 // This function returns a retained CGImage that needs to be released after
 // use. The reason for this is that we want to either reuse an existing CGImage
 // or create a new one.
 static CGImageRef
 GetRetainedImageFromSourceSurface(SourceSurface *aSurface)
 {
-  if (aSurface->GetType() == SURFACE_COREGRAPHICS_IMAGE)
+  if (aSurface->GetType() == SurfaceType::COREGRAPHICS_IMAGE)
     return CGImageRetain(static_cast<SourceSurfaceCG*>(aSurface)->GetImage());
-  else if (aSurface->GetType() == SURFACE_COREGRAPHICS_CGCONTEXT)
+  else if (aSurface->GetType() == SurfaceType::COREGRAPHICS_CGCONTEXT)
     return CGImageRetain(static_cast<SourceSurfaceCGContext*>(aSurface)->GetImage());
 
-  if (aSurface->GetType() == SURFACE_DATA) {
+  if (aSurface->GetType() == SurfaceType::DATA) {
     DataSourceSurface* dataSource = static_cast<DataSourceSurface*>(aSurface);
     return CreateCGImage(nullptr, dataSource->GetData(), dataSource->GetSize(),
                          dataSource->Stride(), dataSource->GetFormat());
   }
 
   MOZ_CRASH("unsupported source surface");
 }
 
@@ -1188,18 +1188,18 @@ CGContextResetClip(CGContextRef);
 
 void
 DrawTargetCG::CopySurface(SourceSurface *aSurface,
                           const IntRect& aSourceRect,
                           const IntPoint &aDestination)
 {
   MarkChanged();
 
-  if (aSurface->GetType() == SURFACE_COREGRAPHICS_IMAGE ||
-      aSurface->GetType() == SURFACE_COREGRAPHICS_CGCONTEXT) {
+  if (aSurface->GetType() == SurfaceType::COREGRAPHICS_IMAGE ||
+      aSurface->GetType() == SurfaceType::COREGRAPHICS_CGCONTEXT) {
     CGImageRef image = GetRetainedImageFromSourceSurface(aSurface);
 
     /* we have two options here:
      *  - create a subimage -- this is slower
      *  - fancy things with clip and different dest rects */
     CGImageRef subimage = CGImageCreateWithImageInRect(image, IntRectToCGRect(aSourceRect));
     CGImageRelease(image);
     // XXX: it might be more efficient for us to do the copy directly if we have access to the bits
--- a/gfx/2d/DrawTargetCairo.cpp
+++ b/gfx/2d/DrawTargetCairo.cpp
@@ -197,23 +197,23 @@ ReleaseData(void* aData)
  * If possible, it will use the cairo_surface associated with aSurface,
  * otherwise, it will create a new cairo_surface.
  * In either case, the caller must call cairo_surface_destroy on the
  * result when it is done with it.
  */
 cairo_surface_t*
 GetCairoSurfaceForSourceSurface(SourceSurface *aSurface, bool aExistingOnly = false)
 {
-  if (aSurface->GetType() == SURFACE_CAIRO) {
+  if (aSurface->GetType() == SurfaceType::CAIRO) {
     cairo_surface_t* surf = static_cast<SourceSurfaceCairo*>(aSurface)->GetSurface();
     cairo_surface_reference(surf);
     return surf;
   }
 
-  if (aSurface->GetType() == SURFACE_CAIRO_IMAGE) {
+  if (aSurface->GetType() == SurfaceType::CAIRO_IMAGE) {
     cairo_surface_t* surf =
       static_cast<const DataSourceSurfaceCairo*>(aSurface)->GetSurface();
     cairo_surface_reference(surf);
     return surf;
   }
 
   if (aExistingOnly) {
     return nullptr;
@@ -570,17 +570,17 @@ DrawTargetCairo::DrawFilter(FilterNode *
 void
 DrawTargetCairo::DrawSurfaceWithShadow(SourceSurface *aSurface,
                                        const Point &aDest,
                                        const Color &aColor,
                                        const Point &aOffset,
                                        Float aSigma,
                                        CompositionOp aOperator)
 {
-  if (aSurface->GetType() != SURFACE_CAIRO) {
+  if (aSurface->GetType() != SurfaceType::CAIRO) {
     return;
   }
   
   AutoClearDeviceOffset clear(aSurface);
 
   Float width = Float(aSurface->GetSize().width);
   Float height = Float(aSurface->GetSize().height);
 
--- a/gfx/2d/DrawTargetD2D.cpp
+++ b/gfx/2d/DrawTargetD2D.cpp
@@ -268,23 +268,23 @@ DrawTargetD2D::AddDependencyOnSource(Sou
 TemporaryRef<ID2D1Bitmap>
 DrawTargetD2D::GetBitmapForSurface(SourceSurface *aSurface,
                                    Rect &aSource)
 {
   RefPtr<ID2D1Bitmap> bitmap;
 
   switch (aSurface->GetType()) {
 
-  case SURFACE_D2D1_BITMAP:
+  case SurfaceType::D2D1_BITMAP:
     {
       SourceSurfaceD2D *srcSurf = static_cast<SourceSurfaceD2D*>(aSurface);
       bitmap = srcSurf->GetBitmap();
     }
     break;
-  case SURFACE_D2D1_DRAWTARGET:
+  case SurfaceType::D2D1_DRAWTARGET:
     {
       SourceSurfaceD2DTarget *srcSurf = static_cast<SourceSurfaceD2DTarget*>(aSurface);
       bitmap = srcSurf->GetBitmap(mRT);
       AddDependencyOnSource(srcSurf);
     }
     break;
   default:
     {
@@ -422,17 +422,17 @@ void
 DrawTargetD2D::DrawSurfaceWithShadow(SourceSurface *aSurface,
                                      const Point &aDest,
                                      const Color &aColor,
                                      const Point &aOffset,
                                      Float aSigma,
                                      CompositionOp aOperator)
 {
   RefPtr<ID3D10ShaderResourceView> srView = nullptr;
-  if (aSurface->GetType() != SURFACE_D2D1_DRAWTARGET) {
+  if (aSurface->GetType() != SurfaceType::D2D1_DRAWTARGET) {
     return;
   }
 
   SetScissorToRect(nullptr);
 
   // XXX - This function is way too long, it should be split up soon to make
   // it more graspable!
 
@@ -2317,28 +2317,28 @@ DrawTargetD2D::CreateBrushForPattern(con
       return nullptr;
     }
 
     RefPtr<ID2D1Bitmap> bitmap;
 
     Matrix mat = pat->mMatrix;
     
     switch (pat->mSurface->GetType()) {
-    case SURFACE_D2D1_BITMAP:
+    case SurfaceType::D2D1_BITMAP:
       {
         SourceSurfaceD2D *surf = static_cast<SourceSurfaceD2D*>(pat->mSurface.get());
 
         bitmap = surf->mBitmap;
 
         if (!bitmap) {
           return nullptr;
         }
       }
       break;
-    case SURFACE_D2D1_DRAWTARGET:
+    case SurfaceType::D2D1_DRAWTARGET:
       {
         SourceSurfaceD2DTarget *surf =
           static_cast<SourceSurfaceD2DTarget*>(pat->mSurface.get());
         bitmap = surf->GetBitmap(mRT);
         AddDependencyOnSource(surf);
       }
       break;
     default:
--- a/gfx/2d/DrawTargetD2D1.cpp
+++ b/gfx/2d/DrawTargetD2D1.cpp
@@ -889,17 +889,17 @@ DrawTargetD2D1::CreateBrushForPattern(co
 
 TemporaryRef<ID2D1Image>
 DrawTargetD2D1::GetImageForSurface(SourceSurface *aSurface, Matrix &aSourceTransform,
                                    ExtendMode aExtendMode)
 {
   RefPtr<ID2D1Image> image;
 
   switch (aSurface->GetType()) {
-  case SURFACE_D2D1_1_IMAGE:
+  case SurfaceType::D2D1_1_IMAGE:
     {
       SourceSurfaceD2D1 *surf = static_cast<SourceSurfaceD2D1*>(aSurface);
       image = surf->GetImage();
       AddDependencyOnSource(surf);
     }
     break;
   default:
     {
--- a/gfx/2d/DrawTargetDual.cpp
+++ b/gfx/2d/DrawTargetDual.cpp
@@ -9,17 +9,17 @@
 namespace mozilla {
 namespace gfx {
 
 class DualSurface
 {
 public:
   inline DualSurface(SourceSurface *aSurface)
   {
-    if (aSurface->GetType() != SURFACE_DUAL_DT) {
+    if (aSurface->GetType() != SurfaceType::DUAL_DT) {
       mA = mB = aSurface;
       return;
     }
 
     SourceSurfaceDual *ssDual =
       static_cast<SourceSurfaceDual*>(aSurface);
     mA = ssDual->mA;
     mB = ssDual->mB;
@@ -42,17 +42,17 @@ public:
     if (aPattern.GetType() != PATTERN_SURFACE) {
       mA = mB = &aPattern;
       return;
     }
 
     const SurfacePattern *surfPat =
       static_cast<const SurfacePattern*>(&aPattern);
 
-    if (surfPat->mSurface->GetType() != SURFACE_DUAL_DT) {
+    if (surfPat->mSurface->GetType() != SurfaceType::DUAL_DT) {
       mA = mB = &aPattern;
       return;
     }
 
     const SourceSurfaceDual *ssDual =
       static_cast<const SourceSurfaceDual*>(surfPat->mSurface.get());
     mA = new (mSurfPatA.addr()) SurfacePattern(ssDual->mA, surfPat->mExtendMode,
                                                surfPat->mMatrix, surfPat->mFilter);
--- a/gfx/2d/DrawTargetRecording.cpp
+++ b/gfx/2d/DrawTargetRecording.cpp
@@ -22,17 +22,17 @@ public:
   {
   }
 
   ~SourceSurfaceRecording()
   {
     mRecorder->RecordEvent(RecordedSourceSurfaceDestruction(this));
   }
 
-  virtual SurfaceType GetType() const { return SURFACE_RECORDING; }
+  virtual SurfaceType GetType() const { return SurfaceType::RECORDING; }
   virtual IntSize GetSize() const { return mFinalSurface->GetSize(); }
   virtual SurfaceFormat GetFormat() const { return mFinalSurface->GetFormat(); }
   virtual TemporaryRef<DataSourceSurface> GetDataSurface() { return mFinalSurface->GetDataSurface(); }
 
   RefPtr<SourceSurface> mFinalSurface;
   RefPtr<DrawEventRecorderPrivate> mRecorder;
 };
 
@@ -53,17 +53,17 @@ public:
 
   RefPtr<GradientStops> mFinalGradientStops;
   RefPtr<DrawEventRecorderPrivate> mRecorder;
 };
 
 static SourceSurface *
 GetSourceSurface(SourceSurface *aSurface)
 {
-  if (aSurface->GetType() != SURFACE_RECORDING) {
+  if (aSurface->GetType() != SurfaceType::RECORDING) {
     return aSurface;
   }
 
   return static_cast<SourceSurfaceRecording*>(aSurface)->mFinalSurface;
 }
 
 static GradientStops *
 GetGradientStops(GradientStops *aStops)
--- a/gfx/2d/DrawTargetSkia.cpp
+++ b/gfx/2d/DrawTargetSkia.cpp
@@ -150,19 +150,19 @@ DrawTargetSkia::PurgeAllCaches()
 }
 
 #endif
 
 static SkBitmap
 GetBitmapForSurface(SourceSurface *aSurface)
 {
   switch (aSurface->GetType()) {
-  case SURFACE_SKIA:
+  case SurfaceType::SKIA:
     return static_cast<SourceSurfaceSkia*>(aSurface)->GetBitmap();
-  case SURFACE_DATA:
+  case SurfaceType::DATA:
     {
       DataSourceSurface* surf = static_cast<DataSourceSurface*>(aSurface);
       SkBitmap tmp;
       tmp.setConfig(GfxFormatToSkiaConfig(surf->GetFormat()),
                     surf->GetSize().width, surf->GetSize().height, surf->Stride());
       tmp.setPixels(surf->GetData());
       return tmp;
     }
@@ -347,17 +347,17 @@ DrawTargetSkia::Flush()
 
 void
 DrawTargetSkia::DrawSurface(SourceSurface *aSurface,
                             const Rect &aDest,
                             const Rect &aSource,
                             const DrawSurfaceOptions &aSurfOptions,
                             const DrawOptions &aOptions)
 {
-  if (!(aSurface->GetType() == SURFACE_SKIA || aSurface->GetType() == SURFACE_DATA)) {
+  if (!(aSurface->GetType() == SurfaceType::SKIA || aSurface->GetType() == SurfaceType::DATA)) {
     return;
   }
 
   if (aSource.IsEmpty()) {
     return;
   }
 
   MarkChanged();
@@ -686,21 +686,21 @@ DrawTargetSkia::CreateSimilarDrawTarget(
     return nullptr;
   }
   return target;
 }
 
 TemporaryRef<SourceSurface>
 DrawTargetSkia::OptimizeSourceSurface(SourceSurface *aSurface) const
 {
-  if (aSurface->GetType() == SURFACE_SKIA) {
+  if (aSurface->GetType() == SurfaceType::SKIA) {
     return aSurface;
   }
 
-  if (aSurface->GetType() != SURFACE_DATA) {
+  if (aSurface->GetType() != SurfaceType::DATA) {
     return nullptr;
   }
 
   RefPtr<DataSourceSurface> data = aSurface->GetDataSurface();
   RefPtr<SourceSurface> surface = CreateSourceSurfaceFromData(data->GetData(),
                                                               data->GetSize(),
                                                               data->Stride(),
                                                               data->GetFormat());
@@ -715,17 +715,17 @@ DrawTargetSkia::CreateSourceSurfaceFromN
 
 void
 DrawTargetSkia::CopySurface(SourceSurface *aSurface,
                             const IntRect& aSourceRect,
                             const IntPoint &aDestination)
 {
   //TODO: We could just use writePixels() here if the sourceRect is the entire source
 
-  if (aSurface->GetType() != SURFACE_SKIA) {
+  if (aSurface->GetType() != SurfaceType::SKIA) {
     return;
   }
 
   MarkChanged();
 
   const SkBitmap& bitmap = GetBitmapForSurface(aSurface);
 
   mCanvas->save();
--- a/gfx/2d/FilterNodeD2D1.cpp
+++ b/gfx/2d/FilterNodeD2D1.cpp
@@ -128,24 +128,24 @@ D2D1_CHANNEL_SELECTOR D2DChannelSelector
 
 TemporaryRef<ID2D1Image> GetImageForSourceSurface(DrawTarget *aDT, SourceSurface *aSurface)
 {
   if (aDT->GetType() == BACKEND_DIRECT2D1_1) {
     return static_cast<DrawTargetD2D1*>(aDT)->GetImageForSurface(aSurface, EXTEND_CLAMP);
   }
   RefPtr<ID2D1Image> image;
   switch (aSurface->GetType()) {
-  case SURFACE_D2D1_1_IMAGE:
+  case SurfaceType::D2D1_1_IMAGE:
     image = static_cast<SourceSurfaceD2D1*>(aSurface)->GetImage();
     static_cast<SourceSurfaceD2D1*>(aSurface)->EnsureIndependent();
     break;
-  case SURFACE_D2D1_BITMAP:
+  case SurfaceType::D2D1_BITMAP:
    image = static_cast<SourceSurfaceD2D*>(aSurface)->GetBitmap();
     break;
-  case SURFACE_D2D1_DRAWTARGET: {
+  case SurfaceType::D2D1_DRAWTARGET: {
       SourceSurfaceD2DTarget *surf = static_cast<SourceSurfaceD2DTarget*>(aSurface);
       image = surf->GetBitmap(static_cast<DrawTargetD2D*>(aDT)->GetRT());
     }
     break;
   default:
     gfxWarning() << "Unknown input SourceSurface set on effect.";
     MOZ_ASSERT(0);
   }
--- a/gfx/2d/SourceSurfaceCG.cpp
+++ b/gfx/2d/SourceSurfaceCG.cpp
@@ -37,17 +37,17 @@ SourceSurfaceCG::GetFormat() const
 TemporaryRef<DataSourceSurface>
 SourceSurfaceCG::GetDataSurface()
 {
   //XXX: we should be more disciplined about who takes a reference and where
   CGImageRetain(mImage);
   RefPtr<DataSourceSurface> dataSurf = new DataSourceSurfaceCG(mImage);
 
   // We also need to make sure that the returned surface has
-  // surface->GetType() == SURFACE_DATA.
+  // surface->GetType() == SurfaceType::DATA.
   dataSurf = new DataSourceSurfaceWrapper(dataSurf);
 
   return dataSurf;
 }
 
 static void releaseCallback(void *info, const void *data, size_t size) {
   free(info);
 }
--- a/gfx/2d/SourceSurfaceCG.h
+++ b/gfx/2d/SourceSurfaceCG.h
@@ -25,17 +25,17 @@ class DrawTargetCG;
 
 class SourceSurfaceCG : public SourceSurface
 {
 public:
   SourceSurfaceCG() {}
   SourceSurfaceCG(CGImageRef aImage) : mImage(aImage) {}
   ~SourceSurfaceCG();
 
-  virtual SurfaceType GetType() const { return SURFACE_COREGRAPHICS_IMAGE; }
+  virtual SurfaceType GetType() const { return SurfaceType::COREGRAPHICS_IMAGE; }
   virtual IntSize GetSize() const;
   virtual SurfaceFormat GetFormat() const;
   virtual TemporaryRef<DataSourceSurface> GetDataSurface();
 
   CGImageRef GetImage() { return mImage; }
 
   bool InitFromData(unsigned char *aData,
                     const IntSize &aSize,
@@ -53,17 +53,17 @@ private:
 
 class DataSourceSurfaceCG : public DataSourceSurface
 {
 public:
   DataSourceSurfaceCG() {}
   DataSourceSurfaceCG(CGImageRef aImage);
   ~DataSourceSurfaceCG();
 
-  virtual SurfaceType GetType() const { return SURFACE_DATA; }
+  virtual SurfaceType GetType() const { return SurfaceType::DATA; }
   virtual IntSize GetSize() const;
   virtual SurfaceFormat GetFormat() const { return mFormat; }
 
   CGImageRef GetImage() { return mImage; }
 
   bool InitFromData(unsigned char *aData,
                     const IntSize &aSize,
                     int32_t aStride,
@@ -93,17 +93,17 @@ public:
 };
 
 class SourceSurfaceCGBitmapContext : public SourceSurfaceCGContext
 {
 public:
   SourceSurfaceCGBitmapContext(DrawTargetCG *);
   ~SourceSurfaceCGBitmapContext();
 
-  virtual SurfaceType GetType() const { return SURFACE_COREGRAPHICS_CGCONTEXT; }
+  virtual SurfaceType GetType() const { return SurfaceType::COREGRAPHICS_CGCONTEXT; }
   virtual IntSize GetSize() const;
   virtual SurfaceFormat GetFormat() const { return mFormat; }
   virtual TemporaryRef<DataSourceSurface> GetDataSurface()
   {
     // This call to DrawTargetWillChange() is needed to make a local copy of
     // the data from mDrawTarget.  If we don't do that, the data can end up
     // getting deleted before the CGImageRef it belongs to.
     //
@@ -148,17 +148,17 @@ private:
 };
 
 class SourceSurfaceCGIOSurfaceContext : public SourceSurfaceCGContext
 {
 public:
   SourceSurfaceCGIOSurfaceContext(DrawTargetCG *);
   ~SourceSurfaceCGIOSurfaceContext();
 
-  virtual SurfaceType GetType() const { return SURFACE_COREGRAPHICS_CGCONTEXT; }
+  virtual SurfaceType GetType() const { return SurfaceType::COREGRAPHICS_CGCONTEXT; }
   virtual IntSize GetSize() const;
   virtual SurfaceFormat GetFormat() const { return mFormat; }
 
   CGImageRef GetImage() { EnsureImage(); return mImage; }
 
   virtual unsigned char *GetData();
 
   virtual int32_t Stride() { return mStride; }
--- a/gfx/2d/SourceSurfaceCairo.cpp
+++ b/gfx/2d/SourceSurfaceCairo.cpp
@@ -75,17 +75,17 @@ SourceSurfaceCairo::GetDataSurface()
     cairo_paint(ctx);
     cairo_destroy(ctx);
 
     dataSurf = new DataSourceSurfaceCairo(imageSurf);
     cairo_surface_destroy(imageSurf);
   }
 
   // We also need to make sure that the returned surface has
-  // surface->GetType() == SURFACE_DATA.
+  // surface->GetType() == SurfaceType::DATA.
   dataSurf = new DataSourceSurfaceWrapper(dataSurf);
 
   return dataSurf;
 }
 
 cairo_surface_t*
 SourceSurfaceCairo::GetSurface() const
 {
--- a/gfx/2d/SourceSurfaceCairo.h
+++ b/gfx/2d/SourceSurfaceCairo.h
@@ -21,17 +21,17 @@ public:
   // If aDrawTarget is non-nullptr, it is assumed that this is a snapshot source
   // surface, and we'll call DrawTargetCairo::RemoveSnapshot(this) on it when
   // we're destroyed.
   SourceSurfaceCairo(cairo_surface_t* aSurface, const IntSize& aSize,
                      const SurfaceFormat& aFormat,
                      DrawTargetCairo* aDrawTarget = nullptr);
   virtual ~SourceSurfaceCairo();
 
-  virtual SurfaceType GetType() const { return SURFACE_CAIRO; }
+  virtual SurfaceType GetType() const { return SurfaceType::CAIRO; }
   virtual IntSize GetSize() const;
   virtual SurfaceFormat GetFormat() const;
   virtual TemporaryRef<DataSourceSurface> GetDataSurface();
 
   cairo_surface_t* GetSurface() const;
 
 private: // methods
   friend class DrawTargetCairo;
@@ -47,17 +47,17 @@ private: // data
 class DataSourceSurfaceCairo : public DataSourceSurface
 {
 public:
   DataSourceSurfaceCairo(cairo_surface_t* imageSurf);
   virtual ~DataSourceSurfaceCairo();
   virtual unsigned char *GetData();
   virtual int32_t Stride();
 
-  virtual SurfaceType GetType() const { return SURFACE_CAIRO_IMAGE; }
+  virtual SurfaceType GetType() const { return SurfaceType::CAIRO_IMAGE; }
   virtual IntSize GetSize() const;
   virtual SurfaceFormat GetFormat() const;
 
   cairo_surface_t* GetSurface() const;
 
 private:
   cairo_surface_t* mImageSurface;
 };
--- a/gfx/2d/SourceSurfaceD2D.h
+++ b/gfx/2d/SourceSurfaceD2D.h
@@ -16,17 +16,17 @@ namespace gfx {
 class DataSourceSurfaceD2D;
 
 class SourceSurfaceD2D : public SourceSurface
 {
 public:
   SourceSurfaceD2D();
   ~SourceSurfaceD2D();
 
-  virtual SurfaceType GetType() const { return SURFACE_D2D1_BITMAP; }
+  virtual SurfaceType GetType() const { return SurfaceType::D2D1_BITMAP; }
   virtual IntSize GetSize() const;
   virtual SurfaceFormat GetFormat() const;
   virtual bool IsValid() const;
 
   virtual TemporaryRef<DataSourceSurface> GetDataSurface();
 
   ID2D1Bitmap *GetBitmap() { return mBitmap; }
 
--- a/gfx/2d/SourceSurfaceD2D1.h
+++ b/gfx/2d/SourceSurfaceD2D1.h
@@ -20,17 +20,17 @@ class DrawTargetD2D1;
 class SourceSurfaceD2D1 : public SourceSurface
 {
 public:
   SourceSurfaceD2D1(ID2D1Image* aImage, ID2D1DeviceContext *aDC,
                     SurfaceFormat aFormat, const IntSize &aSize,
                     DrawTargetD2D1 *aDT = nullptr);
   ~SourceSurfaceD2D1();
 
-  virtual SurfaceType GetType() const { return SURFACE_D2D1_1_IMAGE; }
+  virtual SurfaceType GetType() const { return SurfaceType::D2D1_1_IMAGE; }
   virtual IntSize GetSize() const { return mSize; }
   virtual SurfaceFormat GetFormat() const { return mFormat; }
   virtual TemporaryRef<DataSourceSurface> GetDataSurface();
 
   ID2D1Image *GetImage() { return mImage; }
 
   void EnsureIndependent() { if (!mDrawTarget) return; DrawTargetWillChange(); }
 
@@ -60,17 +60,17 @@ private:
 };
 
 class DataSourceSurfaceD2D1 : public DataSourceSurface
 {
 public:
   DataSourceSurfaceD2D1(ID2D1Bitmap1 *aMappableBitmap, SurfaceFormat aFormat);
   ~DataSourceSurfaceD2D1();
 
-  virtual SurfaceType GetType() const { return SURFACE_DATA; }
+  virtual SurfaceType GetType() const { return SurfaceType::DATA; }
   virtual IntSize GetSize() const;
   virtual SurfaceFormat GetFormat() const { return mFormat; }
   virtual uint8_t *GetData();
   virtual int32_t Stride();
 
 private:
   friend class SourceSurfaceD2DTarget;
   void EnsureMapped();
--- a/gfx/2d/SourceSurfaceD2DTarget.h
+++ b/gfx/2d/SourceSurfaceD2DTarget.h
@@ -18,17 +18,17 @@ class DrawTargetD2D;
 
 class SourceSurfaceD2DTarget : public SourceSurface
 {
 public:
   SourceSurfaceD2DTarget(DrawTargetD2D* aDrawTarget, ID3D10Texture2D* aTexture,
                          SurfaceFormat aFormat);
   ~SourceSurfaceD2DTarget();
 
-  virtual SurfaceType GetType() const { return SURFACE_D2D1_DRAWTARGET; }
+  virtual SurfaceType GetType() const { return SurfaceType::D2D1_DRAWTARGET; }
   virtual IntSize GetSize() const;
   virtual SurfaceFormat GetFormat() const;
   virtual TemporaryRef<DataSourceSurface> GetDataSurface();
 
   DrawTargetD2D* GetDT() { return mDrawTarget; }
   ID2D1Bitmap *GetBitmap(ID2D1RenderTarget *aRT);
 
 private:
@@ -58,17 +58,17 @@ private:
 };
 
 class DataSourceSurfaceD2DTarget : public DataSourceSurface
 {
 public:
   DataSourceSurfaceD2DTarget(SurfaceFormat aFormat);
   ~DataSourceSurfaceD2DTarget();
 
-  virtual SurfaceType GetType() const { return SURFACE_DATA; }
+  virtual SurfaceType GetType() const { return SurfaceType::DATA; }
   virtual IntSize GetSize() const;
   virtual SurfaceFormat GetFormat() const;
   virtual uint8_t *GetData();
   virtual int32_t Stride();
 
 private:
   friend class SourceSurfaceD2DTarget;
   void EnsureMapped();
--- a/gfx/2d/SourceSurfaceDual.h
+++ b/gfx/2d/SourceSurfaceDual.h
@@ -17,17 +17,17 @@ class DualPattern;
 class SourceSurfaceDual : public SourceSurface
 {
 public:
   SourceSurfaceDual(DrawTarget *aDTA, DrawTarget *aDTB)
     : mA(aDTA->Snapshot())
     , mB(aDTB->Snapshot())
   { }
 
-  virtual SurfaceType GetType() const { return SURFACE_DUAL_DT; }
+  virtual SurfaceType GetType() const { return SurfaceType::DUAL_DT; }
   virtual IntSize GetSize() const { return mA->GetSize(); }
   virtual SurfaceFormat GetFormat() const { return mA->GetFormat(); }
 
   /* Readback from this surface type is not supported! */
   virtual TemporaryRef<DataSourceSurface> GetDataSurface() { return nullptr; }
 private:
   friend class DualSurface;
   friend class DualPattern;
--- a/gfx/2d/SourceSurfaceRawData.h
+++ b/gfx/2d/SourceSurfaceRawData.h
@@ -16,17 +16,17 @@ class SourceSurfaceRawData : public Data
 {
 public:
   SourceSurfaceRawData() {}
   ~SourceSurfaceRawData() { if(mOwnData) delete [] mRawData; }
 
   virtual uint8_t *GetData() { return mRawData; }
   virtual int32_t Stride() { return mStride; }
 
-  virtual SurfaceType GetType() const { return SURFACE_DATA; }
+  virtual SurfaceType GetType() const { return SurfaceType::DATA; }
   virtual IntSize GetSize() const { return mSize; }
   virtual SurfaceFormat GetFormat() const { return mFormat; }
 
   bool InitWrappingData(unsigned char *aData,
                         const IntSize &aSize,
                         int32_t aStride,
                         SurfaceFormat aFormat,
                         bool aOwnData);
@@ -42,17 +42,17 @@ private:
 class SourceSurfaceAlignedRawData : public DataSourceSurface
 {
 public:
   SourceSurfaceAlignedRawData() {}
 
   virtual uint8_t *GetData() { return mArray; }
   virtual int32_t Stride() { return mStride; }
 
-  virtual SurfaceType GetType() const { return SURFACE_DATA; }
+  virtual SurfaceType GetType() const { return SurfaceType::DATA; }
   virtual IntSize GetSize() const { return mSize; }
   virtual SurfaceFormat GetFormat() const { return mFormat; }
 
   bool Init(const IntSize &aSize,
             SurfaceFormat aFormat);
   bool InitWithStride(const IntSize &aSize,
                       SurfaceFormat aFormat,
                       int32_t aStride);
--- a/gfx/2d/SourceSurfaceSkia.h
+++ b/gfx/2d/SourceSurfaceSkia.h
@@ -17,17 +17,17 @@ namespace gfx {
 class DrawTargetSkia;
 
 class SourceSurfaceSkia : public DataSourceSurface
 {
 public:
   SourceSurfaceSkia();
   ~SourceSurfaceSkia();
 
-  virtual SurfaceType GetType() const { return SURFACE_SKIA; }
+  virtual SurfaceType GetType() const { return SurfaceType::SKIA; }
   virtual IntSize GetSize() const;
   virtual SurfaceFormat GetFormat() const;
 
   SkBitmap& GetBitmap() { return mBitmap; }
 
   bool InitFromData(unsigned char* aData,
                     const IntSize &aSize,
                     int32_t aStride,
--- a/gfx/2d/Types.h
+++ b/gfx/2d/Types.h
@@ -2,39 +2,39 @@
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef MOZILLA_GFX_TYPES_H_
 #define MOZILLA_GFX_TYPES_H_
 
 #include "mozilla/NullPtr.h"
+#include "mozilla/TypedEnum.h"
 
 #include <stddef.h>
 #include <stdint.h>
 
 namespace mozilla {
 namespace gfx {
 
 typedef float Float;
 
-enum SurfaceType
-{
-  SURFACE_DATA, /* Data surface - bitmap in memory */
-  SURFACE_D2D1_BITMAP, /* Surface wrapping a ID2D1Bitmap */
-  SURFACE_D2D1_DRAWTARGET, /* Surface made from a D2D draw target */
-  SURFACE_CAIRO, /* Surface wrapping a cairo surface */
-  SURFACE_CAIRO_IMAGE, /* Data surface wrapping a cairo image surface */
-  SURFACE_COREGRAPHICS_IMAGE, /* Surface wrapping a CoreGraphics Image */
-  SURFACE_COREGRAPHICS_CGCONTEXT, /* Surface wrapping a CG context */
-  SURFACE_SKIA, /* Surface wrapping a Skia bitmap */
-  SURFACE_DUAL_DT, /* Snapshot of a dual drawtarget */
-  SURFACE_D2D1_1_IMAGE, /* A D2D 1.1 ID2D1Image SourceSurface */
-  SURFACE_RECORDING /* Surface used for recording */
-};
+MOZ_BEGIN_ENUM_CLASS(SurfaceType)
+  DATA, /* Data surface - bitmap in memory */
+  D2D1_BITMAP, /* Surface wrapping a ID2D1Bitmap */
+  D2D1_DRAWTARGET, /* Surface made from a D2D draw target */
+  CAIRO, /* Surface wrapping a cairo surface */
+  CAIRO_IMAGE, /* Data surface wrapping a cairo image surface */
+  COREGRAPHICS_IMAGE, /* Surface wrapping a CoreGraphics Image */
+  COREGRAPHICS_CGCONTEXT, /* Surface wrapping a CG context */
+  SKIA, /* Surface wrapping a Skia bitmap */
+  DUAL_DT, /* Snapshot of a dual drawtarget */
+  D2D1_1_IMAGE, /* A D2D 1.1 ID2D1Image SourceSurface */
+  RECORDING /* Surface used for recording */
+MOZ_END_ENUM_CLASS(SurfaceType)
 
 enum SurfaceFormat
 {
   FORMAT_B8G8R8A8,
   FORMAT_B8G8R8X8,
   FORMAT_R8G8B8A8,
   FORMAT_R8G8B8X8,
   FORMAT_R5G6B5,