From 0301b29c56a709eba88ef48e216df7ad017394cf Mon Sep 17 00:00:00 2001 From: ro8inmorgan Date: Sat, 17 May 2025 18:47:58 +0200 Subject: [PATCH 1/2] ok now background draws normally also added some mutex locks to be sure --- workspace/all/nextui/nextui.c | 65 +++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 25 deletions(-) diff --git a/workspace/all/nextui/nextui.c b/workspace/all/nextui/nextui.c index ee179c85d..9177138b7 100644 --- a/workspace/all/nextui/nextui.c +++ b/workspace/all/nextui/nextui.c @@ -1642,6 +1642,7 @@ int main (int argc, char *argv[]) { static int readytoscroll = 0; static int folderbgchanged=0; + static int thumbchanged=0; pthread_t cpucheckthread; pthread_create(&cpucheckthread, NULL, PLAT_cpu_monitor, NULL); LOG_info("Start time time %ims\n",SDL_GetTicks()); @@ -2142,6 +2143,7 @@ int main (int argc, char *argv[]) { static int lastType = -1; if(((entry->type == ENTRY_DIR || entry->type == ENTRY_ROM) && CFG_getRomsUseFolderBackground())) { char *newBg = entry->type == ENTRY_DIR ? entry->path:rompath; + SDL_LockMutex(folderBgMutex); if((strcmp(newBg, folderBgPath) != 0 || lastType != entry->type) && sizeof(folderBgPath) != 1) { lastType = entry->type; if(folderbgbmp) SDL_FreeSurface(folderbgbmp); @@ -2150,6 +2152,7 @@ int main (int argc, char *argv[]) { startLoadFolderBackground(folderBgPath, entry->type, onBackgroundLoaded, NULL); folderbgchanged=1; } + SDL_UnlockMutex(folderBgMutex); } // load game thumbnails if (total > 0) { @@ -2159,6 +2162,7 @@ int main (int argc, char *argv[]) { had_thumb = 0; if (exists(thumbpath)) { startLoadThumb(thumbpath, onThumbLoaded, NULL); + thumbchanged = 1; int max_w = (int)(screen->w - (screen->w * CFG_getGameArtWidth())); int max_h = (int)(screen->h * 0.6); int new_w = max_w; @@ -2166,8 +2170,11 @@ int main (int argc, char *argv[]) { had_thumb = 1; ox = (int)(max_w) - SCALE1(BUTTON_MARGIN*5); } else { + SDL_LockMutex(thumbMutex); if(thumbbmp) SDL_FreeSurface(thumbbmp); thumbbmp = NULL; + thumbchanged = 1; + SDL_UnlockMutex(thumbMutex); } } @@ -2316,6 +2323,7 @@ int main (int argc, char *argv[]) { } } + SDL_LockMutex(thumbMutex); if(thumbbmp && lastScreen == SCREEN_GAMELIST) { int img_w = thumbbmp->w; int img_h = thumbbmp->h; @@ -2337,9 +2345,11 @@ int main (int argc, char *argv[]) { int center_y = target_y - (new_h / 2); // FIX: use new_h instead of thumbbmp->h GFX_clearLayers(2); GFX_drawOnLayer(thumbbmp,target_x,center_y,new_w,new_h,1.0f,0,2); + thumbchanged=0 } else if(lastScreen == SCREEN_GAMELIST) { GFX_clearLayers(2); } + SDL_UnlockMutex(thumbMutex); GFX_flip(screen); dirty = 0; readytoscroll = 0; @@ -2349,12 +2359,41 @@ int main (int argc, char *argv[]) { Uint32 now = SDL_GetTicks(); Uint32 frame_start = now; static char cached_display_name[256] = ""; + SDL_LockMutex(folderBgMutex); if(folderbgbmp && CFG_getRomsUseFolderBackground() && folderbgchanged) { // GFX_clearLayers(1); GFX_drawOnLayer(folderbgbmp,0, 0, screen->w, screen->h,1.0f,0,1); + PLAT_GPU_Flip(); folderbgchanged=0; } + SDL_UnlockMutex(folderBgMutex); + SDL_LockMutex(thumbMutex); + if(thumbbmp && thumbchanged) { + int img_w = thumbbmp->w; + int img_h = thumbbmp->h; + double aspect_ratio = (double)img_h / img_w; + + int max_w = (int)(screen->w * CFG_getGameArtWidth()); + int max_h = (int)(screen->h * 0.6); + + int new_w = max_w; + int new_h = (int)(new_w * aspect_ratio); + + if (new_h > max_h) { + new_h = max_h; + new_w = (int)(new_h / aspect_ratio); + } + + int target_x = screen->w-(new_w + SCALE1(BUTTON_MARGIN*3)); + int target_y = (int)(screen->h * 0.50); + int center_y = target_y - (new_h / 2); // FIX: use new_h instead of thumbbmp->h + GFX_clearLayers(2); + GFX_drawOnLayer(thumbbmp,target_x,center_y,new_w,new_h,1.0f,0,2); + } else { + GFX_clearLayers(2); + } + SDL_UnlockMutex(thumbMutex); if (!show_switcher && !show_version && is_scrolling) { int ow = GFX_blitHardwareGroup(screen, show_setting); @@ -2375,32 +2414,8 @@ int main (int argc, char *argv[]) { int max_width = MIN(available_width, text_width); - - if(thumbbmp) { - int img_w = thumbbmp->w; - int img_h = thumbbmp->h; - double aspect_ratio = (double)img_h / img_w; - - int max_w = (int)(screen->w * CFG_getGameArtWidth()); - int max_h = (int)(screen->h * 0.6); - - int new_w = max_w; - int new_h = (int)(new_w * aspect_ratio); - - if (new_h > max_h) { - new_h = max_h; - new_w = (int)(new_h / aspect_ratio); - } - - int target_x = screen->w-(new_w + SCALE1(BUTTON_MARGIN*3)); - int target_y = (int)(screen->h * 0.50); - int center_y = target_y - (new_h / 2); // FIX: use new_h instead of thumbbmp->h - GFX_clearLayers(2); - GFX_drawOnLayer(thumbbmp,target_x,center_y,new_w,new_h,1.0f,0,2); - } else { - GFX_clearLayers(2); - } + GFX_clearLayers(4); GFX_scrollTextTexture( font.large, From f6094e1a3178f26a6f2c92ca05288a00cdc467d1 Mon Sep 17 00:00:00 2001 From: ro8inmorgan Date: Sat, 17 May 2025 20:24:33 +0200 Subject: [PATCH 2/2] ok all fixed up --- workspace/all/nextui/nextui.c | 55 ++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/workspace/all/nextui/nextui.c b/workspace/all/nextui/nextui.c index 9177138b7..4b6d306a6 100644 --- a/workspace/all/nextui/nextui.c +++ b/workspace/all/nextui/nextui.c @@ -1482,10 +1482,12 @@ void initImageLoaderPool() { } } +static int folderbgchanged=0; +static int thumbchanged=0; + void startLoadFolderBackground(const char* rompath, int type, BackgroundLoadedCallback callback, void* userData) { LoadBackgroundTask* task = malloc(sizeof(LoadBackgroundTask)); if (!task) return; -LOG_info("background start\n"); if (type == ENTRY_DIR) snprintf(task->imagePath, sizeof(task->imagePath), "%s/.media/bg.png", rompath); else if (type == ENTRY_ROM) @@ -1501,11 +1503,11 @@ LOG_info("background start\n"); } void onBackgroundLoaded(SDL_Surface* surface) { - LOG_info("background loaded\n"); if (!surface) return; SDL_LockMutex(folderBgMutex); if (folderbgbmp) SDL_FreeSurface(folderbgbmp); folderbgbmp = surface; + folderbgchanged = 1; SDL_UnlockMutex(folderBgMutex); } @@ -1540,13 +1542,7 @@ void onThumbLoaded(SDL_Surface* surface) { new_h = max_h; new_w = (int)(new_h / aspect_ratio); } - - GFX_ApplyRoundedCorners_RGBA8888( - thumbbmp, - &(SDL_Rect){0, 0, thumbbmp->w, thumbbmp->h}, - SCALE1((float)CFG_getThumbnailRadius() * ((float)img_w / (float)new_w)) - ); - + thumbchanged = 1; SDL_UnlockMutex(thumbMutex); } @@ -1641,8 +1637,7 @@ int main (int argc, char *argv[]) { SDL_FillRect(blackBG,NULL,SDL_MapRGBA(screen->format,0,0,0,255)); static int readytoscroll = 0; - static int folderbgchanged=0; - static int thumbchanged=0; + pthread_t cpucheckthread; pthread_create(&cpucheckthread, NULL, PLAT_cpu_monitor, NULL); LOG_info("Start time time %ims\n",SDL_GetTicks()); @@ -2150,7 +2145,6 @@ int main (int argc, char *argv[]) { folderbgbmp = NULL; strncpy(folderBgPath, newBg, sizeof(folderBgPath) - 1); startLoadFolderBackground(folderBgPath, entry->type, onBackgroundLoaded, NULL); - folderbgchanged=1; } SDL_UnlockMutex(folderBgMutex); } @@ -2161,8 +2155,8 @@ int main (int argc, char *argv[]) { snprintf(thumbpath, sizeof(thumbpath), "%s/.media/%s.png", rompath, res_copy); had_thumb = 0; if (exists(thumbpath)) { + LOG_info("Load thumb\n"); startLoadThumb(thumbpath, onThumbLoaded, NULL); - thumbchanged = 1; int max_w = (int)(screen->w - (screen->w * CFG_getGameArtWidth())); int max_h = (int)(screen->h * 0.6); int new_w = max_w; @@ -2173,7 +2167,7 @@ int main (int argc, char *argv[]) { SDL_LockMutex(thumbMutex); if(thumbbmp) SDL_FreeSurface(thumbbmp); thumbbmp = NULL; - thumbchanged = 1; + GFX_clearLayers(2); SDL_UnlockMutex(thumbMutex); } } @@ -2314,7 +2308,7 @@ int main (int argc, char *argv[]) { SDL_FreeSurface(tmpNewScreen); animationdirection=0; } - + SDL_LockMutex(folderBgMutex); if(folderbgchanged) { GFX_clearLayers(1); if(folderbgbmp && CFG_getRomsUseFolderBackground()) { @@ -2323,8 +2317,10 @@ int main (int argc, char *argv[]) { } } + SDL_UnlockMutex(folderBgMutex); SDL_LockMutex(thumbMutex); - if(thumbbmp && lastScreen == SCREEN_GAMELIST) { + if(thumbbmp && lastScreen == SCREEN_GAMELIST && thumbchanged) { + LOG_info("draw thumb\n"); int img_w = thumbbmp->w; int img_h = thumbbmp->h; double aspect_ratio = (double)img_h / img_w; @@ -2339,16 +2335,16 @@ int main (int argc, char *argv[]) { new_h = max_h; new_w = (int)(new_h / aspect_ratio); } - + GFX_ApplyRoundedCorners_RGBA8888( + thumbbmp, + &(SDL_Rect){0, 0, thumbbmp->w, thumbbmp->h}, + SCALE1((float)CFG_getThumbnailRadius() * ((float)img_w / (float)new_w)) + ); int target_x = screen->w-(new_w + SCALE1(BUTTON_MARGIN*3)); int target_y = (int)(screen->h * 0.50); int center_y = target_y - (new_h / 2); // FIX: use new_h instead of thumbbmp->h - GFX_clearLayers(2); GFX_drawOnLayer(thumbbmp,target_x,center_y,new_w,new_h,1.0f,0,2); - thumbchanged=0 - } else if(lastScreen == SCREEN_GAMELIST) { - GFX_clearLayers(2); - } + } SDL_UnlockMutex(thumbMutex); GFX_flip(screen); dirty = 0; @@ -2370,6 +2366,7 @@ int main (int argc, char *argv[]) { SDL_LockMutex(thumbMutex); if(thumbbmp && thumbchanged) { + int img_w = thumbbmp->w; int img_h = thumbbmp->h; double aspect_ratio = (double)img_h / img_w; @@ -2384,16 +2381,22 @@ int main (int argc, char *argv[]) { new_h = max_h; new_w = (int)(new_h / aspect_ratio); } - + GFX_ApplyRoundedCorners_RGBA8888( + thumbbmp, + &(SDL_Rect){0, 0, thumbbmp->w, thumbbmp->h}, + SCALE1((float)CFG_getThumbnailRadius() * ((float)img_w / (float)new_w)) + ); int target_x = screen->w-(new_w + SCALE1(BUTTON_MARGIN*3)); int target_y = (int)(screen->h * 0.50); int center_y = target_y - (new_h / 2); // FIX: use new_h instead of thumbbmp->h GFX_clearLayers(2); GFX_drawOnLayer(thumbbmp,target_x,center_y,new_w,new_h,1.0f,0,2); - } else { - GFX_clearLayers(2); - } + PLAT_GPU_Flip(); + thumbchanged = 0; + LOG_info("second draw \n"); + } SDL_UnlockMutex(thumbMutex); + if (!show_switcher && !show_version && is_scrolling) { int ow = GFX_blitHardwareGroup(screen, show_setting);