Skip to content

Commit

Permalink
trying to get view binding
Browse files Browse the repository at this point in the history
  • Loading branch information
jakedowns committed Jan 19, 2024
1 parent 2ddd0d8 commit bda7f07
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 67 deletions.
10 changes: 0 additions & 10 deletions src/android/app/src/main/java/org/citra/citra_emu/JakesLeiaView.kt

This file was deleted.

47 changes: 0 additions & 47 deletions src/android/app/src/main/java/org/citra/citra_emu/LeiaHelper2D.kt

This file was deleted.

31 changes: 31 additions & 0 deletions src/android/app/src/main/java/org/citra/citra_emu/LeiaHelper3D.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,40 @@
package org.citra.citra_emu

import android.app.Application
import android.content.Context
import android.graphics.SurfaceTexture
import android.util.AttributeSet
import android.util.Log
import android.view.Surface
import android.widget.Toast
import com.leia.core.LogLevel
import com.leia.sdk.LeiaSDK
import com.leia.sdk.views.InputViewsAsset
import com.leia.sdk.views.InterlacedSurfaceView

class LeiaView : InterlacedSurfaceView {
constructor(context: Context?) : super(context)
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)

fun setSurfaceListener(surfaceListener: LeiaHelper3D.SurfaceListener) {
val surfaceAsset = InputViewsAsset.createEmptySurfaceForVideo {
surfaceTexture: SurfaceTexture? -> surfaceListener.onSurfaceChanged(Surface(surfaceTexture))
}
setViewAsset(surfaceAsset)
}
}
class LeiaHelper3D {


fun interface SurfaceListener {
fun onSurfaceChanged(surface: Surface?) {

}
}




companion object {
fun init(application: Application) {
try {
Expand All @@ -34,5 +61,9 @@ class LeiaHelper3D {
it.enableBacklight(enable3dMode && hasFocus)
}
}

fun SurfaceListener(function: (Surface) -> Unit): LeiaHelper3D.SurfaceListener {
return LeiaHelper3D.SurfaceListener { surface: Surface? -> function(surface!!) }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ import android.annotation.SuppressLint
import android.content.Context
import android.content.DialogInterface
import android.content.SharedPreferences
import android.graphics.SurfaceTexture
import android.net.Uri
import android.opengl.GLES20
import android.opengl.Matrix
import android.os.Bundle
import android.os.Handler
import android.os.Looper
Expand Down Expand Up @@ -44,7 +41,6 @@ import androidx.navigation.fragment.navArgs
import androidx.preference.PreferenceManager
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.slider.Slider
import com.leia.sdk.views.InputViewsAsset
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import org.citra.citra_emu.CitraApplication
Expand All @@ -64,15 +60,16 @@ import org.citra.citra_emu.features.settings.utils.SettingsFile
import org.citra.citra_emu.model.Game
import org.citra.citra_emu.utils.DirectoryInitialization
import org.citra.citra_emu.utils.DirectoryInitialization.DirectoryInitializationState
import org.citra.citra_emu.utils.EmulationLifecycleUtil
import org.citra.citra_emu.utils.EmulationMenuSettings
import org.citra.citra_emu.utils.FileUtil
import org.citra.citra_emu.utils.GameHelper
import org.citra.citra_emu.utils.GameIconUtils
import org.citra.citra_emu.utils.EmulationLifecycleUtil
import org.citra.citra_emu.utils.Log
import org.citra.citra_emu.utils.ViewUtils
import org.citra.citra_emu.viewmodel.EmulationViewModel


class EmulationFragment : Fragment(), SurfaceHolder.Callback, Choreographer.FrameCallback {
private val preferences: SharedPreferences
get() = PreferenceManager.getDefaultSharedPreferences(CitraApplication.appContext)
Expand Down Expand Up @@ -169,9 +166,14 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback, Choreographer.Fram
return
}

LeiaHelper3D.update3dMode(binding.surfaceEmulation, true, true)

binding.surfaceEmulation.holder.addCallback(this)

val sL = { surface: Surface ->
emulationState.newSurface(surface)
}
binding.surfaceEmulation.setSurfaceListener(sL)


binding.doneControlConfig.setOnClickListener {
binding.doneControlConfig.visibility = View.GONE
binding.surfaceInputOverlay.setIsInEditMode(false)
Expand Down Expand Up @@ -348,6 +350,8 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback, Choreographer.Fram
return
}

LeiaHelper3D.update3dMode(binding.surfaceEmulation, false, false)

if (binding.drawerLayout.isOpen) {
binding.drawerLayout.close()
} else {
Expand Down Expand Up @@ -867,8 +871,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback, Choreographer.Fram

override fun surfaceCreated(holder: SurfaceHolder) {
Log.debug("[EmulationFragment] Surface Created")
// We purposely don't do anything here.
// All work is done in surfaceChanged, which we are guaranteed to get even for surface creation.
emulationState.newSurface(holder.surface)
}

override fun surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) {
Expand Down
2 changes: 1 addition & 1 deletion src/android/app/src/main/res/layout/fragment_emulation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
android:layout_height="match_parent">

<!-- This is what everything is rendered to during emulation -->
<com.leia.sdk.views.InterlacedSurfaceView
<org.citra.citra_emu.LeiaView
android:id="@+id/surface_emulation"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down

0 comments on commit bda7f07

Please sign in to comment.