| 1936 | } |
| 1937 | |
| 1938 | static int |
| 1939 | UpdateLogicalSize(SDL_Renderer *renderer) |
| 1940 | { |
| 1941 | int w = 1, h = 1; |
| 1942 | float want_aspect; |
| 1943 | float real_aspect; |
| 1944 | float scale; |
| 1945 | SDL_Rect viewport; |
| 1946 | /* 0 is for letterbox, 1 is for overscan */ |
| 1947 | int scale_policy = 0; |
| 1948 | const char *hint; |
| 1949 | |
| 1950 | if (!renderer->logical_w || !renderer->logical_h) { |
| 1951 | return 0; |
| 1952 | } |
| 1953 | if (SDL_GetRendererOutputSize(renderer, &w, &h) < 0) { |
| 1954 | return -1; |
| 1955 | } |
| 1956 | |
| 1957 | hint = SDL_GetHint(SDL_HINT_RENDER_LOGICAL_SIZE_MODE); |
| 1958 | if (hint && (*hint == '1' || SDL_strcasecmp(hint, "overscan") == 0)) { |
| 1959 | #if SDL_VIDEO_RENDER_D3D |
| 1960 | SDL_bool overscan_supported = SDL_TRUE; |
| 1961 | /* Unfortunately, Direct3D 9 doesn't support negative viewport numbers |
| 1962 | which the overscan implementation relies on. |
| 1963 | */ |
| 1964 | if (SDL_strcasecmp(SDL_GetCurrentVideoDriver(), "direct3d") == 0) { |
| 1965 | overscan_supported = SDL_FALSE; |
| 1966 | } |
| 1967 | if (overscan_supported) { |
| 1968 | scale_policy = 1; |
| 1969 | } |
| 1970 | #else |
| 1971 | scale_policy = 1; |
| 1972 | #endif |
| 1973 | } |
| 1974 | |
| 1975 | want_aspect = (float)renderer->logical_w / renderer->logical_h; |
| 1976 | real_aspect = (float)w / h; |
| 1977 | |
| 1978 | /* Clear the scale because we're setting viewport in output coordinates */ |
| 1979 | SDL_RenderSetScale(renderer, 1.0f, 1.0f); |
| 1980 | |
| 1981 | if (renderer->integer_scale) { |
| 1982 | if (want_aspect > real_aspect) { |
| 1983 | scale = (float)(w / renderer->logical_w); |
| 1984 | } else { |
| 1985 | scale = (float)(h / renderer->logical_h); |
| 1986 | } |
| 1987 | viewport.w = (int)SDL_ceil(renderer->logical_w * scale); |
| 1988 | viewport.x = (w - viewport.w) / 2; |
| 1989 | viewport.h = (int)SDL_ceil(renderer->logical_h * scale); |
| 1990 | viewport.y = (h - viewport.h) / 2; |
| 1991 | |
| 1992 | SDL_RenderSetViewport(renderer, &viewport); |
| 1993 | } else if (SDL_fabs(want_aspect-real_aspect) < 0.0001) { |
| 1994 | /* The aspect ratios are the same, just scale appropriately */ |
| 1995 | scale = (float)w / renderer->logical_w; |
no test coverage detected