mirror of
https://github.com/FelixKratz/SketchyBar
synced 2024-11-25 12:50:18 +00:00
only use threaded rendering for animation frames
when not in an animation the latency reduction doesnt really matter and we save some thread overhead this way
This commit is contained in:
parent
318fb2809b
commit
2673c6349c
6 changed files with 23 additions and 22 deletions
|
@ -10,12 +10,13 @@ static pthread_t g_render_threads[MAX_RENDER_THREADS];
|
|||
static uint32_t g_used_threads = 0;
|
||||
|
||||
void join_render_threads() {
|
||||
static int count = 0;
|
||||
printf("%d Threaded!\n", count++);
|
||||
for (int i = 0; i < g_used_threads; i++)
|
||||
pthread_join(g_render_threads[i], NULL);
|
||||
g_used_threads = 0;
|
||||
}
|
||||
|
||||
|
||||
bool bar_draws_item(struct bar* bar, struct bar_item* bar_item) {
|
||||
if (!bar_item->drawing || !bar->shown || bar->hidden) return false;
|
||||
|
||||
|
@ -148,7 +149,7 @@ static void bar_check_for_clip_updates(struct bar* bar) {
|
|||
}
|
||||
}
|
||||
|
||||
void bar_draw(struct bar* bar, bool forced) {
|
||||
void bar_draw(struct bar* bar, bool forced, bool threaded) {
|
||||
if (bar->sid < 1 || bar->adid < 1) return;
|
||||
|
||||
if (g_bar_manager.might_need_clipping)
|
||||
|
@ -198,7 +199,7 @@ void bar_draw(struct bar* bar, bool forced) {
|
|||
}
|
||||
|
||||
windows_freeze();
|
||||
if (g_used_threads < MAX_RENDER_THREADS) {
|
||||
if (threaded && g_used_threads < MAX_RENDER_THREADS) {
|
||||
uint32_t thread_id = g_used_threads++;
|
||||
struct draw_item_payload {
|
||||
struct window* window;
|
||||
|
|
|
@ -22,7 +22,7 @@ void bar_destroy(struct bar* bar);
|
|||
void bar_set_hidden(struct bar* bar, bool hidden);
|
||||
void bar_calculate_bounds(struct bar* bar);
|
||||
void bar_resize(struct bar* bar);
|
||||
void bar_draw(struct bar* bar, bool forced);
|
||||
void bar_draw(struct bar* bar, bool forced, bool threaded);
|
||||
void bar_order_item_windows(struct bar* bar);
|
||||
|
||||
bool bar_draws_item(struct bar* bar, struct bar_item* bar_item);
|
||||
|
|
|
@ -406,7 +406,7 @@ void bar_manager_reset_bar_association(struct bar_manager* bar_manager) {
|
|||
bar_item_reset_associated_bar(bar_manager->bar_items[i]);
|
||||
}
|
||||
|
||||
void bar_manager_refresh(struct bar_manager* bar_manager, bool forced) {
|
||||
void bar_manager_refresh(struct bar_manager* bar_manager, bool forced, bool threaded) {
|
||||
if (bar_manager->frozen) return;
|
||||
if (forced) {
|
||||
bar_manager_reset_bar_association(bar_manager);
|
||||
|
@ -421,7 +421,7 @@ void bar_manager_refresh(struct bar_manager* bar_manager, bool forced) {
|
|||
if (forced
|
||||
|| bar_manager_bar_needs_redraw(bar_manager, bar_manager->bars[i])) {
|
||||
bar_calculate_bounds(bar_manager->bars[i]);
|
||||
bar_draw(bar_manager->bars[i], false);
|
||||
bar_draw(bar_manager->bars[i], false, threaded);
|
||||
if (bar_manager->needs_ordering) {
|
||||
bar_order_item_windows(bar_manager->bars[i]);
|
||||
}
|
||||
|
@ -429,7 +429,7 @@ void bar_manager_refresh(struct bar_manager* bar_manager, bool forced) {
|
|||
}
|
||||
|
||||
bar_manager_clear_needs_update(bar_manager);
|
||||
join_render_threads();
|
||||
if (threaded) join_render_threads();
|
||||
}
|
||||
|
||||
void bar_manager_resize(struct bar_manager* bar_manager) {
|
||||
|
@ -515,7 +515,7 @@ void bar_manager_animator_refresh(struct bar_manager* bar_manager, uint64_t time
|
|||
bar_manager_unfreeze(bar_manager);
|
||||
|
||||
if (bar_manager->bar_needs_resize) bar_manager_resize(bar_manager);
|
||||
bar_manager_refresh(bar_manager, false);
|
||||
bar_manager_refresh(bar_manager, false, true);
|
||||
}
|
||||
bar_manager_unfreeze(bar_manager);
|
||||
}
|
||||
|
@ -547,7 +547,7 @@ void bar_manager_update(struct bar_manager* bar_manager, bool forced) {
|
|||
}
|
||||
}
|
||||
|
||||
if (needs_refresh || forced) bar_manager_refresh(bar_manager, forced);
|
||||
if (needs_refresh || forced) bar_manager_refresh(bar_manager, forced, false);
|
||||
}
|
||||
|
||||
void bar_manager_reset(struct bar_manager* bar_manager) {
|
||||
|
@ -743,7 +743,7 @@ void bar_manager_display_resized(struct bar_manager* bar_manager, uint32_t did)
|
|||
bar_resize(bar_manager->bars[i]);
|
||||
}
|
||||
}
|
||||
bar_manager_refresh(bar_manager, false);
|
||||
bar_manager_refresh(bar_manager, false, false);
|
||||
}
|
||||
|
||||
void bar_manager_display_moved(struct bar_manager* bar_manager, uint32_t did) {
|
||||
|
@ -757,7 +757,7 @@ void bar_manager_display_moved(struct bar_manager* bar_manager, uint32_t did) {
|
|||
}
|
||||
}
|
||||
bar_manager->needs_ordering = true;
|
||||
bar_manager_refresh(bar_manager, true);
|
||||
bar_manager_refresh(bar_manager, true, false);
|
||||
bar_manager_handle_display_change(bar_manager);
|
||||
}
|
||||
|
||||
|
@ -775,7 +775,7 @@ void bar_manager_display_changed(struct bar_manager* bar_manager) {
|
|||
bar_manager_freeze(bar_manager);
|
||||
bar_manager_reset(bar_manager);
|
||||
bar_manager_unfreeze(bar_manager);
|
||||
bar_manager_refresh(bar_manager, true);
|
||||
bar_manager_refresh(bar_manager, true, false);
|
||||
|
||||
bar_manager_handle_display_change(bar_manager);
|
||||
bar_manager_handle_space_change(bar_manager, true);
|
||||
|
@ -909,7 +909,7 @@ void bar_manager_handle_media_cover_change(struct bar_manager* bar_manager, CGIm
|
|||
}
|
||||
}
|
||||
|
||||
if (needs_refresh) bar_manager_refresh(bar_manager, false);
|
||||
if (needs_refresh) bar_manager_refresh(bar_manager, false, false);
|
||||
}
|
||||
|
||||
void bar_manager_handle_front_app_switch(struct bar_manager* bar_manager, char* info) {
|
||||
|
@ -980,7 +980,7 @@ void bar_manager_handle_space_change(struct bar_manager* bar_manager, bool force
|
|||
|
||||
|
||||
bar_manager_unfreeze(bar_manager);
|
||||
bar_manager_refresh(bar_manager, force_refresh);
|
||||
bar_manager_refresh(bar_manager, force_refresh, false);
|
||||
env_vars_destroy(&env_vars);
|
||||
}
|
||||
|
||||
|
@ -996,7 +996,7 @@ void bar_manager_handle_display_change(struct bar_manager* bar_manager) {
|
|||
COMMAND_SUBSCRIBE_DISPLAY_CHANGE,
|
||||
&env_vars );
|
||||
|
||||
bar_manager_refresh(bar_manager, false);
|
||||
bar_manager_refresh(bar_manager, false, false);
|
||||
env_vars_destroy(&env_vars);
|
||||
}
|
||||
|
||||
|
|
|
@ -100,7 +100,7 @@ void bar_manager_display_resized(struct bar_manager* bar_manager, uint32_t did);
|
|||
void bar_manager_display_moved(struct bar_manager* bar_manager, uint32_t did);
|
||||
void bar_manager_display_removed(struct bar_manager* bar_manager, uint32_t did);
|
||||
void bar_manager_display_added(struct bar_manager* bar_manager, uint32_t did);
|
||||
void bar_manager_refresh(struct bar_manager* bar_manager, bool forced);
|
||||
void bar_manager_refresh(struct bar_manager* bar_manager, bool forced, bool threaded);
|
||||
void bar_manager_resize(struct bar_manager* bar_manager);
|
||||
|
||||
void bar_manager_handle_mouse_entered_global(struct bar_manager* bar_manager);
|
||||
|
|
|
@ -43,7 +43,7 @@ static void event_display_resized(void* context) {
|
|||
static void event_menu_bar_hidden_changed(void* context) {
|
||||
bar_manager_resize(&g_bar_manager);
|
||||
g_bar_manager.bar_needs_update = true;
|
||||
bar_manager_refresh(&g_bar_manager, false);
|
||||
bar_manager_refresh(&g_bar_manager, false, false);
|
||||
}
|
||||
|
||||
static void event_system_woke(void* context) {
|
||||
|
@ -99,7 +99,7 @@ static void event_mouse_up(void* context) {
|
|||
point_in_window_coords);
|
||||
|
||||
if (bar_item && bar_item->needs_update)
|
||||
bar_manager_refresh(&g_bar_manager, false);
|
||||
bar_manager_refresh(&g_bar_manager, false, false);
|
||||
}
|
||||
|
||||
static void event_mouse_dragged(void* context) {
|
||||
|
@ -122,7 +122,7 @@ static void event_mouse_dragged(void* context) {
|
|||
bar_item_on_drag(bar_item, point_in_window_coords);
|
||||
|
||||
if (bar_item->needs_update)
|
||||
bar_manager_refresh(&g_bar_manager, false);
|
||||
bar_manager_refresh(&g_bar_manager, false, false);
|
||||
}
|
||||
|
||||
static void event_mouse_entered(void* context) {
|
||||
|
@ -296,7 +296,7 @@ static void event_mouse_scrolled(void* context) {
|
|||
bar_item_on_scroll(bar_item, scroll_delta + g_scroll_info.delta_y);
|
||||
|
||||
if (bar_item && bar_item->needs_update)
|
||||
bar_manager_refresh(&g_bar_manager, false);
|
||||
bar_manager_refresh(&g_bar_manager, false, false);
|
||||
|
||||
g_scroll_info.delta_y = 0;
|
||||
}
|
||||
|
|
|
@ -575,7 +575,7 @@ static void handle_domain_order(FILE* rsp, struct token domain, char* message) {
|
|||
}
|
||||
|
||||
bar_manager_sort(&g_bar_manager, ordering, count);
|
||||
bar_manager_refresh(&g_bar_manager, false);
|
||||
bar_manager_refresh(&g_bar_manager, false, false);
|
||||
}
|
||||
|
||||
void handle_message_mach(struct mach_buffer* buffer) {
|
||||
|
@ -749,7 +749,7 @@ void handle_message_mach(struct mach_buffer* buffer) {
|
|||
|
||||
animator_lock(&g_bar_manager.animator);
|
||||
bar_manager_unfreeze(&g_bar_manager);
|
||||
bar_manager_refresh(&g_bar_manager, false);
|
||||
bar_manager_refresh(&g_bar_manager, false, false);
|
||||
|
||||
if (rsp) fclose(rsp);
|
||||
|
||||
|
|
Loading…
Reference in a new issue