From 11a52b760154d75b98637e5802c1e0c683e2685b Mon Sep 17 00:00:00 2001 From: Kan-Ru Chen Date: Mon, 4 Oct 2010 19:06:52 +0800 Subject: frameworks: WindowManagerService: Fix out of memory for surface error Surface.openTransaction and Surface.closeTransaction is not reentrant. If we are updating the mouse surface when the WindowManager is also updating the surfaces, the global transaction can be closed too early by the other side. The results are random runtime exceptions and unstable surface state. Move the mouse surface update logic to the big surfaces update loop, together with the other surfaces update logic. Change-Id: I38a4f264f8de59899c3ac0fdaf9d8cd520d41947 --- .../com/android/server/WindowManagerService.java | 55 +++++++++++----------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/services/java/com/android/server/WindowManagerService.java b/services/java/com/android/server/WindowManagerService.java index c603f20..3994c3b 100644 --- a/services/java/com/android/server/WindowManagerService.java +++ b/services/java/com/android/server/WindowManagerService.java @@ -6625,10 +6625,8 @@ public class WindowManagerService extends IWindowManager.Stub //Slog.i(TAG, "Read next event " + ev); dispatchPointer(ev, (MotionEvent)ev.event, 0, 0); if (mMouseDisplayed) { - Surface.openTransaction(); - mMouseSurface.hide(); - Surface.closeTransaction(); mMouseDisplayed = false; + requestAnimationLocked(0); } break; case RawInputEvent.CLASS_MOUSE: @@ -6636,30 +6634,12 @@ public class WindowManagerService extends IWindowManager.Stub int mcx = (int)mmev.getX(); int mcy = (int)mmev.getY(); - if (mMouseSurface != null && (mMlx != mcx || mMly != mcy)) { - Surface.openTransaction(); - if (DEBUG_INPUT) - Slog.i(TAG, "Open transaction for the mouse surface"); - WindowState top = - (WindowState)mWindows.get(mWindows.size() - 1); - try { - if (DEBUG_INPUT) - Slog.i(TAG, "Move surf, x: " + - Integer.toString(mcx) + " y:" - + Integer.toString(mcy)); - - mMouseSurface.setPosition(mcx, mcy); - mMouseSurface.setLayer(top.mAnimLayer + 1); - if (!mMouseDisplayed) { - mMouseSurface.show(); - mMouseDisplayed = true; - } - mMlx = mcx; - mMly = mcy; - } catch ( RuntimeException e) { - Slog.e(TAG, "Failure showing mouse surface",e); - } - Surface.closeTransaction(); + if (mMlx != mcx || mMly != mcy) { + mMlx = mcx; + mMly = mcy; + if (!mMouseDisplayed) + mMouseDisplayed = true; + requestAnimationLocked(0); } dispatchPointer(ev, (MotionEvent)ev.event, 0, 0); break; @@ -10737,6 +10717,27 @@ public class WindowManagerService extends IWindowManager.Stub mBlurShown = false; } + // FOURTH LOOP: Display Mouse + if (mMouseSurface != null) { + if (mMouseDisplayed) { + WindowState top = + (WindowState)mWindows.get(mWindows.size() - 1); + try { + if (DEBUG_INPUT) + Slog.i(TAG, "Move surf, x: " + + Integer.toString(mMlx) + " y:" + + Integer.toString(mMly)); + mMouseSurface.show(); + mMouseSurface.setPosition(mMlx, mMly); + mMouseSurface.setLayer(top.mAnimLayer + 1); + } catch (RuntimeException e) { + Slog.e(TAG, "Failure showing mouse surface", e); + } + } else { + mMouseSurface.hide(); + } + } + if (SHOW_TRANSACTIONS) Slog.i(TAG, "<<< CLOSE TRANSACTION"); } catch (RuntimeException e) { Slog.e(TAG, "Unhandled exception in Window Manager", e); -- cgit v1.1