forked from Blendman974/faceclaw
Fix an issue where animations on the phone preview stopped prematurely
This commit is contained in:
1 parent
eb7f385644
commit
4234d3e9e9
14 files changed
+160
-6
No files matched your search
+3
@@ -971,6 +971,9 @@ class GlassesSessionCore(
|
||||
/** The current composite for previews/screenshots, or null before any surface exists. */
|
||||
fun previewComposite(): SurfaceCompositor.Composite? = compositor.previewComposite()
|
||||
|
||||
/** See SurfaceCompositor.setPreviewAnimationListener; runs on the redraw scheduler's thread. */
|
||||
fun setPreviewAnimationListener(listener: (() -> Unit)?) = compositor.setPreviewAnimationListener(listener)
|
||||
|
||||
/**
|
||||
* Show or hide a compositor surface, immediately submitting the resulting
|
||||
* frame. Recompositing here (rather than waiting for the next surface
|
||||
|
||||
+18
-1
@@ -1,5 +1,6 @@
|
||||
package com.faceclaw.app
|
||||
|
||||
import kotlin.concurrent.Volatile
|
||||
import kotlin.jvm.JvmField
|
||||
import kotlin.jvm.JvmStatic
|
||||
import kotlin.jvm.JvmOverloads
|
||||
@@ -315,6 +316,17 @@ class SurfaceCompositor @JvmOverloads constructor(private val includePreviewInFr
|
||||
/** The last composite's scene; reused while its inputs are unchanged (see compositeLocked). */
|
||||
private var lastScene: ShellScene? = null
|
||||
private var previewKey: String? = null
|
||||
@Volatile private var previewAnimationListener: (() -> Unit)? = null
|
||||
|
||||
/**
|
||||
* Called after each timer redraw of an animated preview (including the one where it settles),
|
||||
* outside the lock and on the redraw scheduler's thread. The mirror pulls previews on new
|
||||
* frames only, and the animation advances between them, so without this the mirror keeps
|
||||
* whichever mid-motion frame it last pulled.
|
||||
*/
|
||||
fun setPreviewAnimationListener(listener: (() -> Unit)?) {
|
||||
previewAnimationListener = listener
|
||||
}
|
||||
|
||||
/**
|
||||
* The phone mirror's view of [scene]: without the whole-screen stereo shift, which would move
|
||||
@@ -324,7 +336,12 @@ class SurfaceCompositor @JvmOverloads constructor(private val includePreviewInFr
|
||||
if (previewKey != key) {
|
||||
animatedPreview?.player?.stop()
|
||||
animatedPreview = scene.unshifted().animatedPreview(gray, screenWidth, screenHeight,
|
||||
schedule = { delay, action -> scheduleDrawRedraw(delay) { lock.withLock(action) } })
|
||||
schedule = { delay, action ->
|
||||
scheduleDrawRedraw(delay) {
|
||||
lock.withLock(action)
|
||||
previewAnimationListener?.invoke()
|
||||
}
|
||||
})
|
||||
previewKey = key
|
||||
}
|
||||
return animatedPreview!!.pixels
|
||||
|
||||
@@ -277,4 +277,7 @@ class IosSurfaceCompositor(width: Int, height: Int) {
|
||||
fun composite(): NSData = compositor.composite().gray.data()
|
||||
|
||||
fun compositeFrame(): IosTextureFrame = IosTextureFrame(compositor.composite())
|
||||
|
||||
/** Called on the main queue after each step of an animation the preview is replaying (see SurfaceCompositor). */
|
||||
fun setPreviewAnimationListener(listener: (() -> Unit)?) = compositor.setPreviewAnimationListener(listener)
|
||||
}
|
||||
@@ -243,6 +243,9 @@ class IosGlassesSession internal constructor(
|
||||
/** The current composited screen (gray, 8bpp) or null before any surface was configured. */
|
||||
fun previewComposite(): IosTextureFrame? = core.previewComposite()?.let { IosTextureFrame(it) }
|
||||
|
||||
/** Called on the main queue after each step of an animation the preview is replaying (see SurfaceCompositor). */
|
||||
fun setPreviewAnimationListener(listener: (() -> Unit)?) = core.setPreviewAnimationListener(listener)
|
||||
|
||||
fun compositeWidth(): Int = core.previewComposite()?.width ?: 0
|
||||
|
||||
fun compositeHeight(): Int = core.previewComposite()?.height ?: 0
|
||||
|
||||
Reference in new issue
Block a user