OSDN Git Service

Set inMutable to true if we may reuse the bitmap.
authorOwen Lin <owenlin@google.com>
Tue, 4 Sep 2012 03:44:57 +0000 (11:44 +0800)
committerOwen Lin <owenlin@google.com>
Tue, 4 Sep 2012 03:44:57 +0000 (11:44 +0800)
bug: 7092330
Change-Id: I0def7e2e9ce57d09ba7f5e001b33cc605a6af44c

gallerycommon/src/com/android/gallery3d/common/ApiHelper.java
src/com/android/gallery3d/data/DecodeUtils.java

index 418e3cd..68aa50d 100644 (file)
@@ -151,6 +151,9 @@ public class ApiHelper {
     public static final boolean HAS_CAMERA_HDR =
             Build.VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1;
 
+    public static final boolean HAS_OPTIONS_IN_MUTABLE =
+            Build.VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB;
+
     public static final boolean CAN_START_PREVIEW_IN_JPEG_CALLBACK =
             Build.VERSION.SDK_INT >= VERSION_CODES.ICE_CREAM_SANDWICH;
 
index 773af74..4d3c996 100644 (file)
@@ -25,6 +25,7 @@ import android.graphics.BitmapRegionDecoder;
 import android.os.Build;
 import android.util.FloatMath;
 
+import com.android.gallery3d.common.ApiHelper;
 import com.android.gallery3d.common.BitmapUtils;
 import com.android.gallery3d.common.Utils;
 import com.android.gallery3d.ui.Log;
@@ -51,9 +52,15 @@ public class DecodeUtils {
         }
     }
 
+    @TargetApi(ApiHelper.VERSION_CODES.HONEYCOMB)
+    public static void setOptionsMutable(Options options) {
+        if (ApiHelper.HAS_OPTIONS_IN_MUTABLE) options.inMutable = true;
+    }
+
     public static Bitmap decode(JobContext jc, FileDescriptor fd, Options options) {
         if (options == null) options = new Options();
         jc.setCancelListener(new DecodeCanceller(options));
+        setOptionsMutable(options);
         return ensureGLCompatibleBitmap(
                 BitmapFactory.decodeFileDescriptor(fd, null, options));
     }
@@ -75,6 +82,7 @@ public class DecodeUtils {
             int length, Options options) {
         if (options == null) options = new Options();
         jc.setCancelListener(new DecodeCanceller(options));
+        setOptionsMutable(options);
         return ensureGLCompatibleBitmap(
                 BitmapFactory.decodeByteArray(bytes, offset, length, options));
     }
@@ -135,6 +143,7 @@ public class DecodeUtils {
         }
 
         options.inJustDecodeBounds = false;
+        setOptionsMutable(options);
 
         Bitmap result = BitmapFactory.decodeFileDescriptor(fd, null, options);
         if (result == null) return null;
@@ -170,6 +179,8 @@ public class DecodeUtils {
         options.inSampleSize = BitmapUtils.computeSampleSizeLarger(
                 options.outWidth, options.outHeight, targetSize);
         options.inJustDecodeBounds = false;
+        setOptionsMutable(options);
+
         return ensureGLCompatibleBitmap(
                 BitmapFactory.decodeByteArray(data, 0, data.length, options));
     }