summaryrefslogtreecommitdiffstats
path: root/core/jni
diff options
context:
space:
mode:
authorMike Reed <reed@google.com>2014-07-08 19:16:14 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2014-07-07 19:25:01 +0000
commit24b45fee5d59bed2d005fb07d129f67bfb16b97a (patch)
tree30beac0ddda9964b8a4a04cf2b02a5e5dd21761a /core/jni
parent684b8ce8de45ccec5034bef14a4cb353fc63c31c (diff)
parent1103b3255945d2eb2fa9c191e84e2270b343cca9 (diff)
downloadframeworks_base-24b45fee5d59bed2d005fb07d129f67bfb16b97a.zip
frameworks_base-24b45fee5d59bed2d005fb07d129f67bfb16b97a.tar.gz
frameworks_base-24b45fee5d59bed2d005fb07d129f67bfb16b97a.tar.bz2
Merge "SkBitmap::Config is deprecated, use SkColorType"
Diffstat (limited to 'core/jni')
-rw-r--r--core/jni/android/graphics/Bitmap.cpp15
-rw-r--r--core/jni/android/graphics/Graphics.cpp53
-rw-r--r--core/jni/android/graphics/GraphicsJNI.h8
-rw-r--r--core/jni/android/graphics/NinePatchImpl.cpp10
-rw-r--r--core/jni/android/opengl/util.cpp64
-rw-r--r--core/jni/com_google_android_gles_jni_EGLImpl.cpp12
6 files changed, 105 insertions, 57 deletions
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 int getPremulBitmapCreateFlags(bool isMutable) {
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_creator(JNIEnv* env, jobject, jintArray jColors,
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 @@ static void Bitmap_reconfigure(JNIEnv* env, jobject clazz, jlong bitmapHandle,
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_rowBytes(JNIEnv* env, jobject, jlong bitmapHandle) {
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 @@ static jboolean Bitmap_sameAs(JNIEnv* env, jobject, jlong bm0Handle,
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 @@ static jboolean Bitmap_sameAs(JNIEnv* env, jobject, jlong bm0Handle,
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 @@ void GraphicsJNI::point_to_jpointf(const SkPoint& r, JNIEnv* env, jobject obj)
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 @@ SkColorType GraphicsJNI::getNativeBitmapColorType(JNIEnv* env, jobject jconfig)
}
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 @@ public:
// 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 @@ void setTracingLevel(JNIEnv *env, jclass clazz, jint level)
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 @@ static int checkFormat(SkBitmap::Config config, int format, int type)
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 @@ static jint util_getInternalFormat(JNIEnv *env, jclass clazz,
{
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 @@ static jint util_getType(JNIEnv *env, jclass clazz,
{
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 @@ static jint util_texImage2D(JNIEnv *env, jclass clazz,
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 @@ static jint util_texSubImage2D(JNIEnv *env, jclass clazz,
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 @@ static jlong jni_eglCreatePbufferSurface(JNIEnv *_env, jobject _this, jobject di
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 @@ static void jni_eglCreatePixmapSurface(JNIEnv *_env, jobject _this, jobject out_
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);