From 2bab844852641648870d7380a271859bd8dc77c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 15 Sep 2025 14:18:10 -0600 Subject: [PATCH] Do the loading of the atlas texture and metadata together. --- UI/NativeApp.cpp | 36 -------------------------------- UI/Theme.cpp | 53 ++++++++++++++++++++++++++++++++++++------------ UI/Theme.h | 2 ++ 3 files changed, 42 insertions(+), 49 deletions(-) diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index f23151fdce..e2179fb55e 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -87,8 +87,6 @@ #include "Common/VR/PPSSPPVR.h" #include "Common/Thread/ThreadManager.h" #include "Common/Audio/AudioBackend.h" -#include "Common/Render/ManagedTexture.h" - #include "Core/ControlMapper.h" #include "Core/Config.h" #include "Core/ConfigValues.h" @@ -821,40 +819,6 @@ static void NativeMixWrapper(float *dest, int framesToWrite, int sampleRateHz, v } } -static AtlasData AtlasProvider(Draw::DrawContext *draw, AtlasChoice atlas) { - switch (atlas) { - case AtlasChoice::General: - return { - GetUIAtlas(), - CreateTextureFromFile(draw, "ui_atlas.zim", ImageFileType::ZIM, false) - }; - case AtlasChoice::Font: - { - Draw::Texture *fontTexture = nullptr; - // NOTE: This ugly check must be the same as the one in UpdateTheme. This will be fixed. -#if PPSSPP_PLATFORM(WINDOWS) || PPSSPP_PLATFORM(ANDROID) || PPSSPP_PLATFORM(MAC) || PPSSPP_PLATFORM(IOS) - // Don't bother with loading font_atlas.zim -#else - fontTexture = CreateTextureFromFile(draw_, "font_atlas.zim", ImageFileType::ZIM, false); -#endif - if (!fontTexture) { - // Load the smaller ascii font only, like on Android. For debug ui etc. - // NOTE: We better be sure here that the correct metadata is loaded.. - fontTexture = CreateTextureFromFile(draw, "asciifont_atlas.zim", ImageFileType::ZIM, false); - if (!fontTexture) { - WARN_LOG(Log::System, "Failed to load font_atlas.zim or asciifont_atlas.zim"); - } - } - return { - GetFontAtlas(), - fontTexture, - }; - } - default: - return {}; - }; -} - bool NativeInitGraphics(GraphicsContext *graphicsContext) { INFO_LOG(Log::System, "NativeInitGraphics"); diff --git a/UI/Theme.cpp b/UI/Theme.cpp index 446bc777c8..98e476cd2f 100644 --- a/UI/Theme.cpp +++ b/UI/Theme.cpp @@ -26,6 +26,7 @@ #include "Common/Data/Format/IniFile.h" #include "Common/File/DirListing.h" #include "Common/Log/LogManager.h" +#include "Common/Render/ManagedTexture.h" #include "Core/Config.h" @@ -171,15 +172,12 @@ static UI::Style MakeStyle(uint32_t fg, uint32_t bg) { return s; } -static void LoadAtlasMetadata(Atlas &metadata, const char *filename, bool required) { +static void LoadAtlasMetadata(Atlas &metadata, const char *filename) { size_t atlas_data_size = 0; const uint8_t *atlas_data = g_VFS.ReadFile(filename, &atlas_data_size); bool load_success = atlas_data != nullptr && metadata.Load(atlas_data, atlas_data_size); if (!load_success) { - if (required) - ERROR_LOG(Log::G3D, "Failed to load %s - graphics will be broken", filename); - else - WARN_LOG(Log::G3D, "Failed to load %s", filename); + ERROR_LOG(Log::G3D, "Failed to load %s - graphics may be broken", filename); // Stumble along with broken visuals instead of dying... } delete[] atlas_data; @@ -251,14 +249,6 @@ void UpdateTheme() { ui_theme.popupSliderColor = themeInfo.uPopupSliderColor; ui_theme.popupSliderFocusedColor = themeInfo.uPopupSliderFocusedColor; - - // Load any missing atlas metadata (the images are loaded from UIContext). - LoadAtlasMetadata(ui_atlas, "ui_atlas.meta", true); -#if PPSSPP_PLATFORM(WINDOWS) || PPSSPP_PLATFORM(ANDROID) || PPSSPP_PLATFORM(MAC) || PPSSPP_PLATFORM(IOS) - LoadAtlasMetadata(font_atlas, "asciifont_atlas.meta", ui_atlas.num_fonts == 0); -#else - LoadAtlasMetadata(font_atlas, "font_atlas.meta", ui_atlas.num_fonts == 0); -#endif } UI::Theme *GetTheme() { @@ -287,3 +277,40 @@ std::vector GetThemeInfoNames() { return names; } + +AtlasData AtlasProvider(Draw::DrawContext *draw, AtlasChoice atlas) { + switch (atlas) { + case AtlasChoice::General: + { + // Load any missing atlas metadata (the images are loaded from UIContext). + LoadAtlasMetadata(ui_atlas, "ui_atlas.meta"); + return { + &ui_atlas, + CreateTextureFromFile(draw, "ui_atlas.zim", ImageFileType::ZIM, false) + }; + } + case AtlasChoice::Font: + { + Draw::Texture *fontTexture = nullptr; +#if PPSSPP_PLATFORM(WINDOWS) || PPSSPP_PLATFORM(ANDROID) || PPSSPP_PLATFORM(MAC) || PPSSPP_PLATFORM(IOS) + // Load the smaller ascii font only, like on Android. For debug ui etc. + // NOTE: We better be sure here that the correct metadata is loaded.. + LoadAtlasMetadata(font_atlas, "asciifont_atlas.meta"); + fontTexture = CreateTextureFromFile(draw, "asciifont_atlas.zim", ImageFileType::ZIM, false); + if (!fontTexture) { + WARN_LOG(Log::System, "Failed to load font_atlas.zim or asciifont_atlas.zim"); + } +#else + // Load the full font texture. + LoadAtlasMetadata(font_atlas, "font_atlas.meta"); + fontTexture = CreateTextureFromFile(draw, "font_atlas.zim", ImageFileType::ZIM, false); +#endif + return { + &font_atlas, + fontTexture, + }; + } + default: + return {}; + }; +} diff --git a/UI/Theme.h b/UI/Theme.h index deeb59df1f..ed0dc68a55 100644 --- a/UI/Theme.h +++ b/UI/Theme.h @@ -30,3 +30,5 @@ void UpdateTheme(); Atlas *GetFontAtlas(); Atlas *GetUIAtlas(); UI::Theme *GetTheme(); + +AtlasData AtlasProvider(Draw::DrawContext *draw, AtlasChoice atlas);