From 366e0c795c3db029a863afd5b8c0c78d2045fed0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 9 Nov 2026 10:08:08 +0100 Subject: [PATCH] Android: Re-fix a hardware scaled surface when the view is resized With a display resolution set (iAndroidHwScale), the surface has a fixed size, and a rotation doesn't change it, so no surfaceChanged came to re-fix it there. Landscape kept rendering into the portrait-sized buffer. A layout listener on the SurfaceView now re-measures and re-fixes it, which brings a surfaceChanged with the new size. Co-Authored-By: Claude Opus 5.5 --- .../ppsspp/ppsspp/NativeSurfaceManager.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/android/src/org/ppsspp/ppsspp/NativeSurfaceManager.java b/android/src/org/ppsspp/ppsspp/NativeSurfaceManager.java index 008bc81752..789357c5b8 100644 --- a/android/src/org/ppsspp/ppsspp/NativeSurfaceManager.java +++ b/android/src/org/ppsspp/ppsspp/NativeSurfaceManager.java @@ -36,6 +36,34 @@ public class NativeSurfaceManager implements SurfaceHolder.Callback { return; surfaceView.getHolder().addCallback(this); + surfaceView.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> { + if (right - left != oldRight - oldLeft || bottom - top != oldBottom - oldTop) { + viewSizeChanged(); + } + }); + } + + // A fixed-size (hardware scaled) surface keeps its size when the view is resized by a rotation, so no + // surfaceChanged follows. Re-fix it here for the new view size, which brings one with the new size. + private void viewSizeChanged() { + if (desiredSize.x == 0 && desiredSize.y == 0) { + // Sized from layout, so surfaceChanged handles it. + return; + } + // onConfigurationChanged measured before this layout, so the size it reported is the old one. + updateDisplayMeasurements(); + Point newDesired = new Point(); + getDesiredBackbufferSize(newDesired); + if (newDesired.equals(desiredSize)) { + return; + } + Log.i(TAG, "View resized, re-fixing surface size to " + newDesired.x + " x " + newDesired.y); + desiredSize.set(newDesired.x, newDesired.y); + if (newDesired.x > 0 && newDesired.y > 0) { + surfaceView.getHolder().setFixedSize(newDesired.x, newDesired.y); + } else { + surfaceView.getHolder().setSizeFromLayout(); + } } @Override