diff options
| author | Tim Murray <timmurray@google.com> | 2013-04-08 22:01:53 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2013-04-08 22:01:53 +0000 |
| commit | a8d4e88207432fc07385d49245ca2221d6fe0be9 (patch) | |
| tree | 7322b43d8b8249bebfe92e76add06f54f9593fff | |
| parent | f1d6d21dfcf59d69a7ba8a3658fcedbf2aa04779 (diff) | |
| parent | e193e864a849f4f816c55cff83a9dc7b39e0018f (diff) | |
| download | android_packages_apps_Gallery2-a8d4e88207432fc07385d49245ca2221d6fe0be9.tar.gz android_packages_apps_Gallery2-a8d4e88207432fc07385d49245ca2221d6fe0be9.tar.bz2 android_packages_apps_Gallery2-a8d4e88207432fc07385d49245ca2221d6fe0be9.zip | |
Merge "Limit creation of greyscale converter RS script." into gb-ub-photos-bryce
| -rw-r--r-- | src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java index a0523c14e..014a11f9e 100644 --- a/src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java +++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java @@ -30,6 +30,9 @@ public abstract class ImageFilterRS extends ImageFilter { private int mLastInputWidth = 0; private int mLastInputHeight = 0; + private static ScriptC_grey mGreyConvert = null; + private static RenderScript mRScache = null; + private volatile boolean mResourcesLoaded = false; protected abstract void createFilter(android.content.res.Resources res, @@ -106,9 +109,13 @@ public abstract class ImageFilterRS extends ImageFilter { private static Allocation convertRGBAtoA(Bitmap bitmap) { RenderScript RS = CachingPipeline.getRenderScriptContext(); + if (RS != mRScache || mGreyConvert == null) { + mGreyConvert = new ScriptC_grey(RS, RS.getApplicationContext().getResources(), + R.raw.grey); + mRScache = RS; + } + Type.Builder tb_a8 = new Type.Builder(RS, Element.A_8(RS)); - ScriptC_grey greyConvert = new ScriptC_grey(RS, - RS.getApplicationContext().getResources(), R.raw.grey); Allocation bitmapTemp = convertBitmap(bitmap); if (bitmapTemp.getType().getElement().isCompatible(Element.A_8(RS))) { @@ -118,8 +125,8 @@ public abstract class ImageFilterRS extends ImageFilter { tb_a8.setX(bitmapTemp.getType().getX()); tb_a8.setY(bitmapTemp.getType().getY()); Allocation bitmapAlloc = Allocation.createTyped(RS, tb_a8.create()); - greyConvert.forEach_RGBAtoA(bitmapTemp, bitmapAlloc); - + mGreyConvert.forEach_RGBAtoA(bitmapTemp, bitmapAlloc); + bitmapTemp.destroy(); return bitmapAlloc; } |
