Bug 839383 - part 1 - fix unhandled enumeration values in SourceSurfaceCG.cpp; r=jrmuizel
authorNathan Froyd <froydnj@mozilla.com>
Wed, 06 Mar 2013 11:11:18 -0500
changeset 127120 3b354780c5ac
parent 127119 e56f91d780df
child 127121 c2715e049b3c
push id117
push usertomi.aarnio@nokia.com
push dateWed, 03 Apr 2013 12:07:07 +0000
reviewersjrmuizel
bugs839383
milestone23.0a1
Bug 839383 - part 1 - fix unhandled enumeration values in SourceSurfaceCG.cpp; r=jrmuizel
gfx/2d/SourceSurfaceCG.cpp
--- a/gfx/2d/SourceSurfaceCG.cpp
+++ b/gfx/2d/SourceSurfaceCG.cpp
@@ -41,51 +41,66 @@ SourceSurfaceCG::GetDataSurface()
     new DataSourceSurfaceCG(mImage);
   return dataSurf;
 }
 
 static void releaseCallback(void *info, const void *data, size_t size) {
   free(info);
 }
 
+static void
+AssignSurfaceParametersFromFormat(SurfaceFormat aFormat,
+                                  CGColorSpaceRef &aColorSpace,
+                                  CGBitmapInfo &aBitinfo,
+                                  int &aBitsPerComponent,
+                                  int &aBitsPerPixel)
+{
+  switch (aFormat) {
+    case FORMAT_B8G8R8A8:
+      aColorSpace = CGColorSpaceCreateDeviceRGB();
+      aBitinfo = kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host;
+      aBitsPerComponent = 8;
+      aBitsPerPixel = 32;
+      break;
+
+    case FORMAT_B8G8R8X8:
+      aColorSpace = CGColorSpaceCreateDeviceRGB();
+      aBitinfo = kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Host;
+      aBitsPerComponent = 8;
+      aBitsPerPixel = 32;
+      break;
+
+    case FORMAT_A8:
+      // XXX: why don't we set a colorspace here?
+      aBitsPerComponent = 8;
+      aBitsPerPixel = 8;
+      break;
+
+    default:
+      MOZ_CRASH();
+  }
+}
+
 bool
 SourceSurfaceCG::InitFromData(unsigned char *aData,
                                const IntSize &aSize,
                                int32_t aStride,
                                SurfaceFormat aFormat)
 {
   //XXX: we should avoid creating this colorspace everytime
   CGColorSpaceRef colorSpace = nullptr;
   CGBitmapInfo bitinfo = 0;
   CGDataProviderRef dataProvider = nullptr;
   int bitsPerComponent = 0;
   int bitsPerPixel = 0;
 
   assert(aSize.width >= 0 && aSize.height >= 0);
 
-  switch (aFormat) {
-    case FORMAT_B8G8R8A8:
-      colorSpace = CGColorSpaceCreateDeviceRGB();
-      bitinfo = kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host;
-      bitsPerComponent = 8;
-      bitsPerPixel = 32;
-      break;
-
-    case FORMAT_B8G8R8X8:
-      colorSpace = CGColorSpaceCreateDeviceRGB();
-      bitinfo = kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Host;
-      bitsPerComponent = 8;
-      bitsPerPixel = 32;
-      break;
-
-    case FORMAT_A8:
-      // XXX: why don't we set a colorspace here?
-      bitsPerComponent = 8;
-      bitsPerPixel = 8;
-  };
+  AssignSurfaceParametersFromFormat(aFormat, colorSpace, bitinfo,
+                                    bitsPerComponent, bitsPerPixel);
 
   void *data = malloc(aStride * aSize.height);
   memcpy(data, aData, aStride * aSize.height);
 
   mFormat = aFormat;
 
   dataProvider = CGDataProviderCreateWithData (data,
                                                data,
@@ -145,36 +160,18 @@ DataSourceSurfaceCG::InitFromData(unsign
 {
   //XXX: we should avoid creating this colorspace everytime
   CGColorSpaceRef colorSpace = nullptr;
   CGBitmapInfo bitinfo = 0;
   CGDataProviderRef dataProvider = nullptr;
   int bitsPerComponent = 0;
   int bitsPerPixel = 0;
 
-  switch (aFormat) {
-    case FORMAT_B8G8R8A8:
-      colorSpace = CGColorSpaceCreateDeviceRGB();
-      bitinfo = kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host;
-      bitsPerComponent = 8;
-      bitsPerPixel = 32;
-      break;
-
-    case FORMAT_B8G8R8X8:
-      colorSpace = CGColorSpaceCreateDeviceRGB();
-      bitinfo = kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Host;
-      bitsPerComponent = 8;
-      bitsPerPixel = 32;
-      break;
-
-    case FORMAT_A8:
-      // XXX: why don't we set a colorspace here?
-      bitsPerComponent = 8;
-      bitsPerPixel = 8;
-  };
+  AssignSurfaceParametersFromFormat(aFormat, colorSpace, bitinfo,
+                                    bitsPerComponent, bitsPerPixel);
 
   void *data = malloc(aStride * aSize.height);
   memcpy(data, aData, aStride * aSize.height);
 
   //mFormat = aFormat;
 
   dataProvider = CGDataProviderCreateWithData (data,
                                                data,