SkBitmap::Config is deprecated, use SkColorType
Change-Id: Ic953741325607bf85598c097bb3ab648d4a08996
diff --git a/core/jni/android/graphics/Bitmap.cpp b/core/jni/android/graphics/Bitmap.cpp
index f7886d3..53aca3d 100644
--- a/core/jni/android/graphics/Bitmap.cpp
+++ b/core/jni/android/graphics/Bitmap.cpp
@@ -316,7 +316,7 @@
static jobject Bitmap_creator(JNIEnv* env, jobject, jintArray jColors,
jint offset, jint stride, jint width, jint height,
jint configHandle, jboolean isMutable) {
- SkColorType colorType = SkBitmapConfigToColorType(static_cast<SkBitmap::Config>(configHandle));
+ SkColorType colorType = GraphicsJNI::legacyBitmapConfigToColorType(configHandle);
if (NULL != jColors) {
size_t n = env->GetArrayLength(jColors);
if (n < SkAbs32(stride) * (size_t)height) {
@@ -350,11 +350,11 @@
static jobject Bitmap_copy(JNIEnv* env, jobject, jlong srcHandle,
jint dstConfigHandle, jboolean isMutable) {
const SkBitmap* src = reinterpret_cast<SkBitmap*>(srcHandle);
- SkBitmap::Config dstConfig = static_cast<SkBitmap::Config>(dstConfigHandle);
+ SkColorType dstCT = GraphicsJNI::legacyBitmapConfigToColorType(dstConfigHandle);
SkBitmap result;
JavaPixelAllocator allocator(env);
- if (!src->copyTo(&result, SkBitmapConfigToColorType(dstConfig), &allocator)) {
+ if (!src->copyTo(&result, dstCT, &allocator)) {
return NULL;
}
return GraphicsJNI::createBitmap(env, new SkBitmap(result), allocator.getStorageObj(),
@@ -389,8 +389,7 @@
jint width, jint height, jint configHandle, jint allocSize,
jboolean requestPremul) {
SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);
- SkBitmap::Config config = static_cast<SkBitmap::Config>(configHandle);
- SkColorType colorType = SkBitmapConfigToColorType(config);
+ SkColorType colorType = GraphicsJNI::legacyBitmapConfigToColorType(configHandle);
// ARGB_4444 is a deprecated format, convert automatically to 8888
if (colorType == kARGB_4444_SkColorType) {
@@ -494,7 +493,7 @@
static jint Bitmap_config(JNIEnv* env, jobject, jlong bitmapHandle) {
SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);
- return static_cast<jint>(bitmap->config());
+ return GraphicsJNI::colorTypeToLegacyBitmapConfig(bitmap->colorType());
}
static jint Bitmap_getGenerationId(JNIEnv* env, jobject, jlong bitmapHandle) {
@@ -810,7 +809,7 @@
const SkBitmap* bm1 = reinterpret_cast<SkBitmap*>(bm1Handle);
if (bm0->width() != bm1->width() ||
bm0->height() != bm1->height() ||
- bm0->config() != bm1->config()) {
+ bm0->colorType() != bm1->colorType()) {
return JNI_FALSE;
}
@@ -822,7 +821,7 @@
return JNI_FALSE;
}
- if (bm0->config() == SkBitmap::kIndex8_Config) {
+ if (bm0->colorType() == kIndex_8_SkColorType) {
SkColorTable* ct0 = bm0->getColorTable();
SkColorTable* ct1 = bm1->getColorTable();
if (NULL == ct0 || NULL == ct1) {
diff --git a/core/jni/android/graphics/Graphics.cpp b/core/jni/android/graphics/Graphics.cpp
index 7a186a2..9177696 100644
--- a/core/jni/android/graphics/Graphics.cpp
+++ b/core/jni/android/graphics/Graphics.cpp
@@ -291,6 +291,54 @@
env->SetFloatField(obj, gPointF_yFieldID, SkScalarToFloat(r.fY));
}
+// This enum must keep these int values, to match the int values
+// in the java Bitmap.Config enum.
+enum LegacyBitmapConfig {
+ kNo_LegacyBitmapConfig = 0,
+ kA8_LegacyBitmapConfig = 1,
+ kIndex8_LegacyBitmapConfig = 2,
+ kRGB_565_LegacyBitmapConfig = 3,
+ kARGB_4444_LegacyBitmapConfig = 4,
+ kARGB_8888_LegacyBitmapConfig = 5,
+
+ kLastEnum_LegacyBitmapConfig = kARGB_8888_LegacyBitmapConfig
+};
+
+jint GraphicsJNI::colorTypeToLegacyBitmapConfig(SkColorType colorType) {
+ switch (colorType) {
+ case kN32_SkColorType:
+ return kARGB_8888_LegacyBitmapConfig;
+ case kARGB_4444_SkColorType:
+ return kARGB_4444_LegacyBitmapConfig;
+ case kRGB_565_SkColorType:
+ return kRGB_565_LegacyBitmapConfig;
+ case kIndex_8_SkColorType:
+ return kIndex8_LegacyBitmapConfig;
+ case kAlpha_8_SkColorType:
+ return kA8_LegacyBitmapConfig;
+ case kUnknown_SkColorType:
+ default:
+ break;
+ }
+ return kNo_LegacyBitmapConfig;
+}
+
+SkColorType GraphicsJNI::legacyBitmapConfigToColorType(jint legacyConfig) {
+ const uint8_t gConfig2ColorType[] = {
+ kUnknown_SkColorType,
+ kAlpha_8_SkColorType,
+ kIndex_8_SkColorType,
+ kRGB_565_SkColorType,
+ kARGB_4444_SkColorType,
+ kN32_SkColorType
+ };
+
+ if (legacyConfig < 0 || legacyConfig > kLastEnum_LegacyBitmapConfig) {
+ legacyConfig = kNo_LegacyBitmapConfig;
+ }
+ return static_cast<SkColorType>(gConfig2ColorType[legacyConfig]);
+}
+
SkBitmap* GraphicsJNI::getNativeBitmap(JNIEnv* env, jobject bitmap) {
SkASSERT(env);
SkASSERT(bitmap);
@@ -308,10 +356,7 @@
}
SkASSERT(env->IsInstanceOf(jconfig, gBitmapConfig_class));
int c = env->GetIntField(jconfig, gBitmapConfig_nativeInstanceID);
- if (c < 0 || c >= SkBitmap::kConfigCount) {
- c = kUnknown_SkColorType;
- }
- return SkBitmapConfigToColorType(static_cast<SkBitmap::Config>(c));
+ return legacyBitmapConfigToColorType(c);
}
SkCanvas* GraphicsJNI::getNativeCanvas(JNIEnv* env, jobject canvas) {
diff --git a/core/jni/android/graphics/GraphicsJNI.h b/core/jni/android/graphics/GraphicsJNI.h
index 6d82ceb..a03391d 100644
--- a/core/jni/android/graphics/GraphicsJNI.h
+++ b/core/jni/android/graphics/GraphicsJNI.h
@@ -58,6 +58,14 @@
// ref to its SkRasterizer* (or NULL).
static SkRasterizer* refNativeRasterizer(jlong rasterizerHandle);
+ /*
+ * LegacyBitmapConfig is the old enum in Skia that matched the enum int values
+ * in Bitmap.Config. Skia no longer supports this config, but has replaced it
+ * with SkColorType. These routines convert between the two.
+ */
+ static SkColorType legacyBitmapConfigToColorType(jint legacyConfig);
+ static jint colorTypeToLegacyBitmapConfig(SkColorType colorType);
+
/** Return the corresponding native colorType from the java Config enum,
or kUnknown_SkColorType if the java object is null.
*/
diff --git a/core/jni/android/graphics/NinePatchImpl.cpp b/core/jni/android/graphics/NinePatchImpl.cpp
index 1793208..c162c48 100644
--- a/core/jni/android/graphics/NinePatchImpl.cpp
+++ b/core/jni/android/graphics/NinePatchImpl.cpp
@@ -38,18 +38,18 @@
#include <utils/Log.h>
static bool getColor(const SkBitmap& bitmap, int x, int y, SkColor* c) {
- switch (bitmap.config()) {
- case SkBitmap::kARGB_8888_Config:
+ switch (bitmap.colorType()) {
+ case kN32_SkColorType:
*c = SkUnPreMultiply::PMColorToColor(*bitmap.getAddr32(x, y));
break;
- case SkBitmap::kRGB_565_Config:
+ case kRGB_565_SkColorType:
*c = SkPixel16ToPixel32(*bitmap.getAddr16(x, y));
break;
- case SkBitmap::kARGB_4444_Config:
+ case kARGB_4444_SkColorType:
*c = SkUnPreMultiply::PMColorToColor(
SkPixel4444ToPixel32(*bitmap.getAddr16(x, y)));
break;
- case SkBitmap::kIndex8_Config: {
+ case kIndex_8_SkColorType: {
SkColorTable* ctable = bitmap.getColorTable();
*c = SkUnPreMultiply::PMColorToColor(
(*ctable)[*bitmap.getAddr8(x, y)]);
diff --git a/core/jni/android/opengl/util.cpp b/core/jni/android/opengl/util.cpp
index a91c622..89baef8 100644
--- a/core/jni/android/opengl/util.cpp
+++ b/core/jni/android/opengl/util.cpp
@@ -562,18 +562,18 @@
setGLDebugLevel(level);
}
-static int checkFormat(SkBitmap::Config config, int format, int type)
+static int checkFormat(SkColorType colorType, int format, int type)
{
- switch(config) {
- case SkBitmap::kIndex8_Config:
+ switch(colorType) {
+ case kIndex_8_SkColorType:
if (format == GL_PALETTE8_RGBA8_OES)
return 0;
- case SkBitmap::kARGB_8888_Config:
- case SkBitmap::kA8_Config:
+ case kN32_SkColorType:
+ case kAlpha_8_SkColorType:
if (type == GL_UNSIGNED_BYTE)
return 0;
- case SkBitmap::kARGB_4444_Config:
- case SkBitmap::kRGB_565_Config:
+ case kARGB_4444_SkColorType:
+ case kRGB_565_SkColorType:
switch (type) {
case GL_UNSIGNED_SHORT_4_4_4_4:
case GL_UNSIGNED_SHORT_5_6_5:
@@ -590,36 +590,36 @@
return -1;
}
-static int getInternalFormat(SkBitmap::Config config)
+static int getInternalFormat(SkColorType colorType)
{
- switch(config) {
- case SkBitmap::kA8_Config:
+ switch(colorType) {
+ case kAlpha_8_SkColorType:
return GL_ALPHA;
- case SkBitmap::kARGB_4444_Config:
+ case kARGB_4444_SkColorType:
return GL_RGBA;
- case SkBitmap::kARGB_8888_Config:
+ case kN32_SkColorType:
return GL_RGBA;
- case SkBitmap::kIndex8_Config:
+ case kIndex_8_SkColorType:
return GL_PALETTE8_RGBA8_OES;
- case SkBitmap::kRGB_565_Config:
+ case kRGB_565_SkColorType:
return GL_RGB;
default:
return -1;
}
}
-static int getType(SkBitmap::Config config)
+static int getType(SkColorType colorType)
{
- switch(config) {
- case SkBitmap::kA8_Config:
+ switch(colorType) {
+ case kAlpha_8_SkColorType:
return GL_UNSIGNED_BYTE;
- case SkBitmap::kARGB_4444_Config:
+ case kARGB_4444_SkColorType:
return GL_UNSIGNED_SHORT_4_4_4_4;
- case SkBitmap::kARGB_8888_Config:
+ case kN32_SkColorType:
return GL_UNSIGNED_BYTE;
- case SkBitmap::kIndex8_Config:
+ case kIndex_8_SkColorType:
return -1; // No type for compressed data.
- case SkBitmap::kRGB_565_Config:
+ case kRGB_565_SkColorType:
return GL_UNSIGNED_SHORT_5_6_5;
default:
return -1;
@@ -631,9 +631,7 @@
{
SkBitmap const * nativeBitmap =
(SkBitmap const *)env->GetLongField(jbitmap, nativeBitmapID);
- const SkBitmap& bitmap(*nativeBitmap);
- SkBitmap::Config config = bitmap.config();
- return getInternalFormat(config);
+ return getInternalFormat(nativeBitmap->colorType());
}
static jint util_getType(JNIEnv *env, jclass clazz,
@@ -641,9 +639,7 @@
{
SkBitmap const * nativeBitmap =
(SkBitmap const *)env->GetLongField(jbitmap, nativeBitmapID);
- const SkBitmap& bitmap(*nativeBitmap);
- SkBitmap::Config config = bitmap.config();
- return getType(config);
+ return getType(nativeBitmap->colorType());
}
static jint util_texImage2D(JNIEnv *env, jclass clazz,
@@ -653,14 +649,14 @@
SkBitmap const * nativeBitmap =
(SkBitmap const *)env->GetLongField(jbitmap, nativeBitmapID);
const SkBitmap& bitmap(*nativeBitmap);
- SkBitmap::Config config = bitmap.config();
+ SkColorType colorType = bitmap.colorType();
if (internalformat < 0) {
- internalformat = getInternalFormat(config);
+ internalformat = getInternalFormat(colorType);
}
if (type < 0) {
- type = getType(config);
+ type = getType(colorType);
}
- int err = checkFormat(config, internalformat, type);
+ int err = checkFormat(colorType, internalformat, type);
if (err)
return err;
bitmap.lockPixels();
@@ -702,13 +698,13 @@
SkBitmap const * nativeBitmap =
(SkBitmap const *)env->GetLongField(jbitmap, nativeBitmapID);
const SkBitmap& bitmap(*nativeBitmap);
- SkBitmap::Config config = bitmap.config();
+ SkColorType colorType = bitmap.colorType();
if (format < 0) {
- format = getInternalFormat(config);
+ format = getInternalFormat(colorType);
if (format == GL_PALETTE8_RGBA8_OES)
return -1; // glCompressedTexSubImage2D() not supported
}
- int err = checkFormat(config, format, type);
+ int err = checkFormat(colorType, format, type);
if (err)
return err;
bitmap.lockPixels();
diff --git a/core/jni/com_google_android_gles_jni_EGLImpl.cpp b/core/jni/com_google_android_gles_jni_EGLImpl.cpp
index 3d421d5..8ad2eea 100644
--- a/core/jni/com_google_android_gles_jni_EGLImpl.cpp
+++ b/core/jni/com_google_android_gles_jni_EGLImpl.cpp
@@ -257,13 +257,13 @@
return reinterpret_cast<jlong>(sur);
}
-static PixelFormat convertPixelFormat(SkBitmap::Config format)
+static PixelFormat convertPixelFormat(SkColorType format)
{
switch (format) {
- case SkBitmap::kARGB_8888_Config: return PIXEL_FORMAT_RGBA_8888;
- case SkBitmap::kARGB_4444_Config: return PIXEL_FORMAT_RGBA_4444;
- case SkBitmap::kRGB_565_Config: return PIXEL_FORMAT_RGB_565;
- default: return PIXEL_FORMAT_NONE;
+ case kN32_SkColorType: return PIXEL_FORMAT_RGBA_8888;
+ case kARGB_4444_SkColorType: return PIXEL_FORMAT_RGBA_4444;
+ case kRGB_565_SkColorType: return PIXEL_FORMAT_RGB_565;
+ default: return PIXEL_FORMAT_NONE;
}
}
@@ -297,7 +297,7 @@
pixmap.width = nativeBitmap->width();
pixmap.height = nativeBitmap->height();
pixmap.stride = nativeBitmap->rowBytes() / nativeBitmap->bytesPerPixel();
- pixmap.format = convertPixelFormat(nativeBitmap->config());
+ pixmap.format = convertPixelFormat(nativeBitmap->colorType());
pixmap.data = (uint8_t*)ref->pixels();
base = beginNativeAttribList(_env, attrib_list);
diff --git a/libs/hwui/DisplayListOp.h b/libs/hwui/DisplayListOp.h
index 901c69e..75d52b4 100644
--- a/libs/hwui/DisplayListOp.h
+++ b/libs/hwui/DisplayListOp.h
@@ -732,7 +732,7 @@
deferInfo.mergeable = state.mMatrix.isSimple() && state.mMatrix.positiveScale() &&
!state.mClipSideFlags &&
OpenGLRenderer::getXfermodeDirect(mPaint) == SkXfermode::kSrcOver_Mode &&
- (mBitmap->config() != SkBitmap::kA8_Config);
+ (mBitmap->colorType() != kAlpha_8_SkColorType);
}
const SkBitmap* bitmap() { return mBitmap; }
diff --git a/libs/hwui/LayerRenderer.cpp b/libs/hwui/LayerRenderer.cpp
index 873baf5..a92ef94 100644
--- a/libs/hwui/LayerRenderer.cpp
+++ b/libs/hwui/LayerRenderer.cpp
@@ -383,20 +383,20 @@
GLenum error = GL_NO_ERROR;
bool status = false;
- switch (bitmap->config()) {
- case SkBitmap::kA8_Config:
+ switch (bitmap->colorType()) {
+ case kAlpha_8_SkColorType:
format = GL_ALPHA;
type = GL_UNSIGNED_BYTE;
break;
- case SkBitmap::kRGB_565_Config:
+ case kRGB_565_SkColorType:
format = GL_RGB;
type = GL_UNSIGNED_SHORT_5_6_5;
break;
- case SkBitmap::kARGB_4444_Config:
+ case kARGB_4444_SkColorType:
format = GL_RGBA;
type = GL_UNSIGNED_SHORT_4_4_4_4;
break;
- case SkBitmap::kARGB_8888_Config:
+ case kN32_SkColorType:
default:
format = GL_RGBA;
type = GL_UNSIGNED_BYTE;
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp
index 1bbcff1..c9f541b 100644
--- a/libs/hwui/OpenGLRenderer.cpp
+++ b/libs/hwui/OpenGLRenderer.cpp
@@ -1957,7 +1957,7 @@
const float x = (int) floorf(bounds.left + 0.5f);
const float y = (int) floorf(bounds.top + 0.5f);
- if (CC_UNLIKELY(bitmap->config() == SkBitmap::kA8_Config)) {
+ if (CC_UNLIKELY(bitmap->colorType() == kAlpha_8_SkColorType)) {
drawAlpha8TextureMesh(x, y, x + bounds.getWidth(), y + bounds.getHeight(),
texture->id, paint, &vertices[0].x, &vertices[0].u,
GL_TRIANGLES, bitmapCount * 6, true,
@@ -1986,7 +1986,7 @@
if (!texture) return DrawGlInfo::kStatusDone;
const AutoTexture autoCleanup(texture);
- if (CC_UNLIKELY(bitmap->config() == SkBitmap::kA8_Config)) {
+ if (CC_UNLIKELY(bitmap->colorType() == kAlpha_8_SkColorType)) {
drawAlphaBitmap(texture, left, top, paint);
} else {
drawTextureRect(left, top, right, bottom, texture, paint);
@@ -2014,7 +2014,7 @@
// to the vertex shader. The save/restore is a bit overkill.
save(SkCanvas::kMatrix_SaveFlag);
concatMatrix(matrix);
- if (CC_UNLIKELY(bitmap->config() == SkBitmap::kA8_Config)) {
+ if (CC_UNLIKELY(bitmap->colorType() == kAlpha_8_SkColorType)) {
drawAlphaBitmap(texture, 0.0f, 0.0f, paint);
} else {
drawTextureRect(0.0f, 0.0f, bitmap->width(), bitmap->height(), texture, paint);
@@ -2037,7 +2037,7 @@
Texture* texture = mCaches.textureCache.getTransient(bitmap);
const AutoTexture autoCleanup(texture);
- if (CC_UNLIKELY(bitmap->config() == SkBitmap::kA8_Config)) {
+ if (CC_UNLIKELY(bitmap->colorType() == kAlpha_8_SkColorType)) {
drawAlphaBitmap(texture, left, top, paint);
} else {
drawTextureRect(left, top, right, bottom, texture, paint);
@@ -2232,7 +2232,7 @@
dstBottom = srcBottom - srcTop;
}
- if (CC_UNLIKELY(bitmap->config() == SkBitmap::kA8_Config)) {
+ if (CC_UNLIKELY(bitmap->colorType() == kAlpha_8_SkColorType)) {
drawAlpha8TextureMesh(dstLeft, dstTop, dstRight, dstBottom,
texture->id, paint,
&mMeshVertices[0].x, &mMeshVertices[0].u,
diff --git a/libs/hwui/TextureCache.cpp b/libs/hwui/TextureCache.cpp
index 9212d0a..ec9e30a 100644
--- a/libs/hwui/TextureCache.cpp
+++ b/libs/hwui/TextureCache.cpp
@@ -285,20 +285,20 @@
Caches::getInstance().bindTexture(texture->id);
- switch (bitmap->config()) {
- case SkBitmap::kA8_Config:
+ switch (bitmap->colorType()) {
+ case kAlpha_8_SkColorType:
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
uploadToTexture(resize, GL_ALPHA, bitmap->rowBytesAsPixels(), bitmap->bytesPerPixel(),
texture->width, texture->height, GL_UNSIGNED_BYTE, bitmap->getPixels());
texture->blend = true;
break;
- case SkBitmap::kRGB_565_Config:
+ case kRGB_565_SkColorType:
glPixelStorei(GL_UNPACK_ALIGNMENT, bitmap->bytesPerPixel());
uploadToTexture(resize, GL_RGB, bitmap->rowBytesAsPixels(), bitmap->bytesPerPixel(),
texture->width, texture->height, GL_UNSIGNED_SHORT_5_6_5, bitmap->getPixels());
texture->blend = false;
break;
- case SkBitmap::kARGB_8888_Config:
+ case kN32_SkColorType:
glPixelStorei(GL_UNPACK_ALIGNMENT, bitmap->bytesPerPixel());
uploadToTexture(resize, GL_RGBA, bitmap->rowBytesAsPixels(), bitmap->bytesPerPixel(),
texture->width, texture->height, GL_UNSIGNED_BYTE, bitmap->getPixels());
@@ -306,14 +306,14 @@
// decoding happened
texture->blend = !bitmap->isOpaque();
break;
- case SkBitmap::kARGB_4444_Config:
- case SkBitmap::kIndex8_Config:
+ case kARGB_4444_SkColorType:
+ case kIndex_8_SkColorType:
glPixelStorei(GL_UNPACK_ALIGNMENT, bitmap->bytesPerPixel());
uploadLoFiTexture(resize, bitmap, texture->width, texture->height);
texture->blend = !bitmap->isOpaque();
break;
default:
- ALOGW("Unsupported bitmap config: %d", bitmap->config());
+ ALOGW("Unsupported bitmap colorType: %d", bitmap->colorType());
break;
}
diff --git a/native/graphics/jni/bitmap.cpp b/native/graphics/jni/bitmap.cpp
index eaa2cbe..df0751d 100644
--- a/native/graphics/jni/bitmap.cpp
+++ b/native/graphics/jni/bitmap.cpp
@@ -34,17 +34,17 @@
info->stride = bm->rowBytes();
info->flags = 0;
- switch (bm->config()) {
- case SkBitmap::kARGB_8888_Config:
+ switch (bm->colorType()) {
+ case kN32_SkColorType:
info->format = ANDROID_BITMAP_FORMAT_RGBA_8888;
break;
- case SkBitmap::kRGB_565_Config:
+ case kRGB_565_SkColorType:
info->format = ANDROID_BITMAP_FORMAT_RGB_565;
break;
- case SkBitmap::kARGB_4444_Config:
+ case kARGB_4444_SkColorType:
info->format = ANDROID_BITMAP_FORMAT_RGBA_4444;
break;
- case SkBitmap::kA8_Config:
+ case kAlpha_8_SkColorType:
info->format = ANDROID_BITMAP_FORMAT_A_8;
break;
default: