41
41
42
42
#define ALIGN (val , align ) (((val) + (align) - 1) & ~((align) - 1))
43
43
44
+ #define GRALLOC_DRM_GET_FORMAT 1
45
+
44
46
struct droid_yuv_format {
45
47
/* Lookup keys */
46
48
int native ; /* HAL_PIXEL_FORMAT_ */
@@ -218,6 +220,31 @@ droid_window_dequeue_buffer(struct dri2_egl_surface *dri2_surf)
218
220
return EGL_TRUE ;
219
221
}
220
222
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
+
221
248
static EGLBoolean
222
249
droid_window_enqueue_buffer (_EGLDisplay * disp , struct dri2_egl_surface * dri2_surf )
223
250
{
@@ -696,6 +723,12 @@ droid_create_image_from_prime_fd_yuv(_EGLDisplay *disp, _EGLContext *ctx,
696
723
int fourcc ;
697
724
int ret ;
698
725
726
+ int format = droid_resolve_format (dri2_dpy , buf );
727
+ if (format < 0 ) {
728
+ _eglError (EGL_BAD_PARAMETER , "eglCreateEGLImageKHR" );
729
+ return NULL ;
730
+ }
731
+
699
732
memset (& ycbcr , 0 , sizeof (ycbcr ));
700
733
701
734
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,
721
754
const gralloc_module_t * gralloc0 ;
722
755
gralloc0 = dri2_dpy -> gralloc ;
723
756
757
+ int format = droid_resolve_format (dri2_dpy , buf );
758
+ if (format < 0 ) {
759
+ _eglError (EGL_BAD_PARAMETER , "eglCreateEGLImageKHR" );
760
+ return NULL ;
761
+ }
762
+
724
763
if (!gralloc0 -> lock_ycbcr ) {
725
764
_eglLog (_EGL_WARNING , "Gralloc does not support lock_ycbcr" );
726
765
return NULL ;
@@ -757,10 +796,10 @@ droid_create_image_from_prime_fd_yuv(_EGLDisplay *disp, _EGLContext *ctx,
757
796
758
797
/* .chroma_step is the byte distance between the same chroma channel
759
798
* 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 );
761
800
if (fourcc == -1 ) {
762
801
_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 );
764
803
return NULL ;
765
804
}
766
805
@@ -806,18 +845,25 @@ static _EGLImage *
806
845
droid_create_image_from_prime_fd (_EGLDisplay * disp , _EGLContext * ctx ,
807
846
struct ANativeWindowBuffer * buf , int fd )
808
847
{
848
+ struct dri2_egl_display * dri2_dpy = dri2_egl_display (disp );
809
849
unsigned int pitch ;
810
850
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 ))
812
858
return droid_create_image_from_prime_fd_yuv (disp , ctx , buf , fd );
813
859
814
- const int fourcc = get_fourcc (buf -> format );
860
+ const int fourcc = get_fourcc (format );
815
861
if (fourcc == -1 ) {
816
862
_eglError (EGL_BAD_PARAMETER , "eglCreateEGLImageKHR" );
817
863
return NULL ;
818
864
}
819
865
820
- pitch = buf -> stride * get_format_bpp (buf -> format );
866
+ pitch = buf -> stride * get_format_bpp (format );
821
867
if (pitch == 0 ) {
822
868
_eglError (EGL_BAD_PARAMETER , "eglCreateEGLImageKHR" );
823
869
return NULL ;
0 commit comments