mirror of
https://github.com/skyline-emu/skyline.git
synced 2024-12-23 16:21:52 +01:00
Add GPU Driver Configuration
preference
This preference launches `GpuDriverActivity` for managing custom gpu drivers. When the device has an incompatible GPU, the preference will be disabled and greyed out.
This commit is contained in:
parent
48cf1263bc
commit
59c60df993
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
* Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/)
|
||||
*/
|
||||
|
||||
package emu.skyline.preference
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.util.AttributeSet
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.Preference.SummaryProvider
|
||||
import androidx.preference.R
|
||||
import emu.skyline.utils.GpuDriverHelper
|
||||
import emu.skyline.utils.PreferenceSettings
|
||||
import emu.skyline.R as SkylineR
|
||||
|
||||
/**
|
||||
* This preference is used to launch [GpuDriverActivity] using a preference
|
||||
*/
|
||||
class GpuDriverPreference @JvmOverloads constructor(context : Context, attrs : AttributeSet? = null, defStyleAttr : Int = R.attr.preferenceStyle) : Preference(context, attrs, defStyleAttr) {
|
||||
private val driverCallback = (context as ComponentActivity).registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
|
||||
notifyChanged()
|
||||
}
|
||||
|
||||
init {
|
||||
val supportsCustomDriverLoading = GpuDriverHelper.supportsCustomDriverLoading()
|
||||
if (supportsCustomDriverLoading) {
|
||||
summaryProvider = SummaryProvider<GpuDriverPreference> {
|
||||
sharedPreferences?.getString(key, PreferenceSettings.SYSTEM_GPU_DRIVER)?.let {
|
||||
var driver = it
|
||||
if (it == PreferenceSettings.SYSTEM_GPU_DRIVER)
|
||||
driver = context.getString(SkylineR.string.system_driver)
|
||||
|
||||
context.getString(SkylineR.string.gpu_driver_config_desc, driver)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
isEnabled = false
|
||||
summaryProvider = SummaryProvider<GpuDriverPreference> {
|
||||
context.getString(SkylineR.string.gpu_driver_config_desc_unsupported)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This launches [GpuDriverActivity] on click to manage driver packages
|
||||
*/
|
||||
override fun onClick() = driverCallback.launch(Intent(context, GpuDriverActivity::class.java))
|
||||
}
|
@ -37,6 +37,8 @@
|
||||
<string name="perf_stats_desc_on">Performance Statistics will be shown in the top-left corner</string>
|
||||
<string name="log_level">Log Level</string>
|
||||
<string name="gpu_driver_config">GPU Driver Configuration</string>
|
||||
<string name="gpu_driver_config_desc">Active driver: %1$s</string>
|
||||
<string name="gpu_driver_config_desc_unsupported">Your GPU is not supported</string>
|
||||
<!-- Settings - System -->
|
||||
<string name="system">System</string>
|
||||
<string name="use_docked">Use Docked Mode</string>
|
||||
|
@ -40,6 +40,9 @@
|
||||
app:key="log_level"
|
||||
app:title="@string/log_level"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
<emu.skyline.preference.GpuDriverPreference
|
||||
app:key="gpu_driver"
|
||||
app:title="@string/gpu_driver_config" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory
|
||||
android:key="category_keys"
|
||||
|
Loading…
Reference in New Issue
Block a user