Last active
December 18, 2015 09:59
-
-
Save Zoxc/5765678 to your computer and use it in GitHub Desktop.
Rendering on multiple threads with Wayland subsurfaces
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mutex commit | |
atomic<int> render_complete_count | |
signal resizing_complete | |
apply_pending_state(surface) { | |
wl_surface_attach(surface, ...) | |
wl_surface_damage(surface, ...) | |
} | |
remote_rendering_thread() { | |
event_t event | |
while(true) { | |
read_event(&event) | |
switch(event) { | |
case RESIZE: | |
resize_frame() | |
render_frame() | |
// Create a closure which is able to apply the pending state in the main thread | |
thread.apply_pending_state_closure = create_closure { | |
apply_pending_state(thread_surface) | |
} | |
// Signal that we're done rendering | |
render_complete_count++ | |
// Wait until the main thread commits before we do anything further in this thread | |
wait_for(resizing_complete) | |
break | |
case NEXT_FRAME: | |
generate_next_frame() | |
render_frame() | |
commit.sync { | |
apply_pending_state(thread_surface) | |
commit_all_surfaces() | |
} | |
break | |
} | |
} | |
} | |
main_thread_resize() { | |
render_complete_count = 0 | |
remote_apply_pending_state_count = 0 | |
// Inform the remote threads that we're resizing | |
remote_threads.each { | |
queue_event(thread, RESIZE, PRIORITY_HIGHEST) | |
} | |
// Render local surfaces while we wait for the other threads to render | |
render_main_thread_surfaces() | |
// Wait for the other threads to complete rendering | |
wait until render_complete_count == remote_threads.count | |
// We now apply all the pending state | |
main_surfaces.each { | |
apply_pending_state(surface) | |
} | |
remote_threads.each { | |
thread.apply_pending_state_closure() | |
} | |
// Apply all changes in a single commit | |
commit_all_surfaces() | |
// Tell the other threads to continue drawing at will | |
signal(resizing_complete) | |
} | |
main_thread_render() { | |
render_main_surface() | |
commit.sync { | |
main_surfaces.each { | |
apply_pending_state(surface) | |
} | |
commit_all_surfaces() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment