[Feature] (EGL+GL): advertise EGL_EXT_create_context_robustness and GL robustness, with per-context reset notification and a pid-targeted device-loss knob.

This commit is contained in:
2026-10-03 04:37:33 -04:00
parent af2b9f4c1c
commit 90e63c9e2a
19 changed files with 963 additions and 40 deletions
+42
View File
@@ -54,6 +54,7 @@
#include <algorithm>
#include <atomic>
#include <chrono>
#include <cmath>
#include <cstdarg>
#include <cstdio>
@@ -209,6 +210,47 @@ namespace MobileGL::MG_Pipe {
return true;
}
bool MGPipeDebugSessionLossDue(unsigned clientPid) {
if (clientPid == 0) return false;
// The first call on a thread only starts the clock, so a session is first asked 100 ms
// after it started rendering - never in the middle of its first make-current.
thread_local auto lastAsked = std::chrono::steady_clock::time_point{};
const auto now = std::chrono::steady_clock::now();
if (lastAsked == std::chrono::steady_clock::time_point{}) {
lastAsked = now;
return false;
}
if (now - lastAsked < std::chrono::milliseconds(100)) return false;
lastAsked = now;
long target = 0;
if (const char* value = std::getenv("MOBILEGL_DEBUG_INJECT_DEVICE_LOST_PID")) {
target = std::strtol(value, nullptr, 10);
}
#if defined(__ANDROID__)
else {
char property[PROP_VALUE_MAX] = {};
if (__system_property_get("debug.mobilegl.inject_device_lost_pid", property) > 0) {
target = std::strtol(property, nullptr, 10);
}
}
#endif
// Once per value: the session it hit is over, and a later session of the same process (the
// recovery's) must not be lost again by the same setting. Another pid - or unset/0 and
// then the same one - re-arms it.
static std::atomic<long> firedFor{0};
if (target <= 0) {
if (firedFor.load(std::memory_order_relaxed) != 0) firedFor.store(0, std::memory_order_relaxed);
return false;
}
if (static_cast<unsigned long>(target) != clientPid) return false;
long previous = firedFor.load(std::memory_order_acquire);
if (previous == target || !firedFor.compare_exchange_strong(previous, target, std::memory_order_acq_rel)) {
return false;
}
MGLOG_E("MGPipe: debug knob inject_device_lost_pid=%ld - this session's device is reported LOST", target);
return true;
}
bool MGPipeSessionLatch(MGPipeFatalFamily family, const char* fmt, ...) {
char line[512];
va_list args;