diff options
author | Dianne Hackborn <hackbod@google.com> | 2011-11-17 05:46:34 -0800 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2011-11-17 05:46:34 -0800 |
commit | 77c5f4def49357a89abd9849b0bab950179d71f4 (patch) | |
tree | 0048a35fc889732713233de3723464f86b6128e0 /core | |
parent | 7cd2b19a926224dee2b2e12f37c1d71ce658bf97 (diff) | |
parent | 9aa6bd1c34fe3583fe31f283a6415e84fec12567 (diff) | |
download | frameworks_base-77c5f4def49357a89abd9849b0bab950179d71f4.zip frameworks_base-77c5f4def49357a89abd9849b0bab950179d71f4.tar.gz frameworks_base-77c5f4def49357a89abd9849b0bab950179d71f4.tar.bz2 |
am 9aa6bd1c: am 717a25dc: Add new ManagedEGLContext class to help apps participate in memory trimming.
* commit '9aa6bd1c34fe3583fe31f283a6415e84fec12567':
Add new ManagedEGLContext class to help apps participate in memory trimming.
Diffstat (limited to 'core')
-rw-r--r-- | core/java/android/view/HardwareRenderer.java | 90 | ||||
-rw-r--r-- | core/java/android/view/WindowManagerImpl.java | 3 |
2 files changed, 58 insertions, 35 deletions
diff --git a/core/java/android/view/HardwareRenderer.java b/core/java/android/view/HardwareRenderer.java index e0167d8..8e39d6e 100644 --- a/core/java/android/view/HardwareRenderer.java +++ b/core/java/android/view/HardwareRenderer.java @@ -22,6 +22,9 @@ import android.graphics.Paint; import android.graphics.Rect; import android.graphics.SurfaceTexture; import android.opengl.GLUtils; +import android.opengl.ManagedEGLContext; +import android.os.Handler; +import android.os.Looper; import android.os.SystemClock; import android.os.SystemProperties; import android.util.Log; @@ -409,7 +412,8 @@ public abstract class HardwareRenderer { static final Object[] sEglLock = new Object[0]; int mWidth = -1, mHeight = -1; - static final ThreadLocal<EGLContext> sEglContextStorage = new ThreadLocal<EGLContext>(); + static final ThreadLocal<Gl20Renderer.MyEGLContext> sEglContextStorage + = new ThreadLocal<Gl20Renderer.MyEGLContext>(); EGLContext mEglContext; Thread mEglThread; @@ -561,12 +565,13 @@ public abstract class HardwareRenderer { } } - mEglContext = sEglContextStorage.get(); + Gl20Renderer.MyEGLContext managedContext = sEglContextStorage.get(); + mEglContext = managedContext != null ? managedContext.getContext() : null; mEglThread = Thread.currentThread(); if (mEglContext == null) { mEglContext = createContext(sEgl, sEglDisplay, sEglConfig); - sEglContextStorage.set(mEglContext); + sEglContextStorage.set(new Gl20Renderer.MyEGLContext(mEglContext)); } } @@ -904,6 +909,51 @@ public abstract class HardwareRenderer { private static EGLSurface sPbuffer; private static final Object[] sPbufferLock = new Object[0]; + static class MyEGLContext extends ManagedEGLContext { + final Handler mHandler = new Handler(); + + public MyEGLContext(EGLContext context) { + super(context); + } + + @Override + public void onTerminate(final EGLContext eglContext) { + // Make sure we do this on the correct thread. + if (mHandler.getLooper() != Looper.myLooper()) { + mHandler.post(new Runnable() { + @Override public void run() { + onTerminate(eglContext); + } + }); + return; + } + + synchronized (sEglLock) { + if (sEgl == null) return; + + if (EGLImpl.getInitCount(sEglDisplay) == 1) { + usePbufferSurface(eglContext); + GLES20Canvas.terminateCaches(); + + sEgl.eglDestroyContext(sEglDisplay, eglContext); + sEglContextStorage.remove(); + + sEgl.eglDestroySurface(sEglDisplay, sPbuffer); + sEgl.eglMakeCurrent(sEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + + sEgl.eglReleaseThread(); + sEgl.eglTerminate(sEglDisplay); + + sEgl = null; + sEglDisplay = null; + sEglConfig = null; + sPbuffer = null; + sEglContextStorage.set(null); + } + } + } + } + Gl20Renderer(boolean translucent) { super(2, translucent); } @@ -1020,12 +1070,12 @@ public abstract class HardwareRenderer { static void trimMemory(int level) { if (sEgl == null || sEglConfig == null) return; - EGLContext eglContext = sEglContextStorage.get(); + Gl20Renderer.MyEGLContext managedContext = sEglContextStorage.get(); // We do not have OpenGL objects - if (eglContext == null) { + if (managedContext == null) { return; } else { - usePbufferSurface(eglContext); + usePbufferSurface(managedContext.getContext()); } switch (level) { @@ -1052,33 +1102,5 @@ public abstract class HardwareRenderer { } sEgl.eglMakeCurrent(sEglDisplay, sPbuffer, sPbuffer, eglContext); } - - static void terminate() { - synchronized (sEglLock) { - if (sEgl == null) return; - - if (EGLImpl.getInitCount(sEglDisplay) == 1) { - EGLContext eglContext = sEglContextStorage.get(); - if (eglContext == null) return; - - usePbufferSurface(eglContext); - GLES20Canvas.terminateCaches(); - - sEgl.eglDestroyContext(sEglDisplay, eglContext); - sEglContextStorage.remove(); - - sEgl.eglDestroySurface(sEglDisplay, sPbuffer); - sEgl.eglMakeCurrent(sEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); - - sEgl.eglReleaseThread(); - sEgl.eglTerminate(sEglDisplay); - - sEgl = null; - sEglDisplay = null; - sEglConfig = null; - sPbuffer = null; - } - } - } } } diff --git a/core/java/android/view/WindowManagerImpl.java b/core/java/android/view/WindowManagerImpl.java index d89bc36..660e3f4 100644 --- a/core/java/android/view/WindowManagerImpl.java +++ b/core/java/android/view/WindowManagerImpl.java @@ -21,6 +21,7 @@ import android.content.ComponentCallbacks2; import android.content.res.CompatibilityInfo; import android.content.res.Configuration; import android.graphics.PixelFormat; +import android.opengl.ManagedEGLContext; import android.os.IBinder; import android.util.AndroidRuntimeException; import android.util.Log; @@ -428,7 +429,7 @@ public class WindowManagerImpl implements WindowManager { } } // Terminate the hardware renderer to free all resources - HardwareRenderer.terminate(); + ManagedEGLContext.doTerminate(); break; } // high end gfx devices fall through to next case |