Skip to content

Commit

Permalink
功能[使用系统Vulkan驱动程序]: 强制检测设备为"AdrenoGPU"的用户在打开"使用系统Vulkan驱动"选项时进行二次确认
Browse files Browse the repository at this point in the history
  • Loading branch information
Vera-Firefly committed Oct 6, 2024
1 parent 305ba40 commit 826b338
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 0 deletions.
71 changes: 71 additions & 0 deletions app_pojavlauncher/src/main/java/com/firefly/utils/PGWTools.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.firefly.utils;

import android.opengl.EGL14;
import android.opengl.EGLConfig;
import android.opengl.EGLContext;
import android.opengl.EGLDisplay;
import android.opengl.GLES20;
import android.util.Log;

public class PGWTools {

public static boolean isAdrenoGPU() {
EGLDisplay eglDisplay = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY);
if (eglDisplay == EGL14.EGL_NO_DISPLAY) {
Log.e("CheckVendor", "Failed to get EGL display");
return false;
}

if (!EGL14.eglInitialize(eglDisplay, null, 0, null, 0)) {
Log.e("CheckVendor", "Failed to initialize EGL");
return false;
}

int[] eglAttributes = new int[]{
EGL14.EGL_RENDERABLE_TYPE, EGL14.EGL_OPENGL_ES2_BIT,
EGL14.EGL_NONE
};

EGLConfig[] configs = new EGLConfig[1];
int[] numConfigs = new int[1];
if (!EGL14.eglChooseConfig(eglDisplay, eglAttributes, 0, configs, 0, 1, numConfigs, 0) || numConfigs[0] == 0) {
EGL14.eglTerminate(eglDisplay);
Log.e("CheckVendor", "Failed to choose EGL config");
return false;
}

int[] contextAttributes = new int[]{
EGL14.EGL_CONTEXT_CLIENT_VERSION, 2, // OpenGL ES 2.0
EGL14.EGL_NONE
};

EGLContext context = EGL14.eglCreateContext(eglDisplay, configs[0], EGL14.EGL_NO_CONTEXT, contextAttributes, 0);
if (context == EGL14.EGL_NO_CONTEXT) {
EGL14.eglTerminate(eglDisplay);
Log.e("CheckVendor", "Failed to create EGL context");
return false;
}

if (!EGL14.eglMakeCurrent(eglDisplay, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, context)) {
EGL14.eglDestroyContext(eglDisplay, context);
EGL14.eglTerminate(eglDisplay);
Log.e("CheckVendor", "Failed to make EGL context current");
return false;
}

String vendor = GLES20.glGetString(GLES20.GL_VENDOR);
String renderer = GLES20.glGetString(GLES20.GL_RENDERER);
boolean isAdreno = (vendor != null && renderer != null &&
vendor.equalsIgnoreCase("Qualcomm") &&
renderer.toLowerCase().contains("adreno"));

// Cleanup
EGL14.eglMakeCurrent(eglDisplay, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_CONTEXT);
EGL14.eglDestroyContext(eglDisplay, context);
EGL14.eglTerminate(eglDisplay);

Log.d("CheckVendor", "Running on Adreno GPU: " + isAdreno);
return isAdreno;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
import android.os.Bundle;

import androidx.preference.Preference;
import androidx.preference.SwitchPreference;
import androidx.preference.Preference.OnPreferenceChangeListener;

import com.firefly.utils.PGWTools;
import com.firefly.ui.dialog.CustomDialog;

import net.kdt.pojavlaunch.R;
import net.kdt.pojavlaunch.Tools;
Expand All @@ -15,5 +20,31 @@ public void onCreatePreferences(Bundle b, String str) {
if (!Tools.checkVulkanSupport(driverPreference.getContext().getPackageManager())) {
driverPreference.setVisible(false);
}
SwitchPreference useSystemVulkan = requirePreference("zinkPreferSystemDriver", SwitchPreference.class);
useSystemVulkan.setOnPreferenceChangeListener((p, v) -> {
boolean set = (boolean) v;
boolean isAdreno = PGWTools.isAdrenoGPU();
if (set && isAdreno) {
onCheckGPUDialog(p);
} else {
return true;
}
return false;
});
}

private void onCheckGPUDialog(Preference pre) {
new CustomDialog.Builder(getContext())
.setTitle("No No No No No!")
.setMessage(getString(R.string.worning_system_vulkan_adreno))
.setConfirmListener(R.string.preference_rendererexp_alertdialog_done, customView -> {
((SwitchPreference) pre).setChecked(true);
return true;
})
.setCancelListener(R.string.alertdialog_cancel, customView -> true)
.setCancelable(false)
.build()
.show();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<string name="preference_quit_launcher">在应用正式开始运行游戏时,是否退出启动器</string>
<string name="preference_fix_q3_behavior_title">修复 Q3 行为</string>
<string name="preference_fix_q3_behavior_desc">修复 740v3 上的 Q3 行为</string>
<string name="worning_system_vulkan_adreno">我们检测到您的设备为 AdrenoGPU ,打开该选项可能会导致 Zink 渲染器无法正常使用\n你真的确定你要开启这个选项?</string>
<!-- Terminal -->
<string name="main_terminal">Terminal</string>
<string name="main_termianl_init">初始化</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<string name="preference_quit_launcher">在運行遊戲時退出啟動器</string>
<string name="preference_fix_q3_behavior_title">修復 Q3 行為</string>
<string name="preference_fix_q3_behavior_desc">修復 740v3 上的 Q3 行為</string>
<string name="worning_system_vulkan_adreno">我們檢測到您的設備為 Adreno GPU,開啟該選項可能會導致 Zink 渲染器無法正常使用。\n您真的確定要開啟這個選項嗎?</string>
<!-- Terminal -->
<string name="main_terminal">Terminal</string>
<string name="main_termianl_init">初始化</string>
Expand Down
1 change: 1 addition & 0 deletions app_pojavlauncher/src/main/res/values/pgw_strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<string name="preference_quit_launcher">Exit the launcher when the running the game</string>
<string name="preference_fix_q3_behavior_title">Fix Q3 behavior</string>
<string name="preference_fix_q3_behavior_desc">Fix Q3 behavior on 740v3</string>
<string name="worning_system_vulkan_adreno">We have detected that your device is an Adreno GPU. Turning this option on may cause the Zink renderer to not work properly.\nAre you sure you want to turn this option on?</string>
<!-- Terminal -->
<string name="main_terminal">Terminal</string>
<string name="main_termianl_init">Initialization</string>
Expand Down

0 comments on commit 826b338

Please sign in to comment.