• 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

Revisionace14fb65bc6b37e90c775dd34899c7a087f4187 (tree)
Zeit2017-09-07 01:48:40
AutorRob Herring <robh@kern...>
CommiterRob Herring

Log Message

remove handle from BO

Pass the handle to internal functions instead of the BO pointer, then we
can always get the BO from the handle and never need to get the handle
from the BO.

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

Ändern Zusammenfassung

Diff

--- 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
@@ -242,21 +226,20 @@ static int gbm_mod_alloc_gpu0(alloc_device_t *dev,
242226 buffer_handle_t *handle, int *stride)
243227 {
244228 struct gbm_module_t *dmod = (struct gbm_module_t *) dev->common.module;
245- struct gralloc_gbm_bo_t *bo;
229+ struct gralloc_gbm_handle_t *gbm_handle;
246230 int err = 0;
247231
248232 pthread_mutex_lock(&dmod->mutex);
249233
250- bo = gralloc_gbm_bo_create(dmod->gbm, w, h, format, usage);
251- if (!bo) {
234+ gbm_handle = gralloc_gbm_bo_create(dmod->gbm, w, h, format, usage);
235+ if (!gbm_handle) {
252236 err = -errno;
253237 goto unlock;
254238 }
255239
256- *handle = gralloc_gbm_bo_get_handle(bo);
240+ *handle = &gbm_handle->base;
257241 /* in pixels */
258- *stride = gbm_bo_get_stride(gralloc_gbm_bo_to_gbm_bo(bo)) /
259- gralloc_gbm_get_bpp(format);
242+ *stride = gbm_handle->stride / gralloc_gbm_get_bpp(format);
260243
261244 ALOGV("buffer %p usage = %08x", *handle, usage);
262245 unlock:
--- a/gralloc_gbm.cpp
+++ b/gralloc_gbm.cpp
@@ -50,8 +50,6 @@ struct gralloc_gbm_bo_t {
5050 struct gbm_bo *bo;
5151 void *map_data;
5252
53- struct gralloc_gbm_handle_t *handle;
54-
5553 int lock_count;
5654 int locked_for;
5755 };
@@ -213,19 +211,40 @@ void gbm_free(struct gralloc_gbm_bo_t *bo)
213211 delete bo;
214212 }
215213
216-static int gbm_map(struct gralloc_gbm_bo_t *bo, int x, int y, int w, int h,
214+/*
215+ * Return the bo of a registered handle.
216+ */
217+struct gralloc_gbm_bo_t *gralloc_gbm_bo_from_handle(buffer_handle_t handle)
218+{
219+ int pid = getpid();
220+ struct gralloc_gbm_handle_t *gbm_handle = gralloc_gbm_handle(handle);
221+
222+ if (!gbm_handle)
223+ return NULL;
224+
225+ /* the buffer handle is passed to a new process */
226+ ALOGV("data_owner=%d gralloc_pid=%d data=%p\n", gbm_handle->data_owner, pid, gbm_handle->data);
227+ if (gbm_handle->data_owner == pid)
228+ return (struct gralloc_gbm_bo_t *)gbm_handle->data;
229+
230+ return NULL;
231+}
232+
233+static int gbm_map(buffer_handle_t handle, int x, int y, int w, int h,
217234 int enable_write, void **addr)
218235 {
219236 int err = 0;
220237 int flags = GBM_BO_TRANSFER_READ;
238+ struct gralloc_gbm_handle_t *gbm_handle = gralloc_gbm_handle(handle);
239+ struct gralloc_gbm_bo_t *bo = gralloc_gbm_bo_from_handle(handle);
221240 uint32_t stride;
222241
223242 if (bo->map_data)
224243 return -EINVAL;
225244
226- if (bo->handle->format == HAL_PIXEL_FORMAT_YV12) {
245+ if (gbm_handle->format == HAL_PIXEL_FORMAT_YV12) {
227246 if (x || y)
228- ALOGE("can't map with offset for planar %p - fmt %x", bo, bo->handle->format);
247+ ALOGE("can't map with offset for planar %p - fmt %x", bo, gbm_handle->format);
229248 w /= 2;
230249 h += h / 2;
231250 }
@@ -314,8 +333,6 @@ static struct gralloc_gbm_bo_t *validate_handle(buffer_handle_t _handle,
314333 ALOGV("handle: pfd=%d\n", handle->prime_fd);
315334
316335 bo = gbm_import(gbm, handle);
317- if (bo)
318- bo->handle = handle;
319336
320337 handle->data_owner = gralloc_gbm_get_pid();
321338 handle->data = bo;
@@ -379,7 +396,7 @@ static struct gralloc_gbm_handle_t *create_bo_handle(int width,
379396 /*
380397 * Create a bo.
381398 */
382-struct gralloc_gbm_bo_t *gralloc_gbm_bo_create(struct gbm_device *gbm,
399+struct gralloc_gbm_handle_t *gralloc_gbm_bo_create(struct gbm_device *gbm,
383400 int width, int height, int format, int usage)
384401 {
385402 struct gralloc_gbm_bo_t *bo;
@@ -395,28 +412,10 @@ struct gralloc_gbm_bo_t *gralloc_gbm_bo_create(struct gbm_device *gbm,
395412 return NULL;
396413 }
397414
398- bo->handle = handle;
399-
400415 handle->data_owner = gralloc_gbm_get_pid();
401416 handle->data = bo;
402417
403- return bo;
404-}
405-
406-/*
407- * Return the bo of a registered handle.
408- */
409-struct gralloc_gbm_bo_t *gralloc_gbm_bo_from_handle(buffer_handle_t handle)
410-{
411- return validate_handle(handle, NULL);
412-}
413-
414-/*
415- * Get the buffer handle and stride of a bo.
416- */
417-buffer_handle_t gralloc_gbm_bo_get_handle(struct gralloc_gbm_bo_t *bo)
418-{
419- return &bo->handle->base;
418+ return handle;
420419 }
421420
422421 /*
@@ -430,18 +429,24 @@ struct gbm_bo *gralloc_gbm_bo_to_gbm_bo(struct gralloc_gbm_bo_t *_bo)
430429 /*
431430 * Lock a bo. XXX thread-safety?
432431 */
433-int gralloc_gbm_bo_lock(struct gralloc_gbm_bo_t *bo,
432+int gralloc_gbm_bo_lock(buffer_handle_t handle,
434433 int usage, int x, int y, int w, int h,
435434 void **addr)
436435 {
437- if ((bo->handle->usage & usage) != usage) {
436+ struct gralloc_gbm_handle_t *gbm_handle = gralloc_gbm_handle(handle);
437+ struct gralloc_gbm_bo_t *bo = gralloc_gbm_bo_from_handle(handle);
438+ if (!bo)
439+ return -EINVAL;
440+
441+ ALOGI("lock bo %p, cnt=%d, usage=%x", bo, bo->lock_count, usage);
442+ if ((gbm_handle->usage & usage) != usage) {
438443 /* make FB special for testing software renderer with */
439444
440- if (!(bo->handle->usage & GRALLOC_USAGE_SW_READ_OFTEN) &&
441- !(bo->handle->usage & GRALLOC_USAGE_HW_FB) &&
442- !(bo->handle->usage & GRALLOC_USAGE_HW_TEXTURE)) {
445+ if (!(gbm_handle->usage & GRALLOC_USAGE_SW_READ_OFTEN) &&
446+ !(gbm_handle->usage & GRALLOC_USAGE_HW_FB) &&
447+ !(gbm_handle->usage & GRALLOC_USAGE_HW_TEXTURE)) {
443448 ALOGE("bo.usage:x%X/usage:x%X is not GRALLOC_USAGE_HW_FB or GRALLOC_USAGE_HW_TEXTURE",
444- bo->handle->usage, usage);
449+ gbm_handle->usage, usage);
445450 return -EINVAL;
446451 }
447452 }
@@ -456,7 +461,7 @@ int gralloc_gbm_bo_lock(struct gralloc_gbm_bo_t *bo,
456461 GRALLOC_USAGE_SW_READ_MASK)) {
457462 /* the driver is supposed to wait for the bo */
458463 int write = !!(usage & GRALLOC_USAGE_SW_WRITE_MASK);
459- int err = gbm_map(bo, x, y, w, h, write, addr);
464+ int err = gbm_map(handle, x, y, w, h, write, addr);
460465 if (err)
461466 return err;
462467 }
@@ -473,13 +478,17 @@ int gralloc_gbm_bo_lock(struct gralloc_gbm_bo_t *bo,
473478 /*
474479 * Unlock a bo.
475480 */
476-void gralloc_gbm_bo_unlock(struct gralloc_gbm_bo_t *bo)
481+int gralloc_gbm_bo_unlock(buffer_handle_t handle)
477482 {
483+ struct gralloc_gbm_bo_t *bo = gralloc_gbm_bo_from_handle(handle);
484+ if (!bo)
485+ return -EINVAL;
486+
478487 int mapped = bo->locked_for &
479488 (GRALLOC_USAGE_SW_WRITE_MASK | GRALLOC_USAGE_SW_READ_MASK);
480489
481490 if (!bo->lock_count)
482- return;
491+ return 0;
483492
484493 if (mapped)
485494 gbm_unmap(bo);
@@ -487,4 +496,6 @@ void gralloc_gbm_bo_unlock(struct gralloc_gbm_bo_t *bo)
487496 bo->lock_count--;
488497 if (!bo->lock_count)
489498 bo->locked_for = 0;
499+
500+ return 0;
490501 }
--- a/gralloc_gbm_priv.h
+++ b/gralloc_gbm_priv.h
@@ -38,7 +38,7 @@ 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);
4343 void gbm_free(struct gralloc_gbm_bo_t *bo);
4444
@@ -47,8 +47,8 @@ buffer_handle_t gralloc_gbm_bo_get_handle(struct gralloc_gbm_bo_t *bo);
4747 int gralloc_gbm_get_gem_handle(buffer_handle_t handle);
4848 struct gbm_bo *gralloc_gbm_bo_to_gbm_bo(struct gralloc_gbm_bo_t *_bo);
4949
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);
50+int gralloc_gbm_bo_lock(buffer_handle_t handle, int x, int y, int w, int h, int enable_write, void **addr);
51+int gralloc_gbm_bo_unlock(buffer_handle_t handle);
5252
5353 struct gbm_device *gbm_dev_create(void);
5454 void gbm_dev_destroy(struct gbm_device *gbm);