use colortype instead of config

clone of https://codereview.chromium.org/305133006/

TBR=

BUG=skia:

Author: reed@google.com

Review URL: https://codereview.chromium.org/301233011
diff --git a/include/core/SkImageInfo.h b/include/core/SkImageInfo.h
index 8391954..d66158d 100644
--- a/include/core/SkImageInfo.h
+++ b/include/core/SkImageInfo.h
@@ -189,6 +189,14 @@
 
     SkISize dimensions() const { return SkISize::Make(fWidth, fHeight); }
 
+    /**
+     *  Return a new ImageInfo with the same colortype and alphatype as this info,
+     *  but with the specified width and height.
+     */
+    SkImageInfo makeWH(int newWidth, int newHeight) const {
+        return SkImageInfo::Make(newWidth, newHeight, fColorType, fAlphaType);
+    }
+
     int bytesPerPixel() const {
         return SkColorTypeBytesPerPixel(fColorType);
     }
diff --git a/src/effects/SkAlphaThresholdFilter.cpp b/src/effects/SkAlphaThresholdFilter.cpp
index 205e9a9..6fcd2b4 100644
--- a/src/effects/SkAlphaThresholdFilter.cpp
+++ b/src/effects/SkAlphaThresholdFilter.cpp
@@ -323,8 +323,7 @@
         return false;
     }
 
-    dst->setConfig(src.config(), src.width(), src.height());
-    if (!dst->allocPixels()) {
+    if (!dst->allocPixels(src.info())) {
         return false;
     }
 
diff --git a/src/effects/SkBicubicImageFilter.cpp b/src/effects/SkBicubicImageFilter.cpp
index 8f78ff2..ea2d13e 100644
--- a/src/effects/SkBicubicImageFilter.cpp
+++ b/src/effects/SkBicubicImageFilter.cpp
@@ -107,8 +107,7 @@
     if (dstIRect.isEmpty()) {
         return false;
     }
-    result->setConfig(src.config(), dstIRect.width(), dstIRect.height());
-    if (!result->allocPixels()) {
+    if (!result->allocPixels(src.info().makeWH(dstIRect.width(), dstIRect.height()))) {
         return false;
     }
 
diff --git a/src/effects/SkBlurImageFilter.cpp b/src/effects/SkBlurImageFilter.cpp
index 00064d4..470dcac 100644
--- a/src/effects/SkBlurImageFilter.cpp
+++ b/src/effects/SkBlurImageFilter.cpp
@@ -163,11 +163,10 @@
         return false;
     }
 
-    dst->setConfig(src.config(), srcBounds.width(), srcBounds.height());
-    dst->getBounds(&dstBounds);
-    if (!dst->allocPixels()) {
+    if (!dst->allocPixels(src.info().makeWH(srcBounds.width(), srcBounds.height()))) {
         return false;
     }
+    dst->getBounds(&dstBounds);
 
     SkVector sigma = SkVector::Make(fSigma.width(), fSigma.height());
     ctx.ctm().mapVectors(&sigma, 1);
@@ -191,8 +190,7 @@
     }
 
     SkBitmap temp;
-    temp.setConfig(dst->config(), dst->width(), dst->height());
-    if (!temp.allocPixels()) {
+    if (!temp.allocPixels(dst->info())) {
         return false;
     }
 
diff --git a/src/effects/SkDisplacementMapEffect.cpp b/src/effects/SkDisplacementMapEffect.cpp
index d0f134b..a5519d1 100644
--- a/src/effects/SkDisplacementMapEffect.cpp
+++ b/src/effects/SkDisplacementMapEffect.cpp
@@ -227,8 +227,7 @@
         return false;
     }
 
-    dst->setConfig(color.config(), bounds.width(), bounds.height());
-    if (!dst->allocPixels()) {
+    if (!dst->allocPixels(color.info().makeWH(bounds.width(), bounds.height()))) {
         return false;
     }
 
diff --git a/src/effects/SkLightingImageFilter.cpp b/src/effects/SkLightingImageFilter.cpp
index 24fdd0e..c0c605c 100644
--- a/src/effects/SkLightingImageFilter.cpp
+++ b/src/effects/SkLightingImageFilter.cpp
@@ -960,8 +960,7 @@
         return false;
     }
 
-    dst->setConfig(src.config(), bounds.width(), bounds.height());
-    if (!dst->allocPixels()) {
+    if (!dst->allocPixels(src.info().makeWH(bounds.width(), bounds.height()))) {
         return false;
     }
 
@@ -1052,9 +1051,7 @@
         return false;
     }
 
-    dst->setConfig(src.config(), bounds.width(), bounds.height());
-    dst->allocPixels();
-    if (!dst->getPixels()) {
+    if (!dst->allocPixels(src.info().makeWH(bounds.width(), bounds.height()))) {
         return false;
     }
 
diff --git a/src/effects/SkMagnifierImageFilter.cpp b/src/effects/SkMagnifierImageFilter.cpp
index 5096640..99c0176 100644
--- a/src/effects/SkMagnifierImageFilter.cpp
+++ b/src/effects/SkMagnifierImageFilter.cpp
@@ -298,9 +298,7 @@
       return false;
     }
 
-    dst->setConfig(src.config(), src.width(), src.height());
-    dst->allocPixels();
-    if (!dst->getPixels()) {
+    if (!dst->allocPixels(src.info())) {
         return false;
     }
 
diff --git a/src/effects/SkMatrixConvolutionImageFilter.cpp b/src/effects/SkMatrixConvolutionImageFilter.cpp
index f6bc6a1..8ae8377 100644
--- a/src/effects/SkMatrixConvolutionImageFilter.cpp
+++ b/src/effects/SkMatrixConvolutionImageFilter.cpp
@@ -238,9 +238,7 @@
         return SkBitmap();
     }
     SkBitmap result;
-    result.setConfig(src.config(), src.width(), src.height());
-    result.allocPixels();
-    if (!result.getPixels()) {
+    if (!result.allocPixels(src.info())) {
         return SkBitmap();
     }
     for (int y = 0; y < src.height(); ++y) {
diff --git a/src/effects/SkMorphologyImageFilter.cpp b/src/effects/SkMorphologyImageFilter.cpp
index 8803f8a..19a9b68 100644
--- a/src/effects/SkMorphologyImageFilter.cpp
+++ b/src/effects/SkMorphologyImageFilter.cpp
@@ -163,9 +163,7 @@
         return false;
     }
 
-    dst->setConfig(src.config(), bounds.width(), bounds.height());
-    dst->allocPixels();
-    if (!dst->getPixels()) {
+    if (!dst->allocPixels(src.info().makeWH(bounds.width(), bounds.height()))) {
         return false;
     }
 
@@ -190,8 +188,7 @@
     }
 
     SkBitmap temp;
-    temp.setConfig(dst->config(), dst->width(), dst->height());
-    if (!temp.allocPixels()) {
+    if (!temp.allocPixels(dst->info())) {
         return false;
     }
 
diff --git a/src/opts/SkBitmapProcState_opts_SSE2.cpp b/src/opts/SkBitmapProcState_opts_SSE2.cpp
index 2279b9d..1f3bbc1 100644
--- a/src/opts/SkBitmapProcState_opts_SSE2.cpp
+++ b/src/opts/SkBitmapProcState_opts_SSE2.cpp
@@ -16,7 +16,7 @@
                                    int count, uint32_t* colors) {
     SkASSERT(count > 0 && colors != NULL);
     SkASSERT(s.fFilterLevel != SkPaint::kNone_FilterLevel);
-    SkASSERT(s.fBitmap->config() == SkBitmap::kARGB_8888_Config);
+    SkASSERT(kN32_SkColorType == s.fBitmap->colorType());
     SkASSERT(s.fAlphaScale == 256);
 
     const char* srcAddr = static_cast<const char*>(s.fBitmap->getPixels());
@@ -122,7 +122,7 @@
                                   int count, uint32_t* colors) {
     SkASSERT(count > 0 && colors != NULL);
     SkASSERT(s.fFilterLevel != SkPaint::kNone_FilterLevel);
-    SkASSERT(s.fBitmap->config() == SkBitmap::kARGB_8888_Config);
+    SkASSERT(kN32_SkColorType == s.fBitmap->colorType());
     SkASSERT(s.fAlphaScale < 256);
 
     const char* srcAddr = static_cast<const char*>(s.fBitmap->getPixels());
@@ -642,7 +642,7 @@
                             int count, uint16_t* colors) {
     SkASSERT(count > 0 && colors != NULL);
     SkASSERT(s.fFilterLevel != SkPaint::kNone_FilterLevel);
-    SkASSERT(s.fBitmap->config() == SkBitmap::kARGB_8888_Config);
+    SkASSERT(kN32_SkColorType == s.fBitmap->colorType());
     SkASSERT(s.fBitmap->isOpaque());
 
     SkPMColor dstColor;
diff --git a/src/opts/SkBitmapProcState_opts_SSSE3.cpp b/src/opts/SkBitmapProcState_opts_SSSE3.cpp
index 4622937..5b97215 100644
--- a/src/opts/SkBitmapProcState_opts_SSSE3.cpp
+++ b/src/opts/SkBitmapProcState_opts_SSSE3.cpp
@@ -395,7 +395,7 @@
                                      int count, uint32_t* colors) {
     SkASSERT(count > 0 && colors != NULL);
     SkASSERT(s.fFilterLevel != SkPaint::kNone_FilterLevel);
-    SkASSERT(s.fBitmap->config() == SkBitmap::kARGB_8888_Config);
+    SkASSERT(kN32_SkColorType == s.fBitmap->colorType());
     if (has_alpha) {
         SkASSERT(s.fAlphaScale < 256);
     } else {
@@ -587,7 +587,7 @@
                                        int count, uint32_t* colors) {
     SkASSERT(count > 0 && colors != NULL);
     SkASSERT(s.fFilterLevel != SkPaint::kNone_FilterLevel);
-    SkASSERT(s.fBitmap->config() == SkBitmap::kARGB_8888_Config);
+    SkASSERT(kN32_SkColorType == s.fBitmap->colorType());
     if (has_alpha) {
         SkASSERT(s.fAlphaScale < 256);
     } else {
diff --git a/src/opts/SkBitmapProcState_opts_arm.cpp b/src/opts/SkBitmapProcState_opts_arm.cpp
index c2376d4..ffa0ccf 100644
--- a/src/opts/SkBitmapProcState_opts_arm.cpp
+++ b/src/opts/SkBitmapProcState_opts_arm.cpp
@@ -202,8 +202,8 @@
         justDx = true;
     }
 
-    switch (fBitmap->config()) {
-        case SkBitmap::kIndex8_Config:
+    switch (fBitmap->colorType()) {
+        case kIndex_8_SkColorType:
             if (justDx && SkPaint::kNone_FilterLevel == fFilterLevel) {
 #if 0   /* crashing on android device */
                 fSampleProc16 = SI8_D16_nofilter_DX_arm;
diff --git a/src/opts/SkBlitMask_opts_arm.cpp b/src/opts/SkBlitMask_opts_arm.cpp
index a8a92cc..11e172c 100644
--- a/src/opts/SkBlitMask_opts_arm.cpp
+++ b/src/opts/SkBlitMask_opts_arm.cpp
@@ -24,7 +24,7 @@
         return NULL;
     }
 #endif
-    if ((SkBitmap::kARGB_8888_Config == dstConfig) &&
+    if ((kN32_SkColorType == dstCT) &&
         (SkMask::kA8_Format == maskFormat)) {
             return D32_A8_Factory_neon(color);
     }
diff --git a/src/pdf/SkPDFImage.cpp b/src/pdf/SkPDFImage.cpp
index f39dc59..77fd84e 100644
--- a/src/pdf/SkPDFImage.cpp
+++ b/src/pdf/SkPDFImage.cpp
@@ -27,16 +27,17 @@
 
 static size_t get_uncompressed_size(const SkBitmap& bitmap,
                                     const SkIRect& srcRect) {
-    switch (bitmap.config()) {
-        case SkBitmap::kIndex8_Config:
+    switch (bitmap.colorType()) {
+        case kIndex_8_SkColorType:
             return srcRect.width() * srcRect.height();
-        case SkBitmap::kARGB_4444_Config:
+        case kARGB_4444_SkColorType:
             return ((srcRect.width() * 3 + 1) / 2) * srcRect.height();
-        case SkBitmap::kRGB_565_Config:
+        case kRGB_565_SkColorType:
             return srcRect.width() * 3 * srcRect.height();
-        case SkBitmap::kARGB_8888_Config:
+        case kRGBA_8888_SkColorType:
+        case kBGRA_8888_SkColorType:
             return srcRect.width() * 3 * srcRect.height();
-        case SkBitmap::kA8_Config:
+        case kAlpha_8_SkColorType:
             return 1;
         default:
             SkASSERT(false);
@@ -208,9 +209,9 @@
 static SkStream* extract_image_data(const SkBitmap& bitmap,
                                     const SkIRect& srcRect,
                                     bool extractAlpha, bool* isTransparent) {
-    SkBitmap::Config config = bitmap.config();
-    if (extractAlpha && (config == SkBitmap::kIndex8_Config ||
-            config == SkBitmap::kRGB_565_Config)) {
+    SkColorType colorType = bitmap.colorType();
+    if (extractAlpha && (kIndex_8_SkColorType == colorType ||
+                         kRGB_565_SkColorType == colorType)) {
         if (isTransparent != NULL) {
             *isTransparent = false;
         }
@@ -221,26 +222,26 @@
     SkStream* stream = NULL;
 
     bitmap.lockPixels();
-    switch (config) {
-        case SkBitmap::kIndex8_Config:
+    switch (colorType) {
+        case kIndex_8_SkColorType:
             if (!extractAlpha) {
                 stream = extract_index8_image(bitmap, srcRect);
             }
             break;
-        case SkBitmap::kARGB_4444_Config:
+        case kARGB_4444_SkColorType:
             stream = extract_argb4444_data(bitmap, srcRect, extractAlpha,
                                            &isOpaque, &transparent);
             break;
-        case SkBitmap::kRGB_565_Config:
+        case kRGB_565_SkColorType:
             if (!extractAlpha) {
                 stream = extract_rgb565_image(bitmap, srcRect);
             }
             break;
-        case SkBitmap::kARGB_8888_Config:
+        case kN32_SkColorType:
             stream = extract_argb8888_data(bitmap, srcRect, extractAlpha,
                                            &isOpaque, &transparent);
             break;
-        case SkBitmap::kA8_Config:
+        case kAlpha_8_SkColorType:
             if (!extractAlpha) {
                 stream = create_black_image();
             } else {
@@ -373,14 +374,13 @@
 static SkBitmap unpremultiply_bitmap(const SkBitmap& bitmap,
                                      const SkIRect& srcRect) {
     SkBitmap outBitmap;
-    outBitmap.setConfig(bitmap.config(), srcRect.width(), srcRect.height());
-    outBitmap.allocPixels();
+    outBitmap.allocPixels(bitmap.info().makeWH(srcRect.width(), srcRect.height()));
     int dstRow = 0;
 
     outBitmap.lockPixels();
     bitmap.lockPixels();
-    switch (bitmap.config()) {
-        case SkBitmap::kARGB_4444_Config: {
+    switch (bitmap.colorType()) {
+        case kARGB_4444_SkColorType: {
             for (int y = srcRect.fTop; y < srcRect.fBottom; y++) {
                 uint16_t* dst = outBitmap.getAddr16(0, dstRow);
                 uint16_t* src = bitmap.getAddr16(0, y);
@@ -408,7 +408,7 @@
             }
             break;
         }
-        case SkBitmap::kARGB_8888_Config: {
+        case kN32_SkColorType: {
             for (int y = srcRect.fTop; y < srcRect.fBottom; y++) {
                 uint32_t* dst = outBitmap.getAddr32(0, dstRow);
                 uint32_t* src = bitmap.getAddr32(0, y);
@@ -440,7 +440,7 @@
 SkPDFImage* SkPDFImage::CreateImage(const SkBitmap& bitmap,
                                     const SkIRect& srcRect,
                                     SkPicture::EncodeBitmap encoder) {
-    if (bitmap.config() == SkBitmap::kNo_Config) {
+    if (bitmap.colorType() == kUnknown_SkColorType) {
         return NULL;
     }
 
@@ -459,9 +459,9 @@
     }
 
     SkPDFImage* image;
-    SkBitmap::Config config = bitmap.config();
-    if (alphaData.get() != NULL && (config == SkBitmap::kARGB_8888_Config ||
-            config == SkBitmap::kARGB_4444_Config)) {
+    SkColorType colorType = bitmap.colorType();
+    if (alphaData.get() != NULL && (kN32_SkColorType == colorType ||
+                                    kARGB_4444_SkColorType == colorType)) {
         SkBitmap unpremulBitmap = unpremultiply_bitmap(bitmap, srcRect);
         image = SkNEW_ARGS(SkPDFImage, (NULL, unpremulBitmap, false,
                            SkIRect::MakeWH(srcRect.width(), srcRect.height()),
@@ -518,12 +518,12 @@
         fStreamValid = false;
     }
 
-    SkBitmap::Config config = fBitmap.config();
+    SkColorType colorType = fBitmap.colorType();
 
     insertName("Type", "XObject");
     insertName("Subtype", "Image");
 
-    bool alphaOnly = (config == SkBitmap::kA8_Config);
+    bool alphaOnly = (kAlpha_8_SkColorType == colorType);
 
     if (!isAlpha && alphaOnly) {
         // For alpha only images, we stretch a single pixel of black for
@@ -538,7 +538,7 @@
 
     if (isAlpha || alphaOnly) {
         insertName("ColorSpace", "DeviceGray");
-    } else if (config == SkBitmap::kIndex8_Config) {
+    } else if (kIndex_8_SkColorType == colorType) {
         SkAutoLockPixels alp(fBitmap);
         insert("ColorSpace",
                make_indexed_color_space(fBitmap.getColorTable()))->unref();
@@ -547,12 +547,12 @@
     }
 
     int bitsPerComp = 8;
-    if (config == SkBitmap::kARGB_4444_Config) {
+    if (kARGB_4444_SkColorType == colorType) {
         bitsPerComp = 4;
     }
     insertInt("BitsPerComponent", bitsPerComp);
 
-    if (config == SkBitmap::kRGB_565_Config) {
+    if (kRGB_565_SkColorType == colorType) {
         SkASSERT(!isAlpha);
         SkAutoTUnref<SkPDFInt> zeroVal(new SkPDFInt(0));
         SkAutoTUnref<SkPDFScalar> scale5Val(
@@ -592,8 +592,6 @@
             SkBitmap subset;
             // Extract subset
             if (!fBitmap.extractSubset(&subset, fSrcRect)) {
-                // TODO(edisonn) It fails only for kA1_Config, if that is a
-                // major concern we will fix it later, so far it is NYI.
                 return false;
             }
             size_t pixelRefOffset = 0;
diff --git a/src/utils/SkBitmapHasher.cpp b/src/utils/SkBitmapHasher.cpp
index bd038dd..32ff1cb 100644
--- a/src/utils/SkBitmapHasher.cpp
+++ b/src/utils/SkBitmapHasher.cpp
@@ -55,7 +55,7 @@
     }
 
     // Hmm, that didn't work. Maybe if we create a new
-    // kARGB_8888_Config version of the bitmap it will work better?
+    // version of the bitmap it will work better?
     SkBitmap copyBitmap;
     if (!bitmap.copyTo(&copyBitmap, kN32_SkColorType)) {
         return false;
diff --git a/src/utils/SkBitmapHasher.h b/src/utils/SkBitmapHasher.h
index d52a6d7..c8a5c04 100644
--- a/src/utils/SkBitmapHasher.h
+++ b/src/utils/SkBitmapHasher.h
@@ -22,7 +22,7 @@
      * If this is unable to compute the hash for some reason,
      * it returns false.
      *
-     * Note: depending on the bitmap config, we may need to create an
+     * Note: depending on the bitmap colortype, we may need to create an
      * intermediate SkBitmap and copy the pixels over to it... so in some
      * cases, performance and memory usage can suffer.
      */
diff --git a/src/utils/SkPictureUtils.cpp b/src/utils/SkPictureUtils.cpp
index 4dcb855..a2d6da1 100644
--- a/src/utils/SkPictureUtils.cpp
+++ b/src/utils/SkPictureUtils.cpp
@@ -114,7 +114,7 @@
     virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap,
                             const SkMatrix&, const SkPaint& paint) SK_OVERRIDE {
         this->addBitmap(bitmap);
-        if (SkBitmap::kA8_Config == bitmap.config()) {
+        if (kAlpha_8_SkColorType == bitmap.colorType()) {
             this->addBitmapFromPaint(paint);
         }
     }
@@ -123,7 +123,7 @@
                                 const SkPaint& paint,
                                 SkCanvas::DrawBitmapRectFlags flags) SK_OVERRIDE {
         this->addBitmap(bitmap);
-        if (SkBitmap::kA8_Config == bitmap.config()) {
+        if (kAlpha_8_SkColorType == bitmap.colorType()) {
             this->addBitmapFromPaint(paint);
         }
     }
diff --git a/src/utils/debugger/SkObjectParser.cpp b/src/utils/debugger/SkObjectParser.cpp
index a3b2085..b932036 100644
--- a/src/utils/debugger/SkObjectParser.cpp
+++ b/src/utils/debugger/SkObjectParser.cpp
@@ -25,13 +25,13 @@
     mBitmap->append(" H: ");
     mBitmap->appendS32(bitmap.height());
 
-    const char* gConfigStrings[] = {
-        "None", "A8", "Index8", "RGB565", "ARGB4444", "ARGB8888"
+    const char* gColorTypeStrings[] = {
+        "None", "A8", "565", "4444", "RGBA", "BGRA", "Index8"
     };
-    SkASSERT(SkBitmap::kConfigCount == SK_ARRAY_COUNT(gConfigStrings));
+    SkASSERT(kLastEnum_SkColorType + 1 == SK_ARRAY_COUNT(gColorTypeStrings));
 
-    mBitmap->append(" Config: ");
-    mBitmap->append(gConfigStrings[bitmap.config()]);
+    mBitmap->append(" ColorType: ");
+    mBitmap->append(gColorTypeStrings[bitmap.colorType()]);
 
     if (bitmap.isOpaque()) {
         mBitmap->append(" opaque");
diff --git a/src/utils/debugger/SkObjectParser.h b/src/utils/debugger/SkObjectParser.h
index 911b778..da84265 100644
--- a/src/utils/debugger/SkObjectParser.h
+++ b/src/utils/debugger/SkObjectParser.h
@@ -20,7 +20,7 @@
 public:
 
     /**
-        Returns a string about a bitmaps bounds and config.
+        Returns a string about a bitmaps bounds and colortype.
         @param bitmap  SkBitmap
     */
     static SkString* BitmapToString(const SkBitmap& bitmap);