From 6f39b9641bab7a8ed1185a280df089d3ab509a79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Eric=20Janouch?= Date: Thu, 30 Sep 2021 12:35:43 +0200 Subject: [PATCH] Fix the sdl-imageviewer demo on DefaultDepth 30 Using SDL renderers should make this work reliably with pratically any root window visual. --- example/sdl-imageviewer/sdl-imageviewer.cc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/example/sdl-imageviewer/sdl-imageviewer.cc b/example/sdl-imageviewer/sdl-imageviewer.cc index 6d2b0fec..14721462 100644 --- a/example/sdl-imageviewer/sdl-imageviewer.cc +++ b/example/sdl-imageviewer/sdl-imageviewer.cc @@ -79,6 +79,7 @@ isn't otherwise doing anything. // ---------------- #include +#include #include // -------- @@ -229,6 +230,19 @@ bool g_load_via_sdl_image = false; bool // draw(SDL_Window* window) { SDL_Surface* ws = SDL_GetWindowSurface(window); + if (!ws) { + // This resolves DefaultDepth 30 X.org, in a slightly inefficient manner. + SDL_Renderer* r = SDL_CreateRenderer(window, -1, 0); + SDL_RenderClear(r); + if (g_image) { + SDL_Texture* texture = SDL_CreateTextureFromSurface(r, g_image); + SDL_RenderCopy(r, texture, NULL, &g_image->clip_rect); + SDL_DestroyTexture(texture); + } + SDL_RenderPresent(r); + SDL_DestroyRenderer(r); + return true; + } SDL_FillRect(ws, NULL, SDL_MapRGB(ws->format, 0x00, 0x00, 0x00)); if (g_image) { SDL_BlitSurface(g_image, NULL, ws, NULL);