OSDN Git Service

Make Gallery2 use platform RenderScript
[android-x86/packages-apps-Gallery2.git] / src / com / android / gallery3d / filtershow / pipeline / Buffer.java
index 7268516..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 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();
-        mBitmap = bitmap.copy(BITMAP_CONFIG, true);
+        if (bitmap != null) {
+            BitmapCache cache = MasterImage.getImage().getBitmapCache();
+            mBitmap = cache.getBitmapCopy(bitmap, BitmapCache.PREVIEW_CACHE);
+        }
         if (mUseAllocation) {
             // TODO: recreate the allocation when the RS context changes
             mAllocation = Allocation.createFromBitmap(rs, mBitmap,
@@ -38,7 +45,23 @@ public class Buffer {
         }
     }
 
-    public Bitmap getBitmap() {
+    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 synchronized Bitmap getBitmap() {
         return mBitmap;
     }
 
@@ -52,5 +75,23 @@ public class Buffer {
         }
     }
 
+    public ImagePreset getPreset() {
+        return mPreset;
+    }
+
+    public void setPreset(ImagePreset preset) {
+        if ((mPreset == null) || (!mPreset.same(preset))) {
+            mPreset = new ImagePreset(preset);
+        } else {
+            mPreset.updateWith(preset);
+        }
+    }
+
+    public void remove() {
+        BitmapCache cache = MasterImage.getImage().getBitmapCache();
+        if (cache.cache(mBitmap)) {
+            mBitmap = null;
+        }
+    }
 }