• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javaandroidc++linuxc#objective-ccocoa誰得qtrubypythonwindowsphpgamebathyscapheguic翻訳omegattwitterframeworkbtronvb.net計画中(planning stage)testdomarduinodirectxpreviewerゲームエンジン

external/gbm_gralloc


Commit MetaInfo

Revisiond659dc35a2f90d4813edea9987ed284d31a5bd8c (tree)
Zeit2017-09-12 00:11:25
AutorRob Herring <robh@kern...>
CommiterRob Herring

Log Message

Convert gralloc_gbm_bo_t to gbm user data

Instead of wrapping struct gbm_bo with our own BO struct, make the
struct GBM BO userdata instead. This makes things clearer as to what a
BO is.

Signed-off-by: Rob Herring <robh@kernel.org>

Ändern Zusammenfassung

Diff

--- a/gralloc.cpp
+++ b/gralloc.cpp
@@ -201,24 +201,14 @@ static int gbm_mod_close_gpu0(struct hw_device_t *dev)
201201 static int gbm_mod_free_gpu0(alloc_device_t *dev, buffer_handle_t handle)
202202 {
203203 struct gbm_module_t *dmod = (struct gbm_module_t *) dev->common.module;
204- struct gralloc_gbm_bo_t *bo;
205- int err = 0;
206204
207205 pthread_mutex_lock(&dmod->mutex);
208-
209- bo = gralloc_gbm_bo_from_handle(handle);
210- if (!bo) {
211- err = -EINVAL;
212- goto unlock;
213- }
214-
215- gbm_free(bo);
206+ gbm_free(handle);
216207 native_handle_close(handle);
217208 delete handle;
218209
219-unlock:
220210 pthread_mutex_unlock(&dmod->mutex);
221- return err;
211+ return 0;
222212 }
223213
224214 static int gbm_mod_alloc_gpu0(alloc_device_t *dev,
--- a/gralloc_gbm.cpp
+++ b/gralloc_gbm.cpp
@@ -46,14 +46,25 @@
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-
5351 int lock_count;
5452 int locked_for;
5553 };
5654
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+
67+
5768 static uint32_t get_gbm_format(int format)
5869 {
5970 uint32_t fmt;
@@ -104,10 +115,10 @@ static unsigned int get_pipe_bind(int usage)
104115 return bind;
105116 }
106117
107-static struct gralloc_gbm_bo_t *gbm_import(struct gbm_device *gbm,
118+static struct gbm_bo *gbm_import(struct gbm_device *gbm,
108119 struct gralloc_gbm_handle_t *handle)
109120 {
110- struct gralloc_gbm_bo_t *buf;
121+ struct gbm_bo *bo;
111122 #ifdef GBM_BO_IMPORT_FD_MODIFIER
112123 struct gbm_import_fd_modifier_data data;
113124 #else
@@ -118,12 +129,6 @@ static struct gralloc_gbm_bo_t *gbm_import(struct gbm_device *gbm,
118129 if (handle->prime_fd < 0)
119130 return NULL;
120131
121- buf = new struct gralloc_gbm_bo_t();
122- if (!buf) {
123- ALOGE("failed to allocate pipe buffer");
124- return NULL;
125- }
126-
127132 memset(&data, 0, sizeof(data));
128133 data.width = handle->width;
129134 data.height = handle->height;
@@ -139,33 +144,24 @@ static struct gralloc_gbm_bo_t *gbm_import(struct gbm_device *gbm,
139144 data.fds[0] = handle->prime_fd;
140145 data.strides[0] = handle->stride;
141146 data.modifier = handle->modifier;
142- 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);
143148 #else
144149 data.fd = handle->prime_fd;
145150 data.stride = handle->stride;
146- buf->bo = gbm_bo_import(gbm, GBM_BO_IMPORT_FD, &data, 0);
151+ bo = gbm_bo_import(gbm, GBM_BO_IMPORT_FD, &data, 0);
147152 #endif
148- if (!buf->bo) {
149- delete buf;
150- return NULL;
151- }
152- return buf;
153+
154+ return bo;
153155 }
154156
155-static struct gralloc_gbm_bo_t *gbm_alloc(struct gbm_device *gbm,
157+static struct gbm_bo *gbm_alloc(struct gbm_device *gbm,
156158 struct gralloc_gbm_handle_t *handle)
157159 {
158- struct gralloc_gbm_bo_t *buf;
160+ struct gbm_bo *bo;
159161 int format = get_gbm_format(handle->format);
160162 int usage = get_pipe_bind(handle->usage);
161163 int width, height;
162164
163- buf = new struct gralloc_gbm_bo_t();
164- if (!buf) {
165- ALOGE("failed to allocate pipe buffer");
166- return NULL;
167- }
168-
169165 width = handle->width;
170166 height = handle->height;
171167 if (usage & GBM_BO_USE_CURSOR) {
@@ -186,33 +182,36 @@ static struct gralloc_gbm_bo_t *gbm_alloc(struct gbm_device *gbm,
186182
187183 ALOGV("create BO, size=%dx%d, fmt=%d, usage=%x",
188184 handle->width, handle->height, handle->format, usage);
189- buf->bo = gbm_bo_create(gbm, width, height, format, usage);
190- if (!buf->bo) {
185+ bo = gbm_bo_create(gbm, width, height, format, usage);
186+ if (!bo) {
191187 ALOGE("failed to create BO, size=%dx%d, fmt=%d, usage=%x",
192188 handle->width, handle->height, handle->format, usage);
193- delete buf;
194189 return NULL;
195190 }
196191
197- handle->prime_fd = gbm_bo_get_fd(buf->bo);
198- 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);
199194 #ifdef GBM_BO_IMPORT_FD_MODIFIER
200- handle->modifier = gbm_bo_get_modifier(buf->bo);
195+ handle->modifier = gbm_bo_get_modifier(bo);
201196 #endif
202197
203- return buf;
198+ return bo;
204199 }
205200
206-void gbm_free(struct gralloc_gbm_bo_t *bo)
201+void gbm_free(buffer_handle_t handle)
207202 {
208- gbm_bo_destroy(bo->bo);
209- delete bo;
203+ struct gbm_bo *bo = gralloc_gbm_bo_from_handle(handle);
204+
205+ if (!bo)
206+ return;
207+
208+ gbm_bo_destroy(bo);
210209 }
211210
212211 /*
213212 * Return the bo of a registered handle.
214213 */
215-struct gralloc_gbm_bo_t *gralloc_gbm_bo_from_handle(buffer_handle_t handle)
214+struct gbm_bo *gralloc_gbm_bo_from_handle(buffer_handle_t handle)
216215 {
217216 int pid = getpid();
218217 struct gralloc_gbm_handle_t *gbm_handle = gralloc_gbm_handle(handle);
@@ -223,7 +222,7 @@ struct gralloc_gbm_bo_t *gralloc_gbm_bo_from_handle(buffer_handle_t handle)
223222 /* the buffer handle is passed to a new process */
224223 ALOGV("data_owner=%d gralloc_pid=%d data=%p\n", gbm_handle->data_owner, pid, gbm_handle->data);
225224 if (gbm_handle->data_owner == pid)
226- return (struct gralloc_gbm_bo_t *)gbm_handle->data;
225+ return (struct gbm_bo *)gbm_handle->data;
227226
228227 return NULL;
229228 }
@@ -234,10 +233,11 @@ static int gbm_map(buffer_handle_t handle, int x, int y, int w, int h,
234233 int err = 0;
235234 int flags = GBM_BO_TRANSFER_READ;
236235 struct gralloc_gbm_handle_t *gbm_handle = gralloc_gbm_handle(handle);
237- struct gralloc_gbm_bo_t *bo = gralloc_gbm_bo_from_handle(handle);
236+ struct gbm_bo *bo = gralloc_gbm_bo_from_handle(handle);
237+ struct bo_data_t *bo_data = gbm_bo_data(bo);
238238 uint32_t stride;
239239
240- if (bo->map_data)
240+ if (bo_data->map_data)
241241 return -EINVAL;
242242
243243 if (gbm_handle->format == HAL_PIXEL_FORMAT_YV12) {
@@ -250,7 +250,7 @@ static int gbm_map(buffer_handle_t handle, int x, int y, int w, int h,
250250 if (enable_write)
251251 flags |= GBM_BO_TRANSFER_WRITE;
252252
253- *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);
254254 ALOGV("mapped bo %p (%d, %d)-(%d, %d) at %p", bo, x, y, w, h, *addr);
255255 if (*addr == NULL)
256256 return -ENOMEM;
@@ -260,10 +260,12 @@ static int gbm_map(buffer_handle_t handle, int x, int y, int w, int h,
260260 return err;
261261 }
262262
263-static void gbm_unmap(struct gralloc_gbm_bo_t *bo)
263+static void gbm_unmap(struct gbm_bo *bo)
264264 {
265- gbm_bo_unmap(bo->bo, bo->map_data);
266- 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;
267269 }
268270
269271 void gbm_dev_destroy(struct gbm_device *gbm)
@@ -301,7 +303,7 @@ struct gbm_device *gbm_dev_create(void)
301303 */
302304 int gralloc_gbm_handle_register(buffer_handle_t _handle, struct gbm_device *gbm)
303305 {
304- struct gralloc_gbm_bo_t *bo;
306+ struct gbm_bo *bo;
305307 struct gralloc_gbm_handle_t *handle = gralloc_gbm_handle(_handle);
306308
307309 if (!handle)
@@ -323,12 +325,8 @@ int gralloc_gbm_handle_register(buffer_handle_t _handle, struct gbm_device *gbm)
323325 int gralloc_gbm_handle_unregister(buffer_handle_t handle)
324326 {
325327 struct gralloc_gbm_handle_t *gbm_handle = gralloc_gbm_handle(handle);
326- struct gralloc_gbm_bo_t *bo = gralloc_gbm_bo_from_handle(handle);
327328
328- if (!bo)
329- return -EINVAL;
330-
331- gbm_free(bo);
329+ gbm_free(handle);
332330 gbm_handle->data_owner = 0;
333331 gbm_handle->data = NULL;
334332
@@ -367,7 +365,7 @@ static struct gralloc_gbm_handle_t *create_bo_handle(int width,
367365 struct gralloc_gbm_handle_t *gralloc_gbm_bo_create(struct gbm_device *gbm,
368366 int width, int height, int format, int usage)
369367 {
370- struct gralloc_gbm_bo_t *bo;
368+ struct gbm_bo *bo;
371369 struct gralloc_gbm_handle_t *handle;
372370
373371 handle = create_bo_handle(width, height, format, usage);
@@ -387,14 +385,6 @@ struct gralloc_gbm_handle_t *gralloc_gbm_bo_create(struct gbm_device *gbm,
387385 }
388386
389387 /*
390- * Get the buffer handle and stride of a bo.
391- */
392-struct gbm_bo *gralloc_gbm_bo_to_gbm_bo(struct gralloc_gbm_bo_t *_bo)
393-{
394- return _bo->bo;
395-}
396-
397-/*
398388 * Lock a bo. XXX thread-safety?
399389 */
400390 int gralloc_gbm_bo_lock(buffer_handle_t handle,
@@ -402,11 +392,12 @@ int gralloc_gbm_bo_lock(buffer_handle_t handle,
402392 void **addr)
403393 {
404394 struct gralloc_gbm_handle_t *gbm_handle = gralloc_gbm_handle(handle);
405- struct gralloc_gbm_bo_t *bo = gralloc_gbm_bo_from_handle(handle);
395+ struct gbm_bo *bo = gralloc_gbm_bo_from_handle(handle);
396+ struct bo_data_t *bo_data;
397+
406398 if (!bo)
407399 return -EINVAL;
408400
409- ALOGI("lock bo %p, cnt=%d, usage=%x", bo, bo->lock_count, usage);
410401 if ((gbm_handle->usage & usage) != usage) {
411402 /* make FB special for testing software renderer with */
412403
@@ -419,11 +410,19 @@ int gralloc_gbm_bo_lock(buffer_handle_t handle,
419410 }
420411 }
421412
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+
422421 /* allow multiple locks with compatible usages */
423- if (bo->lock_count && (bo->locked_for & usage) != usage)
422+ if (bo_data->lock_count && (bo_data->locked_for & usage) != usage)
424423 return -EINVAL;
425424
426- usage |= bo->locked_for;
425+ usage |= bo_data->locked_for;
427426
428427 if (usage & (GRALLOC_USAGE_SW_WRITE_MASK |
429428 GRALLOC_USAGE_SW_READ_MASK)) {
@@ -437,8 +436,8 @@ int gralloc_gbm_bo_lock(buffer_handle_t handle,
437436 /* kernel handles the synchronization here */
438437 }
439438
440- bo->lock_count++;
441- bo->locked_for |= usage;
439+ bo_data->lock_count++;
440+ bo_data->locked_for |= usage;
442441
443442 return 0;
444443 }
@@ -448,22 +447,25 @@ int gralloc_gbm_bo_lock(buffer_handle_t handle,
448447 */
449448 int gralloc_gbm_bo_unlock(buffer_handle_t handle)
450449 {
451- struct gralloc_gbm_bo_t *bo = gralloc_gbm_bo_from_handle(handle);
450+ struct gbm_bo *bo = gralloc_gbm_bo_from_handle(handle);
451+ struct bo_data_t *bo_data;
452452 if (!bo)
453453 return -EINVAL;
454454
455- int mapped = bo->locked_for &
455+ bo_data = gbm_bo_data(bo);
456+
457+ int mapped = bo_data->locked_for &
456458 (GRALLOC_USAGE_SW_WRITE_MASK | GRALLOC_USAGE_SW_READ_MASK);
457459
458- if (!bo->lock_count)
460+ if (!bo_data->lock_count)
459461 return 0;
460462
461463 if (mapped)
462464 gbm_unmap(bo);
463465
464- bo->lock_count--;
465- if (!bo->lock_count)
466- bo->locked_for = 0;
466+ bo_data->lock_count--;
467+ if (!bo_data->lock_count)
468+ bo_data->locked_for = 0;
467469
468470 return 0;
469471 }
--- 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
@@ -40,12 +40,11 @@ int gralloc_gbm_handle_unregister(buffer_handle_t handle);
4040
4141 struct gralloc_gbm_handle_t *gralloc_gbm_bo_create(struct gbm_device *gbm,
4242 int width, int height, int format, int usage);
43-void gbm_free(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
5049 int gralloc_gbm_bo_lock(buffer_handle_t handle, int x, int y, int w, int h, int enable_write, void **addr);
5150 int gralloc_gbm_bo_unlock(buffer_handle_t handle);