Fixed SDL applications being killed immediately after being backgrounded, because they were trying to draw while minimized.
authorSam Lantinga <slouken@libsdl.org>
Mon, 07 Nov 2011 23:07:00 -0500
changeset 6060 59d398ac031e
parent 6054 effedf4d675c
child 6061 4746757951ac
Fixed SDL applications being killed immediately after being backgrounded, because they were trying to draw while minimized.
src/render/SDL_render.c
src/render/SDL_sysrender.h
src/render/opengles/SDL_render_gles.c
src/render/opengles2/SDL_render_gles2.c
--- a/src/render/SDL_render.c	Mon Nov 07 02:24:52 2011 -0500
+++ b/src/render/SDL_render.c	Mon Nov 07 23:07:00 2011 -0500
@@ -111,6 +111,10 @@
                 viewport.w = renderer->viewport.w;
                 viewport.h = renderer->viewport.h;
                 SDL_RenderSetViewport(renderer, &viewport);
+            } else if (event->window.event == SDL_WINDOWEVENT_MINIMIZED) {
+                renderer->minimized = SDL_TRUE;
+            } else if (event->window.event == SDL_WINDOWEVENT_RESTORED) {
+                renderer->minimized = SDL_FALSE;
             }
         }
     }
@@ -189,6 +193,12 @@
         renderer->magic = &renderer_magic;
         renderer->window = window;
 
+        if (SDL_GetWindowFlags(window) & SDL_WINDOW_MINIMIZED) {
+            renderer->minimized = SDL_TRUE;
+        } else {
+            renderer->minimized = SDL_FALSE;
+        }
+
         SDL_SetWindowData(window, SDL_WINDOWRENDERDATA, renderer);
 
         SDL_RenderSetViewport(renderer, NULL);
@@ -873,6 +883,10 @@
 {
     CHECK_RENDERER_MAGIC(renderer, -1);
 
+    /* Don't draw while we're minimized */
+    if (renderer->minimized) {
+        return 0;
+    }
     return renderer->RenderClear(renderer);
 }
 
@@ -899,6 +913,10 @@
     if (count < 1) {
         return 0;
     }
+    /* Don't draw while we're minimized */
+    if (renderer->minimized) {
+        return 0;
+    }
     return renderer->RenderDrawPoints(renderer, points, count);
 }
 
@@ -927,6 +945,10 @@
     if (count < 2) {
         return 0;
     }
+    /* Don't draw while we're minimized */
+    if (renderer->minimized) {
+        return 0;
+    }
     return renderer->RenderDrawLines(renderer, points, count);
 }
 
@@ -976,6 +998,10 @@
         return 0;
     }
 
+    /* Don't draw while we're minimized */
+    if (renderer->minimized) {
+        return 0;
+    }
     for (i = 0; i < count; ++i) {
         if (SDL_RenderDrawRect(renderer, &rects[i]) < 0) {
             return -1;
@@ -1015,6 +1041,10 @@
     if (count < 1) {
         return 0;
     }
+    /* Don't draw while we're minimized */
+    if (renderer->minimized) {
+        return 0;
+    }
     return renderer->RenderFillRects(renderer, rects, count);
 }
 
@@ -1072,6 +1102,10 @@
         texture = texture->native;
     }
 
+    /* Don't draw while we're minimized */
+    if (renderer->minimized) {
+        return 0;
+    }
     return renderer->RenderCopy(renderer, texture, &real_srcrect,
                                 &real_dstrect);
 }
@@ -1121,6 +1155,10 @@
 {
     CHECK_RENDERER_MAGIC(renderer, );
 
+    /* Don't draw while we're minimized */
+    if (renderer->minimized) {
+        return;
+    }
     renderer->RenderPresent(renderer);
 }
 
--- a/src/render/SDL_sysrender.h	Mon Nov 07 02:24:52 2011 -0500
+++ b/src/render/SDL_sysrender.h	Mon Nov 07 23:07:00 2011 -0500
@@ -99,6 +99,7 @@
 
     /* The window associated with the renderer */
     SDL_Window *window;
+    SDL_bool minimized;
 
     /* The drawable area within the window */
     SDL_Rect viewport;
--- a/src/render/opengles/SDL_render_gles.c	Mon Nov 07 02:24:52 2011 -0500
+++ b/src/render/opengles/SDL_render_gles.c	Mon Nov 07 23:07:00 2011 -0500
@@ -279,6 +279,11 @@
         /* Rebind the context to the window area and update matrices */
         SDL_CurrentContext = NULL;
     }
+
+    if (event->event == SDL_WINDOWEVENT_MINIMIZED) {
+        /* According to Apple documentation, we need to finish drawing NOW! */
+	glFinish();
+    }
 }
 
 static __inline__ int
--- a/src/render/opengles2/SDL_render_gles2.c	Mon Nov 07 02:24:52 2011 -0500
+++ b/src/render/opengles2/SDL_render_gles2.c	Mon Nov 07 23:07:00 2011 -0500
@@ -169,6 +169,11 @@
         /* Rebind the context to the window area */
         SDL_CurrentContext = NULL;
     }
+
+    if (event->event == SDL_WINDOWEVENT_MINIMIZED) {
+        /* According to Apple documentation, we need to finish drawing NOW! */
+	glFinish();
+    }
 }
 
 static int