From e8be8f7b6d700e60fd1f3e6438f8d4080ba205cc Mon Sep 17 00:00:00 2001 From: Tobias Christiansen Date: Wed, 16 Mar 2022 19:54:34 +0100 Subject: [PATCH] PixelPaint: Add Timer for displaying previews of filters This way the preview image is not generated on _every_ update_preview() call but rather only if the last update_preview() was longer than 100ms ago. When rapidly moving the Slider for large blur values in the FastBoxBlurFilter with the Gaussian approximation the usage became noticeably sliggush because we queued a lot of preview generation just to throw it away immediately. This patch fixes that. --- .../Applications/PixelPaint/Filters/Filter.cpp | 14 +++++++++++--- Userland/Applications/PixelPaint/Filters/Filter.h | 6 ++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Userland/Applications/PixelPaint/Filters/Filter.cpp b/Userland/Applications/PixelPaint/Filters/Filter.cpp index 4cd3c708eb..567ab10a5f 100644 --- a/Userland/Applications/PixelPaint/Filters/Filter.cpp +++ b/Userland/Applications/PixelPaint/Filters/Filter.cpp @@ -11,6 +11,16 @@ namespace PixelPaint { +Filter::Filter(ImageEditor* editor) + : m_editor(editor) + , m_update_timer(Core::Timer::create_single_shot(100, [&] { + if (on_settings_change) + on_settings_change(); + })) +{ + m_update_timer->set_active(false); +} + RefPtr Filter::get_settings_widget() { if (!m_settings_widget) { @@ -39,8 +49,6 @@ void Filter::apply() const void Filter::update_preview() { - if (on_settings_change) - on_settings_change(); + m_update_timer->restart(); } - } diff --git a/Userland/Applications/PixelPaint/Filters/Filter.h b/Userland/Applications/PixelPaint/Filters/Filter.h index 3d201a0282..cfb8f0e57b 100644 --- a/Userland/Applications/PixelPaint/Filters/Filter.h +++ b/Userland/Applications/PixelPaint/Filters/Filter.h @@ -24,8 +24,7 @@ public: virtual ~Filter() {}; - Filter(ImageEditor* editor) - : m_editor(editor) {}; + Filter(ImageEditor* editor); Function on_settings_change; @@ -33,6 +32,9 @@ protected: ImageEditor* m_editor { nullptr }; RefPtr m_settings_widget { nullptr }; void update_preview(); + +private: + NonnullRefPtr m_update_timer; }; }