X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=src%2Fcom%2Fandroid%2Fgallery3d%2Ffiltershow%2Ffilters%2FImageFilterRS.java;h=3c54456b69fe5b51b793f449773823c50696ebde;hb=31ba765062fbb75d8b187fb2686e8868d695e754;hp=cfbb560c764dd024139965e526f02d4de3ec2e62;hpb=1e22d9bdda7285053ac0b57d43cef041575cc94f;p=android-x86%2Fpackages-apps-Gallery2.git diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java index cfbb560c7..3c54456b6 100644 --- a/src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java +++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java @@ -18,17 +18,18 @@ package com.android.gallery3d.filtershow.filters; import android.graphics.Bitmap; import android.graphics.BitmapFactory; -import android.support.v8.renderscript.*; +import android.renderscript.*; import android.util.Log; import android.content.res.Resources; import com.android.gallery3d.R; -import com.android.gallery3d.filtershow.cache.CachingPipeline; +import com.android.gallery3d.filtershow.pipeline.PipelineInterface; 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 long mLastTimeCalled; public static boolean PERF_LOGGING = false; @@ -51,26 +52,36 @@ public abstract class ImageFilterRS extends ImageFilter { } protected RenderScript getRenderScriptContext() { - return CachingPipeline.getRenderScriptContext(); + PipelineInterface pipeline = getEnvironment().getPipeline(); + return pipeline.getRSContext(); } protected Allocation getInPixelsAllocation() { - CachingPipeline pipeline = getEnvironment().getCachingPipeline(); + PipelineInterface pipeline = getEnvironment().getPipeline(); return pipeline.getInPixelsAllocation(); } protected Allocation getOutPixelsAllocation() { - CachingPipeline pipeline = getEnvironment().getCachingPipeline(); + PipelineInterface pipeline = getEnvironment().getPipeline(); return pipeline.getOutPixelsAllocation(); } @Override public void apply(Allocation in, Allocation out) { long startOverAll = System.nanoTime(); + if (PERF_LOGGING) { + long delay = (startOverAll - mLastTimeCalled) / 1000; + String msg = String.format("%s; image size %dx%d; ", getName(), + in.getType().getX(), in.getType().getY()); + msg += String.format("called after %.2f ms (%.2f FPS); ", + delay / 1000.f, 1000000.f / delay); + Log.i(LOGTAG, msg); + } + mLastTimeCalled = startOverAll; long startFilter = 0; long endFilter = 0; if (!mResourcesLoaded) { - CachingPipeline pipeline = getEnvironment().getCachingPipeline(); + PipelineInterface pipeline = getEnvironment().getPipeline(); createFilter(pipeline.getResources(), getEnvironment().getScaleFactor(), getEnvironment().getQuality(), in); mResourcesLoaded = true; @@ -102,7 +113,7 @@ public abstract class ImageFilterRS extends ImageFilter { return bitmap; } try { - CachingPipeline pipeline = getEnvironment().getCachingPipeline(); + PipelineInterface pipeline = getEnvironment().getPipeline(); if (DEBUG) { Log.v(LOGTAG, "apply filter " + getName() + " in pipeline " + pipeline.getName()); } @@ -137,27 +148,24 @@ public abstract class ImageFilterRS extends ImageFilter { displayLowMemoryToast(); Log.e(LOGTAG, "not enough memory for filter " + getName(), e); } - return bitmap; } - protected static Allocation convertBitmap(Bitmap bitmap) { - return Allocation.createFromBitmap(CachingPipeline.getRenderScriptContext(), bitmap, + protected static Allocation convertBitmap(RenderScript RS, Bitmap bitmap) { + return Allocation.createFromBitmap(RS, bitmap, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT | Allocation.USAGE_GRAPHICS_TEXTURE); } - private static Allocation convertRGBAtoA(Bitmap bitmap) { - RenderScript RS = CachingPipeline.getRenderScriptContext(); + private static Allocation convertRGBAtoA(RenderScript RS, Bitmap bitmap) { if (RS != mRScache || mGreyConvert == null) { - mGreyConvert = new ScriptC_grey(RS, RS.getApplicationContext().getResources(), - R.raw.grey); + mGreyConvert = new ScriptC_grey(RS); mRScache = RS; } Type.Builder tb_a8 = new Type.Builder(RS, Element.A_8(RS)); - Allocation bitmapTemp = convertBitmap(bitmap); + Allocation bitmapTemp = convertBitmap(RS, bitmap); if (bitmapTemp.getType().getElement().isCompatible(Element.A_8(RS))) { return bitmapTemp; } @@ -173,28 +181,26 @@ public abstract class ImageFilterRS extends ImageFilter { } public Allocation loadScaledResourceAlpha(int resource, int inSampleSize) { - Resources res = CachingPipeline.getResources(); + Resources res = getEnvironment().getPipeline().getResources(); final BitmapFactory.Options options = new BitmapFactory.Options(); - options.inPreferredConfig = Bitmap.Config.ALPHA_8; options.inSampleSize = inSampleSize; Bitmap bitmap = BitmapFactory.decodeResource( res, resource, options); - Allocation ret = convertRGBAtoA(bitmap); + Allocation ret = convertRGBAtoA(getRenderScriptContext(), bitmap); bitmap.recycle(); return ret; } public Allocation loadScaledResourceAlpha(int resource, int w, int h, int inSampleSize) { - Resources res = CachingPipeline.getResources(); + Resources res = getEnvironment().getPipeline().getResources(); final BitmapFactory.Options options = new BitmapFactory.Options(); - options.inPreferredConfig = Bitmap.Config.ALPHA_8; options.inSampleSize = inSampleSize; Bitmap bitmap = BitmapFactory.decodeResource( res, resource, options); Bitmap resizeBitmap = Bitmap.createScaledBitmap(bitmap, w, h, true); - Allocation ret = convertRGBAtoA(resizeBitmap); + Allocation ret = convertRGBAtoA(getRenderScriptContext(), resizeBitmap); resizeBitmap.recycle(); bitmap.recycle(); return ret; @@ -205,13 +211,13 @@ public abstract class ImageFilterRS extends ImageFilter { } public Allocation loadResource(int resource) { - Resources res = CachingPipeline.getResources(); + Resources res = getEnvironment().getPipeline().getResources(); final BitmapFactory.Options options = new BitmapFactory.Options(); options.inPreferredConfig = Bitmap.Config.ARGB_8888; Bitmap bitmap = BitmapFactory.decodeResource( res, resource, options); - Allocation ret = convertBitmap(bitmap); + Allocation ret = convertBitmap(getRenderScriptContext(), bitmap); bitmap.recycle(); return ret; } @@ -232,7 +238,7 @@ public abstract class ImageFilterRS extends ImageFilter { /** * RS Script objects (and all other RS objects) should be cleared here */ - abstract protected void resetScripts(); + public abstract void resetScripts(); /** * Scripts values should be bound here @@ -244,6 +250,8 @@ public abstract class ImageFilterRS extends ImageFilter { return; } resetAllocations(); + mLastInputWidth = 0; + mLastInputHeight = 0; setResourcesLoaded(false); } }