diff options
author | Jamie Gennis <jgennis@google.com> | 2012-04-17 13:07:45 -0700 |
---|---|---|
committer | Jamie Gennis <jgennis@google.com> | 2012-04-17 15:53:31 -0700 |
commit | 9aa74dbc7070aa396bc425ea3feae3d26e5393f6 (patch) | |
tree | fb23384ece7723ed4fc1194b7a07b390dcb53532 /libs/gui/SurfaceTexture.cpp | |
parent | 2efa4b2bb0128cd65ea8ade46f46bacaf72c194f (diff) | |
download | frameworks_native-9aa74dbc7070aa396bc425ea3feae3d26e5393f6.zip frameworks_native-9aa74dbc7070aa396bc425ea3feae3d26e5393f6.tar.gz frameworks_native-9aa74dbc7070aa396bc425ea3feae3d26e5393f6.tar.bz2 |
SurfaceTexture: fix a memory leak
This change fixes an issue where we were sometimes setting the SurfaceTexture's
EGLDisplay to EGL_NO_DISPLAY in detachFromContext, and then subsequently
abandoning the texture. Abandoning while in the detached state would result in
the eglDestroyImageKHR calls failing, which resulted in a memory leak.
Bug: 6302694
Change-Id: I24c1de0dac029a83c7508075fb8aaeaed96a14ea
Diffstat (limited to 'libs/gui/SurfaceTexture.cpp')
-rw-r--r-- | libs/gui/SurfaceTexture.cpp | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/libs/gui/SurfaceTexture.cpp b/libs/gui/SurfaceTexture.cpp index ed1ea4e..a6ee971 100644 --- a/libs/gui/SurfaceTexture.cpp +++ b/libs/gui/SurfaceTexture.cpp @@ -344,6 +344,18 @@ status_t SurfaceTexture::detachFromContext() { glDeleteTextures(1, &mTexName); } + // Because we're giving up the EGLDisplay we need to free all the EGLImages + // that are associated with it. They'll be recreated when the + // SurfaceTexture gets attached to a new OpenGL ES context (and thus gets a + // new EGLDisplay). + for (int i =0; i < BufferQueue::NUM_BUFFER_SLOTS; i++) { + EGLImageKHR img = mEGLSlots[i].mEglImage; + if (img != EGL_NO_IMAGE_KHR) { + eglDestroyImageKHR(mEglDisplay, img); + mEGLSlots[i].mEglImage = EGL_NO_IMAGE_KHR; + } + } + mEglDisplay = EGL_NO_DISPLAY; mEglContext = EGL_NO_CONTEXT; mAttached = false; @@ -668,13 +680,12 @@ void SurfaceTexture::freeBufferLocked(int slotIndex) { if (slotIndex == mCurrentTexture) { mCurrentTexture = BufferQueue::INVALID_BUFFER_SLOT; } - if (mEGLSlots[slotIndex].mEglImage != EGL_NO_IMAGE_KHR) { - EGLImageKHR img = mEGLSlots[slotIndex].mEglImage; - if (img != EGL_NO_IMAGE_KHR) { - eglDestroyImageKHR(mEglDisplay, img); - } - mEGLSlots[slotIndex].mEglImage = EGL_NO_IMAGE_KHR; + EGLImageKHR img = mEGLSlots[slotIndex].mEglImage; + if (img != EGL_NO_IMAGE_KHR) { + ST_LOGV("destroying EGLImage dpy=%p img=%p", mEglDisplay, img); + eglDestroyImageKHR(mEglDisplay, img); } + mEGLSlots[slotIndex].mEglImage = EGL_NO_IMAGE_KHR; } void SurfaceTexture::abandon() { |