Refactor code.
[sdk/emulator/qemu.git] / hw / yagl / yagl_drivers / egl_cgl / yagl_egl_cgl.c
index 40b15b1..90cd0bc 100644 (file)
@@ -380,7 +380,6 @@ static EGLSurface yagl_egl_cgl_pbuffer_surface_create(struct yagl_egl_driver *dr
 {
     CGLPBufferObj pbuffer = NULL;
     CGLError error;
-    bool is_3_2_core = false;
 
     YAGL_LOG_FUNC_ENTER(yagl_egl_cgl_pbuffer_surface_create,
                         "dpy = %p, width = %d, height = %d",
@@ -388,15 +387,12 @@ static EGLSurface yagl_egl_cgl_pbuffer_surface_create(struct yagl_egl_driver *dr
                         width,
                         height);
 
-    if (driver->gl_version > yagl_gl_2)
-        is_3_2_core = true;
-
     // TODO: Migrate to Metal Framework
     // CGLCreatePBuffer is deprecated on MAC.
     // Below hack is to fix Emulator launch issue on MAC.
     // The surface returned by CGLCreatePBuffer is not used in case of opengl 3.2
     // Hence return dummy surface in case of opengl 3.2 instead of returning null and exiting.
-    if (is_3_2_core) {
+    if (driver->gl_version > yagl_gl_2) {
        YAGL_LOG_INFO("Creating Dummy EGLSurface\n");
        pbuffer = (EGLSurface)1;
     }
@@ -424,15 +420,14 @@ static void yagl_egl_cgl_pbuffer_surface_destroy(struct yagl_egl_driver *driver,
                         "dpy = %p, sfc = %p",
                         dpy,
                         sfc);
-    if (driver->gl_version > yagl_gl_2)
-       goto done;
-
-    error = CGLDestroyPBuffer((CGLPBufferObj)sfc);
+    if (!(driver->gl_version > yagl_gl_2)) {
+        error = CGLDestroyPBuffer((CGLPBufferObj)sfc);
 
-    if (error) {
-        YAGL_LOG_ERROR("CGLDestroyPBuffer failed: %s", CGLErrorString(error));
+        if (error) {
+            YAGL_LOG_ERROR("CGLDestroyPBuffer failed: %s", CGLErrorString(error));
+        }
     }
-done:
+
     YAGL_LOG_FUNC_EXIT(NULL);
 }
 
@@ -520,7 +515,7 @@ static bool yagl_egl_cgl_make_current(struct yagl_egl_driver *driver,
                         draw,
                         read,
                         ctx);
-
+    // Call CGLSetPBuffer only in case a valid CGLCreatePBuffer is created.
     if (cgl_ctx && !cgl_ctx->is_3_2_core) {
         if (read_pbuffer) {
             error = CGLSetPBuffer(cgl_ctx->base, read_pbuffer, 0, 0, 0);