forked from len0rd/rockbox
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
This commit is contained in:
parent
60f3283f48
commit
759cbf4e5f
5 changed files with 21 additions and 43 deletions
|
@ -284,8 +284,8 @@ static bool event_handler(SDL_Event *event)
|
||||||
case SDL_MOUSEMOTION:
|
case SDL_MOUSEMOTION:
|
||||||
if (event->motion.state & SDL_BUTTON(1))
|
if (event->motion.state & SDL_BUTTON(1))
|
||||||
{
|
{
|
||||||
int x = event->motion.x / display_zoom;
|
int x = event->motion.x;
|
||||||
int y = event->motion.y / display_zoom;
|
int y = event->motion.y;
|
||||||
touchscreen_event(x, y);
|
touchscreen_event(x, y);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -295,8 +295,6 @@ static bool event_handler(SDL_Event *event)
|
||||||
case SDL_MOUSEBUTTONDOWN:
|
case SDL_MOUSEBUTTONDOWN:
|
||||||
{
|
{
|
||||||
SDL_MouseButtonEvent *mev = &event->button;
|
SDL_MouseButtonEvent *mev = &event->button;
|
||||||
mev->x /= display_zoom;
|
|
||||||
mev->y /= display_zoom;
|
|
||||||
mouse_event(mev, event->type == SDL_MOUSEBUTTONUP);
|
mouse_event(mev, event->type == SDL_MOUSEBUTTONUP);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -183,15 +183,11 @@ void sim_backlight(int value)
|
||||||
void lcd_init_device(void)
|
void lcd_init_device(void)
|
||||||
{
|
{
|
||||||
#if LCD_DEPTH >= 16
|
#if LCD_DEPTH >= 16
|
||||||
lcd_surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
|
lcd_surface = SDL_CreateRGBSurface(SDL_SWSURFACE, SIM_LCD_WIDTH, SIM_LCD_HEIGHT,
|
||||||
SIM_LCD_WIDTH * display_zoom,
|
|
||||||
SIM_LCD_HEIGHT * display_zoom,
|
|
||||||
LCD_DEPTH, 0, 0, 0, 0);
|
LCD_DEPTH, 0, 0, 0, 0);
|
||||||
SDL_SetSurfaceBlendMode(lcd_surface, SDL_BLENDMODE_BLEND);
|
SDL_SetSurfaceBlendMode(lcd_surface, SDL_BLENDMODE_BLEND);
|
||||||
#elif LCD_DEPTH <= 8
|
#elif LCD_DEPTH <= 8
|
||||||
lcd_surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
|
lcd_surface = SDL_CreateRGBSurface(SDL_SWSURFACE, SIM_LCD_WIDTH, SIM_LCD_HEIGHT,
|
||||||
SIM_LCD_WIDTH * display_zoom,
|
|
||||||
SIM_LCD_HEIGHT * display_zoom,
|
|
||||||
8, 0, 0, 0, 0);
|
8, 0, 0, 0, 0);
|
||||||
|
|
||||||
#ifdef HAVE_BACKLIGHT
|
#ifdef HAVE_BACKLIGHT
|
||||||
|
|
|
@ -102,10 +102,8 @@ void lcd_remote_init_device(void)
|
||||||
{
|
{
|
||||||
if (!showremote)
|
if (!showremote)
|
||||||
return;
|
return;
|
||||||
remote_surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
|
remote_surface = SDL_CreateRGBSurface(SDL_SWSURFACE, LCD_REMOTE_WIDTH,
|
||||||
LCD_REMOTE_WIDTH * display_zoom,
|
LCD_REMOTE_HEIGHT, 8, 0, 0, 0, 0);
|
||||||
LCD_REMOTE_HEIGHT * display_zoom,
|
|
||||||
8, 0, 0, 0, 0);
|
|
||||||
|
|
||||||
sdl_set_gradient(remote_surface, &remote_bl_color_dark,
|
sdl_set_gradient(remote_surface, &remote_bl_color_dark,
|
||||||
&remote_bl_color_bright, 0, NUM_SHADES);
|
&remote_bl_color_bright, 0, NUM_SHADES);
|
||||||
|
|
|
@ -26,7 +26,6 @@
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
|
||||||
double display_zoom = 1;
|
double display_zoom = 1;
|
||||||
|
|
||||||
static bool window_needs_update;
|
static bool window_needs_update;
|
||||||
|
|
||||||
void sdl_get_window_dimensions(int *w, int *h)
|
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.w = width;
|
||||||
src.h = height;
|
src.h = height;
|
||||||
|
|
||||||
if (display_zoom == 1) {
|
|
||||||
dest = src;
|
dest = src;
|
||||||
SDL_BlitSurface(lcd, &src, surface, &dest);
|
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);
|
|
||||||
}
|
|
||||||
SDL_FreeSurface(lcd);
|
SDL_FreeSurface(lcd);
|
||||||
#else
|
#else
|
||||||
int x, y;
|
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)
|
if(ymax >= max_y)
|
||||||
ymax = max_y;
|
ymax = max_y;
|
||||||
|
|
||||||
dest.w = display_zoom;
|
dest.w = 1;
|
||||||
dest.h = display_zoom;
|
dest.h = 1;
|
||||||
|
|
||||||
for (x = x_start; x < xmax; x++) {
|
for (x = x_start; x < xmax; x++) {
|
||||||
dest.x = x * display_zoom;
|
dest.x = x;
|
||||||
|
|
||||||
#ifdef HAVE_LCD_SPLIT
|
#ifdef HAVE_LCD_SPLIT
|
||||||
for (y = y_start; y < MIN(ymax, LCD_SPLIT_POS); y++) {
|
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));
|
SDL_FillRect(surface, &dest, (Uint32)(getpixel(x, y) | 0x80));
|
||||||
}
|
}
|
||||||
for (y = MAX(y_start, LCD_SPLIT_POS); y < ymax; y++) {
|
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));
|
SDL_FillRect(surface, &dest, (Uint32)getpixel(x, y));
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
for (y = y_start; y < ymax; y++) {
|
for (y = y_start; y < ymax; y++) {
|
||||||
dest.y = y * display_zoom;
|
dest.y = y;
|
||||||
|
|
||||||
SDL_FillRect(surface, &dest, (Uint32)getpixel(x, 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)
|
if (y_start + height > max_y)
|
||||||
height = max_y - y_start;
|
height = max_y - y_start;
|
||||||
|
|
||||||
SDL_Rect src = {x_start * display_zoom, y_start * display_zoom,
|
SDL_Rect src = {x_start, y_start, width, height};
|
||||||
width * display_zoom, height * display_zoom};
|
SDL_Rect dest= {ui_x + x_start, ui_y + y_start, width, height};
|
||||||
SDL_Rect dest= {(ui_x + x_start) * display_zoom,
|
|
||||||
(ui_y + y_start) * display_zoom,
|
|
||||||
width * display_zoom, height * display_zoom};
|
|
||||||
|
|
||||||
uint8_t alpha;
|
uint8_t alpha;
|
||||||
if (SDL_GetSurfaceAlphaMod(surface,&alpha) == 0 && alpha < 255)
|
if (SDL_GetSurfaceAlphaMod(surface,&alpha) == 0 && alpha < 255)
|
||||||
|
|
|
@ -112,10 +112,10 @@ static void sdl_window_setup(void)
|
||||||
if ((sdlRenderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTVSYNC)) == NULL)
|
if ((sdlRenderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTVSYNC)) == NULL)
|
||||||
panicf("%s", SDL_GetError());
|
panicf("%s", SDL_GetError());
|
||||||
|
|
||||||
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
|
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, display_zoom == 1 ? "best" : "nearest");
|
||||||
SDL_RenderSetLogicalSize(sdlRenderer, width * display_zoom, height * display_zoom);
|
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)
|
0, 0, 0, 0)) == NULL)
|
||||||
panicf("%s", SDL_GetError());
|
panicf("%s", SDL_GetError());
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue