OSDN Git Service

Revert "Stopgap fixes for more of the photo editor's memory issues."
authorRuben Brunk <rubenbrunk@google.com>
Fri, 22 Feb 2013 21:45:26 +0000 (21:45 +0000)
committerAndroid (Google) Code Review <android-gerrit@google.com>
Fri, 22 Feb 2013 21:45:26 +0000 (21:45 +0000)
This reverts commit 4c91156f9a2e48ebaec86e3a46ea9b7855392cfd

Change-Id: If94d87fd4d84bd518b7cc113c3cd422b59fdd3ed

src/com/android/gallery3d/filtershow/FilterShowActivity.java
src/com/android/gallery3d/filtershow/cache/FilteringPipeline.java
src/com/android/gallery3d/filtershow/cache/ImageLoader.java
src/com/android/gallery3d/filtershow/filters/ImageFilter.java
src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java

index cd80e92..7e8a3f5 100644 (file)
@@ -152,7 +152,6 @@ public class FilterShowActivity extends Activity implements OnItemClickListener,
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
-        ImageFilter.setActivityForMemoryToasts(this);
         setResources();
 
         Resources res = getResources();
@@ -521,9 +520,6 @@ public class FilterShowActivity extends Activity implements OnItemClickListener,
         if (mLoadBitmapTask != null) {
             mLoadBitmapTask.cancel(false);
         }
-        MasterImage.reset();
-        FilteringPipeline.reset();
-        ImageFilter.reset();
         super.onDestroy();
     }
 
index 0af4063..7d5b529 100644 (file)
@@ -31,7 +31,7 @@ import com.android.gallery3d.filtershow.presets.ImagePreset;
 
 public class FilteringPipeline implements Handler.Callback {
 
-    private static FilteringPipeline sPipeline;
+    private final static FilteringPipeline gPipeline = new FilteringPipeline();
     private static final String LOGTAG = "FilteringPipeline";
     private ImagePreset mPreviousGeometryPreset = null;
     private ImagePreset mPreviousFiltersPreset = null;
@@ -117,10 +117,7 @@ public class FilteringPipeline implements Handler.Callback {
     }
 
     public static FilteringPipeline getPipeline() {
-        if (sPipeline == null) {
-            sPipeline = new FilteringPipeline();
-        }
-        return sPipeline;
+        return gPipeline;
     }
 
     public synchronized void setOriginal(Bitmap bitmap) {
@@ -340,8 +337,4 @@ public class FilteringPipeline implements Handler.Callback {
     public float getPreviewScaleFactor() {
         return mPreviewScaleFactor;
     }
-
-    public static void reset() {
-        sPipeline = null;
-    }
 }
index a5b1bc5..25bb6b6 100644 (file)
@@ -62,8 +62,6 @@ import java.io.OutputStream;
 import java.util.Vector;
 import java.util.concurrent.locks.ReentrantLock;
 
-
-// TODO: this class has waaaay to much bitmap copying.  Cleanup.
 public class ImageLoader {
 
     private static final String LOGTAG = "ImageLoader";
@@ -391,13 +389,15 @@ public class ImageLoader {
             }
             bmp = loadRegionBitmap(mUri, options, bounds);
             if (bmp != null) {
+                // TODO: this workaround for RS might not be needed ultimately
+                Bitmap bmp2 = bmp.copy(Bitmap.Config.ARGB_8888, true);
                 float scaleFactor = imagePreset.getScaleFactor();
                 imagePreset.setScaleFactor(1.0f);
-                bmp = imagePreset.apply(bmp);
+                bmp2 = imagePreset.apply(bmp2);
                 imagePreset.setScaleFactor(scaleFactor);
-                mZoomCache.setImage(imagePreset, bounds, bmp);
+                mZoomCache.setImage(imagePreset, bounds, bmp2);
                 mLoadingLock.unlock();
-                return bmp;
+                return bmp2;
             }
         }
         mLoadingLock.unlock();
index 866fc5e..614c6a0 100644 (file)
@@ -18,10 +18,8 @@ package com.android.gallery3d.filtershow.filters;
 
 import android.graphics.Bitmap;
 import android.graphics.Matrix;
-import android.widget.Toast;
 
 import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.FilterShowActivity;
 import com.android.gallery3d.filtershow.editors.BasicEditor;
 import com.android.gallery3d.filtershow.imageshow.GeometryMetadata;
 import com.android.gallery3d.filtershow.presets.ImagePreset;
@@ -33,30 +31,6 @@ public abstract class ImageFilter implements Cloneable {
     protected String mName = "Original";
     private final String LOGTAG = "ImageFilter";
 
-    // TODO: Temporary, for dogfood note memory issues with toasts for better
-    // feedback. Remove this when filters actually work in low memory
-    // situations.
-    private static FilterShowActivity sActivity = null;
-
-    public static void setActivityForMemoryToasts(FilterShowActivity activity) {
-        sActivity = activity;
-    }
-
-    public static void reset() {
-        sActivity = null;
-    }
-
-    public void displayLowMemoryToast() {
-        if (sActivity != null) {
-            sActivity.runOnUiThread(new Runnable() {
-                public void run() {
-                    Toast.makeText(sActivity, "Memory too low for filter " + getName() +
-                            ", please file a bug report", Toast.LENGTH_SHORT).show();
-                }
-            });
-        }
-    }
-
     public void setName(String name) {
         mName = name;
     }
@@ -71,8 +45,8 @@ public abstract class ImageFilter implements Cloneable {
     }
 
     /**
-     * Called on small bitmaps to create button icons for each filter. Override
-     * this to provide filter-specific button icons.
+     * Called on small bitmaps to create button icons for each filter.
+     * Override this to provide filter-specific button icons.
      */
     public Bitmap iconApply(Bitmap bitmap, float scaleFactor, int quality) {
         return apply(bitmap, scaleFactor, quality);
index a3467ed..74712be 100644 (file)
@@ -89,11 +89,6 @@ public abstract class ImageFilterRS extends ImageFilter {
             Log.e(LOGTAG, "Illegal argument? " + e);
         } catch (android.renderscript.RSRuntimeException e) {
             Log.e(LOGTAG, "RS runtime exception ? " + e);
-        } catch (java.lang.OutOfMemoryError e) {
-            // Many of the renderscript filters allocated large (>16Mb resources) in order to apply.
-            System.gc();
-            displayLowMemoryToast();
-            Log.e(LOGTAG, "not enough memory for filter " + getName(), e);
         }
         return bitmap;
     }