gallium: dmabuf support for yuv formats that are not natively supported
[mesa.git] / src / gallium / state_trackers / dri / dri_helpers.c
index d4de8cdc59facc68ad0c4b7d65a7d1d1f7ffa410..90a8a392fad52aa854b24543d9bae1d3d6ef6c18 100644 (file)
@@ -566,6 +566,21 @@ dri2_get_pipe_format_for_dri_format(int format)
    return PIPE_FORMAT_NONE;
 }
 
+boolean
+dri2_yuv_dma_buf_supported(struct dri_screen *screen,
+                           const struct dri2_format_mapping *map)
+{
+   struct pipe_screen *pscreen = screen->base.screen;
+
+   for (unsigned i = 0; i < map->nplanes; i++) {
+      if (!pscreen->is_format_supported(pscreen,
+            dri2_get_pipe_format_for_dri_format(map->planes[i].dri_format),
+            screen->target, 0, 0, PIPE_BIND_SAMPLER_VIEW))
+         return false;
+   }
+   return true;
+}
+
 boolean
 dri2_query_dma_buf_formats(__DRIscreen *_screen, int max, int *formats,
                            int *count)
@@ -589,7 +604,8 @@ dri2_query_dma_buf_formats(__DRIscreen *_screen, int max, int *formats,
                                        PIPE_BIND_RENDER_TARGET) ||
           pscreen->is_format_supported(pscreen, map->pipe_format,
                                        screen->target, 0, 0,
-                                       PIPE_BIND_SAMPLER_VIEW)) {
+                                       PIPE_BIND_SAMPLER_VIEW) ||
+          dri2_yuv_dma_buf_supported(screen, map)) {
          if (j < max)
             formats[j] = map->dri_fourcc;
          j++;