Skip to content

Commit

Permalink
重构[桥接]: 重构原来的备用桥接方案,新增新的选择方案
Browse files Browse the repository at this point in the history
  • Loading branch information
Vera-Firefly committed Nov 13, 2024
1 parent 332b0cf commit 8b70447
Show file tree
Hide file tree
Showing 46 changed files with 464 additions and 281 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -380,21 +380,24 @@ public static boolean isAndroid8OrHigher() {
}

private void runCraft(String versionId, JMinecraftVersionList.Version version) throws Throwable {
if (Tools.LOCAL_RENDERER == null) {
if (Tools.LOCAL_RENDERER == null)
Tools.LOCAL_RENDERER = LauncherPreferences.PREF_RENDERER;
}
if (Tools.MESA_LIBS == null) {

if (Tools.MESA_LIBS == null)
Tools.MESA_LIBS = LauncherPreferences.PREF_MESA_LIB;
}
if (Tools.DRIVER_MODEL == null) {

if (Tools.DRIVER_MODEL == null)
Tools.DRIVER_MODEL = LauncherPreferences.PREF_DRIVER_MODEL;
}
if (Tools.LOADER_OVERRIDE == null) {

if (Tools.LOADER_OVERRIDE == null)
Tools.LOADER_OVERRIDE = LauncherPreferences.PREF_LOCAL_LOADER_OVERRIDE;
}
if (Tools.TURNIP_LIBS == null) {

if (Tools.TURNIP_LIBS == null)
Tools.TURNIP_LIBS = LauncherPreferences.PREF_TURNIP_LIBS;
}

if (Tools.CONFIG_BRIDGE == null)
Tools.CONFIG_BRIDGE = LauncherPreferences.PREF_CONFIG_BRIDGE;

if (!Tools.checkRendererCompatible(this, Tools.LOCAL_RENDERER)) {
Tools.RenderersList renderersList = Tools.getCompatibleRenderers(this);
String firstCompatibleRenderer = renderersList.rendererIds.get(0);
Expand Down
36 changes: 36 additions & 0 deletions app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public final class Tools {
public static File FILE_PROFILE_PATH;
public static String MULTIRT_HOME;
public static String LOCAL_RENDERER = null;
public static String CONFIG_BRIDGE;
public static int DEVICE_ARCHITECTURE;
public static final String LAUNCHERPROFILES_RTPREFIX = "pojav://";

Expand All @@ -140,6 +141,7 @@ public final class Tools {
private static CMesaLDOList sCompatibleCMesaLDO;
private static CTurnipDriverList sCompatibleCTurnipDriver;
private static RenderersList sCompatibleRenderers;
private static ConfigBridgeList sCompatibleConfigBridge;

private static File getPojavStorageRoot(Context ctx) {
if (SDK_INT >= 29) {
Expand Down Expand Up @@ -1275,6 +1277,40 @@ public static void releaseRenderersCache() {
System.gc();
}

public static class ConfigBridgeList implements IListAndArry {
public final List<String> configIds;
public final String[] configNames;

public ConfigBridgeList(List<String> configIds, String[] configNames) {
this.configIds = configIds;
this.configNames = configNames;
}

@Override
public List<String> getList() {
return configIds;
}

@Override
public String[] getArray() {
return configNames;
}
}

public static ConfigBridgeList getCompatibleConfigBridge(Context context) {
Resources resources = context.getResources();
String[] defaultIds = resources.getStringArray(R.array.config_bridge_values);
String[] defaultNames = resources.getStringArray(R.array.config_bridge_names);
List<String> Ids = new ArrayList<>(defaultIds.length);
List<String> Names = new ArrayList<>(defaultNames.length);
for (int i = 0; i < defaultIds.length; i++) {
Ids.add(defaultIds[i]);
Names.add(defaultNames[i]);
}
sCompatibleConfigBridge = new ConfigBridgeList(Ids, Names.toArray(new String[0]));
return sCompatibleConfigBridge;
}

public static class CMesaLibList implements IListAndArry {
public final List<String> CMesaLibIds;
public final String[] CMesaLibs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class LauncherPreferences {
public static String PREF_MESA_LIB = "default";
public static String PREF_TURNIP_LIBS = "default";
public static String PREF_DRIVER_MODEL = "driver_zink";
public static String PREF_CONFIG_BRIDGE = "default";
public static String PREF_LOCAL_LOADER_OVERRIDE = "kgsl";

public static boolean PREF_VERTYPE_RELEASE = true;
Expand Down Expand Up @@ -74,7 +75,6 @@ public class LauncherPreferences {

public static boolean PREF_EXP_SETUP = false;

public static boolean PREF_SPARE_BRIDGE = false;
public static boolean PREF_SPARE_FRAME_BUFFER = false;
public static boolean PREF_EXP_ENABLE_SYSTEM = true;
public static boolean PREF_EXP_ENABLE_SPECIFIC = false;
Expand Down Expand Up @@ -140,7 +140,7 @@ public static void loadPreferences(Context ctx) {
PREF_SKIP_NOTIFICATION_PERMISSION_CHECK = DEFAULT_PREF.getBoolean(PREF_KEY_SKIP_NOTIFICATION_CHECK, false);
PREF_VSYNC_IN_ZINK = DEFAULT_PREF.getBoolean("vsync_in_zink", true);

PREF_SPARE_BRIDGE = DEFAULT_PREF.getBoolean("spareBridge", false);
PREF_CONFIG_BRIDGE = DEFAULT_PREF.getString("configBridge", "default");
PREF_SPARE_FRAME_BUFFER = DEFAULT_PREF.getBoolean("SpareFrameBuffer", false);
PREF_EXP_ENABLE_SYSTEM = DEFAULT_PREF.getBoolean("ebSystem", true);
PREF_EXP_ENABLE_SPECIFIC = DEFAULT_PREF.getBoolean("ebSpecific", false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,14 @@ public void onCreatePreferences(Bundle b, String str) {
});

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

setListPreference(rendererListPref, "renderer");
setListPreference(configBridgePref, "configBridge");
setListPreference(CMesaLibP, "CMesaLibrary");
setListPreference(CTurnipP, "chooseTurnipDriver");
setListPreference(CDriverModelP, "CDriverModels");
Expand All @@ -123,6 +125,11 @@ public void onCreatePreferences(Bundle b, String str) {
return true;
});

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

CMesaLibP.setOnPreferenceChangeListener((pre, obj) -> {
Tools.MESA_LIBS = (String) obj;
setListPreference(CDriverModelP, "CDriverModels");
Expand Down Expand Up @@ -273,16 +280,29 @@ private void setListPreference(ListPreference listPreference, String preferenceK
listPreference.setValue(value);
}
Tools.MESA_LIBS = value;
} else if (preferenceKey.equals("CDriverModels")) {
}

if (preferenceKey.equals("renderer")) {
array = Tools.getCompatibleRenderers(getContext());
Tools.LOCAL_RENDERER = value;
}

if (preferenceKey.equals("configBridge")) {
array = Tools.getCompatibleConfigBridge(getContext());
Tools.CONFIG_BRIDGE = value;
}

if (preferenceKey.equals("CDriverModels")) {
array = Tools.getCompatibleCDriverModel(getContext());
Tools.DRIVER_MODEL = value;
} else if (preferenceKey.equals("ChooseMldo")) {
}

if (preferenceKey.equals("ChooseMldo")) {
array = Tools.getCompatibleCMesaLDO(getContext());
Tools.LOADER_OVERRIDE = value;
} else if (preferenceKey.equals("renderer")) {
array = Tools.getCompatibleRenderers(getContext());
Tools.LOCAL_RENDERER = value;
} else if (preferenceKey.equals("chooseTurnipDriver")) {
}

if (preferenceKey.equals("chooseTurnipDriver")) {
array = Tools.getCompatibleCTurnipDriver(getContext());
Tools.TURNIP_LIBS = value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static net.kdt.pojavlaunch.Architecture.ARCH_X86;
import static net.kdt.pojavlaunch.Architecture.is64BitsDevice;
import static net.kdt.pojavlaunch.Tools.CONFIG_BRIDGE;
import static net.kdt.pojavlaunch.Tools.DRIVER_MODEL;
import static net.kdt.pojavlaunch.Tools.LOADER_OVERRIDE;
import static net.kdt.pojavlaunch.Tools.LOCAL_RENDERER;
Expand Down Expand Up @@ -211,6 +212,8 @@ private static void setJavaEnv(String jreHome) throws Throwable {
envMap.put("AWTSTUB_WIDTH", Integer.toString(CallbackBridge.windowWidth > 0 ? CallbackBridge.windowWidth : CallbackBridge.physicalWidth));
envMap.put("AWTSTUB_HEIGHT", Integer.toString(CallbackBridge.windowHeight > 0 ? CallbackBridge.windowHeight : CallbackBridge.physicalHeight));

if (Tools.CONFIG_BRIDGE != null)
envMap.put("POJAV_CONFIG_BRIDGE", Tools.CONFIG_BRIDGE);
if (PREF_BIG_CORE_AFFINITY)
envMap.put("POJAV_BIG_CORE_AFFINITY", "1");
if (PREF_DUMP_SHADERS)
Expand All @@ -221,8 +224,6 @@ private static void setJavaEnv(String jreHome) throws Throwable {
envMap.put("POJAV_VSYNC_IN_ZINK", "1");
if (PREF_EXP_SETUP)
envMap.put("POJAV_EXP_SETUP", "1");
if (PREF_SPARE_BRIDGE)
envMap.put("POJAV_SPARE_BRIDGE", "1");
if (PREF_SPARE_FRAME_BUFFER)
envMap.put("POJAV_SPARE_FRAME_BUFFER", "1");
if (FIX_Q3_BEHAVIOR)
Expand Down
3 changes: 2 additions & 1 deletion app_pojavlauncher/src/main/jni/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ LOCAL_SRC_FILES := \
egl_bridge.c \
ctxbridges/gl_bridge.c \
ctxbridges/osm_bridge.c \
ctxbridges/spare_osm_bridge.c \
ctxbridges/osm_bridge_xxx1.c \
ctxbridges/osm_bridge_xxx2.c \
ctxbridges/egl_loader.c \
ctxbridges/osmesa_loader.c \
ctxbridges/swap_interval_no_egl.c \
Expand Down
11 changes: 11 additions & 0 deletions app_pojavlauncher/src/main/jni/ctxbridges/bridge_tbl.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <ctxbridges/common.h>
#include <ctxbridges/gl_bridge.h>
#include <ctxbridges/osm_bridge.h>
#include <ctxbridges/osm_bridge_xxx1.h>

typedef basic_render_window_t* (*br_init_context_t)(basic_render_window_t* share);
typedef void (*br_make_current_t)(basic_render_window_t* bundle);
Expand All @@ -32,6 +33,16 @@ void set_osm_bridge_tbl() {
br_swap_interval = osm_swap_interval;
}

void osm_bridge_xxx1() {
br_init = xxx1_osm_init;
br_init_context = (br_init_context_t) xxx1_osm_init_context;
br_make_current = (br_make_current_t) xxx1_osm_make_current;
br_get_current = (br_get_current_t) xxx1_osm_get_current;
br_swap_buffers = xxx1_osm_swap_buffers;
br_setup_window = xxx1_osm_setup_window;
br_swap_interval = xxx1_osm_swap_interval;
}

void set_gl_bridge_tbl() {
br_init = gl_init;
br_init_context = (br_init_context_t) gl_init_context;
Expand Down
4 changes: 2 additions & 2 deletions app_pojavlauncher/src/main/jni/ctxbridges/gl_bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void gl_make_current(gl_render_window_t* bundle) {
}
bool hasSetMainWindow = false;
if(pojav_environ->mainWindowBundle == NULL) {
if(getenv("POJAV_SPARE_BRIDGE") != NULL) {
if(getenv("POJAV_CONFIG_BRIDGE") != NULL) {
pojav_environ->mainWindowBundle = bundle;
} else {
pojav_environ->mainWindowBundle = (basic_render_window_t*)bundle;
Expand All @@ -131,7 +131,7 @@ void gl_make_current(gl_render_window_t* bundle) {
}else {
if(hasSetMainWindow) {
pojav_environ->mainWindowBundle->newNativeSurface = NULL;
if(getenv("POJAV_SPARE_BRIDGE") != NULL) {
if(getenv("POJAV_CONFIG_BRIDGE") != NULL) {
gl_swap_surface(pojav_environ->mainWindowBundle);
} else {
gl_swap_surface((gl_render_window_t*)pojav_environ->mainWindowBundle);
Expand Down
Loading

0 comments on commit 8b70447

Please sign in to comment.