promote SkImage::AlphaType to SkAlphaType

BUG=
R=bsalomon@google.com

Review URL: https://codereview.chromium.org/24130009

git-svn-id: http://skia.googlecode.com/svn/trunk@11421 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/bench/DeferredSurfaceCopyBench.cpp b/bench/DeferredSurfaceCopyBench.cpp
index 2aaebe7..f9f8c8e 100644
--- a/bench/DeferredSurfaceCopyBench.cpp
+++ b/bench/DeferredSurfaceCopyBench.cpp
@@ -38,7 +38,7 @@
         info.fWidth = kSurfaceWidth;
         info.fHeight = kSurfaceHeight;
         info.fColorType = SkImage::kPMColor_ColorType;
-        info.fAlphaType = SkImage::kPremul_AlphaType;
+        info.fAlphaType = kPremul_SkAlphaType;
         const SkRect fullCanvasRect = SkRect::MakeWH(
             SkIntToScalar(kSurfaceWidth), SkIntToScalar(kSurfaceHeight));
         SkSurface* surface;
diff --git a/gm/fatpathfill.cpp b/gm/fatpathfill.cpp
index 4498879..8b89232 100644
--- a/gm/fatpathfill.cpp
+++ b/gm/fatpathfill.cpp
@@ -16,13 +16,7 @@
 #define REPEAT_LOOP 5
 
 static SkSurface* new_surface(int width, int height) {
-    SkImage::Info info = {
-        width,
-        height,
-        SkImage::kPMColor_ColorType,
-        SkImage::kPremul_AlphaType
-    };
-    return SkSurface::NewRaster(info);
+    return SkSurface::NewRasterPMColor(width, height);
 }
 
 static void draw_pixel_centers(SkCanvas* canvas) {
diff --git a/gm/image.cpp b/gm/image.cpp
index 6dada0d..e9378be 100644
--- a/gm/image.cpp
+++ b/gm/image.cpp
@@ -178,12 +178,9 @@
         // since we draw into this directly, we need to start fresh
         sk_bzero(fBuffer, fBufferSize);
 
-        SkImage::Info info;
-
-        info.fWidth = W;
-        info.fHeight = H;
-        info.fColorType = SkImage::kPMColor_ColorType;
-        info.fAlphaType = SkImage::kPremul_AlphaType;
+        SkImage::Info info = {
+            W, H, SkImage::kPMColor_ColorType, kPremul_SkAlphaType
+        };
         SkAutoTUnref<SkSurface> surf0(SkSurface::NewRasterDirect(info, fBuffer, RB));
         SkAutoTUnref<SkSurface> surf1(SkSurface::NewRaster(info));
         SkAutoTUnref<SkSurface> surf2(SkSurface::NewPicture(info.fWidth, info.fHeight));
diff --git a/gm/srcmode.cpp b/gm/srcmode.cpp
index e8a97e2..0f2591c 100644
--- a/gm/srcmode.cpp
+++ b/gm/srcmode.cpp
@@ -121,7 +121,7 @@
             size.width(),
             size.height(),
             SkImage::kPMColor_ColorType,
-            SkImage::kPremul_AlphaType
+            kPremul_SkAlphaType
         };
 #if SK_SUPPORT_GPU
         SkBaseDevice* dev = canvas->getDevice();
diff --git a/gyp/core.gypi b/gyp/core.gypi
index 3fdca92..5120805 100644
--- a/gyp/core.gypi
+++ b/gyp/core.gypi
@@ -214,6 +214,7 @@
 
         '<(skia_include_path)/core/Sk64.h',
         '<(skia_include_path)/core/SkAdvancedTypefaceMetrics.h',
+        '<(skia_include_path)/core/SkAlpha.h',
         '<(skia_include_path)/core/SkBitmap.h',
         '<(skia_include_path)/core/SkBitmapDevice.h',
         '<(skia_include_path)/core/SkBlitRow.h',
diff --git a/include/core/SkAlpha.h b/include/core/SkAlpha.h
new file mode 100644
index 0000000..662b741
--- /dev/null
+++ b/include/core/SkAlpha.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkAlpha_DEFINED
+#define SkAlpha_DEFINED
+
+#include "SkTypes.h"
+
+/**
+ *  Describes how to interpret the alpha compoent of a pixel.
+ */
+enum SkAlphaType {
+    /**
+     *  All pixels should be treated as opaque, regardless of the value stored
+     *  in their alpha field. Used for legacy images that wrote 0 or garbarge
+     *  in their alpha field, but intended the RGB to be treated as opaque.
+     */
+    kIgnore_SkAlphaType,
+
+    /**
+     *  All pixels are stored as opaque. This differs slightly from kIgnore in
+     *  that kOpaque has correct "opaque" values stored in the pixels, while
+     *  kIgnore may not, but in both cases the caller should treat the pixels
+     *  as opaque.
+     */
+    kOpaque_SkAlphaType,
+
+    /**
+     *  All pixels have their alpha premultiplied in their color components.
+     *  This is the natural format for the rendering target pixels.
+     */
+    kPremul_SkAlphaType,
+
+    /**
+     *  All pixels have their color components stored without any regard to the
+     *  alpha. e.g. this is the default configuration for PNG images.
+     *
+     *  This alpha-type is ONLY supported for input images. Rendering cannot
+     *  generate this on output.
+     */
+    kUnpremul_SkAlphaType,
+    
+    kLastEnum_SkAlphaType = kUnpremul_SkAlphaType
+};
+
+#endif
diff --git a/include/core/SkImage.h b/include/core/SkImage.h
index 871d461..f6f6a41 100644
--- a/include/core/SkImage.h
+++ b/include/core/SkImage.h
@@ -8,6 +8,7 @@
 #ifndef SkImage_DEFINED
 #define SkImage_DEFINED
 
+#include "SkAlpha.h"
 #include "SkImageEncoder.h"
 #include "SkRefCnt.h"
 #include "SkScalar.h"
@@ -41,25 +42,32 @@
         kRGB_565_ColorType,
         kRGBA_8888_ColorType,
         kBGRA_8888_ColorType,
-        kPMColor_ColorType,
+    
+#if SK_PMCOLOR_BYTE_ORDER(B,G,R,A)
+        kPMColor_ColorType = kBGRA_8888_ColorType,
+#elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A)
+        kPMColor_ColorType = kRGBA_8888_ColorType,
+#else
+        #error "SK_*32_SHFIT values must correspond to BGRA or RGBA byte order
+#endif
 
-        kLastEnum_ColorType = kPMColor_ColorType
+        kLastEnum_ColorType = kBGRA_8888_ColorType
     };
 
+#ifdef SK_ENABLE_LEGACY_API_ALIASING
     enum AlphaType {
-        kIgnore_AlphaType,
-        kOpaque_AlphaType,
-        kPremul_AlphaType,
-        kUnpremul_AlphaType,
-
-        kLastEnum_AlphaType = kUnpremul_AlphaType
+        kIgnore_AlphaType   = kIgnore_SkAlphaType,
+        kOpaque_AlphaType   = kOpaque_SkAlphaType,
+        kPremul_AlphaType   = kPremul_SkAlphaType,
+        kUnpremul_AlphaType = kUnpremul_SkAlphaType,
     };
+#endif
 
     struct Info {
         int         fWidth;
         int         fHeight;
         ColorType   fColorType;
-        AlphaType   fAlphaType;
+        SkAlphaType fAlphaType;
     };
 
     static SkImage* NewRasterCopy(const Info&, const void* pixels, size_t rowBytes);
diff --git a/include/core/SkSurface.h b/include/core/SkSurface.h
index 663cea0..d197a57 100644
--- a/include/core/SkSurface.h
+++ b/include/core/SkSurface.h
@@ -53,7 +53,7 @@
      */
     static SkSurface* NewRasterPMColor(int width, int height) {
         SkImage::Info info = {
-            width, height, SkImage::kPMColor_ColorType, SkImage::kPremul_AlphaType
+            width, height, SkImage::kPMColor_ColorType, kPremul_SkAlphaType
         };
         return NewRaster(info);
     }
diff --git a/samplecode/SampleFatBits.cpp b/samplecode/SampleFatBits.cpp
index 04fa1a3..8159cc5 100644
--- a/samplecode/SampleFatBits.cpp
+++ b/samplecode/SampleFatBits.cpp
@@ -91,13 +91,10 @@
         fInverse.setScale(SK_Scalar1 / zoom, SK_Scalar1 / zoom);
         fShader->setLocalMatrix(fMatrix);
 
-        SkImage::Info info = {
-            width, height, SkImage::kPMColor_ColorType, SkImage::kPremul_AlphaType
-        };
-        fMinSurface.reset(SkSurface::NewRaster(info));
-        info.fWidth *= zoom;
-        info.fHeight *= zoom;
-        fMaxSurface.reset(SkSurface::NewRaster(info));
+        fMinSurface.reset(SkSurface::NewRasterPMColor(width, height));
+        width *= zoom;
+        height *= zoom;
+        fMaxSurface.reset(SkSurface::NewRasterPMColor(width, height));
     }
 
     void drawBG(SkCanvas*);
diff --git a/src/image/SkImagePriv.cpp b/src/image/SkImagePriv.cpp
index 9454272..1e72236 100644
--- a/src/image/SkImagePriv.cpp
+++ b/src/image/SkImagePriv.cpp
@@ -14,16 +14,16 @@
     switch (info.fColorType) {
         case SkImage::kAlpha_8_ColorType:
             switch (info.fAlphaType) {
-                case SkImage::kIgnore_AlphaType:
+                case kIgnore_SkAlphaType:
                     // makes no sense
                     return SkBitmap::kNo_Config;
 
-                case SkImage::kOpaque_AlphaType:
+                case kOpaque_SkAlphaType:
                     *isOpaque = true;
                     return SkBitmap::kA8_Config;
 
-                case SkImage::kPremul_AlphaType:
-                case SkImage::kUnpremul_AlphaType:
+                case kPremul_SkAlphaType:
+                case kUnpremul_SkAlphaType:
                     *isOpaque = false;
                     return SkBitmap::kA8_Config;
             }
@@ -34,27 +34,25 @@
             *isOpaque = true;
             return SkBitmap::kRGB_565_Config;
 
-        case SkImage::kRGBA_8888_ColorType:
-        case SkImage::kBGRA_8888_ColorType:
-            // not supported yet
-            return SkBitmap::kNo_Config;
-
         case SkImage::kPMColor_ColorType:
             switch (info.fAlphaType) {
-                case SkImage::kIgnore_AlphaType:
-                case SkImage::kUnpremul_AlphaType:
+                case kIgnore_SkAlphaType:
+                case kUnpremul_SkAlphaType:
                     // not supported yet
                     return SkBitmap::kNo_Config;
-                case SkImage::kOpaque_AlphaType:
+                case kOpaque_SkAlphaType:
                     *isOpaque = true;
                     return SkBitmap::kARGB_8888_Config;
-                case SkImage::kPremul_AlphaType:
+                case kPremul_SkAlphaType:
                     *isOpaque = false;
                     return SkBitmap::kARGB_8888_Config;
             }
             break;
+        
+        default:
+            // break for unsupported colortypes
+            break;
     }
-    SkDEBUGFAIL("how did we get here");
     return SkBitmap::kNo_Config;
 }
 
@@ -91,8 +89,8 @@
 
     info->fWidth = bm.width();
     info->fHeight = bm.height();
-    info->fAlphaType = bm.isOpaque() ? SkImage::kOpaque_AlphaType :
-                                       SkImage::kPremul_AlphaType;
+    info->fAlphaType = bm.isOpaque() ? kOpaque_SkAlphaType :
+                                       kPremul_SkAlphaType;
     return true;
 }
 
diff --git a/src/image/SkImage_Raster.cpp b/src/image/SkImage_Raster.cpp
index 3e26856..cd9b70f 100644
--- a/src/image/SkImage_Raster.cpp
+++ b/src/image/SkImage_Raster.cpp
@@ -27,7 +27,7 @@
         if ((unsigned)info.fColorType > (unsigned)kLastEnum_ColorType) {
             return false;
         }
-        if ((unsigned)info.fAlphaType > (unsigned)kLastEnum_AlphaType) {
+        if ((unsigned)info.fAlphaType > (unsigned)kLastEnum_SkAlphaType) {
             return false;
         }
 
diff --git a/src/image/SkSurface_Picture.cpp b/src/image/SkSurface_Picture.cpp
index 79812c4..915530c 100644
--- a/src/image/SkSurface_Picture.cpp
+++ b/src/image/SkSurface_Picture.cpp
@@ -62,7 +62,7 @@
         SkImage::Info info;
         info.fWidth = info.fHeight = 0;
         info.fColorType = SkImage::kPMColor_ColorType;
-        info.fAlphaType = SkImage::kOpaque_AlphaType;
+        info.fAlphaType = kOpaque_SkAlphaType;
         return SkImage::NewRasterCopy(info, NULL, 0);
     }
 }
diff --git a/tests/DeferredCanvasTest.cpp b/tests/DeferredCanvasTest.cpp
index 7593ba8..e8075bd 100644
--- a/tests/DeferredCanvasTest.cpp
+++ b/tests/DeferredCanvasTest.cpp
@@ -696,7 +696,7 @@
         10,  // width
         10,  // height
         SkImage::kPMColor_ColorType,
-        SkImage::kPremul_AlphaType
+        kPremul_SkAlphaType
     };
     SkSurface* surface;
     bool useGpu = NULL != factory;
@@ -763,7 +763,7 @@
         10,  // width
         10,  // height
         SkImage::kPMColor_ColorType,
-        SkImage::kPremul_AlphaType
+        kPremul_SkAlphaType
     };
     SkSurface* surface;
     SkSurface* alternateSurface;
diff --git a/tests/DrawPathTest.cpp b/tests/DrawPathTest.cpp
index 9f440f6..40f4a04 100644
--- a/tests/DrawPathTest.cpp
+++ b/tests/DrawPathTest.cpp
@@ -36,10 +36,7 @@
     output.setConfig(SkBitmap::kARGB_8888_Config, 1, 1, 4);
     output.setPixels(pixel);
 
-    SkImage::Info info = {
-        300, 33300, SkImage::kPMColor_ColorType, SkImage::kPremul_AlphaType
-    };
-    SkSurface* surf = SkSurface::NewRaster(info);
+    SkSurface* surf = SkSurface::NewRasterPMColor(300, 33300);
     SkCanvas* canvas = surf->getCanvas();
 
     SkRect r = { 0, 33000, 300, 33300 };
diff --git a/tests/PathTest.cpp b/tests/PathTest.cpp
index 080ce28..ff51edd 100644
--- a/tests/PathTest.cpp
+++ b/tests/PathTest.cpp
@@ -25,13 +25,6 @@
     #define SUPPRESS_VISIBILITY_WARNING __attribute__((visibility("hidden")))
 #endif
 
-static SkSurface* new_surface(int w, int h) {
-    SkImage::Info info = {
-        w, h, SkImage::kPMColor_ColorType, SkImage::kPremul_AlphaType
-    };
-    return SkSurface::NewRaster(info);
-}
-
 static void test_path_close_issue1474(skiatest::Reporter* reporter) {
     // This test checks that r{Line,Quad,Conic,Cubic}To following a close()
     // are relative to the point we close to, not relative to the point we close from.
@@ -141,7 +134,7 @@
 
     SkPaint paint;
     paint.setAntiAlias(true);
-    SkAutoTUnref<SkSurface> surface(new_surface(84, 88));
+    SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(84, 88));
     surface->getCanvas()->drawPath(path, paint);
 }
 
@@ -260,7 +253,7 @@
     SkPaint paint;
     paint.setAntiAlias(true);
 
-    SkAutoTUnref<SkSurface> surface(new_surface(1000, 1000));
+    SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(1000, 1000));
 
     build_path_simple_170666(path);
     surface->getCanvas()->drawPath(path, paint);
@@ -312,7 +305,7 @@
 }
 
 static void test_clipped_cubic() {
-    SkAutoTUnref<SkSurface> surface(new_surface(640, 480));
+    SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(640, 480));
 
     // This path used to assert, because our cubic-chopping code incorrectly
     // moved control points after the chop. This test should be run in SK_DEBUG
@@ -348,7 +341,7 @@
     SkPaint paint;
     paint.setAntiAlias(true);
 
-    SkSurface* surface = new_surface(19, 130);
+    SkSurface* surface = SkSurface::NewRasterPMColor(19, 130);
     surface->getCanvas()->drawPath(path, paint);
     surface->unref();
 }
diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp
index 049f250..80822a1 100644
--- a/tests/SurfaceTest.cpp
+++ b/tests/SurfaceTest.cpp
@@ -28,7 +28,7 @@
         10,  // width
         10,  // height
         SkImage::kPMColor_ColorType,
-        SkImage::kPremul_AlphaType
+        kPremul_SkAlphaType
     };
 
     switch (surfaceType) {
diff --git a/tools/skhello.cpp b/tools/skhello.cpp
index bd31742..d30849b 100644
--- a/tools/skhello.cpp
+++ b/tools/skhello.cpp
@@ -30,10 +30,7 @@
 
 static bool do_surface(int w, int h, const char path[], const char text[],
                        const SkPaint& paint) {
-    SkImage::Info info = {
-        w, h, SkImage::kPMColor_ColorType, SkImage::kPremul_AlphaType
-    };
-    SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info));
+    SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(w, h));
     doDraw(surface->getCanvas(), paint, text);
 
     SkAutoTUnref<SkImage> image(surface->newImageSnapshot());