From 7dc62e48c41943003e8ec5659c9f48fca318df2c Mon Sep 17 00:00:00 2001 From: Jorge Ruesga Date: Sun, 22 Jun 2014 00:33:14 +0200 Subject: photophase: cleanup GL resources in GLThread This avoid causing problem in HWUI thread, purging some undesired textures. Change-Id: Ibb713872e5ad19b0980c2e333d2a3fade4f21155 Signed-off-by: Jorge Ruesga --- .../photophase/GLESWallpaperService.java | 4 ++-- .../wallpapers/photophase/PhotoPhaseRenderer.java | 23 ++++++++++++++-------- .../wallpapers/photophase/PhotoPhaseWallpaper.java | 10 +++++++++- .../photophase/PhotoPhaseWallpaperWorld.java | 14 +++++++++++-- 4 files changed, 38 insertions(+), 13 deletions(-) diff --git a/src/org/cyanogenmod/wallpapers/photophase/GLESWallpaperService.java b/src/org/cyanogenmod/wallpapers/photophase/GLESWallpaperService.java index 69b61cf..e3c26d5 100644 --- a/src/org/cyanogenmod/wallpapers/photophase/GLESWallpaperService.java +++ b/src/org/cyanogenmod/wallpapers/photophase/GLESWallpaperService.java @@ -138,13 +138,13 @@ public abstract class GLESWallpaperService extends EGLWallpaperService { */ @Override public void onDestroy() { - super.onDestroy(); - // Notify initialization if (mListener != null) { mListener.onDestroyEGLView(getGlSurfaceView(), mRenderer); } mRenderer = null; + + super.onDestroy(); } /** diff --git a/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseRenderer.java b/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseRenderer.java index 98a07e6..7fb467f 100644 --- a/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseRenderer.java +++ b/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseRenderer.java @@ -254,12 +254,10 @@ public class PhotoPhaseRenderer implements GLSurfaceView.Renderer { } /** - * Method called when renderer is destroyed + * Method called when renderer when GL context is destroyed */ - public void onDestroy() { - if (DEBUG) Log.d(TAG, "onDestroy [" + mInstance + "]"); - // Register a receiver to listen for media reload request - mContext.unregisterReceiver(mSettingsChangedReceiver); + public void onGLContextDestroy() { + if (DEBUG) Log.d(TAG, "onGLContextDestroy [" + mInstance + "]"); recycle(); if (mEffectContext != null) { mEffectContext.release(); @@ -270,6 +268,15 @@ public class PhotoPhaseRenderer implements GLSurfaceView.Renderer { mMeasuredHeight = -1; } + /** + * Method called when renderer is destroyed + */ + public void onDestroy() { + if (DEBUG) Log.d(TAG, "onDestroy [" + mInstance + "]"); + // Register a receiver to listen for media reload request + mContext.unregisterReceiver(mSettingsChangedReceiver); + } + /** * Method called when system runs under low memory */ @@ -559,7 +566,7 @@ public class PhotoPhaseRenderer implements GLSurfaceView.Renderer { } // Delete the world - if (mWorld != null) mWorld.recycle(); + if (mWorld != null) mWorld.recycle(true); if (mTextureManager != null) mTextureManager.recycle(); if (mOverlay != null) mOverlay.recycle(); if (mOopsShape != null) mOopsShape.recycle(); @@ -655,9 +662,9 @@ public class PhotoPhaseRenderer implements GLSurfaceView.Renderer { mTextureManager.setScreenDimesions(screenDimensions); mTextureManager.setPause(false); - // Create the wallpaper (destroy the previous) + // Create the wallpaper (destroy the previous world) if (mWorld != null) { - mWorld.recycle(); + mWorld.recycle(false); } mWorld = new PhotoPhaseWallpaperWorld(mContext, mTextureManager); diff --git a/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseWallpaper.java b/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseWallpaper.java index cb7fd0e..ecb0872 100644 --- a/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseWallpaper.java +++ b/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseWallpaper.java @@ -76,9 +76,17 @@ public class PhotoPhaseWallpaper public void onDestroy() { if (DEBUG) Log.d(TAG, "onDestroy"); super.onDestroy(); - for (PhotoPhaseRenderer renderer : mRenderers) { + for (final PhotoPhaseRenderer renderer : mRenderers) { + // Destroy the instance in the GLThread + renderer.mDispatcher.dispatch(new Runnable() { + @Override + public void run() { + renderer.onGLContextDestroy(); + } + }); renderer.onDestroy(); } + mRenderers.clear(); } /** diff --git a/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseWallpaperWorld.java b/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseWallpaperWorld.java index f01c86c..d548e0a 100644 --- a/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseWallpaperWorld.java +++ b/src/org/cyanogenmod/wallpapers/photophase/PhotoPhaseWallpaperWorld.java @@ -226,8 +226,10 @@ public class PhotoPhaseWallpaperWorld { /** * Method that removes all internal references. + * + * @param full Indicates a full recycle (textures also) */ - public void recycle() { + public void recycle(boolean full) { // Destroy the previous world if (mTransitions != null) { int cc = mTransitions.size() - 1; @@ -252,6 +254,14 @@ public class PhotoPhaseWallpaperWorld { if (mUsedTransitionsQueue != null) { mUsedTransitionsQueue.clear(); } + if (mPhotoFrames != null && full) { + int cc = mPhotoFrames.size() - 1; + for (int i = cc; i >= 0; i--) { + PhotoFrame frame = mPhotoFrames.get(i); + frame.recycle(); + mPhotoFrames.remove(i); + } + } mRecycled = true; } @@ -282,7 +292,7 @@ public class PhotoPhaseWallpaperWorld { // Destroy the previous world if (mRecycled) { - recycle(); + recycle(false); mRecycled = false; } -- cgit v1.2.3