From 0f014790c92146e8575e39a4db9f92cf3a55fbff Mon Sep 17 00:00:00 2001 From: daiqingshuang Date: Mon, 24 Mar 2025 14:03:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DCPU=E5=8D=A0=E7=94=A8?= =?UTF-8?q?=E8=BF=87=E9=AB=98=EF=BC=8C=E5=85=A8=E5=B1=80=E7=BB=98=E5=88=B6?= =?UTF-8?q?=E8=84=8F=E6=A0=87=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mirage.cpp | 4 ++-- src/widget/mwidget.h | 3 +++ src/widget_tree/widget_system.cpp | 3 +++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/mirage.cpp b/src/mirage.cpp index 44f9ee3..fb8ee4f 100644 --- a/src/mirage.cpp +++ b/src/mirage.cpp @@ -53,8 +53,8 @@ void mirage_app::run() { widget_manager::get().update(); last_time = get_current_time(); - // std::this_thread::sleep_for(std::chrono::milliseconds(1)); - std::this_thread::yield(); + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + // std::this_thread::yield(); } running = false; render_context->cleanup(); diff --git a/src/widget/mwidget.h b/src/widget/mwidget.h index 3ecca57..dc23e61 100644 --- a/src/widget/mwidget.h +++ b/src/widget/mwidget.h @@ -57,6 +57,9 @@ public: void set_parent(const widget_key& in_parent); virtual void invalidate(invalidate_reason in_reason); + auto has_invalidate_reason(invalidate_reason in_reason) const { return get_component_ref().has(in_reason); } + void clear_invalidate_reason(invalidate_reason in_reason) { get_component_ref().unset(in_reason); } + auto get_invalidation_reason() const { return get_component_ref().invalidate; } auto is_enabled() const { return get_component_ref().is_enabled(); } diff --git a/src/widget_tree/widget_system.cpp b/src/widget_tree/widget_system.cpp index 1dfa225..a148e62 100644 --- a/src/widget_tree/widget_system.cpp +++ b/src/widget_tree/widget_system.cpp @@ -224,6 +224,8 @@ void widget_render_system::onUpdate(mustache::World& in_world) { return; if (!window->is_visible()) return; + if (!window->has_invalidate_reason(invalidate_reason::paint)) + return; auto& window_state = window->get_state(); @@ -248,6 +250,7 @@ void widget_render_system::onUpdate(mustache::World& in_world) { sg_commit(); window_state.present(); + window->clear_invalidate_reason(invalidate_reason::paint); } void widget_render_system::paint(const widget_key& in_key) {