Android-x86
Fork
捐款

  • R/O
  • HTTP
  • SSH
  • HTTPS

external-gbm_gralloc: 提交

external/gbm_gralloc


Commit MetaInfo

修訂e0cd733446fd44409ccde4d987850ac30038fcc2 (tree)
時間2020-06-30 04:23:46
作者Rob Herring <robh@kern...>
CommiterGitHub

Log Message

Merge pull request #15 from pundiramit/master

support video playback

Change Summary

差異

--- a/gralloc.cpp
+++ b/gralloc.cpp
@@ -150,6 +150,19 @@ static int gbm_mod_unlock(const gralloc_module_t *mod, buffer_handle_t handle)
150150 return err;
151151 }
152152
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+
153166 static int gbm_mod_close_gpu0(struct hw_device_t *dev)
154167 {
155168 struct gbm_module_t *dmod = (struct gbm_module_t *)dev->module;
@@ -251,6 +264,7 @@ struct gbm_module_t HAL_MODULE_INFO_SYM = {
251264 .unregisterBuffer = gbm_mod_unregister_buffer,
252265 .lock = gbm_mod_lock,
253266 .unlock = gbm_mod_unlock,
267+ .lock_ycbcr = gbm_mod_lock_ycbcr,
254268 .perform = gbm_mod_perform
255269 },
256270
--- a/gralloc_gbm.cpp
+++ b/gralloc_gbm.cpp
@@ -482,3 +482,50 @@ int gralloc_gbm_bo_unlock(buffer_handle_t handle)
482482
483483 return 0;
484484 }
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+}
--- a/gralloc_gbm_priv.h
+++ b/gralloc_gbm_priv.h
@@ -43,8 +43,10 @@ struct gbm_bo *gralloc_gbm_bo_from_handle(buffer_handle_t handle);
4343 buffer_handle_t gralloc_gbm_bo_get_handle(struct gbm_bo *bo);
4444 int gralloc_gbm_get_gem_handle(buffer_handle_t handle);
4545
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);
4747 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);
4850
4951 struct gbm_device *gbm_dev_create(void);
5052 void gbm_dev_destroy(struct gbm_device *gbm);
Show on old repository browser