Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
55b4a35
[Chore] (version): bump version to 1.3.5
BZLZHH Jul 11, 2026
938611b
[Refactor] (config): rewrite the config layer and adopt the new multi…
BZLZHH Aug 5, 2026
5cd4095
[Refactor] (multidraw): follow the backend rename in the native confi…
BZLZHH Aug 5, 2026
3858ea2
[Build] (compose): switch the toolchain from View/XML to Compose + Miuix
BZLZHH Aug 6, 2026
613dbd4
[Refactor] (storage): put the shared state layer behind skin-agnostic…
BZLZHH Aug 6, 2026
a6d1db6
[Feature] (ui): add the Compose shell, controller and MD3 component set
BZLZHH Aug 6, 2026
f0b675d
[Chore] (ui): drop the last View-era files
BZLZHH Aug 6, 2026
1dec7d7
[Build] (deps): pin Miuix to 0.8.8 and raise activity-compose to 1.13
BZLZHH Aug 6, 2026
ae5ce6c
[Feature] (ui): draw the MD3 skin
BZLZHH Aug 6, 2026
d25ad73
[Feature] (ui): draw the Miuix skin
BZLZHH Aug 6, 2026
7008f1e
[Fix] (auth): take the grant the system already gave us
BZLZHH Aug 6, 2026
38f4ac5
[Test]: follow the storage abstraction and cover the new pure logic
BZLZHH Aug 6, 2026
f6787a6
[Chore] (submodule): follow MobileGlues dev up to be7e31b
BZLZHH Aug 6, 2026
cdea69f
[Chore] (version): bump to 1.3.6·Dev (1359)
BZLZHH Aug 6, 2026
f8e0530
Merge remote-tracking branch 'origin/dev' into refactor/ui
BZLZHH Aug 6, 2026
3145490
[Chore] (strings): soften the privacy intro and sponsor prompt
BZLZHH Aug 6, 2026
ce08cc1
[Refactor] (sponsor): count launches where they happen, in the renderer
BZLZHH Aug 6, 2026
0e97830
[Feat] (privacy): ask for consent on the very first launch
BZLZHH Aug 6, 2026
7d8aa4a
[Chore] (info): give the GL info and privacy rows a group heading
BZLZHH Aug 6, 2026
2aab8a9
[Feat] (auth): let the user take back what they granted
BZLZHH Aug 6, 2026
916ed6a
[Refactor] (danger zone): one entry for revoking and resetting
BZLZHH Aug 6, 2026
15a40c0
[Feat] (danger zone): say goodbye before leaving
BZLZHH Aug 6, 2026
e35339c
[Fix] (danger zone): a full reset has to clear what the app kept too
BZLZHH Aug 6, 2026
80c5f6b
[Fix] (auth): authorization is what the user chose, not what the syst…
BZLZHH Aug 6, 2026
e7463cb
[Chore] (privacy): lift the section headings out of their cards
BZLZHH Aug 6, 2026
082150c
[Chore] (privacy): give the section headings a document colour
BZLZHH Aug 6, 2026
fd12b15
[Refactor] (stats): opt in to launch counting from the launcher env
BZLZHH Aug 6, 2026
889f058
[Feat] (sponsor): offer every channel instead of one link
BZLZHH Aug 6, 2026
90c3524
[Feat] (info): three repositories, and credit for what we build on
BZLZHH Aug 6, 2026
fc74dce
[Feat] (info): thank everyone who worked on this
BZLZHH Aug 6, 2026
177e8b1
[Chore] (version): bump to 2.0.0·Dev (1999)
BZLZHH Aug 6, 2026
04026b5
[Chore] (credits): drop GLM
BZLZHH Aug 6, 2026
20856d8
[Chore] (submodule): follow the rebased GLM removal
BZLZHH Aug 6, 2026
e220741
[Chore] (version): number this development build 2.0.0·Dev1
BZLZHH Aug 6, 2026
cf0b684
[Chore] (submodule): follow the renderer to 2.0.0
BZLZHH Aug 6, 2026
a7c77fc
Merge pull request #39 from MobileGL-Dev/refactor/ui
BZLZHH Aug 6, 2026
6231a6a
[Chore] (version): 2.0.0·Dev2
BZLZHH Aug 7, 2026
04bbb0a
[Chore] (credits): drop GlslOptimizerV2
BZLZHH Aug 7, 2026
f7a821f
[Feat] (miuix): buzz when a fling reaches the end
BZLZHH Aug 7, 2026
57584d7
[Feat] (miuix): give the backend chips a switch's feel
BZLZHH Aug 7, 2026
d23a870
[Chore] (settings): move the custom GL version into Advanced
BZLZHH Aug 7, 2026
52fe306
[Chore] (miuix): let the dialogs read like Miuix dialogs
BZLZHH Aug 7, 2026
0e850e4
[Chore] (submodule): follow MobileGlues dev to a6011a2
BZLZHH Aug 7, 2026
03a4198
[Fix] (reset): only delete files MobileGlues and the plugin actually …
BZLZHH Aug 7, 2026
49e56ab
[Chore] (submodule): follow MobileGlues dev to a560d6e
BZLZHH Aug 7, 2026
a4f7ad1
[Feat] (multidraw): order the MultiDraw strategies by hand or by benc…
BZLZHH Aug 7, 2026
bcc4835
[Fix] (multidraw): let the drop animation follow the row, not its old…
BZLZHH Aug 7, 2026
b90321a
[Feat] (multidraw): say which pass is running, and ask before adoptin…
BZLZHH Aug 7, 2026
fdfb224
[Feat] (multidraw): benchmark each function on its own, and trim the …
BZLZHH Aug 7, 2026
cb23834
[Feat] (bench): borrow ANGLE from a launcher so it measures the real …
BZLZHH Aug 7, 2026
d8288b0
[Feat] (multidraw): point users at the benchmark when it is worth run…
BZLZHH Aug 7, 2026
bffea37
[Fix] (renderer): pull in the EGL lifetime fixes and the uniform-name…
BZLZHH Aug 8, 2026
684eebd
[Fix] (renderer): pull in the framebuffer and pixel subsystem fixes
BZLZHH Aug 8, 2026
dd67aad
[Fix] (angle): run each query in a throwaway process, and report the …
BZLZHH Aug 8, 2026
8549b22
[Fix] (bench): tell the user the run died instead of showing a rankin…
BZLZHH Aug 8, 2026
c498100
[Feat] (bench): start over on a smaller scene when the driver loses t…
BZLZHH Aug 8, 2026
99b9232
[Fix] (bench): say what happened and what it means, not how it works
BZLZHH Aug 8, 2026
1e9b009
[Fix] (renderer): pull in the adaptive benchmark scene and the indire…
BZLZHH Aug 8, 2026
3b6d608
[Fix] (ui): let the contributor grid fill the width instead of leanin…
BZLZHH Aug 8, 2026
b938de1
[Refactor] (renderer): pull in the single-hash-map change
BZLZHH Aug 8, 2026
19e87d5
[Refactor] (renderer): follow the hash map to ska::flat_hash_map
BZLZHH Aug 8, 2026
8ebd10d
[Perf] (renderer): pull in the Dev4 performance batch
BZLZHH Aug 9, 2026
08a0cdc
[Feat] (bench): let a benchmark be started from adb, and follow the r…
BZLZHH Aug 9, 2026
7941161
[Fix] (bench): stop promising eight seconds, and stop calling one res…
BZLZHH Aug 9, 2026
edfd326
[Fix] (ui): make both skins usable in landscape
BZLZHH Aug 9, 2026
52e0d3c
[Fix] (ui): give the MultiDraw actions a button to press
BZLZHH Aug 9, 2026
49d28be
[Feat] (ui): default to the Miuix skin on MIUI and HyperOS
BZLZHH Aug 9, 2026
69887fb
[Fix] (bench): hold the screen on for the run, and say how long it ca…
BZLZHH Aug 9, 2026
c0e4884
[Chore] (release): 2.0.0
BZLZHH Aug 9, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion MobileGlues
Submodule MobileGlues updated 67 files
+3 −6 .gitmodules
+0 −1 MobileGlues-cpp/3rdparty/glm
+20 −1 MobileGlues-cpp/CMakeLists.txt
+1,437 −0 MobileGlues-cpp/bench/multidraw_bench.cpp
+2 −0 MobileGlues-cpp/config/config.cpp
+44 −43 MobileGlues-cpp/config/gpu_utils.cpp
+448 −118 MobileGlues-cpp/config/settings.cpp
+78 −8 MobileGlues-cpp/config/settings.h
+112 −0 MobileGlues-cpp/config/stats.cpp
+37 −0 MobileGlues-cpp/config/stats.h
+330 −0 MobileGlues-cpp/egl/context.cpp
+128 −0 MobileGlues-cpp/egl/context.h
+848 −28 MobileGlues-cpp/egl/egl.cpp
+49 −11 MobileGlues-cpp/egl/loader.cpp
+32 −2 MobileGlues-cpp/egl/loader.h
+105 −0 MobileGlues-cpp/egl/trace.h
+542 −74 MobileGlues-cpp/gl/ExtWrappers/DSAWrapper.cpp
+3 −1 MobileGlues-cpp/gl/ExtWrappers/DSAWrapper.h
+33 −7 MobileGlues-cpp/gl/ExtWrappers/MultiBindWrapper.cpp
+0 −1 MobileGlues-cpp/gl/ExtWrappers/MultiBindWrapper.h
+293 −59 MobileGlues-cpp/gl/FSR1/FSR1.cpp
+16 −4 MobileGlues-cpp/gl/FSR1/FSR1.h
+395 −49 MobileGlues-cpp/gl/buffer.cpp
+14 −0 MobileGlues-cpp/gl/buffer.h
+399 −91 MobileGlues-cpp/gl/drawing.cpp
+21 −0 MobileGlues-cpp/gl/drawing.h
+704 −0 MobileGlues-cpp/gl/enable.cpp
+125 −0 MobileGlues-cpp/gl/enable.h
+434 −51 MobileGlues-cpp/gl/framebuffer.cpp
+74 −6 MobileGlues-cpp/gl/framebuffer.h
+125 −19 MobileGlues-cpp/gl/getter.cpp
+61 −17 MobileGlues-cpp/gl/gl.cpp
+19 −19 MobileGlues-cpp/gl/gl_native.cpp
+30 −19 MobileGlues-cpp/gl/gl_stub.cpp
+189 −35 MobileGlues-cpp/gl/glsl/cache.cpp
+22 −1 MobileGlues-cpp/gl/glsl/cache.h
+98 −118 MobileGlues-cpp/gl/glsl/glsl_for_es.cpp
+2 −1 MobileGlues-cpp/gl/log.cpp
+2 −1 MobileGlues-cpp/gl/mg.cpp
+50 −1 MobileGlues-cpp/gl/mg.h
+1,973 −384 MobileGlues-cpp/gl/multidraw.cpp
+43 −0 MobileGlues-cpp/gl/multidraw.h
+190 −457 MobileGlues-cpp/gl/pixel.cpp
+61 −21 MobileGlues-cpp/gl/pixel.h
+54 −38 MobileGlues-cpp/gl/program.cpp
+2 −0 MobileGlues-cpp/gl/program.h
+197 −0 MobileGlues-cpp/gl/restart.cpp
+70 −0 MobileGlues-cpp/gl/restart.h
+1 −5 MobileGlues-cpp/gl/shader.cpp
+5 −1 MobileGlues-cpp/gl/shader.h
+933 −164 MobileGlues-cpp/gl/texture.cpp
+36 −0 MobileGlues-cpp/gl/texture.h
+763 −0 MobileGlues-cpp/gl/transfer.cpp
+140 −0 MobileGlues-cpp/gl/transfer.h
+85 −6 MobileGlues-cpp/gles/loader.cpp
+68 −12 MobileGlues-cpp/gles/loader.h
+21 −25 MobileGlues-cpp/glx/lookup.cpp
+0 −1 MobileGlues-cpp/include/FastSTL
+0 −2,101 MobileGlues-cpp/include/ankerl/unordered_dense.h
+1 −0 MobileGlues-cpp/include/ska
+20 −3 MobileGlues-cpp/includes.h
+6 −1 MobileGlues-cpp/main.cpp
+147 −0 MobileGlues-cpp/tests/framebuffer_shuffle_test.cpp
+93 −0 MobileGlues-cpp/tests/pixel_size_test.cpp
+14 −0 MobileGlues-cpp/tests/run.sh
+10 −3 MobileGlues-cpp/version.h
+2 −2 README.md
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,19 @@ Please see [LICENSE](https://github.com/MobileGL-Dev/MobileGlues-plugin/blob/mai

Third party components
====
Please see [MobileGlues-release](https://github.com/MobileGL-Dev/MobileGlues-release).
For the components used by the renderer itself, please see [MobileGlues-release](https://github.com/MobileGL-Dev/MobileGlues-release).

The plugin application additionally uses:

**Miuix** by **compose-miuix-ui** - [Apache License 2.0](https://github.com/compose-miuix-ui/miuix/blob/main/LICENSE): [github](https://github.com/compose-miuix-ui/miuix)

**Jetpack Compose** by **Android Open Source Project (AOSP)** - [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0.txt): [Android Developers](https://developer.android.com/jetpack/compose)

**AndroidX** by **Android Open Source Project (AOSP)** - [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0.txt): [Android Developers](https://developer.android.com/jetpack/androidx)

**kotlinx.coroutines** by **JetBrains** - [Apache License 2.0](https://github.com/Kotlin/kotlinx.coroutines/blob/master/LICENSE.txt): [github](https://github.com/Kotlin/kotlinx.coroutines)

**Gson** by **Google** - [Apache License 2.0](https://github.com/google/gson/blob/main/LICENSE): [github](https://github.com/google/gson)

Check signature of your release
====
Expand Down
36 changes: 28 additions & 8 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlin.compose)
}

android {
Expand All @@ -13,8 +14,8 @@ android {
applicationId = "com.fcl.plugin.mobileglues"
minSdk = 26
targetSdk = 36
versionCode = 1350
versionName = "1.3.5"
versionCode = 2000
versionName = "2.0.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down Expand Up @@ -47,8 +48,11 @@ android {
manifestPlaceholders["minMCVer"] = "1.17"
manifestPlaceholders["maxMCVer"] = "" //为空则不限制 No restriction if empty

// MG_COUNT_LAUNCH:只有经启动器起来的这一次才算「一次启动」。
// 基准测试、各种工具、以及本插件自己 dlopen 一次去读 GL 信息,都不该计数。
manifestPlaceholders["boatEnv"] = mutableMapOf<String,String>().apply {
put("LIBGL_ES", "3")
put("MG_COUNT_LAUNCH", "1")
}.run {
var env = ""
forEach { (key, value) ->
Expand All @@ -61,6 +65,7 @@ android {
put("POJAV_RENDERER", "opengles3")
put("POJAVEXEC_EGL", "libmobileglues.so")
put("LIBGL_EGL", "libmobileglues.so")
put("MG_COUNT_LAUNCH", "1")
}.run {
var env = ""
forEach { (key, value) ->
Expand All @@ -81,12 +86,15 @@ android {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = "11"
kotlin {
compilerOptions {
jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_11)
}
}
buildFeatures {
buildConfig = true
viewBinding = true
aidl = true
compose = true
}
packaging {
jniLibs {
Expand All @@ -97,8 +105,20 @@ android {

dependencies {
implementation(libs.gson)
implementation(libs.appcompat)
implementation(libs.constraintlayout)
implementation(libs.google.material)
implementation(platform(libs.androidx.compose.bom))
implementation(libs.androidx.compose.ui)
implementation(libs.androidx.compose.ui.graphics)
implementation(libs.androidx.compose.ui.tooling.preview)
implementation(libs.androidx.compose.material3)
implementation(libs.androidx.activity.compose)
implementation(libs.androidx.lifecycle.runtime.compose)
implementation(libs.androidx.documentfile)
implementation(libs.miuix.ui)
// 协程和 lifecycleScope 以前是从 appcompat 传递依赖里蹭来的,这里显式声明。
implementation(libs.coroutines.android)
implementation(libs.lifecycle.runtime.ktx)
implementation(project(":MobileGlues"))

testImplementation(libs.junit)
testImplementation(libs.coroutines.test)
}
26 changes: 26 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,24 @@
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="29" />

<!--
ANGLE 随启动器分发,不在本 App 里。跑分要在与游戏相同的驱动上测,就得先看看
装了哪些启动器、它们的 native 库目录里有没有 ANGLE——Android 11 起,没在这里
点名的包,PackageManager 一律当作不存在。名单与 AngleProvider 的保持一致。
-->
<queries>
<package android:name="com.tungsten.fcl" />
<package android:name="com.tungsten.fcm" />
<package android:name="com.tungsten.fcl.ngg" />
<package android:name="com.tungsten.fcl.qualcommdr" />
<package android:name="com.tungsten.fcl.mgdebug.debug" />
<package android:name="com.movtery.zalithlauncher.v2" />
<package android:name="com.movtery.zalithlauncher.v2.debug" />
<package android:name="org.fcl.enchantnet" />
</queries>

<application
android:name=".MGApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
Expand All @@ -30,6 +47,15 @@
</intent-filter>
</activity>

<!--
渲染器查询(跑分、GL 信息)的一次性进程。库的静态构造只在首次载入时读
MG_ANGLE_DIR 与配置,而库离不开进程——所以每次查询用一个新进程,查完即弃。
-->
<service
android:name=".MgQueryService"
android:exported="false"
android:process=":mgquery" />

<meta-data
android:name="fclPlugin"
android:value="true" />
Expand Down
19 changes: 19 additions & 0 deletions app/src/main/aidl/com/fcl/plugin/mobileglues/IMgQuery.aidl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.fcl.plugin.mobileglues;

/**
* 渲染器查询:在一次性的 :mgquery 进程里执行。
*
* 每个方法都是阻塞的同步调用(runBench 可达一分多钟),binder 会占住调用方的一条线程,
* 所以只能从后台线程发起。angleDirectory 传空串表示「不借 ANGLE」——AIDL 的 String
* 不好表达 null,而渲染器那边空串与 null 本就同义(MG_ANGLE_DIR 的空值状态)。
*/
interface IMgQuery {
/**
* startSections = 起手场景规模,0 用渲染器默认值;maxSections = 本次不得越过的上限,
* 0 表示没有。上一次跑分丢了 GL 上下文之后,调用方带着上限重来一次——崩过的那个规模
* 只能由调用方记住,查询进程每次都是新的,它自己不可能知道。
*/
String runBench(String mgDirectory, String angleDirectory, int startSections, int maxSections);
int benchProgress();
String glInfo(String mgDirectory, String angleDirectory);
}
2 changes: 2 additions & 0 deletions app/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ add_library(mobileglues_info_getter SHARED
)

find_library(android-lib android)
find_library(log-lib log)

target_compile_options(mobileglues_info_getter PRIVATE
-Oz
Expand All @@ -34,5 +35,6 @@ target_include_directories(mobileglues_info_getter PRIVATE

target_link_libraries(mobileglues_info_getter
${android-lib}
${log-lib}
dl
)
123 changes: 123 additions & 0 deletions app/src/main/cpp/mobileglues_info_getter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,17 @@ static std::string create_context_and_query() {

out << "Is MobileGlues (>=1.3.3): " << (g_MGQueryCapability.HasMobileGluesExt ? "Yes\n" : "No\n");

// Which driver actually answered. The loader is the only honest source: the
// renderer string cannot be trusted (a system driver may itself be ANGLE),
// and the caller's own "did I pass a directory" is an intention, not a fact.
// Old renderers lack the symbol; the line is simply absent then, and the
// Kotlin side treats that as "unknown".
typedef int (*PFN_mg_angle_in_use)();
auto p_angle_in_use = (PFN_mg_angle_in_use) dlsym(mg_handle, "mg_angle_in_use");
if (p_angle_in_use) {
out << "ANGLE in use: " << (p_angle_in_use() ? "yes" : "no") << "\n";
}

const GLubyte* renderer = p_glGetString(GL_RENDERER);
const GLubyte* version = p_glGetString(GL_VERSION);
const GLubyte* vendor = p_glGetString(GL_VENDOR);
Expand Down Expand Up @@ -203,6 +214,118 @@ Java_com_fcl_plugin_mobileglues_MGInfoGetter_getMobileGluesGLInfo(JNIEnv *env,
return env->NewStringUTF(res.c_str());
}

// Runs the MultiDraw micro benchmark that lives inside libmobileglues
// (gl/multidraw_bench.cpp) and returns its JSON verbatim. Same shape as the GL
// info query: dlopen the renderer, make a context current through its own EGL
// layer, call one symbol, tear everything down.
// Published while the benchmark runs so the UI thread can poll how far along it
// is. The pointer belongs to a dlopen'd library, so it is only valid between
// the dlsym below and the dlclose at the end of the run -- hence the lock.
typedef int (*PFN_mg_multidraw_bench_progress)();
static std::mutex g_bench_progress_mutex;
static PFN_mg_multidraw_bench_progress p_bench_progress = nullptr;

static void set_bench_progress_fn(PFN_mg_multidraw_bench_progress fn) {
std::lock_guard<std::mutex> lock(g_bench_progress_mutex);
p_bench_progress = fn;
}

static std::string create_context_and_bench(int start_sections, int max_sections) {
if (!load_mobile_symbols()) return R"({"error":"failed to load libmobileglues symbols"})";

typedef const char* (*PFN_mg_multidraw_bench_run)(int, int);
auto p_bench = (PFN_mg_multidraw_bench_run) dlsym(mg_handle, "mg_multidraw_bench_run");
if (!p_bench) {
return R"({"error":"mg_multidraw_bench_run is missing; the renderer is too old"})";
}
// Optional: an older renderer has the benchmark but not the progress
// counter, and the caller falls back to an indeterminate spinner.
auto p_progress = (PFN_mg_multidraw_bench_progress) dlsym(mg_handle, "mg_multidraw_bench_progress");

EGLDisplay display = p_eglGetDisplay(EGL_DEFAULT_DISPLAY);
if (display == EGL_NO_DISPLAY) return R"({"error":"eglGetDisplay returned EGL_NO_DISPLAY"})";

EGLint major = 0, minor = 0;
if (!p_eglInitialize(display, &major, &minor)) {
return R"({"error":"eglInitialize failed"})";
}

EGLint configAttribs[] = {
EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_ALPHA_SIZE, 8,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT,
EGL_NONE
};
EGLConfig config;
EGLint numConfigs = 0;
if (!p_eglChooseConfig(display, configAttribs, &config, 1, &numConfigs) || numConfigs <= 0) {
p_eglTerminate(display);
return R"({"error":"eglChooseConfig failed"})";
}

EGLint pbufAttribs[] = { EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE };
EGLSurface surface = p_eglCreatePbufferSurface(display, config, pbufAttribs);
if (surface == EGL_NO_SURFACE) {
p_eglTerminate(display);
return R"({"error":"eglCreatePbufferSurface failed"})";
}

EGLint ctxAttribs3[] = { EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE };
EGLContext context = p_eglCreateContext(display, config, EGL_NO_CONTEXT, ctxAttribs3);
if (context == EGL_NO_CONTEXT) {
p_eglDestroySurface(display, surface);
p_eglTerminate(display);
return R"({"error":"eglCreateContext failed"})";
}

if (!p_eglMakeCurrent(display, surface, surface, context)) {
p_eglDestroyContext(display, context);
p_eglDestroySurface(display, surface);
p_eglTerminate(display);
return R"({"error":"eglMakeCurrent failed"})";
}

set_bench_progress_fn(p_progress);
const char* raw = p_bench(start_sections, max_sections);
// Copy before teardown: the string lives inside libmobileglues.
std::string res = raw ? raw : R"({"error":"benchmark returned nothing"})";
set_bench_progress_fn(nullptr);

p_eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
p_eglDestroySurface(display, surface);
p_eglDestroyContext(display, context);
p_eglTerminate(display);

dlclose(mg_handle);
mg_handle = nullptr;

return res;
}

extern "C"
JNIEXPORT jstring JNICALL
Java_com_fcl_plugin_mobileglues_MGBench_runMultidrawBench(JNIEnv *env, jobject thiz,
jint startSections, jint maxSections) {
std::string res = create_context_and_bench(startSections, maxSections);
printf("MobileGlues MultiDraw bench: \n%s", res.c_str());
__android_log_print(ANDROID_LOG_INFO, "MGBench", "%s", res.c_str());
return env->NewStringUTF(res.c_str());
}

// 0..1000 while a benchmark is running, -1 when none is (or when the renderer
// predates the progress counter). Called from a different thread than the run.
extern "C"
JNIEXPORT jint JNICALL
Java_com_fcl_plugin_mobileglues_MGBench_benchProgress(JNIEnv *env, jobject thiz) {
(void)env;
(void)thiz;
std::lock_guard<std::mutex> lock(g_bench_progress_mutex);
return p_bench_progress ? p_bench_progress() : -1;
}

JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
(void)vm;
(void)reserved;
Expand Down
1 change: 1 addition & 0 deletions app/src/main/cpp/mobileglues_info_getter.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once
#include <jni.h>
#include <mutex>
#include <string>
#include <vector>
#include <sstream>
Expand Down
Loading
Loading