Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for 752x560 resolution used by new MMv4 screens #1272

Merged
merged 23 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
7e19b6a
Add support for new screen resolution in runtime.sh
tGecko Nov 8, 2023
8a78733
Add screen resolution option and save it to a
tGecko Nov 8, 2023
365964b
Add scaling for screenshots to fix garbled gameswitcher
tGecko Nov 10, 2023
3d7e9b8
Fix game resolution for certain standalones
tGecko Nov 10, 2023
cffc07f
update brightness bar to respect current resolution
tGecko Nov 10, 2023
d21a832
Fix batwarn icon at new resolution
tGecko Nov 10, 2023
a80d8ce
Add SIGUSR1 signal handler to batmon and keymon,
tGecko Nov 10, 2023
31a2ce9
Remove unneeded function call, replaced by sighandler
tGecko Nov 10, 2023
d1ef51b
Update screenshot scaling to use render resolution
tGecko Nov 11, 2023
cd95fef
Move code to change resolution into a function
tGecko Nov 11, 2023
2108da0
Add retries if failing to get screen resolution,
tGecko Nov 15, 2023
06dab28
prepare for NDS integration
tGecko Nov 19, 2023
fdeccb3
don't print newline in /tmp/screen_resolution
tGecko Nov 20, 2023
711caad
save screenshots in render resolution
tGecko Nov 23, 2023
c3f9d89
infoPanel: scale image to 640x480 if needed
tGecko Nov 23, 2023
cb04773
Add exception for EasyLogoTweak
tGecko Nov 24, 2023
3a19eea
add newline
tGecko Nov 24, 2023
0bd0e30
Add res_exceptions to .gitattributes
tGecko Nov 24, 2023
66049f8
bump RA_SUBVERSION to trigger update
tGecko Nov 28, 2023
ab4a1ad
Remove NDS exception as it supports 560p now
tGecko Dec 19, 2023
3f47a18
Merge branch 'main' into MMv4_res_support
schmurtzm Dec 21, 2023
5061312
🎨 apply clang-format changes
schmurtzm Dec 21, 2023
dc4b4a2
Fix build
schmurtzm Dec 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ static/dist/miyoo354/app/MainUI text eol=lf
static/build/.tmp_update/bin/shutdown text eol=lf
static/configs/.tmp_update/config/passwd text eol=lf
static/configs/.tmp_update/config/group text eol=lf
static/configs/.tmp_update/config/res_exceptions text eol=lf
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

TARGET=Onion
VERSION=4.2.2
RA_SUBVERSION=1.15.0.6
RA_SUBVERSION=1.15.0.7

###########################################################

Expand Down
6 changes: 5 additions & 1 deletion src/batmon/batmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ int main(int argc, char *argv[])
signal(SIGTERM, sigHandler);
signal(SIGSTOP, sigHandler);
signal(SIGCONT, sigHandler);
signal(SIGUSR1, sigHandler);

display_init();
int ticks = CHECK_BATTERY_TIMEOUT_S;
Expand Down Expand Up @@ -160,6 +161,9 @@ static void sigHandler(int sig)
}
is_suspended = false;
break;
case SIGUSR1:
display_getRenderResolution();
break;
default:
break;
}
Expand Down Expand Up @@ -380,7 +384,7 @@ int batteryPercentage(int value)
static void *batteryWarning_thread(void *param)
{
while (1) {
display_drawBatteryIcon(0x00FF0000, 15, 450, 10,
display_drawBatteryIcon(0x00FF0000, 15, RENDER_HEIGHT - 30, 10,
0x00FF0000); // draw red battery icon
usleep(0x4000);
}
Expand Down
46 changes: 37 additions & 9 deletions src/common/system/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
#include "utils/file.h"
#include "utils/log.h"

#define DISPLAY_WIDTH 640
#define DISPLAY_HEIGHT 480

#define display_on() display_setScreen(true)
#define display_off() display_setScreen(false)

Expand All @@ -25,6 +22,36 @@ static struct fb_var_screeninfo vinfo;
static uint32_t stride, bpp;
static uint8_t *savebuf;
static bool display_enabled = true;
static int DISPLAY_WIDTH = 640; // physical screen resolution
static int DISPLAY_HEIGHT = 480;
int RENDER_WIDTH = 640; // render resolution
int RENDER_HEIGHT = 480;
struct timeval start_time, end_time;

//
// Get render resolution
//
void display_getRenderResolution()
{
print_debug("Getting render resolution\n");
if (fb_fd < 0)
fb_fd = open("/dev/fb0", O_RDWR);
ioctl(fb_fd, FBIOGET_VSCREENINFO, &vinfo);
RENDER_WIDTH = vinfo.xres;
RENDER_HEIGHT = vinfo.yres;
}

//
// Get physical screen resolution
//
void display_getResolution()
{
FILE *file = fopen("/tmp/screen_resolution", "r");
if (file == NULL || !(fscanf(file, "%dx%d", &DISPLAY_WIDTH, &DISPLAY_HEIGHT) == 2))
printf("failed to get screen resolution\n");
fclose(file);
display_getRenderResolution();
}

void display_init(void)
{
Expand All @@ -33,6 +60,7 @@ void display_init(void)
ioctl(fb_fd, FBIOGET_FSCREENINFO, &finfo);
fb_addr = (uint32_t *)mmap(0, finfo.smem_len, PROT_READ | PROT_WRITE,
MAP_SHARED, fb_fd, 0);
display_getResolution();
}

//
Expand Down Expand Up @@ -175,26 +203,26 @@ void display_drawBatteryIcon(uint32_t color, int x, int y, int level,

// Draw battery body wireframe
for (i = x; i < x + 30; i++) {
ofs[i + y * 640] = color; // Top border
ofs[i + (y + 14) * 640] = color; // Bottom border
ofs[i + y * RENDER_WIDTH] = color; // Top border
ofs[i + (y + 14) * RENDER_WIDTH] = color; // Bottom border
}
for (j = y; j < y + 15; j++) {
ofs[x + j * 640] = color; // Left border
ofs[x + 29 + j * 640] = color; // Right border
ofs[x + j * RENDER_WIDTH] = color; // Left border
ofs[x + 29 + j * RENDER_WIDTH] = color; // Right border
}

// Draw battery charge level
int levelWidth = (level * 26) / 100;
for (i = x + 3 + 26 - levelWidth; i < x + 1 + 26; i++) {
for (j = y + 3; j < y + 12; j++) {
ofs[i + j * 640] = fillColor;
ofs[i + j * RENDER_WIDTH] = fillColor;
}
}

// Draw battery head wireframe
for (i = x - 4; i < x; i++) {
for (j = y + 2; j < y + 13; j++) {
ofs[i + j * 640] = color;
ofs[i + j * RENDER_WIDTH] = color;
}
}
}
Expand Down
22 changes: 11 additions & 11 deletions src/common/system/osd.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,11 @@ void _print_bar(void)
{
#ifdef PLATFORM_MIYOOMINI
uint32_t *ofs = fb_addr;
uint32_t i, j, curr, percentage = _bar_max > 0 ? _bar_value * DISPLAY_HEIGHT / _bar_max : 0;
uint32_t i, j, curr, percentage = _bar_max > 0 ? _bar_value * RENDER_HEIGHT / _bar_max : 0;

ofs += DISPLAY_WIDTH - meterWidth;
for (i = 0; i < DISPLAY_HEIGHT * 3; i++, ofs += DISPLAY_WIDTH) {
curr = (i % DISPLAY_HEIGHT) < percentage ? _bar_color : 0;
ofs += RENDER_WIDTH - meterWidth;
for (i = 0; i < RENDER_HEIGHT * 3; i++, ofs += RENDER_WIDTH) {
curr = (i % RENDER_HEIGHT) < percentage ? _bar_color : 0;
for (j = 0; j < meterWidth; j++)
ofs[j] = curr;
}
Expand All @@ -162,9 +162,9 @@ void _bar_restoreBufferBehind(void)
_print_bar();
if (_bar_savebuf) {
uint32_t i, j, *ofs = fb_addr, *ofss = _bar_savebuf;
ofs += DISPLAY_WIDTH - meterWidth;
ofss += DISPLAY_WIDTH - meterWidth;
for (i = 0; i < DISPLAY_HEIGHT; i++, ofs += DISPLAY_WIDTH, ofss += DISPLAY_WIDTH) {
ofs += RENDER_WIDTH - meterWidth;
ofss += RENDER_WIDTH - meterWidth;
for (i = 0; i < RENDER_HEIGHT; i++, ofs += RENDER_WIDTH, ofss += RENDER_WIDTH) {
for (j = 0; j < meterWidth; j++)
ofs[j] = ofss[j];
}
Expand All @@ -178,12 +178,12 @@ void _bar_saveBufferBehind(void)
{
#ifdef PLATFORM_MIYOOMINI
// Save display area and clear
if ((_bar_savebuf = (uint32_t *)malloc(DISPLAY_WIDTH * DISPLAY_HEIGHT *
if ((_bar_savebuf = (uint32_t *)malloc(RENDER_WIDTH * RENDER_HEIGHT *
sizeof(uint32_t)))) {
uint32_t i, j, *ofs = fb_addr, *ofss = _bar_savebuf;
ofs += DISPLAY_WIDTH - meterWidth;
ofss += DISPLAY_WIDTH - meterWidth;
for (i = 0; i < DISPLAY_HEIGHT; i++, ofs += DISPLAY_WIDTH, ofss += DISPLAY_WIDTH) {
ofs += RENDER_WIDTH - meterWidth;
ofss += RENDER_WIDTH - meterWidth;
for (i = 0; i < RENDER_HEIGHT; i++, ofs += RENDER_WIDTH, ofss += RENDER_WIDTH) {
for (j = 0; j < meterWidth; j++)
ofss[j] = ofs[j];
}
Expand Down
16 changes: 10 additions & 6 deletions src/common/system/screenshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ bool __get_path_recent(char *path_out)

uint32_t *__screenshot_buffer(void)
{
static size_t buffer_size = DISPLAY_WIDTH * DISPLAY_HEIGHT * sizeof(uint32_t);
size_t buffer_size = DISPLAY_WIDTH * DISPLAY_HEIGHT * sizeof(uint32_t);
uint32_t *buffer = (uint32_t *)malloc(buffer_size);

ioctl(fb_fd, FBIOGET_VSCREENINFO, &vinfo);
Expand All @@ -103,11 +103,15 @@ uint32_t *__screenshot_buffer(void)
bool __screenshot_save(const uint32_t *buffer, const char *screenshot_path)
{
uint32_t *src;
uint32_t line_buffer[DISPLAY_WIDTH], x, y, pix;
uint32_t line_buffer[RENDER_WIDTH], x, y, pix;

FILE *fp;
png_structp png_ptr;
png_infop info_ptr;

// make sure render resolution is up to date
display_getRenderResolution();

if (!(fp = file_open_ensure_path(screenshot_path, "wb"))) {
return false;
}
Expand All @@ -116,15 +120,15 @@ bool __screenshot_save(const uint32_t *buffer, const char *screenshot_path)
info_ptr = png_create_info_struct(png_ptr);

png_init_io(png_ptr, fp);
png_set_IHDR(png_ptr, info_ptr, DISPLAY_WIDTH, DISPLAY_HEIGHT, 8,
png_set_IHDR(png_ptr, info_ptr, RENDER_WIDTH, RENDER_HEIGHT, 8,
PNG_COLOR_TYPE_RGBA, PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
png_write_info(png_ptr, info_ptr);

src = (uint32_t *)buffer + DISPLAY_WIDTH * DISPLAY_HEIGHT;
src = (uint32_t *)buffer + RENDER_WIDTH * RENDER_HEIGHT;

for (y = 0; y < DISPLAY_HEIGHT; y++) {
for (x = 0; x < DISPLAY_WIDTH; x++) {
for (y = 0; y < RENDER_HEIGHT; y++) {
for (x = 0; x < RENDER_WIDTH; x++) {
pix = *--src;
line_buffer[x] = 0xFF000000 | (pix & 0x0000FF00) | (pix & 0x00FF0000) >> 16 | (pix & 0x000000FF) << 16;
}
Expand Down
19 changes: 13 additions & 6 deletions src/gameSwitcher/gameSwitcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ void readHistory()
if (bGameExists) {
// recentlist line deletion
file_delete_line(getMiyooRecentFilePath(), lineCounter);
lineCounter --;
lineCounter--;
continue;
}

Expand Down Expand Up @@ -492,7 +492,7 @@ int main(int argc, char *argv[])
footer_height = 0;

SDL_Surface *current_bg = NULL;
// SDL_Rect frame = {theme()->frame.border_left, 0, 640 - theme()->frame.border_left - theme()->frame.border_right, 480};
SDL_Rect frame = {theme()->frame.border_left, 0, 640 - theme()->frame.border_left - theme()->frame.border_right, 480};

while (!quit) {
uint32_t ticks = SDL_GetTicks();
Expand Down Expand Up @@ -695,10 +695,17 @@ int main(int argc, char *argv[])
current_bg = loadRomScreen(current_game);

if (current_bg != NULL) {
int x_offset = (int)((640 - current_bg->w) / 2);
int y_offset = (int)((480 - current_bg->h) / 2);
SDL_Rect frame_bg = {x_offset, y_offset, 640, 480};
SDL_BlitSurface(current_bg, NULL, screen, &frame_bg);
if (current_bg->w != 640 || current_bg->h != 480) {
printf_debug("Scaling screenshot from %dx%d to 640x480\n", current_bg->w, current_bg->h);
SDL_Rect dest_rect = {0, 0, 640, 480};
SDL_SoftStretch(current_bg, NULL, current_bg, &dest_rect);
current_bg->w = 640;
current_bg->h = 480;
}
if (view_mode == VIEW_NORMAL)
SDL_BlitSurface(current_bg, &frame, screen, &frame);
else
SDL_BlitSurface(current_bg, NULL, screen, NULL);
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/infoPanel/imagesCache.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ static void drawImage(SDL_Surface *image_to_draw, SDL_Surface *screen,
if (!image_to_draw)
return;

if (image_to_draw->w != 640 || image_to_draw->h != 480) {
// scale image to 640x480 if needed
SDL_Rect dest_rect = {0, 0, 640, 480};
SDL_SoftStretch(image_to_draw, NULL, image_to_draw, &dest_rect);
image_to_draw->w = 640;
image_to_draw->h = 480;
}

DEBUG_PRINT(("frame %p\n", frame));
int border_left = 0;
SDL_Rect new_frame = {0, 0};
Expand Down
2 changes: 1 addition & 1 deletion src/keymon/keymon.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ int main(void)
// Initialize
signal(SIGTERM, quit);
signal(SIGSEGV, quit);

signal(SIGUSR1, display_getRenderResolution);
log_setName("keymon");

getDeviceModel();
Expand Down
Loading
Loading