diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-11-24 13:48:45 +0200 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-11-24 13:48:45 +0200 |
commit | 2fa433ad7c61389b9b950ce4ee2f8d9f0340ff80 (patch) | |
tree | 0a8479358b7a9539b6dd0421f6e678378f973f94 /src/ui | |
parent | b0bcb98681e3076a44ec80cee306d14b7e6df094 (diff) |
Window: Only one draw operation at once
Ensure that a draw is not started if it is already ongoing, especially when using the resize event watcher.
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/window.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/ui/window.c b/src/ui/window.c index 2f6fe430..b8ce413b 100644 --- a/src/ui/window.c +++ b/src/ui/window.c | |||
@@ -68,6 +68,7 @@ static float initialUiScale_ = 1.1f; | |||
68 | #endif | 68 | #endif |
69 | 69 | ||
70 | static iBool isOpenGLRenderer_; | 70 | static iBool isOpenGLRenderer_; |
71 | static iBool isDrawing_; | ||
71 | 72 | ||
72 | iDefineTypeConstructionArgs(Window, | 73 | iDefineTypeConstructionArgs(Window, |
73 | (enum iWindowType type, iRect rect, uint32_t flags), | 74 | (enum iWindowType type, iRect rect, uint32_t flags), |
@@ -244,7 +245,9 @@ static void updateSize_MainWindow_(iMainWindow *d, iBool notifyAlways) { | |||
244 | } | 245 | } |
245 | 246 | ||
246 | void drawWhileResizing_MainWindow(iMainWindow *d, int w, int h) { | 247 | void drawWhileResizing_MainWindow(iMainWindow *d, int w, int h) { |
247 | draw_MainWindow(d); | 248 | if (!isDrawing_) { |
249 | draw_MainWindow(d); | ||
250 | } | ||
248 | } | 251 | } |
249 | 252 | ||
250 | static float pixelRatio_Window_(const iWindow *d) { | 253 | static float pixelRatio_Window_(const iWindow *d) { |
@@ -1183,9 +1186,10 @@ iBool postContextClick_Window(iWindow *d, const SDL_MouseButtonEvent *ev) { | |||
1183 | } | 1186 | } |
1184 | 1187 | ||
1185 | void draw_Window(iWindow *d) { | 1188 | void draw_Window(iWindow *d) { |
1186 | if (SDL_GetWindowFlags(d->win) & SDL_WINDOW_HIDDEN) { | 1189 | if (isDrawing_ || SDL_GetWindowFlags(d->win) & SDL_WINDOW_HIDDEN) { |
1187 | return; | 1190 | return; |
1188 | } | 1191 | } |
1192 | isDrawing_ = iTrue; | ||
1189 | iPaint p; | 1193 | iPaint p; |
1190 | init_Paint(&p); | 1194 | init_Paint(&p); |
1191 | iRoot *root = d->roots[0]; | 1195 | iRoot *root = d->roots[0]; |
@@ -1208,14 +1212,20 @@ void draw_Window(iWindow *d) { | |||
1208 | uiBackgroundSelected_ColorId); | 1212 | uiBackgroundSelected_ColorId); |
1209 | setCurrent_Root(NULL); | 1213 | setCurrent_Root(NULL); |
1210 | SDL_RenderPresent(d->render); | 1214 | SDL_RenderPresent(d->render); |
1215 | isDrawing_ = iFalse; | ||
1211 | } | 1216 | } |
1212 | 1217 | ||
1213 | void draw_MainWindow(iMainWindow *d) { | 1218 | void draw_MainWindow(iMainWindow *d) { |
1219 | if (isDrawing_) { | ||
1220 | /* Already drawing! */ | ||
1221 | return; | ||
1222 | } | ||
1214 | /* TODO: Try to make this a specialization of `draw_Window`? */ | 1223 | /* TODO: Try to make this a specialization of `draw_Window`? */ |
1215 | iWindow *w = as_Window(d); | 1224 | iWindow *w = as_Window(d); |
1216 | if (d->isDrawFrozen) { | 1225 | if (d->isDrawFrozen) { |
1217 | return; | 1226 | return; |
1218 | } | 1227 | } |
1228 | isDrawing_ = iTrue; | ||
1219 | setCurrent_Text(d->base.text); | 1229 | setCurrent_Text(d->base.text); |
1220 | /* Check if root needs resizing. */ { | 1230 | /* Check if root needs resizing. */ { |
1221 | iInt2 renderSize; | 1231 | iInt2 renderSize; |
@@ -1312,6 +1322,7 @@ void draw_MainWindow(iMainWindow *d) { | |||
1312 | } | 1322 | } |
1313 | #endif | 1323 | #endif |
1314 | SDL_RenderPresent(w->render); | 1324 | SDL_RenderPresent(w->render); |
1325 | isDrawing_ = iFalse; | ||
1315 | } | 1326 | } |
1316 | 1327 | ||
1317 | void resize_MainWindow(iMainWindow *d, int w, int h) { | 1328 | void resize_MainWindow(iMainWindow *d, int w, int h) { |