Loading src/com/android/gallery3d/filtershow/pipeline/Buffer.java +20 −2 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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 Loading @@ -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; } Loading src/com/android/gallery3d/filtershow/pipeline/CachingPipeline.java +1 −1 Original line number Diff line number Diff line Loading @@ -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) { Loading src/com/android/gallery3d/filtershow/pipeline/SharedBuffer.java +9 −13 Original line number Diff line number Diff line Loading @@ -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 void removeProducer() { synchronized (this) { if (mProducer != null) { public synchronized void setProducer(Bitmap producer) { if (mProducer != null && !mProducer.isSameSize(producer)) { mProducer.remove(); mProducer = null; } if (mProducer == null) { mProducer = new Buffer(producer); } else { mProducer.useBitmap(producer); } } Loading Loading
src/com/android/gallery3d/filtershow/pipeline/Buffer.java +20 −2 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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 Loading @@ -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; } Loading
src/com/android/gallery3d/filtershow/pipeline/CachingPipeline.java +1 −1 Original line number Diff line number Diff line Loading @@ -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) { Loading
src/com/android/gallery3d/filtershow/pipeline/SharedBuffer.java +9 −13 Original line number Diff line number Diff line Loading @@ -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 void removeProducer() { synchronized (this) { if (mProducer != null) { public synchronized void setProducer(Bitmap producer) { if (mProducer != null && !mProducer.isSameSize(producer)) { mProducer.remove(); mProducer = null; } if (mProducer == null) { mProducer = new Buffer(producer); } else { mProducer.useBitmap(producer); } } Loading