mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-03 07:07:23 +00:00
Ladybird/Android: Add EventLoopImplementation for ALooper
Timers run in their own thread, to take advantage of existing Java Executor features. By hooking into ALooper, we can spin the main Activity's UI thread event loop without causing a fuss, or spinning the CPU by just polling our event loop constantly.
This commit is contained in:
committed by
Andrew Kaster
parent
d63fb8fa61
commit
d93911928b
29
Ladybird/Android/src/main/cpp/TimerExecutorService.cpp
Normal file
29
Ladybird/Android/src/main/cpp/TimerExecutorService.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (c) 2023, Andrew Kaster <akaster@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "ALooperEventLoopImplementation.h"
|
||||
#include <LibCore/EventLoop.h>
|
||||
#include <jni.h>
|
||||
|
||||
extern "C" JNIEXPORT void JNICALL Java_org_serenityos_ladybird_TimerExecutorService_00024Timer_nativeRun(JNIEnv*, jobject /* thiz */, jlong native_data, jlong id)
|
||||
{
|
||||
auto& thread_data = *reinterpret_cast<Ladybird::EventLoopThreadData*>(native_data);
|
||||
|
||||
if (auto timer_data = thread_data.timers.get(id); timer_data.has_value()) {
|
||||
auto receiver = timer_data->receiver.strong_ref();
|
||||
if (!receiver)
|
||||
return;
|
||||
|
||||
if (timer_data->visibility == Core::TimerShouldFireWhenNotVisible::No)
|
||||
if (!receiver->is_visible_for_timer_purposes())
|
||||
return;
|
||||
|
||||
Core::TimerEvent event(id);
|
||||
|
||||
// FIXME: Should the dispatch happen on the thread that registered the timer?
|
||||
receiver->dispatch_event(event);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user