Skip to content

Commit

Permalink
Set EGL surface for foreign X11 windows
Browse files Browse the repository at this point in the history
Also slightly changes up the cleanup code for SetupWindowData, to avoid copy pasting.

See libsdl-org#10611
  • Loading branch information
CasualPokePlayer committed Aug 31, 2024
1 parent 4eac44b commit b905583
Showing 1 changed file with 38 additions and 27 deletions.
65 changes: 38 additions & 27 deletions src/video/x11/SDL_x11window.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,8 @@ static int SetupWindowData(_THIS, SDL_Window *window, Window w, BOOL created)
1) *
sizeof(*windowlist));
if (!windowlist) {
SDL_free(data);
return SDL_OutOfMemory();
SDL_OutOfMemory();
goto error_cleanup;
}
windowlist[numwindows] = data;
videodata->numwindows++;
Expand Down Expand Up @@ -331,9 +331,45 @@ static int SetupWindowData(_THIS, SDL_Window *window, Window w, BOOL created)
}
}

#if defined(SDL_VIDEO_OPENGL_ES) || defined(SDL_VIDEO_OPENGL_ES2) || defined(SDL_VIDEO_OPENGL_EGL)
if ((window->flags & SDL_WINDOW_OPENGL) &&
((_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) ||
SDL_GetHintBoolean(SDL_HINT_VIDEO_X11_FORCE_EGL, SDL_FALSE))
#ifdef SDL_VIDEO_OPENGL_GLX
&& (!_this->gl_data || X11_GL_UseEGL(_this) )
#endif
) {
#ifdef SDL_VIDEO_OPENGL_EGL
if (!_this->egl_data) {
goto error_cleanup;
}

/* Create the GLES window surface */
data->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType)w);

if (data->egl_surface == EGL_NO_SURFACE) {
SDL_SetError("Could not create GLES window surface");
goto error_cleanup;
}
#else
SDL_SetError("Could not create GLES window surface (EGL support not configured)");
goto error_cleanup;
#endif /* SDL_VIDEO_OPENGL_EGL */
}
#endif

/* All done! */
window->driverdata = data;
return 0;

error_cleanup:
#ifdef X_HAVE_UTF8_STRING
if (data->ic) {
X11_XDestroyIC(data->ic);
}
#endif
SDL_free(data);
return -1;
}

static void SetWindowBordered(Display *display, int screen, Window window, SDL_bool border)
Expand Down Expand Up @@ -634,31 +670,6 @@ int X11_CreateWindow(_THIS, SDL_Window *window)
}
windowdata = (SDL_WindowData *)window->driverdata;

#if defined(SDL_VIDEO_OPENGL_ES) || defined(SDL_VIDEO_OPENGL_ES2) || defined(SDL_VIDEO_OPENGL_EGL)
if ((window->flags & SDL_WINDOW_OPENGL) &&
((_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) ||
SDL_GetHintBoolean(SDL_HINT_VIDEO_X11_FORCE_EGL, SDL_FALSE))
#ifdef SDL_VIDEO_OPENGL_GLX
&& (!_this->gl_data || X11_GL_UseEGL(_this) )
#endif
) {
#ifdef SDL_VIDEO_OPENGL_EGL
if (!_this->egl_data) {
return -1;
}

/* Create the GLES window surface */
windowdata->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType)w);

if (windowdata->egl_surface == EGL_NO_SURFACE) {
return SDL_SetError("Could not create GLES window surface");
}
#else
return SDL_SetError("Could not create GLES window surface (EGL support not configured)");
#endif /* SDL_VIDEO_OPENGL_EGL */
}
#endif

#ifdef X_HAVE_UTF8_STRING
if (SDL_X11_HAVE_UTF8 && windowdata->ic) {
X11_XGetICValues(windowdata->ic, XNFilterEvents, &fevent, NULL);
Expand Down

0 comments on commit b905583

Please sign in to comment.