Skip to content

Commit

Permalink
Feat[Plugin]: renderer plugin
Browse files Browse the repository at this point in the history
Allow loading external renderers
  • Loading branch information
ShirosakiMio committed Oct 13, 2024
1 parent 9914181 commit 9ceb480
Show file tree
Hide file tree
Showing 11 changed files with 178 additions and 12 deletions.
2 changes: 1 addition & 1 deletion FCL/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android' version '1.9.20'
id 'org.jetbrains.kotlin.android' version '2.0.21'
id "org.hidetake.ssh" version "2.11.2"
}

Expand Down
3 changes: 3 additions & 0 deletions FCL/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,5 +152,8 @@
</application>
<queries>
<package android:name="net.kdt.pojavlaunch.ffmpeg"/>
<intent>
<action android:name="android.intent.action.MAIN" />
</intent>
</queries>
</manifest>
11 changes: 10 additions & 1 deletion FCL/src/main/java/com/tungsten/fcl/activity/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import com.tungsten.fcl.util.FXUtils
import com.tungsten.fcl.util.WeakListenerHolder
import com.tungsten.fclauncher.FCLConfig
import com.tungsten.fclauncher.bridge.FCLBridge
import com.tungsten.fclauncher.plugins.RendererPlugin
import com.tungsten.fclcore.auth.Account
import com.tungsten.fclcore.auth.authlibinjector.AuthlibInjectorAccount
import com.tungsten.fclcore.auth.authlibinjector.AuthlibInjectorServer
Expand Down Expand Up @@ -482,6 +483,9 @@ class MainActivity : FCLActivity(), OnSelectListener, View.OnClickListener {
add(getString(R.string.settings_fcl_renderer_vgpu))
add(getString(R.string.settings_fcl_renderer_zink))
add(getString(R.string.settings_fcl_renderer_freedreno))
RendererPlugin.rendererList.forEach {
add(it.des)
}
})
listView.setOnItemClickListener { _, _, position, _ ->
val selectedProfile = Profiles.getSelectedProfile()
Expand All @@ -494,7 +498,12 @@ class MainActivity : FCLActivity(), OnSelectListener, View.OnClickListener {
add(FCLConfig.Renderer.RENDERER_ZINK)
add(FCLConfig.Renderer.RENDERER_FREEDRENO)
}
versionSetting.renderer = rendererList[position]
if (position > rendererList.size - 1) {
versionSetting.renderer = FCLConfig.Renderer.RENDERER_CUSTOM
RendererPlugin.selected = RendererPlugin.rendererList[position - rendererList.size]
} else {
versionSetting.renderer = rendererList[position]
}
popupWindow?.dismiss()
onClick(view)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import com.tungsten.fclauncher.plugins.RendererPlugin;
import com.tungsten.fcl.R;
import com.tungsten.fcl.fragment.EulaFragment;
import com.tungsten.fcl.fragment.RuntimeFragment;
Expand Down Expand Up @@ -124,6 +125,7 @@ private void transFile() {
}

public void enterLauncher() {
RendererPlugin.init(this);
finish();
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
Expand Down
26 changes: 25 additions & 1 deletion FCL/src/main/java/com/tungsten/fcl/setting/VersionSetting.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import com.google.gson.JsonSerializationContext
import com.google.gson.JsonSerializer
import com.google.gson.annotations.JsonAdapter
import com.tungsten.fclauncher.FCLConfig
import com.tungsten.fclauncher.plugins.RendererPlugin
import com.tungsten.fclauncher.utils.FCLPath
import com.tungsten.fclcore.fakefx.beans.InvalidationListener
import com.tungsten.fclcore.fakefx.beans.property.BooleanProperty
Expand Down Expand Up @@ -225,6 +226,14 @@ class VersionSetting : Cloneable {
rendererProperty.set(renderer)
}

val customRendererProperty: ObjectProperty<String> =
SimpleObjectProperty(this, "customRenderer", "")
var customRenderer: String
get() = customRendererProperty.get()
set(renderer) {
customRendererProperty.set(renderer)
}

// launcher settings
fun getJavaVersion(version: Version?): Task<JavaVersion> {
return Task.runAsync(Schedulers.androidUIThread()) {
Expand Down Expand Up @@ -274,6 +283,7 @@ class VersionSetting : Cloneable {
vkDriverSystemProperty.addListener(listener)
controllerProperty.addListener(listener)
rendererProperty.addListener(listener)
customRendererProperty.addListener(listener)
}

public override fun clone(): VersionSetting {
Expand All @@ -295,6 +305,7 @@ class VersionSetting : Cloneable {
it.isVKDriverSystem = isVKDriverSystem
it.controller = controller
it.renderer = renderer
it.customRenderer = customRenderer
}
}

Expand Down Expand Up @@ -326,6 +337,7 @@ class VersionSetting : Cloneable {
addProperty("controller", src.controller)
addProperty("renderer", src.renderer.ordinal)
addProperty("isolateGameDir", src.isIsolateGameDir)
addProperty("customRenderer", src.customRenderer)
}
}

Expand Down Expand Up @@ -358,9 +370,21 @@ class VersionSetting : Cloneable {
vs.isBeGesture = json["beGesture"]?.asBoolean ?: false
vs.isVKDriverSystem = json["vulkanDriverSystem"]?.asBoolean ?: false
vs.controller = json["controller"]?.asString ?: ("00000000")
vs.renderer = FCLConfig.Renderer.values()[json["renderer"]?.asInt
vs.renderer = FCLConfig.Renderer.entries.toTypedArray()[json["renderer"]?.asInt
?: FCLConfig.Renderer.RENDERER_GL4ES.ordinal]
vs.isIsolateGameDir = json["isolateGameDir"]?.asBoolean ?: false
vs.customRenderer = json["customRenderer"]?.asString ?: ""
if (vs.customRenderer != "") {
RendererPlugin.rendererList.forEach {
if (it.des == vs.customRenderer) {
RendererPlugin.selected = it
}
}
}
if (RendererPlugin.rendererList.size == 0 && vs.customRenderer != "") {
vs.renderer = FCLConfig.Renderer.entries.toTypedArray()[0]
vs.customRenderer = ""
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.tungsten.fcl.util.RequestCodes;
import com.tungsten.fcl.util.WeakListenerHolder;
import com.tungsten.fclauncher.FCLConfig;
import com.tungsten.fclauncher.plugins.RendererPlugin;
import com.tungsten.fclauncher.utils.FCLPath;
import com.tungsten.fclcore.event.Event;
import com.tungsten.fclcore.fakefx.beans.InvalidationListener;
Expand Down Expand Up @@ -154,6 +155,9 @@ private void create() {
rendererDataList.add(FCLConfig.Renderer.RENDERER_VGPU);
rendererDataList.add(FCLConfig.Renderer.RENDERER_ZINK);
rendererDataList.add(FCLConfig.Renderer.RENDERER_FREEDRENO);
if (!RendererPlugin.getRendererList().isEmpty()) {
rendererDataList.add(FCLConfig.Renderer.RENDERER_CUSTOM);
}
rendererSpinner.setDataList(rendererDataList);

// add spinner text
Expand All @@ -174,9 +178,19 @@ private void create() {
rendererList.add(getContext().getString(R.string.settings_fcl_renderer_vgpu));
rendererList.add(getContext().getString(R.string.settings_fcl_renderer_zink));
rendererList.add(getContext().getString(R.string.settings_fcl_renderer_freedreno));
RendererPlugin.getRendererList().forEach(renderer -> {
rendererList.add(renderer.getDes());
});
ArrayAdapter<String> rendererAdapter = new ArrayAdapter<>(getContext(), R.layout.item_spinner_auto_tint, rendererList);
rendererAdapter.setDropDownViewResource(R.layout.item_spinner_dropdown);
rendererSpinner.setAdapter(rendererAdapter);
rendererSpinner.setListener(pos -> {
if (pos > 5) {
lastVersionSetting.setRenderer(FCLConfig.Renderer.RENDERER_CUSTOM);
lastVersionSetting.setCustomRenderer(RendererPlugin.getRendererList().get(pos - 6).getDes());
RendererPlugin.setSelected(RendererPlugin.getRendererList().get(pos - 6));
}
});

editIconButton = findViewById(R.id.edit_icon);
deleteIconButton = findViewById(R.id.delete_icon);
Expand Down Expand Up @@ -208,10 +222,10 @@ private void create() {
allocateSeekbar.progressProperty().bindBidirectional(maxMemory);

memoryText.stringProperty().bind(Bindings.createStringBinding(() -> allocateSeekbar.progressProperty().intValue() + " MB", allocateSeekbar.progressProperty()));
memoryText.setOnClickListener(v->{
memoryText.setOnClickListener(v -> {
EditDialog dialog = new EditDialog(getContext(), s -> {
if (s.matches("\\d+(\\.\\d+)?$")) {
allocateSeekbar.setProgress(Integer.parseInt(s));
allocateSeekbar.setProgress(Integer.parseInt(s));
}
});
dialog.getEditText().setInputType(EditorInfo.TYPE_NUMBER_FLAG_DECIMAL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,24 @@
import com.tungsten.fclcore.task.Schedulers;

import java.util.ArrayList;
import java.util.function.Consumer;

public class FCLSpinner<T> extends AppCompatSpinner {

private boolean fromUserOrSystem = false;
private ArrayList<T> dataList;
private ObjectProperty<T> selectedItemProperty;
private BooleanProperty visibilityProperty;
private Consumer<Integer> listener;

public void addSelectListener() {
setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
if (listener != null && dataList != null && i > dataList.size() - 1) {
listener.accept(i);
return;
}
if (dataList != null && dataList.size() > i) {
fromUserOrSystem = true;
selectedItemProperty().set(dataList.get(i));
Expand All @@ -43,6 +49,10 @@ public void onNothingSelected(AdapterView<?> adapterView) {
});
}

public void setListener(Consumer<Integer> listener) {
this.listener = listener;
}

public FCLSpinner(@NonNull Context context) {
super(context);
}
Expand Down
4 changes: 4 additions & 0 deletions FCLauncher/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android' version '2.0.21'
}

android {
Expand Down Expand Up @@ -36,6 +37,9 @@ android {
buildFeatures {
prefab true
}
kotlinOptions {
jvmTarget = '1.8'
}
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public enum Renderer implements Serializable {
RENDERER_LTW("LTW:libltw.so:libltw.so"),
RENDERER_VGPU("VGPU:libvgpu.so:libEGL.so"),
RENDERER_ZINK("Zink:libOSMesa_8.so:libEGL.so"),
RENDERER_FREEDRENO("Freedreno:libOSMesa_8.so:libEGL.so");
RENDERER_FREEDRENO("Freedreno:libOSMesa_8.so:libEGL.so"),
RENDERER_CUSTOM("Custom:libCustom.so:libEGL.so");

private final String glInfo;
private String glVersion;
Expand Down
35 changes: 29 additions & 6 deletions FCLauncher/src/main/java/com/tungsten/fclauncher/FCLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.oracle.dalvik.VMLauncher;
import com.tungsten.fclauncher.bridge.FCLBridge;
import com.tungsten.fclauncher.plugins.FFmpegPlugin;
import com.tungsten.fclauncher.plugins.RendererPlugin;
import com.tungsten.fclauncher.utils.Architecture;
import com.tungsten.fclauncher.utils.FCLPath;

Expand Down Expand Up @@ -81,7 +82,7 @@ private static String getJvmLibDir(String javaPath) throws IOException {
return jvmLibDir;
}

private static String getLibraryPath(Context context, String javaPath) throws IOException {
private static String getLibraryPath(Context context, String javaPath, String pluginLibPath) throws IOException {
String nativeDir = context.getApplicationInfo().nativeLibraryDir;
String libDirName = is64BitsDevice() ? "lib64" : "lib";
String jreLibDir = getJreLibDir(javaPath);
Expand Down Expand Up @@ -118,10 +119,12 @@ private static String getLibraryPath(Context context, String javaPath) throws IO
FCLPath.RUNTIME_DIR + "/jna" +
split +

((pluginLibPath != null) ? pluginLibPath + split : "") +

nativeDir;
}

private static String getLibraryPath(Context context) {
private static String getLibraryPath(Context context, String pluginLibPath) {
String nativeDir = context.getApplicationInfo().nativeLibraryDir;
String libDirName = is64BitsDevice() ? "lib64" : "lib";
String split = ":";
Expand All @@ -138,6 +141,8 @@ private static String getLibraryPath(Context context) {
"/hw" +
split +

((pluginLibPath != null) ? pluginLibPath + split : "") +

nativeDir;
}

Expand All @@ -146,8 +151,8 @@ private static String[] rebaseArgs(FCLConfig config) throws IOException {
argList.add(0, config.getJavaPath() + "/bin/java");
String[] args = new String[argList.size()];
for (int i = 0; i < argList.size(); i++) {
String a = argList.get(i).replace("${natives_directory}", getLibraryPath(config.getContext(), config.getJavaPath()));
args[i] = config.getRenderer() == null ? a : a.replace("${gl_lib_name}", config.getRenderer().getGlLibName());
String a = argList.get(i).replace("${natives_directory}", getLibraryPath(config.getContext(), config.getJavaPath(), config.getRenderer() == FCLConfig.Renderer.RENDERER_CUSTOM ? RendererPlugin.getSelected().getPath() : null));
args[i] = config.getRenderer() == null ? a : a.replace("${gl_lib_name}", config.getRenderer() == FCLConfig.Renderer.RENDERER_CUSTOM ? RendererPlugin.getSelected().getGlName() : config.getRenderer().getGlLibName());
}
return args;
}
Expand All @@ -159,7 +164,7 @@ private static void addCommonEnv(FCLConfig config, HashMap<String, String> envMa
envMap.put("POJAV_NATIVEDIR", config.getContext().getApplicationInfo().nativeLibraryDir);
envMap.put("TMPDIR", config.getContext().getCacheDir().getAbsolutePath());
envMap.put("PATH", config.getJavaPath() + "/bin:" + Os.getenv("PATH"));
envMap.put("LD_LIBRARY_PATH", getLibraryPath(config.getContext()));
envMap.put("LD_LIBRARY_PATH", getLibraryPath(config.getContext(), config.getRenderer() == FCLConfig.Renderer.RENDERER_CUSTOM ? RendererPlugin.getSelected().getPath() : null));
envMap.put("FORCE_VSYNC", "false");
if (!config.getJavaPath().contains("jre8")) {
String libName = config.getJavaPath().contains("jre17") ? "/libjsph17.so" : "/libjsph21.so";
Expand All @@ -177,6 +182,24 @@ private static void addCommonEnv(FCLConfig config, HashMap<String, String> envMa

private static void addRendererEnv(FCLConfig config, HashMap<String, String> envMap) {
FCLConfig.Renderer renderer = config.getRenderer() == null ? FCLConfig.Renderer.RENDERER_GL4ES : config.getRenderer();
if (renderer == FCLConfig.Renderer.RENDERER_CUSTOM) {
if (FCLBridge.BACKEND_IS_BOAT) {
envMap.put("LIBGL_STRING", RendererPlugin.getSelected().getName());
envMap.put("LIBGL_NAME", RendererPlugin.getSelected().getGlName());
envMap.put("LIBEGL_NAME", RendererPlugin.getSelected().getEglName());
RendererPlugin.getSelected().getBoatEnv().forEach(env -> {
String[] split = env.split("=");
envMap.put(split[0], split[1]);
});
} else {
envMap.put("POJAVEXEC_EGL", RendererPlugin.getSelected().getEglName());
RendererPlugin.getSelected().getPojavEnv().forEach(env -> {
String[] split = env.split("=");
envMap.put(split[0], split[1]);
});
}
return;
}
if (FCLBridge.BACKEND_IS_BOAT) {
envMap.put("LIBGL_STRING", renderer.toString());
envMap.put("LIBGL_NAME", renderer.getGlLibName());
Expand Down Expand Up @@ -316,7 +339,7 @@ private static void launch(FCLConfig config, FCLBridge bridge, String task) thro
isToken = true;
log(bridge, prefix + arg);
}
bridge.setLdLibraryPath(getLibraryPath(config.getContext(), config.getJavaPath()));
bridge.setLdLibraryPath(getLibraryPath(config.getContext(), config.getJavaPath(), config.getRenderer() == FCLConfig.Renderer.RENDERER_CUSTOM ? RendererPlugin.getSelected().getPath() : null));
bridge.setupExitTrap(bridge);
log(bridge, "Hook success");
int exitCode = VMLauncher.launchJVM(args);
Expand Down
Loading

0 comments on commit 9ceb480

Please sign in to comment.