Skip to content

Commit

Permalink
修复[渲染器选择]: 修复打开渲染器实验性设置时ListPre未更新
Browse files Browse the repository at this point in the history
  • Loading branch information
Vera-Firefly committed Oct 29, 2024
1 parent bff078c commit 4dee7ca
Showing 1 changed file with 27 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,10 @@ public void onCreatePreferences(Bundle b, String str) {
SwitchPreference.class);
sustainedPerfSwitch.setVisible(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N);

final ListPreference rendererListPreference = requirePreference("renderer", ListPreference.class);
setListPreference(rendererListPreference, "renderer");

rendererListPreference.setOnPreferenceChangeListener((pre, obj) -> {
Tools.LOCAL_RENDERER = (String) obj;
return true;
});

Preference driverPreference = requirePreference("zinkPreferSystemDriver");
if (!Tools.checkVulkanSupport(driverPreference.getContext().getPackageManager())) {
driverPreference.setVisible(false);
}
SwitchPreference useSystemVulkan = requirePreference("zinkPreferSystemDriver", SwitchPreference.class);
if (!Tools.checkVulkanSupport(useSystemVulkan.getContext().getPackageManager())) {
useSystemVulkan.setVisible(false);
}
useSystemVulkan.setOnPreferenceChangeListener((p, v) -> {
boolean set = (boolean) v;
boolean isAdreno = PGWTools.isAdrenoGPU();
Expand All @@ -110,14 +101,21 @@ public void onCreatePreferences(Bundle b, String str) {
return true;
});

final ListPreference rendererListPref = requirePreference("renderer", ListPreference.class);
final ChooseMesaListPref CMesaLibP = requirePreference("CMesaLibrary", ChooseMesaListPref.class);
final ListPreference CDriverModelP = requirePreference("CDriverModels", ListPreference.class);
final ListPreference CMesaLDOP = requirePreference("ChooseMldo", ListPreference.class);

setListPreference(rendererListPref, "renderer");
setListPreference(CMesaLibP, "CMesaLibrary");
setListPreference(CDriverModelP, "CDriverModels");
setListPreference(CMesaLDOP, "ChooseMldo");

rendererListPref.setOnPreferenceChangeListener((pre, obj) -> {
Tools.LOCAL_RENDERER = (String) obj;
return true;
});

CMesaLibP.setOnPreferenceChangeListener((pre, obj) -> {
Tools.MESA_LIBS = (String) obj;
setListPreference(CDriverModelP, "CDriverModels");
Expand All @@ -137,12 +135,15 @@ public void onCreatePreferences(Bundle b, String str) {

SwitchPreference expRendererPref = requirePreference("ExperimentalSetup", SwitchPreference.class);
expRendererPref.setOnPreferenceChangeListener((p, v) -> {
onChangeRenderer();
boolean isExpRenderer = (boolean) v;
if (isExpRenderer) {
onExpRendererDialog(p);
} else {
setListPreference(rendererListPref, "renderer");
onChangeRenderer(rendererListPref);
return true;
}
return true;
return false;
});

// Custom GL/GLSL
Expand Down Expand Up @@ -294,16 +295,17 @@ private void onCheckGPUDialog(Preference pre) {
.show();
}

private void onExpRendererDialog(Preference pre) {
private void onExpRendererDialog(Preference pre, ListPreference rendererListPref) {
new CustomDialog.Builder(getContext())
.setTitle(getString(R.string.preference_rendererexp_alertdialog_warning))
.setMessage(getString(R.string.preference_rendererexp_alertdialog_message))
.setConfirmListener(R.string.preference_rendererexp_alertdialog_done, customView -> true)
.setCancelListener(R.string.preference_rendererexp_alertdialog_cancel, customView -> {
onChangeRenderer();
((SwitchPreference) pre).setChecked(false);
.setConfirmListener(R.string.preference_rendererexp_alertdialog_done, customView -> {
setListPreference(rendererListPref, "renderer");
onChangeRenderer(rendererListPref);
((SwitchPreference) pre).setChecked(true);
return true;
})
.setCancelListener(R.string.preference_rendererexp_alertdialog_cancel, customView -> true)
.setCancelable(false)
.setDraggable(true)
.build()
Expand Down Expand Up @@ -372,16 +374,20 @@ private boolean isValidVersion(String version, String minVersion, String maxVers
}
}

private void onChangeRenderer() {
private void onChangeRenderer(ListPreference rendererListPref) {
String rendererValue = LauncherPreferences.DEFAULT_PREF.getString("renderer", null);
if ("mesa_3d".equals(rendererValue)) {
LauncherPreferences.DEFAULT_PREF.edit().putString("renderer", expRenderer).apply();
if (expRenderer != null) {
rendererListPref.setValue(expRenderer);
} else rendererListPref.setValueIndex(0);
} else if ("vulkan_zink".equals(rendererValue)
|| "virglrenderer".equals(rendererValue)
|| "freedreno".equals(rendererValue)
|| "panfrost".equals(rendererValue)) {
expRenderer = LauncherPreferences.DEFAULT_PREF.getString("renderer", null);
expRenderer = rendererValue;
LauncherPreferences.DEFAULT_PREF.edit().putString("renderer", "mesa_3d").apply();
rendererListPref.setValue("mesa_3d");
}
}

Expand Down

0 comments on commit 4dee7ca

Please sign in to comment.