am 1689c345: Merge "Add BitmapFactory.Options.inMutable to load mutable bitmaps." into honeycomb
* commit '1689c3459b27657b6900429ae64ac5323c584ce3': Add BitmapFactory.Options.inMutable to load mutable bitmaps.
This commit is contained in:
@@ -77107,6 +77107,16 @@
|
|||||||
visibility="public"
|
visibility="public"
|
||||||
>
|
>
|
||||||
</field>
|
</field>
|
||||||
|
<field name="inMutable"
|
||||||
|
type="boolean"
|
||||||
|
transient="false"
|
||||||
|
volatile="false"
|
||||||
|
static="false"
|
||||||
|
final="false"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
</field>
|
||||||
<field name="inPreferQualityOverSpeed"
|
<field name="inPreferQualityOverSpeed"
|
||||||
type="boolean"
|
type="boolean"
|
||||||
transient="false"
|
transient="false"
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ jclass gOptions_class;
|
|||||||
jfieldID gOptions_justBoundsFieldID;
|
jfieldID gOptions_justBoundsFieldID;
|
||||||
jfieldID gOptions_sampleSizeFieldID;
|
jfieldID gOptions_sampleSizeFieldID;
|
||||||
jfieldID gOptions_configFieldID;
|
jfieldID gOptions_configFieldID;
|
||||||
|
jfieldID gOptions_mutableFieldID;
|
||||||
jfieldID gOptions_ditherFieldID;
|
jfieldID gOptions_ditherFieldID;
|
||||||
jfieldID gOptions_purgeableFieldID;
|
jfieldID gOptions_purgeableFieldID;
|
||||||
jfieldID gOptions_shareableFieldID;
|
jfieldID gOptions_shareableFieldID;
|
||||||
@@ -179,6 +180,7 @@ static jobject doDecode(JNIEnv* env, SkStream* stream, jobject padding,
|
|||||||
SkImageDecoder::Mode mode = SkImageDecoder::kDecodePixels_Mode;
|
SkImageDecoder::Mode mode = SkImageDecoder::kDecodePixels_Mode;
|
||||||
SkBitmap::Config prefConfig = SkBitmap::kNo_Config;
|
SkBitmap::Config prefConfig = SkBitmap::kNo_Config;
|
||||||
bool doDither = true;
|
bool doDither = true;
|
||||||
|
bool isMutable = false;
|
||||||
bool isPurgeable = forcePurgeable ||
|
bool isPurgeable = forcePurgeable ||
|
||||||
(allowPurgeable && optionsPurgeable(env, options));
|
(allowPurgeable && optionsPurgeable(env, options));
|
||||||
bool preferQualityOverSpeed = false;
|
bool preferQualityOverSpeed = false;
|
||||||
@@ -196,6 +198,7 @@ static jobject doDecode(JNIEnv* env, SkStream* stream, jobject padding,
|
|||||||
|
|
||||||
jobject jconfig = env->GetObjectField(options, gOptions_configFieldID);
|
jobject jconfig = env->GetObjectField(options, gOptions_configFieldID);
|
||||||
prefConfig = GraphicsJNI::getNativeBitmapConfig(env, jconfig);
|
prefConfig = GraphicsJNI::getNativeBitmapConfig(env, jconfig);
|
||||||
|
isMutable = env->GetBooleanField(options, gOptions_mutableFieldID);
|
||||||
doDither = env->GetBooleanField(options, gOptions_ditherFieldID);
|
doDither = env->GetBooleanField(options, gOptions_ditherFieldID);
|
||||||
preferQualityOverSpeed = env->GetBooleanField(options,
|
preferQualityOverSpeed = env->GetBooleanField(options,
|
||||||
gOptions_preferQualityOverSpeedFieldID);
|
gOptions_preferQualityOverSpeedFieldID);
|
||||||
@@ -306,15 +309,19 @@ static jobject doDecode(JNIEnv* env, SkStream* stream, jobject padding,
|
|||||||
// already have a pixelref installed.
|
// already have a pixelref installed.
|
||||||
pr = bitmap->pixelRef();
|
pr = bitmap->pixelRef();
|
||||||
}
|
}
|
||||||
// promise we will never change our pixels (great for sharing and pictures)
|
|
||||||
pr->setImmutable();
|
if (!isMutable) {
|
||||||
|
// promise we will never change our pixels (great for sharing and pictures)
|
||||||
|
pr->setImmutable();
|
||||||
|
}
|
||||||
|
|
||||||
if (javaBitmap != NULL) {
|
if (javaBitmap != NULL) {
|
||||||
// If a java bitmap was passed in for reuse, pass it back
|
// If a java bitmap was passed in for reuse, pass it back
|
||||||
return javaBitmap;
|
return javaBitmap;
|
||||||
}
|
}
|
||||||
// now create the java bitmap
|
// now create the java bitmap
|
||||||
return GraphicsJNI::createBitmap(env, bitmap, javaAllocator.getStorageObj(), false, ninePatchChunk);
|
return GraphicsJNI::createBitmap(env, bitmap, javaAllocator.getStorageObj(),
|
||||||
|
isMutable, ninePatchChunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
static jobject nativeDecodeStream(JNIEnv* env, jobject clazz,
|
static jobject nativeDecodeStream(JNIEnv* env, jobject clazz,
|
||||||
@@ -572,6 +579,7 @@ int register_android_graphics_BitmapFactory(JNIEnv* env) {
|
|||||||
gOptions_sampleSizeFieldID = getFieldIDCheck(env, gOptions_class, "inSampleSize", "I");
|
gOptions_sampleSizeFieldID = getFieldIDCheck(env, gOptions_class, "inSampleSize", "I");
|
||||||
gOptions_configFieldID = getFieldIDCheck(env, gOptions_class, "inPreferredConfig",
|
gOptions_configFieldID = getFieldIDCheck(env, gOptions_class, "inPreferredConfig",
|
||||||
"Landroid/graphics/Bitmap$Config;");
|
"Landroid/graphics/Bitmap$Config;");
|
||||||
|
gOptions_mutableFieldID = getFieldIDCheck(env, gOptions_class, "inMutable", "Z");
|
||||||
gOptions_ditherFieldID = getFieldIDCheck(env, gOptions_class, "inDither", "Z");
|
gOptions_ditherFieldID = getFieldIDCheck(env, gOptions_class, "inDither", "Z");
|
||||||
gOptions_purgeableFieldID = getFieldIDCheck(env, gOptions_class, "inPurgeable", "Z");
|
gOptions_purgeableFieldID = getFieldIDCheck(env, gOptions_class, "inPurgeable", "Z");
|
||||||
gOptions_shareableFieldID = getFieldIDCheck(env, gOptions_class, "inInputShareable", "Z");
|
gOptions_shareableFieldID = getFieldIDCheck(env, gOptions_class, "inInputShareable", "Z");
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ public final class Bitmap implements Parcelable {
|
|||||||
*/
|
*/
|
||||||
public byte[] mBuffer;
|
public byte[] mBuffer;
|
||||||
|
|
||||||
|
@SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"}) // Keep to finalize native resources
|
||||||
private final BitmapFinalizer mFinalizer;
|
private final BitmapFinalizer mFinalizer;
|
||||||
|
|
||||||
private final boolean mIsMutable;
|
private final boolean mIsMutable;
|
||||||
|
|||||||
@@ -63,6 +63,14 @@ public class BitmapFactory {
|
|||||||
*/
|
*/
|
||||||
public Bitmap inBitmap;
|
public Bitmap inBitmap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If set, decode methods will always return a mutable Bitmap instead of
|
||||||
|
* an immutable one. This can be used for instance to programmatically apply
|
||||||
|
* effects to a Bitmap loaded through BitmapFactory.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings({"UnusedDeclaration"}) // used in native code
|
||||||
|
public boolean inMutable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If set to true, the decoder will return null (no bitmap), but
|
* If set to true, the decoder will return null (no bitmap), but
|
||||||
* the out... fields will still be set, allowing the caller to query
|
* the out... fields will still be set, allowing the caller to query
|
||||||
@@ -523,7 +531,7 @@ public class BitmapFactory {
|
|||||||
}
|
}
|
||||||
bm.setDensity(targetDensity);
|
bm.setDensity(targetDensity);
|
||||||
}
|
}
|
||||||
|
|
||||||
return bm;
|
return bm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import android.graphics.Paint;
|
|||||||
import android.graphics.PorterDuff;
|
import android.graphics.PorterDuff;
|
||||||
import android.graphics.PorterDuffXfermode;
|
import android.graphics.PorterDuffXfermode;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.animation.Animation;
|
import android.view.animation.Animation;
|
||||||
@@ -61,7 +62,15 @@ public class BitmapsActivity extends Activity {
|
|||||||
|
|
||||||
mBitmap1 = BitmapFactory.decodeResource(c.getResources(), R.drawable.sunset1);
|
mBitmap1 = BitmapFactory.decodeResource(c.getResources(), R.drawable.sunset1);
|
||||||
mBitmap2 = BitmapFactory.decodeResource(c.getResources(), R.drawable.sunset2);
|
mBitmap2 = BitmapFactory.decodeResource(c.getResources(), R.drawable.sunset2);
|
||||||
|
|
||||||
|
Log.d("Bitmap", "mBitmap1.isMutable() = " + mBitmap1.isMutable());
|
||||||
|
Log.d("Bitmap", "mBitmap2.isMutable() = " + mBitmap2.isMutable());
|
||||||
|
|
||||||
|
BitmapFactory.Options opts = new BitmapFactory.Options();
|
||||||
|
opts.inMutable = true;
|
||||||
|
Bitmap bitmap = BitmapFactory.decodeResource(c.getResources(), R.drawable.sunset1, opts);
|
||||||
|
Log.d("Bitmap", "bitmap.isMutable() = " + bitmap.isMutable());
|
||||||
|
|
||||||
mBitmapPaint = new Paint();
|
mBitmapPaint = new Paint();
|
||||||
mDstIn = new PorterDuffXfermode(PorterDuff.Mode.DST_IN);
|
mDstIn = new PorterDuffXfermode(PorterDuff.Mode.DST_IN);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user