From b7513ceb654f44dc9ea3b2b914de087c02ad6471 Mon Sep 17 00:00:00 2001 From: Karthik Bhat Date: Tue, 7 May 2019 14:09:48 +0530 Subject: [PATCH] Fix emulator launch crash on MAC Change-Id: I187f7b398993b52daa07203bb29a3093bbb12714 Signed-off-by: Karthik Bhat --- hw/yagl/yagl_drivers/egl_cgl/yagl_egl_cgl.c | 35 +++++++++++++++++++---------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/hw/yagl/yagl_drivers/egl_cgl/yagl_egl_cgl.c b/hw/yagl/yagl_drivers/egl_cgl/yagl_egl_cgl.c index 0f398ba..90cd0bc 100644 --- a/hw/yagl/yagl_drivers/egl_cgl/yagl_egl_cgl.c +++ b/hw/yagl/yagl_drivers/egl_cgl/yagl_egl_cgl.c @@ -387,14 +387,24 @@ static EGLSurface yagl_egl_cgl_pbuffer_surface_create(struct yagl_egl_driver *dr width, height); - error = CGLCreatePBuffer(width, height, GL_TEXTURE_2D, GL_RGBA, - 0, &pbuffer); - - if (error) { - YAGL_LOG_ERROR("CGLCreatePBuffer failed: %s", CGLErrorString(error)); - pbuffer = NULL; + // 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 (driver->gl_version > yagl_gl_2) { + YAGL_LOG_INFO("Creating Dummy EGLSurface\n"); + pbuffer = (EGLSurface)1; } + else { + error = CGLCreatePBuffer(width, height, GL_TEXTURE_2D, GL_RGBA, + 0, &pbuffer); + if (error) { + YAGL_LOG_ERROR("CGLCreatePBuffer failed: %s", CGLErrorString(error)); + pbuffer = NULL; + } + } YAGL_LOG_FUNC_EXIT("%p", pbuffer); return pbuffer; @@ -410,11 +420,12 @@ 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)) { + error = CGLDestroyPBuffer((CGLPBufferObj)sfc); - error = CGLDestroyPBuffer((CGLPBufferObj)sfc); - - if (error) { - YAGL_LOG_ERROR("CGLDestroyPBuffer failed: %s", CGLErrorString(error)); + if (error) { + YAGL_LOG_ERROR("CGLDestroyPBuffer failed: %s", CGLErrorString(error)); + } } YAGL_LOG_FUNC_EXIT(NULL); @@ -445,7 +456,7 @@ static EGLContext yagl_egl_cgl_context_create(struct yagl_egl_driver *driver, share_ctx = NULL; } - if ((egl_cgl->base.gl_version > yagl_gl_2) && (version != 1)) { + if (egl_cgl->base.gl_version > yagl_gl_2) { ctx->is_3_2_core = true; } else { ctx->is_3_2_core = false; @@ -504,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); -- 2.7.4