use some helper Make functions to initialize SkImageInfo

BUG=
R=halcanary@google.com, scroggo@google.com

Author: reed@google.com

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

git-svn-id: http://skia.googlecode.com/svn/trunk@13081 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gm/image.cpp b/gm/image.cpp
index 93e16b7..f5f5228 100644
--- a/gm/image.cpp
+++ b/gm/image.cpp
@@ -178,9 +178,7 @@
         // since we draw into this directly, we need to start fresh
         sk_bzero(fBuffer, fBufferSize);
 
-        SkImageInfo info = {
-            W, H, kPMColor_SkColorType, kPremul_SkAlphaType
-        };
+        SkImageInfo info = SkImageInfo::MakeN32Premul(W, H);
         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 666a36b..6aa236f 100644
--- a/gm/srcmode.cpp
+++ b/gm/srcmode.cpp
@@ -117,12 +117,7 @@
 
     static SkSurface* compat_surface(SkCanvas* canvas, const SkISize& size,
                                      bool skipGPU) {
-        SkImageInfo info = {
-            size.width(),
-            size.height(),
-            kPMColor_SkColorType,
-            kPremul_SkAlphaType
-        };
+        SkImageInfo info = SkImageInfo::MakeN32Premul(size);
 #if SK_SUPPORT_GPU
         SkBaseDevice* dev = canvas->getDevice();
         if (!skipGPU && dev->accessRenderTarget()) {
diff --git a/include/core/SkImageInfo.h b/include/core/SkImageInfo.h
index 1165479..e37f2ef 100644
--- a/include/core/SkImageInfo.h
+++ b/include/core/SkImageInfo.h
@@ -9,6 +9,7 @@
 #define SkImageInfo_DEFINED
 
 #include "SkTypes.h"
+#include "SkSize.h"
 
 class SkFlattenableWriteBuffer;
 class SkFlattenableReadBuffer;
@@ -109,6 +110,55 @@
     SkColorType fColorType;
     SkAlphaType fAlphaType;
 
+    static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at) {
+        SkASSERT(width >= 0);
+        SkASSERT(height >= 0);
+        SkImageInfo info = {
+            width, height, ct, at
+        };
+        return info;
+    }
+
+    /**
+     *  Sets colortype to the native ARGB32 type.
+     */
+    static SkImageInfo MakeN32(int width, int height, SkAlphaType at) {
+        SkASSERT(width >= 0);
+        SkASSERT(height >= 0);
+        SkImageInfo info = {
+            width, height, kPMColor_SkColorType, at
+        };
+        return info;
+    }
+
+    /**
+     *  Sets colortype to the native ARGB32 type, and the alphatype to premul.
+     */
+    static SkImageInfo MakeN32Premul(int width, int height) {
+        SkASSERT(width >= 0);
+        SkASSERT(height >= 0);
+        SkImageInfo info = {
+            width, height, kPMColor_SkColorType, kPremul_SkAlphaType
+        };
+        return info;
+    }
+    
+    /**
+     *  Sets colortype to the native ARGB32 type, and the alphatype to premul.
+     */
+    static SkImageInfo MakeN32Premul(const SkISize& size) {
+        return MakeN32Premul(size.width(), size.height());
+    }
+    
+    static SkImageInfo MakeA8(int width, int height) {
+        SkASSERT(width >= 0);
+        SkASSERT(height >= 0);
+        SkImageInfo info = {
+            width, height, kAlpha_8_SkColorType, kPremul_SkAlphaType
+        };
+        return info;
+    }
+    
     bool isOpaque() const {
         return SkAlphaTypeIsOpaque(fAlphaType);
     }
diff --git a/platform_tools/android/examples/hello_skia_app/jni/helloskia.cpp b/platform_tools/android/examples/hello_skia_app/jni/helloskia.cpp
index 65f6228..dec529f 100644
--- a/platform_tools/android/examples/hello_skia_app/jni/helloskia.cpp
+++ b/platform_tools/android/examples/hello_skia_app/jni/helloskia.cpp
@@ -26,9 +26,7 @@
     AndroidBitmap_getInfo(env, dstBitmap, &dstInfo);
     AndroidBitmap_lockPixels(env, dstBitmap, &dstPixels);
 
-    SkImageInfo info = {
-        dstInfo.width, dstInfo.height, kPMColor_SkColorType, kPremul_SkAlphaType
-    };
+    SkImageInfo info = SkImageInfo::MakeN32Premul(dstInfo.width, dstInfo.height);
 
     // Create a surface from the given bitmap
     SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterDirect(info, dstPixels, dstInfo.stride));
diff --git a/samplecode/SampleFatBits.cpp b/samplecode/SampleFatBits.cpp
index c6fc67f..8b486bd 100644
--- a/samplecode/SampleFatBits.cpp
+++ b/samplecode/SampleFatBits.cpp
@@ -106,9 +106,7 @@
         fInverse.setScale(SK_Scalar1 / zoom, SK_Scalar1 / zoom);
         fShader->setLocalMatrix(fMatrix);
 
-        SkImageInfo info = {
-            width, height, kPMColor_SkColorType, kPremul_SkAlphaType
-        };
+        SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
         fMinSurface.reset(SkSurface::NewRaster(info));
         info.fWidth *= zoom;
         info.fHeight *= zoom;
diff --git a/src/core/SkImageFilterUtils.cpp b/src/core/SkImageFilterUtils.cpp
index 92fe67e..204f38d 100644
--- a/src/core/SkImageFilterUtils.cpp
+++ b/src/core/SkImageFilterUtils.cpp
@@ -15,12 +15,7 @@
 #include "SkGr.h"
 
 bool SkImageFilterUtils::WrapTexture(GrTexture* texture, int width, int height, SkBitmap* result) {
-    SkImageInfo info = {
-        width,
-        height,
-        kPMColor_SkColorType,
-        kPremul_SkAlphaType,
-    };
+    SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
     result->setConfig(info);
     result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref();
     return true;
diff --git a/src/core/SkScaledImageCache.cpp b/src/core/SkScaledImageCache.cpp
index fc3148b..d875973 100644
--- a/src/core/SkScaledImageCache.cpp
+++ b/src/core/SkScaledImageCache.cpp
@@ -293,13 +293,8 @@
         return false;
     }
 
-    SkImageInfo info = {
-        bitmap->width(),
-        bitmap->height(),
-        kPMColor_SkColorType,
-        bitmap->alphaType()
-    };
-
+    SkImageInfo info = SkImageInfo::MakeN32(bitmap->width(), bitmap->height(),
+                                            bitmap->alphaType());
     bitmap->setPixelRef(SkNEW_ARGS(SkOneShotDiscardablePixelRef,
                                    (info, dm, bitmap->rowBytes())))->unref();
     bitmap->lockPixels();
diff --git a/tests/MallocPixelRefTest.cpp b/tests/MallocPixelRefTest.cpp
index bf8f16d..5c28ac8 100644
--- a/tests/MallocPixelRefTest.cpp
+++ b/tests/MallocPixelRefTest.cpp
@@ -22,7 +22,7 @@
  */
 DEF_TEST(MallocPixelRef, reporter) {
     REPORTER_ASSERT(reporter, true);
-    SkImageInfo info = {10, 13, kPMColor_SkColorType, kPremul_SkAlphaType};
+    SkImageInfo info = SkImageInfo::MakeN32Premul(10, 13);
     {
         SkAutoTUnref<SkMallocPixelRef> pr(
             SkMallocPixelRef::NewAllocate(info, info.minRowBytes() - 1, NULL));
diff --git a/tests/PixelRefTest.cpp b/tests/PixelRefTest.cpp
index 3c735c6..d7fe9f4 100644
--- a/tests/PixelRefTest.cpp
+++ b/tests/PixelRefTest.cpp
@@ -50,7 +50,7 @@
 }  // namespace
 
 DEF_TEST(PixelRef_GenIDChange, r) {
-    SkImageInfo info = { 10, 10, kPMColor_SkColorType, kPremul_SkAlphaType };
+    SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10);
 
     SkAutoTUnref<SkPixelRef> pixelRef(SkMallocPixelRef::NewAllocate(info, 0, NULL));