summaryrefslogtreecommitdiffstats
path: root/src/com/android
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android')
-rw-r--r--src/com/android/gallery3d/filtershow/cache/CachingPipeline.java17
-rw-r--r--src/com/android/gallery3d/filtershow/cache/FilteringPipeline.java5
-rw-r--r--src/com/android/gallery3d/filtershow/imageshow/MasterImage.java19
-rw-r--r--src/com/android/gallery3d/filtershow/pipeline/Buffer.java56
-rw-r--r--src/com/android/gallery3d/filtershow/pipeline/SharedBuffer.java (renamed from src/com/android/gallery3d/filtershow/cache/TripleBufferBitmap.java)48
-rw-r--r--src/com/android/gallery3d/filtershow/presets/FilterEnvironment.java7
6 files changed, 108 insertions, 44 deletions
diff --git a/src/com/android/gallery3d/filtershow/cache/CachingPipeline.java b/src/com/android/gallery3d/filtershow/cache/CachingPipeline.java
index 494c0a636..9901e5705 100644
--- a/src/com/android/gallery3d/filtershow/cache/CachingPipeline.java
+++ b/src/com/android/gallery3d/filtershow/cache/CachingPipeline.java
@@ -27,6 +27,7 @@ import com.android.gallery3d.filtershow.filters.FiltersManager;
import com.android.gallery3d.filtershow.filters.ImageFilterGeometry;
import com.android.gallery3d.filtershow.imageshow.GeometryMetadata;
import com.android.gallery3d.filtershow.imageshow.MasterImage;
+import com.android.gallery3d.filtershow.pipeline.SharedBuffer;
import com.android.gallery3d.filtershow.presets.FilterEnvironment;
import com.android.gallery3d.filtershow.presets.ImagePreset;
import com.android.gallery3d.filtershow.presets.PipelineInterface;
@@ -342,7 +343,7 @@ public class CachingPipeline implements PipelineInterface {
FilterEnvironment.QUALITY_PREVIEW);
}
- public synchronized void compute(TripleBufferBitmap buffer, ImagePreset preset, int type) {
+ public synchronized void compute(SharedBuffer buffer, ImagePreset preset, int type) {
synchronized (CachingPipeline.class) {
if (getRenderScriptContext() == null) {
return;
@@ -361,16 +362,20 @@ public class CachingPipeline implements PipelineInterface {
if (updateOriginalAllocation(preset)) {
resizedOriginalBitmap = mResizedOriginalBitmap;
mEnvironment.cache(buffer.getProducer());
- buffer.updateProducerBitmap(resizedOriginalBitmap);
+ buffer.setProducer(resizedOriginalBitmap);
+ }
+
+ Bitmap bitmap = null;
+ if (buffer.getProducer() != null) {
+ bitmap = buffer.getProducer().getBitmap();
}
- Bitmap bitmap = buffer.getProducer();
long time2 = System.currentTimeMillis();
if (bitmap == null || (bitmap.getWidth() != resizedOriginalBitmap.getWidth())
|| (bitmap.getHeight() != resizedOriginalBitmap.getHeight())) {
mEnvironment.cache(buffer.getProducer());
- buffer.updateProducerBitmap(resizedOriginalBitmap);
- bitmap = buffer.getProducer();
+ buffer.setProducer(resizedOriginalBitmap);
+ bitmap = buffer.getProducer().getBitmap();
}
mOriginalAllocation.copyTo(bitmap);
@@ -393,7 +398,7 @@ public class CachingPipeline implements PipelineInterface {
}
public boolean needsRepaint() {
- TripleBufferBitmap buffer = MasterImage.getImage().getDoubleBuffer();
+ SharedBuffer buffer = MasterImage.getImage().getPreviewBuffer();
return buffer.checkRepaintNeeded();
}
diff --git a/src/com/android/gallery3d/filtershow/cache/FilteringPipeline.java b/src/com/android/gallery3d/filtershow/cache/FilteringPipeline.java
index a0b289733..cac7e056d 100644
--- a/src/com/android/gallery3d/filtershow/cache/FilteringPipeline.java
+++ b/src/com/android/gallery3d/filtershow/cache/FilteringPipeline.java
@@ -26,6 +26,7 @@ import com.android.gallery3d.filtershow.filters.FiltersManager;
import com.android.gallery3d.filtershow.filters.ImageFilterRS;
import com.android.gallery3d.filtershow.imageshow.GeometryMetadata;
import com.android.gallery3d.filtershow.imageshow.MasterImage;
+import com.android.gallery3d.filtershow.pipeline.SharedBuffer;
import com.android.gallery3d.filtershow.presets.ImagePreset;
public class FilteringPipeline implements Handler.Callback {
@@ -71,7 +72,7 @@ public class FilteringPipeline implements Handler.Callback {
public void handleMessage(Message msg) {
switch (msg.what) {
case NEW_PRESET: {
- TripleBufferBitmap buffer = MasterImage.getImage().getDoubleBuffer();
+ SharedBuffer buffer = MasterImage.getImage().getPreviewBuffer();
buffer.swapConsumer();
MasterImage.getImage().notifyObservers();
if (mHasUnhandledPreviewRequest) {
@@ -96,7 +97,7 @@ public class FilteringPipeline implements Handler.Callback {
switch (msg.what) {
case COMPUTE_PRESET: {
ImagePreset preset = (ImagePreset) msg.obj;
- TripleBufferBitmap buffer = MasterImage.getImage().getDoubleBuffer();
+ SharedBuffer buffer = MasterImage.getImage().getPreviewBuffer();
mPreviewPipeline.compute(buffer, preset, COMPUTE_PRESET);
buffer.swapProducer();
Message uimsg = mUIHandler.obtainMessage(NEW_PRESET);
diff --git a/src/com/android/gallery3d/filtershow/imageshow/MasterImage.java b/src/com/android/gallery3d/filtershow/imageshow/MasterImage.java
index 44b9d82bc..76670754e 100644
--- a/src/com/android/gallery3d/filtershow/imageshow/MasterImage.java
+++ b/src/com/android/gallery3d/filtershow/imageshow/MasterImage.java
@@ -31,9 +31,10 @@ import com.android.gallery3d.filtershow.cache.FilteringPipeline;
import com.android.gallery3d.filtershow.cache.ImageLoader;
import com.android.gallery3d.filtershow.cache.RenderingRequest;
import com.android.gallery3d.filtershow.cache.RenderingRequestCaller;
-import com.android.gallery3d.filtershow.cache.TripleBufferBitmap;
import com.android.gallery3d.filtershow.filters.FilterRepresentation;
import com.android.gallery3d.filtershow.filters.ImageFilter;
+import com.android.gallery3d.filtershow.pipeline.Buffer;
+import com.android.gallery3d.filtershow.pipeline.SharedBuffer;
import com.android.gallery3d.filtershow.presets.ImagePreset;
import com.android.gallery3d.filtershow.state.StateAdapter;
@@ -56,7 +57,7 @@ public class MasterImage implements RenderingRequestCaller {
private ImagePreset mGeometryOnlyPreset = null;
private ImagePreset mFiltersOnlyPreset = null;
- private TripleBufferBitmap mFilteredPreview = new TripleBufferBitmap();
+ private SharedBuffer mPreviewBuffer = new SharedBuffer();
private Bitmap mGeometryOnlyBitmap = null;
private Bitmap mFiltersOnlyBitmap = null;
@@ -250,8 +251,8 @@ public class MasterImage implements RenderingRequestCaller {
}
}
- public TripleBufferBitmap getDoubleBuffer() {
- return mFilteredPreview;
+ public SharedBuffer getPreviewBuffer() {
+ return mPreviewBuffer;
}
public void setOriginalGeometry(Bitmap originalBitmapLarge) {
@@ -265,7 +266,11 @@ public class MasterImage implements RenderingRequestCaller {
}
public Bitmap getFilteredImage() {
- return mFilteredPreview.getConsumer();
+ Buffer consumer = mPreviewBuffer.getConsumer();
+ if (consumer != null) {
+ return consumer.getBitmap();
+ }
+ return null;
}
public Bitmap getFiltersOnlyImage() {
@@ -344,7 +349,7 @@ public class MasterImage implements RenderingRequestCaller {
}
public void invalidatePreview() {
- mFilteredPreview.invalidate();
+ mPreviewBuffer.invalidate();
invalidatePartialPreview();
invalidateHighresPreview();
needsUpdatePartialPreview();
@@ -373,7 +378,7 @@ public class MasterImage implements RenderingRequestCaller {
Point translate = getTranslation();
float scaleFactor = getScaleFactor();
m.postTranslate(translate.x, translate.y);
- m.postScale(scaleFactor, scaleFactor, mImageShowSize.x/2.0f, mImageShowSize.y/2.0f);
+ m.postScale(scaleFactor, scaleFactor, mImageShowSize.x / 2.0f, mImageShowSize.y / 2.0f);
return m;
}
diff --git a/src/com/android/gallery3d/filtershow/pipeline/Buffer.java b/src/com/android/gallery3d/filtershow/pipeline/Buffer.java
new file mode 100644
index 000000000..72685167a
--- /dev/null
+++ b/src/com/android/gallery3d/filtershow/pipeline/Buffer.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+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;
+
+public class Buffer {
+ private Bitmap mBitmap;
+ private Allocation mAllocation;
+ private boolean mUseAllocation = false;
+ private static final Bitmap.Config BITMAP_CONFIG = Bitmap.Config.ARGB_8888;
+
+ public Buffer(Bitmap bitmap) {
+ RenderScript rs = CachingPipeline.getRenderScriptContext();
+ mBitmap = bitmap.copy(BITMAP_CONFIG, true);
+ if (mUseAllocation) {
+ // TODO: recreate the allocation when the RS context changes
+ mAllocation = Allocation.createFromBitmap(rs, mBitmap,
+ Allocation.MipmapControl.MIPMAP_NONE,
+ Allocation.USAGE_SHARED | Allocation.USAGE_SCRIPT);
+ }
+ }
+
+ public Bitmap getBitmap() {
+ return mBitmap;
+ }
+
+ public Allocation getAllocation() {
+ return mAllocation;
+ }
+
+ public void sync() {
+ if (mUseAllocation) {
+ mAllocation.copyTo(mBitmap);
+ }
+ }
+
+}
+
diff --git a/src/com/android/gallery3d/filtershow/cache/TripleBufferBitmap.java b/src/com/android/gallery3d/filtershow/pipeline/SharedBuffer.java
index ba7b76925..587174668 100644
--- a/src/com/android/gallery3d/filtershow/cache/TripleBufferBitmap.java
+++ b/src/com/android/gallery3d/filtershow/pipeline/SharedBuffer.java
@@ -14,54 +14,42 @@
* limitations under the License.
*/
-package com.android.gallery3d.filtershow.cache;
+package com.android.gallery3d.filtershow.pipeline;
import android.graphics.Bitmap;
+import android.util.Log;
-public class TripleBufferBitmap {
+public class SharedBuffer {
- private static String LOGTAG = "TripleBufferBitmap";
+ private static final String LOGTAG = "SharedBuffer";
- private volatile Bitmap mBitmaps[] = new Bitmap[3];
- private volatile Bitmap mProducer = null;
- private volatile Bitmap mConsumer = null;
- private volatile Bitmap mIntermediate = null;
+ private volatile Buffer mProducer = null;
+ private volatile Buffer mConsumer = null;
+ private volatile Buffer mIntermediate = null;
private volatile boolean mNeedsSwap = false;
- private final Bitmap.Config mBitmapConfig = Bitmap.Config.ARGB_8888;
private volatile boolean mNeedsRepaint = true;
- public TripleBufferBitmap() {
-
- }
-
- public synchronized void updateBitmaps(Bitmap bitmap) {
- mBitmaps[0] = bitmap.copy(mBitmapConfig, true);
- mBitmaps[1] = bitmap.copy(mBitmapConfig, true);
- mBitmaps[2] = bitmap.copy(mBitmapConfig, true);
- mProducer = mBitmaps[0];
- mConsumer = mBitmaps[1];
- mIntermediate = mBitmaps[2];
- }
-
- public synchronized void updateProducerBitmap(Bitmap bitmap) {
- mProducer = bitmap.copy(mBitmapConfig, true);
+ public SharedBuffer() {
}
public synchronized void setProducer(Bitmap producer) {
- mProducer = producer;
+ mProducer = new Buffer(producer);
}
- public synchronized Bitmap getProducer() {
+ public synchronized Buffer getProducer() {
return mProducer;
}
- public synchronized Bitmap getConsumer() {
+ public synchronized Buffer getConsumer() {
return mConsumer;
}
public synchronized void swapProducer() {
- Bitmap intermediate = mIntermediate;
+ if (mProducer != null) {
+ mProducer.sync();
+ }
+ Buffer intermediate = mIntermediate;
mIntermediate = mProducer;
mProducer = intermediate;
mNeedsSwap = true;
@@ -71,7 +59,10 @@ public class TripleBufferBitmap {
if (!mNeedsSwap) {
return;
}
- Bitmap intermediate = mIntermediate;
+ if (mConsumer != null) {
+ mConsumer.sync();
+ }
+ Buffer intermediate = mIntermediate;
mIntermediate = mConsumer;
mConsumer = intermediate;
mNeedsSwap = false;
@@ -90,3 +81,4 @@ public class TripleBufferBitmap {
}
}
+
diff --git a/src/com/android/gallery3d/filtershow/presets/FilterEnvironment.java b/src/com/android/gallery3d/filtershow/presets/FilterEnvironment.java
index 8d59c9f54..6a130a3e3 100644
--- a/src/com/android/gallery3d/filtershow/presets/FilterEnvironment.java
+++ b/src/com/android/gallery3d/filtershow/presets/FilterEnvironment.java
@@ -22,6 +22,7 @@ import android.support.v8.renderscript.Allocation;
import com.android.gallery3d.filtershow.filters.FilterRepresentation;
import com.android.gallery3d.filtershow.filters.FiltersManagerInterface;
import com.android.gallery3d.filtershow.filters.ImageFilter;
+import com.android.gallery3d.filtershow.pipeline.Buffer;
import java.lang.ref.WeakReference;
import java.util.HashMap;
@@ -53,7 +54,11 @@ public class FilterEnvironment {
private HashMap<Integer, Integer>
generalParameters = new HashMap<Integer, Integer>();
- public void cache(Bitmap bitmap) {
+ public void cache(Buffer buffer) {
+ if (buffer == null) {
+ return;
+ }
+ Bitmap bitmap = buffer.getBitmap();
if (bitmap == null) {
return;
}