summaryrefslogtreecommitdiffstats
path: root/src/android/app/src/main/java/org/yuzu/yuzu_emu/disk_shader_cache/DiskShaderCacheProgress.kt
blob: a18efef198e3c7f4a4056b9b0940d726f79e3b70 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// SPDX-FileCopyrightText: 2023 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

package org.yuzu.yuzu_emu.disk_shader_cache

import androidx.annotation.Keep
import org.yuzu.yuzu_emu.NativeLibrary
import org.yuzu.yuzu_emu.R
import org.yuzu.yuzu_emu.disk_shader_cache.ui.ShaderProgressDialogFragment

@Keep
object DiskShaderCacheProgress {
    val finishLock = Object()
    private lateinit var fragment: ShaderProgressDialogFragment

    private fun prepareDialog() {
        val emulationActivity = NativeLibrary.sEmulationActivity.get()!!
        emulationActivity.runOnUiThread {
            fragment = ShaderProgressDialogFragment.newInstance(
                emulationActivity.getString(R.string.loading),
                emulationActivity.getString(R.string.preparing_shaders)
            )
            fragment.show(
                emulationActivity.supportFragmentManager,
                ShaderProgressDialogFragment.TAG
            )
        }
        synchronized(finishLock) { finishLock.wait() }
    }

    @JvmStatic
    fun loadProgress(stage: Int, progress: Int, max: Int) {
        val emulationActivity = NativeLibrary.sEmulationActivity.get()
            ?: error("[DiskShaderCacheProgress] EmulationActivity not present")

        when (LoadCallbackStage.values()[stage]) {
            LoadCallbackStage.Prepare -> prepareDialog()
            LoadCallbackStage.Build -> fragment.onUpdateProgress(
                emulationActivity.getString(R.string.building_shaders),
                progress,
                max
            )
            LoadCallbackStage.Complete -> fragment.dismiss()
        }
    }

    // Equivalent to VideoCore::LoadCallbackStage
    enum class LoadCallbackStage {
        Prepare, Build, Complete
    }
}