summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authornicolasroard <nicolasroard@google.com>2013-07-31 16:22:59 -0700
committernicolasroard <nicolasroard@google.com>2013-07-31 17:39:52 -0700
commit3a5bc6b23096365e1a814f8999937028bc12b401 (patch)
treee3f532fb73211a0ac4622581623c1d555aff511a /src
parentbb2848ab2a8d532956f4730c8cf7434eb3a8600f (diff)
downloadandroid_packages_apps_Snap-3a5bc6b23096365e1a814f8999937028bc12b401.tar.gz
android_packages_apps_Snap-3a5bc6b23096365e1a814f8999937028bc12b401.tar.bz2
android_packages_apps_Snap-3a5bc6b23096365e1a814f8999937028bc12b401.zip
Fix problem with N-1 caching when no filters / one filter
- also fix equals() for geometry Change-Id: I6f6f21d1e274b3b95ac4b5189b2fa7f419912864
Diffstat (limited to 'src')
-rw-r--r--src/com/android/gallery3d/filtershow/FilterShowActivity.java5
-rw-r--r--src/com/android/gallery3d/filtershow/filters/FilterCropRepresentation.java19
-rw-r--r--src/com/android/gallery3d/filtershow/filters/FilterMirrorRepresentation.java12
-rw-r--r--src/com/android/gallery3d/filtershow/filters/FilterRotateRepresentation.java12
-rw-r--r--src/com/android/gallery3d/filtershow/filters/FilterStraightenRepresentation.java12
-rw-r--r--src/com/android/gallery3d/filtershow/imageshow/GeometryMetadata.java16
-rw-r--r--src/com/android/gallery3d/filtershow/pipeline/CacheProcessing.java27
7 files changed, 93 insertions, 10 deletions
diff --git a/src/com/android/gallery3d/filtershow/FilterShowActivity.java b/src/com/android/gallery3d/filtershow/FilterShowActivity.java
index b06010f61..0fca6520a 100644
--- a/src/com/android/gallery3d/filtershow/FilterShowActivity.java
+++ b/src/com/android/gallery3d/filtershow/FilterShowActivity.java
@@ -127,7 +127,6 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
private static final int SELECT_PICTURE = 1;
private static final String LOGTAG = "FilterShowActivity";
- protected static final boolean ANIMATE_PANELS = true;
private boolean mShowingTinyPlanet = false;
private boolean mShowingImageStatePanel = false;
@@ -142,7 +141,6 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
private WeakReference<ProgressDialog> mSavingProgressDialog;
private LoadBitmapTask mLoadBitmapTask;
- private boolean mLoading = true;
private Uri mOriginalImageUri = null;
private ImagePreset mOriginalPreset = null;
@@ -420,7 +418,6 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
}
private void startLoadBitmap(Uri uri) {
- mLoading = true;
final View loading = findViewById(R.id.loading);
final View imageShow = findViewById(R.id.imageShow);
imageShow.setVisibility(View.INVISIBLE);
@@ -653,7 +650,7 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
if (mAction == TINY_PLANET_ACTION) {
showRepresentation(mCategoryFiltersAdapter.getTinyPlanet());
}
- mLoading = false;
+
MasterImage.getImage().notifyGeometryChange();
LoadHighresBitmapTask highresLoad = new LoadHighresBitmapTask();
highresLoad.execute();
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterCropRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterCropRepresentation.java
index 345c2f1bf..fea8b2139 100644
--- a/src/com/android/gallery3d/filtershow/filters/FilterCropRepresentation.java
+++ b/src/com/android/gallery3d/filtershow/filters/FilterCropRepresentation.java
@@ -60,6 +60,25 @@ public class FilterCropRepresentation extends FilterRepresentation {
mImage.set(r.mImage);
}
+ @Override
+ public boolean equals(FilterRepresentation rep) {
+ if (!(rep instanceof FilterCropRepresentation)) {
+ return false;
+ }
+ FilterCropRepresentation crop = (FilterCropRepresentation) rep;
+ if (mCrop.bottom != crop.mCrop.bottom
+ || mCrop.left != crop.mCrop.left
+ || mCrop.right != crop.mCrop.right
+ || mCrop.top != crop.mCrop.top
+ || mImage.bottom != crop.mImage.bottom
+ || mImage.left != crop.mImage.left
+ || mImage.right != crop.mImage.right
+ || mImage.top != crop.mImage.top) {
+ return false;
+ }
+ return true;
+ }
+
public RectF getCrop() {
return new RectF(mCrop);
}
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterMirrorRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterMirrorRepresentation.java
index 0acf70e71..22a15f27e 100644
--- a/src/com/android/gallery3d/filtershow/filters/FilterMirrorRepresentation.java
+++ b/src/com/android/gallery3d/filtershow/filters/FilterMirrorRepresentation.java
@@ -79,6 +79,18 @@ public class FilterMirrorRepresentation extends FilterRepresentation {
this(Mirror.NONE);
}
+ @Override
+ public boolean equals(FilterRepresentation rep) {
+ if (!(rep instanceof FilterMirrorRepresentation)) {
+ return false;
+ }
+ FilterMirrorRepresentation mirror = (FilterMirrorRepresentation) rep;
+ if (mirror.mMirror.value() != mirror.mMirror.value()) {
+ return false;
+ }
+ return true;
+ }
+
public Mirror getMirror() {
return mMirror;
}
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterRotateRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterRotateRepresentation.java
index 8f7d8ebef..d5f3a5b40 100644
--- a/src/com/android/gallery3d/filtershow/filters/FilterRotateRepresentation.java
+++ b/src/com/android/gallery3d/filtershow/filters/FilterRotateRepresentation.java
@@ -134,6 +134,18 @@ public class FilterRotateRepresentation extends FilterRepresentation {
}
@Override
+ public boolean equals(FilterRepresentation rep) {
+ if (!(rep instanceof FilterRotateRepresentation)) {
+ return false;
+ }
+ FilterRotateRepresentation rotate = (FilterRotateRepresentation) rep;
+ if (rotate.mRotation.value() != mRotation.value()) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
public void deSerializeRepresentation(JsonReader reader) throws IOException {
boolean unset = true;
reader.beginObject();
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterStraightenRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterStraightenRepresentation.java
index a06216ef3..890f1cfd6 100644
--- a/src/com/android/gallery3d/filtershow/filters/FilterStraightenRepresentation.java
+++ b/src/com/android/gallery3d/filtershow/filters/FilterStraightenRepresentation.java
@@ -55,6 +55,18 @@ public class FilterStraightenRepresentation extends FilterRepresentation {
mStraighten = r.mStraighten;
}
+ @Override
+ public boolean equals(FilterRepresentation rep) {
+ if (!(rep instanceof FilterStraightenRepresentation)) {
+ return false;
+ }
+ FilterStraightenRepresentation straighten = (FilterStraightenRepresentation) rep;
+ if (straighten.mStraighten != mStraighten) {
+ return false;
+ }
+ return true;
+ }
+
public float getStraighten() {
return mStraighten;
}
diff --git a/src/com/android/gallery3d/filtershow/imageshow/GeometryMetadata.java b/src/com/android/gallery3d/filtershow/imageshow/GeometryMetadata.java
index 42474df3a..adfce85cf 100644
--- a/src/com/android/gallery3d/filtershow/imageshow/GeometryMetadata.java
+++ b/src/com/android/gallery3d/filtershow/imageshow/GeometryMetadata.java
@@ -101,6 +101,22 @@ public class GeometryMetadata extends FilterRepresentation {
mMirrorRep.set(g.mMirrorRep);
}
+ @Override
+ public boolean equals(FilterRepresentation rep) {
+ if (!(rep instanceof GeometryMetadata)) {
+ return false;
+ }
+ GeometryMetadata geo = (GeometryMetadata) rep;
+ if (geo.mScaleFactor != mScaleFactor
+ || !geo.mRotationRep.equals(mRotationRep)
+ || !geo.mStraightenRep.equals(mStraightenRep)
+ || !geo.mCropRep.equals(mCropRep)
+ || !geo.mMirrorRep.equals(mMirrorRep)) {
+ return false;
+ }
+ return true;
+ }
+
public float getScaleFactor() {
return mScaleFactor;
}
diff --git a/src/com/android/gallery3d/filtershow/pipeline/CacheProcessing.java b/src/com/android/gallery3d/filtershow/pipeline/CacheProcessing.java
index e358ebaa3..10b6c4923 100644
--- a/src/com/android/gallery3d/filtershow/pipeline/CacheProcessing.java
+++ b/src/com/android/gallery3d/filtershow/pipeline/CacheProcessing.java
@@ -35,7 +35,10 @@ public class CacheProcessing {
public Bitmap process(Bitmap originalBitmap,
Vector<FilterRepresentation> filters,
FilterEnvironment environment) {
- Bitmap cacheBitmap = originalBitmap;
+
+ if (filters.size() == 0) {
+ return originalBitmap;
+ }
// New set of filters, let's clear the cache and rebuild it.
if (filters.size() != mSteps.size()) {
@@ -54,7 +57,7 @@ public class CacheProcessing {
// First, let's find how similar we are in our cache
// compared to the current list of filters
- int similarUpToIndex = 0;
+ int similarUpToIndex = -1;
for (int i = 0; i < filters.size(); i++) {
FilterRepresentation representation = filters.elementAt(i);
CacheStep step = mSteps.elementAt(i);
@@ -70,18 +73,27 @@ public class CacheProcessing {
}
// Now, let's get the earliest cached result in our pipeline
+ Bitmap cacheBitmap = null;
int findBaseImageIndex = similarUpToIndex;
- while (findBaseImageIndex > 0
- && mSteps.elementAt(findBaseImageIndex).cache == null) {
- findBaseImageIndex--;
+ if (findBaseImageIndex > -1) {
+ while (findBaseImageIndex > 0
+ && mSteps.elementAt(findBaseImageIndex).cache == null) {
+ findBaseImageIndex--;
+ }
+ cacheBitmap = mSteps.elementAt(findBaseImageIndex).cache;
}
- cacheBitmap = mSteps.elementAt(findBaseImageIndex).cache;
boolean emptyStack = false;
if (cacheBitmap == null) {
emptyStack = true;
// Damn, it's an empty stack, we have to start from scratch
// TODO: use a bitmap cache + RS allocation instead of Bitmap.copy()
cacheBitmap = originalBitmap.copy(Bitmap.Config.ARGB_8888, true);
+ if (findBaseImageIndex > -1) {
+ FilterRepresentation representation = filters.elementAt(findBaseImageIndex);
+ cacheBitmap = environment.applyRepresentation(representation, cacheBitmap);
+ mSteps.elementAt(findBaseImageIndex).representation = representation.copy();
+ mSteps.elementAt(findBaseImageIndex).cache = cacheBitmap;
+ }
if (DEBUG) {
Log.v(LOGTAG, "empty stack");
}
@@ -97,6 +109,9 @@ public class CacheProcessing {
// rebuild the cache image for this step
if (!emptyStack) {
cacheBitmap = cacheBitmap.copy(Bitmap.Config.ARGB_8888, true);
+ } else {
+ // if it was an empty stack, we already applied it
+ findBaseImageIndex ++;
}
for (int i = findBaseImageIndex; i <= similarUpToIndex; i++) {
FilterRepresentation representation = filters.elementAt(i);