Changed the concept of a render clip rect to a render viewport.
authorSam Lantinga <slouken@libsdl.org>
Tue, 15 Feb 2011 13:59:59 -0800
changeset 52971800dc39b74c
parent 5296 48067bfc300c
child 5298 7b1cac2c2230
Changed the concept of a render clip rect to a render viewport.
The render viewport is automatically re-centered when the window changes size, so applications that don't care will not have to handle recalculating their rendering coordinates.

Fixed API for drawing and filling multiple rectangles - the parameter should be an array of rects, not an array of pointers to rects.

Fixed API for updating window rects for consistency with other APIs - the order is pointer to array followed by count in array.
include/SDL_render.h
include/SDL_surface.h
include/SDL_video.h
src/SDL_compat.c
src/render/SDL_render.c
src/render/SDL_sysrender.h
src/render/direct3d/SDL_render_d3d.c
src/render/opengl/SDL_render_gl.c
src/render/opengles/SDL_render_gles.c
src/render/opengles2/SDL_render_gles2.c
src/render/software/SDL_blendfillrect.c
src/render/software/SDL_blendfillrect.h
src/render/software/SDL_render_sw.c
src/video/SDL_fillrect.c
src/video/SDL_sysvideo.h
src/video/SDL_video.c
src/video/dummy/SDL_nullframebuffer.c
src/video/dummy/SDL_nullframebuffer_c.h
src/video/nds/SDL_ndsvideo.c
src/video/windows/SDL_windowsframebuffer.c
src/video/windows/SDL_windowsframebuffer.h
src/video/x11/SDL_x11framebuffer.c
src/video/x11/SDL_x11framebuffer.h
test/testdraw2.c
test/testintersections.c
test/testscale.c
test/testsprite2.c
     1.1 --- a/include/SDL_render.h	Mon Feb 14 11:50:18 2011 -0600
     1.2 +++ b/include/SDL_render.h	Tue Feb 15 13:59:59 2011 -0800
     1.3 @@ -364,16 +364,23 @@
     1.4  extern DECLSPEC void SDLCALL SDL_UnlockTexture(SDL_Texture * texture);
     1.5  
     1.6  /**
     1.7 - *  \brief Set the clipping rectangle for rendering on the current target
     1.8 + *  \brief Set the drawing area for rendering on the current target.
     1.9   *
    1.10 - *  \param rect The rectangle to clip rendering to, or NULL to disable clipping.
    1.11 + *  \param rect The rectangle representing the drawing area, or NULL to set the viewport to the entire target.
    1.12   *
    1.13 - *  The contents of the window are not defined after calling
    1.14 - *  SDL_RenderPresent(), so you should clear the clip rectangle and draw
    1.15 - *  over the entire window each frame.
    1.16 + *  The x,y of the viewport rect represents the origin for rendering.
    1.17 + *
    1.18 + *  \note When the window is resized, the current viewport is automatically
    1.19 + *        centered within the new window size.
    1.20   */
    1.21 -extern DECLSPEC void SDLCALL SDL_RenderSetClipRect(SDL_Renderer * renderer,
    1.22 -                                                   const SDL_Rect * rect);
    1.23 +extern DECLSPEC int SDLCALL SDL_RenderSetViewport(SDL_Renderer * renderer,
    1.24 +                                                  const SDL_Rect * rect);
    1.25 +
    1.26 +/**
    1.27 + *  \brief Get the drawing area for the current target.
    1.28 + */
    1.29 +extern DECLSPEC void SDLCALL SDL_RenderGetViewport(SDL_Renderer * renderer,
    1.30 +                                                   SDL_Rect * rect);
    1.31  
    1.32  /**
    1.33   *  \brief Set the color used for drawing operations (Fill and Line).
    1.34 @@ -434,6 +441,8 @@
    1.35  
    1.36  /**
    1.37   *  \brief Clear the current rendering target with the drawing color
    1.38 + *
    1.39 + *  This function clears the entire rendering target, ignoring the viewport.
    1.40   */
    1.41  extern DECLSPEC int SDLCALL SDL_RenderClear(SDL_Renderer * renderer);
    1.42  
    1.43 @@ -504,7 +513,7 @@
    1.44   *  \return 0 on success, or -1 on error
    1.45   */
    1.46  extern DECLSPEC int SDLCALL SDL_RenderDrawRects(SDL_Renderer * renderer,
    1.47 -                                                const SDL_Rect ** rects,
    1.48 +                                                const SDL_Rect * rects,
    1.49                                                  int count);
    1.50  
    1.51  /**
    1.52 @@ -527,7 +536,7 @@
    1.53   *  \return 0 on success, or -1 on error
    1.54   */
    1.55  extern DECLSPEC int SDLCALL SDL_RenderFillRects(SDL_Renderer * renderer,
    1.56 -                                                const SDL_Rect ** rect,
    1.57 +                                                const SDL_Rect * rect,
    1.58                                                  int count);
    1.59  
    1.60  /**
     2.1 --- a/include/SDL_surface.h	Mon Feb 14 11:50:18 2011 -0600
     2.2 +++ b/include/SDL_surface.h	Tue Feb 15 13:59:59 2011 -0800
     2.3 @@ -374,7 +374,7 @@
     2.4  extern DECLSPEC int SDLCALL SDL_FillRect
     2.5      (SDL_Surface * dst, const SDL_Rect * rect, Uint32 color);
     2.6  extern DECLSPEC int SDLCALL SDL_FillRects
     2.7 -    (SDL_Surface * dst, const SDL_Rect ** rects, int count, Uint32 color);
     2.8 +    (SDL_Surface * dst, const SDL_Rect * rects, int count, Uint32 color);
     2.9  
    2.10  /**
    2.11   *  Performs a fast blit from the source surface to the destination surface.
     3.1 --- a/include/SDL_video.h	Mon Feb 14 11:50:18 2011 -0600
     3.2 +++ b/include/SDL_video.h	Tue Feb 15 13:59:59 2011 -0800
     3.3 @@ -581,8 +581,8 @@
     3.4   *  \sa SDL_UpdateWindowSurfaceRect()
     3.5   */
     3.6  extern DECLSPEC int SDLCALL SDL_UpdateWindowSurfaceRects(SDL_Window * window,
     3.7 -                                                         int numrects,
     3.8 -                                                         SDL_Rect * rects);
     3.9 +                                                         SDL_Rect * rects,
    3.10 +                                                         int numrects);
    3.11  
    3.12  /**
    3.13   *  \brief Set a window's input grab mode.
     4.1 --- a/src/SDL_compat.c	Mon Feb 14 11:50:18 2011 -0600
     4.2 +++ b/src/SDL_compat.c	Tue Feb 15 13:59:59 2011 -0800
     4.3 @@ -785,10 +785,10 @@
     4.4                  stackrect->w = rect->w;
     4.5                  stackrect->h = rect->h;
     4.6              }
     4.7 -            SDL_UpdateWindowSurfaceRects(SDL_VideoWindow, numrects, stackrects);
     4.8 +            SDL_UpdateWindowSurfaceRects(SDL_VideoWindow, stackrects, numrects);
     4.9              SDL_stack_free(stackrects);
    4.10          } else {
    4.11 -            SDL_UpdateWindowSurfaceRects(SDL_VideoWindow, numrects, rects);
    4.12 +            SDL_UpdateWindowSurfaceRects(SDL_VideoWindow, rects, numrects);
    4.13          }
    4.14      }
    4.15  }
     5.1 --- a/src/render/SDL_render.c	Mon Feb 14 11:50:18 2011 -0600
     5.2 +++ b/src/render/SDL_render.c	Tue Feb 15 13:59:59 2011 -0800
     5.3 @@ -89,10 +89,25 @@
     5.4  {
     5.5      SDL_Renderer *renderer = (SDL_Renderer *)userdata;
     5.6  
     5.7 -    if (event->type == SDL_WINDOWEVENT && renderer->WindowEvent) {
     5.8 +    if (event->type == SDL_WINDOWEVENT) {
     5.9          SDL_Window *window = SDL_GetWindowFromID(event->window.windowID);
    5.10          if (window == renderer->window) {
    5.11 -            renderer->WindowEvent(renderer, &event->window);
    5.12 +            if (renderer->WindowEvent) {
    5.13 +                renderer->WindowEvent(renderer, &event->window);
    5.14 +            }
    5.15 +
    5.16 +            if (event->window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
    5.17 +                /* Try to keep the previous viewport centered */
    5.18 +                int w, h;
    5.19 +                SDL_Rect viewport;
    5.20 +
    5.21 +                SDL_GetWindowSize(window, &w, &h);
    5.22 +                viewport.x = (w - renderer->viewport.w) / 2;
    5.23 +                viewport.y = (h - renderer->viewport.h) / 2;
    5.24 +                viewport.w = renderer->viewport.w;
    5.25 +                viewport.h = renderer->viewport.h;
    5.26 +                SDL_RenderSetViewport(renderer, &viewport);
    5.27 +            }
    5.28          }
    5.29      }
    5.30      return 0;
    5.31 @@ -160,6 +175,8 @@
    5.32          renderer->magic = &renderer_magic;
    5.33          renderer->window = window;
    5.34  
    5.35 +        SDL_RenderSetViewport(renderer, NULL);
    5.36 +
    5.37          SDL_AddEventWatch(SDL_RendererEventWatch, renderer);
    5.38  
    5.39          SDL_LogInfo(SDL_LOG_CATEGORY_RENDER,
    5.40 @@ -172,7 +189,16 @@
    5.41  SDL_CreateSoftwareRenderer(SDL_Surface * surface)
    5.42  {
    5.43  #if !SDL_RENDER_DISABLED
    5.44 -    return SW_CreateRendererForSurface(surface);
    5.45 +    SDL_Renderer *renderer;
    5.46 +
    5.47 +    renderer = SW_CreateRendererForSurface(surface);
    5.48 +
    5.49 +    if (renderer) {
    5.50 +        renderer->magic = &renderer_magic;
    5.51 +
    5.52 +        SDL_RenderSetViewport(renderer, NULL);
    5.53 +    }
    5.54 +    return renderer;
    5.55  #else
    5.56      SDL_SetError("SDL not built with rendering support");
    5.57      return NULL;
    5.58 @@ -342,12 +368,13 @@
    5.59              SDL_UpdateTexture(texture, NULL, surface->pixels, surface->pitch);
    5.60          }
    5.61      } else {
    5.62 -        SDL_PixelFormat dst_fmt;
    5.63 +        SDL_PixelFormat *dst_fmt;
    5.64          SDL_Surface *temp = NULL;
    5.65  
    5.66          /* Set up a destination surface for the texture update */
    5.67 -        SDL_InitFormat(&dst_fmt, format);
    5.68 -        temp = SDL_ConvertSurface(surface, &dst_fmt, 0);
    5.69 +        dst_fmt = SDL_AllocFormat(format);
    5.70 +        temp = SDL_ConvertSurface(surface, dst_fmt, 0);
    5.71 +        SDL_FreeFormat(dst_fmt);
    5.72          if (temp) {
    5.73              SDL_UpdateTexture(texture, NULL, temp->pixels, temp->pitch);
    5.74              SDL_FreeSurface(temp);
    5.75 @@ -733,12 +760,34 @@
    5.76      }
    5.77  }
    5.78  
    5.79 +int
    5.80 +SDL_RenderSetViewport(SDL_Renderer * renderer, const SDL_Rect * rect)
    5.81 +{
    5.82 +    CHECK_RENDERER_MAGIC(renderer, -1);
    5.83 +
    5.84 +    if (rect) {
    5.85 +        renderer->viewport = *rect;
    5.86 +    } else {
    5.87 +        renderer->viewport.x = 0;
    5.88 +        renderer->viewport.y = 0;
    5.89 +        if (renderer->window) {
    5.90 +            SDL_GetWindowSize(renderer->window,
    5.91 +                              &renderer->viewport.w, &renderer->viewport.h);
    5.92 +        } else {
    5.93 +            /* This will be filled in by UpdateViewport() */
    5.94 +            renderer->viewport.w = 0;
    5.95 +            renderer->viewport.h = 0;
    5.96 +        }
    5.97 +    }
    5.98 +    return renderer->UpdateViewport(renderer);
    5.99 +}
   5.100 +
   5.101  void
   5.102 -SDL_RenderSetClipRect(SDL_Renderer * renderer, const SDL_Rect * rect)
   5.103 +SDL_RenderGetViewport(SDL_Renderer * renderer, SDL_Rect * rect)
   5.104  {
   5.105      CHECK_RENDERER_MAGIC(renderer, );
   5.106  
   5.107 -    renderer->SetClipRect(renderer, rect);
   5.108 +    *rect = renderer->viewport;
   5.109  }
   5.110  
   5.111  int
   5.112 @@ -884,7 +933,8 @@
   5.113  
   5.114          full_rect.x = 0;
   5.115          full_rect.y = 0;
   5.116 -        SDL_GetWindowSize(window, &full_rect.w, &full_rect.h);
   5.117 +        full_rect.w = renderer->viewport.w;
   5.118 +        full_rect.h = renderer->viewport.h;
   5.119          rect = &full_rect;
   5.120      }
   5.121  
   5.122 @@ -903,7 +953,7 @@
   5.123  
   5.124  int
   5.125  SDL_RenderDrawRects(SDL_Renderer * renderer,
   5.126 -                    const SDL_Rect ** rects, int count)
   5.127 +                    const SDL_Rect * rects, int count)
   5.128  {
   5.129      int i;
   5.130  
   5.131 @@ -917,9 +967,8 @@
   5.132          return 0;
   5.133      }
   5.134  
   5.135 -    /* Check for NULL rect, which means fill entire window */
   5.136      for (i = 0; i < count; ++i) {
   5.137 -        if (SDL_RenderDrawRect(renderer, rects[i]) < 0) {
   5.138 +        if (SDL_RenderDrawRect(renderer, &rects[i]) < 0) {
   5.139              return -1;
   5.140          }
   5.141      }
   5.142 @@ -929,15 +978,13 @@
   5.143  int
   5.144  SDL_RenderFillRect(SDL_Renderer * renderer, const SDL_Rect * rect)
   5.145  {
   5.146 -    return SDL_RenderFillRects(renderer, &rect, 1);
   5.147 +    return SDL_RenderFillRects(renderer, rect, 1);
   5.148  }
   5.149  
   5.150  int
   5.151  SDL_RenderFillRects(SDL_Renderer * renderer,
   5.152 -                    const SDL_Rect ** rects, int count)
   5.153 +                    const SDL_Rect * rects, int count)
   5.154  {
   5.155 -    int i;
   5.156 -
   5.157      CHECK_RENDERER_MAGIC(renderer, -1);
   5.158  
   5.159      if (!rects) {
   5.160 @@ -947,21 +994,6 @@
   5.161      if (count < 1) {
   5.162          return 0;
   5.163      }
   5.164 -
   5.165 -    /* Check for NULL rect, which means fill entire window */
   5.166 -    for (i = 0; i < count; ++i) {
   5.167 -        if (rects[i] == NULL) {
   5.168 -            SDL_Window *window = renderer->window;
   5.169 -            SDL_Rect full_rect;
   5.170 -            const SDL_Rect *rect;
   5.171 -
   5.172 -            full_rect.x = 0;
   5.173 -            full_rect.y = 0;
   5.174 -            SDL_GetWindowSize(window, &full_rect.w, &full_rect.h);
   5.175 -            rect = &full_rect;
   5.176 -            return renderer->RenderFillRects(renderer, &rect, 1);
   5.177 -        }
   5.178 -    }
   5.179      return renderer->RenderFillRects(renderer, rects, count);
   5.180  }
   5.181  
   5.182 @@ -994,7 +1026,8 @@
   5.183  
   5.184      real_dstrect.x = 0;
   5.185      real_dstrect.y = 0;
   5.186 -    SDL_GetWindowSize(window, &real_dstrect.w, &real_dstrect.h);
   5.187 +    real_dstrect.w = renderer->viewport.w;
   5.188 +    real_dstrect.h = renderer->viewport.h;
   5.189      if (dstrect) {
   5.190          if (!SDL_IntersectRect(dstrect, &real_dstrect, &real_dstrect)) {
   5.191              return 0;
   5.192 @@ -1043,7 +1076,8 @@
   5.193  
   5.194      real_rect.x = 0;
   5.195      real_rect.y = 0;
   5.196 -    SDL_GetWindowSize(window, &real_rect.w, &real_rect.h);
   5.197 +    real_rect.w = renderer->viewport.w;
   5.198 +    real_rect.h = renderer->viewport.h;
   5.199      if (rect) {
   5.200          if (!SDL_IntersectRect(rect, &real_rect, &real_rect)) {
   5.201              return 0;
     6.1 --- a/src/render/SDL_sysrender.h	Mon Feb 14 11:50:18 2011 -0600
     6.2 +++ b/src/render/SDL_sysrender.h	Tue Feb 15 13:59:59 2011 -0800
     6.3 @@ -78,13 +78,13 @@
     6.4      int (*LockTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
     6.5                          const SDL_Rect * rect, void **pixels, int *pitch);
     6.6      void (*UnlockTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
     6.7 -    void (*SetClipRect) (SDL_Renderer * renderer, const SDL_Rect *rect);
     6.8 +    int (*UpdateViewport) (SDL_Renderer * renderer);
     6.9      int (*RenderClear) (SDL_Renderer * renderer);
    6.10      int (*RenderDrawPoints) (SDL_Renderer * renderer, const SDL_Point * points,
    6.11                               int count);
    6.12      int (*RenderDrawLines) (SDL_Renderer * renderer, const SDL_Point * points,
    6.13                              int count);
    6.14 -    int (*RenderFillRects) (SDL_Renderer * renderer, const SDL_Rect ** rects,
    6.15 +    int (*RenderFillRects) (SDL_Renderer * renderer, const SDL_Rect * rects,
    6.16                              int count);
    6.17      int (*RenderCopy) (SDL_Renderer * renderer, SDL_Texture * texture,
    6.18                         const SDL_Rect * srcrect, const SDL_Rect * dstrect);
    6.19 @@ -101,6 +101,9 @@
    6.20      /* The window associated with the renderer */
    6.21      SDL_Window *window;
    6.22  
    6.23 +    /* The drawable area within the window */
    6.24 +    SDL_Rect viewport;
    6.25 +
    6.26      /* The list of textures */
    6.27      SDL_Texture *textures;
    6.28  
     7.1 --- a/src/render/direct3d/SDL_render_d3d.c	Mon Feb 14 11:50:18 2011 -0600
     7.2 +++ b/src/render/direct3d/SDL_render_d3d.c	Tue Feb 15 13:59:59 2011 -0800
     7.3 @@ -90,6 +90,8 @@
     7.4  /* Direct3D renderer implementation */
     7.5  
     7.6  static SDL_Renderer *D3D_CreateRenderer(SDL_Window * window, Uint32 flags);
     7.7 +static void D3D_WindowEvent(SDL_Renderer * renderer,
     7.8 +                            const SDL_WindowEvent *event);
     7.9  static int D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
    7.10  static int D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
    7.11                               const SDL_Rect * rect, const void *pixels,
    7.12 @@ -97,13 +99,14 @@
    7.13  static int D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
    7.14                             const SDL_Rect * rect, void **pixels, int *pitch);
    7.15  static void D3D_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
    7.16 -static void D3D_SetClipRect(SDL_Renderer * renderer, const SDL_Rect * rect);
    7.17 +static int D3D_UpdateViewport(SDL_Renderer * renderer);
    7.18 +static int D3D_RenderClear(SDL_Renderer * renderer);
    7.19  static int D3D_RenderDrawPoints(SDL_Renderer * renderer,
    7.20                                  const SDL_Point * points, int count);
    7.21  static int D3D_RenderDrawLines(SDL_Renderer * renderer,
    7.22                                 const SDL_Point * points, int count);
    7.23  static int D3D_RenderFillRects(SDL_Renderer * renderer,
    7.24 -                               const SDL_Rect ** rects, int count);
    7.25 +                               const SDL_Rect * rects, int count);
    7.26  static int D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
    7.27                            const SDL_Rect * srcrect, const SDL_Rect * dstrect);
    7.28  static int D3D_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
    7.29 @@ -132,6 +135,7 @@
    7.30      IDirect3DDevice9 *device;
    7.31      UINT adapter;
    7.32      D3DPRESENT_PARAMETERS pparams;
    7.33 +    SDL_bool updateSize;
    7.34      SDL_bool beginScene;
    7.35  } D3D_RenderData;
    7.36  
    7.37 @@ -143,7 +147,6 @@
    7.38  typedef struct
    7.39  {
    7.40      float x, y, z;
    7.41 -    float rhw;
    7.42      DWORD color;
    7.43      float u, v;
    7.44  } Vertex;
    7.45 @@ -257,6 +260,74 @@
    7.46      }
    7.47  }
    7.48  
    7.49 +static int
    7.50 +D3D_Reset(SDL_Renderer * renderer)
    7.51 +{
    7.52 +    D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
    7.53 +    HRESULT result;
    7.54 +
    7.55 +    result = IDirect3DDevice9_Reset(data->device, &data->pparams);
    7.56 +    if (FAILED(result)) {
    7.57 +        if (result == D3DERR_DEVICELOST) {
    7.58 +            /* Don't worry about it, we'll reset later... */
    7.59 +            return 0;
    7.60 +        } else {
    7.61 +            D3D_SetError("Reset()", result);
    7.62 +            return -1;
    7.63 +        }
    7.64 +    }
    7.65 +    IDirect3DDevice9_SetVertexShader(data->device, NULL);
    7.66 +    IDirect3DDevice9_SetFVF(data->device,
    7.67 +                            D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1);
    7.68 +    IDirect3DDevice9_SetRenderState(data->device, D3DRS_CULLMODE,
    7.69 +                                    D3DCULL_NONE);
    7.70 +    IDirect3DDevice9_SetRenderState(data->device, D3DRS_LIGHTING, FALSE);
    7.71 +    return 0;
    7.72 +}
    7.73 +
    7.74 +static int
    7.75 +D3D_ActivateRenderer(SDL_Renderer * renderer)
    7.76 +{
    7.77 +    D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
    7.78 +    HRESULT result;
    7.79 +
    7.80 +    if (data->updateSize) {
    7.81 +        SDL_Window *window = renderer->window;
    7.82 +        int w, h;
    7.83 +
    7.84 +        SDL_GetWindowSize(window, &w, &h);
    7.85 +        data->pparams.BackBufferWidth = w;
    7.86 +        data->pparams.BackBufferHeight = h;
    7.87 +        if (SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN) {
    7.88 +            data->pparams.BackBufferFormat =
    7.89 +                PixelFormatToD3DFMT(SDL_GetWindowPixelFormat(window));
    7.90 +        } else {
    7.91 +            data->pparams.BackBufferFormat = D3DFMT_UNKNOWN;
    7.92 +        }
    7.93 +        if (D3D_Reset(renderer) < 0) {
    7.94 +            return -1;
    7.95 +        }
    7.96 +        D3D_UpdateViewport(renderer);
    7.97 +
    7.98 +        data->updateSize = SDL_FALSE;
    7.99 +    }
   7.100 +    if (data->beginScene) {
   7.101 +        result = IDirect3DDevice9_BeginScene(data->device);
   7.102 +        if (result == D3DERR_DEVICELOST) {
   7.103 +            if (D3D_Reset(renderer) < 0) {
   7.104 +                return -1;
   7.105 +            }
   7.106 +            result = IDirect3DDevice9_BeginScene(data->device);
   7.107 +        }
   7.108 +        if (FAILED(result)) {
   7.109 +            D3D_SetError("BeginScene()", result);
   7.110 +            return -1;
   7.111 +        }
   7.112 +        data->beginScene = SDL_FALSE;
   7.113 +    }
   7.114 +    return 0;
   7.115 +}
   7.116 +
   7.117  SDL_Renderer *
   7.118  D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
   7.119  {
   7.120 @@ -270,6 +341,7 @@
   7.121      Uint32 window_flags;
   7.122      int w, h;
   7.123      SDL_DisplayMode fullscreen_mode;
   7.124 +    D3DMATRIX matrix;
   7.125  
   7.126      renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
   7.127      if (!renderer) {
   7.128 @@ -306,11 +378,13 @@
   7.129          return NULL;
   7.130      }
   7.131  
   7.132 +    renderer->WindowEvent = D3D_WindowEvent;
   7.133      renderer->CreateTexture = D3D_CreateTexture;
   7.134      renderer->UpdateTexture = D3D_UpdateTexture;
   7.135      renderer->LockTexture = D3D_LockTexture;
   7.136      renderer->UnlockTexture = D3D_UnlockTexture;
   7.137 -    renderer->SetClipRect = D3D_SetClipRect;
   7.138 +    renderer->UpdateViewport = D3D_UpdateViewport;
   7.139 +    renderer->RenderClear = D3D_RenderClear;
   7.140      renderer->RenderDrawPoints = D3D_RenderDrawPoints;
   7.141      renderer->RenderDrawLines = D3D_RenderDrawLines;
   7.142      renderer->RenderFillRects = D3D_RenderFillRects;
   7.143 @@ -405,7 +479,7 @@
   7.144      /* Set up parameters for rendering */
   7.145      IDirect3DDevice9_SetVertexShader(data->device, NULL);
   7.146      IDirect3DDevice9_SetFVF(data->device,
   7.147 -                            D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1);
   7.148 +                            D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1);
   7.149      IDirect3DDevice9_SetRenderState(data->device, D3DRS_ZENABLE, D3DZB_FALSE);
   7.150      IDirect3DDevice9_SetRenderState(data->device, D3DRS_CULLMODE,
   7.151                                      D3DCULL_NONE);
   7.152 @@ -430,55 +504,39 @@
   7.153      IDirect3DDevice9_SetTextureStageState(data->device, 1, D3DTSS_ALPHAOP,
   7.154                                            D3DTOP_DISABLE);
   7.155  
   7.156 +    /* Set an identity world and view matrix */
   7.157 +    matrix.m[0][0] = 1.0f;
   7.158 +    matrix.m[0][1] = 0.0f;
   7.159 +    matrix.m[0][2] = 0.0f;
   7.160 +    matrix.m[0][3] = 0.0f;
   7.161 +    matrix.m[1][0] = 0.0f;
   7.162 +    matrix.m[1][1] = 1.0f;
   7.163 +    matrix.m[1][2] = 0.0f;
   7.164 +    matrix.m[1][3] = 0.0f;
   7.165 +    matrix.m[2][0] = 0.0f;
   7.166 +    matrix.m[2][1] = 0.0f;
   7.167 +    matrix.m[2][2] = 1.0f;
   7.168 +    matrix.m[2][3] = 0.0f;
   7.169 +    matrix.m[3][0] = 0.0f;
   7.170 +    matrix.m[3][1] = 0.0f;
   7.171 +    matrix.m[3][2] = 0.0f;
   7.172 +    matrix.m[3][3] = 1.0f;
   7.173 +    IDirect3DDevice9_SetTransform(data->device, D3DTS_WORLD, &matrix);
   7.174 +    IDirect3DDevice9_SetTransform(data->device, D3DTS_VIEW, &matrix);
   7.175 +
   7.176      return renderer;
   7.177  }
   7.178  
   7.179 -static int
   7.180 -D3D_Reset(SDL_Renderer * renderer)
   7.181 +static void
   7.182 +D3D_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
   7.183  {
   7.184      D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
   7.185 -    HRESULT result;
   7.186  
   7.187 -    result = IDirect3DDevice9_Reset(data->device, &data->pparams);
   7.188 -    if (FAILED(result)) {
   7.189 -        if (result == D3DERR_DEVICELOST) {
   7.190 -            /* Don't worry about it, we'll reset later... */
   7.191 -            return 0;
   7.192 -        } else {
   7.193 -            D3D_SetError("Reset()", result);
   7.194 -            return -1;
   7.195 -        }
   7.196 +    if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED) {
   7.197 +        data->updateSize = SDL_TRUE;
   7.198      }
   7.199 -    IDirect3DDevice9_SetVertexShader(data->device, NULL);
   7.200 -    IDirect3DDevice9_SetFVF(data->device,
   7.201 -                            D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1);
   7.202 -    IDirect3DDevice9_SetRenderState(data->device, D3DRS_CULLMODE,
   7.203 -                                    D3DCULL_NONE);
   7.204 -    IDirect3DDevice9_SetRenderState(data->device, D3DRS_LIGHTING, FALSE);
   7.205 -    return 0;
   7.206  }
   7.207  
   7.208 -/* FIXME: This needs to be called... when? */
   7.209 -#if 0
   7.210 -static int
   7.211 -D3D_DisplayModeChanged(SDL_Renderer * renderer)
   7.212 -{
   7.213 -    D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
   7.214 -    SDL_Window *window = renderer->window;
   7.215 -    SDL_VideoDisplay *display = window->display;
   7.216 -
   7.217 -    data->pparams.BackBufferWidth = window->w;
   7.218 -    data->pparams.BackBufferHeight = window->h;
   7.219 -    if (window->flags & SDL_WINDOW_FULLSCREEN) {
   7.220 -        data->pparams.BackBufferFormat =
   7.221 -            PixelFormatToD3DFMT(window->fullscreen_mode.format);
   7.222 -    } else {
   7.223 -        data->pparams.BackBufferFormat = D3DFMT_UNKNOWN;
   7.224 -    }
   7.225 -    return D3D_Reset(renderer);
   7.226 -}
   7.227 -#endif
   7.228 -
   7.229  static int
   7.230  D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
   7.231  {
   7.232 @@ -604,25 +662,83 @@
   7.233      IDirect3DTexture9_UnlockRect(data->texture, 0);
   7.234  }
   7.235  
   7.236 -static void
   7.237 -D3D_SetClipRect(SDL_Renderer * renderer, const SDL_Rect * rect)
   7.238 +static int
   7.239 +D3D_UpdateViewport(SDL_Renderer * renderer)
   7.240  {
   7.241      D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
   7.242 +    D3DVIEWPORT9 viewport;
   7.243 +    D3DMATRIX matrix;
   7.244  
   7.245 -    if (rect) {
   7.246 -        RECT d3drect;
   7.247 +    /* Set the viewport */
   7.248 +    viewport.X = renderer->viewport.x;
   7.249 +    viewport.Y = renderer->viewport.y;
   7.250 +    viewport.Width = renderer->viewport.w;
   7.251 +    viewport.Height = renderer->viewport.h;
   7.252 +    viewport.MinZ = 0.0f;
   7.253 +    viewport.MaxZ = 1.0f;
   7.254 +    IDirect3DDevice9_SetViewport(data->device, &viewport);
   7.255  
   7.256 -        d3drect.left = rect->x;
   7.257 -        d3drect.right = rect->x + rect->w;
   7.258 -        d3drect.top = rect->y;
   7.259 -        d3drect.bottom = rect->y + rect->h;
   7.260 -        IDirect3DDevice9_SetScissorRect(data->device, &d3drect);
   7.261 -        IDirect3DDevice9_SetRenderState(data->device, D3DRS_SCISSORTESTENABLE,
   7.262 -                                        TRUE);
   7.263 -    } else {
   7.264 -        IDirect3DDevice9_SetRenderState(data->device, D3DRS_SCISSORTESTENABLE,
   7.265 -                                        FALSE);
   7.266 +    /* Set an orthographic projection matrix */
   7.267 +    matrix.m[0][0] = 2.0f / renderer->viewport.w;
   7.268 +    matrix.m[0][1] = 0.0f;
   7.269 +    matrix.m[0][2] = 0.0f;
   7.270 +    matrix.m[0][3] = 0.0f;
   7.271 +    matrix.m[1][0] = 0.0f;
   7.272 +    matrix.m[1][1] = -2.0f / renderer->viewport.h;
   7.273 +    matrix.m[1][2] = 0.0f;
   7.274 +    matrix.m[1][3] = 0.0f;
   7.275 +    matrix.m[2][0] = 0.0f;
   7.276 +    matrix.m[2][1] = 0.0f;
   7.277 +    matrix.m[2][2] = 1.0f;
   7.278 +    matrix.m[2][3] = 0.0f;
   7.279 +    matrix.m[3][0] = -1.0f;
   7.280 +    matrix.m[3][1] = 1.0f;
   7.281 +    matrix.m[3][2] = 0.0f;
   7.282 +    matrix.m[3][3] = 1.0f;
   7.283 +    IDirect3DDevice9_SetTransform(data->device, D3DTS_PROJECTION, &matrix);
   7.284 +
   7.285 +    return 0;
   7.286 +}
   7.287 +
   7.288 +static int
   7.289 +D3D_RenderClear(SDL_Renderer * renderer)
   7.290 +{
   7.291 +    D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
   7.292 +    D3DVIEWPORT9 viewport;
   7.293 +    DWORD color;
   7.294 +    HRESULT result;
   7.295 +
   7.296 +    if (D3D_ActivateRenderer(renderer) < 0) {
   7.297 +        return -1;
   7.298      }
   7.299 +
   7.300 +    /* Clear is defined to clear the entire render target */
   7.301 +    viewport.X = 0;
   7.302 +    viewport.Y = 0;
   7.303 +    viewport.Width = data->pparams.BackBufferWidth;
   7.304 +    viewport.Height = data->pparams.BackBufferHeight;
   7.305 +    viewport.MinZ = 0.0f;
   7.306 +    viewport.MaxZ = 1.0f;
   7.307 +    IDirect3DDevice9_SetViewport(data->device, &viewport);
   7.308 +
   7.309 +    color = D3DCOLOR_ARGB(renderer->a, renderer->r, renderer->g, renderer->b);
   7.310 +
   7.311 +    result = IDirect3DDevice9_Clear(data->device, 0, NULL, D3DCLEAR_TARGET, color, 0.0f, 0);
   7.312 +
   7.313 +    /* Reset the viewport */
   7.314 +    viewport.X = renderer->viewport.x;
   7.315 +    viewport.Y = renderer->viewport.y;
   7.316 +    viewport.Width = renderer->viewport.w;
   7.317 +    viewport.Height = renderer->viewport.h;
   7.318 +    viewport.MinZ = 0.0f;
   7.319 +    viewport.MaxZ = 1.0f;
   7.320 +    IDirect3DDevice9_SetViewport(data->device, &viewport);
   7.321 +
   7.322 +    if (FAILED(result)) {
   7.323 +        D3D_SetError("Clear()", result);
   7.324 +        return -1;
   7.325 +    }
   7.326 +    return 0;
   7.327  }
   7.328  
   7.329  static void
   7.330 @@ -670,9 +786,8 @@
   7.331      int i;
   7.332      HRESULT result;
   7.333  
   7.334 -    if (data->beginScene) {
   7.335 -        IDirect3DDevice9_BeginScene(data->device);
   7.336 -        data->beginScene = SDL_FALSE;
   7.337 +    if (D3D_ActivateRenderer(renderer) < 0) {
   7.338 +        return -1;
   7.339      }
   7.340  
   7.341      D3D_SetBlendMode(data, renderer->blendMode);
   7.342 @@ -692,7 +807,6 @@
   7.343          vertices[i].x = (float) points[i].x;
   7.344          vertices[i].y = (float) points[i].y;
   7.345          vertices[i].z = 0.0f;
   7.346 -        vertices[i].rhw = 1.0f;
   7.347          vertices[i].color = color;
   7.348          vertices[i].u = 0.0f;
   7.349          vertices[i].v = 0.0f;
   7.350 @@ -718,9 +832,8 @@
   7.351      int i;
   7.352      HRESULT result;
   7.353  
   7.354 -    if (data->beginScene) {
   7.355 -        IDirect3DDevice9_BeginScene(data->device);
   7.356 -        data->beginScene = SDL_FALSE;
   7.357 +    if (D3D_ActivateRenderer(renderer) < 0) {
   7.358 +        return -1;
   7.359      }
   7.360  
   7.361      D3D_SetBlendMode(data, renderer->blendMode);
   7.362 @@ -740,7 +853,6 @@
   7.363          vertices[i].x = (float) points[i].x;
   7.364          vertices[i].y = (float) points[i].y;
   7.365          vertices[i].z = 0.0f;
   7.366 -        vertices[i].rhw = 1.0f;
   7.367          vertices[i].color = color;
   7.368          vertices[i].u = 0.0f;
   7.369          vertices[i].v = 0.0f;
   7.370 @@ -766,7 +878,7 @@
   7.371  }
   7.372  
   7.373  static int
   7.374 -D3D_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
   7.375 +D3D_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect * rects,
   7.376                      int count)
   7.377  {
   7.378      D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
   7.379 @@ -776,9 +888,8 @@
   7.380      Vertex vertices[4];
   7.381      HRESULT result;
   7.382  
   7.383 -    if (data->beginScene) {
   7.384 -        IDirect3DDevice9_BeginScene(data->device);
   7.385 -        data->beginScene = SDL_FALSE;
   7.386 +    if (D3D_ActivateRenderer(renderer) < 0) {
   7.387 +        return -1;
   7.388      }
   7.389  
   7.390      D3D_SetBlendMode(data, renderer->blendMode);
   7.391 @@ -794,7 +905,7 @@
   7.392      color = D3DCOLOR_ARGB(renderer->a, renderer->r, renderer->g, renderer->b);
   7.393  
   7.394      for (i = 0; i < count; ++i) {
   7.395 -        const SDL_Rect *rect = rects[i];
   7.396 +        const SDL_Rect *rect = &rects[i];
   7.397  
   7.398          minx = (float) rect->x;
   7.399          miny = (float) rect->y;
   7.400 @@ -804,7 +915,6 @@
   7.401          vertices[0].x = minx;
   7.402          vertices[0].y = miny;
   7.403          vertices[0].z = 0.0f;
   7.404 -        vertices[0].rhw = 1.0f;
   7.405          vertices[0].color = color;
   7.406          vertices[0].u = 0.0f;
   7.407          vertices[0].v = 0.0f;
   7.408 @@ -812,7 +922,6 @@
   7.409          vertices[1].x = maxx;
   7.410          vertices[1].y = miny;
   7.411          vertices[1].z = 0.0f;
   7.412 -        vertices[1].rhw = 1.0f;
   7.413          vertices[1].color = color;
   7.414          vertices[1].u = 0.0f;
   7.415          vertices[1].v = 0.0f;
   7.416 @@ -820,7 +929,6 @@
   7.417          vertices[2].x = maxx;
   7.418          vertices[2].y = maxy;
   7.419          vertices[2].z = 0.0f;
   7.420 -        vertices[2].rhw = 1.0f;
   7.421          vertices[2].color = color;
   7.422          vertices[2].u = 0.0f;
   7.423          vertices[2].v = 0.0f;
   7.424 @@ -828,7 +936,6 @@
   7.425          vertices[3].x = minx;
   7.426          vertices[3].y = maxy;
   7.427          vertices[3].z = 0.0f;
   7.428 -        vertices[3].rhw = 1.0f;
   7.429          vertices[3].color = color;
   7.430          vertices[3].u = 0.0f;
   7.431          vertices[3].v = 0.0f;
   7.432 @@ -857,9 +964,8 @@
   7.433      Vertex vertices[4];
   7.434      HRESULT result;
   7.435  
   7.436 -    if (data->beginScene) {
   7.437 -        IDirect3DDevice9_BeginScene(data->device);
   7.438 -        data->beginScene = SDL_FALSE;
   7.439 +    if (D3D_ActivateRenderer(renderer) < 0) {
   7.440 +        return -1;
   7.441      }
   7.442  
   7.443      minx = (float) dstrect->x - 0.5f;
   7.444 @@ -877,7 +983,6 @@
   7.445      vertices[0].x = minx;
   7.446      vertices[0].y = miny;
   7.447      vertices[0].z = 0.0f;
   7.448 -    vertices[0].rhw = 1.0f;
   7.449      vertices[0].color = color;
   7.450      vertices[0].u = minu;
   7.451      vertices[0].v = minv;
   7.452 @@ -885,7 +990,6 @@
   7.453      vertices[1].x = maxx;
   7.454      vertices[1].y = miny;
   7.455      vertices[1].z = 0.0f;
   7.456 -    vertices[1].rhw = 1.0f;
   7.457      vertices[1].color = color;
   7.458      vertices[1].u = maxu;
   7.459      vertices[1].v = minv;
   7.460 @@ -893,7 +997,6 @@
   7.461      vertices[2].x = maxx;
   7.462      vertices[2].y = maxy;
   7.463      vertices[2].z = 0.0f;
   7.464 -    vertices[2].rhw = 1.0f;
   7.465      vertices[2].color = color;
   7.466      vertices[2].u = maxu;
   7.467      vertices[2].v = maxv;
   7.468 @@ -901,7 +1004,6 @@
   7.469      vertices[3].x = minx;
   7.470      vertices[3].y = maxy;
   7.471      vertices[3].z = 0.0f;
   7.472 -    vertices[3].rhw = 1.0f;
   7.473      vertices[3].color = color;
   7.474      vertices[3].u = minu;
   7.475      vertices[3].v = maxv;
     8.1 --- a/src/render/opengl/SDL_render_gl.c	Mon Feb 14 11:50:18 2011 -0600
     8.2 +++ b/src/render/opengl/SDL_render_gl.c	Tue Feb 15 13:59:59 2011 -0800
     8.3 @@ -55,14 +55,14 @@
     8.4  static int GL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
     8.5                            const SDL_Rect * rect, void **pixels, int *pitch);
     8.6  static void GL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
     8.7 -static void GL_SetClipRect(SDL_Renderer * renderer, const SDL_Rect * rect);
     8.8 +static int GL_UpdateViewport(SDL_Renderer * renderer);
     8.9  static int GL_RenderClear(SDL_Renderer * renderer);
    8.10  static int GL_RenderDrawPoints(SDL_Renderer * renderer,
    8.11                                 const SDL_Point * points, int count);
    8.12  static int GL_RenderDrawLines(SDL_Renderer * renderer,
    8.13                                const SDL_Point * points, int count);
    8.14  static int GL_RenderFillRects(SDL_Renderer * renderer,
    8.15 -                              const SDL_Rect ** rects, int count);
    8.16 +                              const SDL_Rect * rects, int count);
    8.17  static int GL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
    8.18                           const SDL_Rect * srcrect, const SDL_Rect * dstrect);
    8.19  static int GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
    8.20 @@ -86,7 +86,6 @@
    8.21  typedef struct
    8.22  {
    8.23      SDL_GLContext context;
    8.24 -    SDL_bool updateSize;
    8.25      SDL_bool GL_ARB_texture_rectangle_supported;
    8.26      int blendMode;
    8.27  
    8.28 @@ -185,6 +184,24 @@
    8.29      return 0;
    8.30  }
    8.31  
    8.32 +static SDL_GLContext SDL_CurrentContext = NULL;
    8.33 +
    8.34 +static int
    8.35 +GL_ActivateRenderer(SDL_Renderer * renderer)
    8.36 +{
    8.37 +    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
    8.38 +
    8.39 +    if (SDL_CurrentContext != data->context) {
    8.40 +        if (SDL_GL_MakeCurrent(renderer->window, data->context) < 0) {
    8.41 +            return -1;
    8.42 +        }
    8.43 +        SDL_CurrentContext = data->context;
    8.44 +
    8.45 +        GL_UpdateViewport(renderer);
    8.46 +    }
    8.47 +    return 0;
    8.48 +}
    8.49 +
    8.50  SDL_Renderer *
    8.51  GL_CreateRenderer(SDL_Window * window, Uint32 flags)
    8.52  {
    8.53 @@ -219,7 +236,7 @@
    8.54      renderer->UpdateTexture = GL_UpdateTexture;
    8.55      renderer->LockTexture = GL_LockTexture;
    8.56      renderer->UnlockTexture = GL_UnlockTexture;
    8.57 -    renderer->SetClipRect = GL_SetClipRect;
    8.58 +    renderer->UpdateViewport = GL_UpdateViewport;
    8.59      renderer->RenderClear = GL_RenderClear;
    8.60      renderer->RenderDrawPoints = GL_RenderDrawPoints;
    8.61      renderer->RenderDrawLines = GL_RenderDrawLines;
    8.62 @@ -230,10 +247,9 @@
    8.63      renderer->DestroyTexture = GL_DestroyTexture;
    8.64      renderer->DestroyRenderer = GL_DestroyRenderer;
    8.65      renderer->info = GL_RenderDriver.info;
    8.66 +    renderer->info.flags = SDL_RENDERER_ACCELERATED;
    8.67      renderer->driverdata = data;
    8.68  
    8.69 -    renderer->info.flags = SDL_RENDERER_ACCELERATED;
    8.70 -
    8.71      data->context = SDL_GL_CreateContext(window);
    8.72      if (!data->context) {
    8.73          GL_DestroyRenderer(renderer);
    8.74 @@ -309,40 +325,12 @@
    8.75      data->glDisable(GL_CULL_FACE);
    8.76      /* This ended up causing video discrepancies between OpenGL and Direct3D */
    8.77      /*data->glEnable(GL_LINE_SMOOTH);*/
    8.78 -    data->updateSize = SDL_TRUE;
    8.79 +    data->glMatrixMode(GL_MODELVIEW);
    8.80 +    data->glLoadIdentity();
    8.81  
    8.82      return renderer;
    8.83  }
    8.84  
    8.85 -static SDL_GLContext SDL_CurrentContext = NULL;
    8.86 -
    8.87 -static int
    8.88 -GL_ActivateRenderer(SDL_Renderer * renderer)
    8.89 -{
    8.90 -    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
    8.91 -    SDL_Window *window = renderer->window;
    8.92 -
    8.93 -    if (SDL_CurrentContext != data->context) {
    8.94 -        if (SDL_GL_MakeCurrent(window, data->context) < 0) {
    8.95 -            return -1;
    8.96 -        }
    8.97 -        SDL_CurrentContext = data->context;
    8.98 -    }
    8.99 -    if (data->updateSize) {
   8.100 -        int w, h;
   8.101 -
   8.102 -        SDL_GetWindowSize(window, &w, &h);
   8.103 -        data->glMatrixMode(GL_PROJECTION);
   8.104 -        data->glLoadIdentity();
   8.105 -        data->glMatrixMode(GL_MODELVIEW);
   8.106 -        data->glLoadIdentity();
   8.107 -        data->glViewport(0, 0, w, h);
   8.108 -        data->glOrtho(0.0, (GLdouble) w, (GLdouble) h, 0.0, 0.0, 1.0);
   8.109 -        data->updateSize = SDL_FALSE;
   8.110 -    }
   8.111 -    return 0;
   8.112 -}
   8.113 -
   8.114  static void
   8.115  GL_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
   8.116  {
   8.117 @@ -351,7 +339,6 @@
   8.118      if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED) {
   8.119          /* Rebind the context to the window area and update matrices */
   8.120          SDL_CurrentContext = NULL;
   8.121 -        data->updateSize = SDL_TRUE;
   8.122      }
   8.123  }
   8.124  
   8.125 @@ -622,22 +609,26 @@
   8.126      GL_UpdateTexture(renderer, texture, rect, pixels, data->pitch);
   8.127  }
   8.128  
   8.129 -static void
   8.130 -GL_SetClipRect(SDL_Renderer * renderer, const SDL_Rect * rect)
   8.131 +static int
   8.132 +GL_UpdateViewport(SDL_Renderer * renderer)
   8.133  {
   8.134      GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
   8.135  
   8.136 -    GL_ActivateRenderer(renderer);
   8.137 +    if (SDL_CurrentContext != data->context) {
   8.138 +        /* We'll update the viewport after we rebind the context */
   8.139 +        return 0;
   8.140 +    }
   8.141  
   8.142 -    if (rect) {
   8.143 -        int w, h;
   8.144 +    data->glViewport(renderer->viewport.x, renderer->viewport.y,
   8.145 +                     renderer->viewport.w, renderer->viewport.h);
   8.146  
   8.147 -        SDL_GetWindowSize(renderer->window, &w, &h);
   8.148 -        data->glScissor(rect->x, (h-(rect->y+rect->h)), rect->w, rect->h);
   8.149 -        data->glEnable(GL_SCISSOR_TEST);
   8.150 -    } else {
   8.151 -        data->glDisable(GL_SCISSOR_TEST);
   8.152 -    }
   8.153 +    data->glMatrixMode(GL_PROJECTION);
   8.154 +    data->glLoadIdentity();
   8.155 +    data->glOrtho((GLdouble) 0,
   8.156 +                  (GLdouble) renderer->viewport.w,
   8.157 +                  (GLdouble) renderer->viewport.h,
   8.158 +                  (GLdouble) 0, 0.0, 1.0);
   8.159 +    return 0;
   8.160  }
   8.161  
   8.162  static void
   8.163 @@ -785,7 +776,7 @@
   8.164  }
   8.165  
   8.166  static int
   8.167 -GL_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
   8.168 +GL_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect * rects, int count)
   8.169  {
   8.170      GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
   8.171      int i;
   8.172 @@ -801,7 +792,7 @@
   8.173                      (GLfloat) renderer->a * inv255f);
   8.174  
   8.175      for (i = 0; i < count; ++i) {
   8.176 -        const SDL_Rect *rect = rects[i];
   8.177 +        const SDL_Rect *rect = &rects[i];
   8.178  
   8.179          data->glRecti(rect->x, rect->y, rect->x + rect->w, rect->y + rect->h);
   8.180      }
     9.1 --- a/src/render/opengles/SDL_render_gles.c	Mon Feb 14 11:50:18 2011 -0600
     9.2 +++ b/src/render/opengles/SDL_render_gles.c	Tue Feb 15 13:59:59 2011 -0800
     9.3 @@ -53,13 +53,13 @@
     9.4                              const SDL_Rect * rect, void **pixels, int *pitch);
     9.5  static void GLES_UnlockTexture(SDL_Renderer * renderer,
     9.6                                 SDL_Texture * texture);
     9.7 -static void GLES_SetClipRect(SDL_Renderer * renderer, const SDL_Rect * rect);
     9.8 +static int GLES_UpdateViewport(SDL_Renderer * renderer);
     9.9  static int GLES_RenderDrawPoints(SDL_Renderer * renderer,
    9.10                                   const SDL_Point * points, int count);
    9.11  static int GLES_RenderDrawLines(SDL_Renderer * renderer,
    9.12                                  const SDL_Point * points, int count);
    9.13  static int GLES_RenderFillRects(SDL_Renderer * renderer,
    9.14 -                                const SDL_Rect ** rects, int count);
    9.15 +                                const SDL_Rect * rects, int count);
    9.16  static int GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
    9.17                             const SDL_Rect * srcrect,
    9.18                             const SDL_Rect * dstrect);
    9.19 @@ -83,7 +83,6 @@
    9.20  typedef struct
    9.21  {
    9.22      SDL_GLContext context;
    9.23 -    SDL_bool updateSize;
    9.24      int blendMode;
    9.25  
    9.26      SDL_bool useDrawTexture;
    9.27 @@ -136,6 +135,24 @@
    9.28      SDL_SetError("%s: %s", prefix, error);
    9.29  }
    9.30  
    9.31 +static SDL_GLContext SDL_CurrentContext = NULL;
    9.32 +
    9.33 +static int
    9.34 +GLES_ActivateRenderer(SDL_Renderer * renderer)
    9.35 +{
    9.36 +    GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
    9.37 +
    9.38 +    if (SDL_CurrentContext != data->context) {
    9.39 +        if (SDL_GL_MakeCurrent(renderer->window, data->context) < 0) {
    9.40 +            return -1;
    9.41 +        }
    9.42 +        SDL_CurrentContext = data->context;
    9.43 +
    9.44 +        GLES_UpdateViewport(renderer);
    9.45 +    }
    9.46 +    return 0;
    9.47 +}
    9.48 +
    9.49  SDL_Renderer *
    9.50  GLES_CreateRenderer(SDL_Window * window, Uint32 flags)
    9.51  {
    9.52 @@ -162,7 +179,7 @@
    9.53      renderer->UpdateTexture = GLES_UpdateTexture;
    9.54      renderer->LockTexture = GLES_LockTexture;
    9.55      renderer->UnlockTexture = GLES_UnlockTexture;
    9.56 -    renderer->SetClipRect = GLES_SetClipRect;
    9.57 +    renderer->UpdateViewport = GLES_UpdateViewport;
    9.58      renderer->RenderDrawPoints = GLES_RenderDrawPoints;
    9.59      renderer->RenderDrawLines = GLES_RenderDrawLines;
    9.60      renderer->RenderFillRects = GLES_RenderFillRects;
    9.61 @@ -171,10 +188,9 @@
    9.62      renderer->DestroyTexture = GLES_DestroyTexture;
    9.63      renderer->DestroyRenderer = GLES_DestroyRenderer;
    9.64      renderer->info = GLES_RenderDriver.info;
    9.65 +    renderer->info.flags = SDL_RENDERER_ACCELERATED;
    9.66      renderer->driverdata = data;
    9.67  
    9.68 -    renderer->info.flags = SDL_RENDERER_ACCELERATED;
    9.69 -
    9.70      SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
    9.71      SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
    9.72  
    9.73 @@ -219,7 +235,8 @@
    9.74      data->blendMode = -1;
    9.75      glDisable(GL_DEPTH_TEST);
    9.76      glDisable(GL_CULL_FACE);
    9.77 -    data->updateSize = SDL_TRUE;
    9.78 +    glMatrixMode(GL_MODELVIEW);
    9.79 +    glLoadIdentity();
    9.80  
    9.81      glEnableClientState(GL_VERTEX_ARRAY);
    9.82      glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    9.83 @@ -227,35 +244,6 @@
    9.84      return renderer;
    9.85  }
    9.86  
    9.87 -static SDL_GLContext SDL_CurrentContext = NULL;
    9.88 -
    9.89 -static int
    9.90 -GLES_ActivateRenderer(SDL_Renderer * renderer)
    9.91 -{
    9.92 -    GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
    9.93 -    SDL_Window *window = renderer->window;
    9.94 -
    9.95 -    if (SDL_CurrentContext != data->context) {
    9.96 -        if (SDL_GL_MakeCurrent(window, data->context) < 0) {
    9.97 -            return -1;
    9.98 -        }
    9.99 -        SDL_CurrentContext = data->context;
   9.100 -    }
   9.101 -    if (data->updateSize) {
   9.102 -        int w, h;
   9.103 -
   9.104 -        SDL_GetWindowSize(window, &w, &h);
   9.105 -        glMatrixMode(GL_PROJECTION);
   9.106 -        glLoadIdentity();
   9.107 -        glMatrixMode(GL_MODELVIEW);
   9.108 -        glLoadIdentity();
   9.109 -        glViewport(0, 0, w, h);
   9.110 -        glOrthof(0.0, (GLfloat) w, (GLfloat) h, 0.0, 0.0, 1.0);
   9.111 -        data->updateSize = SDL_FALSE;
   9.112 -    }
   9.113 -    return 0;
   9.114 -}
   9.115 -
   9.116  static void
   9.117  GLES_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
   9.118  {
   9.119 @@ -264,7 +252,6 @@
   9.120      if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED) {
   9.121          /* Rebind the context to the window area and update matrices */
   9.122          SDL_CurrentContext = NULL;
   9.123 -        data->updateSize = SDL_TRUE;
   9.124      }
   9.125  }
   9.126  
   9.127 @@ -444,20 +431,26 @@
   9.128      GLES_UpdateTexture(renderer, texture, &rect, data->pixels, data->pitch);
   9.129  }
   9.130  
   9.131 -static void
   9.132 -GLES_SetClipRect(SDL_Renderer * renderer, const SDL_Rect * rect)
   9.133 +static int
   9.134 +GLES_UpdateViewport(SDL_Renderer * renderer)
   9.135  {
   9.136 -    GLES_ActivateRenderer(renderer);
   9.137 +    GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
   9.138  
   9.139 -    if (rect) {
   9.140 -        int w, h;
   9.141 +    if (SDL_CurrentContext != data->context) {
   9.142 +        /* We'll update the viewport after we rebind the context */
   9.143 +        return 0;
   9.144 +    }
   9.145  
   9.146 -        SDL_GetWindowSize(renderer->window, &w, &h);
   9.147 -        glScissor(rect->x, (h-(rect->y+rect->h)), rect->w, rect->h);
   9.148 -        glEnable(GL_SCISSOR_TEST);
   9.149 -    } else {
   9.150 -        glDisable(GL_SCISSOR_TEST);
   9.151 -    }
   9.152 +    glViewport(renderer->viewport.x, renderer->viewport.y,
   9.153 +               renderer->viewport.w, renderer->viewport.h);
   9.154 +
   9.155 +    glMatrixMode(GL_PROJECTION);
   9.156 +    glLoadIdentity();
   9.157 +    glOrthof((GLfloat) 0,
   9.158 +			 (GLfloat) renderer->viewport.w,
   9.159 +             (GLfloat) renderer->viewport.h,
   9.160 +             (GLfloat) 0, 0.0, 1.0);
   9.161 +    return 0;
   9.162  }
   9.163  
   9.164  static void
   9.165 @@ -555,7 +548,7 @@
   9.166  }
   9.167  
   9.168  static int
   9.169 -GLES_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
   9.170 +GLES_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect * rects,
   9.171                       int count)
   9.172  {
   9.173      GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
   9.174 @@ -571,7 +564,7 @@
   9.175                      (GLfloat) renderer->a * inv255f);
   9.176  
   9.177      for (i = 0; i < count; ++i) {
   9.178 -        const SDL_Rect *rect = rects[i];
   9.179 +        const SDL_Rect *rect = &rects[i];
   9.180          GLshort minx = rect->x;
   9.181          GLshort maxx = rect->x + rect->w;
   9.182          GLshort miny = rect->y;
    10.1 --- a/src/render/opengles2/SDL_render_gles2.c	Mon Feb 14 11:50:18 2011 -0600
    10.2 +++ b/src/render/opengles2/SDL_render_gles2.c	Tue Feb 15 13:59:59 2011 -0800
    10.3 @@ -123,7 +123,6 @@
    10.4      GLES2_ShaderCache shader_cache;
    10.5      GLES2_ProgramCache program_cache;
    10.6      GLES2_ProgramCacheEntry *current_program;
    10.7 -	SDL_bool updateSize;
    10.8  } GLES2_DriverContext;
    10.9  
   10.10  #define GLES2_MAX_CACHED_PROGRAMS 8
   10.11 @@ -135,7 +134,7 @@
   10.12  static int GLES2_ActivateRenderer(SDL_Renderer *renderer);
   10.13  static void GLES2_WindowEvent(SDL_Renderer * renderer,
   10.14                                const SDL_WindowEvent *event);
   10.15 -static void GLES2_SetClipRect(SDL_Renderer * renderer, const SDL_Rect * rect);
   10.16 +static int GLES2_UpdateViewport(SDL_Renderer * renderer);
   10.17  static void GLES2_DestroyRenderer(SDL_Renderer *renderer);
   10.18  
   10.19  static SDL_GLContext SDL_CurrentContext = NULL;
   10.20 @@ -144,23 +143,17 @@
   10.21  GLES2_ActivateRenderer(SDL_Renderer * renderer)
   10.22  {
   10.23      GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
   10.24 -    SDL_Window *window = renderer->window;
   10.25  
   10.26      if (SDL_CurrentContext != rdata->context) {
   10.27          /* Null out the current program to ensure we set it again */
   10.28          rdata->current_program = NULL;
   10.29  
   10.30 -        if (SDL_GL_MakeCurrent(window, rdata->context) < 0) {
   10.31 +        if (SDL_GL_MakeCurrent(renderer->window, rdata->context) < 0) {
   10.32              return -1;
   10.33          }
   10.34          SDL_CurrentContext = rdata->context;
   10.35 -    }
   10.36 -    if (rdata->updateSize) {
   10.37 -        int w, h;
   10.38  
   10.39 -        SDL_GetWindowSize(window, &w, &h);
   10.40 -        glViewport(0, 0, w, h);
   10.41 -        rdata->updateSize = SDL_FALSE;
   10.42 +        GLES2_UpdateViewport(renderer);
   10.43      }
   10.44      return 0;
   10.45  }
   10.46 @@ -173,24 +166,22 @@
   10.47      if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED) {
   10.48          /* Rebind the context to the window area */
   10.49          SDL_CurrentContext = NULL;
   10.50 -        rdata->updateSize = SDL_TRUE;
   10.51      }
   10.52  }
   10.53  
   10.54 -static void
   10.55 -GLES2_SetClipRect(SDL_Renderer * renderer, const SDL_Rect * rect)
   10.56 +static int
   10.57 +GLES2_UpdateViewport(SDL_Renderer * renderer)
   10.58  {
   10.59 -    GLES2_ActivateRenderer(renderer);
   10.60 +    GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
   10.61  
   10.62 -    if (rect) {
   10.63 -        int w, h;
   10.64 +    if (SDL_CurrentContext != rdata->context) {
   10.65 +        /* We'll update the viewport after we rebind the context */
   10.66 +        return 0;
   10.67 +    }
   10.68  
   10.69 -        SDL_GetWindowSize(renderer->window, &w, &h);
   10.70 -        glScissor(rect->x, (h-(rect->y+rect->h)), rect->w, rect->h);
   10.71 -        glEnable(GL_SCISSOR_TEST);
   10.72 -    } else {
   10.73 -        glDisable(GL_SCISSOR_TEST);
   10.74 -    }
   10.75 +    glViewport(renderer->viewport.x, renderer->viewport.y,
   10.76 +               renderer->viewport.w, renderer->viewport.h);
   10.77 +    return 0;
   10.78  }
   10.79  
   10.80  static void
   10.81 @@ -735,21 +726,16 @@
   10.82  GLES2_SetOrthographicProjection(SDL_Renderer *renderer)
   10.83  {
   10.84      GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
   10.85 -    SDL_Window *window = renderer->window;
   10.86 -    int w, h;
   10.87      GLfloat projection[4][4];
   10.88      GLuint locProjection;
   10.89  
   10.90 -    /* Get the window width and height */
   10.91 -    SDL_GetWindowSize(window, &w, &h);
   10.92 -
   10.93      /* Prepare an orthographic projection */
   10.94 -    projection[0][0] = 2.0f / w;
   10.95 +    projection[0][0] = 2.0f / renderer->viewport.w;
   10.96      projection[0][1] = 0.0f;
   10.97      projection[0][2] = 0.0f;
   10.98      projection[0][3] = 0.0f;
   10.99      projection[1][0] = 0.0f;
  10.100 -    projection[1][1] = -2.0f / h;
  10.101 +    projection[1][1] = -2.0f / renderer->viewport.h;
  10.102      projection[1][2] = 0.0f;
  10.103      projection[1][3] = 0.0f;
  10.104      projection[2][0] = 0.0f;
  10.105 @@ -782,7 +768,7 @@
  10.106  static int GLES2_RenderClear(SDL_Renderer *renderer);
  10.107  static int GLES2_RenderDrawPoints(SDL_Renderer *renderer, const SDL_Point *points, int count);
  10.108  static int GLES2_RenderDrawLines(SDL_Renderer *renderer, const SDL_Point *points, int count);
  10.109 -static int GLES2_RenderFillRects(SDL_Renderer *renderer, const SDL_Rect **rects, int count);
  10.110 +static int GLES2_RenderFillRects(SDL_Renderer *renderer, const SDL_Rect *rects, int count);
  10.111  static int GLES2_RenderCopy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect,
  10.112                              const SDL_Rect *dstrect);
  10.113  static void GLES2_RenderPresent(SDL_Renderer *renderer);
  10.114 @@ -936,7 +922,7 @@
  10.115  }
  10.116  
  10.117  static int
  10.118 -GLES2_RenderFillRects(SDL_Renderer *renderer, const SDL_Rect **rects, int count)
  10.119 +GLES2_RenderFillRects(SDL_Renderer *renderer, const SDL_Rect *rects, int count)
  10.120  {
  10.121      GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
  10.122      GLfloat vertices[8];
  10.123 @@ -968,12 +954,13 @@
  10.124  
  10.125      /* Emit a line loop for each rectangle */
  10.126      glEnableVertexAttribArray(GLES2_ATTRIBUTE_POSITION);
  10.127 -    for (idx = 0; idx < count; ++idx)
  10.128 -    {
  10.129 -        GLfloat xMin = (GLfloat)rects[idx]->x;
  10.130 -        GLfloat xMax = (GLfloat)(rects[idx]->x + rects[idx]->w);
  10.131 -        GLfloat yMin = (GLfloat)rects[idx]->y;
  10.132 -        GLfloat yMax = (GLfloat)(rects[idx]->y + rects[idx]->h);
  10.133 +    for (idx = 0; idx < count; ++idx) {
  10.134 +        const SDL_Rect *rect = &rects[idx];
  10.135 +
  10.136 +        GLfloat xMin = (GLfloat)rect->x;
  10.137 +        GLfloat xMax = (GLfloat)(rect->x + rect->w);
  10.138 +        GLfloat yMin = (GLfloat)rect->y;
  10.139 +        GLfloat yMax = (GLfloat)(rect->y + rect->h);
  10.140  
  10.141          vertices[0] = xMin;
  10.142          vertices[1] = yMin;
  10.143 @@ -1108,11 +1095,9 @@
  10.144          return NULL;
  10.145      }
  10.146      renderer->info = GLES2_RenderDriver.info;
  10.147 -    renderer->window = window;
  10.148 +    renderer->info.flags = SDL_RENDERER_ACCELERATED;
  10.149      renderer->driverdata = rdata;
  10.150  
  10.151 -    renderer->info.flags = SDL_RENDERER_ACCELERATED;
  10.152 -
  10.153      /* Create an OpenGL ES 2.0 context */
  10.154      SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
  10.155      SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
  10.156 @@ -1169,8 +1154,6 @@
  10.157      if (hasCompiler)
  10.158          rdata->shader_formats[nFormats - 1] = (GLenum)-1;
  10.159  #endif /* ZUNE_HD */
  10.160 -	
  10.161 -    rdata->updateSize = SDL_TRUE;
  10.162  
  10.163      /* Populate the function pointers for the module */
  10.164      renderer->WindowEvent         = &GLES2_WindowEvent;
  10.165 @@ -1178,7 +1161,7 @@
  10.166      renderer->UpdateTexture       = &GLES2_UpdateTexture;
  10.167      renderer->LockTexture         = &GLES2_LockTexture;
  10.168      renderer->UnlockTexture       = &GLES2_UnlockTexture;
  10.169 -    renderer->SetClipRect         = &GLES2_SetClipRect;
  10.170 +    renderer->UpdateViewport      = &GLES2_UpdateViewport;
  10.171      renderer->RenderClear         = &GLES2_RenderClear;
  10.172      renderer->RenderDrawPoints    = &GLES2_RenderDrawPoints;
  10.173      renderer->RenderDrawLines     = &GLES2_RenderDrawLines;
    11.1 --- a/src/render/software/SDL_blendfillrect.c	Mon Feb 14 11:50:18 2011 -0600
    11.2 +++ b/src/render/software/SDL_blendfillrect.c	Tue Feb 15 13:59:59 2011 -0800
    11.3 @@ -265,10 +265,10 @@
    11.4  }
    11.5  
    11.6  int
    11.7 -SDL_BlendFillRects(SDL_Surface * dst, const SDL_Rect ** rects, int count,
    11.8 +SDL_BlendFillRects(SDL_Surface * dst, const SDL_Rect * rects, int count,
    11.9                     SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
   11.10  {
   11.11 -    SDL_Rect clipped;
   11.12 +    SDL_Rect rect;
   11.13      int i;
   11.14      int (*func)(SDL_Surface * dst, const SDL_Rect * rect,
   11.15                  SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) = NULL;
   11.16 @@ -329,20 +329,11 @@
   11.17      }
   11.18  
   11.19      for (i = 0; i < count; ++i) {
   11.20 -        const SDL_Rect * rect = rects[i];
   11.21 -
   11.22 -        /* If 'rect' == NULL, then fill the whole surface */
   11.23 -        if (rect) {
   11.24 -            /* Perform clipping */
   11.25 -            if (!SDL_IntersectRect(rect, &dst->clip_rect, &clipped)) {
   11.26 -                continue;
   11.27 -            }
   11.28 -            rect = &clipped;
   11.29 -        } else {
   11.30 -            rect = &dst->clip_rect;
   11.31 +        /* Perform clipping */
   11.32 +        if (!SDL_IntersectRect(&rects[i], &dst->clip_rect, &rect)) {
   11.33 +            continue;
   11.34          }
   11.35 -
   11.36 -        status = func(dst, rect, blendMode, r, g, b, a);
   11.37 +        status = func(dst, &rect, blendMode, r, g, b, a);
   11.38      }
   11.39      return status;
   11.40  }
    12.1 --- a/src/render/software/SDL_blendfillrect.h	Mon Feb 14 11:50:18 2011 -0600
    12.2 +++ b/src/render/software/SDL_blendfillrect.h	Tue Feb 15 13:59:59 2011 -0800
    12.3 @@ -23,6 +23,6 @@
    12.4  
    12.5  
    12.6  extern int SDL_BlendFillRect(SDL_Surface * dst, const SDL_Rect * rect, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
    12.7 -extern int SDL_BlendFillRects(SDL_Surface * dst, const SDL_Rect ** rects, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
    12.8 +extern int SDL_BlendFillRects(SDL_Surface * dst, const SDL_Rect * rects, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
    12.9  
   12.10  /* vi: set ts=4 sw=4 expandtab: */
    13.1 --- a/src/render/software/SDL_render_sw.c	Mon Feb 14 11:50:18 2011 -0600
    13.2 +++ b/src/render/software/SDL_render_sw.c	Tue Feb 15 13:59:59 2011 -0800
    13.3 @@ -51,13 +51,14 @@
    13.4  static int SW_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
    13.5                            const SDL_Rect * rect, void **pixels, int *pitch);
    13.6  static void SW_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
    13.7 -static void SW_SetClipRect(SDL_Renderer * renderer, const SDL_Rect * rect);
    13.8 +static int SW_UpdateViewport(SDL_Renderer * renderer);
    13.9 +static int SW_RenderClear(SDL_Renderer * renderer);
   13.10  static int SW_RenderDrawPoints(SDL_Renderer * renderer,
   13.11                                 const SDL_Point * points, int count);
   13.12  static int SW_RenderDrawLines(SDL_Renderer * renderer,
   13.13                                const SDL_Point * points, int count);
   13.14  static int SW_RenderFillRects(SDL_Renderer * renderer,
   13.15 -                              const SDL_Rect ** rects, int count);
   13.16 +                              const SDL_Rect * rects, int count);
   13.17  static int SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
   13.18                           const SDL_Rect * srcrect, const SDL_Rect * dstrect);
   13.19  static int SW_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
   13.20 @@ -89,11 +90,23 @@
   13.21  
   13.22  typedef struct
   13.23  {
   13.24 -    SDL_bool updateSize;
   13.25      SDL_Surface *surface;
   13.26  } SW_RenderData;
   13.27  
   13.28  
   13.29 +static SDL_Surface *
   13.30 +SW_ActivateRenderer(SDL_Renderer * renderer)
   13.31 +{
   13.32 +    SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
   13.33 +
   13.34 +    if (!data->surface) {
   13.35 +        data->surface = SDL_GetWindowSurface(renderer->window);
   13.36 +
   13.37 +        SW_UpdateViewport(renderer);
   13.38 +    }
   13.39 +    return data->surface;
   13.40 +}
   13.41 +
   13.42  SDL_Renderer *
   13.43  SW_CreateRendererForSurface(SDL_Surface * surface)
   13.44  {
   13.45 @@ -127,8 +140,9 @@
   13.46      renderer->UpdateTexture = SW_UpdateTexture;
   13.47      renderer->LockTexture = SW_LockTexture;
   13.48      renderer->UnlockTexture = SW_UnlockTexture;
   13.49 -    renderer->SetClipRect = SW_SetClipRect;
   13.50 +    renderer->UpdateViewport = SW_UpdateViewport;
   13.51      renderer->DestroyTexture = SW_DestroyTexture;
   13.52 +    renderer->RenderClear = SW_RenderClear;
   13.53      renderer->RenderDrawPoints = SW_RenderDrawPoints;
   13.54      renderer->RenderDrawLines = SW_RenderDrawLines;
   13.55      renderer->RenderFillRects = SW_RenderFillRects;
   13.56 @@ -139,6 +153,8 @@
   13.57      renderer->info = SW_RenderDriver.info;
   13.58      renderer->driverdata = data;
   13.59  
   13.60 +    SW_ActivateRenderer(renderer);
   13.61 +
   13.62      return renderer;
   13.63  }
   13.64  
   13.65 @@ -154,26 +170,13 @@
   13.66      return SW_CreateRendererForSurface(surface);
   13.67  }
   13.68  
   13.69 -static SDL_Surface *
   13.70 -SW_ActivateRenderer(SDL_Renderer * renderer)
   13.71 -{
   13.72 -    SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
   13.73 -    SDL_Window *window = renderer->window;
   13.74 -
   13.75 -    if (data->updateSize) {
   13.76 -        data->surface = SDL_GetWindowSurface(window);
   13.77 -        data->updateSize = SDL_FALSE;
   13.78 -    }
   13.79 -    return data->surface;
   13.80 -}
   13.81 -
   13.82  static void
   13.83  SW_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
   13.84  {
   13.85      SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
   13.86  
   13.87      if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED) {
   13.88 -        data->updateSize = SDL_TRUE;
   13.89 +        data->surface = NULL;
   13.90      }
   13.91  }
   13.92  
   13.93 @@ -269,15 +272,46 @@
   13.94  {
   13.95  }
   13.96  
   13.97 -static void
   13.98 -SW_SetClipRect(SDL_Renderer * renderer, const SDL_Rect * rect)
   13.99 +static int
  13.100 +SW_UpdateViewport(SDL_Renderer * renderer)
  13.101 +{
  13.102 +    SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
  13.103 +    SDL_Surface *surface = data->surface;
  13.104 +
  13.105 +    if (!surface) {
  13.106 +        /* We'll update the viewport after we recreate the surface */
  13.107 +        return 0;
  13.108 +    }
  13.109 +
  13.110 +    if (!renderer->viewport.w && !renderer->viewport.h) {
  13.111 +        /* There may be no window, so update the viewport directly */
  13.112 +        renderer->viewport.w = surface->w;
  13.113 +        renderer->viewport.h = surface->h;
  13.114 +    }
  13.115 +    //SDL_SetClipRect(data->surface, &renderer->viewport);
  13.116 +    return 0;
  13.117 +}
  13.118 +
  13.119 +static int
  13.120 +SW_RenderClear(SDL_Renderer * renderer)
  13.121  {
  13.122      SDL_Surface *surface = SW_ActivateRenderer(renderer);
  13.123 +    Uint32 color;
  13.124 +    SDL_Rect clip_rect;
  13.125  
  13.126      if (!surface) {
  13.127 -        return;
  13.128 +        return -1;
  13.129      }
  13.130 -    SDL_SetClipRect(surface, rect);
  13.131 +
  13.132 +    color = SDL_MapRGBA(surface->format,
  13.133 +                        renderer->r, renderer->g, renderer->b, renderer->a);
  13.134 +
  13.135 +    /* By definition the clear ignores the clip rect */
  13.136 +    clip_rect = surface->clip_rect;
  13.137 +    SDL_SetClipRect(surface, NULL);
  13.138 +    SDL_FillRect(surface, NULL, color);
  13.139 +    SDL_SetClipRect(surface, &clip_rect);
  13.140 +    return 0;
  13.141  }
  13.142  
  13.143  static int
  13.144 @@ -285,24 +319,44 @@
  13.145                      int count)
  13.146  {
  13.147      SDL_Surface *surface = SW_ActivateRenderer(renderer);
  13.148 +    SDL_Point *temp = NULL;
  13.149 +    int status;
  13.150  
  13.151      if (!surface) {
  13.152          return -1;
  13.153      }
  13.154  
  13.155 +    if (renderer->viewport.x || renderer->viewport.y) {
  13.156 +        int i;
  13.157 +        int x = renderer->viewport.x;
  13.158 +        int y = renderer->viewport.y;
  13.159 +
  13.160 +        temp = SDL_stack_alloc(SDL_Point, count);
  13.161 +        for (i = 0; i < count; ++i) {
  13.162 +            temp[i].x = x + points[i].x;
  13.163 +            temp[i].y = y + points[i].x;
  13.164 +        }
  13.165 +        points = temp;
  13.166 +    }
  13.167 +
  13.168      /* Draw the points! */
  13.169      if (renderer->blendMode == SDL_BLENDMODE_NONE) {
  13.170          Uint32 color = SDL_MapRGBA(surface->format,
  13.171                                     renderer->r, renderer->g, renderer->b,
  13.172                                     renderer->a);
  13.173  
  13.174 -        return SDL_DrawPoints(surface, points, count, color);
  13.175 +        status = SDL_DrawPoints(surface, points, count, color);
  13.176      } else {
  13.177 -        return SDL_BlendPoints(surface, points, count,
  13.178 -                               renderer->blendMode,
  13.179 -                               renderer->r, renderer->g, renderer->b,
  13.180 -                               renderer->a);
  13.181 +        status = SDL_BlendPoints(surface, points, count,
  13.182 +                                renderer->blendMode,
  13.183 +                                renderer->r, renderer->g, renderer->b,
  13.184 +                                renderer->a);
  13.185      }
  13.186 +
  13.187 +    if (temp) {
  13.188 +        SDL_stack_free(temp);
  13.189 +    }
  13.190 +    return status;
  13.191  }
  13.192  
  13.193  static int
  13.194 @@ -310,47 +364,88 @@
  13.195                     int count)
  13.196  {
  13.197      SDL_Surface *surface = SW_ActivateRenderer(renderer);
  13.198 +    SDL_Point *temp = NULL;
  13.199 +    int status;
  13.200  
  13.201      if (!surface) {
  13.202          return -1;
  13.203      }
  13.204  
  13.205 +    if (renderer->viewport.x || renderer->viewport.y) {
  13.206 +        int i;
  13.207 +        int x = renderer->viewport.x;
  13.208 +        int y = renderer->viewport.y;
  13.209 +
  13.210 +        temp = SDL_stack_alloc(SDL_Point, count);
  13.211 +        for (i = 0; i < count; ++i) {
  13.212 +            temp[i].x = x + points[i].x;
  13.213 +            temp[i].y = y + points[i].y;
  13.214 +        }
  13.215 +        points = temp;
  13.216 +    }
  13.217 +
  13.218      /* Draw the lines! */
  13.219      if (renderer->blendMode == SDL_BLENDMODE_NONE) {
  13.220          Uint32 color = SDL_MapRGBA(surface->format,
  13.221                                     renderer->r, renderer->g, renderer->b,
  13.222                                     renderer->a);
  13.223  
  13.224 -        return SDL_DrawLines(surface, points, count, color);
  13.225 +        status = SDL_DrawLines(surface, points, count, color);
  13.226      } else {
  13.227 -        return SDL_BlendLines(surface, points, count,
  13.228 -                              renderer->blendMode,
  13.229 -                              renderer->r, renderer->g, renderer->b,
  13.230 -                              renderer->a);
  13.231 +        status = SDL_BlendLines(surface, points, count,
  13.232 +                                renderer->blendMode,
  13.233 +                                renderer->r, renderer->g, renderer->b,
  13.234 +                                renderer->a);
  13.235      }
  13.236 +
  13.237 +    if (temp) {
  13.238 +        SDL_stack_free(temp);
  13.239 +    }
  13.240 +    return status;
  13.241  }
  13.242  
  13.243  static int
  13.244 -SW_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
  13.245 -                   int count)
  13.246 +SW_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect * rects, int count)
  13.247  {
  13.248      SDL_Surface *surface = SW_ActivateRenderer(renderer);
  13.249 +    SDL_Rect *temp = NULL;
  13.250 +    int status;
  13.251  
  13.252      if (!surface) {
  13.253          return -1;
  13.254      }
  13.255  
  13.256 +    if (renderer->viewport.x || renderer->viewport.y) {
  13.257 +        int i;
  13.258 +        int x = renderer->viewport.x;
  13.259 +        int y = renderer->viewport.y;
  13.260 +
  13.261 +        temp = SDL_stack_alloc(SDL_Rect, count);
  13.262 +        for (i = 0; i < count; ++i) {
  13.263 +            temp[i].x = x + rects[i].x;
  13.264 +            temp[i].y = y + rects[i].y;
  13.265 +            temp[i].w = rects[i].w;
  13.266 +            temp[i].h = rects[i].h;
  13.267 +        }
  13.268 +        rects = temp;
  13.269 +    }
  13.270 +
  13.271      if (renderer->blendMode == SDL_BLENDMODE_NONE) {
  13.272          Uint32 color = SDL_MapRGBA(surface->format,
  13.273                                     renderer->r, renderer->g, renderer->b,
  13.274                                     renderer->a);
  13.275 -        return SDL_FillRects(surface, rects, count, color);
  13.276 +        status = SDL_FillRects(surface, rects, count, color);
  13.277      } else {
  13.278 -        return SDL_BlendFillRects(surface, rects, count,
  13.279 -                                     renderer->blendMode,
  13.280 -                                     renderer->r, renderer->g, renderer->b,
  13.281 -                                     renderer->a);
  13.282 +        status = SDL_BlendFillRects(surface, rects, count,
  13.283 +                                    renderer->blendMode,
  13.284 +                                    renderer->r, renderer->g, renderer->b,
  13.285 +                                    renderer->a);
  13.286      }
  13.287 +
  13.288 +    if (temp) {
  13.289 +        SDL_stack_free(temp);
  13.290 +    }
  13.291 +    return status;
  13.292  }
  13.293  
  13.294  static int
  13.295 @@ -365,6 +460,10 @@
  13.296          return -1;
  13.297      }
  13.298  
  13.299 +    if (renderer->viewport.x || renderer->viewport.y) {
  13.300 +        final_rect.x += renderer->viewport.x;
  13.301 +        final_rect.y += renderer->viewport.y;
  13.302 +    }
  13.303      if ( srcrect->w == final_rect.w && srcrect->h == final_rect.h ) {
  13.304          return SDL_BlitSurface(src, srcrect, surface, &final_rect);
  13.305      } else {
  13.306 @@ -379,22 +478,27 @@
  13.307      SDL_Surface *surface = SW_ActivateRenderer(renderer);
  13.308      Uint32 src_format;
  13.309      void *src_pixels;
  13.310 +    SDL_Rect final_rect;
  13.311  
  13.312      if (!surface) {
  13.313          return -1;
  13.314      }
  13.315  
  13.316 +    if (renderer->viewport.x || renderer->viewport.y) {
  13.317 +        final_rect.x = renderer->viewport.x + rect->x;
  13.318 +        final_rect.y = renderer->viewport.y + rect->y;
  13.319 +        final_rect.w = rect->w;
  13.320 +        final_rect.h = rect->h;
  13.321 +        rect = &final_rect;
  13.322 +    }
  13.323 +
  13.324      if (rect->x < 0 || rect->x+rect->w > surface->w ||
  13.325          rect->y < 0 || rect->y+rect->h > surface->h) {
  13.326          SDL_SetError("Tried to read outside of surface bounds");
  13.327          return -1;
  13.328      }
  13.329  
  13.330 -    src_format = SDL_MasksToPixelFormatEnum(
  13.331 -                    surface->format->BitsPerPixel,
  13.332 -                    surface->format->Rmask, surface->format->Gmask,
  13.333 -                    surface->format->Bmask, surface->format->Amask);
  13.334 -
  13.335 +    src_format = surface->format->format;
  13.336      src_pixels = (void*)((Uint8 *) surface->pixels +
  13.337                      rect->y * surface->pitch +
  13.338                      rect->x * surface->format->BytesPerPixel);
    14.1 --- a/src/video/SDL_fillrect.c	Mon Feb 14 11:50:18 2011 -0600
    14.2 +++ b/src/video/SDL_fillrect.c	Tue Feb 15 13:59:59 2011 -0800
    14.3 @@ -417,14 +417,19 @@
    14.4  }
    14.5  
    14.6  int
    14.7 -SDL_FillRects(SDL_Surface * dst, const SDL_Rect ** rects, int count,
    14.8 +SDL_FillRects(SDL_Surface * dst, const SDL_Rect * rects, int count,
    14.9                Uint32 color)
   14.10  {
   14.11      int i;
   14.12      int status = 0;
   14.13  
   14.14 +    if (!rects) {
   14.15 +        SDL_SetError("SDL_FillRects() passed NULL rects");
   14.16 +        return -1;
   14.17 +    }
   14.18 +
   14.19      for (i = 0; i < count; ++i) {
   14.20 -        status = SDL_FillRect(dst, rects[i], color);
   14.21 +        status += SDL_FillRect(dst, &rects[i], color);
   14.22      }
   14.23      return status;
   14.24  }
    15.1 --- a/src/video/SDL_sysvideo.h	Mon Feb 14 11:50:18 2011 -0600
    15.2 +++ b/src/video/SDL_sysvideo.h	Tue Feb 15 13:59:59 2011 -0800
    15.3 @@ -185,7 +185,7 @@
    15.4      void (*SetWindowGrab) (_THIS, SDL_Window * window);
    15.5      void (*DestroyWindow) (_THIS, SDL_Window * window);
    15.6      int (*CreateWindowFramebuffer) (_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch);
    15.7 -    int (*UpdateWindowFramebuffer) (_THIS, SDL_Window * window, int numrects, SDL_Rect * rects);
    15.8 +    int (*UpdateWindowFramebuffer) (_THIS, SDL_Window * window, SDL_Rect * rects, int numrects);
    15.9      void (*DestroyWindowFramebuffer) (_THIS, SDL_Window * window);
   15.10  
   15.11      /* * * */
    16.1 --- a/src/video/SDL_video.c	Mon Feb 14 11:50:18 2011 -0600
    16.2 +++ b/src/video/SDL_video.c	Tue Feb 15 13:59:59 2011 -0800
    16.3 @@ -300,11 +300,15 @@
    16.4  
    16.5      *pixels = data->pixels;
    16.6      *pitch = data->pitch;
    16.7 +
    16.8 +    /* Make sure we're not double-scaling the viewport */
    16.9 +    SDL_RenderSetViewport(data->renderer, NULL);
   16.10 +
   16.11      return 0;
   16.12  }
   16.13  
   16.14  static int
   16.15 -SDL_UpdateWindowTexture(_THIS, SDL_Window * window, int numrects, SDL_Rect * rects)
   16.16 +SDL_UpdateWindowTexture(_THIS, SDL_Window * window, SDL_Rect * rects, int numrects)
   16.17  {
   16.18      SDL_WindowTextureData *data;
   16.19      SDL_Rect rect;
   16.20 @@ -1629,12 +1633,12 @@
   16.21      full_rect.y = 0;
   16.22      full_rect.w = window->w;
   16.23      full_rect.h = window->h;
   16.24 -    return SDL_UpdateWindowSurfaceRects(window, 1, &full_rect);
   16.25 +    return SDL_UpdateWindowSurfaceRects(window, &full_rect, 1);
   16.26  }
   16.27  
   16.28  int
   16.29 -SDL_UpdateWindowSurfaceRects(SDL_Window * window,
   16.30 -                             int numrects, SDL_Rect * rects)
   16.31 +SDL_UpdateWindowSurfaceRects(SDL_Window * window, SDL_Rect * rects,
   16.32 +                             int numrects)
   16.33  {
   16.34      CHECK_WINDOW_MAGIC(window, -1);
   16.35  
   16.36 @@ -1643,7 +1647,7 @@
   16.37          return -1;
   16.38      }
   16.39  
   16.40 -    return _this->UpdateWindowFramebuffer(_this, window, numrects, rects);
   16.41 +    return _this->UpdateWindowFramebuffer(_this, window, rects, numrects);
   16.42  }
   16.43  
   16.44  void
    17.1 --- a/src/video/dummy/SDL_nullframebuffer.c	Mon Feb 14 11:50:18 2011 -0600
    17.2 +++ b/src/video/dummy/SDL_nullframebuffer.c	Tue Feb 15 13:59:59 2011 -0800
    17.3 @@ -56,7 +56,7 @@
    17.4      return 0;
    17.5  }
    17.6  
    17.7 -int SDL_DUMMY_UpdateWindowFramebuffer(_THIS, SDL_Window * window, int numrects, SDL_Rect * rects)
    17.8 +int SDL_DUMMY_UpdateWindowFramebuffer(_THIS, SDL_Window * window, SDL_Rect * rects, int numrects)
    17.9  {
   17.10      static int frame_number;
   17.11      SDL_Surface *surface;
    18.1 --- a/src/video/dummy/SDL_nullframebuffer_c.h	Mon Feb 14 11:50:18 2011 -0600
    18.2 +++ b/src/video/dummy/SDL_nullframebuffer_c.h	Tue Feb 15 13:59:59 2011 -0800
    18.3 @@ -22,7 +22,7 @@
    18.4  #include "SDL_config.h"
    18.5  
    18.6  extern int SDL_DUMMY_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch);
    18.7 -extern int SDL_DUMMY_UpdateWindowFramebuffer(_THIS, SDL_Window * window, int numrects, SDL_Rect * rects);
    18.8 +extern int SDL_DUMMY_UpdateWindowFramebuffer(_THIS, SDL_Window * window, SDL_Rect * rects, int numrects);
    18.9  extern void SDL_DUMMY_DestroyWindowFramebuffer(_THIS, SDL_Window * window);
   18.10  
   18.11  /* vi: set ts=4 sw=4 expandtab: */
    19.1 --- a/src/video/nds/SDL_ndsvideo.c	Mon Feb 14 11:50:18 2011 -0600
    19.2 +++ b/src/video/nds/SDL_ndsvideo.c	Tue Feb 15 13:59:59 2011 -0800
    19.3 @@ -163,8 +163,8 @@
    19.4  	return 0;
    19.5  }
    19.6  
    19.7 -static int NDS_UpdateWindowFramebuffer(_THIS, SDL_Window * window, int numrects,
    19.8 -									   SDL_Rect * rects)
    19.9 +static int NDS_UpdateWindowFramebuffer(_THIS, SDL_Window * window,
   19.10 +									   SDL_Rect * rects, int numrects)
   19.11  {
   19.12  	/* Nothing to do because writes are done directly into the
   19.13  	 * framebuffer. */
    20.1 --- a/src/video/windows/SDL_windowsframebuffer.c	Mon Feb 14 11:50:18 2011 -0600
    20.2 +++ b/src/video/windows/SDL_windowsframebuffer.c	Tue Feb 15 13:59:59 2011 -0800
    20.3 @@ -100,7 +100,7 @@
    20.4      return 0;
    20.5  }
    20.6  
    20.7 -int WIN_UpdateWindowFramebuffer(_THIS, SDL_Window * window, int numrects, SDL_Rect * rects)
    20.8 +int WIN_UpdateWindowFramebuffer(_THIS, SDL_Window * window, SDL_Rect * rects, int numrects)
    20.9  {
   20.10      SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
   20.11  
    21.1 --- a/src/video/windows/SDL_windowsframebuffer.h	Mon Feb 14 11:50:18 2011 -0600
    21.2 +++ b/src/video/windows/SDL_windowsframebuffer.h	Tue Feb 15 13:59:59 2011 -0800
    21.3 @@ -22,7 +22,7 @@
    21.4  #include "SDL_config.h"
    21.5  
    21.6  extern int WIN_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch);
    21.7 -extern int WIN_UpdateWindowFramebuffer(_THIS, SDL_Window * window, int numrects, SDL_Rect * rects);
    21.8 +extern int WIN_UpdateWindowFramebuffer(_THIS, SDL_Window * window, SDL_Rect * rects, int numrects);
    21.9  extern void WIN_DestroyWindowFramebuffer(_THIS, SDL_Window * window);
   21.10  
   21.11  /* vi: set ts=4 sw=4 expandtab: */
    22.1 --- a/src/video/x11/SDL_x11framebuffer.c	Mon Feb 14 11:50:18 2011 -0600
    22.2 +++ b/src/video/x11/SDL_x11framebuffer.c	Tue Feb 15 13:59:59 2011 -0800
    22.3 @@ -147,8 +147,8 @@
    22.4  }
    22.5  
    22.6  int
    22.7 -X11_UpdateWindowFramebuffer(_THIS, SDL_Window * window,
    22.8 -                            int numrects, SDL_Rect * rects)
    22.9 +X11_UpdateWindowFramebuffer(_THIS, SDL_Window * window, SDL_Rect * rects,
   22.10 +                            int numrects)
   22.11  {
   22.12      SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
   22.13      Display *display = data->videodata->display;
    23.1 --- a/src/video/x11/SDL_x11framebuffer.h	Mon Feb 14 11:50:18 2011 -0600
    23.2 +++ b/src/video/x11/SDL_x11framebuffer.h	Tue Feb 15 13:59:59 2011 -0800
    23.3 @@ -26,7 +26,7 @@
    23.4                                         Uint32 * format,
    23.5                                         void ** pixels, int *pitch);
    23.6  extern int X11_UpdateWindowFramebuffer(_THIS, SDL_Window * window,
    23.7 -                                       int numrects, SDL_Rect * rects);
    23.8 +                                       SDL_Rect * rects, int numrects);
    23.9  extern void X11_DestroyWindowFramebuffer(_THIS, SDL_Window * window);
   23.10  
   23.11  /* vi: set ts=4 sw=4 expandtab: */
    24.1 --- a/test/testdraw2.c	Mon Feb 14 11:50:18 2011 -0600
    24.2 +++ b/test/testdraw2.c	Tue Feb 15 13:59:59 2011 -0800
    24.3 @@ -19,14 +19,14 @@
    24.4  static SDL_BlendMode blendMode = SDL_BLENDMODE_NONE;
    24.5  
    24.6  void
    24.7 -DrawPoints(SDL_Window * window, SDL_Renderer * renderer)
    24.8 +DrawPoints(SDL_Renderer * renderer)
    24.9  {
   24.10      int i;
   24.11      int x, y;
   24.12 -    int window_w, window_h;
   24.13 +    SDL_Rect viewport;
   24.14  
   24.15      /* Query the sizes */
   24.16 -    SDL_GetWindowSize(window, &window_w, &window_h);
   24.17 +    SDL_RenderGetViewport(renderer, &viewport);
   24.18  
   24.19      for (i = 0; i < num_objects * 4; ++i) {
   24.20          /* Cycle the color and alpha, if desired */
   24.21 @@ -55,21 +55,21 @@
   24.22          SDL_SetRenderDrawColor(renderer, 255, (Uint8) current_color,
   24.23                                 (Uint8) current_color, (Uint8) current_alpha);
   24.24  
   24.25 -        x = rand() % window_w;
   24.26 -        y = rand() % window_h;
   24.27 +        x = rand() % viewport.w;
   24.28 +        y = rand() % viewport.h;
   24.29          SDL_RenderDrawPoint(renderer, x, y);
   24.30      }
   24.31  }
   24.32  
   24.33  void
   24.34 -DrawLines(SDL_Window * window, SDL_Renderer * renderer)
   24.35 +DrawLines(SDL_Renderer * renderer)
   24.36  {
   24.37      int i;
   24.38      int x1, y1, x2, y2;
   24.39 -    int window_w, window_h;
   24.40 +    SDL_Rect viewport;
   24.41  
   24.42      /* Query the sizes */
   24.43 -    SDL_GetWindowSize(window, &window_w, &window_h);
   24.44 +    SDL_RenderGetViewport(renderer, &viewport);
   24.45  
   24.46      for (i = 0; i < num_objects; ++i) {
   24.47          /* Cycle the color and alpha, if desired */
   24.48 @@ -99,29 +99,29 @@
   24.49                                 (Uint8) current_color, (Uint8) current_alpha);
   24.50  
   24.51          if (i == 0) {
   24.52 -            SDL_RenderDrawLine(renderer, 0, 0, window_w - 1, window_h - 1);
   24.53 -            SDL_RenderDrawLine(renderer, 0, window_h - 1, window_w - 1, 0);
   24.54 -            SDL_RenderDrawLine(renderer, 0, window_h / 2, window_w - 1, window_h / 2);
   24.55 -            SDL_RenderDrawLine(renderer, window_w / 2, 0, window_w / 2, window_h - 1);
   24.56 +            SDL_RenderDrawLine(renderer, 0, 0, viewport.w - 1, viewport.h - 1);
   24.57 +            SDL_RenderDrawLine(renderer, 0, viewport.h - 1, viewport.w - 1, 0);
   24.58 +            SDL_RenderDrawLine(renderer, 0, viewport.h / 2, viewport.w - 1, viewport.h / 2);
   24.59 +            SDL_RenderDrawLine(renderer, viewport.w / 2, 0, viewport.w / 2, viewport.h - 1);
   24.60          } else {
   24.61 -            x1 = (rand() % (window_w*2)) - window_w;
   24.62 -            x2 = (rand() % (window_w*2)) - window_w;
   24.63 -            y1 = (rand() % (window_h*2)) - window_h;
   24.64 -            y2 = (rand() % (window_h*2)) - window_h;
   24.65 +            x1 = (rand() % (viewport.w*2)) - viewport.w;
   24.66 +            x2 = (rand() % (viewport.w*2)) - viewport.w;
   24.67 +            y1 = (rand() % (viewport.h*2)) - viewport.h;
   24.68 +            y2 = (rand() % (viewport.h*2)) - viewport.h;
   24.69              SDL_RenderDrawLine(renderer, x1, y1, x2, y2);
   24.70          }
   24.71      }
   24.72  }
   24.73  
   24.74  void
   24.75 -DrawRects(SDL_Window * window, SDL_Renderer * renderer)
   24.76 +DrawRects(SDL_Renderer * renderer)
   24.77  {
   24.78      int i;
   24.79      SDL_Rect rect;
   24.80 -    int window_w, window_h;
   24.81 +    SDL_Rect viewport;
   24.82  
   24.83      /* Query the sizes */
   24.84 -    SDL_GetWindowSize(window, &window_w, &window_h);
   24.85 +    SDL_RenderGetViewport(renderer, &viewport);
   24.86  
   24.87      for (i = 0; i < num_objects / 4; ++i) {
   24.88          /* Cycle the color and alpha, if desired */
   24.89 @@ -150,10 +150,10 @@
   24.90          SDL_SetRenderDrawColor(renderer, 255, (Uint8) current_color,
   24.91                                 (Uint8) current_color, (Uint8) current_alpha);
   24.92  
   24.93 -        rect.w = rand() % (window_h / 2);
   24.94 -        rect.h = rand() % (window_h / 2);
   24.95 -        rect.x = (rand() % (window_w*2) - window_w) - (rect.w / 2);
   24.96 -        rect.y = (rand() % (window_h*2) - window_h) - (rect.h / 2);
   24.97 +        rect.w = rand() % (viewport.h / 2);
   24.98 +        rect.h = rand() % (viewport.h / 2);
   24.99 +        rect.x = (rand() % (viewport.w*2) - viewport.w) - (rect.w / 2);
  24.100 +        rect.y = (rand() % (viewport.h*2) - viewport.h) - (rect.h / 2);
  24.101          SDL_RenderFillRect(renderer, &rect);
  24.102      }
  24.103  }
  24.104 @@ -243,9 +243,9 @@
  24.105              SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
  24.106              SDL_RenderClear(renderer);
  24.107  
  24.108 -            DrawRects(state->windows[i], renderer);
  24.109 -            DrawLines(state->windows[i], renderer);
  24.110 -            DrawPoints(state->windows[i], renderer);
  24.111 +            DrawRects(renderer);
  24.112 +            DrawLines(renderer);
  24.113 +            DrawPoints(renderer);
  24.114  
  24.115              SDL_RenderPresent(renderer);
  24.116          }
    25.1 --- a/test/testintersections.c	Mon Feb 14 11:50:18 2011 -0600
    25.2 +++ b/test/testintersections.c	Tue Feb 15 13:59:59 2011 -0800
    25.3 @@ -20,14 +20,14 @@
    25.4  static SDL_BlendMode blendMode = SDL_BLENDMODE_NONE;
    25.5  
    25.6  void
    25.7 -DrawPoints(SDL_Window * window, SDL_Renderer * renderer)
    25.8 +DrawPoints(SDL_Renderer * renderer)
    25.9  {
   25.10      int i;
   25.11      int x, y;
   25.12 -    int window_w, window_h;
   25.13 +    SDL_Rect viewport;
   25.14  
   25.15      /* Query the sizes */
   25.16 -    SDL_GetWindowSize(window, &window_w, &window_h);
   25.17 +    SDL_RenderGetViewport(renderer, &viewport);
   25.18  
   25.19      for (i = 0; i < num_objects * 4; ++i) {
   25.20          /* Cycle the color and alpha, if desired */
   25.21 @@ -56,8 +56,8 @@
   25.22          SDL_SetRenderDrawColor(renderer, 255, (Uint8) current_color,
   25.23                                 (Uint8) current_color, (Uint8) current_alpha);
   25.24  
   25.25 -        x = rand() % window_w;
   25.26 -        y = rand() % window_h;
   25.27 +        x = rand() % viewport.w;
   25.28 +        y = rand() % viewport.h;
   25.29          SDL_RenderDrawPoint(renderer, x, y);
   25.30      }
   25.31  }
   25.32 @@ -84,23 +84,23 @@
   25.33  
   25.34  
   25.35  void
   25.36 -DrawLines(SDL_Window * window, SDL_Renderer * renderer)
   25.37 +DrawLines(SDL_Renderer * renderer)
   25.38  {
   25.39      int i;
   25.40      int x1, y1, x2, y2;
   25.41 -    int window_w, window_h;
   25.42 +    SDL_Rect viewport;
   25.43  
   25.44      /* Query the sizes */
   25.45 -    SDL_GetWindowSize(window, &window_w, &window_h);
   25.46 +    SDL_RenderGetViewport(renderer, &viewport);
   25.47 +
   25.48 +    SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
   25.49  
   25.50      for (i = 0; i < num_lines; ++i) {
   25.51 -        SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
   25.52 -
   25.53          if (i == -1) {
   25.54 -            SDL_RenderDrawLine(renderer, 0, 0, window_w - 1, window_h - 1);
   25.55 -            SDL_RenderDrawLine(renderer, 0, window_h - 1, window_w - 1, 0);
   25.56 -            SDL_RenderDrawLine(renderer, 0, window_h / 2, window_w - 1, window_h / 2);
   25.57 -            SDL_RenderDrawLine(renderer, window_w / 2, 0, window_w / 2, window_h - 1);
   25.58 +            SDL_RenderDrawLine(renderer, 0, 0, viewport.w - 1, viewport.h - 1);
   25.59 +            SDL_RenderDrawLine(renderer, 0, viewport.h - 1, viewport.w - 1, 0);
   25.60 +            SDL_RenderDrawLine(renderer, 0, viewport.h / 2, viewport.w - 1, viewport.h / 2);
   25.61 +            SDL_RenderDrawLine(renderer, viewport.w / 2, 0, viewport.w / 2, viewport.h - 1);
   25.62          } else {
   25.63              SDL_RenderDrawLine(renderer, lines[i].x, lines[i].y, lines[i].w, lines[i].h);
   25.64          }
   25.65 @@ -135,27 +135,18 @@
   25.66  }
   25.67  
   25.68  static void
   25.69 -DrawRects(SDL_Window * window, SDL_Renderer * renderer)
   25.70 +DrawRects(SDL_Renderer * renderer)
   25.71  {
   25.72 -    int i;
   25.73 -    int window_w, window_h;
   25.74 -
   25.75 -    /* Query the sizes */
   25.76 -    SDL_GetWindowSize(window, &window_w, &window_h);
   25.77 -
   25.78 -    for (i = 0; i < num_rects; ++i) {
   25.79 -        SDL_SetRenderDrawColor(renderer, 255, 127, 0, 255);
   25.80 -        SDL_RenderFillRect(renderer, &rects[i]);
   25.81 -    }
   25.82 +    SDL_SetRenderDrawColor(renderer, 255, 127, 0, 255);
   25.83 +    SDL_RenderFillRects(renderer, rects, num_rects);
   25.84  }
   25.85  
   25.86  static void
   25.87 -DrawRectLineIntersections(SDL_Window * window, SDL_Renderer * renderer)
   25.88 +DrawRectLineIntersections(SDL_Renderer * renderer)
   25.89  {
   25.90 -    int i, j, window_w, window_h;
   25.91 +    int i, j;
   25.92  
   25.93 -    /* Query the sizes */
   25.94 -    SDL_GetWindowSize(window, &window_w, &window_h);
   25.95 +    SDL_SetRenderDrawColor(renderer, 0, 255, 55, 255);
   25.96  
   25.97      for (i = 0; i < num_rects; i++)
   25.98          for (j = 0; j < num_lines; j++) {
   25.99 @@ -169,22 +160,22 @@
  25.100              y2 = lines[j].h;
  25.101  
  25.102              if (SDL_IntersectRectAndLine(&r, &x1, &y1, &x2, &y2)) {
  25.103 -                SDL_SetRenderDrawColor(renderer, 0, 255, 55, 255);
  25.104                  SDL_RenderDrawLine(renderer, x1, y1, x2, y2);
  25.105              }
  25.106          }
  25.107  }
  25.108  
  25.109  static void
  25.110 -DrawRectRectIntersections(SDL_Window * window, SDL_Renderer * renderer)
  25.111 +DrawRectRectIntersections(SDL_Renderer * renderer)
  25.112  {
  25.113      int i, j;
  25.114  
  25.115 +    SDL_SetRenderDrawColor(renderer, 255, 200, 0, 255);
  25.116 +
  25.117      for (i = 0; i < num_rects; i++)
  25.118          for (j = i + 1; j < num_rects; j++) {
  25.119              SDL_Rect r;
  25.120              if (SDL_IntersectRect(&rects[i], &rects[j], &r)) {
  25.121 -                SDL_SetRenderDrawColor(renderer, 255, 200, 0, 255);
  25.122                  SDL_RenderFillRect(renderer, &r);
  25.123              }
  25.124          }
  25.125 @@ -310,11 +301,11 @@
  25.126              SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
  25.127              SDL_RenderClear(renderer);
  25.128  
  25.129 -            DrawRects(state->windows[i], renderer);
  25.130 -            DrawPoints(state->windows[i], renderer);
  25.131 -            DrawRectRectIntersections(state->windows[i], renderer);
  25.132 -            DrawLines(state->windows[i], renderer);
  25.133 -            DrawRectLineIntersections(state->windows[i], renderer);
  25.134 +            DrawRects(renderer);
  25.135 +            DrawPoints(renderer);
  25.136 +            DrawRectRectIntersections(renderer);
  25.137 +            DrawLines(renderer);
  25.138 +            DrawRectLineIntersections(renderer);
  25.139  
  25.140              SDL_RenderPresent(renderer);
  25.141          }
    26.1 --- a/test/testscale.c	Mon Feb 14 11:50:18 2011 -0600
    26.2 +++ b/test/testscale.c	Tue Feb 15 13:59:59 2011 -0800
    26.3 @@ -82,9 +82,9 @@
    26.4  void
    26.5  Draw(DrawState *s)
    26.6  {
    26.7 -    int w, h;
    26.8 +    SDL_Rect viewport;
    26.9  
   26.10 -    SDL_GetWindowSize(s->window, &w, &h);
   26.11 +    SDL_RenderGetViewport(s->renderer, &viewport);
   26.12  
   26.13      /* Draw the background */
   26.14      SDL_RenderCopy(s->renderer, s->background, NULL, NULL);
   26.15 @@ -93,7 +93,7 @@
   26.16      s->sprite_rect.w += s->scale_direction;
   26.17      s->sprite_rect.h += s->scale_direction;
   26.18      if (s->scale_direction > 0) {
   26.19 -        if (s->sprite_rect.w >= w || s->sprite_rect.h >= h) {
   26.20 +        if (s->sprite_rect.w >= viewport.w || s->sprite_rect.h >= viewport.h) {
   26.21              s->scale_direction = -1;
   26.22          }
   26.23      } else {
   26.24 @@ -101,8 +101,8 @@
   26.25              s->scale_direction = 1;
   26.26          }
   26.27      }
   26.28 -    s->sprite_rect.x = (w - s->sprite_rect.w) / 2;
   26.29 -    s->sprite_rect.y = (h - s->sprite_rect.h) / 2;
   26.30 +    s->sprite_rect.x = (viewport.w - s->sprite_rect.w) / 2;
   26.31 +    s->sprite_rect.y = (viewport.h - s->sprite_rect.h) / 2;
   26.32  
   26.33      SDL_RenderCopy(s->renderer, s->sprite, NULL, &s->sprite_rect);
   26.34  
    27.1 --- a/test/testsprite2.c	Mon Feb 14 11:50:18 2011 -0600
    27.2 +++ b/test/testsprite2.c	Tue Feb 15 13:59:59 2011 -0800
    27.3 @@ -92,15 +92,14 @@
    27.4  }
    27.5  
    27.6  void
    27.7 -MoveSprites(SDL_Window * window, SDL_Renderer * renderer, SDL_Texture * sprite)
    27.8 +MoveSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
    27.9  {
   27.10      int i, n;
   27.11 -    int window_w, window_h;
   27.12 -    SDL_Rect temp;
   27.13 +    SDL_Rect viewport, temp;
   27.14      SDL_Rect *position, *velocity;
   27.15  
   27.16      /* Query the sizes */
   27.17 -    SDL_GetWindowSize(window, &window_w, &window_h);
   27.18 +    SDL_RenderGetViewport(renderer, &viewport);
   27.19  
   27.20      /* Cycle the color and alpha, if desired */
   27.21      if (cycle_color) {
   27.22 @@ -136,16 +135,16 @@
   27.23      /* Test points */
   27.24      SDL_SetRenderDrawColor(renderer, 0xFF, 0x00, 0x00, 0xFF);
   27.25      SDL_RenderDrawPoint(renderer, 0, 0);
   27.26 -    SDL_RenderDrawPoint(renderer, window_w-1, 0);
   27.27 -    SDL_RenderDrawPoint(renderer, 0, window_h-1);
   27.28 -    SDL_RenderDrawPoint(renderer, window_w-1, window_h-1);
   27.29 +    SDL_RenderDrawPoint(renderer, viewport.w-1, 0);
   27.30 +    SDL_RenderDrawPoint(renderer, 0, viewport.h-1);
   27.31 +    SDL_RenderDrawPoint(renderer, viewport.w-1, viewport.h-1);
   27.32  
   27.33      /* Test horizontal and vertical lines */
   27.34      SDL_SetRenderDrawColor(renderer, 0x00, 0xFF, 0x00, 0xFF);
   27.35 -    SDL_RenderDrawLine(renderer, 1, 0, window_w-2, 0);
   27.36 -    SDL_RenderDrawLine(renderer, 1, window_h-1, window_w-2, window_h-1);
   27.37 -    SDL_RenderDrawLine(renderer, 0, 1, 0, window_h-2);
   27.38 -    SDL_RenderDrawLine(renderer, window_w-1, 1, window_w-1, window_h-2);
   27.39 +    SDL_RenderDrawLine(renderer, 1, 0, viewport.w-2, 0);
   27.40 +    SDL_RenderDrawLine(renderer, 1, viewport.h-1, viewport.w-2, viewport.h-1);
   27.41 +    SDL_RenderDrawLine(renderer, 0, 1, 0, viewport.h-2);
   27.42 +    SDL_RenderDrawLine(renderer, viewport.w-1, 1, viewport.w-1, viewport.h-2);
   27.43  
   27.44      /* Test fill and copy */
   27.45      SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
   27.46 @@ -155,20 +154,20 @@
   27.47      temp.h = sprite_h;
   27.48      SDL_RenderFillRect(renderer, &temp);
   27.49      SDL_RenderCopy(renderer, sprite, NULL, &temp);
   27.50 -    temp.x = window_w-sprite_w-1;
   27.51 +    temp.x = viewport.w-sprite_w-1;
   27.52      temp.y = 1;
   27.53      temp.w = sprite_w;
   27.54      temp.h = sprite_h;
   27.55      SDL_RenderFillRect(renderer, &temp);
   27.56      SDL_RenderCopy(renderer, sprite, NULL, &temp);
   27.57      temp.x = 1;
   27.58 -    temp.y = window_h-sprite_h-1;
   27.59 +    temp.y = viewport.h-sprite_h-1;
   27.60      temp.w = sprite_w;
   27.61      temp.h = sprite_h;
   27.62      SDL_RenderFillRect(renderer, &temp);
   27.63      SDL_RenderCopy(renderer, sprite, NULL, &temp);
   27.64 -    temp.x = window_w-sprite_w-1;
   27.65 -    temp.y = window_h-sprite_h-1;
   27.66 +    temp.x = viewport.w-sprite_w-1;
   27.67 +    temp.y = viewport.h-sprite_h-1;
   27.68      temp.w = sprite_w;
   27.69      temp.h = sprite_h;
   27.70      SDL_RenderFillRect(renderer, &temp);
   27.71 @@ -177,9 +176,9 @@
   27.72      /* Test diagonal lines */
   27.73      SDL_SetRenderDrawColor(renderer, 0x00, 0xFF, 0x00, 0xFF);
   27.74      SDL_RenderDrawLine(renderer, sprite_w, sprite_h,
   27.75 -                       window_w-sprite_w-2, window_h-sprite_h-2);
   27.76 -    SDL_RenderDrawLine(renderer, window_w-sprite_w-2, sprite_h,
   27.77 -                       sprite_w, window_h-sprite_h-2);
   27.78 +                       viewport.w-sprite_w-2, viewport.h-sprite_h-2);
   27.79 +    SDL_RenderDrawLine(renderer, viewport.w-sprite_w-2, sprite_h,
   27.80 +                       sprite_w, viewport.h-sprite_h-2);
   27.81  
   27.82      /* Move the sprite, bounce at the wall, and draw */
   27.83      n = 0;
   27.84 @@ -187,12 +186,12 @@
   27.85          position = &positions[i];
   27.86          velocity = &velocities[i];
   27.87          position->x += velocity->x;
   27.88 -        if ((position->x < 0) || (position->x >= (window_w - sprite_w))) {
   27.89 +        if ((position->x < 0) || (position->x >= (viewport.w - sprite_w))) {
   27.90              velocity->x = -velocity->x;
   27.91              position->x += velocity->x;
   27.92          }
   27.93          position->y += velocity->y;
   27.94 -        if ((position->y < 0) || (position->y >= (window_h - sprite_h))) {
   27.95 +        if ((position->y < 0) || (position->y >= (viewport.h - sprite_h))) {
   27.96              velocity->y = -velocity->y;
   27.97              position->y += velocity->y;
   27.98          }
   27.99 @@ -313,7 +312,7 @@
  27.100              CommonEvent(state, &event, &done);
  27.101          }
  27.102          for (i = 0; i < state->num_windows; ++i) {
  27.103 -            MoveSprites(state->windows[i], state->renderers[i], sprites[i]);
  27.104 +            MoveSprites(state->renderers[i], sprites[i]);
  27.105          }
  27.106      }
  27.107