render: Move non-batching flushes to different place. SDL-ryan-batching-renderer
authorRyan C. Gordon <icculus@icculus.org>
Tue, 25 Sep 2018 17:04:47 -0400
branchSDL-ryan-batching-renderer
changeset 1223680367def8b68
parent 12235 19863e13a81a
child 12237 a960bc8317a9
render: Move non-batching flushes to different place.

This lets us batch up a few commands that are all related to the same API
call.
src/render/SDL_render.c
     1.1 --- a/src/render/SDL_render.c	Tue Sep 25 16:17:10 2018 -0400
     1.2 +++ b/src/render/SDL_render.c	Tue Sep 25 17:04:47 2018 -0400
     1.3 @@ -407,7 +407,7 @@
     1.4              }
     1.5          }
     1.6      }
     1.7 -    return retval < 0 ? retval : FlushRenderCommandsIfNotBatching(renderer);
     1.8 +    return retval;
     1.9  }
    1.10  
    1.11  static int
    1.12 @@ -429,7 +429,7 @@
    1.13              renderer->cliprect_queued = SDL_TRUE;
    1.14          }
    1.15      }
    1.16 -    return retval < 0 ? retval : FlushRenderCommandsIfNotBatching(renderer);
    1.17 +    return retval;
    1.18  }
    1.19  
    1.20  static int
    1.21 @@ -458,7 +458,7 @@
    1.22              }
    1.23          }
    1.24      }
    1.25 -    return retval < 0 ? retval : FlushRenderCommandsIfNotBatching(renderer);
    1.26 +    return retval;
    1.27  }
    1.28  
    1.29  static int
    1.30 @@ -475,7 +475,7 @@
    1.31      cmd->data.color.g = renderer->g;
    1.32      cmd->data.color.b = renderer->b;
    1.33      cmd->data.color.a = renderer->a;
    1.34 -    return FlushRenderCommandsIfNotBatching(renderer);
    1.35 +    return 0;
    1.36  }
    1.37  
    1.38  static int
    1.39 @@ -526,7 +526,7 @@
    1.40              cmd->command = SDL_RENDERCMD_NO_OP;
    1.41          }
    1.42      }
    1.43 -    return retval < 0 ? retval : FlushRenderCommandsIfNotBatching(renderer);
    1.44 +    return retval;
    1.45  }
    1.46  
    1.47  static int
    1.48 @@ -540,7 +540,7 @@
    1.49              cmd->command = SDL_RENDERCMD_NO_OP;
    1.50          }
    1.51      }
    1.52 -    return retval < 0 ? retval : FlushRenderCommandsIfNotBatching(renderer);
    1.53 +    return retval;
    1.54  }
    1.55  
    1.56  static int
    1.57 @@ -554,7 +554,7 @@
    1.58              cmd->command = SDL_RENDERCMD_NO_OP;
    1.59          }
    1.60      }
    1.61 -    return retval < 0 ? retval : FlushRenderCommandsIfNotBatching(renderer);
    1.62 +    return retval;
    1.63  }
    1.64  
    1.65  static SDL_RenderCommand *
    1.66 @@ -589,7 +589,7 @@
    1.67              cmd->command = SDL_RENDERCMD_NO_OP;
    1.68          }
    1.69      }
    1.70 -    return retval < 0 ? retval : FlushRenderCommandsIfNotBatching(renderer);
    1.71 +    return retval;
    1.72  }
    1.73  
    1.74  static int
    1.75 @@ -606,7 +606,7 @@
    1.76              cmd->command = SDL_RENDERCMD_NO_OP;
    1.77          }
    1.78      }
    1.79 -    return retval < 0 ? retval : FlushRenderCommandsIfNotBatching(renderer);
    1.80 +    return retval;
    1.81  }
    1.82  
    1.83  
    1.84 @@ -689,6 +689,7 @@
    1.85                          renderer->viewport.w = w;
    1.86                          renderer->viewport.h = h;
    1.87                          QueueCmdSetViewport(renderer);
    1.88 +                        FlushRenderCommandsIfNotBatching(renderer);
    1.89                      }
    1.90                  }
    1.91  
    1.92 @@ -1822,7 +1823,7 @@
    1.93      }
    1.94  
    1.95      /* All set! */
    1.96 -    return 0;
    1.97 +    return FlushRenderCommandsIfNotBatching(renderer);
    1.98  }
    1.99  
   1.100  SDL_Texture *
   1.101 @@ -1994,6 +1995,7 @@
   1.102  int
   1.103  SDL_RenderSetViewport(SDL_Renderer * renderer, const SDL_Rect * rect)
   1.104  {
   1.105 +    int retval;
   1.106      CHECK_RENDERER_MAGIC(renderer, -1);
   1.107  
   1.108      if (rect) {
   1.109 @@ -2008,7 +2010,8 @@
   1.110              return -1;
   1.111          }
   1.112      }
   1.113 -    return QueueCmdSetViewport(renderer);
   1.114 +    retval = QueueCmdSetViewport(renderer);
   1.115 +    return retval < 0 ? retval : FlushRenderCommandsIfNotBatching(renderer);
   1.116  }
   1.117  
   1.118  void
   1.119 @@ -2027,6 +2030,7 @@
   1.120  int
   1.121  SDL_RenderSetClipRect(SDL_Renderer * renderer, const SDL_Rect * rect)
   1.122  {
   1.123 +    int retval;
   1.124      CHECK_RENDERER_MAGIC(renderer, -1)
   1.125  
   1.126      if (rect) {
   1.127 @@ -2039,7 +2043,9 @@
   1.128          renderer->clipping_enabled = SDL_FALSE;
   1.129          SDL_zero(renderer->clip_rect);
   1.130      }
   1.131 -    return QueueCmdSetClipRect(renderer);
   1.132 +
   1.133 +    retval = QueueCmdSetClipRect(renderer);
   1.134 +    return retval < 0 ? retval : FlushRenderCommandsIfNotBatching(renderer);
   1.135  }
   1.136  
   1.137  void
   1.138 @@ -2143,18 +2149,22 @@
   1.139  int
   1.140  SDL_RenderClear(SDL_Renderer * renderer)
   1.141  {
   1.142 +    int retval;
   1.143      CHECK_RENDERER_MAGIC(renderer, -1);
   1.144 -    return QueueCmdClear(renderer);
   1.145 +    retval = QueueCmdClear(renderer);
   1.146 +    return retval < 0 ? retval : FlushRenderCommandsIfNotBatching(renderer);
   1.147  }
   1.148  
   1.149  int
   1.150  SDL_RenderDrawPoint(SDL_Renderer * renderer, int x, int y)
   1.151  {
   1.152      SDL_Point point;
   1.153 +    int retval;
   1.154  
   1.155      point.x = x;
   1.156      point.y = y;
   1.157 -    return SDL_RenderDrawPoints(renderer, &point, 1);
   1.158 +    retval = SDL_RenderDrawPoints(renderer, &point, 1);
   1.159 +    return retval < 0 ? retval : FlushRenderCommandsIfNotBatching(renderer);
   1.160  }
   1.161  
   1.162  static int
   1.163 @@ -2163,7 +2173,7 @@
   1.164  {
   1.165      SDL_FRect *frects;
   1.166      int i;
   1.167 -    int status = -1;
   1.168 +    int retval = -1;
   1.169  
   1.170      frects = SDL_stack_alloc(SDL_FRect, count);
   1.171      if (!frects) {
   1.172 @@ -2176,11 +2186,11 @@
   1.173          frects[i].h = renderer->scale.y;
   1.174      }
   1.175  
   1.176 -    status = QueueCmdFillRects(renderer, frects, count);
   1.177 +    retval = QueueCmdFillRects(renderer, frects, count);
   1.178  
   1.179      SDL_stack_free(frects);
   1.180  
   1.181 -    return status;
   1.182 +    return retval < 0 ? retval : FlushRenderCommandsIfNotBatching(renderer);
   1.183  }
   1.184  
   1.185  int
   1.186 @@ -2189,7 +2199,7 @@
   1.187  {
   1.188      SDL_FPoint *fpoints;
   1.189      int i;
   1.190 -    int status;
   1.191 +    int retval;
   1.192  
   1.193      CHECK_RENDERER_MAGIC(renderer, -1);
   1.194  
   1.195 @@ -2218,11 +2228,11 @@
   1.196          fpoints[i].y = points[i].y * renderer->scale.y;
   1.197      }
   1.198  
   1.199 -    status = QueueCmdDrawPoints(renderer, fpoints, count);
   1.200 +    retval = QueueCmdDrawPoints(renderer, fpoints, count);
   1.201  
   1.202      SDL_stack_free(fpoints);
   1.203  
   1.204 -    return status;
   1.205 +    return retval < 0 ? retval : FlushRenderCommandsIfNotBatching(renderer);
   1.206  }
   1.207  
   1.208  int
   1.209 @@ -2245,7 +2255,7 @@
   1.210      SDL_FRect *frects;
   1.211      SDL_FPoint fpoints[2];
   1.212      int i, nrects = 0;
   1.213 -    int status = 0;
   1.214 +    int retval = 0;
   1.215  
   1.216      frects = SDL_stack_alloc(SDL_FRect, count-1);
   1.217      if (!frects) {
   1.218 @@ -2277,18 +2287,18 @@
   1.219              fpoints[0].y = points[i].y * renderer->scale.y;
   1.220              fpoints[1].x = points[i+1].x * renderer->scale.x;
   1.221              fpoints[1].y = points[i+1].y * renderer->scale.y;
   1.222 -            status += QueueCmdDrawLines(renderer, fpoints, 2);
   1.223 +            retval += QueueCmdDrawLines(renderer, fpoints, 2);
   1.224          }
   1.225      }
   1.226  
   1.227 -    status += QueueCmdFillRects(renderer, frects, nrects);
   1.228 +    retval += QueueCmdFillRects(renderer, frects, nrects);
   1.229  
   1.230      SDL_stack_free(frects);
   1.231  
   1.232 -    if (status < 0) {
   1.233 -        status = -1;
   1.234 +    if (retval < 0) {
   1.235 +        retval = -1;
   1.236      }
   1.237 -    return status;
   1.238 +    return retval < 0 ? retval : FlushRenderCommandsIfNotBatching(renderer);
   1.239  }
   1.240  
   1.241  int
   1.242 @@ -2297,7 +2307,7 @@
   1.243  {
   1.244      SDL_FPoint *fpoints;
   1.245      int i;
   1.246 -    int status;
   1.247 +    int retval;
   1.248  
   1.249      CHECK_RENDERER_MAGIC(renderer, -1);
   1.250  
   1.251 @@ -2326,11 +2336,11 @@
   1.252          fpoints[i].y = points[i].y * renderer->scale.y;
   1.253      }
   1.254  
   1.255 -    status = QueueCmdDrawLines(renderer, fpoints, count);
   1.256 +    retval = QueueCmdDrawLines(renderer, fpoints, count);
   1.257  
   1.258      SDL_stack_free(fpoints);
   1.259  
   1.260 -    return status;
   1.261 +    return retval < 0 ? retval : FlushRenderCommandsIfNotBatching(renderer);
   1.262  }
   1.263  
   1.264  int
   1.265 @@ -2413,7 +2423,7 @@
   1.266  {
   1.267      SDL_FRect *frects;
   1.268      int i;
   1.269 -    int status;
   1.270 +    int retval;
   1.271  
   1.272      CHECK_RENDERER_MAGIC(renderer, -1);
   1.273  
   1.274 @@ -2440,11 +2450,11 @@
   1.275          frects[i].h = rects[i].h * renderer->scale.y;
   1.276      }
   1.277  
   1.278 -    status = QueueCmdFillRects(renderer, frects, count);
   1.279 +    retval = QueueCmdFillRects(renderer, frects, count);
   1.280  
   1.281      SDL_stack_free(frects);
   1.282  
   1.283 -    return status;
   1.284 +    return retval < 0 ? retval : FlushRenderCommandsIfNotBatching(renderer);
   1.285  }
   1.286  
   1.287  int
   1.288 @@ -2454,6 +2464,7 @@
   1.289      SDL_Rect real_srcrect = { 0, 0, 0, 0 };
   1.290      SDL_Rect real_dstrect = { 0, 0, 0, 0 };
   1.291      SDL_FRect frect;
   1.292 +    int retval;
   1.293  
   1.294      CHECK_RENDERER_MAGIC(renderer, -1);
   1.295      CHECK_TEXTURE_MAGIC(texture, -1);
   1.296 @@ -2498,7 +2509,8 @@
   1.297  
   1.298      texture->last_command_generation = renderer->render_command_generation;
   1.299  
   1.300 -    return QueueCmdCopy(renderer, texture, &real_srcrect, &frect);
   1.301 +    retval = QueueCmdCopy(renderer, texture, &real_srcrect, &frect);
   1.302 +    return retval < 0 ? retval : FlushRenderCommandsIfNotBatching(renderer);
   1.303  }
   1.304  
   1.305