修訂 | e0cd733446fd44409ccde4d987850ac30038fcc2 (tree) |
---|---|
時間 | 2020-06-30 04:23:46 |
作者 | Rob Herring <robh@kern...> |
Commiter | GitHub |
Merge pull request #15 from pundiramit/master
support video playback
@@ -150,6 +150,19 @@ static int gbm_mod_unlock(const gralloc_module_t *mod, buffer_handle_t handle) | ||
150 | 150 | return err; |
151 | 151 | } |
152 | 152 | |
153 | +static int gbm_mod_lock_ycbcr(gralloc_module_t const *mod, buffer_handle_t handle, | |
154 | + int usage, int x, int y, int w, int h, struct android_ycbcr *ycbcr) | |
155 | +{ | |
156 | + struct gbm_module_t *dmod = (struct gbm_module_t *) mod; | |
157 | + int err; | |
158 | + | |
159 | + pthread_mutex_lock(&dmod->mutex); | |
160 | + err = gralloc_gbm_bo_lock_ycbcr(handle, usage, x, y, w, h, ycbcr); | |
161 | + pthread_mutex_unlock(&dmod->mutex); | |
162 | + | |
163 | + return err; | |
164 | +} | |
165 | + | |
153 | 166 | static int gbm_mod_close_gpu0(struct hw_device_t *dev) |
154 | 167 | { |
155 | 168 | struct gbm_module_t *dmod = (struct gbm_module_t *)dev->module; |
@@ -251,6 +264,7 @@ struct gbm_module_t HAL_MODULE_INFO_SYM = { | ||
251 | 264 | .unregisterBuffer = gbm_mod_unregister_buffer, |
252 | 265 | .lock = gbm_mod_lock, |
253 | 266 | .unlock = gbm_mod_unlock, |
267 | + .lock_ycbcr = gbm_mod_lock_ycbcr, | |
254 | 268 | .perform = gbm_mod_perform |
255 | 269 | }, |
256 | 270 |
@@ -482,3 +482,50 @@ int gralloc_gbm_bo_unlock(buffer_handle_t handle) | ||
482 | 482 | |
483 | 483 | return 0; |
484 | 484 | } |
485 | + | |
486 | +#define GRALLOC_ALIGN(value, base) (((value) + ((base)-1)) & ~((base)-1)) | |
487 | + | |
488 | +int gralloc_gbm_bo_lock_ycbcr(buffer_handle_t handle, | |
489 | + int usage, int x, int y, int w, int h, | |
490 | + struct android_ycbcr *ycbcr) | |
491 | +{ | |
492 | + struct gralloc_handle_t *hnd = gralloc_handle(handle); | |
493 | + int ystride, cstride; | |
494 | + void *addr; | |
495 | + int err; | |
496 | + | |
497 | + ALOGD("handle %p, hnd %p, usage 0x%x", handle, hnd, usage); | |
498 | + | |
499 | + err = gralloc_gbm_bo_lock(handle, usage, x, y, w, h, &addr); | |
500 | + if (err) | |
501 | + return err; | |
502 | + | |
503 | + memset(ycbcr->reserved, 0, sizeof(ycbcr->reserved)); | |
504 | + | |
505 | + switch (hnd->format) { | |
506 | + case HAL_PIXEL_FORMAT_YCrCb_420_SP: | |
507 | + ystride = cstride = GRALLOC_ALIGN(hnd->width, 16); | |
508 | + ycbcr->y = addr; | |
509 | + ycbcr->cr = (unsigned char *)addr + ystride * hnd->height; | |
510 | + ycbcr->cb = (unsigned char *)addr + ystride * hnd->height + 1; | |
511 | + ycbcr->ystride = ystride; | |
512 | + ycbcr->cstride = cstride; | |
513 | + ycbcr->chroma_step = 2; | |
514 | + break; | |
515 | + case HAL_PIXEL_FORMAT_YV12: | |
516 | + ystride = hnd->width; | |
517 | + cstride = GRALLOC_ALIGN(ystride / 2, 16); | |
518 | + ycbcr->y = addr; | |
519 | + ycbcr->cr = (unsigned char *)addr + ystride * hnd->height; | |
520 | + ycbcr->cb = (unsigned char *)addr + ystride * hnd->height + cstride * hnd->height / 2; | |
521 | + ycbcr->ystride = ystride; | |
522 | + ycbcr->cstride = cstride; | |
523 | + ycbcr->chroma_step = 1; | |
524 | + break; | |
525 | + default: | |
526 | + ALOGE("Can not lock buffer, invalid format: 0x%x", hnd->format); | |
527 | + return -EINVAL; | |
528 | + } | |
529 | + | |
530 | + return 0; | |
531 | +} |
@@ -43,8 +43,10 @@ struct gbm_bo *gralloc_gbm_bo_from_handle(buffer_handle_t handle); | ||
43 | 43 | buffer_handle_t gralloc_gbm_bo_get_handle(struct gbm_bo *bo); |
44 | 44 | int gralloc_gbm_get_gem_handle(buffer_handle_t handle); |
45 | 45 | |
46 | -int gralloc_gbm_bo_lock(buffer_handle_t handle, int x, int y, int w, int h, int enable_write, void **addr); | |
46 | +int gralloc_gbm_bo_lock(buffer_handle_t handle, int usage, int x, int y, int w, int h, void **addr); | |
47 | 47 | int gralloc_gbm_bo_unlock(buffer_handle_t handle); |
48 | +int gralloc_gbm_bo_lock_ycbcr(buffer_handle_t handle, int usage, | |
49 | + int x, int y, int w, int h, struct android_ycbcr *ycbcr); | |
48 | 50 | |
49 | 51 | struct gbm_device *gbm_dev_create(void); |
50 | 52 | void gbm_dev_destroy(struct gbm_device *gbm); |