Skip to content

Commit 3e65b58

Browse files
authored
standardize usage of video_driver_update_viewport (#18481)
1 parent f0d57b9 commit 3e65b58

File tree

12 files changed

+65
-197
lines changed

12 files changed

+65
-197
lines changed

gfx/drivers/d3d10.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1453,7 +1453,7 @@ static void d3d10_gfx_set_rotation(void* data, unsigned rotation)
14531453
static void d3d10_update_viewport(d3d10_video_t *d3d10, bool force_full)
14541454
{
14551455
video_driver_update_viewport(&d3d10->vp, force_full,
1456-
(d3d10->flags & D3D10_ST_FLAG_KEEP_ASPECT) ? true : false);
1456+
(d3d10->flags & D3D10_ST_FLAG_KEEP_ASPECT) ? true : false, true);
14571457

14581458
d3d10->frame.viewport.TopLeftX = d3d10->vp.x;
14591459
d3d10->frame.viewport.TopLeftY = d3d10->vp.y;

gfx/drivers/d3d11.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1717,7 +1717,7 @@ static void d3d11_gfx_set_rotation(void* data, unsigned rotation)
17171717
static void d3d11_update_viewport(d3d11_video_t *d3d11, bool force_full)
17181718
{
17191719
video_driver_update_viewport(&d3d11->vp, force_full,
1720-
(d3d11->flags & D3D11_ST_FLAG_KEEP_ASPECT) ? true : false);
1720+
(d3d11->flags & D3D11_ST_FLAG_KEEP_ASPECT) ? true : false, true);
17211721

17221722
d3d11->frame.viewport.TopLeftX = d3d11->vp.x;
17231723
d3d11->frame.viewport.TopLeftY = d3d11->vp.y;

gfx/drivers/d3d12.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1978,7 +1978,7 @@ static void d3d12_gfx_set_rotation(void* data, unsigned rotation)
19781978
static void d3d12_update_viewport(d3d12_video_t *d3d12, bool force_full)
19791979
{
19801980
video_driver_update_viewport(&d3d12->vp, force_full,
1981-
(d3d12->flags & D3D12_ST_FLAG_KEEP_ASPECT) ? true : false);
1981+
(d3d12->flags & D3D12_ST_FLAG_KEEP_ASPECT) ? true : false, true);
19821982

19831983
d3d12->frame.viewport.TopLeftX = d3d12->vp.x;
19841984
d3d12->frame.viewport.TopLeftY = d3d12->vp.y;

gfx/drivers/gl1.c

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,45 +1302,19 @@ static void gl1_set_viewport(gl1_t *gl1,
13021302
unsigned vp_width, unsigned vp_height,
13031303
bool force_full, bool allow_rotate)
13041304
{
1305-
settings_t *settings = config_get_ptr();
1306-
float device_aspect = (float)vp_width / vp_height;
1307-
1308-
if (gl1->ctx_driver->translate_aspect)
1309-
device_aspect = gl1->ctx_driver->translate_aspect(
1310-
gl1->ctx_data, vp_width, vp_height);
1311-
1312-
if (settings->bools.video_scale_integer && !force_full)
1313-
{
1314-
video_viewport_get_scaled_integer(&gl1->vp,
1315-
vp_width, vp_height,
1316-
video_driver_get_aspect_ratio(),
1317-
gl1->flags & GL1_FLAG_KEEP_ASPECT, false);
1318-
vp_width = gl1->vp.width;
1319-
vp_height = gl1->vp.height;
1320-
}
1321-
else if ((gl1->flags & GL1_FLAG_KEEP_ASPECT) && !force_full)
1322-
{
1323-
gl1->vp.full_height = gl1->video_height;
1324-
video_viewport_get_scaled_aspect2(&gl1->vp, vp_width, vp_height,
1325-
false, device_aspect, video_driver_get_aspect_ratio());
1326-
vp_width = gl1->vp.width;
1327-
vp_height = gl1->vp.height;
1328-
}
1329-
else
1330-
{
1331-
gl1->vp.x = gl1->vp.y = 0;
1332-
gl1->vp.width = vp_width;
1333-
gl1->vp.height = vp_height;
1334-
}
1305+
gl1->vp.full_width = vp_width;
1306+
gl1->vp.full_height = vp_height;
1307+
video_driver_update_viewport(&gl1->vp, force_full,
1308+
(gl1->flags & GL1_FLAG_KEEP_ASPECT) ? true : false, false);
13351309

13361310
glViewport(gl1->vp.x, gl1->vp.y, gl1->vp.width, gl1->vp.height);
13371311
gl1_set_projection(gl1, &gl1_default_ortho, allow_rotate);
13381312

13391313
/* Set last backbuffer viewport. */
13401314
if (!force_full)
13411315
{
1342-
gl1->out_vp_width = vp_width;
1343-
gl1->out_vp_height = vp_height;
1316+
gl1->out_vp_width = gl1->vp.width;
1317+
gl1->out_vp_height = gl1->vp.height;
13441318
}
13451319
}
13461320

gfx/drivers/gl2.c

Lines changed: 21 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,7 @@ static const GLfloat white_color[16] = {
320320
*/
321321
static void gl2_set_viewport(gl2_t *gl,
322322
unsigned vp_width, unsigned vp_height,
323-
bool force_full, bool allow_rotate,
324-
bool video_scale_integer);
323+
bool force_full, bool allow_rotate);
325324

326325
#ifdef IOS
327326
/* There is no default frame buffer on iOS. */
@@ -947,7 +946,7 @@ static void gl2_raster_font_setup_viewport(
947946
bool full_screen,
948947
bool video_scale_integer)
949948
{
950-
gl2_set_viewport(gl, width, height, full_screen, true, video_scale_integer);
949+
gl2_set_viewport(gl, width, height, full_screen, true);
951950

952951
glEnable(GL_BLEND);
953952
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@@ -1059,7 +1058,7 @@ static void gl2_raster_font_render_msg(
10591058
/* Restore viewport */
10601059
glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]);
10611060
glDisable(GL_BLEND);
1062-
gl2_set_viewport(gl, width, height, false, true, video_scale_integer);
1061+
gl2_set_viewport(gl, width, height, false, true);
10631062
}
10641063
}
10651064

@@ -1091,7 +1090,7 @@ static void gl2_raster_font_flush_block(unsigned width, unsigned height,
10911090
glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]);
10921091

10931092
glDisable(GL_BLEND);
1094-
gl2_set_viewport(gl, width, height, block->fullscreen, true, video_scale_integer);
1093+
gl2_set_viewport(gl, width, height, block->fullscreen, true);
10951094
}
10961095

10971096
static void gl2_raster_font_bind_block(void *data, void *userdata)
@@ -1274,48 +1273,21 @@ static void gl2_set_projection(gl2_t *gl,
12741273
static void gl2_set_viewport(gl2_t *gl,
12751274
unsigned vp_width,
12761275
unsigned vp_height,
1277-
bool force_full, bool allow_rotate,
1278-
bool video_scale_integer)
1276+
bool force_full, bool allow_rotate)
12791277
{
1280-
float device_aspect = (float)vp_width / (float)vp_height;
1281-
1282-
if (gl->ctx_driver->translate_aspect)
1283-
device_aspect = gl->ctx_driver->translate_aspect(
1284-
gl->ctx_data, vp_width, vp_height);
1285-
1286-
if (video_scale_integer && !force_full)
1287-
{
1288-
video_viewport_get_scaled_integer(&gl->vp,
1289-
vp_width, vp_height,
1290-
video_driver_get_aspect_ratio(),
1291-
(gl->flags & GL2_FLAG_KEEP_ASPECT) ? true : false,
1292-
false);
1293-
vp_width = gl->vp.width;
1294-
vp_height = gl->vp.height;
1295-
}
1296-
else if ((gl->flags & GL2_FLAG_KEEP_ASPECT) && !force_full)
1297-
{
1298-
gl->vp.full_height = gl->video_height;
1299-
video_viewport_get_scaled_aspect2(&gl->vp, vp_width, vp_height,
1300-
false, device_aspect, video_driver_get_aspect_ratio());
1301-
vp_width = gl->vp.width;
1302-
vp_height = gl->vp.height;
1303-
}
1304-
else
1305-
{
1306-
gl->vp.x = gl->vp.y = 0;
1307-
gl->vp.width = vp_width;
1308-
gl->vp.height = vp_height;
1309-
}
1278+
gl->vp.full_width = vp_width;
1279+
gl->vp.full_height = vp_height;
1280+
video_driver_update_viewport(&gl->vp, force_full,
1281+
(gl->flags & GL2_FLAG_KEEP_ASPECT) ? true : false, false);
13101282

13111283
glViewport(gl->vp.x, gl->vp.y, gl->vp.width, gl->vp.height);
13121284
gl2_set_projection(gl, &default_ortho, allow_rotate);
13131285

13141286
/* Set last backbuffer viewport. */
13151287
if (!force_full)
13161288
{
1317-
gl->out_vp_width = vp_width;
1318-
gl->out_vp_height = vp_height;
1289+
gl->out_vp_width = gl->vp.width;
1290+
gl->out_vp_height = gl->vp.height;
13191291
}
13201292
}
13211293

@@ -1382,8 +1354,7 @@ static void gl2_renderchain_render(
13821354

13831355
/* Render to FBO with certain size. */
13841356
gl2_set_viewport(gl,
1385-
rect->img_width, rect->img_height, true, false,
1386-
video_scale_integer);
1357+
rect->img_width, rect->img_height, true, false);
13871358

13881359
params.vp_width = gl->out_vp_width;
13891360
params.vp_height = gl->out_vp_height;
@@ -1449,7 +1420,7 @@ static void gl2_renderchain_render(
14491420
glGenerateMipmap(GL_TEXTURE_2D);
14501421

14511422
glClear(GL_COLOR_BUFFER_BIT);
1452-
gl2_set_viewport(gl, width, height, false, true, video_scale_integer);
1423+
gl2_set_viewport(gl, width, height, false, true);
14531424

14541425
params.vp_width = gl->out_vp_width;
14551426
params.vp_height = gl->out_vp_height;
@@ -1866,8 +1837,7 @@ static void gl2_renderchain_start_render(gl2_t *gl,
18661837

18671838
gl2_set_viewport(gl,
18681839
gl->fbo_rect[0].img_width,
1869-
gl->fbo_rect[0].img_height, true, false,
1870-
video_scale_integer);
1840+
gl->fbo_rect[0].img_height, true, false);
18711841

18721842
/* Need to preserve the "flipped" state when in FBO
18731843
* as well to have consistent texture coordinates.
@@ -2768,10 +2738,7 @@ static void gl2_set_viewport_wrapper(void *data, unsigned vp_width,
27682738
unsigned vp_height, bool force_full, bool allow_rotate)
27692739
{
27702740
gl2_t *gl = (gl2_t*)data;
2771-
gl2_set_viewport(gl,
2772-
vp_width, vp_height, force_full, allow_rotate,
2773-
config_get_ptr()->bools.video_scale_integer
2774-
);
2741+
gl2_set_viewport(gl, vp_width, vp_height, force_full, allow_rotate);
27752742
}
27762743

27772744
/* Shaders */
@@ -3105,8 +3072,7 @@ static INLINE void gl2_set_shader_viewports(gl2_t *gl, bool video_scale_integer)
31053072
for (i = 0; i < 2; i++)
31063073
{
31073074
gl->shader->use(gl, gl->shader_data, i, true);
3108-
gl2_set_viewport(gl, width, height, false, true,
3109-
video_scale_integer);
3075+
gl2_set_viewport(gl, width, height, false, true);
31103076
}
31113077
}
31123078

@@ -3220,8 +3186,7 @@ static void gl2_render_osd_background(gl2_t *gl, bool video_scale_integer, const
32203186

32213187
gl2_set_viewport(gl,
32223188
gl->video_width,
3223-
gl->video_height, true, false,
3224-
video_scale_integer);
3189+
gl->video_height, true, false);
32253190

32263191
gl->shader->use(gl, gl->shader_data,
32273192
VIDEO_SHADER_STOCK_BLEND, true);
@@ -3269,7 +3234,7 @@ static void gl2_render_osd_background(gl2_t *gl, bool video_scale_integer, const
32693234

32703235
gl2_set_viewport(gl,
32713236
gl->video_width,
3272-
gl->video_height, false, true, video_scale_integer);
3237+
gl->video_height, false, true);
32733238
}
32743239

32753240
static void gl2_show_mouse(void *data, bool state)
@@ -3415,7 +3380,7 @@ static bool gl2_frame(void *data, const void *frame,
34153380

34163381
#ifdef IOS
34173382
/* Apparently the viewport is lost each frame, thanks Apple. */
3418-
gl2_set_viewport(gl, width, height, false, true, video_scale_integer);
3383+
gl2_set_viewport(gl, width, height, false, true);
34193384
#endif
34203385

34213386
/* Render to texture in first pass. */
@@ -3490,7 +3455,7 @@ static bool gl2_frame(void *data, const void *frame,
34903455
gl2_renderchain_start_render(gl, chain, video_scale_integer);
34913456
}
34923457
else
3493-
gl2_set_viewport(gl, width, height, false, true, video_scale_integer);
3458+
gl2_set_viewport(gl, width, height, false, true);
34943459
}
34953460

34963461
if (frame)
@@ -3524,7 +3489,7 @@ static bool gl2_frame(void *data, const void *frame,
35243489
if (!(gl->flags & GL2_FLAG_FBO_INITED))
35253490
{
35263491
gl2_renderchain_bind_backbuffer();
3527-
gl2_set_viewport(gl, width, height, false, true, video_scale_integer);
3492+
gl2_set_viewport(gl, width, height, false, true);
35283493
}
35293494

35303495
gl2_renderchain_restore_default_state(gl);

gfx/drivers/gl3.c

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,51 +1926,24 @@ static void gl3_set_viewport(gl3_t *gl,
19261926
unsigned vp_width, unsigned vp_height,
19271927
bool force_full, bool allow_rotate)
19281928
{
1929-
settings_t *settings = config_get_ptr();
1930-
float device_aspect = (float)vp_width / vp_height;
1931-
bool video_scale_integer = settings->bools.video_scale_integer;
1932-
1933-
if (gl->ctx_driver->translate_aspect)
1934-
device_aspect = gl->ctx_driver->translate_aspect(
1935-
gl->ctx_data, vp_width, vp_height);
1936-
1937-
if (video_scale_integer && !force_full)
1938-
{
1939-
video_viewport_get_scaled_integer(&gl->vp,
1940-
vp_width, vp_height,
1941-
video_driver_get_aspect_ratio(),
1942-
(gl->flags & GL3_FLAG_KEEP_ASPECT) ? true : false,
1943-
false);
1944-
vp_width = gl->vp.width;
1945-
vp_height = gl->vp.height;
1946-
}
1947-
else if ((gl->flags & GL3_FLAG_KEEP_ASPECT) && !force_full)
1948-
{
1949-
gl->vp.full_height = gl->video_height;
1950-
video_viewport_get_scaled_aspect2(&gl->vp, vp_width, vp_height, false, device_aspect, video_driver_get_aspect_ratio());
1951-
vp_width = gl->vp.width;
1952-
vp_height = gl->vp.height;
1953-
}
1954-
else
1955-
{
1956-
gl->vp.x = gl->vp.y = 0;
1957-
gl->vp.width = vp_width;
1958-
gl->vp.height = vp_height;
1959-
}
1929+
gl->vp.full_width = vp_width;
1930+
gl->vp.full_height = vp_height;
1931+
video_driver_update_viewport(&gl->vp, force_full,
1932+
(gl->flags & GL3_FLAG_KEEP_ASPECT) ? true : false, false);
19601933

19611934
glViewport(gl->vp.x, gl->vp.y, gl->vp.width, gl->vp.height);
19621935
gl3_set_projection(gl, &gl3_default_ortho, allow_rotate);
19631936

19641937
/* Set last backbuffer viewport. */
19651938
if (!force_full)
19661939
{
1967-
gl->out_vp_width = vp_width;
1968-
gl->out_vp_height = vp_height;
1940+
gl->out_vp_width = gl->vp.width;
1941+
gl->out_vp_height = gl->vp.height;
19691942
}
19701943

1971-
gl->filter_chain_vp.x = gl->vp.x;
1972-
gl->filter_chain_vp.y = gl->vp.y;
1973-
gl->filter_chain_vp.width = gl->vp.width;
1944+
gl->filter_chain_vp.x = gl->vp.x;
1945+
gl->filter_chain_vp.y = gl->vp.y;
1946+
gl->filter_chain_vp.width = gl->vp.width;
19741947
gl->filter_chain_vp.height = gl->vp.height;
19751948
}
19761949

gfx/drivers/metal.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ - (void)setViewportWidth:(unsigned)width height:(unsigned)height forceFull:(BOOL
916916
_viewport->full_height = height;
917917
video_driver_set_size(_viewport->full_width, _viewport->full_height);
918918
_layer.drawableSize = CGSizeMake(width, height);
919-
video_driver_update_viewport(_viewport, forceFull, _keepAspect);
919+
video_driver_update_viewport(_viewport, forceFull, _keepAspect, YES);
920920
_context.viewport = _viewport; /* Update matrix */
921921
_viewportMVP.outputSize = simd_make_float2(_viewport->full_width, _viewport->full_height);
922922
}
@@ -1033,7 +1033,7 @@ - (void)_renderMessage:(const char *)msg
10331033
- (void)_beginFrame
10341034
{
10351035
video_viewport_t vp = *_viewport;
1036-
video_driver_update_viewport(_viewport, NO, _keepAspect);
1036+
video_driver_update_viewport(_viewport, NO, _keepAspect, YES);
10371037

10381038
if (memcmp(&vp, _viewport, sizeof(vp)) != 0)
10391039
_context.viewport = _viewport;

gfx/drivers/sdl2_gfx.c

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -227,24 +227,12 @@ static void sdl_refresh_renderer(sdl2_video_t *vid)
227227
static void sdl_refresh_viewport(sdl2_video_t *vid)
228228
{
229229
int win_w, win_h;
230-
settings_t *settings = config_get_ptr();
231-
bool video_scale_integer = settings->bools.video_scale_integer;
232230

233231
SDL_GetWindowSize(vid->window, &win_w, &win_h);
234232

235-
vid->vp.x = 0;
236-
vid->vp.y = 0;
237-
vid->vp.width = win_w;
238-
vid->vp.height = win_h;
239233
vid->vp.full_width = win_w;
240234
vid->vp.full_height = win_h;
241-
242-
if (video_scale_integer)
243-
video_viewport_get_scaled_integer(&vid->vp,
244-
win_w, win_h, video_driver_get_aspect_ratio(),
245-
vid->video.force_aspect, true);
246-
else if (vid->video.force_aspect)
247-
video_viewport_get_scaled_aspect(&vid->vp, win_w, win_h, true);
235+
video_driver_update_viewport(&vid->vp, false, vid->video.force_aspect, true);
248236

249237
vid->flags &= ~SDL2_FLAG_SHOULD_RESIZE;
250238

0 commit comments

Comments
 (0)