[PATCH] ui/sdl2: OpenGL window context

Antonio Caggiano posted 1 patch 11 months, 1 week ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20230612083802.2045-1-quic._5Facaggian@quicinc.com
Maintainers: Gerd Hoffmann <kraxel@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>
There is a newer version of this series
ui/sdl2.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
[PATCH] ui/sdl2: OpenGL window context
Posted by Antonio Caggiano 11 months, 1 week ago
When OpenGL is enabled, create only the OpenGL context, ignoring the SDL
renderer as it is unused anyway.

Signed-off-by: Antonio Caggiano <quic_acaggian@quicinc.com>
---
 ui/sdl2.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/ui/sdl2.c b/ui/sdl2.c
index 9d703200bf..0d91b555e3 100644
--- a/ui/sdl2.c
+++ b/ui/sdl2.c
@@ -113,11 +113,11 @@ void sdl2_window_create(struct sdl2_console *scon)
 
         SDL_SetHint(SDL_HINT_RENDER_DRIVER, driver);
         SDL_SetHint(SDL_HINT_RENDER_BATCHING, "1");
-    }
-    scon->real_renderer = SDL_CreateRenderer(scon->real_window, -1, 0);
 
-    if (scon->opengl) {
         scon->winctx = SDL_GL_CreateContext(scon->real_window);
+    } else {
+        /* The SDL renderer is only used by sdl2-2D, when OpenGL is disabled */
+        scon->real_renderer = SDL_CreateRenderer(scon->real_window, -1, 0);
     }
     sdl_update_caption(scon);
 }
@@ -128,10 +128,14 @@ void sdl2_window_destroy(struct sdl2_console *scon)
         return;
     }
 
-    SDL_GL_DeleteContext(scon->winctx);
-    scon->winctx = NULL;
-    SDL_DestroyRenderer(scon->real_renderer);
-    scon->real_renderer = NULL;
+    if (scon->winctx) {
+        SDL_GL_DeleteContext(scon->winctx);
+        scon->winctx = NULL;
+    }
+    if (scon->real_renderer) {
+        SDL_DestroyRenderer(scon->real_renderer);
+        scon->real_renderer = NULL;
+    }
     SDL_DestroyWindow(scon->real_window);
     scon->real_window = NULL;
 }
-- 
2.40.0
Re: [PATCH] ui/sdl2: OpenGL window context
Posted by Marc-André Lureau 11 months, 1 week ago
On Mon, Jun 12, 2023 at 10:39 AM Antonio Caggiano <quic_acaggian@quicinc.com>
wrote:

> When OpenGL is enabled, create only the OpenGL context, ignoring the SDL
> renderer as it is unused anyway.
>
> Signed-off-by: Antonio Caggiano <quic_acaggian@quicinc.com>
>

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>


> ---
>  ui/sdl2.c | 18 +++++++++++-------
>  1 file changed, 11 insertions(+), 7 deletions(-)
>
> diff --git a/ui/sdl2.c b/ui/sdl2.c
> index 9d703200bf..0d91b555e3 100644
> --- a/ui/sdl2.c
> +++ b/ui/sdl2.c
> @@ -113,11 +113,11 @@ void sdl2_window_create(struct sdl2_console *scon)
>
>          SDL_SetHint(SDL_HINT_RENDER_DRIVER, driver);
>          SDL_SetHint(SDL_HINT_RENDER_BATCHING, "1");
> -    }
> -    scon->real_renderer = SDL_CreateRenderer(scon->real_window, -1, 0);
>
> -    if (scon->opengl) {
>          scon->winctx = SDL_GL_CreateContext(scon->real_window);
> +    } else {
> +        /* The SDL renderer is only used by sdl2-2D, when OpenGL is
> disabled */
> +        scon->real_renderer = SDL_CreateRenderer(scon->real_window, -1,
> 0);
>      }
>      sdl_update_caption(scon);
>  }
> @@ -128,10 +128,14 @@ void sdl2_window_destroy(struct sdl2_console *scon)
>          return;
>      }
>
> -    SDL_GL_DeleteContext(scon->winctx);
> -    scon->winctx = NULL;
> -    SDL_DestroyRenderer(scon->real_renderer);
> -    scon->real_renderer = NULL;
> +    if (scon->winctx) {
> +        SDL_GL_DeleteContext(scon->winctx);
> +        scon->winctx = NULL;
> +    }
> +    if (scon->real_renderer) {
> +        SDL_DestroyRenderer(scon->real_renderer);
> +        scon->real_renderer = NULL;
> +    }
>      SDL_DestroyWindow(scon->real_window);
>      scon->real_window = NULL;
>  }
> --
> 2.40.0
>
>
>

-- 
Marc-André Lureau