OSDN Git Service

Make Gallery2 use platform RenderScript
[android-x86/packages-apps-Gallery2.git] / src / com / android / gallery3d / filtershow / pipeline / Buffer.java
index 3b59688..a487a5d 100644 (file)
@@ -17,8 +17,9 @@
 package com.android.gallery3d.filtershow.pipeline;
 
 import android.graphics.Bitmap;
-import android.support.v8.renderscript.Allocation;
-import android.support.v8.renderscript.RenderScript;
+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;
@@ -33,7 +34,8 @@ public class Buffer {
     public Buffer(Bitmap bitmap) {
         RenderScript rs = CachingPipeline.getRenderScriptContext();
         if (bitmap != null) {
-            mBitmap = bitmap;
+            BitmapCache cache = MasterImage.getImage().getBitmapCache();
+            mBitmap = cache.getBitmapCopy(bitmap, BitmapCache.PREVIEW_CACHE);
         }
         if (mUseAllocation) {
             // TODO: recreate the allocation when the RS context changes
@@ -43,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;
     }