From ae0e1bd6d56abd841c6f5fe2598e206a648fa488 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=9A=93?= Date: Sun, 10 Aug 2025 10:43:26 -0400 Subject: [PATCH] Serialize screen size and window size separately in libretro save states --- src/core.cpp | 29 +++++++++++++++++++++-------- src/display/graphics.cpp | 15 +++++++++------ src/display/graphics.h | 2 +- 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/src/core.cpp b/src/core.cpp index d8b8d03a..42869643 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -1830,6 +1830,8 @@ extern "C" RETRO_API bool retro_serialize(void *data, size_t len) { // Write the graphics state if (!sandbox_serialize((int32_t)shState->graphics().width(), data, max_size)) return false; if (!sandbox_serialize((int32_t)shState->graphics().height(), data, max_size)) return false; + if (!sandbox_serialize((uint32_t)av_info.geometry.base_width, data, max_size)) return false; + if (!sandbox_serialize((uint32_t)av_info.geometry.base_height, data, max_size)) return false; if (!sandbox_serialize((int32_t)shState->graphics().getFrameRate(), data, max_size)) return false; if (!sandbox_serialize((int32_t)shState->graphics().getFrameCount(), data, max_size)) return false; if (!sandbox_serialize((int32_t)shState->graphics().getBrightness(), data, max_size)) return false; @@ -2168,14 +2170,25 @@ extern "C" RETRO_API bool retro_unserialize(const void *data, size_t len) { // Read the graphics state { - int32_t width; - int32_t height; - if (!sandbox_deserialize(width, data, max_size)) DESER_FAIL; - if (!sandbox_deserialize(height, data, max_size)) DESER_FAIL; - width = std::max((int32_t)1, width); - height = std::max((int32_t)1, height); - if (width != shState->graphics().width() || height != shState->graphics().height()) { - shState->graphics().resizeScreen(width, height); + int32_t screen_width; + int32_t screen_height; + if (!sandbox_deserialize(screen_width, data, max_size)) DESER_FAIL; + if (!sandbox_deserialize(screen_height, data, max_size)) DESER_FAIL; + screen_width = std::max((int32_t)1, screen_width); + screen_height = std::max((int32_t)1, screen_height); + if (screen_width != shState->graphics().width() || screen_height != shState->graphics().height()) { + shState->graphics().resizeScreen(screen_width, screen_height, false); + } + } + { + int32_t window_width; + int32_t window_height; + if (!sandbox_deserialize(window_width, data, max_size)) DESER_FAIL; + if (!sandbox_deserialize(window_height, data, max_size)) DESER_FAIL; + window_width = std::max((int32_t)1, window_width); + window_height = std::max((int32_t)1, window_height); + if (window_width != av_info.geometry.base_width || window_height != av_info.geometry.base_height) { + shState->graphics().resizeWindow(window_width, window_height, false); } } { diff --git a/src/display/graphics.cpp b/src/display/graphics.cpp index 5bac0e3f..f53ae6f4 100644 --- a/src/display/graphics.cpp +++ b/src/display/graphics.cpp @@ -1811,7 +1811,7 @@ int Graphics::displayHeight() const { #endif // MKXPZ_RETRO } -void Graphics::resizeScreen(int width, int height) { +void Graphics::resizeScreen(int width, int height, bool resizeWindow) { #ifndef MKXPZ_RETRO p->threadData->rqWindowAdjust.wait(); #endif // MKXPZ_RETRO @@ -1845,14 +1845,17 @@ void Graphics::resizeScreen(int width, int height) { glState.scissorBox.set(IntRect(0, 0, p->scRes.x, p->scRes.y)); + if (resizeWindow) + { #ifdef MKXPZ_RETRO - p->winSize = Vec2i(width, height); - p->recalculateScreenSize(p->threadData->config.fixedAspectRatio); - p->updateScreenResoRatio(p->threadData); - mkxp_retro::request_resize(width, height); + p->winSize = Vec2i(width, height); + p->recalculateScreenSize(p->threadData->config.fixedAspectRatio); + p->updateScreenResoRatio(p->threadData); + mkxp_retro::request_resize(width, height); #else - shState->eThread().requestWindowResize(width, height); + shState->eThread().requestWindowResize(width, height); #endif // MKXPZ_RETRO + } } void Graphics::resizeWindow(int width, int height, bool center) { diff --git a/src/display/graphics.h b/src/display/graphics.h index 9504b4ea..da3922c8 100644 --- a/src/display/graphics.h +++ b/src/display/graphics.h @@ -74,7 +74,7 @@ public: int displayContentHeight() const; int displayWidth() const; int displayHeight() const; - void resizeScreen(int width, int height); + void resizeScreen(int width, int height, bool resizeWindow = true); void resizeWindow(int width, int height, bool center=false); void drawMovieFrame(const THEORAPLAY_VideoFrame* video, Bitmap *videoBitmap); bool updateMovieInput(Movie *movie);