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:
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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());
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue