summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDerek Foreman <derekf@osg.samsung.com>2016-06-30 13:44:51 -0500
committerDerek Foreman <derekf@osg.samsung.com>2016-06-30 13:44:51 -0500
commit10f2e9c15f6212862b307c79fa04f0f04d0ba0cf (patch)
treedfa3f239b87684b16dde9e78c3356e5ffd8baa9b /src
parent744fa9bba11b400b8837c700a8ab0722d8367c0b (diff)
wayland_shm: free dmabuf resources on fallback
Add destructors for the buffer managers, and clean up properly when falling back. Fixes Coverity CID1357163 and CID1357162
Diffstat (limited to 'src')
-rw-r--r--src/modules/evas/engines/wayland_shm/evas_dmabuf.c52
1 files changed, 42 insertions, 10 deletions
diff --git a/src/modules/evas/engines/wayland_shm/evas_dmabuf.c b/src/modules/evas/engines/wayland_shm/evas_dmabuf.c
index 3050f99..1f22626 100644
--- a/src/modules/evas/engines/wayland_shm/evas_dmabuf.c
+++ b/src/modules/evas/engines/wayland_shm/evas_dmabuf.c
@@ -39,14 +39,15 @@ struct _Buffer_Manager
39 void *(*map)(Dmabuf_Buffer *buf); 39 void *(*map)(Dmabuf_Buffer *buf);
40 void (*unmap)(Dmabuf_Buffer *buf); 40 void (*unmap)(Dmabuf_Buffer *buf);
41 void (*discard)(Dmabuf_Buffer *buf); 41 void (*discard)(Dmabuf_Buffer *buf);
42 void (*manager_destroy)(void);
42 void *priv; 43 void *priv;
44 void *dl_handle;
43}; 45};
44 46
45Buffer_Manager *buffer_manager = NULL; 47Buffer_Manager *buffer_manager = NULL;
46 48
47struct _Dmabuf_Buffer 49struct _Dmabuf_Buffer
48{ 50{
49 Buffer_Manager *bm;
50 Dmabuf_Surface *surface; 51 Dmabuf_Surface *surface;
51 struct wl_buffer *wl_buffer; 52 struct wl_buffer *wl_buffer;
52 int w, h; 53 int w, h;
@@ -90,12 +91,14 @@ int (*sym_drm_intel_gem_bo_unmap_gtt)(drm_intel_bo *bo) = NULL;
90int (*sym_drm_intel_gem_bo_map_gtt)(drm_intel_bo *bo) = NULL; 91int (*sym_drm_intel_gem_bo_map_gtt)(drm_intel_bo *bo) = NULL;
91drm_intel_bo *(*sym_drm_intel_bo_alloc_tiled)(drm_intel_bufmgr *mgr, const char *name, int x, int y, int cpp, uint32_t *tile, unsigned long *pitch, unsigned long flags) = NULL; 92drm_intel_bo *(*sym_drm_intel_bo_alloc_tiled)(drm_intel_bufmgr *mgr, const char *name, int x, int y, int cpp, uint32_t *tile, unsigned long *pitch, unsigned long flags) = NULL;
92void (*sym_drm_intel_bo_unreference)(drm_intel_bo *bo) = NULL; 93void (*sym_drm_intel_bo_unreference)(drm_intel_bo *bo) = NULL;
93int (*sym_drmPrimeHandleToFD)(int fd, uint32_t handle, uint32_t flags, int *prime_fd); 94int (*sym_drmPrimeHandleToFD)(int fd, uint32_t handle, uint32_t flags, int *prime_fd) = NULL;
95void (*sym_drm_intel_bufmgr_destroy)(drm_intel_bufmgr *) = NULL;
94 96
95struct exynos_device *(*sym_exynos_device_create)(int fd) = NULL; 97struct exynos_device *(*sym_exynos_device_create)(int fd) = NULL;
96struct exynos_bo *(*sym_exynos_bo_create)(struct exynos_device *dev, size_t size, uint32_t flags) = NULL; 98struct exynos_bo *(*sym_exynos_bo_create)(struct exynos_device *dev, size_t size, uint32_t flags) = NULL;
97void *(*sym_exynos_bo_map)(struct exynos_bo *bo) = NULL; 99void *(*sym_exynos_bo_map)(struct exynos_bo *bo) = NULL;
98void (*sym_exynos_bo_destroy)(struct exynos_bo *bo) = NULL; 100void (*sym_exynos_bo_destroy)(struct exynos_bo *bo) = NULL;
101void (*sym_exynos_device_destroy)(struct exynos_device *) = NULL;
99 102
100static Buffer_Handle * 103static Buffer_Handle *
101_intel_alloc(Buffer_Manager *self, const char *name, int w, int h, unsigned long *stride, int32_t *fd) 104_intel_alloc(Buffer_Manager *self, const char *name, int w, int h, unsigned long *stride, int32_t *fd)
@@ -155,6 +158,12 @@ _intel_discard(Dmabuf_Buffer *buf)
155 sym_drm_intel_bo_unreference(bo); 158 sym_drm_intel_bo_unreference(bo);
156} 159}
157 160
161static void
162_intel_manager_destroy()
163{
164 sym_drm_intel_bufmgr_destroy(buffer_manager->priv);
165}
166
158static Eina_Bool 167static Eina_Bool
159_intel_buffer_manager_setup(int fd) 168_intel_buffer_manager_setup(int fd)
160{ 169{
@@ -169,6 +178,7 @@ _intel_buffer_manager_setup(int fd)
169 SYM(drm_intel_lib, drm_intel_gem_bo_map_gtt); 178 SYM(drm_intel_lib, drm_intel_gem_bo_map_gtt);
170 SYM(drm_intel_lib, drm_intel_bo_alloc_tiled); 179 SYM(drm_intel_lib, drm_intel_bo_alloc_tiled);
171 SYM(drm_intel_lib, drm_intel_bo_unreference); 180 SYM(drm_intel_lib, drm_intel_bo_unreference);
181 SYM(drm_intel_lib, drm_intel_bufmgr_destroy);
172 SYM(drm_intel_lib, drmPrimeHandleToFD); 182 SYM(drm_intel_lib, drmPrimeHandleToFD);
173 183
174 if (fail) goto err; 184 if (fail) goto err;
@@ -180,6 +190,8 @@ _intel_buffer_manager_setup(int fd)
180 buffer_manager->map = _intel_map; 190 buffer_manager->map = _intel_map;
181 buffer_manager->unmap = _intel_unmap; 191 buffer_manager->unmap = _intel_unmap;
182 buffer_manager->discard = _intel_discard; 192 buffer_manager->discard = _intel_discard;
193 buffer_manager->manager_destroy = _intel_manager_destroy;
194 buffer_manager->dl_handle = drm_intel_lib;
183 195
184 return EINA_TRUE; 196 return EINA_TRUE;
185 197
@@ -245,6 +257,12 @@ _exynos_discard(Dmabuf_Buffer *buf)
245 sym_exynos_bo_destroy(bo); 257 sym_exynos_bo_destroy(bo);
246} 258}
247 259
260static void
261_exynos_manager_destroy()
262{
263 sym_exynos_device_destroy(buffer_manager->priv);
264}
265
248static Eina_Bool 266static Eina_Bool
249_exynos_buffer_manager_setup(int fd) 267_exynos_buffer_manager_setup(int fd)
250{ 268{
@@ -258,6 +276,7 @@ _exynos_buffer_manager_setup(int fd)
258 SYM(drm_exynos_lib, exynos_bo_create); 276 SYM(drm_exynos_lib, exynos_bo_create);
259 SYM(drm_exynos_lib, exynos_bo_map); 277 SYM(drm_exynos_lib, exynos_bo_map);
260 SYM(drm_exynos_lib, exynos_bo_destroy); 278 SYM(drm_exynos_lib, exynos_bo_destroy);
279 SYM(drm_exynos_lib, exynos_device_destroy);
261 SYM(drm_exynos_lib, drmPrimeHandleToFD); 280 SYM(drm_exynos_lib, drmPrimeHandleToFD);
262 281
263 if (fail) goto err; 282 if (fail) goto err;
@@ -269,7 +288,8 @@ _exynos_buffer_manager_setup(int fd)
269 buffer_manager->map = _exynos_map; 288 buffer_manager->map = _exynos_map;
270 buffer_manager->unmap = _exynos_unmap; 289 buffer_manager->unmap = _exynos_unmap;
271 buffer_manager->discard = _exynos_discard; 290 buffer_manager->discard = _exynos_discard;
272 291 buffer_manager->manager_destroy = _exynos_manager_destroy;
292 buffer_manager->dl_handle = drm_exynos_lib;
273 return EINA_TRUE; 293 return EINA_TRUE;
274 294
275err: 295err:
@@ -308,6 +328,17 @@ err_alloc:
308} 328}
309 329
310static void 330static void
331_buffer_manager_destroy(void)
332{
333 if (!buffer_manager) return;
334
335 if (buffer_manager->manager_destroy) buffer_manager->manager_destroy();
336 free(buffer_manager);
337 buffer_manager = NULL;
338 close(drm_fd);
339}
340
341static void
311buffer_release(void *data, struct wl_buffer *buffer EINA_UNUSED) 342buffer_release(void *data, struct wl_buffer *buffer EINA_UNUSED)
312{ 343{
313 Dmabuf_Buffer *b = data; 344 Dmabuf_Buffer *b = data;
@@ -348,7 +379,7 @@ _fallback(Dmabuf_Surface *s, int w, int h)
348 if (!b) b = s->current; 379 if (!b) b = s->current;
349 if (!b) goto out; 380 if (!b) goto out;
350 381
351 if (!b->mapping) b->mapping = b->bm->map(b); 382 if (!b->mapping) b->mapping = buffer_manager->map(b);
352 if (!b->mapping) goto out; 383 if (!b->mapping) goto out;
353 384
354 epd = eo_data_scope_get(surf->info->evas, EVAS_CANVAS_CLASS); 385 epd = eo_data_scope_get(surf->info->evas, EVAS_CANVAS_CLASS);
@@ -360,10 +391,11 @@ _fallback(Dmabuf_Surface *s, int w, int h)
360 for (y = 0; y < h; y++) 391 for (y = 0; y < h; y++)
361 memcpy(new_data + y * w * 4, old_data + y * b->stride, w * 4); 392 memcpy(new_data + y * w * 4, old_data + y * b->stride, w * 4);
362 surf->funcs.post(surf, NULL, 0); 393 surf->funcs.post(surf, NULL, 0);
363 b->bm->unmap(b); 394 buffer_manager->unmap(b);
364 395
365out: 396out:
366 _internal_evas_dmabuf_surface_destroy(s); 397 _internal_evas_dmabuf_surface_destroy(s);
398 _buffer_manager_destroy();
367} 399}
368 400
369static void 401static void
@@ -436,7 +468,7 @@ static const struct zwp_linux_buffer_params_v1_listener params_listener =
436static void 468static void
437_evas_dmabuf_buffer_unlock(Dmabuf_Buffer *b) 469_evas_dmabuf_buffer_unlock(Dmabuf_Buffer *b)
438{ 470{
439 b->bm->unmap(b); 471 buffer_manager->unmap(b);
440 b->mapping = NULL; 472 b->mapping = NULL;
441 b->locked = EINA_FALSE; 473 b->locked = EINA_FALSE;
442} 474}
@@ -452,7 +484,9 @@ _evas_dmabuf_buffer_destroy(Dmabuf_Buffer *b)
452 b->surface = NULL; 484 b->surface = NULL;
453 return; 485 return;
454 } 486 }
455 b->bm->discard(b); 487 /* The buffer manager may have been destroyed already if we're
488 * doing fallback */
489 if (buffer_manager) buffer_manager->discard(b);
456 if (b->wl_buffer) wl_buffer_destroy(b->wl_buffer); 490 if (b->wl_buffer) wl_buffer_destroy(b->wl_buffer);
457 b->wl_buffer = NULL; 491 b->wl_buffer = NULL;
458 free(b); 492 free(b);
@@ -507,7 +541,7 @@ _evas_dmabuf_surface_data_get(Surface *s, int *w, int *h)
507 if (h) *h = b->h; 541 if (h) *h = b->h;
508 if (b->locked) return b->mapping; 542 if (b->locked) return b->mapping;
509 543
510 ptr = b->bm->map(b); 544 ptr = buffer_manager->map(b);
511 if (!ptr) 545 if (!ptr)
512 return NULL; 546 return NULL;
513 547
@@ -610,8 +644,6 @@ _evas_dmabuf_buffer_init(Dmabuf_Surface *s, int w, int h)
610 out = calloc(1, sizeof(Dmabuf_Buffer)); 644 out = calloc(1, sizeof(Dmabuf_Buffer));
611 if (!out) return NULL; 645 if (!out) return NULL;
612 646
613 out->bm = bm;
614
615 out->surface = s; 647 out->surface = s;
616 out->bh = bm->alloc(bm, "name", w, h, &out->stride, &out->fd); 648 out->bh = bm->alloc(bm, "name", w, h, &out->stride, &out->fd);
617 if (!out->bh) 649 if (!out->bh)