external/gbm_gralloc
修订版 | 27763e0d43cc16387d6de8ad89eafba33d5072e3 (tree) |
---|---|
时间 | 2018-07-03 07:50:01 |
作者 | Rob Herring <robh@kern...> |
Commiter | Rob Herring |
Switch to use gralloc handle defined in libdrm
Remove our custom handle definition and use the one defined in libdrm.
Signed-off-by: Rob Herring <robh@kernel.org>
@@ -27,6 +27,7 @@ LOCAL_SRC_FILES := \ | ||
27 | 27 | gralloc.cpp |
28 | 28 | |
29 | 29 | LOCAL_SHARED_LIBRARIES := \ |
30 | + libdrm \ | |
30 | 31 | libgbm \ |
31 | 32 | liblog \ |
32 | 33 | libcutils |
@@ -1,99 +0,0 @@ | ||
1 | -/* | |
2 | - * Copyright (C) 2010-2011 Chia-I Wu <olvaffe@gmail.com> | |
3 | - * Copyright (C) 2010-2011 LunarG Inc. | |
4 | - * Copyright (C) 2016 Linaro, Ltd., Rob Herring <robh@kernel.org> | |
5 | - * | |
6 | - * Permission is hereby granted, free of charge, to any person obtaining a | |
7 | - * copy of this software and associated documentation files (the "Software"), | |
8 | - * to deal in the Software without restriction, including without limitation | |
9 | - * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
10 | - * and/or sell copies of the Software, and to permit persons to whom the | |
11 | - * Software is furnished to do so, subject to the following conditions: | |
12 | - * | |
13 | - * The above copyright notice and this permission notice shall be included | |
14 | - * in all copies or substantial portions of the Software. | |
15 | - * | |
16 | - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
17 | - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
18 | - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
19 | - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
20 | - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
21 | - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |
22 | - * DEALINGS IN THE SOFTWARE. | |
23 | - */ | |
24 | - | |
25 | -#ifndef _GRALLOC_DRM_HANDLE_H_ | |
26 | -#define _GRALLOC_DRM_HANDLE_H_ | |
27 | - | |
28 | -#include <cutils/log.h> | |
29 | -#include <cutils/native_handle.h> | |
30 | -#include <system/graphics.h> | |
31 | - | |
32 | -#ifdef __cplusplus | |
33 | -extern "C" { | |
34 | -#endif | |
35 | - | |
36 | -struct gralloc_drm_handle_t { | |
37 | - native_handle_t base; | |
38 | - | |
39 | - /* file descriptors */ | |
40 | - int prime_fd; | |
41 | - | |
42 | - /* integers */ | |
43 | - int magic; | |
44 | - | |
45 | - int width; | |
46 | - int height; | |
47 | - int format; | |
48 | - int usage; | |
49 | - | |
50 | - int name; /* the name of the bo */ | |
51 | - int stride; /* the stride in bytes */ | |
52 | - int data_owner; /* owner of data (for validation) */ | |
53 | - | |
54 | - uint64_t modifier __attribute__((aligned(8))); /* buffer modifiers */ | |
55 | - union { | |
56 | - void *data; /* pointer to struct gralloc_gbm_bo_t */ | |
57 | - uint64_t reserved; | |
58 | - } __attribute__((aligned(8))); | |
59 | -}; | |
60 | -#define GRALLOC_GBM_HANDLE_MAGIC 0x5f47424d | |
61 | -#define GRALLOC_GBM_HANDLE_NUM_FDS 1 | |
62 | -#define GRALLOC_GBM_HANDLE_NUM_INTS ( \ | |
63 | - ((sizeof(struct gralloc_drm_handle_t) - sizeof(native_handle_t))/sizeof(int)) \ | |
64 | - - GRALLOC_GBM_HANDLE_NUM_FDS) | |
65 | - | |
66 | -static inline struct gralloc_drm_handle_t *gralloc_drm_handle(buffer_handle_t _handle) | |
67 | -{ | |
68 | - struct gralloc_drm_handle_t *handle = | |
69 | - (struct gralloc_drm_handle_t *) _handle; | |
70 | - | |
71 | - if (handle && (handle->base.version != sizeof(handle->base) || | |
72 | - handle->base.numInts != GRALLOC_GBM_HANDLE_NUM_INTS || | |
73 | - handle->base.numFds != GRALLOC_GBM_HANDLE_NUM_FDS || | |
74 | - handle->magic != GRALLOC_GBM_HANDLE_MAGIC)) { | |
75 | - ALOGE("invalid handle: version=%d, numInts=%d, numFds=%d, magic=%x", | |
76 | - handle->base.version, handle->base.numInts, | |
77 | - handle->base.numFds, handle->magic); | |
78 | - handle = NULL; | |
79 | - } | |
80 | - | |
81 | - return handle; | |
82 | -} | |
83 | - | |
84 | -static inline int gralloc_drm_get_prime_fd(buffer_handle_t _handle) | |
85 | -{ | |
86 | - struct gralloc_drm_handle_t *handle = gralloc_drm_handle(_handle); | |
87 | - return (handle) ? handle->prime_fd : -1; | |
88 | -} | |
89 | - | |
90 | -static inline int gralloc_drm_get_gem_handle(buffer_handle_t handle) | |
91 | -{ | |
92 | - (void)handle; | |
93 | - return 0; /* Not supported, return invalid handle. */ | |
94 | -} | |
95 | - | |
96 | -#ifdef __cplusplus | |
97 | -} | |
98 | -#endif | |
99 | -#endif /* _GRALLOC_DRM_HANDLE_H_ */ |
@@ -41,7 +41,7 @@ | ||
41 | 41 | #include <gbm.h> |
42 | 42 | |
43 | 43 | #include "gralloc_gbm_priv.h" |
44 | -#include "gralloc_drm_handle.h" | |
44 | +#include <android/gralloc_handle.h> | |
45 | 45 | |
46 | 46 | #include <unordered_map> |
47 | 47 |
@@ -152,9 +152,10 @@ static unsigned int get_pipe_bind(int usage) | ||
152 | 152 | } |
153 | 153 | |
154 | 154 | static struct gbm_bo *gbm_import(struct gbm_device *gbm, |
155 | - struct gralloc_gbm_handle_t *handle) | |
155 | + buffer_handle_t _handle) | |
156 | 156 | { |
157 | 157 | struct gbm_bo *bo; |
158 | + struct gralloc_handle_t *handle = gralloc_handle(_handle); | |
158 | 159 | #ifdef GBM_BO_IMPORT_FD_MODIFIER |
159 | 160 | struct gbm_import_fd_modifier_data data; |
160 | 161 | #else |
@@ -191,9 +192,10 @@ static struct gbm_bo *gbm_import(struct gbm_device *gbm, | ||
191 | 192 | } |
192 | 193 | |
193 | 194 | static struct gbm_bo *gbm_alloc(struct gbm_device *gbm, |
194 | - struct gralloc_gbm_handle_t *handle) | |
195 | + buffer_handle_t _handle) | |
195 | 196 | { |
196 | 197 | struct gbm_bo *bo; |
198 | + struct gralloc_handle_t *handle = gralloc_handle(_handle); | |
197 | 199 | int format = get_gbm_format(handle->format); |
198 | 200 | int usage = get_pipe_bind(handle->usage); |
199 | 201 | int width, height; |
@@ -241,6 +243,7 @@ void gbm_free(buffer_handle_t handle) | ||
241 | 243 | if (!bo) |
242 | 244 | return; |
243 | 245 | |
246 | + gbm_bo_handle_map.erase(handle); | |
244 | 247 | gbm_bo_destroy(bo); |
245 | 248 | } |
246 | 249 |
@@ -257,7 +260,7 @@ static int gbm_map(buffer_handle_t handle, int x, int y, int w, int h, | ||
257 | 260 | { |
258 | 261 | int err = 0; |
259 | 262 | int flags = GBM_BO_TRANSFER_READ; |
260 | - struct gralloc_gbm_handle_t *gbm_handle = gralloc_gbm_handle(handle); | |
263 | + struct gralloc_gbm_handle_t *gbm_handle = gralloc_handle(handle); | |
261 | 264 | struct gbm_bo *bo = gralloc_gbm_bo_from_handle(handle); |
262 | 265 | struct bo_data_t *bo_data = gbm_bo_data(bo); |
263 | 266 | uint32_t stride; |
@@ -267,7 +270,7 @@ static int gbm_map(buffer_handle_t handle, int x, int y, int w, int h, | ||
267 | 270 | |
268 | 271 | if (gbm_handle->format == HAL_PIXEL_FORMAT_YV12) { |
269 | 272 | if (x || y) |
270 | - ALOGE("can't map with offset for planar %p - fmt %x", bo, gbm_handle->format); | |
273 | + ALOGE("can't map with offset for planar %p", bo); | |
271 | 274 | w /= 2; |
272 | 275 | h += h / 2; |
273 | 276 | } |
@@ -329,15 +332,14 @@ struct gbm_device *gbm_dev_create(void) | ||
329 | 332 | int gralloc_gbm_handle_register(buffer_handle_t _handle, struct gbm_device *gbm) |
330 | 333 | { |
331 | 334 | struct gbm_bo *bo; |
332 | - struct gralloc_gbm_handle_t *handle = gralloc_gbm_handle(_handle); | |
333 | 335 | |
334 | - if (!handle) | |
336 | + if (!_handle) | |
335 | 337 | return -EINVAL; |
336 | 338 | |
337 | 339 | if (gbm_bo_handle_map.count(_handle)) |
338 | 340 | return -EINVAL; |
339 | 341 | |
340 | - bo = gbm_import(gbm, handle); | |
342 | + bo = gbm_import(gbm, _handle); | |
341 | 343 | if (!bo) |
342 | 344 | return -EINVAL; |
343 | 345 |
@@ -352,58 +354,35 @@ int gralloc_gbm_handle_register(buffer_handle_t _handle, struct gbm_device *gbm) | ||
352 | 354 | int gralloc_gbm_handle_unregister(buffer_handle_t handle) |
353 | 355 | { |
354 | 356 | gbm_free(handle); |
355 | - gbm_bo_handle_map.erase(handle); | |
356 | 357 | |
357 | 358 | return 0; |
358 | 359 | } |
359 | 360 | |
360 | 361 | /* |
361 | - * Create a buffer handle. | |
362 | - */ | |
363 | -static struct gralloc_gbm_handle_t *create_bo_handle(int width, | |
364 | - int height, int format, int usage) | |
365 | -{ | |
366 | - struct gralloc_gbm_handle_t *handle; | |
367 | - | |
368 | - handle = (gralloc_gbm_handle_t *)native_handle_create(GRALLOC_GBM_HANDLE_NUM_FDS, GRALLOC_GBM_HANDLE_NUM_INTS); | |
369 | - if (!handle) | |
370 | - return NULL; | |
371 | - | |
372 | - handle->magic = GRALLOC_GBM_HANDLE_MAGIC; | |
373 | - handle->width = width; | |
374 | - handle->height = height; | |
375 | - handle->format = format; | |
376 | - handle->usage = usage; | |
377 | - handle->prime_fd = -1; | |
378 | - | |
379 | - return handle; | |
380 | -} | |
381 | - | |
382 | -/* | |
383 | 362 | * Create a bo. |
384 | 363 | */ |
385 | 364 | buffer_handle_t gralloc_gbm_bo_create(struct gbm_device *gbm, |
386 | 365 | int width, int height, int format, int usage, int *stride) |
387 | 366 | { |
388 | 367 | struct gbm_bo *bo; |
389 | - struct gralloc_gbm_handle_t *handle; | |
368 | + native_handle_t *handle; | |
390 | 369 | |
391 | - handle = create_bo_handle(width, height, format, usage); | |
370 | + handle = gralloc_handle_create(width, height, format, usage); | |
392 | 371 | if (!handle) |
393 | 372 | return NULL; |
394 | 373 | |
395 | 374 | bo = gbm_alloc(gbm, handle); |
396 | 375 | if (!bo) { |
397 | - native_handle_delete(&handle->base); | |
376 | + native_handle_delete(handle); | |
398 | 377 | return NULL; |
399 | 378 | } |
400 | 379 | |
401 | - gbm_bo_handle_map.emplace(&handle->base, bo); | |
380 | + gbm_bo_handle_map.emplace(handle, bo); | |
402 | 381 | |
403 | 382 | /* in pixels */ |
404 | - *stride = handle->stride / gralloc_gbm_get_bpp(format); | |
383 | + *stride = gralloc_handle(handle)->stride / gralloc_gbm_get_bpp(format); | |
405 | 384 | |
406 | - return &handle->base; | |
385 | + return handle; | |
407 | 386 | } |
408 | 387 | |
409 | 388 | /* |
@@ -413,14 +392,14 @@ int gralloc_gbm_bo_lock(buffer_handle_t handle, | ||
413 | 392 | int usage, int x, int y, int w, int h, |
414 | 393 | void **addr) |
415 | 394 | { |
416 | - struct gralloc_gbm_handle_t *gbm_handle = gralloc_gbm_handle(handle); | |
395 | + struct gralloc_handle_t *gbm_handle = gralloc_handle(handle); | |
417 | 396 | struct gbm_bo *bo = gralloc_gbm_bo_from_handle(handle); |
418 | 397 | struct bo_data_t *bo_data; |
419 | 398 | |
420 | 399 | if (!bo) |
421 | 400 | return -EINVAL; |
422 | 401 | |
423 | - if ((gbm_handle->usage & usage) != usage) { | |
402 | + if ((gbm_handle->usage & usage) != (uint32_t)usage) { | |
424 | 403 | /* make FB special for testing software renderer with */ |
425 | 404 | |
426 | 405 | if (!(gbm_handle->usage & GRALLOC_USAGE_SW_READ_OFTEN) && |
@@ -32,9 +32,6 @@ extern "C" { | ||
32 | 32 | struct gbm_device; |
33 | 33 | struct gbm_bo; |
34 | 34 | |
35 | -#define gralloc_gbm_handle_t gralloc_drm_handle_t | |
36 | -#define gralloc_gbm_handle gralloc_drm_handle | |
37 | - | |
38 | 35 | int gralloc_gbm_handle_register(buffer_handle_t handle, struct gbm_device *gbm); |
39 | 36 | int gralloc_gbm_handle_unregister(buffer_handle_t handle); |
40 | 37 |