From ca99c7c0aa43517b29159cd1691a51caffa62afc Mon Sep 17 00:00:00 2001 From: jake Date: Mon, 8 May 2023 18:08:48 -0700 Subject: [PATCH] make sure to call through to base implementation from callbacks --- .../simongellis/leia/webxr/LeiaTextureRenderer.kt | 8 +++----- app/src/main/java/is/xyz/mpv/MPVActivity.kt | 10 ++++++++++ app/src/main/java/is/xyz/mpv/MPVView.kt | 12 +++++++++++- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/simongellis/leia/webxr/LeiaTextureRenderer.kt b/app/src/main/java/com/simongellis/leia/webxr/LeiaTextureRenderer.kt index f16bd99b3..4cd5191e6 100644 --- a/app/src/main/java/com/simongellis/leia/webxr/LeiaTextureRenderer.kt +++ b/app/src/main/java/com/simongellis/leia/webxr/LeiaTextureRenderer.kt @@ -55,7 +55,7 @@ class LeiaTextureRenderer { } fun onDrawFrame() { - Log.i(TAG, "onDrawFrame") + //Log.i(TAG, "onDrawFrame") glViewport(0, 0, size.width, size.height) logError("glViewport") glUseProgram(program) @@ -163,12 +163,10 @@ class LeiaTextureRenderer { varying vec2 v_TexCoord; uniform samplerExternalOES u_Texture; void main() { - // DEBUG: show red pixels - gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); - /*gl_FragColor = texture2D(u_Texture, v_TexCoord); + gl_FragColor = texture2D(u_Texture, v_TexCoord); if (gl_FragColor.a < 0.1) { discard; - }*/ + } } """ diff --git a/app/src/main/java/is/xyz/mpv/MPVActivity.kt b/app/src/main/java/is/xyz/mpv/MPVActivity.kt index dee4938bb..43b31cd8c 100644 --- a/app/src/main/java/is/xyz/mpv/MPVActivity.kt +++ b/app/src/main/java/is/xyz/mpv/MPVActivity.kt @@ -49,6 +49,8 @@ class MPVActivity : AppCompatActivity(), MPVLib.EventObserver, TouchGesturesObse // LitByLeia private var mPrevDesiredBacklightModeState = false private lateinit var sdk: LeiaSDK + // needed so we can forward Pause/Resume + private lateinit var myView: MPVView // for calls to eventUi() and eventPropertyUi() @@ -250,6 +252,9 @@ class MPVActivity : AppCompatActivity(), MPVLib.EventObserver, TouchGesturesObse binding = PlayerBinding.inflate(layoutInflater) setContentView(binding.root) + // Leia + myView = findViewById(R.id.player) + // Init controls to be hidden and view fullscreen hideControls() @@ -391,6 +396,9 @@ class MPVActivity : AppCompatActivity(), MPVLib.EventObserver, TouchGesturesObse } override fun onPause() { + + myView.onPause() + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { if (isInMultiWindowMode || isInPictureInPictureMode) { Log.v(TAG, "Going into multi-window mode (PiP=$isInPictureInPictureMode)") @@ -470,6 +478,8 @@ class MPVActivity : AppCompatActivity(), MPVLib.EventObserver, TouchGesturesObse } override fun onResume() { + myView.onResume() + // If we weren't actually in the background (e.g. multi window mode), don't reinitialize stuff if (activityIsForeground) { super.onResume() diff --git a/app/src/main/java/is/xyz/mpv/MPVView.kt b/app/src/main/java/is/xyz/mpv/MPVView.kt index f83ab732c..2a1c5686e 100644 --- a/app/src/main/java/is/xyz/mpv/MPVView.kt +++ b/app/src/main/java/is/xyz/mpv/MPVView.kt @@ -397,11 +397,17 @@ internal class MPVView(context: Context, attrs: AttributeSet) : LeiaSurfaceView( // pass the change the mainSurface resize(width, height) + + super.surfaceChanged(holder, format, width, height) } override fun surfaceCreated(holder: SurfaceHolder) { Log.w(TAG, "MPVView surfaceCreated. attaching mainSurface to MPV...") - MPVLib.attachSurface(mainSurface) // WAS: holder.surface, changed to write to mainSurface instead + + //MPVLib.attachSurface(holder.surface) + // WAS: holder.surface, changed to write to mainSurface instead + MPVLib.attachSurface(mainSurface) + // This forces mpv to render subs/osd/whatever into our surface even if it would ordinarily not MPVLib.setOptionString("force-window", "yes") @@ -412,6 +418,8 @@ internal class MPVView(context: Context, attrs: AttributeSet) : LeiaSurfaceView( // We disable video output when the context disappears, enable it back MPVLib.setPropertyString("vo", "gpu") } + + super.surfaceCreated(holder) } override fun surfaceDestroyed(holder: SurfaceHolder) { @@ -420,6 +428,8 @@ internal class MPVView(context: Context, attrs: AttributeSet) : LeiaSurfaceView( MPVLib.setPropertyString("vo", "null") MPVLib.setOptionString("force-window", "no") MPVLib.detachSurface() + + super.surfaceDestroyed(holder) } companion object {