Skip to content

Commit bfbcbbd

Browse files
committed
standardize usage of video_driver_update_viewport - pt 2
1 parent 3e65b58 commit bfbcbbd

9 files changed

Lines changed: 76 additions & 418 deletions

File tree

gfx/common/d3d9_common.c

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,31 +1327,17 @@ void d3d9_calculate_rect(d3d9_video_t *d3d,
13271327
bool allow_rotate)
13281328
{
13291329
struct video_viewport vp;
1330-
settings_t *settings = config_get_ptr();
1331-
bool video_scale_integer = settings->bools.video_scale_integer;
13321330

13331331
video_driver_get_size(width, height);
13341332

1335-
vp.x = 0;
1336-
vp.y = 0;
1337-
vp.width = *width;
1338-
vp.height = *height;
13391333
vp.full_width = *width;
13401334
vp.full_height = *height;
1335+
video_driver_update_viewport(&vp, force_full, d3d->keep_aspect, true);
13411336

1342-
if (video_scale_integer && !force_full)
1343-
video_viewport_get_scaled_integer(&vp,
1344-
*width,
1345-
*height,
1346-
video_driver_get_aspect_ratio(),
1347-
d3d->keep_aspect,
1348-
true);
1349-
else if (d3d->keep_aspect && !force_full)
1350-
video_viewport_get_scaled_aspect(&vp, *width, *height, true);
1351-
*x = vp.x;
1352-
*y = vp.y;
1353-
*width = vp.width;
1354-
*height = vp.height;
1337+
*x = vp.x;
1338+
*y = vp.y;
1339+
*width = vp.width;
1340+
*height = vp.height;
13551341
}
13561342

13571343
void d3d9_set_rotation(void *data, unsigned rot)

gfx/drivers/ctr_gfx.c

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -904,44 +904,13 @@ static void ctr_free_overlay(ctr_video_t *ctr)
904904
}
905905
#endif
906906

907-
static void ctr_update_viewport(
908-
ctr_video_t* ctr,
909-
settings_t *settings,
910-
int custom_vp_x,
911-
int custom_vp_y,
912-
unsigned custom_vp_width,
913-
unsigned custom_vp_height
914-
)
915-
{
916-
int x = 0;
917-
int y = 0;
918-
float width = ctr->vp.full_width;
919-
float height = ctr->vp.full_height;
920-
float desired_aspect = video_driver_get_aspect_ratio();
921-
bool video_scale_integer = settings->bools.video_scale_integer;
922-
unsigned aspect_ratio_idx = settings->uints.video_aspect_ratio_idx;
923-
924-
if (video_scale_integer)
925-
{
926-
/* TODO: does CTR use top-left or bottom-left coordinates? assuming top-left. */
927-
video_viewport_get_scaled_integer(&ctr->vp, ctr->vp.full_width,
928-
ctr->vp.full_height, desired_aspect, ctr->keep_aspect,
929-
true);
930-
}
931-
else if (ctr->keep_aspect)
932-
video_viewport_get_scaled_aspect(&ctr->vp, width, height, true);
933-
else
934-
{
935-
ctr->vp.x = 0;
936-
ctr->vp.y = 0;
937-
ctr->vp.width = width;
938-
ctr->vp.height = height;
939-
}
907+
static void ctr_update_viewport(ctr_video_t* ctr)
908+
{
909+
video_driver_update_viewport(&ctr->vp, false, ctr->keep_aspect, true);
940910

941911
ctr_set_screen_coords(ctr);
942912

943913
ctr->should_resize = false;
944-
945914
}
946915

947916
static const char *ctr_texture_path(unsigned id)
@@ -2173,12 +2142,7 @@ static bool ctr_frame(void* data, const void* frame,
21732142
#endif
21742143

21752144
if (ctr->should_resize)
2176-
ctr_update_viewport(ctr, settings,
2177-
custom_vp_x,
2178-
custom_vp_y,
2179-
custom_vp_width,
2180-
custom_vp_height
2181-
);
2145+
ctr_update_viewport(ctr);
21822146

21832147
if (ctr->refresh_bottom_menu)
21842148
ctrGuSetMemoryFill(true,

gfx/drivers/d3d8.c

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,34 +1208,18 @@ static void d3d8_calculate_rect(void *data,
12081208
bool allow_rotate)
12091209
{
12101210
struct video_viewport vp;
1211-
float device_aspect = (float)*width / *height;
12121211
d3d8_video_t *d3d = (d3d8_video_t*)data;
1213-
settings_t *settings = config_get_ptr();
1214-
bool video_scale_integer = settings->bools.video_scale_integer;
1215-
unsigned aspect_ratio_idx = settings->uints.video_aspect_ratio_idx;
12161212

12171213
video_driver_get_size(width, height);
12181214

1219-
vp.x = 0;
1220-
vp.y = 0;
1221-
vp.width = *width;
1222-
vp.height = *height;
12231215
vp.full_width = *width;
12241216
vp.full_height = *height;
1217+
video_driver_update_viewport(&vp, force_full, d3d->keep_aspect, true);
12251218

1226-
if (video_scale_integer && !force_full)
1227-
video_viewport_get_scaled_integer(&vp,
1228-
*width,
1229-
*height,
1230-
video_driver_get_aspect_ratio(),
1231-
d3d->keep_aspect,
1232-
true);
1233-
else if (d3d->keep_aspect && !force_full)
1234-
video_viewport_get_scaled_aspect(&vp, *width, *height, true);
1235-
*x = vp.x;
1236-
*y = vp.y;
1237-
*width = vp.width;
1238-
*height = vp.height;
1219+
*x = vp.x;
1220+
*y = vp.y;
1221+
*width = vp.width;
1222+
*height = vp.height;
12391223
}
12401224

12411225
static void d3d8_set_viewport(void *data,

gfx/drivers/gx2_gfx.c

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,28 +1039,9 @@ static void gx2_set_projection(wiiu_video_t *wiiu)
10391039

10401040
static void gx2_update_viewport(wiiu_video_t *wiiu)
10411041
{
1042-
unsigned vp_width = wiiu->color_buffer.surface.width;
1043-
unsigned vp_height = wiiu->color_buffer.surface.height;
1044-
settings_t *settings = config_get_ptr();
1045-
bool video_scale_integer = settings->bools.video_scale_integer;
1046-
1047-
if (video_scale_integer)
1048-
{
1049-
video_viewport_get_scaled_integer(&wiiu->vp,
1050-
vp_width, vp_height,
1051-
video_driver_get_aspect_ratio(), wiiu->keep_aspect, true);
1052-
vp_width = wiiu->vp.width;
1053-
vp_height = wiiu->vp.height;
1054-
}
1055-
else if (wiiu->keep_aspect)
1056-
video_viewport_get_scaled_aspect(&wiiu->vp, vp_width, vp_height, true);
1057-
else
1058-
{
1059-
wiiu->vp.x = 0;
1060-
wiiu->vp.y = 0;
1061-
wiiu->vp.width = vp_width;
1062-
wiiu->vp.height = vp_height;
1063-
}
1042+
wiiu->vp.full_width = wiiu->color_buffer.surface.width;
1043+
wiiu->vp.full_height = wiiu->color_buffer.surface.height;
1044+
video_driver_update_viewport(&wiiu->vp, false, wiiu->keep_aspect, true);
10641045

10651046
gx2_set_projection(wiiu);
10661047
}

gfx/drivers/psp1_gfx.c

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -242,47 +242,20 @@ static INLINE void psp_set_tex_coords (psp1_sprite_t* framecoords,
242242
}
243243
}
244244

245-
static void psp_update_viewport(psp1_video_t* psp,
246-
video_frame_info_t *video_info)
245+
static void psp_update_viewport(psp1_video_t* psp)
247246
{
248-
int x = 0;
249-
int y = 0;
250-
float device_aspect = ((float)SCEGU_SCR_WIDTH) / SCEGU_SCR_HEIGHT;
251-
float width = SCEGU_SCR_WIDTH;
252-
float height = SCEGU_SCR_HEIGHT;
253-
settings_t *settings = config_get_ptr();
254-
bool video_scale_integer = settings->bools.video_scale_integer;
255-
unsigned aspect_ratio_idx = settings->uints.video_aspect_ratio_idx;
256-
257-
if (video_scale_integer)
258-
{
259-
video_viewport_get_scaled_integer(&psp->vp, SCEGU_SCR_WIDTH,
260-
SCEGU_SCR_HEIGHT, video_driver_get_aspect_ratio(), psp->keep_aspect, true);
261-
width = psp->vp.width;
262-
height = psp->vp.height;
263-
}
264-
else if (psp->keep_aspect)
265-
{
266-
video_viewport_get_scaled_aspect(&psp->vp, width, height, true);
267-
width = psp->vp.width;
268-
height = psp->vp.height;
269-
}
270-
else
271-
{
272-
psp->vp.x = 0;
273-
psp->vp.y = 0;
274-
psp->vp.width = width;
275-
psp->vp.height = height;
276-
}
247+
psp->vp.full_width = SCEGU_SCR_WIDTH;
248+
psp->vp.full_height = SCEGU_SCR_HEIGHT;
249+
video_driver_update_viewport(&psp->vp, false, psp->keep_aspect, true);
277250

251+
/* Ensure even dimensions */
278252
psp->vp.width += psp->vp.width & 0x1;
279253
psp->vp.height += psp->vp.height & 0x1;
280254

281255
psp_set_screen_coords(psp->frame_coords, psp->vp.x,
282256
psp->vp.y, psp->vp.width, psp->vp.height, psp->rotation);
283257

284258
psp->should_resize = false;
285-
286259
}
287260

288261

@@ -542,7 +515,7 @@ static bool psp_frame(void *data, const void *frame,
542515
psp->draw_buffer = FROM_GU_POINTER(sceGuSwapBuffers());
543516

544517
if (psp->should_resize)
545-
psp_update_viewport(psp, video_info);
518+
psp_update_viewport(psp);
546519

547520
psp_set_tex_coords(psp->frame_coords, width, height);
548521

gfx/drivers/rsx_gfx.c

Lines changed: 8 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,35 +1140,14 @@ static void rsx_set_projection(rsx_t *rsx,
11401140
static void rsx_set_viewport(void *data, unsigned vp_width, unsigned vp_height,
11411141
bool force_full, bool allow_rotate)
11421142
{
1143-
int i;
1143+
int i;
11441144
rsx_viewport_t vp;
11451145
struct video_ortho ortho = {0, 1, 0, 1, -1, 1};
1146-
settings_t *settings = config_get_ptr();
11471146
rsx_t *rsx = (rsx_t*)data;
1148-
bool video_scale_integer = settings->bools.video_scale_integer;
11491147

1150-
if (video_scale_integer && !force_full)
1151-
{
1152-
video_viewport_get_scaled_integer(&rsx->vp,
1153-
vp_width, vp_height,
1154-
video_driver_get_aspect_ratio(), rsx->keep_aspect,
1155-
true);
1156-
vp_width = rsx->vp.width;
1157-
vp_height = rsx->vp.height;
1158-
}
1159-
else if (rsx->keep_aspect && !force_full)
1160-
{
1161-
video_viewport_get_scaled_aspect(&rsx->vp, vp_width, vp_height, true);
1162-
vp_width = rsx->vp.width;
1163-
vp_height = rsx->vp.height;
1164-
}
1165-
else
1166-
{
1167-
rsx->vp.x = 0;
1168-
rsx->vp.y = 0;
1169-
rsx->vp.width = vp_width;
1170-
rsx->vp.height = vp_height;
1171-
}
1148+
rsx->vp.full_width = vp_width;
1149+
rsx->vp.full_height = vp_height;
1150+
video_driver_update_viewport(&rsx->vp, force_full, rsx->keep_aspect, true);
11721151

11731152
vp.min = 0.0f;
11741153
vp.max = 1.0f;
@@ -1191,13 +1170,6 @@ static void rsx_set_viewport(void *data, unsigned vp_width, unsigned vp_height,
11911170
rsxSetScissor(rsx->context, vp.x, vp.y, vp.w, vp.h);
11921171

11931172
rsx_set_projection(rsx, &ortho, allow_rotate);
1194-
1195-
/* Set last backbuffer viewport. */
1196-
if (!force_full)
1197-
{
1198-
rsx->vp.width = vp_width;
1199-
rsx->vp.height = vp_height;
1200-
}
12011173
}
12021174

12031175
static const gfx_ctx_driver_t* rsx_get_context(rsx_t* rsx)
@@ -1597,81 +1569,11 @@ static void* rsx_init(const video_info_t* video,
15971569

15981570
static void rsx_update_viewport(rsx_t* rsx)
15991571
{
1600-
int x = 0;
1601-
int y = 0;
1602-
unsigned vp_width = rsx->width;
1603-
unsigned vp_height = rsx->height;
1604-
float device_aspect = ((float)vp_width) / vp_height;
1605-
settings_t *settings = config_get_ptr();
1606-
bool video_scale_integer = settings->bools.video_scale_integer;
1607-
unsigned aspect_ratio_idx = settings->uints.video_aspect_ratio_idx;
1608-
1609-
if (video_scale_integer)
1610-
{
1611-
video_viewport_get_scaled_integer(&rsx->vp, vp_width, vp_height,
1612-
video_driver_get_aspect_ratio(), rsx->keep_aspect,
1613-
true);
1614-
vp_width = rsx->vp.width;
1615-
vp_height = rsx->vp.height;
1616-
}
1617-
else if (rsx->keep_aspect)
1618-
{
1619-
float desired_aspect = video_driver_get_aspect_ratio();
1620-
1621-
#if defined(HAVE_MENU)
1622-
if (aspect_ratio_idx == ASPECT_RATIO_CUSTOM)
1623-
{
1624-
video_viewport_t *custom_vp = &settings->video_vp_custom;
1625-
/* RSX/libgcm has top-left origin viewport. */
1626-
x = custom_vp->x;
1627-
y = custom_vp->y;
1628-
vp_width = custom_vp->width;
1629-
vp_height = custom_vp->height;
1630-
}
1631-
else
1632-
#endif
1633-
{
1634-
float delta;
1635-
1636-
if ((fabsf(device_aspect - desired_aspect) < 0.0001f))
1637-
{
1638-
/* If the aspect ratios of screen and desired aspect
1639-
* ratio are sufficiently equal (floating point stuff),
1640-
* assume they are actually equal.
1641-
*/
1642-
}
1643-
else if (device_aspect > desired_aspect)
1644-
{
1645-
float viewport_bias = settings->floats.video_vp_bias_x;
1646-
delta = (desired_aspect / device_aspect - 1.0f)
1647-
/ 2.0f + 0.5f;
1648-
x = (int)roundf(vp_width * ((0.5f - delta) * (viewport_bias * 2.0f)));
1649-
vp_width = (unsigned)roundf(2.0f * vp_width * delta);
1650-
}
1651-
else
1652-
{
1653-
float viewport_bias = 1.0 - settings->floats.video_vp_bias_y;
1654-
delta = (device_aspect / desired_aspect - 1.0f)
1655-
/ 2.0f + 0.5f;
1656-
y = (int)roundf(vp_height * ((0.5f - delta) * (viewport_bias * 2.0f)));
1657-
vp_height = (unsigned)roundf(2.0f * vp_height * delta);
1658-
}
1659-
}
1660-
1661-
rsx->vp.x = x;
1662-
rsx->vp.y = y;
1663-
rsx->vp.width = vp_width;
1664-
rsx->vp.height = vp_height;
1665-
}
1666-
else
1667-
{
1668-
rsx->vp.x = 0;
1669-
rsx->vp.y = 0;
1670-
rsx->vp.width = vp_width;
1671-
rsx->vp.height = vp_height;
1672-
}
1572+
rsx->vp.full_width = rsx->width;
1573+
rsx->vp.full_height = rsx->height;
1574+
video_driver_update_viewport(&rsx->vp, false, rsx->keep_aspect, true);
16731575

1674-
rsx->should_resize = false;
1576+
rsx->should_resize = false;
16751577
}
16761578

16771579
static unsigned rsx_wrap_type_to_enum(enum gfx_wrap_type type)

0 commit comments

Comments
 (0)