diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index 6ff03dd5e..a8fbe806e 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -985,8 +985,6 @@ UI::EventReturn MainScreen::OnLoadFile(UI::EventParams &e) { return UI::EVENT_DONE; } -extern void DrawBackground(UIContext &dc, float alpha); - void MainScreen::DrawBackground(UIContext &dc) { UIScreenWithBackground::DrawBackground(dc); if (highlightedGamePath_.empty() && prevHighlightedGamePath_.empty()) { diff --git a/UI/MiscScreens.cpp b/UI/MiscScreens.cpp index 4d49057e7..d7b31db86 100644 --- a/UI/MiscScreens.cpp +++ b/UI/MiscScreens.cpp @@ -69,7 +69,23 @@ static const uint32_t colors[4] = { 0xC0FFFFFF, }; -void DrawBackground(UIContext &dc, float alpha = 1.0f) { +static ManagedTexture *bgTexture = nullptr; + +void UIBackgroundInit(UIContext &dc) { + const std::string bgPng = GetSysDirectory(DIRECTORY_SYSTEM) + "background.png"; + const std::string bgJpg = GetSysDirectory(DIRECTORY_SYSTEM) + "background.jpg"; + if (File::Exists(bgPng) || File::Exists(bgJpg)) { + const std::string &bgFile = File::Exists(bgPng) ? bgPng : bgJpg; + bgTexture = CreateTextureFromFile(dc.GetDrawContext(), bgFile.c_str(), DETECT, true); + } +} + +void UIBackgroundShutdown() { + delete bgTexture; + bgTexture = nullptr; +} + +void DrawBackground(UIContext &dc, float alpha) { static float xbase[100] = {0}; static float ybase[100] = {0}; float xres = dc.GetBounds().w; @@ -87,10 +103,20 @@ void DrawBackground(UIContext &dc, float alpha = 1.0f) { last_yres = yres; } - int img = I_BG; - uint32_t bgColor = whiteAlpha(alpha); - ui_draw2d.DrawImageStretch(img, dc.GetBounds(), bgColor); + + if (bgTexture != nullptr) { + dc.Flush(); + dc.GetDrawContext()->BindTexture(0, bgTexture->GetTexture()); + dc.Draw()->DrawTexRect(dc.GetBounds(), 0, 0, 1, 1, bgColor); + + dc.Flush(); + dc.RebindTexture(); + } else { + ImageID img = I_BG; + ui_draw2d.DrawImageStretch(img, dc.GetBounds(), bgColor); + } + float t = time_now(); for (int i = 0; i < 100; i++) { float x = xbase[i] + dc.GetBounds().x; @@ -216,7 +242,7 @@ UI::EventReturn UIDialogScreenWithBackground::OnLanguageChange(UI::EventParams & } void UIDialogScreenWithBackground::DrawBackground(UIContext &dc) { - ::DrawBackground(dc); + ::DrawBackground(dc, 1.0f); dc.Flush(); } diff --git a/UI/MiscScreens.h b/UI/MiscScreens.h index f1508cdf0..d189121d7 100644 --- a/UI/MiscScreens.h +++ b/UI/MiscScreens.h @@ -28,6 +28,8 @@ struct ShaderInfo; extern std::string boot_filename; +void UIBackgroundInit(UIContext &dc); +void UIBackgroundShutdown(); inline void NoOpVoidBool(bool) {} @@ -147,7 +149,3 @@ private: int frames_; }; - - -// Utility functions that create various popup screens -ListPopupScreen *CreateLanguageScreen(); diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index 3f8059380..be721b9e3 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -633,6 +633,8 @@ void NativeInitGraphics(GraphicsContext *graphicsContext) { screenManager->setUIContext(uiContext); screenManager->setDrawContext(g_draw); + UIBackgroundInit(*uiContext); + #ifdef _WIN32 winAudioBackend = CreateAudioBackend((AudioBackendType)g_Config.iAudioBackend); #if PPSSPP_PLATFORM(UWP) @@ -651,17 +653,19 @@ void NativeShutdownGraphics() { #ifdef _WIN32 delete winAudioBackend; - winAudioBackend = NULL; + winAudioBackend = nullptr; #endif delete g_gameInfoCache; g_gameInfoCache = nullptr; + UIBackgroundShutdown(); + delete uiTexture; uiTexture = nullptr; delete uiContext; - uiContext = NULL; + uiContext = nullptr; ui_draw2d.Shutdown(); ui_draw2d_front.Shutdown(); diff --git a/ext/native/gfx_es2/draw_buffer.h b/ext/native/gfx_es2/draw_buffer.h index 9232bf15e..ba0efc548 100644 --- a/ext/native/gfx_es2/draw_buffer.h +++ b/ext/native/gfx_es2/draw_buffer.h @@ -117,7 +117,7 @@ public: void MeasureImage(ImageID atlas_image, float *w, float *h); void DrawImage(ImageID atlas_image, float x, float y, float scale, Color color = COLOR(0xFFFFFF), int align = ALIGN_TOPLEFT); void DrawImageStretch(ImageID atlas_image, float x1, float y1, float x2, float y2, Color color = COLOR(0xFFFFFF)); - void DrawImageStretch(int atlas_image, const Bounds &bounds, Color color = COLOR(0xFFFFFF)) { + void DrawImageStretch(ImageID atlas_image, const Bounds &bounds, Color color = COLOR(0xFFFFFF)) { DrawImageStretch(atlas_image, bounds.x, bounds.y, bounds.x2(), bounds.y2(), color); } void DrawImageRotated(ImageID atlas_image, float x, float y, float scale, float angle, Color color = COLOR(0xFFFFFF), bool mirror_h = false); // Always centers