Weston wayland - improving the screenshooter (wl_display_roundtrip blocks for over a second)

Viewed 691

I'm using weston on an armv7 device. I'm using the weston's screenshooter module to capture screenshots on it from time to time, but what I noticed is that when a screenshot is being captured, the whole image being displayed gets frozen for over a second, which causes an ugly jitter on the screen.

I have examined the screenshot.c code in weston source and compiled it with some simple performance measurements (time now - time after), and found out that only one place in the entire code is causing this jitter: the while loop that waits for wl_display_roundtrip:

wl_list_for_each(output, &output_list, link) {
        output->buffer = create_shm_buffer(output->width, output->height, &output->data);
        weston_screenshooter_shoot(screenshooter,
                       output->output,
                       output->buffer);
        buffer_copy_done = 0;
        ms2 = ctimestamp();
        while (!buffer_copy_done)
            wl_display_roundtrip(display);
        fprintf(stderr, "while roundtrip took %llu ms\n", ctimestamp()-ms2);
    }
    fprintf(stderr, "foreach took %llu ms\n", ctimestamp()-oldMS);

The whole for each block took 901ms to execute, the while loop took 896ms so the majority of the cpu time is spent for waiting for the roundtrip.

Is there any way I could optimize this to get rid of the jitter on the screen? Is calling wl_display_roundtrip in another thread safe? Or is there any async way of doing this?

1 Answers

wl_display_roundtrip is used by wayland for synchronous response. This call will block until server server response and must be used with care as it may slow down system or even in worst case may cause deadlock. wl_display_roundtrip is only used once when binding for registry and getting global object and bind, since client can't do anything without getting the object interface.

for non-blocking you should use wl_display_dispatch

Related