summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDerek Foreman <derekf@osg.samsung.com>2017-11-06 17:05:25 -0600
committerDerek Foreman <derekf@osg.samsung.com>2017-11-08 15:12:47 -0600
commitc54a12aca60f169a7f2a8536d9a5c4cd71bb86b7 (patch)
tree0cca13f1f6a1b45eb949748540f4bafd491847eb /src
parentd346ac7b2e609ed459148bf56cfd14bd6ecb8fbc (diff)
wayland_shm: Add wl_shm to dmabuf
wl_shm and dmabuf only really need to differ in how they allocate a buffer, but right now we've got them in separate files. This dramatically reduces the complexity of the wl_shm code and shares much more implementation with the dmabuf code. This throws away at least one "optimization" wl_shm used - over-allocating buffers so that window resizing doesn't always require a new buffer allocation. If people feel that window resizing has become too slow now this can be added to the dmabuf code to the benefit of both allocators. Disabling dmabuf by env var still uses the old wl_shm implementation for now, but soon that code will be removed entirely and the env var disable will use this path.
Diffstat (limited to 'src')
-rw-r--r--src/modules/evas/engines/wayland_shm/evas_dmabuf.c84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/modules/evas/engines/wayland_shm/evas_dmabuf.c b/src/modules/evas/engines/wayland_shm/evas_dmabuf.c
index 813d7b2d92..9947cb5e51 100644
--- a/src/modules/evas/engines/wayland_shm/evas_dmabuf.c
+++ b/src/modules/evas/engines/wayland_shm/evas_dmabuf.c
@@ -322,6 +322,89 @@ err:
322 return EINA_FALSE; 322 return EINA_FALSE;
323} 323}
324 324
325static Buffer_Handle *
326_wl_shm_alloc(Buffer_Manager *self EINA_UNUSED, const char *name EINA_UNUSED, int w, int h, unsigned long *stride, int32_t *fd)
327{
328 Efl_Vpath_File *file_obj;
329 Eina_Tmpstr *fullname;
330 size_t size = w * h * 4;
331 void *out = NULL;
332
333 file_obj = efl_vpath_manager_fetch(EFL_VPATH_MANAGER_CLASS,
334 "(:run:)/evas-wayland_shm-XXXXXX");
335 *fd = eina_file_mkstemp(efl_vpath_file_result_get(file_obj), &fullname);
336 efl_del(file_obj);
337 if (*fd < 0) return NULL;
338
339 unlink(fullname);
340 eina_tmpstr_del(fullname);
341
342 *stride = w * 4;
343 if (ftruncate(*fd, size) < 0) goto err;
344
345 out = mmap(NULL, size, (PROT_READ | PROT_WRITE), MAP_SHARED, *fd, 0);
346 if (out == MAP_FAILED) goto err;
347
348 return out;
349
350err:
351 close(*fd);
352 return NULL;
353}
354
355static void *
356_wl_shm_map(Dmabuf_Buffer *buf)
357{
358 return buf->bh;
359}
360
361static void
362_wl_shm_unmap(Dmabuf_Buffer *buf EINA_UNUSED)
363{
364 /* wl_shm is mapped for its lifetime */
365}
366
367static void
368_wl_shm_discard(Dmabuf_Buffer *buf)
369{
370 munmap(buf->bh, buf->size);
371}
372
373static void
374_wl_shm_manager_destroy()
375{
376 /* Nop. */
377}
378
379static struct wl_buffer *
380_wl_shm_to_buffer(Ecore_Wl2_Display *ewd, Dmabuf_Buffer *db)
381{
382 struct wl_buffer *buf;
383 struct wl_shm_pool *pool;
384 struct wl_shm *shm;
385
386 shm = ecore_wl2_display_shm_get(ewd);
387 pool = wl_shm_create_pool(shm, db->fd, db->size);
388 buf = wl_shm_pool_create_buffer(pool, 0, db->w, db->h, db->stride, 0);
389 wl_shm_pool_destroy(pool);
390 close(db->fd);
391 db->fd = -1;
392 wl_buffer_add_listener(buf, &buffer_listener, db);
393 return buf;
394}
395
396static Eina_Bool
397_wl_shm_buffer_manager_setup(int fd EINA_UNUSED)
398{
399 buffer_manager->alloc = _wl_shm_alloc;
400 buffer_manager->to_buffer = _wl_shm_to_buffer;
401 buffer_manager->map = _wl_shm_map;
402 buffer_manager->unmap = _wl_shm_unmap;
403 buffer_manager->discard = _wl_shm_discard;
404 buffer_manager->manager_destroy = _wl_shm_manager_destroy;
405 return EINA_TRUE;
406}
407
325static Buffer_Manager * 408static Buffer_Manager *
326_buffer_manager_get(void) 409_buffer_manager_get(void)
327{ 410{
@@ -342,6 +425,7 @@ _buffer_manager_get(void)
342 425
343 success = _intel_buffer_manager_setup(fd); 426 success = _intel_buffer_manager_setup(fd);
344 if (!success) success = _exynos_buffer_manager_setup(fd); 427 if (!success) success = _exynos_buffer_manager_setup(fd);
428 if (!success) success = _wl_shm_buffer_manager_setup(fd);
345 if (!success) goto err_bm; 429 if (!success) goto err_bm;
346 430
347 drm_fd = fd; 431 drm_fd = fd;