hide SkBitmap::Config entirely (behind a flag)

patch from issue 339463002

TBR=

I think the NoGPU failure is unrelated, so ignoring
NOTRY=True

Author: reed@google.com

Review URL: https://codereview.chromium.org/340533002
diff --git a/gm/bitmapfilters.cpp b/gm/bitmapfilters.cpp
index 37d49c3..eaaa11a 100644
--- a/gm/bitmapfilters.cpp
+++ b/gm/bitmapfilters.cpp
@@ -1,11 +1,12 @@
-
 /*
  * Copyright 2011 Google Inc.
  *
  * Use of this source code is governed by a BSD-style license that can be
  * found in the LICENSE file.
  */
+
 #include "gm.h"
+#include "sk_tool_utils.h"
 
 namespace skiagm {
 
@@ -46,15 +47,6 @@
     return x + draw_bm(c, bm, x, 0, p);
 }
 
-static const char* gConfigNames[] = {
-    "unknown config",
-    "A8",
-    "Index8",
-    "565",
-    "4444",
-    "8888"
-};
-
 static SkScalar draw_row(SkCanvas* canvas, const SkBitmap& bm) {
     SkAutoCanvasRestore acr(canvas, true);
 
@@ -63,7 +55,7 @@
     const int scale = 32;
 
     paint.setAntiAlias(true);
-    const char* name = gConfigNames[bm.config()];
+    const char* name = sk_tool_utils::colortype_name(bm.colorType());
     canvas->drawText(name, strlen(name), x, SkIntToScalar(bm.height())*scale*5/8,
                      paint);
     canvas->translate(SkIntToScalar(48), 0);
diff --git a/gyp/SampleApp.gyp b/gyp/SampleApp.gyp
index 342e0aa..d4dda70 100644
--- a/gyp/SampleApp.gyp
+++ b/gyp/SampleApp.gyp
@@ -19,6 +19,7 @@
         '../samplecode', # To pull SampleApp.h and SampleCode.h
         '../src/pipe/utils', # For TiledPipeController
         '../src/utils/debugger',
+        '../tools',
       ],
       'includes': [
         'gmslides.gypi',
@@ -134,6 +135,9 @@
         # Lua
         '../src/utils/SkLuaCanvas.cpp',
         '../src/utils/SkLua.cpp',
+        
+        # tools
+        '../tools/sk_tool_utils.cpp',
       ],
       'sources!': [
         '../samplecode/SampleSkLayer.cpp', #relies on SkMatrix44 which doesn't compile
diff --git a/gyp/gm.gyp b/gyp/gm.gyp
index ee52b91..9b74e74 100644
--- a/gyp/gm.gyp
+++ b/gyp/gm.gyp
@@ -13,6 +13,7 @@
       'sources': [
         '../gm/gm_expectations.h',
         '../gm/gm_expectations.cpp',
+        '../tools/sk_tool_utils.cpp',
       ],
       'dependencies': [
         'skia_lib.gyp:skia_lib',
@@ -33,6 +34,7 @@
         '../src/effects',
         '../src/pipe/utils/',
         '../src/utils/',
+        '../tools',
       ],
       'includes': [
         'gmslides.gypi',
diff --git a/gyp/skia_for_android_framework_defines.gypi b/gyp/skia_for_android_framework_defines.gypi
index 39a6b62..9559f43 100644
--- a/gyp/skia_for_android_framework_defines.gypi
+++ b/gyp/skia_for_android_framework_defines.gypi
@@ -17,6 +17,7 @@
       'SK_SUPPORT_LEGACY_SETCONFIG',
       'SK_SUPPORT_LEGACY_IMAGEDECODER_CONFIG',
       'SK_SUPPORT_LEGACY_DEVICE_VIRTUAL_ISOPAQUE',
+      'SK_SUPPORT_LEGACY_BITMAP_CONFIG',
       # Needed until we fix skbug.com/2440.
       'SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG',
       # Transitional, for deprecated SkCanvas::SaveFlags methods.
diff --git a/gyp/skia_for_chromium_defines.gypi b/gyp/skia_for_chromium_defines.gypi
index cb75613..4f4b8d0 100644
--- a/gyp/skia_for_chromium_defines.gypi
+++ b/gyp/skia_for_chromium_defines.gypi
@@ -14,6 +14,7 @@
     #
     'skia_for_chromium_defines': [
       'SK_SUPPORT_LEGACY_GETTOPDEVICE',
+      'SK_SUPPORT_LEGACY_BITMAP_CONFIG',
       'SK_SUPPORT_LEGACY_DEVICE_VIRTUAL_ISOPAQUE',
       'SK_SUPPORT_LEGACY_N32_NAME',
       'SK_SUPPORT_LEGACY_SETCONFIG',
diff --git a/include/core/SkBitmap.h b/include/core/SkBitmap.h
index ddeac25..d3c33a8 100644
--- a/include/core/SkBitmap.h
+++ b/include/core/SkBitmap.h
@@ -38,6 +38,7 @@
 public:
     class SK_API Allocator;
 
+#ifdef SK_SUPPORT_LEGACY_BITMAP_CONFIG
     enum Config {
         kNo_Config,         //!< bitmap has not been configured
         kA8_Config,         //!< 8-bits per pixel, with only alpha specified (0 is transparent, 0xFF is opaque)
@@ -58,6 +59,7 @@
     
     SK_ATTR_DEPRECATED("use config()")
     Config  getConfig() const { return this->config(); }
+#endif
 
     /**
      *  Default construct creates a bitmap with zero width and height, and no pixels.
@@ -895,11 +897,13 @@
     return (*fColorTable)[*((const uint8_t*)fPixels + y * fRowBytes + x)];
 }
 
+#ifdef SK_SUPPORT_LEGACY_BITMAP_CONFIG
 ///////////////////////////////////////////////////////////////////////////////
 //
 // Helpers until we can fully deprecate SkBitmap::Config
 //
 extern SkBitmap::Config SkColorTypeToBitmapConfig(SkColorType);
 extern SkColorType SkBitmapConfigToColorType(SkBitmap::Config);
+#endif
 
 #endif
diff --git a/include/core/SkImageDecoder.h b/include/core/SkImageDecoder.h
index c5c4c78..9ab32d7 100644
--- a/include/core/SkImageDecoder.h
+++ b/include/core/SkImageDecoder.h
@@ -159,6 +159,7 @@
     Chooser* setChooser(Chooser*);
 #endif
 
+#ifdef SK_SUPPORT_LEGACY_BITMAP_CONFIG
     /**
      *  Optional table describing the caller's preferred config based on
      *  information about the src data. Each field should be set to the
@@ -202,6 +203,7 @@
      *  was previously set.
      */
     void resetPrefConfigTable() { fUsePrefTable = false; }
+#endif
 
     SkBitmap::Allocator* getAllocator() const { return fAllocator; }
     SkBitmap::Allocator* setAllocator(SkBitmap::Allocator*);
@@ -471,9 +473,11 @@
     SkBitmap::Allocator*    fAllocator;
     int                     fSampleSize;
     SkColorType             fDefaultPref;   // use if fUsePrefTable is false
+#ifdef SK_SUPPORT_LEGACY_BITMAP_CONFIG
     PrefConfigTable         fPrefTable;     // use if fUsePrefTable is true
-    bool                    fDitherImage;
     bool                    fUsePrefTable;
+#endif
+    bool                    fDitherImage;
     bool                    fSkipWritingZeroes;
     mutable bool            fShouldCancelDecode;
     bool                    fPreferQualityOverSpeed;
diff --git a/include/gpu/SkGr.h b/include/gpu/SkGr.h
index 835d353..1adac65 100644
--- a/include/gpu/SkGr.h
+++ b/include/gpu/SkGr.h
@@ -45,11 +45,13 @@
 
 #include "SkColorPriv.h"
 
+#ifdef SK_SUPPORT_LEGACY_BITMAP_CONFIG
 /**
  *  Convert the SkBitmap::Config to the corresponding PixelConfig, or
  *  kUnknown_PixelConfig if the conversion cannot be done.
  */
 GrPixelConfig SkBitmapConfig2GrPixelConfig(SkBitmap::Config);
+#endif
 GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType, SkAlphaType);
 
 static inline GrPixelConfig SkImageInfo2GrPixelConfig(const SkImageInfo& info) {
diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp
index 35021cb..eee379c 100644
--- a/samplecode/SampleApp.cpp
+++ b/samplecode/SampleApp.cpp
@@ -44,6 +44,7 @@
 #include "SamplePipeControllers.h"
 #include "OverView.h"
 #include "TransitionView.h"
+#include "sk_tool_utils.h"
 
 extern SampleView* CreateSamplePictFileView(const char filename[]);
 
@@ -2082,19 +2083,6 @@
     this->updateTitle();
 }
 
-static const char* gConfigNames[] = {
-    "unknown config",
-    "A8",
-    "Index8",
-    "565",
-    "4444",
-    "8888"
-};
-
-static const char* configToString(SkBitmap::Config c) {
-    return gConfigNames[c];
-}
-
 static const char* gDeviceTypePrefix[] = {
     "raster: ",
     "picture: ",
@@ -2130,7 +2118,7 @@
     title.prepend(gDeviceTypePrefix[fDeviceType]);
 
     title.prepend(" ");
-    title.prepend(configToString(this->getBitmap().config()));
+    title.prepend(sk_tool_utils::colortype_name(this->getBitmap().colorType()));
 
     if (fTilingMode != kNo_Tiling) {
         title.prependf("<T: %s> ", gTilingInfo[fTilingMode].label);
diff --git a/samplecode/SampleFilter.cpp b/samplecode/SampleFilter.cpp
index e17a33c..ae66a0c 100644
--- a/samplecode/SampleFilter.cpp
+++ b/samplecode/SampleFilter.cpp
@@ -20,6 +20,7 @@
 #include "SkColorPriv.h"
 #include "SkColorFilter.h"
 #include "SkDither.h"
+#include "sk_tool_utils.h"
 
 static void make_bm(SkBitmap* bm) {
     const SkPMColor colors[] = {
@@ -52,15 +53,6 @@
     return x + draw_bm(c, bm, x, 0, p);
 }
 
-static const char* gConfigNames[] = {
-    "unknown config",
-    "A8",
-    "Index8",
-    "565",
-    "4444",
-    "8888"
-};
-
 static SkScalar draw_row(SkCanvas* canvas, const SkBitmap& bm) {
     SkAutoCanvasRestore acr(canvas, true);
 
@@ -69,7 +61,7 @@
     const int scale = 32;
 
     paint.setAntiAlias(true);
-    const char* name = gConfigNames[bm.config()];
+    const char* name = sk_tool_utils::colortype_name(bm.colorType());
     canvas->drawText(name, strlen(name), x, SkIntToScalar(bm.height())*scale*5/8,
                      paint);
     canvas->translate(SkIntToScalar(48), 0);
diff --git a/src/animator/SkDrawBitmap.cpp b/src/animator/SkDrawBitmap.cpp
index ce96efb..f481ee7 100644
--- a/src/animator/SkDrawBitmap.cpp
+++ b/src/animator/SkDrawBitmap.cpp
@@ -56,7 +56,7 @@
 
 DEFINE_GET_MEMBER(SkDrawBitmap);
 
-SkDrawBitmap::SkDrawBitmap() : format((SkBitmap::Config) -1), height(-1),
+SkDrawBitmap::SkDrawBitmap() : format((SkColorType) -1), height(-1),
     rowBytes(0),    width(-1), fColor(0), fColorSet(false) {
 }
 
@@ -88,7 +88,7 @@
     SkASSERT(width != -1);
     SkASSERT(height != -1);
     SkASSERT(rowBytes >= 0);
-    SkColorType colorType = SkBitmapConfigToColorType((SkBitmap::Config)format);
+    SkColorType colorType = SkColorType(format);
     fBitmap.setInfo(SkImageInfo::Make(width, height, colorType, kPremul_SkAlphaType), rowBytes);
     fBitmap.allocPixels();
     if (fColorSet)
diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp
index 0490e8f..789bf11 100644
--- a/src/core/SkBitmap.cpp
+++ b/src/core/SkBitmap.cpp
@@ -91,9 +91,11 @@
     sk_bzero(this, sizeof(*this));
 }
 
+#ifdef SK_SUPPORT_LEGACY_BITMAP_CONFIG
 SkBitmap::Config SkBitmap::config() const {
     return SkColorTypeToBitmapConfig(fInfo.colorType());
 }
+#endif
 
 #ifdef SK_SUPPORT_LEGACY_COMPUTE_CONFIG_SIZE
 int SkBitmap::ComputeBytesPerPixel(SkBitmap::Config config) {
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
index 34e5d0f..8e7cea6 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -343,6 +343,7 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 
+#ifdef SK_SUPPORT_LEGACY_BITMAP_CONFIG
 GrPixelConfig SkBitmapConfig2GrPixelConfig(SkBitmap::Config config) {
     switch (config) {
         case SkBitmap::kA8_Config:
@@ -360,6 +361,7 @@
             return kUnknown_GrPixelConfig;
     }
 }
+#endif
 
 // alphatype is ignore for now, but if GrPixelConfig is expanded to encompass
 // alpha info, that will be considered.
diff --git a/src/image/SkImagePriv.cpp b/src/image/SkImagePriv.cpp
index 3ea61d5..f5b7858 100644
--- a/src/image/SkImagePriv.cpp
+++ b/src/image/SkImagePriv.cpp
@@ -9,6 +9,7 @@
 #include "SkCanvas.h"
 #include "SkPicture.h"
 
+#ifdef SK_SUPPORT_LEGACY_BITMAP_CONFIG
 SkBitmap::Config SkColorTypeToBitmapConfig(SkColorType colorType) {
     switch (colorType) {
         case kAlpha_8_SkColorType:
@@ -45,6 +46,7 @@
     SkASSERT((unsigned)config < SK_ARRAY_COUNT(gCT));
     return gCT[config];
 }
+#endif
 
 SkImage* SkNewImageFromBitmap(const SkBitmap& bm, bool canSharePixelRef) {
     const SkImageInfo info = bm.info();
diff --git a/src/images/SkImageDecoder.cpp b/src/images/SkImageDecoder.cpp
index b124187..fe61906 100644
--- a/src/images/SkImageDecoder.cpp
+++ b/src/images/SkImageDecoder.cpp
@@ -23,7 +23,9 @@
     , fSampleSize(1)
     , fDefaultPref(kUnknown_SkColorType)
     , fDitherImage(true)
+#ifdef SK_SUPPORT_LEGACY_BITMAP_CONFIG
     , fUsePrefTable(false)
+#endif
     , fSkipWritingZeroes(false)
     , fPreferQualityOverSpeed(false)
     , fRequireUnpremultipliedColors(false) {
@@ -47,11 +49,13 @@
 #endif
     other->setAllocator(fAllocator);
     other->setSampleSize(fSampleSize);
+#ifdef SK_SUPPORT_LEGACY_BITMAP_CONFIG
     if (fUsePrefTable) {
         other->setPrefConfigTable(fPrefTable);
     } else {
         other->fDefaultPref = fDefaultPref;
     }
+#endif
     other->setDitherImage(fDitherImage);
     other->setSkipWritingZeroes(fSkipWritingZeroes);
     other->setPreferQualityOverSpeed(fPreferQualityOverSpeed);
@@ -140,15 +144,18 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 
+#ifdef SK_SUPPORT_LEGACY_BITMAP_CONFIG
 void SkImageDecoder::setPrefConfigTable(const PrefConfigTable& prefTable) {
     fUsePrefTable = true;
     fPrefTable = prefTable;
 }
+#endif
 
 // TODO: use colortype in fPrefTable, fDefaultPref so we can stop using SkBitmapConfigToColorType()
 //
 SkColorType SkImageDecoder::getPrefColorType(SrcDepth srcDepth, bool srcHasAlpha) const {
     SkColorType ct = fDefaultPref;
+#ifdef SK_SUPPORT_LEGACY_BITMAP_CONFIG
 
     if (fUsePrefTable) {
         // Until we kill or change the PrefTable, we have to go into Config land for a moment.
@@ -169,6 +176,7 @@
         // now return to SkColorType land
         ct = SkBitmapConfigToColorType(config);
     }
+#endif
     return ct;
 }
 
diff --git a/tests/KtxTest.cpp b/tests/KtxTest.cpp
index 93edaf4..5cec2bf 100644
--- a/tests/KtxTest.cpp
+++ b/tests/KtxTest.cpp
@@ -62,7 +62,7 @@
     bool imageDecodeSuccess = SkImageDecoder::DecodeStream(stream, &decodedBitmap);
     REPORTER_ASSERT(reporter, imageDecodeSuccess);
 
-    REPORTER_ASSERT(reporter, decodedBitmap.config() == bm8888.config());
+    REPORTER_ASSERT(reporter, decodedBitmap.colorType() == bm8888.colorType());
     REPORTER_ASSERT(reporter, decodedBitmap.alphaType() == bm8888.alphaType());
     REPORTER_ASSERT(reporter, decodedBitmap.width() == bm8888.width());
     REPORTER_ASSERT(reporter, decodedBitmap.height() == bm8888.height());
diff --git a/third_party/ktx/ktx.cpp b/third_party/ktx/ktx.cpp
index 5eaadef..a05498b 100644
--- a/third_party/ktx/ktx.cpp
+++ b/third_party/ktx/ktx.cpp
@@ -358,7 +358,7 @@
 }
 
 bool SkKTXFile::WriteBitmapToKTX(SkWStream* stream, const SkBitmap& bitmap) {
-    const SkBitmap::Config config = bitmap.config();
+    const SkColorType ct = bitmap.colorType();
     SkAutoLockPixels alp(bitmap);
 
     const int width = bitmap.width();
@@ -379,17 +379,17 @@
 
     // Next, write the header based on the bitmap's config.
     Header hdr;
-    switch (config) {
-        case SkBitmap::kIndex8_Config:
+    switch (ct) {
+        case kIndex_8_SkColorType:
             // There is a compressed format for this, but we don't support it yet.
             SkDebugf("Writing indexed bitmap to KTX unsupported.\n");
             // VVV fall through VVV
         default:
-        case SkBitmap::kNo_Config:
+        case kUnknown_SkColorType:
             // Bitmap hasn't been configured.
             return false;
 
-        case SkBitmap::kA8_Config:
+        case kAlpha_8_SkColorType:
             hdr.fGLType = GR_GL_UNSIGNED_BYTE;
             hdr.fGLTypeSize = 1;
             hdr.fGLFormat = GR_GL_RED;
@@ -397,7 +397,7 @@
             hdr.fGLBaseInternalFormat = GR_GL_RED;
             break;
 
-        case SkBitmap::kRGB_565_Config:
+        case kRGB_565_SkColorType:
             hdr.fGLType = GR_GL_UNSIGNED_SHORT_5_6_5;
             hdr.fGLTypeSize = 2;
             hdr.fGLFormat = GR_GL_RGB;
@@ -405,7 +405,7 @@
             hdr.fGLBaseInternalFormat = GR_GL_RGB;
             break;
 
-        case SkBitmap::kARGB_4444_Config:
+        case kARGB_4444_SkColorType:
             hdr.fGLType = GR_GL_UNSIGNED_SHORT_4_4_4_4;
             hdr.fGLTypeSize = 2;
             hdr.fGLFormat = GR_GL_RGBA;
@@ -414,7 +414,7 @@
             kvPairs.push_back(CreateKeyValue("KTXPremultipliedAlpha", "True"));
             break;
 
-        case SkBitmap::kARGB_8888_Config:
+        case kN32_SkColorType:
             hdr.fGLType = GR_GL_UNSIGNED_BYTE;
             hdr.fGLTypeSize = 1;
             hdr.fGLFormat = GR_GL_RGBA;
@@ -470,7 +470,7 @@
 
     // Write the pixel data...
     const uint8_t* rowPtr = src;
-    if (SkBitmap::kARGB_8888_Config == config) {
+    if (kN32_SkColorType == ct) {
         for (int j = 0; j < height; ++j) {
             const uint32_t* pixelsPtr = reinterpret_cast<const uint32_t*>(rowPtr);
             for (int i = 0; i < width; ++i) {
diff --git a/tools/skpdiff/SkDifferentPixelsMetric_cpu.cpp b/tools/skpdiff/SkDifferentPixelsMetric_cpu.cpp
index 768bfc7..e528b78 100644
--- a/tools/skpdiff/SkDifferentPixelsMetric_cpu.cpp
+++ b/tools/skpdiff/SkDifferentPixelsMetric_cpu.cpp
@@ -21,7 +21,7 @@
     // Ensure the images are comparable
     if (baseline->width() != test->width() || baseline->height() != test->height() ||
         baseline->width() <= 0 || baseline->height() <= 0 ||
-        baseline->config() != test->config()) {
+        baseline->colorType() != test->colorType()) {
         return false;
     }