diff options
author | nicolasroard <nicolasroard@google.com> | 2013-09-16 09:33:57 -0700 |
---|---|---|
committer | nicolasroard <nicolasroard@google.com> | 2013-09-16 09:33:57 -0700 |
commit | 208262085feca3d7f6a9606b21745323f9e88418 (patch) | |
tree | f7a41902ccbdda30ea098fc3a5886021f7a364b4 /src | |
parent | a085f59b0d36825afd98e6448a5013e5ae73af2a (diff) | |
download | android_packages_apps_Gallery2-208262085feca3d7f6a9606b21745323f9e88418.tar.gz android_packages_apps_Gallery2-208262085feca3d7f6a9606b21745323f9e88418.tar.bz2 android_packages_apps_Gallery2-208262085feca3d7f6a9606b21745323f9e88418.zip |
Fix flickering while editing
Change-Id: Ic06e0c59059d97f8dd7c150d22746c1f90d7bed1
Diffstat (limited to 'src')
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); } } |