external/gbm_gralloc
Revision | f552ac5e246f1e7d2348e4baee16d82faa25e7e7 (tree) |
---|---|
Time | 2018-07-03 07:44:01 |
Author | Rob Herring <robh@kern...> |
Commiter | Rob Herring |
Use a std::unordered_map to lookup BOs from handles
Remove the fragile dependency on the handle 'data' pointer and
'data_owner' flag.
This idea is stolen from the CrOS minigbm gralloc implementation.
Signed-off-by: Rob Herring <robh@kernel.org>
@@ -43,10 +43,14 @@ | ||
43 | 43 | #include "gralloc_gbm_priv.h" |
44 | 44 | #include "gralloc_drm_handle.h" |
45 | 45 | |
46 | +#include <unordered_map> | |
47 | + | |
46 | 48 | #define MAX(a, b) (((a) > (b)) ? (a) : (b)) |
47 | 49 | |
48 | 50 | #define unlikely(x) __builtin_expect(!!(x), 0) |
49 | 51 | |
52 | +static std::unordered_map<buffer_handle_t, struct gbm_bo *> gbm_bo_handle_map; | |
53 | + | |
50 | 54 | struct bo_data_t { |
51 | 55 | void *map_data; |
52 | 56 | int lock_count; |
@@ -245,18 +249,7 @@ void gbm_free(buffer_handle_t handle) | ||
245 | 249 | */ |
246 | 250 | struct gbm_bo *gralloc_gbm_bo_from_handle(buffer_handle_t handle) |
247 | 251 | { |
248 | - int pid = getpid(); | |
249 | - struct gralloc_gbm_handle_t *gbm_handle = gralloc_gbm_handle(handle); | |
250 | - | |
251 | - if (!gbm_handle) | |
252 | - return NULL; | |
253 | - | |
254 | - /* the buffer handle is passed to a new process */ | |
255 | - ALOGV("data_owner=%d gralloc_pid=%d data=%p\n", gbm_handle->data_owner, pid, gbm_handle->data); | |
256 | - if (gbm_handle->data_owner == pid) | |
257 | - return (struct gbm_bo *)gbm_handle->data; | |
258 | - | |
259 | - return NULL; | |
252 | + return gbm_bo_handle_map[handle]; | |
260 | 253 | } |
261 | 254 | |
262 | 255 | static int gbm_map(buffer_handle_t handle, int x, int y, int w, int h, |
@@ -341,12 +334,14 @@ int gralloc_gbm_handle_register(buffer_handle_t _handle, struct gbm_device *gbm) | ||
341 | 334 | if (!handle) |
342 | 335 | return -EINVAL; |
343 | 336 | |
337 | + if (gbm_bo_handle_map.count(_handle)) | |
338 | + return -EINVAL; | |
339 | + | |
344 | 340 | bo = gbm_import(gbm, handle); |
345 | 341 | if (!bo) |
346 | 342 | return -EINVAL; |
347 | 343 | |
348 | - handle->data_owner = getpid(); | |
349 | - handle->data = bo; | |
344 | + gbm_bo_handle_map.emplace(_handle, bo); | |
350 | 345 | |
351 | 346 | return 0; |
352 | 347 | } |
@@ -356,11 +351,8 @@ int gralloc_gbm_handle_register(buffer_handle_t _handle, struct gbm_device *gbm) | ||
356 | 351 | */ |
357 | 352 | int gralloc_gbm_handle_unregister(buffer_handle_t handle) |
358 | 353 | { |
359 | - struct gralloc_gbm_handle_t *gbm_handle = gralloc_gbm_handle(handle); | |
360 | - | |
361 | 354 | gbm_free(handle); |
362 | - gbm_handle->data_owner = 0; | |
363 | - gbm_handle->data = NULL; | |
355 | + gbm_bo_handle_map.erase(handle); | |
364 | 356 | |
365 | 357 | return 0; |
366 | 358 | } |
@@ -406,8 +398,7 @@ buffer_handle_t gralloc_gbm_bo_create(struct gbm_device *gbm, | ||
406 | 398 | return NULL; |
407 | 399 | } |
408 | 400 | |
409 | - handle->data_owner = getpid(); | |
410 | - handle->data = bo; | |
401 | + gbm_bo_handle_map.emplace(&handle->base, bo); | |
411 | 402 | |
412 | 403 | /* in pixels */ |
413 | 404 | *stride = handle->stride / gralloc_gbm_get_bpp(format); |