• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

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

Revision13c5034a859bd548c64b44a7f64e95b6d71016ff (tree)
Time2020-06-23 18:29:10
AuthorShawn Guo <shawn.guo@lina...>
CommiterAmit Pundir

Log Message

gralloc_gbm: add .lock_ycbcr to support video playback use case

The .lock_ycbcr function hook is currently missing from gralloc driver,
and that stops video playback from working. Add a .lock_ycbcr function
implementation to get SW video playback test start working, where
HAL_PIXEL_FORMAT_YV12 format is used/tested.

Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
[AmitP: Verified by playing a mp4 format file using s/w codec

(medaswcodec) on db845c running AOSP.]

Signed-off-by: Amit Pundir <amit.pundir@linaro.org>

Change Summary

Incremental Difference

--- 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
@@ -45,6 +45,8 @@ int gralloc_gbm_get_gem_handle(buffer_handle_t handle);
4545
4646 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);