[Fix] (Remote): a surfaceless make-current's hidden pbuffer no longer latches the session offscreen.

This commit is contained in:
2026-10-02 23:59:54 -04:00
parent 8b5295401f
commit b06c2a9bf2
7 changed files with 122 additions and 11 deletions
@@ -289,9 +289,21 @@ namespace MobileGL::MG_Remote::Client {
}
Bool BackendObject_Remote::CreateEGLPbufferSurface(EGLSurface surface, EGLint width, EGLint height) {
return CreatePbufferOnServer(surface, width, height, /*standIn=*/false);
}
Bool BackendObject_Remote::CreateEGLSurfacelessStandIn(EGLSurface surface, EGLint width, EGLint height) {
if (!CreatePbufferOnServer(surface, width, height, /*standIn=*/true)) return false;
const std::lock_guard<std::recursive_mutex> lock(m_eglStateMutex);
m_standInSurfaces.insert(surface);
return true;
}
Bool BackendObject_Remote::CreatePbufferOnServer(EGLSurface surface, EGLint width, EGLint height, Bool standIn) {
WaitForApplyBeforeEglForwarder("CreateEGLPbufferSurface");
Server::SurfaceRefusalCode refusal = Server::SurfaceRefusalCode::None;
if (!Server::ServerCreateEGLPbufferSurface(surface, width, height, &refusal)) {
if (!Server::ServerCreateEGLPbufferSurface(surface, width, height, &refusal,
standIn ? Server::kPbufferFlagSurfacelessStandIn : 0u)) {
if (refusal == Server::SurfaceRefusalCode::SurfaceModeMismatch) {
// P12 (D4), named on THIS side too: the server logged its half.
MGLOG_E("MG_Remote client: SurfaceModeMismatch - eglCreatePbufferSurface (%dx%d) in a session "
@@ -468,6 +480,7 @@ namespace MobileGL::MG_Remote::Client {
{
const std::lock_guard<std::recursive_mutex> lock(m_eglStateMutex);
homed = m_homedSurfaces.erase(surface) != 0;
m_standInSurfaces.erase(surface);
}
if (homed && !ClientSession::SessionLatchedLost()) Server::ServerReleaseEGLSurface(surface);
MG_Backend::BackendObject::ReleaseEGLSurface(surface);
@@ -481,6 +494,7 @@ namespace MobileGL::MG_Remote::Client {
{
const std::lock_guard<std::recursive_mutex> lock(m_eglStateMutex);
m_homedSurfaces.clear();
m_standInSurfaces.clear();
}
MG_Backend::BackendObject::ReleaseEGLResources();
}
@@ -516,7 +530,8 @@ namespace MobileGL::MG_Remote::Client {
Bool recreated = false;
const char* kind = "pbuffer";
if (state.Kind == SurfaceKind::Pbuffer) {
recreated = Server::ServerCreateEGLPbufferSurface(surface, state.Width, state.Height);
const Uint32 flags = m_standInSurfaces.count(surface) != 0 ? Server::kPbufferFlagSurfacelessStandIn : 0u;
recreated = Server::ServerCreateEGLPbufferSurface(surface, state.Width, state.Height, nullptr, flags);
} else if (ClientSession::IsServerOwnedWindowSurface(surface)) {
kind = "server-owned window";
const Server::ServerOwnedWindowReply reply =
@@ -108,6 +108,11 @@ namespace MobileGL::MG_Remote::Client {
// session are forgotten without a release (their server is gone).
void OnSessionReplaced();
// EGL_KHR_surfaceless_context's hidden pbuffer (EGLImpl's SurfacelessStandIn): an ordinary
// pbuffer on this side, created on the server with kPbufferFlagSurfacelessStandIn so it
// takes no surface mode there, and re-created the same way on a fresh session.
Bool CreateEGLSurfacelessStandIn(EGLSurface surface, EGLint width, EGLint height);
protected:
Bool InitPbufferSurface(EGLint width, EGLint height) override;
@@ -125,6 +130,7 @@ namespace MobileGL::MG_Remote::Client {
// The server side of `surface` on the CURRENT session: re-created from its client
// registration when the session that had it was replaced. True when it exists now.
Bool EnsureSurfaceHomed(EGLSurface surface);
Bool CreatePbufferOnServer(EGLSurface surface, EGLint width, EGLint height, Bool standIn);
void NoteHomed(EGLSurface surface) {
const std::lock_guard<std::recursive_mutex> lock(m_eglStateMutex);
m_homedSurfaces.insert(surface);
@@ -140,6 +146,8 @@ namespace MobileGL::MG_Remote::Client {
// nor presented to nor attached on the new server, which never issued it. Guarded by the
// base's m_eglStateMutex.
std::unordered_set<EGLSurface> m_homedSurfaces;
// The surfaceless stand-ins among this object's pbuffers. Guarded by m_eglStateMutex.
std::unordered_set<EGLSurface> m_standInSurfaces;
std::unordered_map<Uint64, Uint32> m_sessionSharedImages; // id -> references taken
// The ids a replaced session held: releasing one is a success with nothing sent.
std::unordered_set<Uint64> m_lostSessionSharedImages;
+16 -3
View File
@@ -1513,12 +1513,16 @@ namespace MobileGL::MG_Remote::Server {
static_cast<Uint32>(frame.width),
static_cast<Uint32>(frame.height));
return MOBILEGL_OK;
case SurfaceControlOp::CreatePbufferSurface:
case SurfaceControlOp::CreatePbufferSurface: {
// A surfaceless stand-in (kPbufferFlagSurfacelessStandIn) is no rendering path: it is
// admitted whatever the mode and latches none, so a client that binds surfacelessly
// before it creates its server-owned window still gets that window.
const Bool standIn = (frame.contextFlags & kPbufferFlagSurfacelessStandIn) != 0;
// P12 (D4): a pbuffer in a session that went on-screen is the other mode, refused by
// name and not latched - the session and its window surface carry on. P14 S2: the mode
// is the session's own - latched by its first surface, on its own loop - and never
// another session's.
if (!SessionSurfaceModeAdmits(m_surfaceMode, /*serverOwnedWindow=*/false)) {
if (!standIn && !SessionSurfaceModeAdmits(m_surfaceMode, /*serverOwnedWindow=*/false)) {
frame.ok = false;
frame.refusal = static_cast<Uint8>(SurfaceRefusalCode::SurfaceModeMismatch);
MGLOG_E("MG_Remote server: SurfaceModeMismatch - CreatePbufferSurface (seq %llu, %dx%d) in a "
@@ -1535,11 +1539,18 @@ namespace MobileGL::MG_Remote::Server {
// make-current that follows is forwarded and deduped one layer down (ID-54).
if (frame.ok) {
ForgetCurrentTuple();
if (standIn) {
MGLOG_I("MG_Remote server: surface=pbuffer %dx%d (surfaceless stand-in; the session's surface "
"mode stays %s)",
frame.width, frame.height, SessionSurfaceModeName(m_surfaceMode));
return MOBILEGL_OK;
}
if (m_surfaceMode == SessionSurfaceMode::None) m_surfaceMode = SessionSurfaceMode::Offscreen;
// P12: THE ARM PROOF (ID-124), once per surface: which of the two paths ran.
MGLOG_I("MG_Remote server: surface=pbuffer %dx%d", frame.width, frame.height);
}
return MOBILEGL_OK;
}
case SurfaceControlOp::MakeCurrent: {
// C7 / ID-54: the apply thread binds the native context ONCE per context lifetime
// and holds it for life. ApplyMakeCurrent forwards a bind only for a tuple it does
@@ -2133,12 +2144,14 @@ namespace MobileGL::MG_Remote::Server {
return rc == MOBILEGL_OK && frame.ok;
}
Bool ServerCreateEGLPbufferSurface(EGLSurface surface, EGLint width, EGLint height, SurfaceRefusalCode* refusal) {
Bool ServerCreateEGLPbufferSurface(EGLSurface surface, EGLint width, EGLint height, SurfaceRefusalCode* refusal,
Uint32 flags) {
SurfaceControlFrame frame;
frame.kind = SurfaceControlOp::CreatePbufferSurface;
frame.surface = TokenFromHandle(surface);
frame.width = width;
frame.height = height;
frame.contextFlags = flags;
const MobileGLResult rc = ServerLoopInstance().RunSurfaceControlFrame(frame);
if (refusal != nullptr) *refusal = static_cast<SurfaceRefusalCode>(frame.refusal);
return rc == MOBILEGL_OK && frame.ok;
+3 -2
View File
@@ -702,9 +702,10 @@ namespace MobileGL::MG_Remote::Server {
Bool ServerCreateEGLWindowSurface(EGLSurface surface, const MG_Backend::WindowHandle& handle);
Bool ServerResizeEGLWindowSurface(EGLSurface surface, Uint32 width, Uint32 height);
// P12: `refusal`, when given, receives the server's named refusal (SurfaceModeMismatch for a
// pbuffer in an on-screen session), None otherwise.
// pbuffer in an on-screen session), None otherwise. `flags`: kPbufferFlagSurfacelessStandIn
// for the hidden pbuffer of a surfaceless make-current, which takes no surface mode.
Bool ServerCreateEGLPbufferSurface(EGLSurface surface, EGLint width, EGLint height,
SurfaceRefusalCode* refusal = nullptr);
SurfaceRefusalCode* refusal = nullptr, Uint32 flags = 0);
// P12 (on-screen server window), D1/D2. CreateWindowSurface on the SERVER's window: one frame,
// WindowKind::ServerOwned with nativeToken 0 on the wire, no SetWindowHandle. `width`/`height`
// is the size the client asked for (0/0 = the server window's own size); the reply carries the
@@ -99,6 +99,15 @@ namespace MobileGL::MG_Remote::Server {
// substitutes its own window there; no pointer crosses the wire (Rule G/H).
inline constexpr Int kServerOwnedWindowBackend = 0x10000;
// CreatePbufferSurface's flags, in the frame's `contextFlags` word (the wire's SurfaceOp
// contextFlags, 0 on every op but CreateContext before this, so an older server reads none).
// SURFACELESS STAND-IN: the hidden 1x1 pbuffer a client binds the backend to for a surfaceless
// make-current (EGL_KHR_surfaceless_context). It is never presented or read back, so it is no
// rendering path: it neither latches the session's surface mode nor is refused by it (D4).
// Without it, a client that made a context current with no surface before it created its
// server-owned window latched its session offscreen, and the window was refused.
inline constexpr Uint32 kPbufferFlagSurfacelessStandIn = 1u;
// P12. Why the server declined a surface op, carried back in the reply half (`refusal`). The
// values ARE the wire's SurfaceRefusal (protocol.fbs); SurfaceOpCodec pins the agreement with
// static_asserts, the way it pins SurfaceControlOp against SurfaceOpKind. None of them latches
@@ -133,7 +142,8 @@ namespace MobileGL::MG_Remote::Server {
Int swapInterval = 0;
// P14 S1. CreateContext's two values beyond `context` (which is the client context token
// itself): the share group the context was derived into, and the reserved flags word the
// schema carries so a later attribute has a slot. 0 on every other op.
// schema carries so a later attribute has a slot. CreatePbufferSurface carries its own
// flags in the same word (kPbufferFlagSurfacelessStandIn). 0 on every other op.
Uint64 shareGroupToken = 0;
Uint32 contextFlags = 0;
// The reply half: written by the dispatch on the apply thread, read by the poster after