Skip to content

Truly independent web browser

Compositor: Reclaim Skia resources after drawing stops

Shannon Boothd79050cb3857
diff --git a/Services/Compositor/SkiaBackendContext.cpp b/Services/Compositor/SkiaBackendContext.cpp
index 740b1037138..ac1a0e414f7 100644
--- a/Services/Compositor/SkiaBackendContext.cpp
+++ b/Services/Compositor/SkiaBackendContext.cpp
@@ -54,6 +54,7 @@ static constexpr size_t skia_resource_cache_limit = 256 * MiB;
static constexpr auto skia_deferred_cleanup_interval = AK::Duration::from_seconds(1);
static constexpr auto skia_aggressive_cleanup_interval = AK::Duration::from_seconds(5);
static constexpr auto skia_deferred_cleanup_resource_age = std::chrono::seconds(5);
+static constexpr auto skia_idle_cleanup_delay = AK::Duration::from_seconds(6);
static constexpr auto skia_resource_cache_high_watermark = 384 * MiB;
static constexpr auto skia_resource_cache_critical_watermark = 512 * MiB;
@@ -149,6 +150,15 @@ void SkiaBackendContext::perform_post_flush_cleanup()
s_last_deferred_cleanup = now;
context->performDeferredCleanup(skia_deferred_cleanup_resource_age);
+ if (!m_idle_cleanup_timer) {
+ m_idle_cleanup_timer = Core::Timer::create_single_shot(skia_idle_cleanup_delay, [this] {
+ auto& context = *sk_context();
+ context.checkAsyncWorkCompletion();
+ context.purgeUnlockedResources(GrPurgeResourceOptions::kAllResources);
+ });
+ }
+ m_idle_cleanup_timer->restart();
+
size_t resource_bytes = 0;
context->getResourceCacheUsage(nullptr, &resource_bytes);
if (resource_bytes < skia_resource_cache_high_watermark)
diff --git a/Services/Compositor/SkiaBackendContext.h b/Services/Compositor/SkiaBackendContext.h
index 8a93975a4a7..2ab6318b038 100644
--- a/Services/Compositor/SkiaBackendContext.h
+++ b/Services/Compositor/SkiaBackendContext.h
@@ -10,6 +10,7 @@
#include <AK/Function.h>
#include <AK/Noncopyable.h>
#include <AK/Optional.h>
+#include <LibCore/Timer.h>
#include <LibGfx/GpuDeviceIdentity.h>
#ifdef USE_DIRECTX
@@ -71,6 +72,8 @@ public:
private:
void perform_post_flush_cleanup();
+
+ RefPtr<Core::Timer> m_idle_cleanup_timer;
};
}