【问题标题】:Weston wayland - improving the screenshooter (wl_display_roundtrip blocks for over a second)Weston Wayland - 改进屏幕截图(wl_display_roundtrip 块超过一秒)
【发布时间】:2019-10-28 07:33:18
【问题描述】:

我在 armv7 设备上使用 weston。我不时使用weston的screenshooter模块在上面截屏,但我注意到截屏时,显示的整个图像会冻结超过一秒钟,这会导致屏幕上出现难看的抖动屏幕。

我检查了 weston 源代码中的 screenshot.c 代码,并使用一些简单的性能测量(现在 - 之后)对其进行编译,发现整个代码中只有一个地方导致了这种抖动:while 循环等待 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);

每个块的整体执行耗时 901 毫秒,while 循环耗时 896 毫秒,因此大部分 cpu 时间都用于等待往返。

有什么办法可以优化它以消除屏幕上的抖动?在另一个线程中调用 wl_display_roundtrip 是否安全?或者有什么异步方法可以做到这一点?

【问题讨论】:

  • 我认为大部分时间都花在了截图上。您是否查看了 wl_display_roundtrip 的功能?它等待服务器做事。
  • 那有什么办法让它异步吗?或者是协议的错,它阻止图像更新以制作屏幕截图?
  • 我会怀疑(但我实际上并不知道 Wayland 是如何工作的)如果您删除程序在屏幕截图完成之前什么都不做的部分,那么您的程序在屏幕截图完成之前可能可以做一些事情。 buffer_copy_done 是如何设置为 1 的?

标签: c wayland


【解决方案1】:

wl_display_roundtrip 被 Wayland 用于同步响应。此调用将阻塞,直到服务器服务器响应,并且必须小心使用,因为它可能会减慢系统速度,甚至在最坏的情况下可能导致死锁。 wl_display_roundtrip 仅在绑定注册表并获取全局对象并绑定时使用一次,因为客户端在没有获取对象接口的情况下无法执行任何操作。

对于非阻塞,你应该使用 wl_display_dispatch

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多