Skip to content

Commit

Permalink
enhancement: Show available refresh rates
Browse files Browse the repository at this point in the history
  • Loading branch information
midwan committed Feb 4, 2025
1 parent 376bfb5 commit 23c2c1a
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 7 deletions.
100 changes: 98 additions & 2 deletions src/osdep/amiberry_gfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,25 @@ static void SDL2_init()
{
write_log("Creating Amiberry window...\n");
Uint32 mode;

// Only enable Windowed mode if we're running under x11
if (!kmsdrm_detected)
{
// Only enable Windowed mode if we're running under x11
if (currprefs.gfx_apmode[APMODE_NATIVE].gfx_fullscreen == GFX_FULLWINDOW)
mode = SDL_WINDOW_FULLSCREEN_DESKTOP;
else if (currprefs.gfx_apmode[APMODE_NATIVE].gfx_fullscreen == GFX_FULLSCREEN)
{
mode = SDL_WINDOW_FULLSCREEN;
SDL_DisplayMode dm = {};
dm.format = SDL_PIXELFORMAT_BGRA32;
dm.w = currprefs.gfx_monitor[0].gfx_size.width;
dm.h = currprefs.gfx_monitor[0].gfx_size.height;
dm.refresh_rate = currprefs.gfx_apmode[APMODE_NATIVE].gfx_refreshrate;
if (SDL_SetWindowDisplayMode(mon->amiga_window, &dm) != 0) {
// Handle error
write_log("Failed to set display mode: %s\n", SDL_GetError());
}
}
else
mode = SDL_WINDOW_RESIZABLE;
}
Expand Down Expand Up @@ -913,6 +925,78 @@ void sortdisplays()
write_log(_T("Desktop: W=%d H=%d B=%d HZ=%d. CXVS=%d CYVS=%d\n"), w, h, b, deskhz, wv, hv);
}

int gfx_adjust_screenmode(MultiDisplay *md, int *pwidth, int *pheight, int *ppixbits)
{
struct PicassoResolution* best;
uae_u32 selected_mask = (*ppixbits == 8 ? RGBMASK_8BIT
: *ppixbits == 15 ? RGBMASK_15BIT
: *ppixbits == 16 ? RGBMASK_16BIT
: *ppixbits == 24 ? RGBMASK_24BIT
: RGBMASK_32BIT);
int pass, i = 0, index = 0;

for (pass = 0; pass < 2; pass++) {
struct PicassoResolution* dm;
uae_u32 mask = (pass == 0
? selected_mask
: RGBMASK_8BIT | RGBMASK_15BIT | RGBMASK_16BIT | RGBMASK_24BIT | RGBMASK_32BIT); /* %%% - BERND, were you missing 15-bit here??? */
i = 0;
index = 0;

best = &md->DisplayModes[0];
dm = &md->DisplayModes[1];

while (dm->depth >= 0) {

/* do we already have supported resolution? */
if (dm->res.width == *pwidth && dm->res.height == *pheight && dm->depth == (*ppixbits / 8))
return i;

if ((dm->colormodes & mask) != 0) {
if (dm->res.width <= best->res.width && dm->res.height <= best->res.height
&& dm->res.width >= *pwidth && dm->res.height >= *pheight)
{
best = dm;
index = i;
}
if (dm->res.width >= best->res.width && dm->res.height >= best->res.height
&& dm->res.width <= *pwidth && dm->res.height <= *pheight)
{
best = dm;
index = i;
}
}
dm++;
i++;
}
if (best->res.width == *pwidth && best->res.height == *pheight) {
selected_mask = mask; /* %%% - BERND, I added this - does it make sense? Otherwise, I'd specify a 16-bit display-mode for my
Workbench (using -H 2, but SHOULD have been -H 1), and end up with an 8-bit mode instead*/
break;
}
}
*pwidth = best->res.width;
*pheight = best->res.height;
if (best->colormodes & selected_mask)
return index;

/* Ordering here is done such that 16-bit is preferred, followed by 15-bit, 8-bit, 32-bit and 24-bit */
if (best->colormodes & RGBMASK_16BIT)
*ppixbits = 16;
else if (best->colormodes & RGBMASK_15BIT) /* %%% - BERND, this possibility was missing? */
*ppixbits = 15;
else if (best->colormodes & RGBMASK_8BIT)
*ppixbits = 8;
else if (best->colormodes & RGBMASK_32BIT)
*ppixbits = 32;
else if (best->colormodes & RGBMASK_24BIT)
*ppixbits = 24;
else
index = -1;

return index;
}

bool render_screen(int monid, int mode, bool immediate)
{
return true;
Expand Down Expand Up @@ -2621,7 +2705,19 @@ void updatewinfsmode(const int monid, struct uae_prefs* p)
if (p->gfx_apmode[id].gfx_fullscreen == GFX_FULLSCREEN && !is_fullscreen)
{
p->gfx_monitor[monid].gfx_size = p->gfx_monitor[monid].gfx_size_fs;
SDL_SetWindowFullscreen(mon->amiga_window, SDL_WINDOW_FULLSCREEN);
SDL_DisplayMode dm = {};
dm.format = SDL_PIXELFORMAT_BGRA32;
dm.w = p->gfx_monitor[monid].gfx_size.width;
dm.h = p->gfx_monitor[monid].gfx_size.height;
dm.refresh_rate = p->gfx_apmode[id].gfx_refreshrate;
if (SDL_SetWindowDisplayMode(mon->amiga_window, &dm) != 0) {
// Handle error
write_log("Failed to set display mode: %s\n", SDL_GetError());
}
if (SDL_SetWindowFullscreen(mon->amiga_window, SDL_WINDOW_FULLSCREEN) != 0) {
// Handle error
write_log("Failed to set window to fullscreen: %s\n", SDL_GetError());
}
set_config_changed();
}
else if (p->gfx_apmode[id].gfx_fullscreen == GFX_FULLWINDOW && !is_fullwindow)
Expand Down
1 change: 1 addition & 0 deletions src/osdep/amiberry_gfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ extern void enumeratedisplays(void);

void Display_change_requested(int);
void DX_Invalidate(struct AmigaMonitor*, int x, int y, int width, int height);
int gfx_adjust_screenmode(MultiDisplay* md, int* pwidth, int* pheight, int* ppixbits);

extern int default_freq;

Expand Down
41 changes: 36 additions & 5 deletions src/osdep/gui/PanelDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,17 +231,15 @@ static int display_mode_index (uae_u32 x, uae_u32 y, uae_u32 d)
j = 0;
for (i = 0; md->DisplayModes[i].depth >= 0; i++) {
if (md->DisplayModes[i].res.width == x &&
md->DisplayModes[i].res.height == y &&
md->DisplayModes[i].depth == d)
md->DisplayModes[i].res.height == y)
break;
j++;
}
if (x == 0 && y == 0) {
j = 0;
for (i = 0; md->DisplayModes[i].depth >= 0; i++) {
if (md->DisplayModes[i].res.width == md->rect.w &&
md->DisplayModes[i].res.height == md->rect.h &&
md->DisplayModes[i].depth == d)
md->DisplayModes[i].res.height == md->rect.h)
break;
j++;
}
Expand All @@ -254,11 +252,44 @@ static int display_mode_index (uae_u32 x, uae_u32 y, uae_u32 d)
static int gui_display_depths[3];
static void init_display_mode ()
{
int d, index;
int d, d2, index;
int i, cnt;
struct MultiDisplay *md = getdisplay(&changed_prefs, 0);
struct monconfig *gm = &changed_prefs.gfx_monitor[0];

switch (changed_prefs.color_mode)
{
case 2:
d = 16;
break;
case 5:
default:
d = 32;
break;
}

if (changed_prefs.gfx_apmode[0].gfx_fullscreen) {
d2 = d;
if ((index = gfx_adjust_screenmode(md, &gm->gfx_size_fs.width, &gm->gfx_size_fs.height, &d2)) >= 0) {
switch (d2)
{
case 15:
case 16:
changed_prefs.color_mode = 2;
d = 2;
break;
case 32:
default:
changed_prefs.color_mode = 5;
d = 4;
break;
}
}
}
else {
d = d / 8;
}

if (gm->gfx_size_fs.special == WH_NATIVE) {
int cnt = fullscreen_modes_list.getNumberOfElements();
cboFullscreen->setSelected(cnt - 1);
Expand Down

0 comments on commit 23c2c1a

Please sign in to comment.