diff --git a/gfx/ipc/GPUParent.cpp b/gfx/ipc/GPUParent.cpp index 43fc22babad6..102d2cc7a106 100644 --- a/gfx/ipc/GPUParent.cpp +++ b/gfx/ipc/GPUParent.cpp @@ -100,17 +100,17 @@ GPUParent* GPUParent::GetSingleton() { return sGPUParent; } -/* static */ void GPUParent::MaybeFlushMemory() { +/* static */ bool GPUParent::MaybeFlushMemory() { #if defined(XP_WIN) && !defined(HAVE_64BIT_BUILD) MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread()); if (!XRE_IsGPUProcess()) { - return; + return false; } MEMORYSTATUSEX stat; stat.dwLength = sizeof(stat); if (!GlobalMemoryStatusEx(&stat)) { - return; + return false; } // We only care about virtual process memory space in the GPU process because @@ -131,6 +131,9 @@ GPUParent* GPUParent::GetSingleton() { })); } sLowMemory = lowMemory; + return lowMemory; +#else + return false; #endif } diff --git a/gfx/ipc/GPUParent.h b/gfx/ipc/GPUParent.h index b2051a4cc481..27daf79af318 100644 --- a/gfx/ipc/GPUParent.h +++ b/gfx/ipc/GPUParent.h @@ -34,7 +34,7 @@ class GPUParent final : public PGPUParent { static void GetGPUProcessName(nsACString& aStr); // Check for memory pressure and notify the parent process if necessary. - static void MaybeFlushMemory(); + static bool MaybeFlushMemory(); bool Init(base::ProcessId aParentPid, const char* aParentBuildID, MessageLoop* aIOLoop, UniquePtr aChannel); diff --git a/gfx/layers/wr/WebRenderBridgeParent.cpp b/gfx/layers/wr/WebRenderBridgeParent.cpp index 7d2dde91a0a8..ea0e765b3c7f 100644 --- a/gfx/layers/wr/WebRenderBridgeParent.cpp +++ b/gfx/layers/wr/WebRenderBridgeParent.cpp @@ -485,8 +485,13 @@ bool WebRenderBridgeParent::UpdateResources( wr::ShmSegmentsReader reader(aSmallShmems, aLargeShmems); UniquePtr scheduleRelease; - if (!aResourceUpdates.IsEmpty()) { - GPUParent::MaybeFlushMemory(); + while (GPUParent::MaybeFlushMemory()) { + // If the GPU process has memory pressure, preemptively unmap some of our + // shared memory images. If we are in the parent process, the expiration + // tracker itself will listen for the memory pressure event. + if (!SharedSurfacesParent::AgeAndExpireOneGeneration()) { + break; + } } for (const auto& cmd : aResourceUpdates) {