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 606059d398ac031e
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
     1.1 --- a/src/render/SDL_render.c	Mon Nov 07 02:24:52 2011 -0500
     1.2 +++ b/src/render/SDL_render.c	Mon Nov 07 23:07:00 2011 -0500
     1.3 @@ -111,6 +111,10 @@
     1.4                  viewport.w = renderer->viewport.w;
     1.5                  viewport.h = renderer->viewport.h;
     1.6                  SDL_RenderSetViewport(renderer, &viewport);
     1.7 +            } else if (event->window.event == SDL_WINDOWEVENT_MINIMIZED) {
     1.8 +                renderer->minimized = SDL_TRUE;
     1.9 +            } else if (event->window.event == SDL_WINDOWEVENT_RESTORED) {
    1.10 +                renderer->minimized = SDL_FALSE;
    1.11              }
    1.12          }
    1.13      }
    1.14 @@ -189,6 +193,12 @@
    1.15          renderer->magic = &renderer_magic;
    1.16          renderer->window = window;
    1.17  
    1.18 +        if (SDL_GetWindowFlags(window) & SDL_WINDOW_MINIMIZED) {
    1.19 +            renderer->minimized = SDL_TRUE;
    1.20 +        } else {
    1.21 +            renderer->minimized = SDL_FALSE;
    1.22 +        }
    1.23 +
    1.24          SDL_SetWindowData(window, SDL_WINDOWRENDERDATA, renderer);
    1.25  
    1.26          SDL_RenderSetViewport(renderer, NULL);
    1.27 @@ -873,6 +883,10 @@
    1.28  {
    1.29      CHECK_RENDERER_MAGIC(renderer, -1);
    1.30  
    1.31 +    /* Don't draw while we're minimized */
    1.32 +    if (renderer->minimized) {
    1.33 +        return 0;
    1.34 +    }
    1.35      return renderer->RenderClear(renderer);
    1.36  }
    1.37  
    1.38 @@ -899,6 +913,10 @@
    1.39      if (count < 1) {
    1.40          return 0;
    1.41      }
    1.42 +    /* Don't draw while we're minimized */
    1.43 +    if (renderer->minimized) {
    1.44 +        return 0;
    1.45 +    }
    1.46      return renderer->RenderDrawPoints(renderer, points, count);
    1.47  }
    1.48  
    1.49 @@ -927,6 +945,10 @@
    1.50      if (count < 2) {
    1.51          return 0;
    1.52      }
    1.53 +    /* Don't draw while we're minimized */
    1.54 +    if (renderer->minimized) {
    1.55 +        return 0;
    1.56 +    }
    1.57      return renderer->RenderDrawLines(renderer, points, count);
    1.58  }
    1.59  
    1.60 @@ -976,6 +998,10 @@
    1.61          return 0;
    1.62      }
    1.63  
    1.64 +    /* Don't draw while we're minimized */
    1.65 +    if (renderer->minimized) {
    1.66 +        return 0;
    1.67 +    }
    1.68      for (i = 0; i < count; ++i) {
    1.69          if (SDL_RenderDrawRect(renderer, &rects[i]) < 0) {
    1.70              return -1;
    1.71 @@ -1015,6 +1041,10 @@
    1.72      if (count < 1) {
    1.73          return 0;
    1.74      }
    1.75 +    /* Don't draw while we're minimized */
    1.76 +    if (renderer->minimized) {
    1.77 +        return 0;
    1.78 +    }
    1.79      return renderer->RenderFillRects(renderer, rects, count);
    1.80  }
    1.81  
    1.82 @@ -1072,6 +1102,10 @@
    1.83          texture = texture->native;
    1.84      }
    1.85  
    1.86 +    /* Don't draw while we're minimized */
    1.87 +    if (renderer->minimized) {
    1.88 +        return 0;
    1.89 +    }
    1.90      return renderer->RenderCopy(renderer, texture, &real_srcrect,
    1.91                                  &real_dstrect);
    1.92  }
    1.93 @@ -1121,6 +1155,10 @@
    1.94  {
    1.95      CHECK_RENDERER_MAGIC(renderer, );
    1.96  
    1.97 +    /* Don't draw while we're minimized */
    1.98 +    if (renderer->minimized) {
    1.99 +        return;
   1.100 +    }
   1.101      renderer->RenderPresent(renderer);
   1.102  }
   1.103  
     2.1 --- a/src/render/SDL_sysrender.h	Mon Nov 07 02:24:52 2011 -0500
     2.2 +++ b/src/render/SDL_sysrender.h	Mon Nov 07 23:07:00 2011 -0500
     2.3 @@ -99,6 +99,7 @@
     2.4  
     2.5      /* The window associated with the renderer */
     2.6      SDL_Window *window;
     2.7 +    SDL_bool minimized;
     2.8  
     2.9      /* The drawable area within the window */
    2.10      SDL_Rect viewport;
     3.1 --- a/src/render/opengles/SDL_render_gles.c	Mon Nov 07 02:24:52 2011 -0500
     3.2 +++ b/src/render/opengles/SDL_render_gles.c	Mon Nov 07 23:07:00 2011 -0500
     3.3 @@ -279,6 +279,11 @@
     3.4          /* Rebind the context to the window area and update matrices */
     3.5          SDL_CurrentContext = NULL;
     3.6      }
     3.7 +
     3.8 +    if (event->event == SDL_WINDOWEVENT_MINIMIZED) {
     3.9 +        /* According to Apple documentation, we need to finish drawing NOW! */
    3.10 +	glFinish();
    3.11 +    }
    3.12  }
    3.13  
    3.14  static __inline__ int
     4.1 --- a/src/render/opengles2/SDL_render_gles2.c	Mon Nov 07 02:24:52 2011 -0500
     4.2 +++ b/src/render/opengles2/SDL_render_gles2.c	Mon Nov 07 23:07:00 2011 -0500
     4.3 @@ -169,6 +169,11 @@
     4.4          /* Rebind the context to the window area */
     4.5          SDL_CurrentContext = NULL;
     4.6      }
     4.7 +
     4.8 +    if (event->event == SDL_WINDOWEVENT_MINIMIZED) {
     4.9 +        /* According to Apple documentation, we need to finish drawing NOW! */
    4.10 +	glFinish();
    4.11 +    }
    4.12  }
    4.13  
    4.14  static int