Rebind the compositor when the Surface changes size

A foldable opening or closing resizes the Surface rather than recreating it.
The compositor's swapchain, built for the old size, kept presenting, and the
system scaled those buffers onto the new window — on a Fold a 16:9 picture
came back stretched to the square panel, the same width and 2.09x the height.
Rebinding the window on a size change rebuilds the swapchain at the new size,
and the fit mode letterboxes as it should.
This commit is contained in:
The412Banner committed 2026-09-19 16:35:53 -04:00
1 parent 033db93058
commit de1bfb6b94
2 files changed
+28 -1

No files matched your search

@@ -226,9 +226,22 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
applyFrameGen()
}
override fun surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) {}
private var surfaceW = 0
private var surfaceH = 0
override fun surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) {
val resized = surfaceW != 0 && (width != surfaceW || height != surfaceH)
surfaceW = width
surfaceH = height
if (resized) {
Log.i(TAG, "surface resized to ${width}x$height — rebinding the compositor")
CompositorHost.resize(holder.surface)
}
}
override fun surfaceDestroyed(holder: SurfaceHolder) {
surfaceW = 0
surfaceH = 0
CompositorHost.detach()
}