summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Soffke <christian.soffke@gmail.com>2024-12-22 12:47:21 +0100
committerChristian Soffke <christian.soffke@gmail.com>2024-12-25 08:34:40 -0500
commit759cbf4e5f3acf55245b5d181bfe9fa2bbb8a472 (patch)
tree8146e86852b1c6bb7ed82d10c2511f19bc7c4828
parent60f3283f48d07926d64f001602f8c2aeb57a871d (diff)
downloadrockbox-759cbf4e5f.tar.gz
rockbox-759cbf4e5f.zip
sdl: Remove usage of SDL_SoftStretch
SDL 2 lets us take advantage of a fixed logical resolution, where the renderer scales content up or down automatically. Relative mouse motion is also affected by renderer scaling by default (see SDL_HINT_MOUSE_RELATIVE_SCALING). If window zoom has been enabled from the command line, set scaling quality to "nearest pixel sampling" instead of "best" to allow pixel peeping. Change-Id: I4e5c19d36b55c985c26ac5ae64c4a6b8dd9b308d
-rw-r--r--firmware/target/hosted/sdl/button-sdl.c6
-rw-r--r--firmware/target/hosted/sdl/lcd-bitmap.c8
-rw-r--r--firmware/target/hosted/sdl/lcd-remote-bitmap.c10
-rw-r--r--firmware/target/hosted/sdl/lcd-sdl.c34
-rw-r--r--firmware/target/hosted/sdl/system-sdl.c6
5 files changed, 21 insertions, 43 deletions
diff --git a/firmware/target/hosted/sdl/button-sdl.c b/firmware/target/hosted/sdl/button-sdl.c
index 0ba54d064a..d10e681b15 100644
--- a/firmware/target/hosted/sdl/button-sdl.c
+++ b/firmware/target/hosted/sdl/button-sdl.c
@@ -284,8 +284,8 @@ static bool event_handler(SDL_Event *event)
case SDL_MOUSEMOTION:
if (event->motion.state & SDL_BUTTON(1))
{
- int x = event->motion.x / display_zoom;
- int y = event->motion.y / display_zoom;
+ int x = event->motion.x;
+ int y = event->motion.y;
touchscreen_event(x, y);
}
break;
@@ -295,8 +295,6 @@ static bool event_handler(SDL_Event *event)
case SDL_MOUSEBUTTONDOWN:
{
SDL_MouseButtonEvent *mev = &event->button;
- mev->x /= display_zoom;
- mev->y /= display_zoom;
mouse_event(mev, event->type == SDL_MOUSEBUTTONUP);
break;
}
diff --git a/firmware/target/hosted/sdl/lcd-bitmap.c b/firmware/target/hosted/sdl/lcd-bitmap.c
index ef284eeb48..22d48fd2b1 100644
--- a/firmware/target/hosted/sdl/lcd-bitmap.c
+++ b/firmware/target/hosted/sdl/lcd-bitmap.c
@@ -183,15 +183,11 @@ void sim_backlight(int value)
void lcd_init_device(void)
{
#if LCD_DEPTH >= 16
- lcd_surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
- SIM_LCD_WIDTH * display_zoom,
- SIM_LCD_HEIGHT * display_zoom,
+ lcd_surface = SDL_CreateRGBSurface(SDL_SWSURFACE, SIM_LCD_WIDTH, SIM_LCD_HEIGHT,
LCD_DEPTH, 0, 0, 0, 0);
SDL_SetSurfaceBlendMode(lcd_surface, SDL_BLENDMODE_BLEND);
#elif LCD_DEPTH <= 8
- lcd_surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
- SIM_LCD_WIDTH * display_zoom,
- SIM_LCD_HEIGHT * display_zoom,
+ lcd_surface = SDL_CreateRGBSurface(SDL_SWSURFACE, SIM_LCD_WIDTH, SIM_LCD_HEIGHT,
8, 0, 0, 0, 0);
#ifdef HAVE_BACKLIGHT
diff --git a/firmware/target/hosted/sdl/lcd-remote-bitmap.c b/firmware/target/hosted/sdl/lcd-remote-bitmap.c
index 5f08b4440b..1bbcc96542 100644
--- a/firmware/target/hosted/sdl/lcd-remote-bitmap.c
+++ b/firmware/target/hosted/sdl/lcd-remote-bitmap.c
@@ -80,11 +80,11 @@ void sim_remote_backlight(int value)
{
if (remote_surface)
{
- if (value > 0)
+ if (value > 0)
{
sdl_set_gradient(remote_surface, &remote_bl_color_dark,
&remote_bl_color_bright, 0, NUM_SHADES);
- }
+ }
else
{
sdl_set_gradient(remote_surface, &remote_color_dark,
@@ -102,10 +102,8 @@ void lcd_remote_init_device(void)
{
if (!showremote)
return;
- remote_surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
- LCD_REMOTE_WIDTH * display_zoom,
- LCD_REMOTE_HEIGHT * display_zoom,
- 8, 0, 0, 0, 0);
+ remote_surface = SDL_CreateRGBSurface(SDL_SWSURFACE, LCD_REMOTE_WIDTH,
+ LCD_REMOTE_HEIGHT, 8, 0, 0, 0, 0);
sdl_set_gradient(remote_surface, &remote_bl_color_dark,
&remote_bl_color_bright, 0, NUM_SHADES);
diff --git a/firmware/target/hosted/sdl/lcd-sdl.c b/firmware/target/hosted/sdl/lcd-sdl.c
index 2e4caa7edc..212d35b88c 100644
--- a/firmware/target/hosted/sdl/lcd-sdl.c
+++ b/firmware/target/hosted/sdl/lcd-sdl.c
@@ -26,7 +26,6 @@
#include "misc.h"
double display_zoom = 1;
-
static bool window_needs_update;
void sdl_get_window_dimensions(int *w, int *h)
@@ -138,18 +137,8 @@ void sdl_update_rect(SDL_Surface *surface, int x_start, int y_start, int width,
src.w = width;
src.h = height;
- if (display_zoom == 1) {
- dest = src;
- SDL_BlitSurface(lcd, &src, surface, &dest);
- } else {
- /* Note: SDL_SoftStretch is currently marked as DO NOT USE
- but there are no real alternatives for efficent zooming. */
- dest.x = src.x * display_zoom;
- dest.y = src.y * display_zoom;
- dest.w = src.w * display_zoom;
- dest.h = src.h * display_zoom;
- SDL_SoftStretch(lcd, &src, surface, &dest);
- }
+ dest = src;
+ SDL_BlitSurface(lcd, &src, surface, &dest);
SDL_FreeSurface(lcd);
#else
int x, y;
@@ -163,26 +152,26 @@ void sdl_update_rect(SDL_Surface *surface, int x_start, int y_start, int width,
if(ymax >= max_y)
ymax = max_y;
- dest.w = display_zoom;
- dest.h = display_zoom;
+ dest.w = 1;
+ dest.h = 1;
for (x = x_start; x < xmax; x++) {
- dest.x = x * display_zoom;
+ dest.x = x;
#ifdef HAVE_LCD_SPLIT
for (y = y_start; y < MIN(ymax, LCD_SPLIT_POS); y++) {
- dest.y = y * display_zoom;
+ dest.y = y;
SDL_FillRect(surface, &dest, (Uint32)(getpixel(x, y) | 0x80));
}
for (y = MAX(y_start, LCD_SPLIT_POS); y < ymax; y++) {
- dest.y = (y + LCD_SPLIT_LINES) * display_zoom ;
+ dest.y = (y + LCD_SPLIT_LINES) ;
SDL_FillRect(surface, &dest, (Uint32)getpixel(x, y));
}
#else
for (y = y_start; y < ymax; y++) {
- dest.y = y * display_zoom;
+ dest.y = y;
SDL_FillRect(surface, &dest, (Uint32)getpixel(x, y));
}
@@ -199,11 +188,8 @@ void sdl_gui_update(SDL_Surface *surface, int x_start, int y_start, int width,
if (y_start + height > max_y)
height = max_y - y_start;
- SDL_Rect src = {x_start * display_zoom, y_start * display_zoom,
- width * display_zoom, height * display_zoom};
- SDL_Rect dest= {(ui_x + x_start) * display_zoom,
- (ui_y + y_start) * display_zoom,
- width * display_zoom, height * display_zoom};
+ SDL_Rect src = {x_start, y_start, width, height};
+ SDL_Rect dest= {ui_x + x_start, ui_y + y_start, width, height};
uint8_t alpha;
if (SDL_GetSurfaceAlphaMod(surface,&alpha) == 0 && alpha < 255)
diff --git a/firmware/target/hosted/sdl/system-sdl.c b/firmware/target/hosted/sdl/system-sdl.c
index e18bbd779c..f135cc7b55 100644
--- a/firmware/target/hosted/sdl/system-sdl.c
+++ b/firmware/target/hosted/sdl/system-sdl.c
@@ -112,10 +112,10 @@ static void sdl_window_setup(void)
if ((sdlRenderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTVSYNC)) == NULL)
panicf("%s", SDL_GetError());
- SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
- SDL_RenderSetLogicalSize(sdlRenderer, width * display_zoom, height * display_zoom);
+ SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, display_zoom == 1 ? "best" : "nearest");
+ SDL_RenderSetLogicalSize(sdlRenderer, width, height);
- if ((gui_surface = SDL_CreateRGBSurface(0, width * display_zoom, height * display_zoom, depth,
+ if ((gui_surface = SDL_CreateRGBSurface(0, width, height, depth,
0, 0, 0, 0)) == NULL)
panicf("%s", SDL_GetError());