mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-11-20 08:21:56 +09:00
[Refactor] (MG_Backend, MG_Backend/DirectGLES, MG_Backend/DirectVulkan, MG_Impl, MG_Impl/EGLImpl, MG_Impl/GLImpl, MG_Impl/GLXImpl, MG_Pipe, MG_Remote/Client, MG_Remote/Server, MG_Test/Wire): split the server-only and client-only hooks out of BackendObject
- ServerHooks and ClientHooks (BackendRoles.h) hold the virtuals that only the server, or only a client of a remote server, calls, with the defaults they had; BackendObject::AsServer and AsClient return them, or null for a backend without the role - DirectGLES and DirectVulkan implement ServerHooks, BackendObject_Remote implements ClientHooks, and the test doubles that run as a server's backend take the server role - every call site keeps its answer: where no backend and a backend without the role answered differently, the backend check stays and the role check gives the old default - ServerLoop::BackendHooks is the server's accessor, asked at each use - comments that placed the function table in BackendObject.h name BackendFunctions.h
This commit is contained in:
@@ -509,45 +509,45 @@ namespace MobileGL::MG_Remote::Server {
|
||||
return holder.Release(op.ImageId);
|
||||
case MG_Pipe::kMGPSharedImagePresent: {
|
||||
SI::ImageRef image = holder.Get(op.ImageId);
|
||||
MG_Backend::BackendObject* backend = ServerLoopInstance().Backend();
|
||||
if (image == nullptr || backend == nullptr) return false;
|
||||
MG_Backend::ServerHooks* server = ServerLoopInstance().BackendHooks();
|
||||
if (image == nullptr || server == nullptr) return false;
|
||||
MG_Backend::SharedImageView view;
|
||||
view.Id = image->Id;
|
||||
view.Width = image->Width;
|
||||
view.Height = image->Height;
|
||||
view.Fourcc = image->Fourcc;
|
||||
view.NativeBuffer = image->Native;
|
||||
if (!backend->BlitDefaultFramebufferToSharedImage(view, DamageOfRecord(op.DamageCount, op.Damage)))
|
||||
if (!server->BlitDefaultFramebufferToSharedImage(view, DamageOfRecord(op.DamageCount, op.Damage)))
|
||||
return false;
|
||||
fill(*image);
|
||||
return true;
|
||||
}
|
||||
case MG_Pipe::kMGPSharedImageQueryBufferAge: {
|
||||
MG_Backend::BackendObject* backend = ServerLoopInstance().Backend();
|
||||
if (backend == nullptr) return false;
|
||||
MG_Backend::ServerHooks* server = ServerLoopInstance().BackendHooks();
|
||||
if (server == nullptr) return false;
|
||||
reply.BufferAge =
|
||||
backend->QueryCurrentBufferAge((op.Format & MG_Pipe::kMGPBufferAgeDamageRegionFollows) != 0);
|
||||
server->QueryCurrentBufferAge((op.Format & MG_Pipe::kMGPBufferAgeDamageRegionFollows) != 0);
|
||||
return true;
|
||||
}
|
||||
case MG_Pipe::kMGPSharedImageSetDamageRegion: {
|
||||
MG_Backend::BackendObject* backend = ServerLoopInstance().Backend();
|
||||
if (backend == nullptr) return false;
|
||||
return backend->SetCurrentDamageRegion(DamageOfRecord(op.DamageCount, op.Damage));
|
||||
MG_Backend::ServerHooks* server = ServerLoopInstance().BackendHooks();
|
||||
if (server == nullptr) return false;
|
||||
return server->SetCurrentDamageRegion(DamageOfRecord(op.DamageCount, op.Damage));
|
||||
}
|
||||
case MG_Pipe::kMGPSharedImageFlush: {
|
||||
// The answer is posted after the fence is published: the client commits the buffer to
|
||||
// its compositor only after this returns, so the compositor's session finds the write.
|
||||
MG_Backend::BackendObject* backend = ServerLoopInstance().Backend();
|
||||
if (backend == nullptr) return false;
|
||||
return backend->PublishSharedImageAccesses();
|
||||
MG_Backend::ServerHooks* server = ServerLoopInstance().BackendHooks();
|
||||
if (server == nullptr) return false;
|
||||
return server->PublishSharedImageAccesses();
|
||||
}
|
||||
case MG_Pipe::kMGPSharedImageNativeFence: {
|
||||
// A descriptor of the session's work, and an image writer's flush (MGPipeTypes.h). Like
|
||||
// an Allocate's, the descriptor goes out BEFORE the reply is posted.
|
||||
MG_Backend::BackendObject* backend = ServerLoopInstance().Backend();
|
||||
if (backend == nullptr) return false;
|
||||
MG_Backend::ServerHooks* server = ServerLoopInstance().BackendHooks();
|
||||
if (server == nullptr) return false;
|
||||
int fence = -1;
|
||||
if (!backend->ExportNativeFence(&fence)) return false;
|
||||
if (!server->ExportNativeFence(&fence)) return false;
|
||||
#if !defined(_WIN32)
|
||||
if (fence >= 0) {
|
||||
m_lastNativeFence.Reset(::dup(fence));
|
||||
@@ -626,8 +626,8 @@ namespace MobileGL::MG_Remote::Server {
|
||||
if (MG_Config::Transport != MG_Config::TransportMode::Monolith) {
|
||||
(void)MG_Backend::DirectGLES::MakeNativeContextCurrentForBoundToken();
|
||||
// The backend half for one that keeps a single native surface binding (Magma).
|
||||
if (MG_Backend::BackendObject* backend = ServerLoopInstance().Backend()) {
|
||||
backend->OnClientContextBound(bind.ClientContextToken);
|
||||
if (MG_Backend::ServerHooks* server = ServerLoopInstance().BackendHooks()) {
|
||||
server->OnClientContextBound(bind.ClientContextToken);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -767,7 +767,7 @@ namespace MobileGL::MG_Remote::Server {
|
||||
// Clear -> Clear, DrawVbo -> DrawArrays, ReadPixels -> ReadPixels, Blit -> BlitFramebuffer.
|
||||
//
|
||||
// PRESENT IS DELIBERATELY NOT ONE, although contract 7 puts it in class B: Present and
|
||||
// SetSwapInterval sit outside GLFunctionsTable (BackendObject.h) and read no frontend state,
|
||||
// SetSwapInterval sit outside GLFunctionsTable (BackendFunctions.h) and read no frontend state,
|
||||
// so FillPoints.def's MGP_FILL_VERB_LIST has no row for them. There is no MGPipeVerb::Present,
|
||||
// and stamping there would retire the previous verb's answers with nothing to put in their place.
|
||||
void PipeApplier::StampVerbBoundary(MG_Pipe::MGPWireOp op) {
|
||||
|
||||
@@ -393,6 +393,10 @@ namespace MobileGL::MG_Remote::Server {
|
||||
return m_backend.get();
|
||||
}
|
||||
|
||||
MG_Backend::ServerHooks* ServerLoop::BackendHooks() {
|
||||
return MG_Backend::ServerHooksOf(m_backend.get());
|
||||
}
|
||||
|
||||
MobileGLResult ServerLoop::InstallBackendForTesting(UniquePtr<MG_Backend::BackendObject> backend) {
|
||||
if (m_backend != nullptr || backend == nullptr || m_running.load(std::memory_order_acquire)) {
|
||||
return MOBILEGL_ERR_INVALID_ARGUMENT;
|
||||
@@ -644,9 +648,9 @@ namespace MobileGL::MG_Remote::Server {
|
||||
session.PeerSharedSegments() ? "shared segments" : "stream", policy.rule);
|
||||
|
||||
// A served session shares its process with other sessions: its backend's own native state
|
||||
// is bound to this thread before anything can apply a record (BackendObject.h). The inproc
|
||||
// is bound to this thread before anything can apply a record (BackendRoles.h). The inproc
|
||||
// one-process shape has no runtime and keeps the process-wide state.
|
||||
if (m_runtime != nullptr && m_backend != nullptr) m_backend->BindSessionStateToThisThread();
|
||||
if (m_runtime != nullptr && BackendHooks() != nullptr) BackendHooks()->BindSessionStateToThisThread();
|
||||
|
||||
// The decoder is built HERE, on this thread, because PipeWireDecoder is "not thread
|
||||
// safe: one decoder on the apply thread, by construction" and its constructor installs
|
||||
@@ -722,9 +726,9 @@ namespace MobileGL::MG_Remote::Server {
|
||||
// The head is loaded BEFORE the poll, so every record below it was in the ring when the
|
||||
// poll ran and the drain need not poll for it again (DrainRing's `polledHead`).
|
||||
std::uint64_t polledHead = 0;
|
||||
if (m_backend != nullptr && !SessionLatched()) {
|
||||
if (BackendHooks() != nullptr && !SessionLatched()) {
|
||||
polledHead = signals.CmdHead != nullptr ? signals.CmdHead->load(std::memory_order_acquire) : 0;
|
||||
(void)m_backend->LatchIfGpuFaulted();
|
||||
(void)BackendHooks()->LatchIfGpuFaulted();
|
||||
}
|
||||
if (eventRingHasRoom()) DrainRing(polledHead);
|
||||
if (stopOrForfeit()) break;
|
||||
@@ -1141,7 +1145,8 @@ namespace MobileGL::MG_Remote::Server {
|
||||
record.kind == static_cast<std::uint16_t>(MG_Pipe::MGPWireOp::Present)) {
|
||||
if (unseen) polledHead = signals.CmdHead->load(std::memory_order_acquire);
|
||||
recordsSinceFaultCheck = 0;
|
||||
if (m_backend->LatchIfGpuFaulted()) return false;
|
||||
MG_Backend::ServerHooks* server = BackendHooks();
|
||||
if (server != nullptr && server->LatchIfGpuFaulted()) return false;
|
||||
}
|
||||
}
|
||||
if (SessionLatched()) return false;
|
||||
@@ -2185,7 +2190,7 @@ namespace MobileGL::MG_Remote::Server {
|
||||
}
|
||||
|
||||
void ServerLoop::PublishServerWindowResize() {
|
||||
if (!m_holdsWindowLease || m_backend == nullptr) return;
|
||||
if (!m_holdsWindowLease || BackendHooks() == nullptr) return;
|
||||
// THE DISPLAY'S EXTENT, READ NOW: the latest report wins over any a burst of them left queued.
|
||||
void* window = nullptr;
|
||||
Uint32 width = 0;
|
||||
@@ -2197,7 +2202,7 @@ namespace MobileGL::MG_Remote::Server {
|
||||
const Uint32 previousWidth = m_publishedWindowWidth;
|
||||
const Uint32 previousHeight = m_publishedWindowHeight;
|
||||
NoteServerWindowExtent(window, width, height);
|
||||
const Bool published = m_backend->ServerWindowResized(window, width, height);
|
||||
const Bool published = BackendHooks()->ServerWindowResized(window, width, height);
|
||||
if (published) m_serverWindowResizes.fetch_add(1, std::memory_order_acq_rel);
|
||||
MGLOG_I("MG_Remote server: server window %p resized %ux%u -> %ux%u; %s", window, previousWidth, previousHeight,
|
||||
width, height,
|
||||
@@ -2228,7 +2233,7 @@ namespace MobileGL::MG_Remote::Server {
|
||||
// window surfaces, Magma the swapchain and VkSurfaceKHR - keeps its contexts, objects and
|
||||
// device, and the session waits for the display's next window with every record still applied.
|
||||
void* const window = m_leasedWindow;
|
||||
if (m_backend != nullptr && m_backend->SuspendServerWindow(window)) {
|
||||
if (BackendHooks() != nullptr && BackendHooks()->SuspendServerWindow(window)) {
|
||||
// N-3: the native binding moved off the window's surface.
|
||||
ForgetCurrentTuple();
|
||||
m_serverWindowSuspended.store(true, std::memory_order_release);
|
||||
@@ -2277,7 +2282,7 @@ namespace MobileGL::MG_Remote::Server {
|
||||
Bool ServerLoop::ResumeServerWindowOnLease(const ServerWindowLease& lease) {
|
||||
// Before the backend: its republished extent is the server window's (MGPipeServerOwnedWindow).
|
||||
NoteServerWindowExtent(lease.window, lease.width, lease.height);
|
||||
if (m_backend == nullptr || !m_backend->ResumeServerWindow(lease.window, lease.width, lease.height)) {
|
||||
if (BackendHooks() == nullptr || !BackendHooks()->ResumeServerWindow(lease.window, lease.width, lease.height)) {
|
||||
LatchServerWindowLost("the suspended on-screen session's surfaces could not be rebuilt on the new server "
|
||||
"window");
|
||||
return false;
|
||||
|
||||
@@ -111,6 +111,9 @@ namespace MobileGL::MG_Remote::Server {
|
||||
// lookups - take the format cache as a parameter instead. That is six functions across
|
||||
// two files, and it is why no thread-keyed shim is needed for MOBILEGL_BUILD_DISAGGREGATED_INPROC.
|
||||
MG_Backend::BackendObject* Backend();
|
||||
// Its server hooks (BackendRoles.h); null with no backend. Asked at each use, never kept: a
|
||||
// test may swap the backend under a running apply thread.
|
||||
MG_Backend::ServerHooks* BackendHooks();
|
||||
|
||||
// Runs one blocking control request on the apply thread and waits for it; every Server*
|
||||
// EGL forwarder funnels through here. Blocking rather than async, because each caller
|
||||
|
||||
Reference in New Issue
Block a user