From 8130925c60b786759e852a6088776c626d8ee0e2 Mon Sep 17 00:00:00 2001 From: Owen Lin Date: Wed, 16 May 2012 10:54:14 -0700 Subject: Fix a dead lock while we freeze the screen. bug: 6504696 Change-Id: If960967142bb0df773ce075bf76f5726c37e1d27 --- src/com/android/gallery3d/app/PhotoPage.java | 1 - src/com/android/gallery3d/ui/GLRoot.java | 1 + src/com/android/gallery3d/ui/GLRootView.java | 40 +++++++++++++++++++++++++++- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/com/android/gallery3d/app/PhotoPage.java b/src/com/android/gallery3d/app/PhotoPage.java index a46c777fa..2022a6e2d 100644 --- a/src/com/android/gallery3d/app/PhotoPage.java +++ b/src/com/android/gallery3d/app/PhotoPage.java @@ -56,7 +56,6 @@ import com.android.gallery3d.ui.GLView; import com.android.gallery3d.ui.ImportCompleteListener; import com.android.gallery3d.ui.MenuExecutor; import com.android.gallery3d.ui.PhotoView; -import com.android.gallery3d.ui.ScreenNail; import com.android.gallery3d.ui.SelectionManager; import com.android.gallery3d.ui.SynchronizedHandler; import com.android.gallery3d.util.GalleryUtils; diff --git a/src/com/android/gallery3d/ui/GLRoot.java b/src/com/android/gallery3d/ui/GLRoot.java index 5ed323a88..f4b7572a7 100644 --- a/src/com/android/gallery3d/ui/GLRoot.java +++ b/src/com/android/gallery3d/ui/GLRoot.java @@ -17,6 +17,7 @@ package com.android.gallery3d.ui; import android.graphics.Matrix; + import com.android.gallery3d.anim.CanvasAnimation; public interface GLRoot { diff --git a/src/com/android/gallery3d/ui/GLRootView.java b/src/com/android/gallery3d/ui/GLRootView.java index 1f25b9085..73e982509 100644 --- a/src/com/android/gallery3d/ui/GLRootView.java +++ b/src/com/android/gallery3d/ui/GLRootView.java @@ -19,12 +19,12 @@ package com.android.gallery3d.ui; import android.content.Context; import android.graphics.Matrix; import android.graphics.PixelFormat; -import android.graphics.Rect; import android.opengl.GLSurfaceView; import android.os.Process; import android.os.SystemClock; import android.util.AttributeSet; import android.view.MotionEvent; +import android.view.SurfaceHolder; import com.android.gallery3d.anim.CanvasAnimation; import com.android.gallery3d.common.Utils; @@ -467,6 +467,7 @@ public class GLRootView extends GLSurfaceView @Override public void onPause() { + unfreeze(); super.onPause(); if (DEBUG_PROFILE) { Log.d(TAG, "Stop profiling"); @@ -510,4 +511,41 @@ public class GLRootView extends GLSurfaceView mFreezeCondition.signalAll(); mRenderLock.unlock(); } + + // We need to unfreeze in the following methods and in onPause(). + // These methods will wait on GLThread. If we have freezed the GLRootView, + // the GLThread will wait on main thread to call unfreeze and cause dead + // lock. + @Override + public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { + unfreeze(); + super.surfaceChanged(holder, format, w, h); + } + + @Override + public void surfaceCreated(SurfaceHolder holder) { + unfreeze(); + super.surfaceCreated(holder); + } + + @Override + public void surfaceDestroyed(SurfaceHolder holder) { + unfreeze(); + super.surfaceDestroyed(holder); + } + + @Override + protected void onDetachedFromWindow() { + unfreeze(); + super.onDetachedFromWindow(); + } + + @Override + protected void finalize() throws Throwable { + try { + unfreeze(); + } finally { + super.finalize(); + } + } } -- cgit v1.2.3