Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+279 -186
+1
firmware/SOURCES
··· 74 74 target/hosted/sdl/lcd-remote-bitmap.c 75 75 #endif 76 76 target/hosted/sdl/lcd-sdl.c 77 + target/hosted/sdl/window-sdl.c 77 78 target/hosted/sdl/system-sdl.c 78 79 #ifdef HAVE_SDL_THREADS 79 80 target/hosted/sdl/filesystem-sdl.c
+2 -2
firmware/drivers/button_queue.c
··· 24 24 #include "button.h" 25 25 #ifdef HAVE_SDL 26 26 #include "button-sdl.h" 27 - #include "lcd-sdl.h" 27 + #include "window-sdl.h" 28 28 #endif 29 29 30 30 static struct event_queue button_queue SHAREDBSS_ATTR; ··· 119 119 #else 120 120 queue_wait_w_tmo(&button_queue, evp, timeout); 121 121 #ifdef HAVE_SDL 122 - sdl_update_window(); /* Window may have been resized */ 122 + sdl_window_adjust(); /* Window may have been resized */ 123 123 #endif 124 124 #endif 125 125 }
+3 -3
firmware/target/hosted/sdl/button-sdl.c
··· 31 31 #include "backlight.h" 32 32 #include "system.h" 33 33 #include "button-sdl.h" 34 - #include "lcd-sdl.h" 34 + #include "window-sdl.h" 35 35 #include "sim_tasks.h" 36 36 #include "buttonmap.h" 37 37 #include "debug.h" ··· 243 243 sdl_app_has_input_focus = 0; 244 244 else if(event->window.event == SDL_WINDOWEVENT_RESIZED) 245 245 { 246 - sdl_window_needs_update(); 246 + sdl_window_adjustment_needed(false); 247 247 #if !defined (__APPLE__) && !defined(__WIN32) 248 248 static unsigned long last_tick; 249 249 if (TIME_AFTER(current_tick, last_tick + HZ/20) && !button_queue_full()) ··· 370 370 strcmp(SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY) ?: 371 371 "best", "best") ? "best": "nearest"); 372 372 373 - sdl_window_needs_update(); 373 + sdl_window_adjustment_needed(!display_zoom); 374 374 #if !defined(__WIN32) && !defined (__APPLE__) 375 375 button_queue_post(SDLK_UNKNOWN, 0); /* update window on main thread */ 376 376 #endif
+7 -103
firmware/target/hosted/sdl/lcd-sdl.c
··· 23 23 #include "lcd-sdl.h" 24 24 #include "sim-ui-defines.h" 25 25 #include "system.h" /* for MIN() and MAX() */ 26 - #include "misc.h" 27 - 28 - double display_zoom = 1; 29 - static bool window_needs_update; 30 - 31 - void sdl_get_window_dimensions(int *w, int *h) 32 - { 33 - if (background) 34 - { 35 - *w = UI_WIDTH; 36 - *h = UI_HEIGHT; 37 - } 38 - else 39 - { 40 - #ifdef HAVE_REMOTE_LCD 41 - if (showremote) 42 - { 43 - *w = SIM_LCD_WIDTH > SIM_REMOTE_WIDTH ? SIM_LCD_WIDTH : SIM_REMOTE_WIDTH; 44 - *h = SIM_LCD_HEIGHT + SIM_REMOTE_HEIGHT; 45 - } 46 - else 47 - #endif 48 - { 49 - *w = SIM_LCD_WIDTH; 50 - *h = SIM_LCD_HEIGHT; 51 - } 52 - } 53 - } 54 - 55 - static inline void sdl_render(void) 56 - { 57 - SDL_Texture *sdlTexture = SDL_CreateTextureFromSurface(sdlRenderer, gui_surface); 58 - SDL_RenderClear(sdlRenderer); 59 - SDL_RenderCopy(sdlRenderer, sdlTexture, NULL, NULL); 60 - SDL_RenderPresent(sdlRenderer); 61 - SDL_DestroyTexture(sdlTexture); 62 - } 63 - 64 - 65 - #define SNAP_MARGIN 50 66 - int sdl_update_window(void) 67 - { 68 - int w, h; 69 - 70 - if (!window_needs_update) 71 - return false; 72 - window_needs_update = false; 73 - 74 - sdl_get_window_dimensions(&w, &h); 75 - 76 - if (!(SDL_GetWindowFlags(window) & (SDL_WINDOW_MAXIMIZED | SDL_WINDOW_FULLSCREEN))) 77 - { 78 - if (display_zoom) 79 - { 80 - SDL_SetWindowSize(window, display_zoom * w, display_zoom * h); 81 - } 82 - #if defined(__APPLE__) || defined(__WIN32) 83 - else /* Constrain aspect ratio on Windows and MacOS */ 84 - { 85 - 86 - float aspect_ratio = (float) h / w; 87 - int original_height = h; 88 - int original_width = w; 89 - 90 - SDL_GetWindowSize(window, &w, &h); 91 - if (w != original_width || h != original_height) 92 - { 93 - if (abs(original_width - w) < SNAP_MARGIN) 94 - { 95 - w = original_width; 96 - h = original_height; 97 - } 98 - else 99 - h = w * aspect_ratio; 100 - 101 - SDL_SetWindowSize(window, w, h); 102 - } 103 - } 104 - #endif 105 - } 106 - display_zoom = 0; 107 - sdl_render(); 108 - return true; 109 - } 110 - 111 - void sdl_window_needs_update(void) 112 - { 113 - window_needs_update = true; 114 - 115 - /* For MacOS and Windows, we're on a main or 116 - display thread already, and can immediately 117 - update the window. 118 - On Linux, we have to defer the update, until 119 - it is handled by the main thread later. */ 120 - #if defined (__APPLE__) || defined(__WIN32) 121 - sdl_update_window(); 122 - #endif 123 - } 124 - 26 + #include "window-sdl.h" 125 27 126 28 void sdl_update_rect(SDL_Surface *surface, int x_start, int y_start, int width, 127 29 int height, int max_x, int max_y, ··· 201 103 202 104 uint8_t alpha; 203 105 if (SDL_GetSurfaceAlphaMod(surface,&alpha) == 0 && alpha < 255) 204 - SDL_FillRect(gui_surface, &dest, 0); /* alpha needs a black background */ 106 + SDL_FillRect(sim_lcd_surface, NULL, 0); /* alpha needs a black background */ 205 107 206 - SDL_BlitSurface(surface, &src, gui_surface, &dest); 108 + SDL_BlitSurface(surface, &src, sim_lcd_surface, NULL); 109 + SDL_UpdateTexture(gui_texture, &dest, 110 + sim_lcd_surface->pixels, sim_lcd_surface->pitch); 207 111 208 - if (!sdl_update_window()) /* already calls sdl_render itself */ 209 - sdl_render(); 112 + if (!sdl_window_adjust()) /* already calls sdl_window_render itself */ 113 + sdl_window_render(); 210 114 } 211 115 212 116 /* set a range of bitmap indices to a gradient from startcolour to endcolour */
-9
firmware/target/hosted/sdl/lcd-sdl.h
··· 25 25 #include "lcd.h" 26 26 #include "SDL.h" 27 27 28 - /* Default display zoom level */ 29 - extern SDL_Surface *gui_surface; 30 - extern SDL_Renderer *sdlRenderer; 31 - extern SDL_Window *window; 32 - 33 - void sdl_get_window_dimensions(int *w, int *h); 34 - int sdl_update_window(void); 35 - void sdl_window_needs_update(void); 36 - 37 28 void sdl_update_rect(SDL_Surface *surface, int x_start, int y_start, int width, 38 29 int height, int max_x, int max_y, 39 30 unsigned long (*getpixel)(int, int));
+2 -69
firmware/target/hosted/sdl/system-sdl.c
··· 32 32 #include "thread-sdl.h" 33 33 #include "system-sdl.h" 34 34 #include "sim-ui-defines.h" 35 - #include "lcd-sdl.h" 35 + #include "window-sdl.h" 36 36 #include "lcd-bitmap.h" 37 37 #ifdef HAVE_REMOTE_LCD 38 38 #include "lcd-remote-bitmap.h" ··· 44 44 #include <glib.h> 45 45 #include <glib-object.h> 46 46 #include "maemo-thread.h" 47 - 48 47 #endif 49 48 50 49 #define SIMULATOR_DEFAULT_ROOT "simdisk" 51 50 52 - SDL_Surface *gui_surface; 53 - SDL_Window *window; 54 - SDL_Renderer *sdlRenderer; 55 - 56 51 bool background = true; /* use backgrounds by default */ 57 52 #ifdef HAVE_REMOTE_LCD 58 53 bool showremote = true; /* include remote by default */ ··· 61 56 const char *audiodev = NULL; 62 57 bool debug_buttons = false; 63 58 64 - bool lcd_display_redraw = true; /* Used for player simulator */ 65 - char having_new_lcd = true; /* Used for player simulator */ 66 59 bool sim_alarm_wakeup = false; 67 60 const char *sim_root_dir = SIMULATOR_DEFAULT_ROOT; 68 61 ··· 75 68 bool debug_wps = false; 76 69 int wps_verbose_level = 3; 77 70 78 - static void sdl_window_setup(void) 79 - { 80 - SDL_Surface *picture_surface = NULL; 81 - int width, height; 82 - int depth; 83 - Uint32 flags = 0; 84 - 85 - /* Try and load the background image. If it fails go without */ 86 - if (background) { 87 - picture_surface = SDL_LoadBMP("UI256.bmp"); 88 - if (picture_surface == NULL) { 89 - background = false; 90 - DEBUGF("warn: %s\n", SDL_GetError()); 91 - } 92 - } 93 - 94 - sdl_get_window_dimensions(&width, &height); 95 - depth = LCD_DEPTH; 96 - if (depth < 8) 97 - depth = 16; 98 - 99 - #if (CONFIG_PLATFORM & (PLATFORM_MAEMO|PLATFORM_PANDORA)) 100 - /* Fullscreen mode for maemo app */ 101 - flags |= SDL_WINDOW_FULLSCREEN; 102 - #endif 103 - 104 - if (display_zoom == 1) 105 - flags |= SDL_WINDOW_RESIZABLE; 106 - 107 - flags |= SDL_WINDOW_ALLOW_HIGHDPI; 108 - 109 - if ((window = SDL_CreateWindow(UI_TITLE, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 110 - width * display_zoom, height * display_zoom , flags)) == NULL) 111 - panicf("%s", SDL_GetError()); 112 - if ((sdlRenderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTVSYNC)) == NULL) 113 - panicf("%s", SDL_GetError()); 114 - 115 - SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, display_zoom == 1 ? "best" : "nearest"); 116 - display_zoom = 0; /* keeps track of user requesting a scale level change */ 117 - SDL_RenderSetLogicalSize(sdlRenderer, width, height); 118 - 119 - if ((gui_surface = SDL_CreateRGBSurface(0, width, height, depth, 120 - 0, 0, 0, 0)) == NULL) 121 - panicf("%s", SDL_GetError()); 122 - 123 - /* If we have a background, blit it over to the display surface */ 124 - if (background && picture_surface) 125 - { 126 - SDL_BlitSurface(picture_surface, NULL, gui_surface, NULL); 127 - SDL_FreeSurface(picture_surface); 128 - } 129 - } 130 - 131 71 #ifndef __APPLE__ /* MacOS requires events to be handled on main thread */ 132 72 /* 133 73 * This thread will read the buttons in an interrupt like fashion, and ··· 173 113 /* let system_init proceed */ 174 114 SDL_SemPost((SDL_sem *)param); 175 115 176 - /* 177 - * finally enter the button loop */ 116 + /* finally enter the button loop */ 178 117 gui_message_loop(); 179 118 180 119 #if (CONFIG_PLATFORM & PLATFORM_MAEMO5) ··· 354 293 printf("Disabling remote image.\n"); 355 294 } 356 295 #endif 357 - else if (!strcmp("--old_lcd", argv[x])) 358 - { 359 - having_new_lcd = false; 360 - printf("Using old LCD layout.\n"); 361 - } 362 296 else if (!strcmp("--zoom", argv[x])) 363 297 { 364 298 x++; ··· 413 347 #ifdef HAVE_REMOTE_LCD 414 348 printf(" --noremote \t Disable the remote image (will disable backgrounds)\n"); 415 349 #endif 416 - printf(" --old_lcd \t [Player] simulate old playermodel (ROM version<4.51)\n"); 417 350 printf(" --zoom [VAL]\t Window zoom (will disable backgrounds)\n"); 418 351 printf(" --alarm \t Simulate a wake-up on alarm\n"); 419 352 printf(" --root [DIR]\t Set root directory\n");
+223
firmware/target/hosted/sdl/window-sdl.c
··· 1 + /*************************************************************************** 2 + * __________ __ ___. 3 + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 + * \/ \/ \/ \/ \/ 8 + * $Id$ 9 + * 10 + * 11 + * This program is free software; you can redistribute it and/or 12 + * modify it under the terms of the GNU General Public License 13 + * as published by the Free Software Foundation; either version 2 14 + * of the License, or (at your option) any later version. 15 + * 16 + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 17 + * KIND, either express or implied. 18 + * 19 + ****************************************************************************/ 20 + 21 + #include <SDL.h> 22 + #include "sim-ui-defines.h" 23 + #include "window-sdl.h" 24 + #include "lcd-sdl.h" 25 + #include "misc.h" 26 + #include "panic.h" 27 + 28 + extern SDL_Surface *lcd_surface; 29 + #ifdef HAVE_REMOTE_LCD 30 + extern SDL_Surface *remote_surface; 31 + #endif 32 + 33 + SDL_Texture *gui_texture; 34 + SDL_Surface *sim_lcd_surface; 35 + 36 + static SDL_Window *window; 37 + static SDL_Renderer *sdlRenderer; 38 + static SDL_Surface *picture_surface; 39 + 40 + static bool new_gui_texture_needed = true; 41 + static bool window_adjustment_needed; 42 + double display_zoom = 1; 43 + 44 + static void get_window_dimensions(int *w, int *h) 45 + { 46 + if (background) 47 + { 48 + *w = UI_WIDTH; 49 + *h = UI_HEIGHT; 50 + } 51 + else 52 + { 53 + #ifdef HAVE_REMOTE_LCD 54 + if (showremote) 55 + { 56 + *w = SIM_LCD_WIDTH > SIM_REMOTE_WIDTH ? SIM_LCD_WIDTH : SIM_REMOTE_WIDTH; 57 + *h = SIM_LCD_HEIGHT + SIM_REMOTE_HEIGHT; 58 + } 59 + else 60 + #endif 61 + { 62 + *w = SIM_LCD_WIDTH; 63 + *h = SIM_LCD_HEIGHT; 64 + } 65 + } 66 + } 67 + 68 + #define SNAP_MARGIN 50 69 + static void restore_aspect_ratio(int w, int h) 70 + { 71 + float aspect_ratio = (float) h / w; 72 + int original_height = h; 73 + int original_width = w; 74 + 75 + if ((SDL_GetWindowFlags(window) & (SDL_WINDOW_MAXIMIZED | SDL_WINDOW_FULLSCREEN)) 76 + || display_zoom) 77 + return; 78 + 79 + SDL_GetWindowSize(window, &w, &h); 80 + if (w != original_width || h != original_height) 81 + { 82 + if (abs(original_width - w) < SNAP_MARGIN) 83 + { 84 + w = original_width; 85 + h = original_height; 86 + } 87 + else 88 + h = w * aspect_ratio; 89 + 90 + SDL_SetWindowSize(window, w, h); 91 + } 92 + } 93 + 94 + static void rebuild_gui_texture(void) 95 + { 96 + SDL_Surface *gui_surface; 97 + int w, h, depth = LCD_DEPTH < 8 ? 16 : LCD_DEPTH; 98 + 99 + get_window_dimensions(&w, &h); 100 + SDL_RenderSetLogicalSize(sdlRenderer, w, h); 101 + if ((gui_texture = SDL_CreateTexture(sdlRenderer, SDL_MasksToPixelFormatEnum(depth, 102 + 0, 0, 0, 0), SDL_TEXTUREACCESS_STATIC, w, h)) == NULL) 103 + panicf("%s", SDL_GetError()); 104 + 105 + if (SDL_GetWindowFlags(window) & SDL_WINDOW_RESIZABLE) 106 + restore_aspect_ratio(w, h); 107 + 108 + if (background && picture_surface && 109 + (gui_surface = SDL_ConvertSurface(picture_surface, sim_lcd_surface->format, 0))) 110 + { 111 + SDL_UpdateTexture(gui_texture, NULL, gui_surface->pixels, gui_surface->pitch); 112 + SDL_FreeSurface(gui_surface); 113 + } 114 + 115 + sdl_gui_update(lcd_surface, 0, 0, SIM_LCD_WIDTH, SIM_LCD_HEIGHT, 116 + SIM_LCD_WIDTH, SIM_LCD_HEIGHT, 117 + background ? UI_LCD_POSX : 0, background? UI_LCD_POSY : 0); 118 + 119 + #ifdef HAVE_REMOTE_LCD 120 + sdl_gui_update(remote_surface, 0, 0, LCD_REMOTE_WIDTH, LCD_REMOTE_HEIGHT, 121 + LCD_REMOTE_WIDTH, LCD_REMOTE_HEIGHT, 122 + background ? UI_REMOTE_POSX : 0, 123 + background? UI_REMOTE_POSY : LCD_HEIGHT); 124 + #endif 125 + } 126 + 127 + void sdl_window_render(void) 128 + { 129 + if (new_gui_texture_needed) 130 + { 131 + new_gui_texture_needed = false; 132 + if (gui_texture) 133 + SDL_DestroyTexture(gui_texture); 134 + rebuild_gui_texture(); 135 + } 136 + else 137 + { 138 + SDL_RenderClear(sdlRenderer); 139 + SDL_RenderCopy(sdlRenderer, gui_texture, NULL, NULL); 140 + SDL_RenderPresent(sdlRenderer); 141 + } 142 + } 143 + 144 + bool sdl_window_adjust(void) 145 + { 146 + int w, h; 147 + 148 + if (!window_adjustment_needed) 149 + return false; 150 + window_adjustment_needed = false; 151 + 152 + get_window_dimensions(&w, &h); 153 + 154 + if (!(SDL_GetWindowFlags(window) & (SDL_WINDOW_MAXIMIZED | SDL_WINDOW_FULLSCREEN)) 155 + && display_zoom) 156 + { 157 + SDL_SetWindowSize(window, display_zoom * w, display_zoom * h); 158 + } 159 + #if defined(__APPLE__) || defined(__WIN32) 160 + restore_aspect_ratio(w, h); 161 + #endif 162 + display_zoom = 0; 163 + sdl_window_render(); 164 + return true; 165 + } 166 + 167 + void sdl_window_adjustment_needed(bool destroy_texture) 168 + { 169 + window_adjustment_needed = true; 170 + new_gui_texture_needed = destroy_texture; 171 + 172 + /* For MacOS and Windows, we're on a main or 173 + display thread already, and can immediately 174 + adjust the window. 175 + On Linux, we have to defer the update, until 176 + it is handled by the main thread later. */ 177 + #if defined (__APPLE__) || defined(__WIN32) 178 + sdl_window_adjust(); 179 + #endif 180 + } 181 + 182 + void sdl_window_setup(void) 183 + { 184 + int width, height; 185 + int depth = LCD_DEPTH < 8 ? 16 : LCD_DEPTH; 186 + Uint32 flags = SDL_WINDOW_ALLOW_HIGHDPI; 187 + 188 + #if (CONFIG_PLATFORM & (PLATFORM_MAEMO|PLATFORM_PANDORA)) 189 + /* Fullscreen mode for maemo app */ 190 + flags |= SDL_WINDOW_FULLSCREEN; 191 + #else 192 + if (display_zoom == 1) 193 + flags |= SDL_WINDOW_RESIZABLE; 194 + #endif 195 + 196 + if (!(picture_surface = SDL_LoadBMP("UI256.bmp"))) 197 + background = false; 198 + 199 + get_window_dimensions(&width, &height); 200 + 201 + if ((window = SDL_CreateWindow(UI_TITLE, SDL_WINDOWPOS_CENTERED, 202 + SDL_WINDOWPOS_CENTERED, width * display_zoom, 203 + height * display_zoom , flags)) == NULL) 204 + panicf("%s", SDL_GetError()); 205 + if ((sdlRenderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTVSYNC)) == NULL) 206 + panicf("%s", SDL_GetError()); 207 + 208 + /* Surface for LCD content only. Needs to fit largest LCD */ 209 + if ((sim_lcd_surface = SDL_CreateRGBSurface(0, 210 + #ifdef HAVE_REMOTE_LCD 211 + SIM_LCD_WIDTH > SIM_REMOTE_WIDTH ? 212 + SIM_LCD_WIDTH : SIM_REMOTE_WIDTH, 213 + SIM_LCD_HEIGHT > SIM_REMOTE_HEIGHT ? 214 + SIM_LCD_HEIGHT : SIM_REMOTE_HEIGHT, 215 + #else 216 + SIM_LCD_WIDTH, SIM_LCD_HEIGHT, 217 + #endif 218 + depth, 0, 0, 0, 0)) == NULL) 219 + panicf("%s", SDL_GetError()); 220 + 221 + SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, display_zoom == 1 ? "best" : "nearest"); 222 + display_zoom = 0; /* reset to 0 unless/until user requests a scale level change */ 223 + }
+41
firmware/target/hosted/sdl/window-sdl.h
··· 1 + /*************************************************************************** 2 + * __________ __ ___. 3 + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 + * \/ \/ \/ \/ \/ 8 + * $Id$ 9 + * 10 + * 11 + * This program is free software; you can redistribute it and/or 12 + * modify it under the terms of the GNU General Public License 13 + * as published by the Free Software Foundation; either version 2 14 + * of the License, or (at your option) any later version. 15 + * 16 + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 17 + * KIND, either express or implied. 18 + * 19 + ****************************************************************************/ 20 + 21 + #ifndef __WINDOWSDL_H__ 22 + #define __WINDOWSDL_H__ 23 + 24 + #include "SDL.h" 25 + 26 + extern SDL_Texture *gui_texture; /* Window content, including background */ 27 + extern SDL_Surface *sim_lcd_surface; /* LCD content */ 28 + 29 + /* Renders GUI texture. Sets up new texture, if necessary */ 30 + void sdl_window_render(void); 31 + 32 + /* Updates size, aspect ratio, and re-renders window content */ 33 + bool sdl_window_adjust(void); 34 + 35 + /* Needs to be called when window size, scale quality, or background should change */ 36 + void sdl_window_adjustment_needed(bool destroy_texture); 37 + 38 + /* Creates window, renderer, and LCD surface when app launches */ 39 + void sdl_window_setup(void); 40 + 41 + #endif /* #ifndef __WINDOWSDL_H__ */