mirror of
https://github.com/twinksoftware/Gearslip.git
synced 2026-11-11 08:12:26 +01:00
map screen wont rebuild on each app/page switch
This commit is contained in:
1 parent
42785ce6be
commit
ebd0ba4add
2 files changed
+13
-33
No files matched your search
@@ -83,16 +83,13 @@ fun CarHome() {
|
|||||||
val navigator = LocalCarNavigator.current
|
val navigator = LocalCarNavigator.current
|
||||||
val panel = navigator.sidePanel
|
val panel = navigator.sidePanel
|
||||||
|
|
||||||
// Leaving the map for another screen: hand the nav app a fresh surface while it's covered, so
|
// Coming back to the map from another screen: the map stayed loaded underneath, so its surface
|
||||||
// it has redrawn by the time the map comes back - a new surface shows black until the app's
|
// is only replaced if it died meanwhile. The first composition is skipped, since the surface
|
||||||
// next frame. Coming back only replaces one that died meanwhile. Nothing happens before Home
|
// is only just being lent.
|
||||||
// has first been shown, since the surface is only just being lent.
|
|
||||||
val onHome = navigator.current == CarScreen.Home
|
val onHome = navigator.current == CarScreen.Home
|
||||||
val seenHome = remember { booleanArrayOf(false) }
|
val seenHome = remember { booleanArrayOf(false) }
|
||||||
LaunchedEffect(onHome) {
|
LaunchedEffect(onHome) {
|
||||||
if (seenHome[0]) {
|
if (onHome && seenHome[0]) CarServices.nav.replaceDeadSurface()
|
||||||
if (onHome) CarServices.nav.replaceDeadSurface() else CarServices.nav.renewSurface()
|
|
||||||
}
|
|
||||||
if (onHome) seenHome[0] = true
|
if (onHome) seenHome[0] = true
|
||||||
}
|
}
|
||||||
val splitScreen = phase == CarMedia.Phase.READY && now.isActive && panel != SidePanel.NONE
|
val splitScreen = phase == CarMedia.Phase.READY && now.isActive && panel != SidePanel.NONE
|
||||||
|
|||||||
@@ -458,44 +458,27 @@ class CarAppConnection(private val context: Context) {
|
|||||||
/** Bumped to throw the lent surface away, so the stage builds a fresh one. */
|
/** Bumped to throw the lent surface away, so the stage builds a fresh one. */
|
||||||
val surfaceEpoch: StateFlow<Int> = _surfaceEpoch.asStateFlow()
|
val surfaceEpoch: StateFlow<Int> = _surfaceEpoch.asStateFlow()
|
||||||
|
|
||||||
/**
|
|
||||||
* Lends the app a fresh surface: called as the map goes out of view, so the app has redrawn
|
|
||||||
* on the new one by the time it comes back. An app that draws through its own VirtualDisplay
|
|
||||||
* (Organic Maps does) can be left pointing at a surface that has since died, and draws black
|
|
||||||
* until it's told about a live one.
|
|
||||||
*
|
|
||||||
* Always a new surface, never the same one lent again: such an app (Flitsmeister does) builds
|
|
||||||
* its new display on the re-lent surface before releasing the old, and the old one's
|
|
||||||
* disconnect then takes the shared BufferQueue's connection with it - the map freezes on its
|
|
||||||
* last frame for good. The stage's key on [surfaceEpoch] swaps in a new SurfaceView, which
|
|
||||||
* lends itself as it comes up.
|
|
||||||
*/
|
|
||||||
fun renewSurface() {
|
|
||||||
main.post {
|
|
||||||
val current = lent ?: return@post
|
|
||||||
GearslipLog.i("host: building a fresh surface as the map goes out of view")
|
|
||||||
replaceSurface(current)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called as the map comes back into view: replaces the surface only if it died while the map
|
* Called as the map comes back into view: replaces the surface only if it died while the map
|
||||||
* was covered, since a new one shows black until the app's next frame.
|
* was covered. A live one is left alone, because every hand-over costs the app its map - some
|
||||||
|
* (MapQuest) rebuild theirs from a world view and fly back to the car's position.
|
||||||
|
*
|
||||||
|
* Always a new surface, never the dead one lent again: an app that draws through its own
|
||||||
|
* VirtualDisplay (Flitsmeister does) builds its new display on a re-lent surface before
|
||||||
|
* releasing the old, and the old one's disconnect then takes the shared BufferQueue's
|
||||||
|
* connection with it - the map freezes on its last frame for good. The stage's key on
|
||||||
|
* [surfaceEpoch] swaps in a new SurfaceView, which lends itself as it comes up.
|
||||||
*/
|
*/
|
||||||
fun replaceDeadSurface() {
|
fun replaceDeadSurface() {
|
||||||
main.post {
|
main.post {
|
||||||
val current = lent ?: return@post
|
val current = lent ?: return@post
|
||||||
if (current.surface.isValid) return@post
|
if (current.surface.isValid) return@post
|
||||||
GearslipLog.w("host: the lent surface died; building a new one")
|
GearslipLog.w("host: the lent surface died; building a new one")
|
||||||
replaceSurface(current)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun replaceSurface(current: Lent) {
|
|
||||||
lent = null
|
lent = null
|
||||||
sendSurfaceDestroyed(current)
|
sendSurfaceDestroyed(current)
|
||||||
_surfaceEpoch.value = _surfaceEpoch.value + 1
|
_surfaceEpoch.value = _surfaceEpoch.value + 1
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun sendSurfaceAvailable() {
|
private fun sendSurfaceAvailable() {
|
||||||
val callback = surfaceCallback ?: return
|
val callback = surfaceCallback ?: return
|
||||||
|
|||||||
Reference in new issue
Block a user