From c644a8d4f7053085483cc7de644597895d3f339b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Tue, 23 May 2017 11:09:12 +0200 Subject: [PATCH] [escher] Fix bug: do not redraw window at each timer fire but only for timer requiring redraw Change-Id: Ia39a35185a4836809970f5ba77cc76a8b2e6ee26 --- apps/apps_container.cpp | 11 +++++++---- apps/apps_container.h | 2 +- apps/backlight_dimming_timer.cpp | 3 ++- apps/backlight_dimming_timer.h | 2 +- apps/battery_timer.cpp | 5 +++-- apps/battery_timer.h | 2 +- apps/led_timer.cpp | 3 ++- apps/led_timer.h | 2 +- apps/on_boarding/logo_controller.cpp | 3 ++- apps/on_boarding/logo_controller.h | 2 +- apps/suspend_timer.cpp | 3 ++- apps/suspend_timer.h | 2 +- apps/usb_timer.cpp | 5 ++++- apps/usb_timer.h | 2 +- escher/Makefile | 1 - escher/include/escher.h | 1 - escher/include/escher/invocation_timer.h | 15 --------------- escher/include/escher/timer.h | 2 +- escher/src/container.cpp | 2 +- escher/src/invocation_timer.cpp | 11 ----------- escher/src/run_loop.cpp | 2 +- escher/src/timer.cpp | 4 ++-- ion/include/ion/events.h | 2 +- 23 files changed, 35 insertions(+), 52 deletions(-) delete mode 100644 escher/include/escher/invocation_timer.h delete mode 100644 escher/src/invocation_timer.cpp diff --git a/apps/apps_container.cpp b/apps/apps_container.cpp index 053915c01..b0896a2e6 100644 --- a/apps/apps_container.cpp +++ b/apps/apps_container.cpp @@ -151,10 +151,13 @@ void AppsContainer::switchTo(App::Snapshot * snapshot) { } } -void AppsContainer::updateBatteryState() { - m_window.updateBatteryLevel(); - m_window.updateIsChargingState(); - m_window.updatePluggedState(); +bool AppsContainer::updateBatteryState() { + if (m_window.updateBatteryLevel() || + m_window.updateIsChargingState() || + m_window.updatePluggedState()) { + return true; + } + return false; } void AppsContainer::refreshPreferences() { diff --git a/apps/apps_container.h b/apps/apps_container.h index 6ea3d70b5..12119b50e 100644 --- a/apps/apps_container.h +++ b/apps/apps_container.h @@ -43,7 +43,7 @@ public: void suspend(bool checkIfPowerKeyReleased = false); virtual bool dispatchEvent(Ion::Events::Event event) override; void switchTo(App::Snapshot * snapshot) override; - void updateBatteryState(); + bool updateBatteryState(); void refreshPreferences(); void displayExamModePopUp(bool activate); void shutdownDueToLowBattery(); diff --git a/apps/backlight_dimming_timer.cpp b/apps/backlight_dimming_timer.cpp index 58be974eb..2f60e809b 100644 --- a/apps/backlight_dimming_timer.cpp +++ b/apps/backlight_dimming_timer.cpp @@ -5,6 +5,7 @@ BacklightDimmingTimer::BacklightDimmingTimer() : { } -void BacklightDimmingTimer::fire() { +bool BacklightDimmingTimer::fire() { Ion::Backlight::setBrightness(k_dimBacklightBrightness); + return false; } diff --git a/apps/backlight_dimming_timer.h b/apps/backlight_dimming_timer.h index 71a5bbfe6..17059e408 100644 --- a/apps/backlight_dimming_timer.h +++ b/apps/backlight_dimming_timer.h @@ -9,7 +9,7 @@ public: private: constexpr static int k_idleBeforeDimmingDuration = 30*1000; // In miliseconds constexpr static int k_dimBacklightBrightness = 0; - void fire() override; + bool fire() override; }; #endif diff --git a/apps/battery_timer.cpp b/apps/battery_timer.cpp index 61ec7df41..ced5c1896 100644 --- a/apps/battery_timer.cpp +++ b/apps/battery_timer.cpp @@ -7,9 +7,10 @@ BatteryTimer::BatteryTimer(AppsContainer * container) : { } -void BatteryTimer::fire() { - m_container->updateBatteryState(); +bool BatteryTimer::fire() { + bool needRedrawing = m_container->updateBatteryState(); if (Ion::Battery::level() == Ion::Battery::Charge::EMPTY) { m_container->shutdownDueToLowBattery(); } + return needRedrawing; } diff --git a/apps/battery_timer.h b/apps/battery_timer.h index c7e083eda..ccc7d0c46 100644 --- a/apps/battery_timer.h +++ b/apps/battery_timer.h @@ -9,7 +9,7 @@ class BatteryTimer : public Timer { public: BatteryTimer(AppsContainer * container); private: - void fire() override; + bool fire() override; AppsContainer * m_container; }; diff --git a/apps/led_timer.cpp b/apps/led_timer.cpp index a71fe7248..d462ca6c7 100644 --- a/apps/led_timer.cpp +++ b/apps/led_timer.cpp @@ -6,8 +6,9 @@ LedTimer::LedTimer() : { } -void LedTimer::fire() { +bool LedTimer::fire() { m_on = !m_on; KDColor ledColor = m_on ? KDColorRed : KDColorBlack; Ion::LED::setColor(ledColor); + return false; } diff --git a/apps/led_timer.h b/apps/led_timer.h index fd193ea79..17f221e48 100644 --- a/apps/led_timer.h +++ b/apps/led_timer.h @@ -7,7 +7,7 @@ class LedTimer : public Timer { public: LedTimer(); private: - void fire() override; + bool fire() override; bool m_on; }; diff --git a/apps/on_boarding/logo_controller.cpp b/apps/on_boarding/logo_controller.cpp index 32700462f..9fa2f10cb 100644 --- a/apps/on_boarding/logo_controller.cpp +++ b/apps/on_boarding/logo_controller.cpp @@ -14,8 +14,9 @@ View * LogoController::view() { return &m_logoView; } -void LogoController::fire() { +bool LogoController::fire() { app()->dismissModalViewController(); + return true; } } diff --git a/apps/on_boarding/logo_controller.h b/apps/on_boarding/logo_controller.h index 59e8437f4..8fdc82de2 100644 --- a/apps/on_boarding/logo_controller.h +++ b/apps/on_boarding/logo_controller.h @@ -11,7 +11,7 @@ public: LogoController(); View * view() override; private: - void fire() override; + bool fire() override; LogoView m_logoView; }; diff --git a/apps/suspend_timer.cpp b/apps/suspend_timer.cpp index 48fa53fc2..ee47ba663 100644 --- a/apps/suspend_timer.cpp +++ b/apps/suspend_timer.cpp @@ -7,6 +7,7 @@ SuspendTimer::SuspendTimer(AppsContainer * container) : { } -void SuspendTimer::fire() { +bool SuspendTimer::fire() { m_container->suspend(); + return false; } diff --git a/apps/suspend_timer.h b/apps/suspend_timer.h index 3124fc246..c63c97ad3 100644 --- a/apps/suspend_timer.h +++ b/apps/suspend_timer.h @@ -10,7 +10,7 @@ public: SuspendTimer(AppsContainer * container); private: constexpr static int k_idleBeforeSuspendDuration = 5*60*1000; // In miliseconds - void fire() override; + bool fire() override; AppsContainer * m_container; }; diff --git a/apps/usb_timer.cpp b/apps/usb_timer.cpp index 456435bdb..123f43959 100644 --- a/apps/usb_timer.cpp +++ b/apps/usb_timer.cpp @@ -9,10 +9,12 @@ USBTimer::USBTimer(AppsContainer * container) : { } -void USBTimer::fire() { +bool USBTimer::fire() { + bool needRedrawing = false; if (Ion::USB::isPlugged()) { if (!m_previousPluggedState && GlobalPreferences::sharedGlobalPreferences()->examMode() == GlobalPreferences::ExamMode::Activate) { m_container->displayExamModePopUp(false); + needRedrawing = true; } #if LED_WHILE_CHARGING KDColor LEDColor = Ion::Battery::isCharging() ? KDColorYellow : KDColorGreen; @@ -27,4 +29,5 @@ void USBTimer::fire() { m_previousPluggedState = false; } } + return needRedrawing; } diff --git a/apps/usb_timer.h b/apps/usb_timer.h index 5f49f6085..82ed9b581 100644 --- a/apps/usb_timer.h +++ b/apps/usb_timer.h @@ -9,7 +9,7 @@ class USBTimer : public Timer { public: USBTimer(AppsContainer * container); private: - void fire() override; + bool fire() override; AppsContainer * m_container; bool m_previousPluggedState; }; diff --git a/escher/Makefile b/escher/Makefile index 0da0c885a..ede40d2f6 100644 --- a/escher/Makefile +++ b/escher/Makefile @@ -22,7 +22,6 @@ objs += $(addprefix escher/src/,\ highlight_cell.o\ image_view.o\ invocation.o\ - invocation_timer.o\ input_view_controller.o\ key_view.o\ list_view_data_source.o\ diff --git a/escher/include/escher.h b/escher/include/escher.h index 35df10e91..820e0373b 100644 --- a/escher/include/escher.h +++ b/escher/include/escher.h @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include diff --git a/escher/include/escher/invocation_timer.h b/escher/include/escher/invocation_timer.h deleted file mode 100644 index 366d0c69f..000000000 --- a/escher/include/escher/invocation_timer.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef ESCHER_INVOCATION_TIMER_H -#define ESCHER_INVOCATION_TIMER_H - -#include -#include - -class InvocationTimer : public Timer { -public: - InvocationTimer(Invocation invocation, uint32_t period); -private: - void fire() override; - Invocation m_invocation; -}; - -#endif diff --git a/escher/include/escher/timer.h b/escher/include/escher/timer.h index 6d2825f77..bc2a06088 100644 --- a/escher/include/escher/timer.h +++ b/escher/include/escher/timer.h @@ -19,7 +19,7 @@ public: bool tick(); void reset(); protected: - virtual void fire() = 0; + virtual bool fire() = 0; private: uint32_t m_period; uint32_t m_numberOfTicksBeforeFire; diff --git a/escher/src/container.cpp b/escher/src/container.cpp index 8e8347902..7a4d6c855 100644 --- a/escher/src/container.cpp +++ b/escher/src/container.cpp @@ -35,7 +35,7 @@ App * Container::activeApp() { } bool Container::dispatchEvent(Ion::Events::Event event) { - if (event == Ion::Events::TimerTick || m_activeApp->processEvent(event)) { + if (event == Ion::Events::TimerFire || m_activeApp->processEvent(event)) { window()->redraw(); return true; } diff --git a/escher/src/invocation_timer.cpp b/escher/src/invocation_timer.cpp deleted file mode 100644 index 37ca92df0..000000000 --- a/escher/src/invocation_timer.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include - -InvocationTimer::InvocationTimer(Invocation invocation, uint32_t period) : - Timer(period), - m_invocation(invocation) -{ -} - -void InvocationTimer::fire() { - m_invocation.perform(this); -} diff --git a/escher/src/run_loop.cpp b/escher/src/run_loop.cpp index 6c14ced8f..55eb0d870 100644 --- a/escher/src/run_loop.cpp +++ b/escher/src/run_loop.cpp @@ -49,7 +49,7 @@ bool RunLoop::step() { for (int i=0; itick()) { - dispatchEvent(Ion::Events::TimerTick); + dispatchEvent(Ion::Events::TimerFire); } } } diff --git a/escher/src/timer.cpp b/escher/src/timer.cpp index 4aebee229..0e9f5a5ea 100644 --- a/escher/src/timer.cpp +++ b/escher/src/timer.cpp @@ -9,9 +9,9 @@ Timer::Timer(uint32_t period) : bool Timer::tick() { m_numberOfTicksBeforeFire--; if (m_numberOfTicksBeforeFire == 0) { - fire(); + bool needRedraw = fire(); reset(); - return true; + return needRedraw; } return false; } diff --git a/ion/include/ion/events.h b/ion/include/ion/events.h index effbe1abb..6f38628c5 100644 --- a/ion/include/ion/events.h +++ b/ion/include/ion/events.h @@ -200,7 +200,7 @@ constexpr Event UpperZ = Event::ShiftAlphaKey(Keyboard::Key::H4); constexpr Event None = Event::Special(0); constexpr Event Termination = Event::Special(1); -constexpr Event TimerTick = Event::Special(2); +constexpr Event TimerFire = Event::Special(2); } }