OSDN Git Service

Adding eglInitialize and eglTerminate image creation and deletion.
authorMichael Lentine <mlentine@google.com>
Thu, 2 Oct 2014 19:10:07 +0000 (12:10 -0700)
committerMichael Lentine <mlentine@google.com>
Thu, 9 Oct 2014 17:26:37 +0000 (10:26 -0700)
Previously it was possible to have the driver's eglTerminate called beofre
eglDestroyImageKHR in GLConsumer. This was because we didn't increment the
refcount for the lifetime of the image. This could lead to a crash or a deadlock
when multiple threads called terminate and destroy simultaneously.

Bug: 17700483
Change-Id: I7010d0f1b3db875332e95630b5e098a5564ba755

libs/gui/GLConsumer.cpp

index ccafe81..cc96a92 100644 (file)
@@ -1065,6 +1065,7 @@ GLConsumer::EglImage::~EglImage() {
         if (!eglDestroyImageKHR(mEglDisplay, mEglImage)) {
            ALOGE("~EglImage: eglDestroyImageKHR failed");
         }
+        eglTerminate(mEglDisplay);
     }
 }
 
@@ -1079,6 +1080,7 @@ status_t GLConsumer::EglImage::createIfNeeded(EGLDisplay eglDisplay,
         if (!eglDestroyImageKHR(mEglDisplay, mEglImage)) {
            ALOGE("createIfNeeded: eglDestroyImageKHR failed");
         }
+        eglTerminate(mEglDisplay);
         mEglImage = EGL_NO_IMAGE_KHR;
         mEglDisplay = EGL_NO_DISPLAY;
     }
@@ -1129,11 +1131,13 @@ EGLImageKHR GLConsumer::EglImage::createImage(EGLDisplay dpy,
         // removes this restriction if there is hardware that can support it.
         attrs[2] = EGL_NONE;
     }
+    eglInitialize(dpy, 0, 0);
     EGLImageKHR image = eglCreateImageKHR(dpy, EGL_NO_CONTEXT,
             EGL_NATIVE_BUFFER_ANDROID, cbuf, attrs);
     if (image == EGL_NO_IMAGE_KHR) {
         EGLint error = eglGetError();
         ALOGE("error creating EGLImage: %#x", error);
+        eglTerminate(dpy);
     }
     return image;
 }