external/gbm_gralloc
Revisão | 3f7e566fd8abc0e1a90280bc7def2732abe2f41f (tree) |
---|---|
Hora | 2017-10-05 15:57:42 |
Autor | Chih-Wei Huang <cwhuang@linu...> |
Commiter | Chih-Wei Huang |
Merge remote-tracking branch 'origin/master' into nougat-x86
@@ -37,4 +37,6 @@ LOCAL_EXPORT_C_INCLUDE_DIRS := \ | ||
37 | 37 | LOCAL_MODULE := gralloc.gbm |
38 | 38 | LOCAL_MODULE_TAGS := optional |
39 | 39 | LOCAL_MODULE_RELATIVE_PATH := hw |
40 | +LOCAL_PROPRIETARY_MODULE := true | |
41 | + | |
40 | 42 | include $(BUILD_SHARED_LIBRARY) |
@@ -0,0 +1,2 @@ | ||
1 | +$(call add-clean-step, rm -f $(PRODUCT_OUT)/system/lib*/libgralloc_drm.so) | |
2 | +$(call add-clean-step, rm -f $(PRODUCT_OUT)/system/lib*/hw/gralloc.gbm.so) |
@@ -37,6 +37,7 @@ | ||
37 | 37 | |
38 | 38 | #include "gralloc_drm.h" |
39 | 39 | #include "gralloc_gbm_priv.h" |
40 | +#include "gralloc_drm_handle.h" | |
40 | 41 | |
41 | 42 | struct gbm_module_t { |
42 | 43 | gralloc_module_t base; |
@@ -163,21 +164,13 @@ static int gbm_mod_lock(const gralloc_module_t *mod, buffer_handle_t handle, | ||
163 | 164 | int usage, int x, int y, int w, int h, void **ptr) |
164 | 165 | { |
165 | 166 | struct gbm_module_t *dmod = (struct gbm_module_t *) mod; |
166 | - struct gralloc_gbm_bo_t *bo; | |
167 | 167 | int err; |
168 | 168 | |
169 | 169 | pthread_mutex_lock(&dmod->mutex); |
170 | 170 | |
171 | - bo = gralloc_gbm_bo_from_handle(handle); | |
172 | - if (!bo) { | |
173 | - err = -EINVAL; | |
174 | - goto unlock; | |
175 | - } | |
176 | - | |
177 | - err = gralloc_gbm_bo_lock(bo, usage, x, y, w, h, ptr); | |
171 | + err = gralloc_gbm_bo_lock(handle, usage, x, y, w, h, ptr); | |
178 | 172 | ALOGV("buffer %p lock usage = %08x", handle, usage); |
179 | 173 | |
180 | -unlock: | |
181 | 174 | pthread_mutex_unlock(&dmod->mutex); |
182 | 175 | return err; |
183 | 176 | } |
@@ -185,21 +178,12 @@ unlock: | ||
185 | 178 | static int gbm_mod_unlock(const gralloc_module_t *mod, buffer_handle_t handle) |
186 | 179 | { |
187 | 180 | struct gbm_module_t *dmod = (struct gbm_module_t *) mod; |
188 | - struct gralloc_gbm_bo_t *bo; | |
189 | - int err = 0; | |
181 | + int err; | |
190 | 182 | |
191 | 183 | pthread_mutex_lock(&dmod->mutex); |
192 | - | |
193 | - bo = gralloc_gbm_bo_from_handle(handle); | |
194 | - if (!bo) { | |
195 | - err = -EINVAL; | |
196 | - goto unlock; | |
197 | - } | |
198 | - | |
199 | - gralloc_gbm_bo_unlock(bo); | |
200 | - | |
201 | -unlock: | |
184 | + err = gralloc_gbm_bo_unlock(handle); | |
202 | 185 | pthread_mutex_unlock(&dmod->mutex); |
186 | + | |
203 | 187 | return err; |
204 | 188 | } |
205 | 189 |
@@ -217,22 +201,14 @@ static int gbm_mod_close_gpu0(struct hw_device_t *dev) | ||
217 | 201 | static int gbm_mod_free_gpu0(alloc_device_t *dev, buffer_handle_t handle) |
218 | 202 | { |
219 | 203 | struct gbm_module_t *dmod = (struct gbm_module_t *) dev->common.module; |
220 | - struct gralloc_gbm_bo_t *bo; | |
221 | - int err = 0; | |
222 | 204 | |
223 | 205 | pthread_mutex_lock(&dmod->mutex); |
206 | + gbm_free(handle); | |
207 | + native_handle_close(handle); | |
208 | + delete handle; | |
224 | 209 | |
225 | - bo = gralloc_gbm_bo_from_handle(handle); | |
226 | - if (!bo) { | |
227 | - err = -EINVAL; | |
228 | - goto unlock; | |
229 | - } | |
230 | - | |
231 | - gralloc_gbm_bo_decref(bo); | |
232 | - | |
233 | -unlock: | |
234 | 210 | pthread_mutex_unlock(&dmod->mutex); |
235 | - return err; | |
211 | + return 0; | |
236 | 212 | } |
237 | 213 | |
238 | 214 | static int gbm_mod_alloc_gpu0(alloc_device_t *dev, |
@@ -240,21 +216,20 @@ static int gbm_mod_alloc_gpu0(alloc_device_t *dev, | ||
240 | 216 | buffer_handle_t *handle, int *stride) |
241 | 217 | { |
242 | 218 | struct gbm_module_t *dmod = (struct gbm_module_t *) dev->common.module; |
243 | - struct gralloc_gbm_bo_t *bo; | |
219 | + struct gralloc_gbm_handle_t *gbm_handle; | |
244 | 220 | int err = 0; |
245 | 221 | |
246 | 222 | pthread_mutex_lock(&dmod->mutex); |
247 | 223 | |
248 | - bo = gralloc_gbm_bo_create(dmod->gbm, w, h, format, usage); | |
249 | - if (!bo) { | |
224 | + gbm_handle = gralloc_gbm_bo_create(dmod->gbm, w, h, format, usage); | |
225 | + if (!gbm_handle) { | |
250 | 226 | err = -errno; |
251 | 227 | goto unlock; |
252 | 228 | } |
253 | 229 | |
254 | - *handle = gralloc_gbm_bo_get_handle(bo); | |
230 | + *handle = &gbm_handle->base; | |
255 | 231 | /* in pixels */ |
256 | - *stride = gbm_bo_get_stride(gralloc_gbm_bo_to_gbm_bo(bo)) / | |
257 | - gralloc_gbm_get_bpp(format); | |
232 | + *stride = gbm_handle->stride / gralloc_gbm_get_bpp(format); | |
258 | 233 | |
259 | 234 | ALOGV("buffer %p usage = %08x", *handle, usage); |
260 | 235 | unlock: |
@@ -49,9 +49,9 @@ struct gralloc_drm_handle_t { | ||
49 | 49 | |
50 | 50 | int name; /* the name of the bo */ |
51 | 51 | int stride; /* the stride in bytes */ |
52 | - uint64_t modifier; /* buffer modifiers */ | |
53 | - | |
54 | 52 | int data_owner; /* owner of data (for validation) */ |
53 | + | |
54 | + uint64_t modifier __attribute__((aligned(8))); /* buffer modifiers */ | |
55 | 55 | union { |
56 | 56 | void *data; /* pointer to struct gralloc_gbm_bo_t */ |
57 | 57 | uint64_t reserved; |
@@ -46,21 +46,24 @@ | ||
46 | 46 | |
47 | 47 | #define unlikely(x) __builtin_expect(!!(x), 0) |
48 | 48 | |
49 | -struct gralloc_gbm_bo_t { | |
50 | - struct gbm_bo *bo; | |
49 | +struct bo_data_t { | |
51 | 50 | void *map_data; |
52 | - | |
53 | - struct gralloc_gbm_handle_t *handle; | |
54 | - | |
55 | - int imported; /* the handle is from a remote proces when true */ | |
56 | - | |
57 | 51 | int lock_count; |
58 | 52 | int locked_for; |
59 | - | |
60 | - unsigned int refcount; | |
61 | 53 | }; |
62 | 54 | |
63 | -static int32_t gralloc_gbm_pid = 0; | |
55 | +void gralloc_gbm_destroy_user_data(struct gbm_bo *bo, void *data) | |
56 | +{ | |
57 | + struct bo_data_t *bo_data = (struct bo_data_t *)data; | |
58 | + delete bo_data; | |
59 | + | |
60 | + (void)bo; | |
61 | +} | |
62 | + | |
63 | +static struct bo_data_t *gbm_bo_data(struct gbm_bo *bo) { | |
64 | + return (struct bo_data_t *)gbm_bo_get_user_data(bo); | |
65 | +} | |
66 | + | |
64 | 67 | |
65 | 68 | static uint32_t get_gbm_format(int format) |
66 | 69 | { |
@@ -112,10 +115,10 @@ static unsigned int get_pipe_bind(int usage) | ||
112 | 115 | return bind; |
113 | 116 | } |
114 | 117 | |
115 | -static struct gralloc_gbm_bo_t *gbm_import(struct gbm_device *gbm, | |
118 | +static struct gbm_bo *gbm_import(struct gbm_device *gbm, | |
116 | 119 | struct gralloc_gbm_handle_t *handle) |
117 | 120 | { |
118 | - struct gralloc_gbm_bo_t *buf; | |
121 | + struct gbm_bo *bo; | |
119 | 122 | #ifdef GBM_BO_IMPORT_FD_MODIFIER |
120 | 123 | struct gbm_import_fd_modifier_data data; |
121 | 124 | #else |
@@ -126,12 +129,6 @@ static struct gralloc_gbm_bo_t *gbm_import(struct gbm_device *gbm, | ||
126 | 129 | if (handle->prime_fd < 0) |
127 | 130 | return NULL; |
128 | 131 | |
129 | - buf = new struct gralloc_gbm_bo_t(); | |
130 | - if (!buf) { | |
131 | - ALOGE("failed to allocate pipe buffer"); | |
132 | - return NULL; | |
133 | - } | |
134 | - | |
135 | 132 | memset(&data, 0, sizeof(data)); |
136 | 133 | data.width = handle->width; |
137 | 134 | data.height = handle->height; |
@@ -147,33 +144,24 @@ static struct gralloc_gbm_bo_t *gbm_import(struct gbm_device *gbm, | ||
147 | 144 | data.fds[0] = handle->prime_fd; |
148 | 145 | data.strides[0] = handle->stride; |
149 | 146 | data.modifier = handle->modifier; |
150 | - buf->bo = gbm_bo_import(gbm, GBM_BO_IMPORT_FD_MODIFIER, &data, 0); | |
147 | + bo = gbm_bo_import(gbm, GBM_BO_IMPORT_FD_MODIFIER, &data, 0); | |
151 | 148 | #else |
152 | 149 | data.fd = handle->prime_fd; |
153 | 150 | data.stride = handle->stride; |
154 | - buf->bo = gbm_bo_import(gbm, GBM_BO_IMPORT_FD, &data, 0); | |
151 | + bo = gbm_bo_import(gbm, GBM_BO_IMPORT_FD, &data, 0); | |
155 | 152 | #endif |
156 | - if (!buf->bo) { | |
157 | - delete buf; | |
158 | - return NULL; | |
159 | - } | |
160 | - return buf; | |
153 | + | |
154 | + return bo; | |
161 | 155 | } |
162 | 156 | |
163 | -static struct gralloc_gbm_bo_t *gbm_alloc(struct gbm_device *gbm, | |
157 | +static struct gbm_bo *gbm_alloc(struct gbm_device *gbm, | |
164 | 158 | struct gralloc_gbm_handle_t *handle) |
165 | 159 | { |
166 | - struct gralloc_gbm_bo_t *buf; | |
160 | + struct gbm_bo *bo; | |
167 | 161 | int format = get_gbm_format(handle->format); |
168 | 162 | int usage = get_pipe_bind(handle->usage); |
169 | 163 | int width, height; |
170 | 164 | |
171 | - buf = new struct gralloc_gbm_bo_t(); | |
172 | - if (!buf) { | |
173 | - ALOGE("failed to allocate pipe buffer"); | |
174 | - return NULL; | |
175 | - } | |
176 | - | |
177 | 165 | width = handle->width; |
178 | 166 | height = handle->height; |
179 | 167 | if (usage & GBM_BO_USE_CURSOR) { |
@@ -194,47 +182,67 @@ static struct gralloc_gbm_bo_t *gbm_alloc(struct gbm_device *gbm, | ||
194 | 182 | |
195 | 183 | ALOGV("create BO, size=%dx%d, fmt=%d, usage=%x", |
196 | 184 | handle->width, handle->height, handle->format, usage); |
197 | - buf->bo = gbm_bo_create(gbm, width, height, format, usage); | |
198 | - if (!buf->bo) { | |
185 | + bo = gbm_bo_create(gbm, width, height, format, usage); | |
186 | + if (!bo) { | |
199 | 187 | ALOGE("failed to create BO, size=%dx%d, fmt=%d, usage=%x", |
200 | 188 | handle->width, handle->height, handle->format, usage); |
201 | - delete buf; | |
202 | 189 | return NULL; |
203 | 190 | } |
204 | 191 | |
205 | - handle->prime_fd = gbm_bo_get_fd(buf->bo); | |
206 | - handle->stride = gbm_bo_get_stride(buf->bo); | |
192 | + handle->prime_fd = gbm_bo_get_fd(bo); | |
193 | + handle->stride = gbm_bo_get_stride(bo); | |
207 | 194 | #ifdef GBM_BO_IMPORT_FD_MODIFIER |
208 | - handle->modifier = gbm_bo_get_modifier(buf->bo); | |
195 | + handle->modifier = gbm_bo_get_modifier(bo); | |
209 | 196 | #endif |
210 | 197 | |
211 | - return buf; | |
198 | + return bo; | |
212 | 199 | } |
213 | 200 | |
214 | -static void gbm_free(struct gralloc_gbm_bo_t *bo) | |
201 | +void gbm_free(buffer_handle_t handle) | |
215 | 202 | { |
216 | - struct gralloc_gbm_handle_t *handle = bo->handle; | |
203 | + struct gbm_bo *bo = gralloc_gbm_bo_from_handle(handle); | |
217 | 204 | |
218 | - close(handle->prime_fd); | |
219 | - handle->prime_fd = -1; | |
205 | + if (!bo) | |
206 | + return; | |
220 | 207 | |
221 | - gbm_bo_destroy(bo->bo); | |
222 | - delete bo; | |
208 | + gbm_bo_destroy(bo); | |
223 | 209 | } |
224 | 210 | |
225 | -static int gbm_map(struct gralloc_gbm_bo_t *bo, int x, int y, int w, int h, | |
211 | +/* | |
212 | + * Return the bo of a registered handle. | |
213 | + */ | |
214 | +struct gbm_bo *gralloc_gbm_bo_from_handle(buffer_handle_t handle) | |
215 | +{ | |
216 | + int pid = getpid(); | |
217 | + struct gralloc_gbm_handle_t *gbm_handle = gralloc_gbm_handle(handle); | |
218 | + | |
219 | + if (!gbm_handle) | |
220 | + return NULL; | |
221 | + | |
222 | + /* the buffer handle is passed to a new process */ | |
223 | + ALOGV("data_owner=%d gralloc_pid=%d data=%p\n", gbm_handle->data_owner, pid, gbm_handle->data); | |
224 | + if (gbm_handle->data_owner == pid) | |
225 | + return (struct gbm_bo *)gbm_handle->data; | |
226 | + | |
227 | + return NULL; | |
228 | +} | |
229 | + | |
230 | +static int gbm_map(buffer_handle_t handle, int x, int y, int w, int h, | |
226 | 231 | int enable_write, void **addr) |
227 | 232 | { |
228 | 233 | int err = 0; |
229 | 234 | int flags = GBM_BO_TRANSFER_READ; |
235 | + struct gralloc_gbm_handle_t *gbm_handle = gralloc_gbm_handle(handle); | |
236 | + struct gbm_bo *bo = gralloc_gbm_bo_from_handle(handle); | |
237 | + struct bo_data_t *bo_data = gbm_bo_data(bo); | |
230 | 238 | uint32_t stride; |
231 | 239 | |
232 | - if (bo->map_data) | |
240 | + if (bo_data->map_data) | |
233 | 241 | return -EINVAL; |
234 | 242 | |
235 | - if (bo->handle->format == HAL_PIXEL_FORMAT_YV12) { | |
243 | + if (gbm_handle->format == HAL_PIXEL_FORMAT_YV12) { | |
236 | 244 | if (x || y) |
237 | - ALOGE("can't map with offset for planar %p - fmt %x", bo, bo->handle->format); | |
245 | + ALOGE("can't map with offset for planar %p - fmt %x", bo, gbm_handle->format); | |
238 | 246 | w /= 2; |
239 | 247 | h += h / 2; |
240 | 248 | } |
@@ -242,7 +250,7 @@ static int gbm_map(struct gralloc_gbm_bo_t *bo, int x, int y, int w, int h, | ||
242 | 250 | if (enable_write) |
243 | 251 | flags |= GBM_BO_TRANSFER_WRITE; |
244 | 252 | |
245 | - *addr = gbm_bo_map(bo->bo, 0, 0, x + w, y + h, flags, &stride, &bo->map_data); | |
253 | + *addr = gbm_bo_map(bo, 0, 0, x + w, y + h, flags, &stride, &bo_data->map_data); | |
246 | 254 | ALOGV("mapped bo %p (%d, %d)-(%d, %d) at %p", bo, x, y, w, h, *addr); |
247 | 255 | if (*addr == NULL) |
248 | 256 | return -ENOMEM; |
@@ -252,10 +260,12 @@ static int gbm_map(struct gralloc_gbm_bo_t *bo, int x, int y, int w, int h, | ||
252 | 260 | return err; |
253 | 261 | } |
254 | 262 | |
255 | -static void gbm_unmap(struct gralloc_gbm_bo_t *bo) | |
263 | +static void gbm_unmap(struct gbm_bo *bo) | |
256 | 264 | { |
257 | - gbm_bo_unmap(bo->bo, bo->map_data); | |
258 | - bo->map_data = NULL; | |
265 | + struct bo_data_t *bo_data = gbm_bo_data(bo); | |
266 | + | |
267 | + gbm_bo_unmap(bo, bo_data->map_data); | |
268 | + bo_data->map_data = NULL; | |
259 | 269 | } |
260 | 270 | |
261 | 271 | void gbm_dev_destroy(struct gbm_device *gbm) |
@@ -289,58 +299,24 @@ struct gbm_device *gbm_dev_create(void) | ||
289 | 299 | } |
290 | 300 | |
291 | 301 | /* |
292 | - * Return the pid of the process. | |
293 | - */ | |
294 | -static int gralloc_gbm_get_pid(void) | |
295 | -{ | |
296 | - if (unlikely(!gralloc_gbm_pid)) | |
297 | - android_atomic_write((int32_t) getpid(), &gralloc_gbm_pid); | |
298 | - | |
299 | - return gralloc_gbm_pid; | |
300 | -} | |
301 | - | |
302 | -/* | |
303 | - * Validate a buffer handle and return the associated bo. | |
302 | + * Register a buffer handle. | |
304 | 303 | */ |
305 | -static struct gralloc_gbm_bo_t *validate_handle(buffer_handle_t _handle, | |
306 | - struct gbm_device *gbm) | |
304 | +int gralloc_gbm_handle_register(buffer_handle_t _handle, struct gbm_device *gbm) | |
307 | 305 | { |
308 | - struct gralloc_gbm_bo_t *bo; | |
306 | + struct gbm_bo *bo; | |
309 | 307 | struct gralloc_gbm_handle_t *handle = gralloc_gbm_handle(_handle); |
310 | 308 | |
311 | 309 | if (!handle) |
312 | - return NULL; | |
313 | - | |
314 | - /* the buffer handle is passed to a new process */ | |
315 | - //ALOGE("data_owner=%d gralloc_pid=%d data=%p\n", handle->data_owner, gralloc_gbm_get_pid(), handle->data); | |
316 | - if (handle->data_owner == gralloc_gbm_get_pid()) | |
317 | - return (struct gralloc_gbm_bo_t *)handle->data; | |
318 | - | |
319 | - /* check only */ | |
320 | - if (!gbm) | |
321 | - return NULL; | |
322 | - | |
323 | - ALOGV("handle: pfd=%d\n", handle->prime_fd); | |
310 | + return -EINVAL; | |
324 | 311 | |
325 | 312 | bo = gbm_import(gbm, handle); |
326 | - if (bo) { | |
327 | - bo->imported = 1; | |
328 | - bo->handle = handle; | |
329 | - bo->refcount = 1; | |
330 | - } | |
313 | + if (!bo) | |
314 | + return -EINVAL; | |
331 | 315 | |
332 | - handle->data_owner = gralloc_gbm_get_pid(); | |
316 | + handle->data_owner = getpid(); | |
333 | 317 | handle->data = bo; |
334 | 318 | |
335 | - return bo; | |
336 | -} | |
337 | - | |
338 | -/* | |
339 | - * Register a buffer handle. | |
340 | - */ | |
341 | -int gralloc_gbm_handle_register(buffer_handle_t handle, struct gbm_device *gbm) | |
342 | -{ | |
343 | - return (validate_handle(handle, gbm)) ? 0 : -EINVAL; | |
319 | + return 0; | |
344 | 320 | } |
345 | 321 | |
346 | 322 | /* |
@@ -348,14 +324,11 @@ int gralloc_gbm_handle_register(buffer_handle_t handle, struct gbm_device *gbm) | ||
348 | 324 | */ |
349 | 325 | int gralloc_gbm_handle_unregister(buffer_handle_t handle) |
350 | 326 | { |
351 | - struct gralloc_gbm_bo_t *bo; | |
327 | + struct gralloc_gbm_handle_t *gbm_handle = gralloc_gbm_handle(handle); | |
352 | 328 | |
353 | - bo = validate_handle(handle, NULL); | |
354 | - if (!bo) | |
355 | - return -EINVAL; | |
356 | - | |
357 | - if (bo->imported) | |
358 | - gralloc_gbm_bo_decref(bo); | |
329 | + gbm_free(handle); | |
330 | + gbm_handle->data_owner = 0; | |
331 | + gbm_handle->data = NULL; | |
359 | 332 | |
360 | 333 | return 0; |
361 | 334 | } |
@@ -389,10 +362,10 @@ static struct gralloc_gbm_handle_t *create_bo_handle(int width, | ||
389 | 362 | /* |
390 | 363 | * Create a bo. |
391 | 364 | */ |
392 | -struct gralloc_gbm_bo_t *gralloc_gbm_bo_create(struct gbm_device *gbm, | |
365 | +struct gralloc_gbm_handle_t *gralloc_gbm_bo_create(struct gbm_device *gbm, | |
393 | 366 | int width, int height, int format, int usage) |
394 | 367 | { |
395 | - struct gralloc_gbm_bo_t *bo; | |
368 | + struct gbm_bo *bo; | |
396 | 369 | struct gralloc_gbm_handle_t *handle; |
397 | 370 | |
398 | 371 | handle = create_bo_handle(width, height, format, usage); |
@@ -405,101 +378,57 @@ struct gralloc_gbm_bo_t *gralloc_gbm_bo_create(struct gbm_device *gbm, | ||
405 | 378 | return NULL; |
406 | 379 | } |
407 | 380 | |
408 | - bo->imported = 0; | |
409 | - bo->handle = handle; | |
410 | - bo->refcount = 1; | |
411 | - | |
412 | - handle->data_owner = gralloc_gbm_get_pid(); | |
381 | + handle->data_owner = getpid(); | |
413 | 382 | handle->data = bo; |
414 | 383 | |
415 | - return bo; | |
416 | -} | |
417 | - | |
418 | -/* | |
419 | - * Destroy a bo. | |
420 | - */ | |
421 | -static void gralloc_gbm_bo_destroy(struct gralloc_gbm_bo_t *bo) | |
422 | -{ | |
423 | - struct gralloc_gbm_handle_t *handle = bo->handle; | |
424 | - int imported = bo->imported; | |
425 | - | |
426 | - /* gralloc still has a reference */ | |
427 | - if (bo->refcount) | |
428 | - return; | |
429 | - | |
430 | - gbm_free(bo); | |
431 | - if (imported) { | |
432 | - handle->data_owner = 0; | |
433 | - handle->data = 0; | |
434 | - } | |
435 | - else { | |
436 | - delete handle; | |
437 | - } | |
438 | -} | |
439 | - | |
440 | -/* | |
441 | - * Decrease refcount, if no refs anymore then destroy. | |
442 | - */ | |
443 | -void gralloc_gbm_bo_decref(struct gralloc_gbm_bo_t *bo) | |
444 | -{ | |
445 | - if (!--bo->refcount) | |
446 | - gralloc_gbm_bo_destroy(bo); | |
447 | -} | |
448 | - | |
449 | -/* | |
450 | - * Return the bo of a registered handle. | |
451 | - */ | |
452 | -struct gralloc_gbm_bo_t *gralloc_gbm_bo_from_handle(buffer_handle_t handle) | |
453 | -{ | |
454 | - return validate_handle(handle, NULL); | |
455 | -} | |
456 | - | |
457 | -/* | |
458 | - * Get the buffer handle and stride of a bo. | |
459 | - */ | |
460 | -buffer_handle_t gralloc_gbm_bo_get_handle(struct gralloc_gbm_bo_t *bo) | |
461 | -{ | |
462 | - return &bo->handle->base; | |
463 | -} | |
464 | - | |
465 | -/* | |
466 | - * Get the buffer handle and stride of a bo. | |
467 | - */ | |
468 | -struct gbm_bo *gralloc_gbm_bo_to_gbm_bo(struct gralloc_gbm_bo_t *_bo) | |
469 | -{ | |
470 | - return _bo->bo; | |
384 | + return handle; | |
471 | 385 | } |
472 | 386 | |
473 | 387 | /* |
474 | 388 | * Lock a bo. XXX thread-safety? |
475 | 389 | */ |
476 | -int gralloc_gbm_bo_lock(struct gralloc_gbm_bo_t *bo, | |
390 | +int gralloc_gbm_bo_lock(buffer_handle_t handle, | |
477 | 391 | int usage, int x, int y, int w, int h, |
478 | 392 | void **addr) |
479 | 393 | { |
480 | - if ((bo->handle->usage & usage) != usage) { | |
394 | + struct gralloc_gbm_handle_t *gbm_handle = gralloc_gbm_handle(handle); | |
395 | + struct gbm_bo *bo = gralloc_gbm_bo_from_handle(handle); | |
396 | + struct bo_data_t *bo_data; | |
397 | + | |
398 | + if (!bo) | |
399 | + return -EINVAL; | |
400 | + | |
401 | + if ((gbm_handle->usage & usage) != usage) { | |
481 | 402 | /* make FB special for testing software renderer with */ |
482 | 403 | |
483 | - if (!(bo->handle->usage & GRALLOC_USAGE_SW_READ_OFTEN) && | |
484 | - !(bo->handle->usage & GRALLOC_USAGE_HW_FB) && | |
485 | - !(bo->handle->usage & GRALLOC_USAGE_HW_TEXTURE)) { | |
404 | + if (!(gbm_handle->usage & GRALLOC_USAGE_SW_READ_OFTEN) && | |
405 | + !(gbm_handle->usage & GRALLOC_USAGE_HW_FB) && | |
406 | + !(gbm_handle->usage & GRALLOC_USAGE_HW_TEXTURE)) { | |
486 | 407 | ALOGE("bo.usage:x%X/usage:x%X is not GRALLOC_USAGE_HW_FB or GRALLOC_USAGE_HW_TEXTURE", |
487 | - bo->handle->usage, usage); | |
408 | + gbm_handle->usage, usage); | |
488 | 409 | return -EINVAL; |
489 | 410 | } |
490 | 411 | } |
491 | 412 | |
413 | + bo_data = gbm_bo_data(bo); | |
414 | + if (!bo_data) { | |
415 | + bo_data = new struct bo_data_t(); | |
416 | + gbm_bo_set_user_data(bo, bo_data, gralloc_gbm_destroy_user_data); | |
417 | + } | |
418 | + | |
419 | + ALOGI("lock bo %p, cnt=%d, usage=%x", bo, bo_data->lock_count, usage); | |
420 | + | |
492 | 421 | /* allow multiple locks with compatible usages */ |
493 | - if (bo->lock_count && (bo->locked_for & usage) != usage) | |
422 | + if (bo_data->lock_count && (bo_data->locked_for & usage) != usage) | |
494 | 423 | return -EINVAL; |
495 | 424 | |
496 | - usage |= bo->locked_for; | |
425 | + usage |= bo_data->locked_for; | |
497 | 426 | |
498 | 427 | if (usage & (GRALLOC_USAGE_SW_WRITE_MASK | |
499 | 428 | GRALLOC_USAGE_SW_READ_MASK)) { |
500 | 429 | /* the driver is supposed to wait for the bo */ |
501 | 430 | int write = !!(usage & GRALLOC_USAGE_SW_WRITE_MASK); |
502 | - int err = gbm_map(bo, x, y, w, h, write, addr); | |
431 | + int err = gbm_map(handle, x, y, w, h, write, addr); | |
503 | 432 | if (err) |
504 | 433 | return err; |
505 | 434 | } |
@@ -507,8 +436,8 @@ int gralloc_gbm_bo_lock(struct gralloc_gbm_bo_t *bo, | ||
507 | 436 | /* kernel handles the synchronization here */ |
508 | 437 | } |
509 | 438 | |
510 | - bo->lock_count++; | |
511 | - bo->locked_for |= usage; | |
439 | + bo_data->lock_count++; | |
440 | + bo_data->locked_for |= usage; | |
512 | 441 | |
513 | 442 | return 0; |
514 | 443 | } |
@@ -516,18 +445,27 @@ int gralloc_gbm_bo_lock(struct gralloc_gbm_bo_t *bo, | ||
516 | 445 | /* |
517 | 446 | * Unlock a bo. |
518 | 447 | */ |
519 | -void gralloc_gbm_bo_unlock(struct gralloc_gbm_bo_t *bo) | |
448 | +int gralloc_gbm_bo_unlock(buffer_handle_t handle) | |
520 | 449 | { |
521 | - int mapped = bo->locked_for & | |
450 | + struct gbm_bo *bo = gralloc_gbm_bo_from_handle(handle); | |
451 | + struct bo_data_t *bo_data; | |
452 | + if (!bo) | |
453 | + return -EINVAL; | |
454 | + | |
455 | + bo_data = gbm_bo_data(bo); | |
456 | + | |
457 | + int mapped = bo_data->locked_for & | |
522 | 458 | (GRALLOC_USAGE_SW_WRITE_MASK | GRALLOC_USAGE_SW_READ_MASK); |
523 | 459 | |
524 | - if (!bo->lock_count) | |
525 | - return; | |
460 | + if (!bo_data->lock_count) | |
461 | + return 0; | |
526 | 462 | |
527 | 463 | if (mapped) |
528 | 464 | gbm_unmap(bo); |
529 | 465 | |
530 | - bo->lock_count--; | |
531 | - if (!bo->lock_count) | |
532 | - bo->locked_for = 0; | |
466 | + bo_data->lock_count--; | |
467 | + if (!bo_data->lock_count) | |
468 | + bo_data->locked_for = 0; | |
469 | + | |
470 | + return 0; | |
533 | 471 | } |
@@ -30,7 +30,7 @@ extern "C" { | ||
30 | 30 | #endif |
31 | 31 | |
32 | 32 | struct gbm_device; |
33 | -struct gralloc_gbm_bo_t; | |
33 | +struct gbm_bo; | |
34 | 34 | |
35 | 35 | #define gralloc_gbm_handle_t gralloc_drm_handle_t |
36 | 36 | #define gralloc_gbm_handle gralloc_drm_handle |
@@ -38,17 +38,16 @@ struct gralloc_gbm_bo_t; | ||
38 | 38 | int gralloc_gbm_handle_register(buffer_handle_t handle, struct gbm_device *gbm); |
39 | 39 | int gralloc_gbm_handle_unregister(buffer_handle_t handle); |
40 | 40 | |
41 | -struct gralloc_gbm_bo_t *gralloc_gbm_bo_create(struct gbm_device *gbm, | |
41 | +struct gralloc_gbm_handle_t *gralloc_gbm_bo_create(struct gbm_device *gbm, | |
42 | 42 | int width, int height, int format, int usage); |
43 | -void gralloc_gbm_bo_decref(struct gralloc_gbm_bo_t *bo); | |
43 | +void gbm_free(buffer_handle_t handle); | |
44 | 44 | |
45 | -struct gralloc_gbm_bo_t *gralloc_gbm_bo_from_handle(buffer_handle_t handle); | |
46 | -buffer_handle_t gralloc_gbm_bo_get_handle(struct gralloc_gbm_bo_t *bo); | |
45 | +struct gbm_bo *gralloc_gbm_bo_from_handle(buffer_handle_t handle); | |
46 | +buffer_handle_t gralloc_gbm_bo_get_handle(struct gbm_bo *bo); | |
47 | 47 | int gralloc_gbm_get_gem_handle(buffer_handle_t handle); |
48 | -struct gbm_bo *gralloc_gbm_bo_to_gbm_bo(struct gralloc_gbm_bo_t *_bo); | |
49 | 48 | |
50 | -int gralloc_gbm_bo_lock(struct gralloc_gbm_bo_t *bo, int x, int y, int w, int h, int enable_write, void **addr); | |
51 | -void gralloc_gbm_bo_unlock(struct gralloc_gbm_bo_t *bo); | |
49 | +int gralloc_gbm_bo_lock(buffer_handle_t handle, int x, int y, int w, int h, int enable_write, void **addr); | |
50 | +int gralloc_gbm_bo_unlock(buffer_handle_t handle); | |
52 | 51 | |
53 | 52 | struct gbm_device *gbm_dev_create(void); |
54 | 53 | void gbm_dev_destroy(struct gbm_device *gbm); |