From 67dd6e6af3b652893c5890f24c35b2b5acfd633d Mon Sep 17 00:00:00 2001 From: nicolasroard Date: Tue, 2 Apr 2013 22:22:37 -0700 Subject: Fix segfaults in RS filters We did not recreate the filters in all cases when the input size change. bug:8530112 Change-Id: I4cb47498532618271b90e56c01ec63ad991db787 --- .../android/gallery3d/filtershow/filters/ImageFilterRS.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/com/android/gallery3d/filtershow') diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java index 2aeaed877..a0523c14e 100644 --- a/src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java +++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java @@ -16,7 +16,6 @@ package com.android.gallery3d.filtershow.filters; -import android.app.Activity; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.support.v8.renderscript.*; @@ -28,6 +27,8 @@ import com.android.gallery3d.filtershow.cache.CachingPipeline; public abstract class ImageFilterRS extends ImageFilter { private static final String LOGTAG = "ImageFilterRS"; private boolean DEBUG = false; + private int mLastInputWidth = 0; + private int mLastInputHeight = 0; private volatile boolean mResourcesLoaded = false; @@ -65,11 +66,19 @@ public abstract class ImageFilterRS extends ImageFilter { Log.v(LOGTAG, "apply filter " + getName() + " in pipeline " + pipeline.getName()); } Resources rsc = pipeline.getResources(); + boolean sizeChanged = false; + if (getInPixelsAllocation() != null + && ((getInPixelsAllocation().getType().getX() != mLastInputWidth) + || (getInPixelsAllocation().getType().getY() != mLastInputHeight))) { + sizeChanged = true; + } if (pipeline.prepareRenderscriptAllocations(bitmap) - || !isResourcesLoaded()) { + || !isResourcesLoaded() || sizeChanged) { freeResources(); createFilter(rsc, scaleFactor, quality); setResourcesLoaded(true); + mLastInputWidth = getInPixelsAllocation().getType().getX(); + mLastInputHeight = getInPixelsAllocation().getType().getY(); } bindScriptValues(); runFilter(); -- cgit v1.2.3