[Feature] (disaggregated): MOBILEGL_IPC_SURFACE=host - the display host owns the screen and the frames

The third on-screen shape, and the one this whole line was built toward: Anland keeps Wayland,
input and the display, and the render server draws into the frames the display host allocates.

    client (container)      asks for a window surface with no window of its own
    server (Android)        takes a frame from the host over the host frame bridge and binds it as
                            the draw target of that surface
    host (the app that
    owns the screen)        offers each frame, presents it when the server says it is drawn

The pieces, in the order a frame travels:

 - Config: MOBILEGL_IPC_SURFACE=host beside =server, and HostFrameWindowSurfaces() as the one
   predicate every client-side consumer asks (EGLImpl accepts a NULL window for either on-screen
   shape, and BackendObject_Remote routes the creation to the server instead of sending a handle).
 - Wire: the frame-local tag kHostFrameWindowBackend, the mirror of kServerOwnedWindowBackend - it
   names no WindowBackend of the pull build's enum, and the server consumes it before the unpack
   that would refuse it.
 - Server: ApplyHostFrameWindowSurface replaces nothing, unlike the server-owned arm: there is no
   window of either side's to substitute, because the backend takes the frames from the bridge.
 - Backend: SurfaceKind::HostFrame, InitHostFrameSurface (the EGL context comes from the pbuffer
   path; what changes is what it draws INTO) and PresentHostFrame (glFinish, answer the host, take
   the next frame) - and SwapEGLBuffers routes to it, because a host-framed surface has no
   swapchain to swap: the host is what puts the frame on the glass.

HostFrameTarget and HostFrameBridge, committed just before this, are what the backend uses.

Compiles and links in this tree (libMobileGL.so and libMobileGLServer.so, exit 0).  What is NOT
here yet, and is the next thing: the run that puts Plasma on the phone's screen through it.
This commit is contained in:
gold
2026-10-01 01:11:21 +08:00
parent c7ab618ab0
commit 035f1b07ae
14 changed files with 298 additions and 30 deletions
@@ -216,6 +216,10 @@ namespace MobileGL::MG_Remote::Client {
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);
// The other on-screen shape: the frames belong to the display host, and the server takes
// them from the bridge. As for the server-owned shape, no window of the client's crosses
// the wire - only the size it asked for.
if (MG_Config::HostFrameWindowSurfaces()) return CreateHostFrameWindowSurface(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
@@ -295,6 +299,10 @@ namespace MobileGL::MG_Remote::Client {
// dereferenced - the client's InitWindowSurface is a no-op - and never crosses the wire
// (the ServerOwned frame carries token 0).
char g_serverOwnedWindowPlaceholder = 0;
// The host-framed shape names no window of the client's either; the base class still wants
// a handle to register the surface with, and this is the same stand-in the server-owned
// shape uses.
char g_hostFrameWindowPlaceholder = 0;
} // namespace
Bool BackendObject_Remote::CreateServerOwnedWindowSurface(EGLSurface surface,
@@ -360,6 +368,46 @@ namespace MobileGL::MG_Remote::Client {
return MG_Backend::BackendObject::CreateEGLWindowSurface(surface, local);
}
Bool BackendObject_Remote::CreateHostFrameWindowSurface(EGLSurface surface,
const MG_Backend::WindowHandle& handle) {
// The size crosses the wire and nothing else of the client's does: the server takes frames
// from the display host at that size and answers with the extent the surface has.
const Server::ServerOwnedWindowReply reply =
Server::ServerCreateHostFrameWindowSurface(surface, handle.Width, handle.Height);
if (!reply.ok) {
// FAILS BY NAME ON THIS SIDE TOO, as the server-owned shape does: the server logged its
// reason, and the refusal code is what lets this line say the same thing.
switch (reply.refusal) {
case Server::SurfaceRefusalCode::SurfaceModeMismatch:
MGLOG_E("MG_Remote client: Refuse HostFrame (SurfaceModeMismatch) - MOBILEGL_IPC_SURFACE=host "
"asked for this %ux%u window surface in a session that already chose a pbuffer: only "
"one rendering path is active per session. eglCreateWindowSurface fails with "
"EGL_BAD_NATIVE_WINDOW",
handle.Width, handle.Height);
break;
case Server::SurfaceRefusalCode::NoServerWindow:
MGLOG_E("MG_Remote client: Refuse HostFrame (NoServerWindow) - the server could not take a frame "
"from the display host for this %ux%u surface; its log names what the host or the "
"bridge said (its own answer was %ux%u)",
handle.Width, handle.Height, reply.width, reply.height);
break;
default:
MGLOG_E("MG_Remote client: Refuse HostFrame (code %u) for this %ux%u window surface",
static_cast<Uint>(reply.refusal), handle.Width, handle.Height);
break;
}
return false;
}
// From here the frames are the server's and the host's business; this side only registers the
// surface, exactly as it does for the server-owned shape.
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_hostFrameWindowPlaceholder;
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
@@ -91,6 +91,9 @@ namespace MobileGL::MG_Remote::Client {
// 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);
// MOBILEGL_IPC_SURFACE=host: the frames are the display host's, and the server takes
// them from the host frame bridge. Nothing of the client's crosses the wire here either.
Bool CreateHostFrameWindowSurface(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
+69
View File
@@ -287,6 +287,7 @@ namespace MobileGL::MG_Remote::Server {
m_surfaceMode = SessionSurfaceMode::None;
m_holdsWindowLease = false;
m_serverOwnedSurfaces.clear();
m_hostFrameSurfaces.clear();
m_windowLostRequested.store(false, std::memory_order_release);
m_serverWindowsLost.store(0, std::memory_order_release);
m_testLogFloodLines = ApplyLogFloodLinesForTest();
@@ -1338,6 +1339,8 @@ namespace MobileGL::MG_Remote::Server {
// P12 (D3): the SERVER's window, asked for by a headless client. Before the unpack,
// which would refuse the frame-local tag as a WindowBackend out of range.
if (frame.windowBackend == kServerOwnedWindowBackend) return ApplyServerOwnedWindowSurface(backend, frame);
// The mirror image: the frames are the display host's, and it presents them.
if (frame.windowBackend == kHostFrameWindowBackend) return ApplyHostFrameWindowSurface(backend, frame);
MG_Backend::WindowHandle window;
if (!UnpackWindowHandle(frame, &window)) {
frame.ok = false;
@@ -1445,6 +1448,7 @@ namespace MobileGL::MG_Remote::Server {
const EGLSurface surface = HandleFromToken<EGLSurface>(frame.surface);
backend->ReleaseEGLSurface(surface);
ForgetServerOwnedSurface(surface);
ForgetHostFrameSurface(surface);
// N-3: a released surface the held tuple names may have taken the context with it
// (BackendObject::ReleaseEGLSurface -> OnEGLSurfaceReleased -> DestroyEGLContext once
// nothing holds it current). Forgetting when the base class only DEFERRED the destroy
@@ -1658,6 +1662,52 @@ namespace MobileGL::MG_Remote::Server {
return MOBILEGL_OK;
}
MobileGLResult ServerLoop::ApplyHostFrameWindowSurface(MG_Backend::BackendObject* backend,
SurfaceControlFrame& frame) {
frame.ok = false;
frame.refusal = static_cast<Uint8>(SurfaceRefusalCode::None);
const Uint32 wantWidth = frame.width > 0 ? static_cast<Uint32>(frame.width) : 0u;
const Uint32 wantHeight = frame.height > 0 ? static_cast<Uint32>(frame.height) : 0u;
// Both on-screen shapes are the same session mode: one rendering path per session, and
// this is the on-screen one whichever side owns the window.
if (!SessionSurfaceModeAdmits(m_surfaceMode, /*serverOwnedWindow=*/true)) {
frame.refusal = static_cast<Uint8>(SurfaceRefusalCode::SurfaceModeMismatch);
MGLOG_E("MG_Remote server: SurfaceModeMismatch - a HostFrame CreateWindowSurface (seq %llu, "
"%ux%u) in a session whose surface mode is %s. Refused, the session is not latched",
static_cast<unsigned long long>(frame.seq), wantWidth, wantHeight,
SessionSurfaceModeName(m_surfaceMode));
return MOBILEGL_ERR_INVALID_ARGUMENT;
}
const EGLSurface surface = HandleFromToken<EGLSurface>(frame.surface);
// THE SUBSTITUTION, the other way round from ServerOwned: nothing of the client's and
// nothing of the server's goes into the backend call - the backend takes the frames from
// the display host, and every swap hands the next one back to it.
frame.ok = backend->CreateEGLHostFrameSurface(surface, wantWidth, wantHeight);
if (!frame.ok) {
MGLOG_E("MG_Remote server: the backend could not take the display host frames (seq %llu, %ux%u)",
static_cast<unsigned long long>(frame.seq), wantWidth, wantHeight);
return MOBILEGL_OK;
}
ForgetCurrentTuple();
m_surfaceMode = SessionSurfaceMode::OnScreen;
if (!IsHostFrameSurface(surface)) m_hostFrameSurfaces.push_back(surface);
frame.width = static_cast<Int>(wantWidth);
frame.height = static_cast<Int>(wantHeight);
MGLOG_I("MG_Remote server: surface=window %ux%u owner=host (HostFrame seq %llu)", wantWidth,
wantHeight, static_cast<unsigned long long>(frame.seq));
return MOBILEGL_OK;
}
Bool ServerLoop::IsHostFrameSurface(EGLSurface surface) const {
return std::find(m_hostFrameSurfaces.begin(), m_hostFrameSurfaces.end(), surface) !=
m_hostFrameSurfaces.end();
}
void ServerLoop::ForgetHostFrameSurface(EGLSurface surface) {
m_hostFrameSurfaces.erase(std::remove(m_hostFrameSurfaces.begin(), m_hostFrameSurfaces.end(), surface),
m_hostFrameSurfaces.end());
}
Bool ServerLoop::IsServerOwnedSurface(EGLSurface surface) const {
return std::find(m_serverOwnedSurfaces.begin(), m_serverOwnedSurfaces.end(), surface) !=
m_serverOwnedSurfaces.end();
@@ -1770,6 +1820,25 @@ namespace MobileGL::MG_Remote::Server {
return rc == MOBILEGL_OK && frame.ok;
}
ServerOwnedWindowReply ServerCreateHostFrameWindowSurface(EGLSurface surface, Uint32 width, Uint32 height) {
// One frame, and no SetWindowHandle in front of it: the client names no window, and this
// side does not make one - the frames are the display host's, taken from the bridge.
SurfaceControlFrame frame;
frame.kind = SurfaceControlOp::CreateWindowSurface;
frame.surface = TokenFromHandle(surface);
frame.windowBackend = kHostFrameWindowBackend;
frame.nativeToken = 0;
frame.width = static_cast<Int>(width);
frame.height = static_cast<Int>(height);
const MobileGLResult rc = ServerLoopInstance().RunSurfaceControlFrame(frame);
ServerOwnedWindowReply reply;
reply.transport = rc;
reply.ok = rc == MOBILEGL_OK && frame.ok;
reply.refusal = static_cast<SurfaceRefusalCode>(frame.refusal);
reply.width = frame.width > 0 ? static_cast<Uint32>(frame.width) : 0u;
reply.height = frame.height > 0 ? static_cast<Uint32>(frame.height) : 0u;
return reply;
}
ServerOwnedWindowReply ServerCreateServerOwnedWindowSurface(EGLSurface surface, Uint32 width, Uint32 height) {
// P12 (D1/D2): ONE frame, and no SetWindowHandle in front of it - the window is the
// server's, so there is nothing of the client's to name. The frame-local tag is what the
+11
View File
@@ -459,6 +459,9 @@ namespace MobileGL::MG_Remote::Server {
// P12. The ServerOwned arm of the CreateWindowSurface dispatch (D3, D4).
MobileGLResult ApplyServerOwnedWindowSurface(MG_Backend::BackendObject* backend, SurfaceControlFrame& frame);
MobileGLResult ApplyHostFrameWindowSurface(MG_Backend::BackendObject* backend, SurfaceControlFrame& frame);
Bool IsHostFrameSurface(EGLSurface surface) const;
void ForgetHostFrameSurface(EGLSurface surface);
// P12 (D6), apply thread: the lost window's backend surface goes, the lease ends, and the
// session latches ServerWindowLost. Runs from PumpControlRequest when Detach asked.
void ReleaseLostServerWindow();
@@ -471,6 +474,10 @@ namespace MobileGL::MG_Remote::Server {
void ForgetServerOwnedSurface(EGLSurface surface);
// Apply thread only: this session's surfaces created on the server's window; reset by Start().
std::vector<EGLSurface> m_serverOwnedSurfaces;
// The surfaces whose drawing target is a frame the display host owns. Kept apart from
// the server-owned list because the two are different paths with different owners,
// and a resize or a release has to reach the right one.
std::vector<EGLSurface> m_hostFrameSurfaces;
// ServerDisplay's lost hook: called under the display's lock from Detach's thread. Sets the
// request and rings the apply thread's bell; never blocks.
static void ServerWindowLostThunk(void* self);
@@ -659,6 +666,10 @@ namespace MobileGL::MG_Remote::Server {
Uint32 height = 0;
};
ServerOwnedWindowReply ServerCreateServerOwnedWindowSurface(EGLSurface surface, Uint32 width, Uint32 height);
// The host-framed on-screen shape (MOBILEGL_IPC_SURFACE=host): the client names no window
// either, but the frames come from the display host over the host frame bridge, and the
// host presents them. The reply carries the size the surface was made at.
ServerOwnedWindowReply ServerCreateHostFrameWindowSurface(EGLSurface surface, Uint32 width, Uint32 height);
// P12 review fix: ResizeWindowSurface for a surface created on the server's window. The server
// resizes its WINDOW (a geometry request) and replies with the window's real extent.
ServerOwnedWindowReply ServerResizeServerOwnedWindowSurface(EGLSurface surface, Uint32 width, Uint32 height);
@@ -87,6 +87,14 @@ namespace MobileGL::MG_Remote::Server {
// substitutes its own window there; no pointer crosses the wire (Rule G/H).
inline constexpr Int kServerOwnedWindowBackend = 0x10000;
// The OTHER on-screen shape, and its mirror image. With MOBILEGL_IPC_SURFACE=server the
// client has no window and the SERVER's own goes into the backend call; with =host the
// client still has no window, but the frames are the display host's - it allocates them,
// offers each one over the host frame bridge, and puts them on the glass itself. Same
// kind of frame-local tag as the one above, and for the same reason: it names no
// WindowBackend of MG_Backend's enum, which is in the pull build (gate G1).
inline constexpr Int kHostFrameWindowBackend = 0x10001;
// 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