[cairo] [PATCH 2/2] xcb: Use SHM FD-passing if possible

Alexander Volkov a.volkov at rusbitech.ru
Fri Apr 6 14:17:31 UTC 2018


06.04.2018 16:38, Chris Wilson пишет:
> Quoting Alexander Volkov (2018-04-06 13:33:37)
>> +    if (connection->flags & CAIRO_XCB_HAS_SHM_FD) {
>> +       xcb_shm_create_segment_cookie_t cookie;
>> +       xcb_shm_create_segment_reply_t *reply;
>> +       xcb_generic_error_t *error;
>> +       int *fds;
>> +       int err;
>> +
>> +       if (unlikely (size > UINT32_MAX))
>> +           return CAIRO_STATUS_NO_MEMORY;
> That's not the protocol limit, surely? It may well be, just a bit
> surprising if it was.
Unfortunately it is. The size argument of xcb_shm_create_segment() is of 
type uint32_t.

>> +       shm->shmseg = _cairo_xcb_connection_get_xid (connection);
>> +       cookie = xcb_shm_create_segment (connection->xcb_connection, shm->shmseg, size, FALSE);
>> +       reply = xcb_shm_create_segment_reply (connection->xcb_connection, cookie, &error);
>> +       if (error) {
>> +           free (error);
>> +           _cairo_xcb_connection_put_xid (connection, shm->shmseg);
>> +           return CAIRO_INT_STATUS_UNSUPPORTED;
>> +       }
>> +
>> +       fds = xcb_shm_create_segment_reply_fds (connection->xcb_connection, reply);
>> +       if (reply->nfd != 1) {
>> +           for (int i = 0; i < reply->nfd; i++)
>> +               close (fds[i]);
>> +
>> +           free (reply);
>> +           xcb_shm_detach (connection->xcb_connection, shm->shmseg);
>> +           _cairo_xcb_connection_put_xid (connection, shm->shmseg);
>> +           return CAIRO_INT_STATUS_UNSUPPORTED;
>> +       }
>> +
>> +       shm->shm = mmap (NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, fds[0], 0);
> A roundtrip on allocation. That doesn't seem like something we would want
> in a frequent path? And creating temporary surfaces is frequent enough.
> That would suggest to me that we want an allocation cache... And packing
> into a larger object?
Well, it seems that it would be better to use xcb_shm_attach_fd() 
instead of xcb_shm_create_segment().
It will also allow to avoid UINT32_MAX restriction.
Maybe I'll try it next week.


More information about the cairo mailing list