GTK: Use a struct for S9xApplyAspect output.

Reusing the parameters is likely confusing.
This commit is contained in:
Brandon Wright 2019-05-14 14:59:51 -05:00
parent 38d2d2773c
commit 124594d220
5 changed files with 85 additions and 98 deletions

View File

@ -84,47 +84,47 @@ double S9xGetAspect ()
return aspect;
}
void S9xApplyAspect (int &s_width, /* Output: x */
int &s_height, /* Output: y */
int &d_width, /* Output: width */
int &d_height) /* Output: height */
S9xRect S9xApplyAspect (int src_width,
int src_height,
int dst_width,
int dst_height)
{
double screen_aspect = (double) d_width / (double) d_height;
double screen_aspect = (double)dst_width / (double)dst_height;
double snes_aspect = S9xGetAspect ();
bool integer = gui_config->aspect_ratio & 1;
double granularity = 1.0 / (double) MAX (d_width, d_height);
double granularity = 1.0 / (double)MAX(dst_width, dst_height);
int x, y, w, h;
if (!gui_config->scale_to_fit)
{
if (gui_config->maintain_aspect_ratio)
{
w = s_height * snes_aspect + 0.5;
h = s_height;
x = (d_width - w) / 2;
y = (d_height - s_height) / 2;
w = src_height * snes_aspect + 0.5;
h = src_height;
x = (dst_width - w) / 2;
y = (dst_height - src_height) / 2;
}
else
{
w = s_width;
h = s_height;
x = (d_width - w) / 2;
y = (d_height - h) / 2;
w = src_width;
h = src_height;
x = (dst_width - w) / 2;
y = (dst_height - h) / 2;
}
}
else if (gui_config->maintain_aspect_ratio && integer)
{
for (h = s_height * 2; h <= d_height && (int)(h * (snes_aspect) + 0.5) <= d_width; h += s_height) {}
h -= s_height;
for (h = src_height * 2; h <= dst_height && (int)(h * (snes_aspect) + 0.5) <= dst_width; h += src_height) {}
h -= src_height;
w = h * snes_aspect + 0.5;
x = (d_width - w) / 2;
y = (d_height - h) / 2;
x = (dst_width - w) / 2;
y = (dst_height - h) / 2;
if (w > d_width || h > d_height)
if (w > dst_width || h > dst_height)
{
w = d_width;
h = d_height;
w = dst_width;
h = dst_height;
x = 0;
y = 0;
}
@ -135,17 +135,17 @@ void S9xApplyAspect (int &s_width, /* Output: x */
{
if (screen_aspect > snes_aspect)
{
w = d_height * snes_aspect + 0.5;
h = d_height;
x = (d_width - w) / 2;
w = dst_height * snes_aspect + 0.5;
h = dst_height;
x = (dst_width - w) / 2;
y = 0;
}
else
{
w = d_width;
h = d_width / snes_aspect + 0.5;
w = dst_width;
h = dst_width / snes_aspect + 0.5;
x = 0;
y = (d_height - h) / 2;
y = (dst_height - h) / 2;
}
}
@ -154,14 +154,11 @@ void S9xApplyAspect (int &s_width, /* Output: x */
{
x = 0;
y = 0;
w = d_width;
h = d_height;
w = dst_width;
h = dst_height;
}
s_width = x;
s_height = y;
d_width = w;
d_height = h;
return { x, y, w, h };
}
void S9xRegisterYUVTables (uint8 *y, uint8 *u, uint8 *v)

View File

@ -81,10 +81,17 @@ typedef struct thread_job_t
volatile bool complete;
} thread_job_t;
struct S9xRect {
int x;
int y;
int w;
int h;
};
void S9xRegisterYUVTables (uint8 *y, uint8 *u, uint8 *v);
void S9xSetEndianess (int type);
double S9xGetAspect ();
void S9xApplyAspect (int&, int&, int&, int&);
S9xRect S9xApplyAspect (int, int, int, int);
void S9xConvertYUV (void *src_buffer,
void *dst_buffer,
int src_pitch,

View File

@ -21,7 +21,6 @@ S9xGTKDisplayDriver::S9xGTKDisplayDriver (Snes9xWindow *window,
void
S9xGTKDisplayDriver::update (int width, int height, int yoffset)
{
int x, y, w, h;
int final_pitch;
uint8 *final_buffer;
GtkAllocation allocation;
@ -57,10 +56,8 @@ S9xGTKDisplayDriver::update (int width, int height, int yoffset)
final_buffer += (final_pitch * yoffset);
}
x = width; y = height; w = allocation.width; h = allocation.height;
S9xApplyAspect (x, y, w, h);
output (final_buffer, final_pitch, x, y, width, height, w, h);
S9xRect dst = S9xApplyAspect(width, height, allocation.width, allocation.height);
output (final_buffer, final_pitch, dst.x, dst.y, width, height, dst.w, dst.h);
}
void
@ -147,8 +144,7 @@ S9xGTKDisplayDriver::deinit ()
void
S9xGTKDisplayDriver::clear ()
{
int x, y, w, h;
int width, height;
int width, height;
GtkAllocation allocation;
gtk_widget_get_allocation (drawing_area, &allocation);
@ -167,28 +163,27 @@ S9xGTKDisplayDriver::clear ()
return;
}
x = window->last_width;
y = window->last_height;
get_filter_scale (x, y);
w = width;
h = height;
S9xApplyAspect (x, y, w, h);
S9xRect dst;
dst.w = window->last_width;
dst.h = window->last_height;
get_filter_scale(dst.w, dst.h);
dst = S9xApplyAspect(dst.w, dst.h, width, height);
if (x > 0)
if (dst.x > 0)
{
cairo_rectangle (cr, 0, y, x, h);
cairo_rectangle (cr, 0, dst.y, dst.x, dst.h);
}
if (x + w < width)
if (dst.x + dst.w < width)
{
cairo_rectangle (cr, x + w, y, width - (x + w), h);
cairo_rectangle (cr, dst.x + dst.w, dst.y, width - (dst.x + dst.w), dst.h);
}
if (y > 0)
if (dst.y > 0)
{
cairo_rectangle (cr, 0, 0, width, y);
cairo_rectangle (cr, 0, 0, width, dst.y);
}
if (y + h < height)
if (dst.y + dst.h < height)
{
cairo_rectangle (cr, 0, y + h, width, height - (y + h));
cairo_rectangle (cr, 0, dst.y + dst.h, width, height - (dst.y + dst.h));
}
cairo_fill (cr);

View File

@ -74,12 +74,11 @@ static void S9xViewportCallback (int src_width, int src_height,
int *out_x, int *out_y,
int *out_width, int *out_height)
{
S9xApplyAspect (src_width, src_height, viewport_width, viewport_height);
*out_x = src_width + viewport_x;
*out_y = src_height + viewport_y;
*out_width = viewport_width;
*out_height = viewport_height;
S9xRect dst = S9xApplyAspect(src_width, src_height, viewport_width, viewport_height);
*out_x = dst.x + viewport_x;
*out_y = dst.y + viewport_y;
*out_width = dst.w;
*out_height = dst.h;
}
S9xOpenGLDisplayDriver::S9xOpenGLDisplayDriver (Snes9xWindow *window,
@ -95,7 +94,6 @@ void S9xOpenGLDisplayDriver::update (int width, int height, int yoffset)
uint8 *final_buffer = NULL;
int final_pitch;
void *pbo_map = NULL;
int x, y, w, h;
GtkAllocation allocation;
gtk_widget_get_allocation (drawing_area, &allocation);
@ -153,14 +151,9 @@ void S9xOpenGLDisplayDriver::update (int width, int height, int yoffset)
final_buffer += (final_pitch * yoffset);
}
x = width;
y = height;
w = allocation.width;
h = allocation.height;
S9xApplyAspect (x, y, w, h);
glViewport (x, allocation.height - y - h, w, h);
window->set_mouseable_area (x, y, w, h);
S9xRect r = S9xApplyAspect(width, height, allocation.width, allocation.height);
glViewport (r.x, allocation.height - r.y - r.h, r.w, r.h);
window->set_mouseable_area (r.x, r.y, r.w, r.h);
update_texture_size (width, height);
@ -263,7 +256,7 @@ void S9xOpenGLDisplayDriver::update (int width, int height, int yoffset)
if (using_glsl_shaders)
{
glsl_shader->render (texmap, width, height, x, allocation.height - y - h, w, h, S9xViewportCallback);
glsl_shader->render (texmap, width, height, r.x, allocation.height - r.y - r.h, r.w, r.h, S9xViewportCallback);
swap_buffers ();
return;
}

View File

@ -77,7 +77,6 @@ S9xXVDisplayDriver::update (int width, int height, int yoffset)
{
int current_width, current_height, final_pitch;
uint8 *final_buffer;
int dst_x, dst_y, dst_width, dst_height;
GtkAllocation allocation;
gtk_widget_get_allocation (drawing_area, &allocation);
@ -150,14 +149,12 @@ S9xXVDisplayDriver::update (int width, int height, int yoffset)
bpp);
}
dst_x = width; dst_y = height;
dst_width = current_width; dst_height = current_height;
S9xApplyAspect (dst_x, dst_y, dst_width, dst_height);
S9xRect dst = S9xApplyAspect(width, height, current_width, current_height);
if (last_known_width != dst_width || last_known_height != dst_height)
if (last_known_width != dst.w || last_known_height != dst.h)
{
last_known_width = dst_width;
last_known_height = dst_height;
last_known_width = dst.w;
last_known_height = dst.h;
clear ();
}
@ -170,13 +167,13 @@ S9xXVDisplayDriver::update (int width, int height, int yoffset)
0,
width,
height,
dst_x,
dst_y,
dst_width,
dst_height,
dst.x,
dst.y,
dst.w,
dst.h,
False);
top_level->set_mouseable_area (dst_x, dst_y, dst_width, dst_height);
top_level->set_mouseable_area (dst.x, dst.y, dst.w, dst.h);
XSync (display, False);
}
@ -493,7 +490,6 @@ S9xXVDisplayDriver::deinit ()
void
S9xXVDisplayDriver::clear ()
{
int x, y, w, h;
int width, height;
GtkAllocation allocation;
GC xgc = XDefaultGC (display, XDefaultScreen (display));
@ -516,28 +512,27 @@ S9xXVDisplayDriver::clear ()
}
/* Get width of modified display */
x = window->last_width;
y = window->last_height;
get_filter_scale (x, y);
w = width;
h = height;
S9xApplyAspect (x, y, w, h);
S9xRect dst;
dst.w = window->last_width;
dst.h = window->last_height;
get_filter_scale (dst.w, dst.h);
dst = S9xApplyAspect (dst.w, dst.h, width, height);
if (x > 0)
if (dst.x > 0)
{
XFillRectangle (display, xwindow, xgc, 0, y, x, h);
XFillRectangle (display, xwindow, xgc, 0, dst.y, dst.x, dst.h);
}
if (x + w < width)
if (dst.x + dst.w < width)
{
XFillRectangle (display, xwindow, xgc, x + w, y, width - (x + w), h);
XFillRectangle (display, xwindow, xgc, dst.x + dst.w, dst.y, width - (dst.x + dst.w), dst.h);
}
if (y > 0)
if (dst.y > 0)
{
XFillRectangle (display, xwindow, xgc, 0, 0, width, y);
XFillRectangle (display, xwindow, xgc, 0, 0, width, dst.y);
}
if (y + h < height)
if (dst.y + dst.h < height)
{
XFillRectangle (display, xwindow, xgc, 0, y + h, width, height - (y + h));
XFillRectangle (display, xwindow, xgc, 0, dst.y + dst.h, width, height - (dst.y + dst.h));
}
XSync (display, False);