diff options
author | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2022-06-07 03:42:29 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2022-06-07 03:42:29 +0000 |
commit | e0c23230b07f8d5503f1daf4a513b9665b3ffddc (patch) | |
tree | fb5d559e72ccf8e9af64d410a8bbad82bbfa317e | |
parent | 290ceed1d8d7e8bafff2585927a679fb3a579d85 (diff) | |
parent | 17541616e3e1a987fe97814e27348a045ba5ed11 (diff) | |
download | mesa3d-android12L-gsi.tar.gz |
Merge "Snap for 8589293 from 26a7b2d5ec0f753a058d807250ad688caba9251c to sc-v2-platform-release am: aba6e191ff" into android12L-gsiandroid12L-gsi
-rw-r--r-- | src/egl/drivers/dri2/platform_android.c | 62 |
1 files changed, 47 insertions, 15 deletions
diff --git a/src/egl/drivers/dri2/platform_android.c b/src/egl/drivers/dri2/platform_android.c index 2b75dfa98a4..fa6949b7109 100644 --- a/src/egl/drivers/dri2/platform_android.c +++ b/src/egl/drivers/dri2/platform_android.c @@ -199,24 +199,56 @@ droid_create_image_from_prime_fds_yuv(_EGLDisplay *disp, int ret; unsigned error; - if (!dri2_dpy->gralloc->lock_ycbcr) { - _eglLog(_EGL_WARNING, "Gralloc does not support lock_ycbcr"); - return NULL; - } - memset(&ycbcr, 0, sizeof(ycbcr)); - ret = dri2_dpy->gralloc->lock_ycbcr(dri2_dpy->gralloc, buf->handle, - 0, 0, 0, 0, 0, &ycbcr); - if (ret) { - /* HACK: See droid_create_image_from_prime_fds() and - * https://issuetracker.google.com/32077885.*/ - if (buf->format == HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED) + if (dri2_dpy->gralloc->lock_ycbcr) { + ret = dri2_dpy->gralloc->lock_ycbcr(dri2_dpy->gralloc, buf->handle, + 0, 0, 0, 0, 0, &ycbcr); + if (ret) { + /* HACK: See droid_create_image_from_prime_fds() and + * https://issuetracker.google.com/32077885.*/ + if (buf->format == HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED) + return NULL; + + _eglLog(_EGL_WARNING, "gralloc->lock_ycbcr failed: %d", ret); return NULL; - - _eglLog(_EGL_WARNING, "gralloc->lock_ycbcr failed: %d", ret); - return NULL; + } + dri2_dpy->gralloc->unlock(dri2_dpy->gralloc, buf->handle); + } else { + _eglLog(_EGL_WARNING, "Gralloc does not support lock_ycbcr!"); + // HACK: Prepare a hardcoded ycrcb struct to prevent crashes while trying + // to create a YVU420_ANDROID or FLEX_YCbCr_420 (NV12) image with gralloc4 + // see: b/225392099 + if (buf->format == HAL_PIXEL_FORMAT_YV12) { + // HAL_PIXEL_FORMAT_YV12 => DRM_FORMAT_YVU420_ANDROID + // The stride of Android YV12 buffers is required to be aligned to 16 bytes + size_t luma_stride = ALIGN(buf->width, 32); + size_t chroma_stride = ALIGN(buf->width/2, 16); + ycbcr.y = 0; + ycbcr.cr = (void*)(luma_stride*buf->height); + ycbcr.cb = (void*)(luma_stride*buf->height+chroma_stride*buf->height/2); + ycbcr.ystride = luma_stride; + ycbcr.cstride = chroma_stride; + ycbcr.chroma_step = 1; + _eglLog(_EGL_WARNING, + "Using a hardcoded ycbcr struct for DRM_FORMAT_YVU420_ANDROID format."); + } else if (buf->format == HAL_PIXEL_FORMAT_YCbCr_420_888) { + // HAL_PIXEL_FORMAT_YCbCr_420_888 => DRM_FORMAT_FLEX_YCbCr_420_888 + size_t luma_stride = buf->width; + size_t chroma_stride = buf->width; + ycbcr.y = 0; + ycbcr.cr = (void*)(luma_stride*buf->height+1); + ycbcr.cb = (void*)(luma_stride*buf->height); + ycbcr.ystride = luma_stride; + ycbcr.cstride = chroma_stride; + ycbcr.chroma_step = 2; + _eglLog(_EGL_WARNING, + "Using a hardcoded ycbcr struct for DRM_FORMAT_FLEX_YCbCr_420_888 format."); + } else { + _eglLog(_EGL_WARNING, + "Unable to create an image for native YUV format %x", buf->format); + return NULL; + } } - dri2_dpy->gralloc->unlock(dri2_dpy->gralloc, buf->handle); /* When lock_ycbcr's usage argument contains no SW_READ/WRITE flags * it will return the .y/.cb/.cr pointers based on a NULL pointer, |