src/render/software/SDL_render_sw.c
changeset 7239 04dda95ba22c
parent 7141 e276777b4247
child 7322 5b94da2650a6
     1.1 --- a/src/render/software/SDL_render_sw.c	Mon May 27 21:44:16 2013 -0700
     1.2 +++ b/src/render/software/SDL_render_sw.c	Wed May 29 03:07:55 2013 -0700
     1.3 @@ -39,6 +39,7 @@
     1.4  static SDL_Renderer *SW_CreateRenderer(SDL_Window * window, Uint32 flags);
     1.5  static void SW_WindowEvent(SDL_Renderer * renderer,
     1.6                             const SDL_WindowEvent *event);
     1.7 +static int SW_GetOutputSize(SDL_Renderer * renderer, int *w, int *h);
     1.8  static int SW_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
     1.9  static int SW_SetTextureColorMod(SDL_Renderer * renderer,
    1.10                                   SDL_Texture * texture);
    1.11 @@ -110,9 +111,14 @@
    1.12          data->surface = data->window;
    1.13      }
    1.14      if (!data->surface) {
    1.15 -        data->surface = data->window = SDL_GetWindowSurface(renderer->window);
    1.16 +        SDL_Surface *surface = SDL_GetWindowSurface(renderer->window);
    1.17 +        if (surface) {
    1.18 +            data->surface = data->window = surface;
    1.19 +            renderer->viewport.w = surface->w;
    1.20 +            renderer->viewport.h = surface->h;
    1.21  
    1.22 -        SW_UpdateViewport(renderer);
    1.23 +            SW_UpdateViewport(renderer);
    1.24 +        }
    1.25      }
    1.26      return data->surface;
    1.27  }
    1.28 @@ -143,6 +149,7 @@
    1.29      data->surface = surface;
    1.30  
    1.31      renderer->WindowEvent = SW_WindowEvent;
    1.32 +    renderer->GetOutputSize = SW_GetOutputSize;
    1.33      renderer->CreateTexture = SW_CreateTexture;
    1.34      renderer->SetTextureColorMod = SW_SetTextureColorMod;
    1.35      renderer->SetTextureAlphaMod = SW_SetTextureAlphaMod;
    1.36 @@ -195,6 +202,25 @@
    1.37  }
    1.38  
    1.39  static int
    1.40 +SW_GetOutputSize(SDL_Renderer * renderer, int *w, int *h)
    1.41 +{
    1.42 +    SDL_Surface *surface = SW_ActivateRenderer(renderer);
    1.43 +
    1.44 +    if (surface) {
    1.45 +        if (w) {
    1.46 +            *w = surface->w;
    1.47 +        }
    1.48 +        if (h) {
    1.49 +            *h = surface->h;
    1.50 +        }
    1.51 +        return 0;
    1.52 +    } else {
    1.53 +        SDL_SetError("Software renderer doesn't have an output surface");
    1.54 +        return -1;
    1.55 +    }
    1.56 +}
    1.57 +
    1.58 +static int
    1.59  SW_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
    1.60  {
    1.61      int bpp;
    1.62 @@ -313,11 +339,6 @@
    1.63          return 0;
    1.64      }
    1.65  
    1.66 -    if (!renderer->viewport.w && !renderer->viewport.h) {
    1.67 -        /* There may be no window, so update the viewport directly */
    1.68 -        renderer->viewport.w = surface->w;
    1.69 -        renderer->viewport.h = surface->h;
    1.70 -    }
    1.71      SDL_SetClipRect(data->surface, &renderer->viewport);
    1.72      return 0;
    1.73  }