1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 03:47:35 +00:00

LibCore: Convert CTimer to ObjectPtr

This commit is contained in:
Andreas Kling 2019-09-20 15:19:46 +02:00
parent c34fd10b5b
commit 50a6560413
22 changed files with 91 additions and 70 deletions

View file

@ -31,29 +31,30 @@ WallpaperMode mode_to_enum(const String& name)
}
WSCompositor::WSCompositor()
: m_compose_timer(this)
, m_immediate_compose_timer(this)
{
m_compose_timer = CTimer::create(this);
m_immediate_compose_timer = CTimer::create(this);
m_screen_can_set_buffer = WSScreen::the().can_set_buffer();
init_bitmaps();
m_compose_timer.on_timeout = [=]() {
m_compose_timer->on_timeout = [&]() {
#if defined(COMPOSITOR_DEBUG)
dbgprintf("WSCompositor: delayed frame callback: %d rects\n", m_dirty_rects.size());
#endif
compose();
};
m_compose_timer.set_single_shot(true);
m_compose_timer.set_interval(1000 / 60);
m_immediate_compose_timer.on_timeout = [=]() {
m_compose_timer->set_single_shot(true);
m_compose_timer->set_interval(1000 / 60);
m_immediate_compose_timer->on_timeout = [=]() {
#if defined(COMPOSITOR_DEBUG)
dbgprintf("WSCompositor: immediate frame callback: %d rects\n", m_dirty_rects.size());
#endif
compose();
};
m_immediate_compose_timer.set_single_shot(true);
m_immediate_compose_timer.set_interval(0);
m_immediate_compose_timer->set_single_shot(true);
m_immediate_compose_timer->set_interval(0);
}
void WSCompositor::init_bitmaps()
@ -248,12 +249,12 @@ void WSCompositor::invalidate(const Rect& a_rect)
// We delay composition by a timer interval, but to not affect latency too
// much, if a pending compose is not already scheduled, we also schedule an
// immediate compose the next spin of the event loop.
if (!m_compose_timer.is_active()) {
if (!m_compose_timer->is_active()) {
#if defined(COMPOSITOR_DEBUG)
dbgprintf("Invalidated (starting immediate frame): %dx%d %dx%d\n", a_rect.x(), a_rect.y(), a_rect.width(), a_rect.height());
#endif
m_compose_timer.start();
m_immediate_compose_timer.start();
m_compose_timer->start();
m_immediate_compose_timer->start();
} else {
#if defined(COMPOSITOR_DEBUG)
dbgprintf("Invalidated (frame callback pending): %dx%d %dx%d\n", a_rect.x(), a_rect.y(), a_rect.width(), a_rect.height());

View file

@ -46,8 +46,8 @@ private:
unsigned m_compose_count { 0 };
unsigned m_flush_count { 0 };
CTimer m_compose_timer;
CTimer m_immediate_compose_timer;
ObjectPtr<CTimer> m_compose_timer;
ObjectPtr<CTimer> m_immediate_compose_timer;
bool m_flash_flush { false };
bool m_buffers_are_flipped { false };
bool m_screen_can_set_buffer { false };

View file

@ -10,7 +10,7 @@ WSMenuManager::WSMenuManager()
{
m_username = getlogin();
new CTimer(300, [this] {
m_timer = CTimer::create(300, [this] {
static time_t last_update_time;
time_t now = time(nullptr);
if (now != last_update_time || m_cpu_monitor.is_dirty()) {

View file

@ -2,6 +2,7 @@
#include "WSMenu.h"
#include <LibCore/CObject.h>
#include <LibCore/CTimer.h>
#include <WindowServer/WSCPUMonitor.h>
#include <WindowServer/WSWindow.h>
@ -32,6 +33,7 @@ private:
OwnPtr<WSWindow> m_window;
WSCPUMonitor m_cpu_monitor;
String m_username;
ObjectPtr<CTimer> m_timer;
Vector<WeakPtr<WSMenu>> m_open_menu_stack;
};