src/render/SDL_render.c
changeset 7239 04dda95ba22c
parent 7191 75360622e65f
child 7240 39eb4958950a
     1.1 --- a/src/render/SDL_render.c	Mon May 27 21:44:16 2013 -0700
     1.2 +++ b/src/render/SDL_render.c	Wed May 29 03:07:55 2013 -0700
     1.3 @@ -337,6 +337,25 @@
     1.4      return 0;
     1.5  }
     1.6  
     1.7 +int
     1.8 +SDL_GetRendererOutputSize(SDL_Renderer * renderer, int *w, int *h)
     1.9 +{
    1.10 +    CHECK_RENDERER_MAGIC(renderer, -1);
    1.11 +
    1.12 +    if (renderer->target) {
    1.13 +        return SDL_QueryTexture(renderer->target, NULL, NULL, w, h);
    1.14 +    } else if (renderer->window) {
    1.15 +        SDL_GetWindowSize(renderer->window, w, h);
    1.16 +        return 0;
    1.17 +    } else if (renderer->GetOutputSize) {
    1.18 +        return renderer->GetOutputSize(renderer, w, h);
    1.19 +    } else {
    1.20 +        /* This should never happen */
    1.21 +        SDL_SetError("Renderer doesn't support querying output size");
    1.22 +        return -1;
    1.23 +    }
    1.24 +}
    1.25 +
    1.26  static SDL_bool
    1.27  IsSupportedFormat(SDL_Renderer * renderer, Uint32 format)
    1.28  {
    1.29 @@ -985,13 +1004,8 @@
    1.30      float scale;
    1.31      SDL_Rect viewport;
    1.32  
    1.33 -    if (renderer->target) {
    1.34 -        SDL_QueryTexture(renderer->target, NULL, NULL, &w, &h);
    1.35 -    } else if (renderer->window) {
    1.36 -        SDL_GetWindowSize(renderer->window, &w, &h);
    1.37 -    } else {
    1.38 -        /* FIXME */
    1.39 -        return SDL_SetError("Internal error: No way to get output resolution");
    1.40 +    if (SDL_GetRendererOutputSize(renderer, &w, &h) < 0) {
    1.41 +        return -1;
    1.42      }
    1.43  
    1.44      want_aspect = (float)renderer->logical_w / renderer->logical_h;
    1.45 @@ -1074,16 +1088,8 @@
    1.46      } else {
    1.47          renderer->viewport.x = 0;
    1.48          renderer->viewport.y = 0;
    1.49 -        if (renderer->target) {
    1.50 -            SDL_QueryTexture(renderer->target, NULL, NULL,
    1.51 -                              &renderer->viewport.w, &renderer->viewport.h);
    1.52 -        } else if (renderer->window) {
    1.53 -            SDL_GetWindowSize(renderer->window,
    1.54 -                              &renderer->viewport.w, &renderer->viewport.h);
    1.55 -        } else {
    1.56 -            /* This will be filled in by UpdateViewport() */
    1.57 -            renderer->viewport.w = 0;
    1.58 -            renderer->viewport.h = 0;
    1.59 +        if (SDL_GetRendererOutputSize(renderer, &renderer->viewport.w, &renderer->viewport.h) < 0) {
    1.60 +            return -1;
    1.61          }
    1.62      }
    1.63      return renderer->UpdateViewport(renderer);