Serialize screen size and window size separately in libretro save states

This commit is contained in:
刘皓 2025-08-10 10:43:26 -04:00
parent 0fb327c93e
commit ae0e1bd6d5
No known key found for this signature in database
GPG key ID: 7901753DB465B711
3 changed files with 31 additions and 15 deletions

View file

@ -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);
}
}
{

View file

@ -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) {

View file

@ -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);