1
0
Fork 0
forked from len0rd/rockbox

sdl: Keep texture around, upload LCD-parts only

No need to create a new texture for every
rendered frame, unless the scaling method
has been adjusted.

We also don't need to upload the (unchanged)
player interface to GPU memory repeatedly.

+ Remove unused lcd_display_redraw &
having_new_lcd variables

Change-Id: I5bff6aa2d54347a3f2c3afba8d8d7eb9e39f77f7
This commit is contained in:
Christian Soffke 2024-12-22 22:55:27 +01:00
parent 7aaa722a5d
commit 400452180d
8 changed files with 279 additions and 186 deletions

View file

@ -23,105 +23,7 @@
#include "lcd-sdl.h"
#include "sim-ui-defines.h"
#include "system.h" /* for MIN() and MAX() */
#include "misc.h"
double display_zoom = 1;
static bool window_needs_update;
void sdl_get_window_dimensions(int *w, int *h)
{
if (background)
{
*w = UI_WIDTH;
*h = UI_HEIGHT;
}
else
{
#ifdef HAVE_REMOTE_LCD
if (showremote)
{
*w = SIM_LCD_WIDTH > SIM_REMOTE_WIDTH ? SIM_LCD_WIDTH : SIM_REMOTE_WIDTH;
*h = SIM_LCD_HEIGHT + SIM_REMOTE_HEIGHT;
}
else
#endif
{
*w = SIM_LCD_WIDTH;
*h = SIM_LCD_HEIGHT;
}
}
}
static inline void sdl_render(void)
{
SDL_Texture *sdlTexture = SDL_CreateTextureFromSurface(sdlRenderer, gui_surface);
SDL_RenderClear(sdlRenderer);
SDL_RenderCopy(sdlRenderer, sdlTexture, NULL, NULL);
SDL_RenderPresent(sdlRenderer);
SDL_DestroyTexture(sdlTexture);
}
#define SNAP_MARGIN 50
int sdl_update_window(void)
{
int w, h;
if (!window_needs_update)
return false;
window_needs_update = false;
sdl_get_window_dimensions(&w, &h);
if (!(SDL_GetWindowFlags(window) & (SDL_WINDOW_MAXIMIZED | SDL_WINDOW_FULLSCREEN)))
{
if (display_zoom)
{
SDL_SetWindowSize(window, display_zoom * w, display_zoom * h);
}
#if defined(__APPLE__) || defined(__WIN32)
else /* Constrain aspect ratio on Windows and MacOS */
{
float aspect_ratio = (float) h / w;
int original_height = h;
int original_width = w;
SDL_GetWindowSize(window, &w, &h);
if (w != original_width || h != original_height)
{
if (abs(original_width - w) < SNAP_MARGIN)
{
w = original_width;
h = original_height;
}
else
h = w * aspect_ratio;
SDL_SetWindowSize(window, w, h);
}
}
#endif
}
display_zoom = 0;
sdl_render();
return true;
}
void sdl_window_needs_update(void)
{
window_needs_update = true;
/* For MacOS and Windows, we're on a main or
display thread already, and can immediately
update the window.
On Linux, we have to defer the update, until
it is handled by the main thread later. */
#if defined (__APPLE__) || defined(__WIN32)
sdl_update_window();
#endif
}
#include "window-sdl.h"
void sdl_update_rect(SDL_Surface *surface, int x_start, int y_start, int width,
int height, int max_x, int max_y,
@ -201,12 +103,14 @@ void sdl_gui_update(SDL_Surface *surface, int x_start, int y_start, int width,
uint8_t alpha;
if (SDL_GetSurfaceAlphaMod(surface,&alpha) == 0 && alpha < 255)
SDL_FillRect(gui_surface, &dest, 0); /* alpha needs a black background */
SDL_FillRect(sim_lcd_surface, NULL, 0); /* alpha needs a black background */
SDL_BlitSurface(surface, &src, gui_surface, &dest);
SDL_BlitSurface(surface, &src, sim_lcd_surface, NULL);
SDL_UpdateTexture(gui_texture, &dest,
sim_lcd_surface->pixels, sim_lcd_surface->pitch);
if (!sdl_update_window()) /* already calls sdl_render itself */
sdl_render();
if (!sdl_window_adjust()) /* already calls sdl_window_render itself */
sdl_window_render();
}
/* set a range of bitmap indices to a gradient from startcolour to endcolour */