Skip to content
This repository was archived by the owner on Jan 7, 2023. It is now read-only.

Commit deb323e

Browse files
harishkrupokalyankondapally
authored andcommitted
AndroidIA: egl/android: Defer format detection to gralloc
Let gralloc decide the format of the buffer when the the format is HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED Signed-off-by: Harish Krupo <harish.krupo.kps@intel.com> Conflicts: src/egl/drivers/dri2/platform_android.c
1 parent 61114ee commit deb323e

File tree

1 file changed

+51
-5
lines changed

1 file changed

+51
-5
lines changed

src/egl/drivers/dri2/platform_android.c

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141

4242
#define ALIGN(val, align) (((val) + (align) - 1) & ~((align) - 1))
4343

44+
#define GRALLOC_DRM_GET_FORMAT 1
45+
4446
struct droid_yuv_format {
4547
/* Lookup keys */
4648
int native; /* HAL_PIXEL_FORMAT_ */
@@ -218,6 +220,31 @@ droid_window_dequeue_buffer(struct dri2_egl_surface *dri2_surf)
218220
return EGL_TRUE;
219221
}
220222

223+
static int
224+
droid_resolve_format(struct dri2_egl_display *dri2_dpy,
225+
struct ANativeWindowBuffer *buf)
226+
{
227+
int format;
228+
int err;
229+
230+
if (buf->format != HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED)
231+
return buf->format;
232+
233+
const gralloc_module_t *gralloc0;
234+
gralloc0 = dri2_dpy->gralloc;
235+
236+
if (!gralloc0->perform)
237+
return -1;
238+
239+
err = gralloc0->perform(dri2_dpy->gralloc,
240+
GRALLOC_DRM_GET_FORMAT,
241+
buf->handle, &format);
242+
if (err)
243+
return -1;
244+
245+
return format;
246+
}
247+
221248
static EGLBoolean
222249
droid_window_enqueue_buffer(_EGLDisplay *disp, struct dri2_egl_surface *dri2_surf)
223250
{
@@ -696,6 +723,12 @@ droid_create_image_from_prime_fd_yuv(_EGLDisplay *disp, _EGLContext *ctx,
696723
int fourcc;
697724
int ret;
698725

726+
int format = droid_resolve_format(dri2_dpy, buf);
727+
if (format < 0) {
728+
_eglError(EGL_BAD_PARAMETER, "eglCreateEGLImageKHR");
729+
return NULL;
730+
}
731+
699732
memset(&ycbcr, 0, sizeof(ycbcr));
700733

701734
if(dri2_dpy->gralloc_version == HARDWARE_MODULE_API_VERSION(1, 0)) {
@@ -721,6 +754,12 @@ droid_create_image_from_prime_fd_yuv(_EGLDisplay *disp, _EGLContext *ctx,
721754
const gralloc_module_t *gralloc0;
722755
gralloc0 = dri2_dpy->gralloc;
723756

757+
int format = droid_resolve_format(dri2_dpy, buf);
758+
if (format < 0) {
759+
_eglError(EGL_BAD_PARAMETER, "eglCreateEGLImageKHR");
760+
return NULL;
761+
}
762+
724763
if (!gralloc0->lock_ycbcr) {
725764
_eglLog(_EGL_WARNING, "Gralloc does not support lock_ycbcr");
726765
return NULL;
@@ -757,10 +796,10 @@ droid_create_image_from_prime_fd_yuv(_EGLDisplay *disp, _EGLContext *ctx,
757796

758797
/* .chroma_step is the byte distance between the same chroma channel
759798
* values of subsequent pixels, assumed to be the same for Cb and Cr. */
760-
fourcc = get_fourcc_yuv(buf->format, is_ycrcb, ycbcr.chroma_step);
799+
fourcc = get_fourcc_yuv(format, is_ycrcb, ycbcr.chroma_step);
761800
if (fourcc == -1) {
762801
_eglLog(_EGL_WARNING, "unsupported YUV format, native = %x, is_ycrcb = %d, chroma_step = %d",
763-
buf->format, is_ycrcb, ycbcr.chroma_step);
802+
format, is_ycrcb, ycbcr.chroma_step);
764803
return NULL;
765804
}
766805

@@ -806,18 +845,25 @@ static _EGLImage *
806845
droid_create_image_from_prime_fd(_EGLDisplay *disp, _EGLContext *ctx,
807846
struct ANativeWindowBuffer *buf, int fd)
808847
{
848+
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
809849
unsigned int pitch;
810850

811-
if (is_yuv(buf->format))
851+
int format = droid_resolve_format(dri2_dpy, buf);
852+
if (format < 0) {
853+
_eglLog(_EGL_WARNING, "Could not resolve buffer format");
854+
return NULL;
855+
}
856+
857+
if (is_yuv(format))
812858
return droid_create_image_from_prime_fd_yuv(disp, ctx, buf, fd);
813859

814-
const int fourcc = get_fourcc(buf->format);
860+
const int fourcc = get_fourcc(format);
815861
if (fourcc == -1) {
816862
_eglError(EGL_BAD_PARAMETER, "eglCreateEGLImageKHR");
817863
return NULL;
818864
}
819865

820-
pitch = buf->stride * get_format_bpp(buf->format);
866+
pitch = buf->stride * get_format_bpp(format);
821867
if (pitch == 0) {
822868
_eglError(EGL_BAD_PARAMETER, "eglCreateEGLImageKHR");
823869
return NULL;

0 commit comments

Comments
 (0)