summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authornicolasroard <nicolasroard@google.com>2013-09-16 16:49:23 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2013-09-16 16:49:23 +0000
commit9d36d82ff910478a06d186ea7f0eb643ea342551 (patch)
tree5bbabe8d00b0db6304e64593de9efb1dc8a2e879 /src
parentf818028e5c78d85bdacd06a6161543d13b42da45 (diff)
parent208262085feca3d7f6a9606b21745323f9e88418 (diff)
downloadandroid_packages_apps_Gallery2-9d36d82ff910478a06d186ea7f0eb643ea342551.tar.gz
android_packages_apps_Gallery2-9d36d82ff910478a06d186ea7f0eb643ea342551.tar.bz2
android_packages_apps_Gallery2-9d36d82ff910478a06d186ea7f0eb643ea342551.zip
Merge "Fix flickering while editing" into gb-ub-photos-carlsbad
Diffstat (limited to 'src')
-rw-r--r--src/com/android/gallery3d/filtershow/pipeline/Buffer.java22
-rw-r--r--src/com/android/gallery3d/filtershow/pipeline/CachingPipeline.java2
-rw-r--r--src/com/android/gallery3d/filtershow/pipeline/SharedBuffer.java22
3 files changed, 30 insertions, 16 deletions
diff --git a/src/com/android/gallery3d/filtershow/pipeline/Buffer.java b/src/com/android/gallery3d/filtershow/pipeline/Buffer.java
index 3b596886f..c378eb994 100644
--- a/src/com/android/gallery3d/filtershow/pipeline/Buffer.java
+++ b/src/com/android/gallery3d/filtershow/pipeline/Buffer.java
@@ -17,6 +17,7 @@
package com.android.gallery3d.filtershow.pipeline;
import android.graphics.Bitmap;
+import android.graphics.Canvas;
import android.support.v8.renderscript.Allocation;
import android.support.v8.renderscript.RenderScript;
import android.util.Log;
@@ -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;
}
diff --git a/src/com/android/gallery3d/filtershow/pipeline/CachingPipeline.java b/src/com/android/gallery3d/filtershow/pipeline/CachingPipeline.java
index 07ab14ac9..f3c32dc01 100644
--- a/src/com/android/gallery3d/filtershow/pipeline/CachingPipeline.java
+++ b/src/com/android/gallery3d/filtershow/pipeline/CachingPipeline.java
@@ -419,9 +419,9 @@ public class CachingPipeline implements PipelineInterface {
}
setupEnvironment(preset, false);
Vector<FilterRepresentation> filters = preset.getFilters();
- buffer.removeProducer();
Bitmap result = mCachedProcessing.process(mOriginalBitmap, filters, mEnvironment);
buffer.setProducer(result);
+ mEnvironment.cache(result);
}
public synchronized void computeOld(SharedBuffer buffer, ImagePreset preset, int type) {
diff --git a/src/com/android/gallery3d/filtershow/pipeline/SharedBuffer.java b/src/com/android/gallery3d/filtershow/pipeline/SharedBuffer.java
index 267315ccd..f243aa66e 100644
--- a/src/com/android/gallery3d/filtershow/pipeline/SharedBuffer.java
+++ b/src/com/android/gallery3d/filtershow/pipeline/SharedBuffer.java
@@ -29,20 +29,16 @@ public class SharedBuffer {
private volatile boolean mNeedsSwap = false;
private volatile boolean mNeedsRepaint = true;
- public void setProducer(Bitmap producer) {
- removeProducer();
- Buffer buffer = new Buffer(producer);
- synchronized (this) {
- mProducer = buffer;
+ public synchronized void setProducer(Bitmap producer) {
+ if (mProducer != null
+ && !mProducer.isSameSize(producer)) {
+ mProducer.remove();
+ mProducer = null;
}
- }
-
- public void removeProducer() {
- synchronized (this) {
- if (mProducer != null) {
- mProducer.remove();
- mProducer = null;
- }
+ if (mProducer == null) {
+ mProducer = new Buffer(producer);
+ } else {
+ mProducer.useBitmap(producer);
}
}