Merge "Introduce Bitmap.Config.Hardware with @hide annotation"

This commit is contained in:
Sergei Vasilinetc
2016-11-23 23:43:42 +00:00
committed by Android (Google) Code Review
5 changed files with 40 additions and 7 deletions

View File

@@ -235,6 +235,7 @@ static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding
int sampleSize = 1;
bool onlyDecodeSize = false;
SkColorType prefColorType = kN32_SkColorType;
bool isHardware = false;
bool isMutable = false;
float scale = 1.0f;
bool requireUnpremultiplied = false;
@@ -260,6 +261,7 @@ static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding
jobject jconfig = env->GetObjectField(options, gOptions_configFieldID);
prefColorType = GraphicsJNI::getNativeBitmapColorType(env, jconfig);
isHardware = GraphicsJNI::isHardwareConfig(env, jconfig);
isMutable = env->GetBooleanField(options, gOptions_mutableFieldID);
requireUnpremultiplied = !env->GetBooleanField(options, gOptions_premultipliedFieldID);
javaBitmap = env->GetObjectField(options, gOptions_bitmapFieldID);
@@ -352,9 +354,10 @@ static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding
decodeAllocator = &scaleCheckingAllocator;
} else if (javaBitmap != nullptr) {
decodeAllocator = &recyclingAllocator;
} else if (willScale) {
// This will allocate pixels using a HeapAllocator, since there will be an extra
// scaling step.
} else if (willScale || isHardware) {
// This will allocate pixels using a HeapAllocator,
// for scale case: there will be an extra scaling step.
// for hardware case: there will be extra swizzling & upload to gralloc step.
decodeAllocator = &heapAllocator;
} else {
decodeAllocator = &defaultAllocator;
@@ -539,6 +542,12 @@ static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding
if (isMutable) bitmapCreateFlags |= android::bitmap::kBitmapCreateFlag_Mutable;
if (isPremultiplied) bitmapCreateFlags |= android::bitmap::kBitmapCreateFlag_Premultiplied;
if (isHardware) {
sk_sp<Bitmap> hardwareBitmap = Bitmap::allocateHardwareBitmap(outputBitmap);
return bitmap::createBitmap(env, hardwareBitmap.release(), bitmapCreateFlags,
ninePatchChunk, ninePatchInsets, -1);
}
// now create the java bitmap
return bitmap::createBitmap(env, defaultAllocator.getStorageObjAndReset(),
bitmapCreateFlags, ninePatchChunk, ninePatchInsets, -1);

View File

@@ -131,12 +131,13 @@ static jobject nativeDecodeRegion(JNIEnv* env, jobject, jlong brdHandle, jint in
SkColorType colorType = kN32_SkColorType;
bool requireUnpremul = false;
jobject javaBitmap = NULL;
bool isHardware = false;
// Update the default options with any options supplied by the client.
if (NULL != options) {
sampleSize = env->GetIntField(options, gOptions_sampleSizeFieldID);
jobject jconfig = env->GetObjectField(options, gOptions_configFieldID);
colorType = GraphicsJNI::getNativeBitmapColorType(env, jconfig);
isHardware = GraphicsJNI::isHardwareConfig(env, jconfig);
requireUnpremul = !env->GetBooleanField(options, gOptions_premultipliedFieldID);
javaBitmap = env->GetObjectField(options, gOptions_bitmapFieldID);
// The Java options of ditherMode and preferQualityOverSpeed are deprecated. We will
@@ -202,6 +203,10 @@ static jobject nativeDecodeRegion(JNIEnv* env, jobject, jlong brdHandle, jint in
if (!requireUnpremul) {
bitmapCreateFlags |= android::bitmap::kBitmapCreateFlag_Premultiplied;
}
if (isHardware) {
sk_sp<Bitmap> hardwareBitmap = Bitmap::allocateHardwareBitmap(bitmap);
return bitmap::createBitmap(env, hardwareBitmap.release(), bitmapCreateFlags);
}
return android::bitmap::createBitmap(env, heapAlloc.getStorageObjAndReset(), bitmapCreateFlags);
}

View File

@@ -297,8 +297,9 @@ enum LegacyBitmapConfig {
kRGB_565_LegacyBitmapConfig = 3,
kARGB_4444_LegacyBitmapConfig = 4,
kARGB_8888_LegacyBitmapConfig = 5,
kHardware_LegacyBitmapConfig = 6,
kLastEnum_LegacyBitmapConfig = kARGB_8888_LegacyBitmapConfig
kLastEnum_LegacyBitmapConfig = kHardware_LegacyBitmapConfig
};
jint GraphicsJNI::colorTypeToLegacyBitmapConfig(SkColorType colorType) {
@@ -327,6 +328,7 @@ SkColorType GraphicsJNI::legacyBitmapConfigToColorType(jint legacyConfig) {
kIndex_8_SkColorType,
kRGB_565_SkColorType,
kARGB_4444_SkColorType,
kN32_SkColorType,
kN32_SkColorType
};
@@ -355,6 +357,15 @@ SkColorType GraphicsJNI::getNativeBitmapColorType(JNIEnv* env, jobject jconfig)
return legacyBitmapConfigToColorType(c);
}
bool GraphicsJNI::isHardwareConfig(JNIEnv* env, jobject jconfig) {
SkASSERT(env);
if (NULL == jconfig) {
return false;
}
int c = env->GetIntField(jconfig, gBitmapConfig_nativeInstanceID);
return c == kHardware_LegacyBitmapConfig;
}
android::Canvas* GraphicsJNI::getNativeCanvas(JNIEnv* env, jobject canvas) {
SkASSERT(env);
SkASSERT(canvas);

View File

@@ -68,6 +68,8 @@ public:
*/
static SkColorType getNativeBitmapColorType(JNIEnv*, jobject jconfig);
static bool isHardwareConfig(JNIEnv* env, jobject jconfig);
static jobject createRegion(JNIEnv* env, SkRegion* region);
static jobject createBitmapRegionDecoder(JNIEnv* env, SkBitmapRegionDecoder* bitmap);

View File

@@ -463,12 +463,18 @@ public final class Bitmap implements Parcelable {
* This configuration is very flexible and offers the best
* quality. It should be used whenever possible.
*/
ARGB_8888 (5);
ARGB_8888 (5),
/**
* @hide
*/
HARDWARE (6);
final int nativeInt;
private static Config sConfigs[] = {
null, ALPHA_8, null, RGB_565, ARGB_4444, ARGB_8888
null, ALPHA_8, null, RGB_565, ARGB_4444, ARGB_8888, HARDWARE
};
Config(int ni) {