external/gbm_gralloc
Revision | c2518c799dc8b0db28626edd0b72c3f0fe9dace7 (tree) |
---|---|
Zeit | 2020-09-28 08:08:35 |
Autor | Chih-Wei Huang <cwhuang@linu...> |
Commiter | Chih-Wei Huang |
Merge remote-tracking branch 'origin/master' into nougat-x86
@@ -30,7 +30,8 @@ LOCAL_SHARED_LIBRARIES := \ | ||
30 | 30 | libdrm \ |
31 | 31 | libgbm \ |
32 | 32 | liblog \ |
33 | - libcutils | |
33 | + libcutils \ | |
34 | + libhardware \ | |
34 | 35 | |
35 | 36 | LOCAL_STATIC_LIBRARIES := libdrm_framebuffer |
36 | 37 |
@@ -24,7 +24,7 @@ | ||
24 | 24 | |
25 | 25 | #define LOG_TAG "GRALLOC-GBM" |
26 | 26 | |
27 | -#include <cutils/log.h> | |
27 | +#include <log/log.h> | |
28 | 28 | #include <stdlib.h> |
29 | 29 | #include <stdarg.h> |
30 | 30 | #include <string.h> |
@@ -154,6 +154,19 @@ static int gbm_mod_unlock(const gralloc_module_t *mod, buffer_handle_t handle) | ||
154 | 154 | return err; |
155 | 155 | } |
156 | 156 | |
157 | +static int gbm_mod_lock_ycbcr(gralloc_module_t const *mod, buffer_handle_t handle, | |
158 | + int usage, int x, int y, int w, int h, struct android_ycbcr *ycbcr) | |
159 | +{ | |
160 | + struct gbm_module_t *dmod = (struct gbm_module_t *) mod; | |
161 | + int err; | |
162 | + | |
163 | + pthread_mutex_lock(&dmod->mutex); | |
164 | + err = gralloc_gbm_bo_lock_ycbcr(handle, usage, x, y, w, h, ycbcr); | |
165 | + pthread_mutex_unlock(&dmod->mutex); | |
166 | + | |
167 | + return err; | |
168 | +} | |
169 | + | |
157 | 170 | static int gbm_mod_close_gpu0(struct hw_device_t *dev) |
158 | 171 | { |
159 | 172 | struct gbm_module_t *dmod = (struct gbm_module_t *)dev->module; |
@@ -270,6 +283,7 @@ struct gbm_module_t HAL_MODULE_INFO_SYM = { | ||
270 | 283 | .unregisterBuffer = gbm_mod_unregister_buffer, |
271 | 284 | .lock = gbm_mod_lock, |
272 | 285 | .unlock = gbm_mod_unlock, |
286 | + .lock_ycbcr = gbm_mod_lock_ycbcr, | |
273 | 287 | .perform = gbm_mod_perform |
274 | 288 | }, |
275 | 289 |
@@ -24,11 +24,12 @@ | ||
24 | 24 | |
25 | 25 | #define LOG_TAG "GRALLOC-GBM" |
26 | 26 | |
27 | -#include <cutils/log.h> | |
27 | +#include <log/log.h> | |
28 | 28 | #include <cutils/atomic.h> |
29 | 29 | #include <cutils/properties.h> |
30 | 30 | #include <stdlib.h> |
31 | 31 | #include <string.h> |
32 | +#include <unistd.h> | |
32 | 33 | #include <errno.h> |
33 | 34 | #include <sys/types.h> |
34 | 35 | #include <sys/stat.h> |
@@ -422,7 +423,7 @@ int gralloc_gbm_bo_lock(buffer_handle_t handle, | ||
422 | 423 | gbm_bo_set_user_data(bo, bo_data, gralloc_gbm_destroy_user_data); |
423 | 424 | } |
424 | 425 | |
425 | - ALOGI("lock bo %p, cnt=%d, usage=%x", bo, bo_data->lock_count, usage); | |
426 | + ALOGV("lock bo %p, cnt=%d, usage=%x", bo, bo_data->lock_count, usage); | |
426 | 427 | |
427 | 428 | /* allow multiple locks with compatible usages */ |
428 | 429 | if (bo_data->lock_count && (bo_data->locked_for & usage) != usage) |
@@ -430,6 +431,15 @@ int gralloc_gbm_bo_lock(buffer_handle_t handle, | ||
430 | 431 | |
431 | 432 | usage |= bo_data->locked_for; |
432 | 433 | |
434 | + /* | |
435 | + * Some users will lock with an null crop rect. | |
436 | + * Interpret this as no-crop (full buffer WxH). | |
437 | + */ | |
438 | + if (w == 0 && h == 0) { | |
439 | + w = gbm_handle->width; | |
440 | + h = gbm_handle->height; | |
441 | + } | |
442 | + | |
433 | 443 | if (usage & (GRALLOC_USAGE_SW_WRITE_MASK | |
434 | 444 | GRALLOC_USAGE_SW_READ_MASK)) { |
435 | 445 | /* the driver is supposed to wait for the bo */ |
@@ -475,3 +485,50 @@ int gralloc_gbm_bo_unlock(buffer_handle_t handle) | ||
475 | 485 | |
476 | 486 | return 0; |
477 | 487 | } |
488 | + | |
489 | +#define GRALLOC_ALIGN(value, base) (((value) + ((base)-1)) & ~((base)-1)) | |
490 | + | |
491 | +int gralloc_gbm_bo_lock_ycbcr(buffer_handle_t handle, | |
492 | + int usage, int x, int y, int w, int h, | |
493 | + struct android_ycbcr *ycbcr) | |
494 | +{ | |
495 | + struct gralloc_handle_t *hnd = gralloc_handle(handle); | |
496 | + int ystride, cstride; | |
497 | + void *addr = 0; | |
498 | + int err; | |
499 | + | |
500 | + ALOGV("handle %p, hnd %p, usage 0x%x", handle, hnd, usage); | |
501 | + | |
502 | + err = gralloc_gbm_bo_lock(handle, usage, x, y, w, h, &addr); | |
503 | + if (err) | |
504 | + return err; | |
505 | + | |
506 | + memset(ycbcr->reserved, 0, sizeof(ycbcr->reserved)); | |
507 | + | |
508 | + switch (hnd->format) { | |
509 | + case HAL_PIXEL_FORMAT_YCrCb_420_SP: | |
510 | + ystride = cstride = GRALLOC_ALIGN(hnd->width, 16); | |
511 | + ycbcr->y = addr; | |
512 | + ycbcr->cr = (unsigned char *)addr + ystride * hnd->height; | |
513 | + ycbcr->cb = (unsigned char *)addr + ystride * hnd->height + 1; | |
514 | + ycbcr->ystride = ystride; | |
515 | + ycbcr->cstride = cstride; | |
516 | + ycbcr->chroma_step = 2; | |
517 | + break; | |
518 | + case HAL_PIXEL_FORMAT_YV12: | |
519 | + ystride = hnd->width; | |
520 | + cstride = GRALLOC_ALIGN(ystride / 2, 16); | |
521 | + ycbcr->y = addr; | |
522 | + ycbcr->cr = (unsigned char *)addr + ystride * hnd->height; | |
523 | + ycbcr->cb = (unsigned char *)addr + ystride * hnd->height + cstride * hnd->height / 2; | |
524 | + ycbcr->ystride = ystride; | |
525 | + ycbcr->cstride = cstride; | |
526 | + ycbcr->chroma_step = 1; | |
527 | + break; | |
528 | + default: | |
529 | + ALOGE("Can not lock buffer, invalid format: 0x%x", hnd->format); | |
530 | + return -EINVAL; | |
531 | + } | |
532 | + | |
533 | + return 0; | |
534 | +} |
@@ -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(bool master); |
50 | 52 | void gbm_dev_destroy(struct gbm_device *gbm); |