external/gbm_gralloc
Revision | 5ddecb14af4da0dda3f3817be23f1b3c54514aec (tree) |
---|---|
Time | 2018-11-02 16:56:54 |
Author | Chih-Wei Huang <cwhuang@linu...> |
Commiter | Chih-Wei Huang |
Merge remote-tracking branch 'origin/master' into oreo-x86
Conflicts:
gralloc_drm_handle.h
@@ -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 |
@@ -38,7 +38,6 @@ | ||
38 | 38 | |
39 | 39 | #include "gralloc_drm.h" |
40 | 40 | #include "gralloc_gbm_priv.h" |
41 | -#include "gralloc_drm_handle.h" | |
42 | 41 | |
43 | 42 | struct gbm_module_t { |
44 | 43 | gralloc_module_t base; |
@@ -47,37 +46,6 @@ struct gbm_module_t { | ||
47 | 46 | struct gbm_device *gbm; |
48 | 47 | }; |
49 | 48 | |
50 | -static inline int gralloc_gbm_get_bpp(int format) | |
51 | -{ | |
52 | - int bpp; | |
53 | - | |
54 | - switch (format) { | |
55 | - case HAL_PIXEL_FORMAT_RGBA_8888: | |
56 | - case HAL_PIXEL_FORMAT_RGBX_8888: | |
57 | - case HAL_PIXEL_FORMAT_BGRA_8888: | |
58 | - bpp = 4; | |
59 | - break; | |
60 | - case HAL_PIXEL_FORMAT_RGB_888: | |
61 | - bpp = 3; | |
62 | - break; | |
63 | - case HAL_PIXEL_FORMAT_RGB_565: | |
64 | - case HAL_PIXEL_FORMAT_YCbCr_422_I: | |
65 | - bpp = 2; | |
66 | - break; | |
67 | - /* planar; only Y is considered */ | |
68 | - case HAL_PIXEL_FORMAT_YV12: | |
69 | - case HAL_PIXEL_FORMAT_YCbCr_422_SP: | |
70 | - case HAL_PIXEL_FORMAT_YCrCb_420_SP: | |
71 | - bpp = 1; | |
72 | - break; | |
73 | - default: | |
74 | - bpp = 0; | |
75 | - break; | |
76 | - } | |
77 | - | |
78 | - return bpp; | |
79 | -} | |
80 | - | |
81 | 49 | /* |
82 | 50 | * Initialize the DRM device object |
83 | 51 | */ |
@@ -116,12 +84,6 @@ static int gbm_mod_perform(const struct gralloc_module_t *mod, int op, ...) | ||
116 | 84 | err = 0; |
117 | 85 | } |
118 | 86 | break; |
119 | - /* TODO: This is a stub and should be implemented fully */ | |
120 | - case GRALLOC_MODULE_PERFORM_GET_USAGE: | |
121 | - { | |
122 | - err = 0; | |
123 | - } | |
124 | - break; | |
125 | 87 | default: |
126 | 88 | err = -EINVAL; |
127 | 89 | break; |
@@ -217,23 +179,15 @@ static int gbm_mod_alloc_gpu0(alloc_device_t *dev, | ||
217 | 179 | buffer_handle_t *handle, int *stride) |
218 | 180 | { |
219 | 181 | struct gbm_module_t *dmod = (struct gbm_module_t *) dev->common.module; |
220 | - struct gralloc_gbm_handle_t *gbm_handle; | |
221 | 182 | int err = 0; |
222 | 183 | |
223 | 184 | pthread_mutex_lock(&dmod->mutex); |
224 | 185 | |
225 | - gbm_handle = gralloc_gbm_bo_create(dmod->gbm, w, h, format, usage); | |
226 | - if (!gbm_handle) { | |
186 | + *handle = gralloc_gbm_bo_create(dmod->gbm, w, h, format, usage, stride); | |
187 | + if (!*handle) | |
227 | 188 | err = -errno; |
228 | - goto unlock; | |
229 | - } | |
230 | - | |
231 | - *handle = &gbm_handle->base; | |
232 | - /* in pixels */ | |
233 | - *stride = gbm_handle->stride / gralloc_gbm_get_bpp(format); | |
234 | 189 | |
235 | 190 | ALOGV("buffer %p usage = %08x", *handle, usage); |
236 | -unlock: | |
237 | 191 | pthread_mutex_unlock(&dmod->mutex); |
238 | 192 | return err; |
239 | 193 | } |
@@ -34,13 +34,6 @@ enum { | ||
34 | 34 | * int *fd); |
35 | 35 | */ |
36 | 36 | GRALLOC_MODULE_PERFORM_GET_DRM_FD = 0x40000002, |
37 | - | |
38 | - /* perform(const struct gralloc_module_t *mod, | |
39 | - * int op, | |
40 | - * buffer_handle_t buffer, | |
41 | - * int *usage); | |
42 | - */ | |
43 | - GRALLOC_MODULE_PERFORM_GET_USAGE = 0xffeeff03, | |
44 | 37 | }; |
45 | 38 | |
46 | 39 | #ifdef __cplusplus |
@@ -1,93 +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 | -#ifdef __cplusplus | |
91 | -} | |
92 | -#endif | |
93 | -#endif /* _GRALLOC_DRM_HANDLE_H_ */ |
@@ -41,12 +41,16 @@ | ||
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 | + | |
46 | +#include <unordered_map> | |
45 | 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; |
@@ -100,6 +104,37 @@ static uint32_t get_gbm_format(int format) | ||
100 | 104 | return fmt; |
101 | 105 | } |
102 | 106 | |
107 | +static int gralloc_gbm_get_bpp(int format) | |
108 | +{ | |
109 | + int bpp; | |
110 | + | |
111 | + switch (format) { | |
112 | + case HAL_PIXEL_FORMAT_RGBA_8888: | |
113 | + case HAL_PIXEL_FORMAT_RGBX_8888: | |
114 | + case HAL_PIXEL_FORMAT_BGRA_8888: | |
115 | + bpp = 4; | |
116 | + break; | |
117 | + case HAL_PIXEL_FORMAT_RGB_888: | |
118 | + bpp = 3; | |
119 | + break; | |
120 | + case HAL_PIXEL_FORMAT_RGB_565: | |
121 | + case HAL_PIXEL_FORMAT_YCbCr_422_I: | |
122 | + bpp = 2; | |
123 | + break; | |
124 | + /* planar; only Y is considered */ | |
125 | + case HAL_PIXEL_FORMAT_YV12: | |
126 | + case HAL_PIXEL_FORMAT_YCbCr_422_SP: | |
127 | + case HAL_PIXEL_FORMAT_YCrCb_420_SP: | |
128 | + bpp = 1; | |
129 | + break; | |
130 | + default: | |
131 | + bpp = 0; | |
132 | + break; | |
133 | + } | |
134 | + | |
135 | + return bpp; | |
136 | +} | |
137 | + | |
103 | 138 | static unsigned int get_pipe_bind(int usage) |
104 | 139 | { |
105 | 140 | unsigned int bind = 0; |
@@ -112,14 +147,17 @@ static unsigned int get_pipe_bind(int usage) | ||
112 | 147 | bind |= GBM_BO_USE_RENDERING; |
113 | 148 | if (usage & GRALLOC_USAGE_HW_FB) |
114 | 149 | bind |= GBM_BO_USE_SCANOUT; |
150 | + if (usage & GRALLOC_USAGE_HW_COMPOSER) | |
151 | + bind |= GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING; | |
115 | 152 | |
116 | 153 | return bind; |
117 | 154 | } |
118 | 155 | |
119 | 156 | static struct gbm_bo *gbm_import(struct gbm_device *gbm, |
120 | - struct gralloc_gbm_handle_t *handle) | |
157 | + buffer_handle_t _handle) | |
121 | 158 | { |
122 | 159 | struct gbm_bo *bo; |
160 | + struct gralloc_handle_t *handle = gralloc_handle(_handle); | |
123 | 161 | #ifdef GBM_BO_IMPORT_FD_MODIFIER |
124 | 162 | struct gbm_import_fd_modifier_data data; |
125 | 163 | #else |
@@ -156,9 +194,10 @@ static struct gbm_bo *gbm_import(struct gbm_device *gbm, | ||
156 | 194 | } |
157 | 195 | |
158 | 196 | static struct gbm_bo *gbm_alloc(struct gbm_device *gbm, |
159 | - struct gralloc_gbm_handle_t *handle) | |
197 | + buffer_handle_t _handle) | |
160 | 198 | { |
161 | 199 | struct gbm_bo *bo; |
200 | + struct gralloc_handle_t *handle = gralloc_handle(_handle); | |
162 | 201 | int format = get_gbm_format(handle->format); |
163 | 202 | int usage = get_pipe_bind(handle->usage); |
164 | 203 | int width, height; |
@@ -206,6 +245,7 @@ void gbm_free(buffer_handle_t handle) | ||
206 | 245 | if (!bo) |
207 | 246 | return; |
208 | 247 | |
248 | + gbm_bo_handle_map.erase(handle); | |
209 | 249 | gbm_bo_destroy(bo); |
210 | 250 | } |
211 | 251 |
@@ -214,18 +254,7 @@ void gbm_free(buffer_handle_t handle) | ||
214 | 254 | */ |
215 | 255 | struct gbm_bo *gralloc_gbm_bo_from_handle(buffer_handle_t handle) |
216 | 256 | { |
217 | - int pid = getpid(); | |
218 | - struct gralloc_gbm_handle_t *gbm_handle = gralloc_gbm_handle(handle); | |
219 | - | |
220 | - if (!gbm_handle) | |
221 | - return NULL; | |
222 | - | |
223 | - /* the buffer handle is passed to a new process */ | |
224 | - ALOGV("data_owner=%d gralloc_pid=%d data=%p\n", gbm_handle->data_owner, pid, gbm_handle->data); | |
225 | - if (gbm_handle->data_owner == pid) | |
226 | - return (struct gbm_bo *)gbm_handle->data; | |
227 | - | |
228 | - return NULL; | |
257 | + return gbm_bo_handle_map[handle]; | |
229 | 258 | } |
230 | 259 | |
231 | 260 | static int gbm_map(buffer_handle_t handle, int x, int y, int w, int h, |
@@ -233,7 +262,7 @@ static int gbm_map(buffer_handle_t handle, int x, int y, int w, int h, | ||
233 | 262 | { |
234 | 263 | int err = 0; |
235 | 264 | int flags = GBM_BO_TRANSFER_READ; |
236 | - struct gralloc_gbm_handle_t *gbm_handle = gralloc_gbm_handle(handle); | |
265 | + struct gralloc_gbm_handle_t *gbm_handle = gralloc_handle(handle); | |
237 | 266 | struct gbm_bo *bo = gralloc_gbm_bo_from_handle(handle); |
238 | 267 | struct bo_data_t *bo_data = gbm_bo_data(bo); |
239 | 268 | uint32_t stride; |
@@ -243,7 +272,7 @@ static int gbm_map(buffer_handle_t handle, int x, int y, int w, int h, | ||
243 | 272 | |
244 | 273 | if (gbm_handle->format == HAL_PIXEL_FORMAT_YV12) { |
245 | 274 | if (x || y) |
246 | - ALOGE("can't map with offset for planar %p - fmt %x", bo, gbm_handle->format); | |
275 | + ALOGE("can't map with offset for planar %p", bo); | |
247 | 276 | w /= 2; |
248 | 277 | h += h / 2; |
249 | 278 | } |
@@ -305,17 +334,18 @@ struct gbm_device *gbm_dev_create(void) | ||
305 | 334 | int gralloc_gbm_handle_register(buffer_handle_t _handle, struct gbm_device *gbm) |
306 | 335 | { |
307 | 336 | struct gbm_bo *bo; |
308 | - struct gralloc_gbm_handle_t *handle = gralloc_gbm_handle(_handle); | |
309 | 337 | |
310 | - if (!handle) | |
338 | + if (!_handle) | |
311 | 339 | return -EINVAL; |
312 | 340 | |
313 | - bo = gbm_import(gbm, handle); | |
341 | + if (gbm_bo_handle_map.count(_handle)) | |
342 | + return -EINVAL; | |
343 | + | |
344 | + bo = gbm_import(gbm, _handle); | |
314 | 345 | if (!bo) |
315 | 346 | return -EINVAL; |
316 | 347 | |
317 | - handle->data_owner = getpid(); | |
318 | - handle->data = bo; | |
348 | + gbm_bo_handle_map.emplace(_handle, bo); | |
319 | 349 | |
320 | 350 | return 0; |
321 | 351 | } |
@@ -325,58 +355,34 @@ int gralloc_gbm_handle_register(buffer_handle_t _handle, struct gbm_device *gbm) | ||
325 | 355 | */ |
326 | 356 | int gralloc_gbm_handle_unregister(buffer_handle_t handle) |
327 | 357 | { |
328 | - struct gralloc_gbm_handle_t *gbm_handle = gralloc_gbm_handle(handle); | |
329 | - | |
330 | 358 | gbm_free(handle); |
331 | - gbm_handle->data_owner = 0; | |
332 | - gbm_handle->data = NULL; | |
333 | 359 | |
334 | 360 | return 0; |
335 | 361 | } |
336 | 362 | |
337 | 363 | /* |
338 | - * Create a buffer handle. | |
339 | - */ | |
340 | -static struct gralloc_gbm_handle_t *create_bo_handle(int width, | |
341 | - int height, int format, int usage) | |
342 | -{ | |
343 | - struct gralloc_gbm_handle_t *handle; | |
344 | - | |
345 | - handle = (gralloc_gbm_handle_t *)native_handle_create(GRALLOC_GBM_HANDLE_NUM_FDS, GRALLOC_GBM_HANDLE_NUM_INTS); | |
346 | - if (!handle) | |
347 | - return NULL; | |
348 | - | |
349 | - handle->magic = GRALLOC_GBM_HANDLE_MAGIC; | |
350 | - handle->width = width; | |
351 | - handle->height = height; | |
352 | - handle->format = format; | |
353 | - handle->usage = usage; | |
354 | - handle->prime_fd = -1; | |
355 | - | |
356 | - return handle; | |
357 | -} | |
358 | - | |
359 | -/* | |
360 | 364 | * Create a bo. |
361 | 365 | */ |
362 | -struct gralloc_gbm_handle_t *gralloc_gbm_bo_create(struct gbm_device *gbm, | |
363 | - int width, int height, int format, int usage) | |
366 | +buffer_handle_t gralloc_gbm_bo_create(struct gbm_device *gbm, | |
367 | + int width, int height, int format, int usage, int *stride) | |
364 | 368 | { |
365 | 369 | struct gbm_bo *bo; |
366 | - struct gralloc_gbm_handle_t *handle; | |
370 | + native_handle_t *handle; | |
367 | 371 | |
368 | - handle = create_bo_handle(width, height, format, usage); | |
372 | + handle = gralloc_handle_create(width, height, format, usage); | |
369 | 373 | if (!handle) |
370 | 374 | return NULL; |
371 | 375 | |
372 | 376 | bo = gbm_alloc(gbm, handle); |
373 | 377 | if (!bo) { |
374 | - native_handle_delete(&handle->base); | |
378 | + native_handle_delete(handle); | |
375 | 379 | return NULL; |
376 | 380 | } |
377 | 381 | |
378 | - handle->data_owner = getpid(); | |
379 | - handle->data = bo; | |
382 | + gbm_bo_handle_map.emplace(handle, bo); | |
383 | + | |
384 | + /* in pixels */ | |
385 | + *stride = gralloc_handle(handle)->stride / gralloc_gbm_get_bpp(format); | |
380 | 386 | |
381 | 387 | return handle; |
382 | 388 | } |
@@ -388,14 +394,14 @@ int gralloc_gbm_bo_lock(buffer_handle_t handle, | ||
388 | 394 | int usage, int x, int y, int w, int h, |
389 | 395 | void **addr) |
390 | 396 | { |
391 | - struct gralloc_gbm_handle_t *gbm_handle = gralloc_gbm_handle(handle); | |
397 | + struct gralloc_handle_t *gbm_handle = gralloc_handle(handle); | |
392 | 398 | struct gbm_bo *bo = gralloc_gbm_bo_from_handle(handle); |
393 | 399 | struct bo_data_t *bo_data; |
394 | 400 | |
395 | 401 | if (!bo) |
396 | 402 | return -EINVAL; |
397 | 403 | |
398 | - if ((gbm_handle->usage & usage) != usage) { | |
404 | + if ((gbm_handle->usage & usage) != (uint32_t)usage) { | |
399 | 405 | /* make FB special for testing software renderer with */ |
400 | 406 | |
401 | 407 | if (!(gbm_handle->usage & GRALLOC_USAGE_SW_READ_OFTEN) && |
@@ -32,14 +32,11 @@ 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 | |
41 | -struct gralloc_gbm_handle_t *gralloc_gbm_bo_create(struct gbm_device *gbm, | |
42 | - int width, int height, int format, int usage); | |
38 | +buffer_handle_t gralloc_gbm_bo_create(struct gbm_device *gbm, | |
39 | + int width, int height, int format, int usage, int *stride); | |
43 | 40 | void gbm_free(buffer_handle_t handle); |
44 | 41 | |
45 | 42 | struct gbm_bo *gralloc_gbm_bo_from_handle(buffer_handle_t handle); |