[MG_Remote, MG_Impl, MG_State, Config] (P12): MOBILEGL_IPC_SURFACE=server - headless window surfaces (NULL accepted), one ServerOwned CreateWindowSurface and no SetWindowHandle, the server's geometry into the EGL state before the create returns, and every refusal named on the client

This commit is contained in:
2026-09-23 23:55:23 -04:00
parent 844b217661
commit d481393f8f
10 changed files with 627 additions and 3 deletions
@@ -16,6 +16,7 @@
#include "../Server/ServerLoop.h"
#include <MG_State/EGLState/Core.h>
#include <MG_Util/Debug/Log.h>
// Declared rather than included: MG_Backend/BackendObjects.h drags in both concrete backend
@@ -212,6 +213,8 @@ namespace MobileGL::MG_Remote::Client {
// The handle first: the server's backend has to know which window it is about to make
// a surface for, and ServerSetWindowHandle is the only way to tell it.
WaitForApplyBeforeEglForwarder("CreateEGLWindowSurface");
// P12 (D1): unless the window is the SERVER's - then there is no handle of ours to tell.
if (MG_Config::ServerOwnedWindowSurfaces()) return CreateServerOwnedWindowSurface(surface, handle);
Server::ServerSetWindowHandle(handle);
if (!Server::ServerCreateEGLWindowSurface(surface, handle)) return false;
// The server's surface init published the default framebuffer's shape as a
@@ -236,13 +239,96 @@ namespace MobileGL::MG_Remote::Client {
Bool BackendObject_Remote::CreateEGLPbufferSurface(EGLSurface surface, EGLint width, EGLint height) {
WaitForApplyBeforeEglForwarder("CreateEGLPbufferSurface");
if (!Server::ServerCreateEGLPbufferSurface(surface, width, height)) return false;
Server::SurfaceRefusalCode refusal = Server::SurfaceRefusalCode::None;
if (!Server::ServerCreateEGLPbufferSurface(surface, width, height, &refusal)) {
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 "
"whose surface mode is on-screen: its first surface was the server's own window "
"(MOBILEGL_IPC_SURFACE=server), and only one rendering path is active per session. "
"The server refused it; the session carries on",
width, height);
}
return false;
}
// Same drain as the window surface: InitPbufferSurface publishes the default
// framebuffer's depth/stencil format on SEG_EVENT from inside this very RPC.
if (ClientSession* session = ClientSession::Active()) session->DrainPublishedEvents();
return MG_Backend::BackendObject::CreateEGLPbufferSurface(surface, width, height);
}
namespace {
// THE CLIENT'S OWN RECORD OF A SERVER-OWNED WINDOW NEEDS A NON-NULL HANDLE, and a headless
// client has none: BackendObject::RegisterEGLWindowSurface refuses a null handle, and that
// base class is in the pull build (G1). This address stands in for it. It is never
// dereferenced - the client's InitWindowSurface is a no-op - and never crosses the wire
// (the ServerOwned frame carries token 0).
char g_serverOwnedWindowPlaceholder = 0;
} // namespace
Bool BackendObject_Remote::CreateServerOwnedWindowSurface(EGLSurface surface,
const MG_Backend::WindowHandle& handle) {
const Server::ServerOwnedWindowReply reply =
Server::ServerCreateServerOwnedWindowSurface(surface, handle.Width, handle.Height);
if (!reply.ok) {
// P12: FAILS BY NAME ON THIS SIDE TOO. The server logged its reason; the reply's refusal
// code is what lets this line say the same thing instead of "ok=false".
switch (reply.refusal) {
case Server::SurfaceRefusalCode::NoServerDisplay:
MGLOG_E("MG_Remote client: Refuse ServerOwned (NoServerDisplay) - MOBILEGL_IPC_SURFACE=server asked "
"the server to create this %ux%u window surface on its own window, and the server owns no "
"display: it is an offscreen server. eglCreateWindowSurface fails with "
"EGL_BAD_NATIVE_WINDOW; connect to the on-screen display server, or unset "
"MOBILEGL_IPC_SURFACE",
handle.Width, handle.Height);
break;
case Server::SurfaceRefusalCode::NoServerWindow:
MGLOG_E("MG_Remote client: Refuse ServerOwned (NoServerWindow) - the server owns a display but no "
"window came up for this %ux%u surface within its wait (is the display's surface visible?). "
"eglCreateWindowSurface fails with EGL_BAD_NATIVE_WINDOW",
handle.Width, handle.Height);
break;
case Server::SurfaceRefusalCode::SurfaceModeMismatch:
MGLOG_E("MG_Remote client: SurfaceModeMismatch - eglCreateWindowSurface on the server's window "
"(MOBILEGL_IPC_SURFACE=server) in a session whose surface mode is offscreen: its first "
"surface was a pbuffer, and only one rendering path is active per session. The server "
"refused it; the session carries on");
break;
default:
MGLOG_E("MG_Remote client: the server could not create the server-owned window surface "
"(MOBILEGL_IPC_SURFACE=server, %ux%u requested; channel rc=%d, refusal %s)",
handle.Width, handle.Height, static_cast<int>(reply.transport),
Server::SurfaceRefusalCodeName(reply.refusal));
break;
}
return false;
}
// D1: THE GEOMETRY FLOWS BACK BEFORE THIS RETURNS. The reply carries the server window's real
// extent, and it goes into the EGL state here, so eglQuerySurface(EGL_WIDTH/EGL_HEIGHT)
// answers the server's size the moment eglCreateWindowSurface returns - whatever the backend
// (Magma builds its swapchain, and publishes its extent, only at the first MakeCurrent). The
// session records the surface as the server-owned one, so every later surface-changed event
// that carries an extent (the window resized or rotated) resizes it too; then the same drain
// as the ordinary window path, for the default framebuffer's shape the server's surface init
// may have published from inside this very RPC.
if (MG_State::pEGLContext && reply.width != 0 && reply.height != 0) {
(void)MG_State::pEGLContext->SetSurfaceExtent(surface, static_cast<EGLint>(reply.width),
static_cast<EGLint>(reply.height));
}
if (ClientSession* session = ClientSession::Active()) {
session->NoteServerOwnedWindowSurface(surface, reply.width, reply.height);
session->DrainPublishedEvents();
}
MGLOG_I("MG_Remote client: surface=window %ux%u owner=server (MOBILEGL_IPC_SURFACE=server, %ux%u requested)",
reply.width, reply.height, handle.Width, handle.Height);
MG_Backend::WindowHandle local = handle;
if (local.Backend == MG_Backend::WindowBackend::Unknown) local.Backend = MG_Backend::WindowBackend::Android;
if (local.Handle == nullptr) local.Handle = &g_serverOwnedWindowPlaceholder;
local.Width = reply.width;
local.Height = reply.height;
return MG_Backend::BackendObject::CreateEGLWindowSurface(surface, local);
}
Bool BackendObject_Remote::MakeEGLCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read,
EGLContext ctx) {
// FORWARD FIRST, THEN RUN THE BASE. The server has to own the context before the base
@@ -298,6 +384,8 @@ namespace MobileGL::MG_Remote::Client {
}
void BackendObject_Remote::ReleaseEGLSurface(EGLSurface surface) {
// P12: a released server-owned surface stops taking the server window's geometry.
if (ClientSession* session = ClientSession::Active()) session->ForgetServerOwnedWindowSurface(surface);
Server::ServerReleaseEGLSurface(surface);
MG_Backend::BackendObject::ReleaseEGLSurface(surface);
}
@@ -88,6 +88,11 @@ namespace MobileGL::MG_Remote::Client {
Bool InitPbufferSurface(EGLint width, EGLint height) override;
private:
// P12 (on-screen server window), D1: MOBILEGL_IPC_SURFACE=server's arm of
// CreateEGLWindowSurface - ONE ServerOwned frame, no SetWindowHandle, the server's real
// geometry adopted before it returns, and every refusal named in this process's log.
Bool CreateServerOwnedWindowSurface(EGLSurface surface, const MG_Backend::WindowHandle& handle);
// The generation of the snapshot m_formatCapabilities was filled from. Exposed only
// through the log line on a refresh: a cache that silently stopped tracking the mirror
// is exactly the shape trap 2 exists to prevent.
@@ -28,6 +28,7 @@
#include <MG_Impl/GLImpl/Framebuffer/GL_Framebuffer.h>
#include <MG_Impl/Pipe/ResourceTracker.h>
#include <MG_Pipe/MGPipeCallbacks.h>
#include <MG_State/EGLState/Core.h>
#include <MG_State/GLState/Core.h>
#include <MG_State/GLState/ErrorState/ErrorInfo.h>
#include <MG_State/GLState/TextureState/TextureObject2D.h>
@@ -346,6 +347,24 @@ namespace MobileGL::MG_Remote::Client {
}
}
// P12 (on-screen server window), D1: the session's server-owned window surface - the
// client's EGL handle for it - or EGL_NO_SURFACE. Written on the GL thread by the surface
// RPCs (NoteServerOwnedWindowSurface / ForgetServerOwnedWindowSurface) and read by the
// drain, which runs on the same thread; atomic only because nothing else pins that.
std::atomic<EGLSurface> g_serverOwnedSurface{EGL_NO_SURFACE};
// An event's extent is the SERVER's surface size. For the server-owned window that is the
// size the client renders at, so the EGL state's record of the surface follows it:
// eglQuerySurface(EGL_WIDTH/EGL_HEIGHT) is what a headless client sizes its viewport from.
// A format-only event (Width/Height 0) says nothing about the size and changes nothing.
void ApplyServerOwnedSurfaceExtent(Uint32 width, Uint32 height) {
if (width == 0 || height == 0) return;
const EGLSurface surface = g_serverOwnedSurface.load(std::memory_order_acquire);
if (surface == EGL_NO_SURFACE || !MG_State::pEGLContext) return;
(void)MG_State::pEGLContext->SetSurfaceExtent(surface, static_cast<EGLint>(width),
static_cast<EGLint>(height));
}
Uint32 DrainEventRing(Transport::EventRingConsumer& events) {
if (!events.Valid()) return 0;
Uint32 delivered = 0;
@@ -416,6 +435,9 @@ namespace MobileGL::MG_Remote::Client {
info.Layers = head->Layers;
info.IsDefault = head->IsDefault;
ApplySurfaceChangedToClient(info);
// P12 (D1): and the server-owned window's EGL-state size, beside the
// default framebuffer's reallocation above.
ApplyServerOwnedSurfaceExtent(info.Width, info.Height);
++delivered;
break;
}
@@ -2445,6 +2467,16 @@ namespace MobileGL::MG_Remote::Client {
return DrainEventRing(*m_events);
}
void ClientSession::NoteServerOwnedWindowSurface(EGLSurface surface, Uint32 width, Uint32 height) {
g_serverOwnedSurface.store(surface, std::memory_order_release);
ApplyServerOwnedSurfaceExtent(width, height);
}
void ClientSession::ForgetServerOwnedWindowSurface(EGLSurface surface) {
EGLSurface expected = surface;
(void)g_serverOwnedSurface.compare_exchange_strong(expected, EGL_NO_SURFACE, std::memory_order_acq_rel);
}
Uint64 ClientSession::EventRingCapacityBytes() const { return m_link->Memory().EventRingCapacity(); }
Uint64 ClientSession::StageCapacityBytes() const { return m_link->Memory().StageBytes(); }
+11
View File
@@ -401,6 +401,17 @@ namespace MobileGL::MG_Remote::Client {
// blit-incompatible with the real thing.
Uint32 DrainPublishedEvents();
// P12 (on-screen server window), D1: THE GEOMETRY FLOWS BACK. `surface` (the client's EGL
// handle) is this session's server-owned window surface, `width`x`height` the server
// window's real extent from the CreateWindowSurface reply (0 = not known yet). The extent
// goes into the EGL state at once - eglQuerySurface answers it before eglCreateWindowSurface
// returns - and every later surface-changed event that carries an extent (the server window
// resized or rotated) is applied to the same surface, beside the default-framebuffer
// reallocation the drain already does. One surface at a time: the newest wins, and
// ForgetServerOwnedWindowSurface drops it when the client releases it.
void NoteServerOwnedWindowSurface(EGLSurface surface, Uint32 width, Uint32 height);
void ForgetServerOwnedWindowSurface(EGLSurface surface);
// SEG_EVENT's ring capacity, exposed so the readback path can slice a writeback
// request into records that always fit (RingProducer::MaxRecordBytes ==
// capacity/2, Ring.h:288).