aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar reed <reed@google.com>2014-06-17 08:38:31 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-06-17 08:38:31 -0700
commitc3b3266b7db2f1a41d41ecac010c766b7ad8eebc (patch)
treec45d9892b2ac00bfe74f322eafb6e68d8121a9ea
parenta272d6d0653620cb6b683a70d3e6993d380147d9 (diff)
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
-rw-r--r--gm/bitmapfilters.cpp14
-rw-r--r--gyp/SampleApp.gyp4
-rw-r--r--gyp/gm.gyp2
-rw-r--r--gyp/skia_for_android_framework_defines.gypi1
-rw-r--r--gyp/skia_for_chromium_defines.gypi1
-rw-r--r--include/core/SkBitmap.h4
-rw-r--r--include/core/SkImageDecoder.h6
-rw-r--r--include/gpu/SkGr.h2
-rw-r--r--samplecode/SampleApp.cpp16
-rw-r--r--samplecode/SampleFilter.cpp12
-rw-r--r--src/animator/SkDrawBitmap.cpp4
-rw-r--r--src/core/SkBitmap.cpp2
-rw-r--r--src/gpu/SkGr.cpp2
-rw-r--r--src/image/SkImagePriv.cpp2
-rw-r--r--src/images/SkImageDecoder.cpp8
-rw-r--r--tests/KtxTest.cpp2
-rw-r--r--third_party/ktx/ktx.cpp18
-rw-r--r--tools/skpdiff/SkDifferentPixelsMetric_cpu.cpp2
18 files changed, 53 insertions, 49 deletions
diff --git a/gm/bitmapfilters.cpp b/gm/bitmapfilters.cpp
index 37d49c3fea..eaaa11a2c6 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 @@ static SkScalar draw_set(SkCanvas* c, const SkBitmap& bm, SkScalar x,
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 @@ static SkScalar draw_row(SkCanvas* canvas, const SkBitmap& bm) {
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 342e0aa1d4..d4dda70049 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 ee52b91d78..9b74e74669 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 39a6b62a78..9559f43923 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 cb75613ed6..4f4b8d07e4 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 ddeac2573b..d3c33a8e03 100644
--- a/include/core/SkBitmap.h
+++ b/include/core/SkBitmap.h
@@ -38,6 +38,7 @@ class SK_API SkBitmap {
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 @@ public:
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 @@ inline SkPMColor SkBitmap::getIndex8Color(int x, int y) const {
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 c5c4c782c0..9ab32d7ce1 100644
--- a/include/core/SkImageDecoder.h
+++ b/include/core/SkImageDecoder.h
@@ -159,6 +159,7 @@ public:
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 @@ public:
* was previously set.
*/
void resetPrefConfigTable() { fUsePrefTable = false; }
+#endif
SkBitmap::Allocator* getAllocator() const { return fAllocator; }
SkBitmap::Allocator* setAllocator(SkBitmap::Allocator*);
@@ -471,9 +473,11 @@ private:
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 835d353a2c..1adac654a6 100644
--- a/include/gpu/SkGr.h
+++ b/include/gpu/SkGr.h
@@ -45,11 +45,13 @@ GR_STATIC_ASSERT((int)kIDA_GrBlendCoeff == (int)SkXfermode::kIDA_Coeff);
#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 35021cba9f..eee379cf8b 100644
--- a/samplecode/SampleApp.cpp
+++ b/samplecode/SampleApp.cpp
@@ -44,6 +44,7 @@ class GrContext;
#include "SamplePipeControllers.h"
#include "OverView.h"
#include "TransitionView.h"
+#include "sk_tool_utils.h"
extern SampleView* CreateSamplePictFileView(const char filename[]);
@@ -2082,19 +2083,6 @@ void SampleWindow::loadView(SkView* view) {
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 @@ void SampleWindow::updateTitle() {
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 e17a33c3d4..ae66a0ce4c 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 @@ static SkScalar draw_set(SkCanvas* c, const SkBitmap& bm, SkScalar x, SkPaint* p
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 @@ static SkScalar draw_row(SkCanvas* canvas, const SkBitmap& bm) {
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 ce96efbed2..f481ee7dba 100644
--- a/src/animator/SkDrawBitmap.cpp
+++ b/src/animator/SkDrawBitmap.cpp
@@ -56,7 +56,7 @@ const SkMemberInfo SkDrawBitmap::fInfo[] = {
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 @@ void SkDrawBitmap::onEndElement(SkAnimateMaker&) {
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 0490e8f482..789bf11b4c 100644
--- a/src/core/SkBitmap.cpp
+++ b/src/core/SkBitmap.cpp
@@ -91,9 +91,11 @@ void SkBitmap::reset() {
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 34e5d0fde3..8e7cea64d4 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -343,6 +343,7 @@ void GrUnlockAndUnrefCachedBitmapTexture(GrTexture* texture) {
///////////////////////////////////////////////////////////////////////////////
+#ifdef SK_SUPPORT_LEGACY_BITMAP_CONFIG
GrPixelConfig SkBitmapConfig2GrPixelConfig(SkBitmap::Config config) {
switch (config) {
case SkBitmap::kA8_Config:
@@ -360,6 +361,7 @@ GrPixelConfig SkBitmapConfig2GrPixelConfig(SkBitmap::Config config) {
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 3ea61d519b..f5b785877c 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 @@ SkColorType SkBitmapConfigToColorType(SkBitmap::Config config) {
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 b124187505..fe61906357 100644
--- a/src/images/SkImageDecoder.cpp
+++ b/src/images/SkImageDecoder.cpp
@@ -23,7 +23,9 @@ SkImageDecoder::SkImageDecoder()
, 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 @@ void SkImageDecoder::copyFieldsToOther(SkImageDecoder* other) {
#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 @@ bool SkImageDecoder::allocPixelRef(SkBitmap* bitmap,
///////////////////////////////////////////////////////////////////////////////
+#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 @@ SkColorType SkImageDecoder::getPrefColorType(SrcDepth srcDepth, bool srcHasAlpha
// now return to SkColorType land
ct = SkBitmapConfigToColorType(config);
}
+#endif
return ct;
}
diff --git a/tests/KtxTest.cpp b/tests/KtxTest.cpp
index 93edaf41f1..5cec2bf297 100644
--- a/tests/KtxTest.cpp
+++ b/tests/KtxTest.cpp
@@ -62,7 +62,7 @@ DEF_TEST(KtxReadWrite, reporter) {
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 5eaadef3bd..a05498b7e8 100644
--- a/third_party/ktx/ktx.cpp
+++ b/third_party/ktx/ktx.cpp
@@ -358,7 +358,7 @@ bool SkKTXFile::WriteETC1ToKTX(SkWStream* stream, const uint8_t *etc1Data,
}
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 @@ bool SkKTXFile::WriteBitmapToKTX(SkWStream* stream, const SkBitmap& bitmap) {
// 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 @@ bool SkKTXFile::WriteBitmapToKTX(SkWStream* stream, const SkBitmap& bitmap) {
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 @@ bool SkKTXFile::WriteBitmapToKTX(SkWStream* stream, const SkBitmap& bitmap) {
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 @@ bool SkKTXFile::WriteBitmapToKTX(SkWStream* stream, const SkBitmap& bitmap) {
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 @@ bool SkKTXFile::WriteBitmapToKTX(SkWStream* stream, const SkBitmap& bitmap) {
// 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 768bfc7d21..e528b78f4f 100644
--- a/tools/skpdiff/SkDifferentPixelsMetric_cpu.cpp
+++ b/tools/skpdiff/SkDifferentPixelsMetric_cpu.cpp
@@ -21,7 +21,7 @@ bool SkDifferentPixelsMetric::diff(SkBitmap* baseline, SkBitmap* test, bool comp
// 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;
}