Skip to content

Commit

Permalink
Add option --scale_proportional. Link hactive to --pixel_precision (t…
Browse files Browse the repository at this point in the history
…o allow non-8-multiples).
  • Loading branch information
antonioginer committed Feb 1, 2024
1 parent d10a5ee commit 29691f7
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 3 deletions.
2 changes: 2 additions & 0 deletions display.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class display_manager
int v_shift_correct() { return m_ds.gs.v_shift_correct; }
int pixel_precision() { return m_ds.gs.pixel_precision; }
int interlace_force_even() { return m_ds.gs.interlace_force_even; }
int scale_proportional() { return m_ds.gs.scale_proportional; }

// getters (modeline result)
bool got_mode() { return (m_selected_mode != nullptr); }
Expand Down Expand Up @@ -161,6 +162,7 @@ class display_manager
void set_v_shift_correct(int value) { m_ds.gs.v_shift_correct = value; }
void set_pixel_precision(int value) { m_ds.gs.pixel_precision = value; }
void set_interlace_force_even(int value) { m_ds.gs.interlace_force_even = value; }
void set_scale_proportional(int value) { m_ds.gs.scale_proportional = value; }

// setters (custom_video backend)
void set_screen_compositing(bool value) { m_ds.vs.screen_compositing = value; }
Expand Down
6 changes: 3 additions & 3 deletions modeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ int modeline_create(modeline *s_mode, modeline *t_mode, monitor_range *range, ge
// if we can, let's apply the same scaling to both directions
if (t_mode->type & X_RES_EDITABLE)
{
x_scale = y_scale;
x_scale = cs->scale_proportional? y_scale : 1;
double aspect_corrector = max(1.0f, cs->monitor_aspect / source_aspect);
t_mode->hactive = normalize(double(t_mode->hactive) * double(x_scale) * aspect_corrector, 8);
t_mode->hactive = normalize(double(t_mode->hactive) * double(x_scale) * aspect_corrector, cs->pixel_precision? 1 : 8);
}

// otherwise, try to get the best out of our current xres
Expand Down Expand Up @@ -204,7 +204,7 @@ int modeline_create(modeline *s_mode, modeline *t_mode, monitor_range *range, ge

// check if we can create a normal aspect resolution
if (t_mode->type & X_RES_EDITABLE)
t_mode->hactive = max(t_mode->hactive, normalize(STANDARD_CRT_ASPECT * t_mode->vactive, 8));
t_mode->hactive = max(t_mode->hactive, normalize(STANDARD_CRT_ASPECT * t_mode->vactive, cs->pixel_precision? 1 : 8));

// calculate integer scale for prescaling
x_scale = max(1, scale_into_aspect(s_mode->hactive, t_mode->hactive, source_aspect, cs->monitor_aspect, &x_diff));
Expand Down
1 change: 1 addition & 0 deletions modeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ typedef struct generator_settings
int v_shift_correct;
int pixel_precision;
int interlace_force_even;
int scale_proportional;
} generator_settings;

//============================================================
Expand Down
5 changes: 5 additions & 0 deletions switchres.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ switchres_manager::switchres_manager()
display()->set_v_shift_correct(0);
display()->set_pixel_precision(1);
display()->set_interlace_force_even(0);
display()->set_scale_proportional(1);

// Set logger properties
set_log_info_fn((void*)printf);
Expand Down Expand Up @@ -359,6 +360,10 @@ void switchres_manager::set_option(const char* key, const char* value)
display()->set_interlace_force_even(atoi(value));
break;

case s2i("scale_proportional"):
display()->set_scale_proportional(atoi(value));
break;

// Custom video backend options
case s2i("screen_compositing"):
display()->set_screen_compositing(atoi(value));
Expand Down
3 changes: 3 additions & 0 deletions switchres.ini
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@
# Calculate all vertical values of interlaced modes as even numbers. Required by AMD APU hardware on Linux
interlace_force_even 0

# Scale both axes by the same factor, when integer scaling is applied
scale_proportional 1


#
# Custom video backend config
Expand Down
1 change: 1 addition & 0 deletions switchres_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#define SR_OPT_V_SHIFT "v_shift"
#define SR_OPT_PIXEL_PRECISION "pixel_precision"
#define SR_OPT_INTERLACE_FORCE_EVEN "interlace_force_even"
#define SR_OPT_SCALE_PROPORTIONAL "scale_proportional"
#define SR_OPT_SCREEN_COMPOSITING "screen_compositing"
#define SR_OPT_SCREEN_REORDERING "screen_reordering"
#define SR_OPT_ALLOW_HARDWARE_REFRESH "allow_hardware_refresh"
Expand Down
3 changes: 3 additions & 0 deletions switchres_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ enum
OPT_V_SHIFT,
OPT_PIXEL_PRECISION,
OPT_INTERLACE_FORCE_EVEN,
OPT_SCALE_PROPORTIONAL,
OPT_SCREEN_COMPOSITING,
OPT_SCREEN_REORDERING,
OPT_ALLOW_HARDWARE_REFRESH,
Expand Down Expand Up @@ -151,6 +152,7 @@ int main(int argc, char **argv)
{SR_OPT_V_SHIFT, required_argument, 0, OPT_V_SHIFT},
{SR_OPT_PIXEL_PRECISION, required_argument, 0, OPT_PIXEL_PRECISION},
{SR_OPT_INTERLACE_FORCE_EVEN, required_argument, 0, OPT_INTERLACE_FORCE_EVEN},
{SR_OPT_SCALE_PROPORTIONAL, required_argument, 0, OPT_SCALE_PROPORTIONAL},
{SR_OPT_SCREEN_COMPOSITING, required_argument, 0, OPT_SCREEN_COMPOSITING},
{SR_OPT_SCREEN_REORDERING, required_argument, 0, OPT_SCREEN_REORDERING},
{SR_OPT_ALLOW_HARDWARE_REFRESH, required_argument, 0, OPT_ALLOW_HARDWARE_REFRESH},
Expand Down Expand Up @@ -282,6 +284,7 @@ int main(int argc, char **argv)
case OPT_V_SHIFT:
case OPT_PIXEL_PRECISION:
case OPT_INTERLACE_FORCE_EVEN:
case OPT_SCALE_PROPORTIONAL:
case OPT_SCREEN_COMPOSITING:
case OPT_SCREEN_REORDERING:
case OPT_ALLOW_HARDWARE_REFRESH:
Expand Down

0 comments on commit 29691f7

Please sign in to comment.