Merge pull request #9728 from JosJuice/android-get-shader-list

Android: Use JNI for getting post-processsing shaders
This commit is contained in:
Mai M 2021-05-20 11:16:08 -04:00 committed by GitHub
commit 1d175e7e13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 67 additions and 87 deletions

View File

@ -0,0 +1,15 @@
package org.dolphinemu.dolphinemu.features.settings.model;
import androidx.annotation.NonNull;
public class PostProcessing
{
@NonNull
public static native String[] getShaderList();
@NonNull
public static native String[] getAnaglyphShaderList();
@NonNull
public static native String[] getPassiveShaderList();
}

View File

@ -17,6 +17,7 @@ import org.dolphinemu.dolphinemu.features.settings.model.IntSetting;
import org.dolphinemu.dolphinemu.features.settings.model.LegacyBooleanSetting;
import org.dolphinemu.dolphinemu.features.settings.model.LegacyIntSetting;
import org.dolphinemu.dolphinemu.features.settings.model.LegacyStringSetting;
import org.dolphinemu.dolphinemu.features.settings.model.PostProcessing;
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
import org.dolphinemu.dolphinemu.features.settings.model.StringSetting;
import org.dolphinemu.dolphinemu.features.settings.model.WiimoteProfileStringSetting;
@ -622,11 +623,17 @@ public final class SettingsFragmentPresenter
int stereoModeValue = IntSetting.GFX_STEREO_MODE.getInt(mSettings);
final int anaglyphMode = 3;
String subDir = stereoModeValue == anaglyphMode ? "Anaglyph" : null;
String[] shaderListEntries = getShaderList(subDir);
String[] shaderListValues = new String[shaderListEntries.length];
System.arraycopy(shaderListEntries, 0, shaderListValues, 0, shaderListEntries.length);
String[] shaderList = stereoModeValue == anaglyphMode ?
PostProcessing.getAnaglyphShaderList() : PostProcessing.getShaderList();
String[] shaderListEntries = new String[shaderList.length + 1];
shaderListEntries[0] = mContext.getString(R.string.off);
System.arraycopy(shaderList, 0, shaderListEntries, 1, shaderList.length);
String[] shaderListValues = new String[shaderList.length + 1];
shaderListValues[0] = "";
System.arraycopy(shaderList, 0, shaderListValues, 1, shaderList.length);
sl.add(new StringSingleChoiceSetting(mContext, StringSetting.GFX_ENHANCE_POST_SHADER,
R.string.post_processing_shader, 0, shaderListEntries, shaderListValues));
@ -664,46 +671,6 @@ public final class SettingsFragmentPresenter
}
}
private String[] getShaderList(String subDir)
{
try
{
String shadersPath =
DirectoryInitialization.getDolphinInternalDirectory() + "/Shaders";
if (!TextUtils.isEmpty(subDir))
{
shadersPath += "/" + subDir;
}
File file = new File(shadersPath);
File[] shaderFiles = file.listFiles();
if (shaderFiles != null)
{
String[] result = new String[shaderFiles.length + 1];
result[0] = mView.getActivity().getString(R.string.off);
for (int i = 0; i < shaderFiles.length; i++)
{
String name = shaderFiles[i].getName();
int extensionIndex = name.indexOf(".glsl");
if (extensionIndex > 0)
{
name = name.substring(0, extensionIndex);
}
result[i + 1] = name;
}
return result;
}
}
catch (Exception ex)
{
Log.debug("[Settings] Unable to find shader files");
// return empty list
}
return new String[]{};
}
private void addHackSettings(ArrayList<SettingsItem> sl)
{
sl.add(new HeaderSetting(mContext, R.string.embedded_frame_buffer, 0));

View File

@ -234,18 +234,6 @@ public final class SettingsFile
readFile(getCustomGameSettingsFile(gameId), ini, view);
}
public static void readGenericGameSettings(final String gameId, IniFile ini,
SettingsActivityView view)
{
readFile(getGenericGameSettingsFile(gameId), ini, view);
}
public static void readGenericGameSettingsForAllRegions(final String gameId,
IniFile ini, SettingsActivityView view)
{
readFile(getGenericGameSettingsForAllRegions(gameId), ini, view);
}
/**
* Saves a given .ini file on disk.
* If unsuccessful, outputs an error telling why it failed.
@ -296,22 +284,6 @@ public final class SettingsFile
DirectoryInitialization.getUserDirectory() + "/Config/" + fileName + ".ini");
}
private static File getGenericGameSettingsForAllRegions(String gameId)
{
// Use the first 3 chars from the gameId to load the generic game settings for all regions
gameId = gameId.substring(0, 3);
return new File(
DirectoryInitialization.getDolphinInternalDirectory() + "/GameSettings/" +
gameId + ".ini");
}
private static File getGenericGameSettingsFile(String gameId)
{
return new File(
DirectoryInitialization.getDolphinInternalDirectory() + "/GameSettings/" +
gameId + ".ini");
}
public static File getCustomGameSettingsFile(String gameId)
{
return new File(

View File

@ -42,7 +42,6 @@ public final class DirectoryInitialization
DirectoryInitializationState.NOT_YET_INITIALIZED;
private static volatile boolean areDirectoriesAvailable = false;
private static String userPath;
private static String internalPath;
private static AtomicBoolean isDolphinDirectoryInitializationRunning = new AtomicBoolean(false);
public enum DirectoryInitializationState
@ -128,7 +127,6 @@ public final class DirectoryInitialization
private static void initializeInternalStorage(Context context)
{
File sysDirectory = new File(context.getFilesDir(), "Sys");
internalPath = sysDirectory.getAbsolutePath();
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
String revision = NativeLibrary.GetGitRevision();
@ -241,16 +239,6 @@ public final class DirectoryInitialization
return userPath;
}
public static String getDolphinInternalDirectory()
{
if (!areDirectoriesAvailable)
{
throw new IllegalStateException(
"DirectoryInitialization must run before accessing the internal directory!");
}
return internalPath;
}
private static void sendBroadcastState(DirectoryInitializationState state, Context context)
{
Intent localIntent =

View File

@ -44,7 +44,7 @@ std::vector<std::string> JStringArrayToVector(JNIEnv* env, jobjectArray array)
return result;
}
jobjectArray JStringArrayFromVector(JNIEnv* env, std::vector<std::string> vector)
jobjectArray VectorToJStringArray(JNIEnv* env, std::vector<std::string> vector)
{
jobjectArray result = env->NewObjectArray(vector.size(), IDCache::GetStringClass(), nullptr);
for (jsize i = 0; i < vector.size(); ++i)
@ -145,7 +145,7 @@ std::vector<std::string> DoFileSearchAndroidContent(const std::string& directory
JNIEnv* env = IDCache::GetEnvForThread();
jobject result = env->CallStaticObjectMethod(
IDCache::GetContentHandlerClass(), IDCache::GetContentHandlerDoFileSearch(),
ToJString(env, directory), JStringArrayFromVector(env, extensions), recursive);
ToJString(env, directory), VectorToJStringArray(env, extensions), recursive);
return JStringArrayToVector(env, reinterpret_cast<jobjectArray>(result));
}

View File

@ -12,7 +12,9 @@
std::string GetJString(JNIEnv* env, jstring jstr);
jstring ToJString(JNIEnv* env, const std::string& str);
std::vector<std::string> JStringArrayToVector(JNIEnv* env, jobjectArray array);
jobjectArray VectorToJStringArray(JNIEnv* env, std::vector<std::string> vector);
// Returns true if the given path should be opened as Android content instead of a normal file.
bool IsPathAndroidContent(const std::string& uri);

View File

@ -1,10 +1,11 @@
add_library(main SHARED
Config/NativeConfig.cpp
Config/PostProcessing.cpp
GameList/GameFile.cpp
GameList/GameFile.h
GameList/GameFileCache.cpp
IniFile.cpp
MainAndroid.cpp
NativeConfig.cpp
WiiUtils.cpp
)

View File

@ -0,0 +1,35 @@
// Copyright 2021 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include <string>
#include <vector>
#include <jni.h>
#include "VideoCommon/PostProcessing.cpp"
#include "jni/AndroidCommon/AndroidCommon.h"
extern "C" {
JNIEXPORT jobjectArray JNICALL
Java_org_dolphinemu_dolphinemu_features_settings_model_PostProcessing_getShaderList(JNIEnv* env,
jclass)
{
return VectorToJStringArray(env, VideoCommon::PostProcessing::GetShaderList());
}
JNIEXPORT jobjectArray JNICALL
Java_org_dolphinemu_dolphinemu_features_settings_model_PostProcessing_getAnaglyphShaderList(
JNIEnv* env, jclass)
{
return VectorToJStringArray(env, VideoCommon::PostProcessing::GetAnaglyphShaderList());
}
JNIEXPORT jobjectArray JNICALL
Java_org_dolphinemu_dolphinemu_features_settings_model_PostProcessing_getPassiveShaderList(
JNIEnv* env, jclass)
{
return VectorToJStringArray(env, VideoCommon::PostProcessing::GetPassiveShaderList());
}
}