mirror of
https://github.com/Genymobile/scrcpy.git
synced 2026-02-19 12:54:30 +01:00
This allows to schedule a runnable to be executed on the main thread. FIXME: the implementation is incorrect: if another event is triggered which makes scrcpy exit, then the callback will never be executed and cause a memory leak.
41 lines
915 B
C
41 lines
915 B
C
#include "events.h"
|
|
|
|
#include "util/log.h"
|
|
|
|
bool
|
|
sc_push_event_impl(uint32_t type, const char *name) {
|
|
SDL_Event event;
|
|
event.type = type;
|
|
int ret = SDL_PushEvent(&event);
|
|
// ret < 0: error (queue full)
|
|
// ret == 0: event was filtered
|
|
// ret == 1: success
|
|
if (ret != 1) {
|
|
LOGE("Could not post %s event: %s", name, SDL_GetError());
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool
|
|
sc_post_to_main_thread(sc_runnable_fn run, void *userdata) {
|
|
SDL_Event event = {
|
|
.user = {
|
|
.type = SC_EVENT_RUN_ON_MAIN_THREAD,
|
|
.data1 = run,
|
|
.data2 = userdata,
|
|
},
|
|
};
|
|
int ret = SDL_PushEvent(&event);
|
|
// ret < 0: error (queue full)
|
|
// ret == 0: event was filtered
|
|
// ret == 1: success
|
|
if (ret != 1) {
|
|
LOGW("Coud not post to main thread: %s", SDL_GetError());
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|