OSDN Git Service

Make Gallery2 use platform RenderScript
[android-x86/packages-apps-Gallery2.git] / src / com / android / gallery3d / filtershow / pipeline / Buffer.java
index c6dbdb7..a487a5d 100644 (file)
 package com.android.gallery3d.filtershow.pipeline;
 
 import android.graphics.Bitmap;
-import android.support.v8.renderscript.Allocation;
-import android.support.v8.renderscript.RenderScript;
-import com.android.gallery3d.filtershow.cache.CachingPipeline;
-import com.android.gallery3d.filtershow.presets.ImagePreset;
+import android.graphics.Canvas;
+import android.renderscript.Allocation;
+import android.renderscript.RenderScript;
+import android.util.Log;
+import com.android.gallery3d.filtershow.cache.BitmapCache;
+import com.android.gallery3d.filtershow.imageshow.MasterImage;
 
 public class Buffer {
     private static final String LOGTAG = "Buffer";
     private Bitmap mBitmap;
     private Allocation mAllocation;
     private boolean mUseAllocation = false;
-    private static final Bitmap.Config BITMAP_CONFIG = Bitmap.Config.ARGB_8888;
     private ImagePreset mPreset;
 
     public Buffer(Bitmap bitmap) {
         RenderScript rs = CachingPipeline.getRenderScriptContext();
         if (bitmap != null) {
-            mBitmap = bitmap.copy(BITMAP_CONFIG, true);
+            BitmapCache cache = MasterImage.getImage().getBitmapCache();
+            mBitmap = cache.getBitmapCopy(bitmap, BitmapCache.PREVIEW_CACHE);
         }
         if (mUseAllocation) {
             // TODO: recreate the allocation when the RS context changes
@@ -43,11 +45,23 @@ public class Buffer {
         }
     }
 
-    public void setBitmap(Bitmap bitmap) {
-        mBitmap = bitmap.copy(BITMAP_CONFIG, true);
+    public boolean isSameSize(Bitmap bitmap) {
+        if (mBitmap == null || bitmap == null) {
+            return false;
+        }
+        if (mBitmap.getWidth() == bitmap.getWidth()
+                && mBitmap.getHeight() == bitmap.getHeight()) {
+            return true;
+        }
+        return false;
+    }
+
+    public synchronized void useBitmap(Bitmap bitmap) {
+        Canvas canvas = new Canvas(mBitmap);
+        canvas.drawBitmap(bitmap, 0, 0, null);
     }
 
-    public Bitmap getBitmap() {
+    public synchronized Bitmap getBitmap() {
         return mBitmap;
     }
 
@@ -72,5 +86,12 @@ public class Buffer {
             mPreset.updateWith(preset);
         }
     }
+
+    public void remove() {
+        BitmapCache cache = MasterImage.getImage().getBitmapCache();
+        if (cache.cache(mBitmap)) {
+            mBitmap = null;
+        }
+    }
 }