• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine 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

Revision3f7e566fd8abc0e1a90280bc7def2732abe2f41f (tree)
Zeit2017-10-05 15:57:42
AutorChih-Wei Huang <cwhuang@linu...>
CommiterChih-Wei Huang

Log Message

Merge remote-tracking branch 'origin/master' into nougat-x86

Ändern Zusammenfassung

Diff

--- a/Android.mk
+++ b/Android.mk
@@ -37,4 +37,6 @@ LOCAL_EXPORT_C_INCLUDE_DIRS := \
3737 LOCAL_MODULE := gralloc.gbm
3838 LOCAL_MODULE_TAGS := optional
3939 LOCAL_MODULE_RELATIVE_PATH := hw
40+LOCAL_PROPRIETARY_MODULE := true
41+
4042 include $(BUILD_SHARED_LIBRARY)
--- /dev/null
+++ b/CleanSpec.mk
@@ -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)
--- a/gralloc.cpp
+++ b/gralloc.cpp
@@ -37,6 +37,7 @@
3737
3838 #include "gralloc_drm.h"
3939 #include "gralloc_gbm_priv.h"
40+#include "gralloc_drm_handle.h"
4041
4142 struct gbm_module_t {
4243 gralloc_module_t base;
@@ -163,21 +164,13 @@ static int gbm_mod_lock(const gralloc_module_t *mod, buffer_handle_t handle,
163164 int usage, int x, int y, int w, int h, void **ptr)
164165 {
165166 struct gbm_module_t *dmod = (struct gbm_module_t *) mod;
166- struct gralloc_gbm_bo_t *bo;
167167 int err;
168168
169169 pthread_mutex_lock(&dmod->mutex);
170170
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);
178172 ALOGV("buffer %p lock usage = %08x", handle, usage);
179173
180-unlock:
181174 pthread_mutex_unlock(&dmod->mutex);
182175 return err;
183176 }
@@ -185,21 +178,12 @@ unlock:
185178 static int gbm_mod_unlock(const gralloc_module_t *mod, buffer_handle_t handle)
186179 {
187180 struct gbm_module_t *dmod = (struct gbm_module_t *) mod;
188- struct gralloc_gbm_bo_t *bo;
189- int err = 0;
181+ int err;
190182
191183 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);
202185 pthread_mutex_unlock(&dmod->mutex);
186+
203187 return err;
204188 }
205189
@@ -217,22 +201,14 @@ static int gbm_mod_close_gpu0(struct hw_device_t *dev)
217201 static int gbm_mod_free_gpu0(alloc_device_t *dev, buffer_handle_t handle)
218202 {
219203 struct gbm_module_t *dmod = (struct gbm_module_t *) dev->common.module;
220- struct gralloc_gbm_bo_t *bo;
221- int err = 0;
222204
223205 pthread_mutex_lock(&dmod->mutex);
206+ gbm_free(handle);
207+ native_handle_close(handle);
208+ delete handle;
224209
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:
234210 pthread_mutex_unlock(&dmod->mutex);
235- return err;
211+ return 0;
236212 }
237213
238214 static int gbm_mod_alloc_gpu0(alloc_device_t *dev,
@@ -240,21 +216,20 @@ static int gbm_mod_alloc_gpu0(alloc_device_t *dev,
240216 buffer_handle_t *handle, int *stride)
241217 {
242218 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;
244220 int err = 0;
245221
246222 pthread_mutex_lock(&dmod->mutex);
247223
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) {
250226 err = -errno;
251227 goto unlock;
252228 }
253229
254- *handle = gralloc_gbm_bo_get_handle(bo);
230+ *handle = &gbm_handle->base;
255231 /* 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);
258233
259234 ALOGV("buffer %p usage = %08x", *handle, usage);
260235 unlock:
--- a/gralloc_drm_handle.h
+++ b/gralloc_drm_handle.h
@@ -49,9 +49,9 @@ struct gralloc_drm_handle_t {
4949
5050 int name; /* the name of the bo */
5151 int stride; /* the stride in bytes */
52- uint64_t modifier; /* buffer modifiers */
53-
5452 int data_owner; /* owner of data (for validation) */
53+
54+ uint64_t modifier __attribute__((aligned(8))); /* buffer modifiers */
5555 union {
5656 void *data; /* pointer to struct gralloc_gbm_bo_t */
5757 uint64_t reserved;
--- a/gralloc_gbm.cpp
+++ b/gralloc_gbm.cpp
@@ -46,21 +46,24 @@
4646
4747 #define unlikely(x) __builtin_expect(!!(x), 0)
4848
49-struct gralloc_gbm_bo_t {
50- struct gbm_bo *bo;
49+struct bo_data_t {
5150 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-
5751 int lock_count;
5852 int locked_for;
59-
60- unsigned int refcount;
6153 };
6254
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+
6467
6568 static uint32_t get_gbm_format(int format)
6669 {
@@ -112,10 +115,10 @@ static unsigned int get_pipe_bind(int usage)
112115 return bind;
113116 }
114117
115-static struct gralloc_gbm_bo_t *gbm_import(struct gbm_device *gbm,
118+static struct gbm_bo *gbm_import(struct gbm_device *gbm,
116119 struct gralloc_gbm_handle_t *handle)
117120 {
118- struct gralloc_gbm_bo_t *buf;
121+ struct gbm_bo *bo;
119122 #ifdef GBM_BO_IMPORT_FD_MODIFIER
120123 struct gbm_import_fd_modifier_data data;
121124 #else
@@ -126,12 +129,6 @@ static struct gralloc_gbm_bo_t *gbm_import(struct gbm_device *gbm,
126129 if (handle->prime_fd < 0)
127130 return NULL;
128131
129- buf = new struct gralloc_gbm_bo_t();
130- if (!buf) {
131- ALOGE("failed to allocate pipe buffer");
132- return NULL;
133- }
134-
135132 memset(&data, 0, sizeof(data));
136133 data.width = handle->width;
137134 data.height = handle->height;
@@ -147,33 +144,24 @@ static struct gralloc_gbm_bo_t *gbm_import(struct gbm_device *gbm,
147144 data.fds[0] = handle->prime_fd;
148145 data.strides[0] = handle->stride;
149146 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);
151148 #else
152149 data.fd = handle->prime_fd;
153150 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);
155152 #endif
156- if (!buf->bo) {
157- delete buf;
158- return NULL;
159- }
160- return buf;
153+
154+ return bo;
161155 }
162156
163-static struct gralloc_gbm_bo_t *gbm_alloc(struct gbm_device *gbm,
157+static struct gbm_bo *gbm_alloc(struct gbm_device *gbm,
164158 struct gralloc_gbm_handle_t *handle)
165159 {
166- struct gralloc_gbm_bo_t *buf;
160+ struct gbm_bo *bo;
167161 int format = get_gbm_format(handle->format);
168162 int usage = get_pipe_bind(handle->usage);
169163 int width, height;
170164
171- buf = new struct gralloc_gbm_bo_t();
172- if (!buf) {
173- ALOGE("failed to allocate pipe buffer");
174- return NULL;
175- }
176-
177165 width = handle->width;
178166 height = handle->height;
179167 if (usage & GBM_BO_USE_CURSOR) {
@@ -194,47 +182,67 @@ static struct gralloc_gbm_bo_t *gbm_alloc(struct gbm_device *gbm,
194182
195183 ALOGV("create BO, size=%dx%d, fmt=%d, usage=%x",
196184 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) {
199187 ALOGE("failed to create BO, size=%dx%d, fmt=%d, usage=%x",
200188 handle->width, handle->height, handle->format, usage);
201- delete buf;
202189 return NULL;
203190 }
204191
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);
207194 #ifdef GBM_BO_IMPORT_FD_MODIFIER
208- handle->modifier = gbm_bo_get_modifier(buf->bo);
195+ handle->modifier = gbm_bo_get_modifier(bo);
209196 #endif
210197
211- return buf;
198+ return bo;
212199 }
213200
214-static void gbm_free(struct gralloc_gbm_bo_t *bo)
201+void gbm_free(buffer_handle_t handle)
215202 {
216- struct gralloc_gbm_handle_t *handle = bo->handle;
203+ struct gbm_bo *bo = gralloc_gbm_bo_from_handle(handle);
217204
218- close(handle->prime_fd);
219- handle->prime_fd = -1;
205+ if (!bo)
206+ return;
220207
221- gbm_bo_destroy(bo->bo);
222- delete bo;
208+ gbm_bo_destroy(bo);
223209 }
224210
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,
226231 int enable_write, void **addr)
227232 {
228233 int err = 0;
229234 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);
230238 uint32_t stride;
231239
232- if (bo->map_data)
240+ if (bo_data->map_data)
233241 return -EINVAL;
234242
235- if (bo->handle->format == HAL_PIXEL_FORMAT_YV12) {
243+ if (gbm_handle->format == HAL_PIXEL_FORMAT_YV12) {
236244 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);
238246 w /= 2;
239247 h += h / 2;
240248 }
@@ -242,7 +250,7 @@ static int gbm_map(struct gralloc_gbm_bo_t *bo, int x, int y, int w, int h,
242250 if (enable_write)
243251 flags |= GBM_BO_TRANSFER_WRITE;
244252
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);
246254 ALOGV("mapped bo %p (%d, %d)-(%d, %d) at %p", bo, x, y, w, h, *addr);
247255 if (*addr == NULL)
248256 return -ENOMEM;
@@ -252,10 +260,12 @@ static int gbm_map(struct gralloc_gbm_bo_t *bo, int x, int y, int w, int h,
252260 return err;
253261 }
254262
255-static void gbm_unmap(struct gralloc_gbm_bo_t *bo)
263+static void gbm_unmap(struct gbm_bo *bo)
256264 {
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;
259269 }
260270
261271 void gbm_dev_destroy(struct gbm_device *gbm)
@@ -289,58 +299,24 @@ struct gbm_device *gbm_dev_create(void)
289299 }
290300
291301 /*
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.
304303 */
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)
307305 {
308- struct gralloc_gbm_bo_t *bo;
306+ struct gbm_bo *bo;
309307 struct gralloc_gbm_handle_t *handle = gralloc_gbm_handle(_handle);
310308
311309 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;
324311
325312 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;
331315
332- handle->data_owner = gralloc_gbm_get_pid();
316+ handle->data_owner = getpid();
333317 handle->data = bo;
334318
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;
344320 }
345321
346322 /*
@@ -348,14 +324,11 @@ int gralloc_gbm_handle_register(buffer_handle_t handle, struct gbm_device *gbm)
348324 */
349325 int gralloc_gbm_handle_unregister(buffer_handle_t handle)
350326 {
351- struct gralloc_gbm_bo_t *bo;
327+ struct gralloc_gbm_handle_t *gbm_handle = gralloc_gbm_handle(handle);
352328
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;
359332
360333 return 0;
361334 }
@@ -389,10 +362,10 @@ static struct gralloc_gbm_handle_t *create_bo_handle(int width,
389362 /*
390363 * Create a bo.
391364 */
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,
393366 int width, int height, int format, int usage)
394367 {
395- struct gralloc_gbm_bo_t *bo;
368+ struct gbm_bo *bo;
396369 struct gralloc_gbm_handle_t *handle;
397370
398371 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,
405378 return NULL;
406379 }
407380
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();
413382 handle->data = bo;
414383
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;
471385 }
472386
473387 /*
474388 * Lock a bo. XXX thread-safety?
475389 */
476-int gralloc_gbm_bo_lock(struct gralloc_gbm_bo_t *bo,
390+int gralloc_gbm_bo_lock(buffer_handle_t handle,
477391 int usage, int x, int y, int w, int h,
478392 void **addr)
479393 {
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) {
481402 /* make FB special for testing software renderer with */
482403
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)) {
486407 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);
488409 return -EINVAL;
489410 }
490411 }
491412
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+
492421 /* 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)
494423 return -EINVAL;
495424
496- usage |= bo->locked_for;
425+ usage |= bo_data->locked_for;
497426
498427 if (usage & (GRALLOC_USAGE_SW_WRITE_MASK |
499428 GRALLOC_USAGE_SW_READ_MASK)) {
500429 /* the driver is supposed to wait for the bo */
501430 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);
503432 if (err)
504433 return err;
505434 }
@@ -507,8 +436,8 @@ int gralloc_gbm_bo_lock(struct gralloc_gbm_bo_t *bo,
507436 /* kernel handles the synchronization here */
508437 }
509438
510- bo->lock_count++;
511- bo->locked_for |= usage;
439+ bo_data->lock_count++;
440+ bo_data->locked_for |= usage;
512441
513442 return 0;
514443 }
@@ -516,18 +445,27 @@ int gralloc_gbm_bo_lock(struct gralloc_gbm_bo_t *bo,
516445 /*
517446 * Unlock a bo.
518447 */
519-void gralloc_gbm_bo_unlock(struct gralloc_gbm_bo_t *bo)
448+int gralloc_gbm_bo_unlock(buffer_handle_t handle)
520449 {
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 &
522458 (GRALLOC_USAGE_SW_WRITE_MASK | GRALLOC_USAGE_SW_READ_MASK);
523459
524- if (!bo->lock_count)
525- return;
460+ if (!bo_data->lock_count)
461+ return 0;
526462
527463 if (mapped)
528464 gbm_unmap(bo);
529465
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;
533471 }
--- a/gralloc_gbm_priv.h
+++ b/gralloc_gbm_priv.h
@@ -30,7 +30,7 @@ extern "C" {
3030 #endif
3131
3232 struct gbm_device;
33-struct gralloc_gbm_bo_t;
33+struct gbm_bo;
3434
3535 #define gralloc_gbm_handle_t gralloc_drm_handle_t
3636 #define gralloc_gbm_handle gralloc_drm_handle
@@ -38,17 +38,16 @@ struct gralloc_gbm_bo_t;
3838 int gralloc_gbm_handle_register(buffer_handle_t handle, struct gbm_device *gbm);
3939 int gralloc_gbm_handle_unregister(buffer_handle_t handle);
4040
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,
4242 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);
4444
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);
4747 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);
4948
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);
5251
5352 struct gbm_device *gbm_dev_create(void);
5453 void gbm_dev_destroy(struct gbm_device *gbm);