• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

external/gbm_gralloc


Commit MetaInfo

Revisionf552ac5e246f1e7d2348e4baee16d82faa25e7e7 (tree)
Time2018-07-03 07:44:01
AuthorRob Herring <robh@kern...>
CommiterRob Herring

Log Message

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>

Change Summary

Incremental Difference

--- a/gralloc_gbm.cpp
+++ b/gralloc_gbm.cpp
@@ -43,10 +43,14 @@
4343 #include "gralloc_gbm_priv.h"
4444 #include "gralloc_drm_handle.h"
4545
46+#include <unordered_map>
47+
4648 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
4749
4850 #define unlikely(x) __builtin_expect(!!(x), 0)
4951
52+static std::unordered_map<buffer_handle_t, struct gbm_bo *> gbm_bo_handle_map;
53+
5054 struct bo_data_t {
5155 void *map_data;
5256 int lock_count;
@@ -245,18 +249,7 @@ void gbm_free(buffer_handle_t handle)
245249 */
246250 struct gbm_bo *gralloc_gbm_bo_from_handle(buffer_handle_t handle)
247251 {
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];
260253 }
261254
262255 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)
341334 if (!handle)
342335 return -EINVAL;
343336
337+ if (gbm_bo_handle_map.count(_handle))
338+ return -EINVAL;
339+
344340 bo = gbm_import(gbm, handle);
345341 if (!bo)
346342 return -EINVAL;
347343
348- handle->data_owner = getpid();
349- handle->data = bo;
344+ gbm_bo_handle_map.emplace(_handle, bo);
350345
351346 return 0;
352347 }
@@ -356,11 +351,8 @@ int gralloc_gbm_handle_register(buffer_handle_t _handle, struct gbm_device *gbm)
356351 */
357352 int gralloc_gbm_handle_unregister(buffer_handle_t handle)
358353 {
359- struct gralloc_gbm_handle_t *gbm_handle = gralloc_gbm_handle(handle);
360-
361354 gbm_free(handle);
362- gbm_handle->data_owner = 0;
363- gbm_handle->data = NULL;
355+ gbm_bo_handle_map.erase(handle);
364356
365357 return 0;
366358 }
@@ -406,8 +398,7 @@ buffer_handle_t gralloc_gbm_bo_create(struct gbm_device *gbm,
406398 return NULL;
407399 }
408400
409- handle->data_owner = getpid();
410- handle->data = bo;
401+ gbm_bo_handle_map.emplace(&handle->base, bo);
411402
412403 /* in pixels */
413404 *stride = handle->stride / gralloc_gbm_get_bpp(format);