dri_interface,egl,gallium: only expose RGBA visuals on Android
authorMarek Olšák <marek.olsak@amd.com>
Fri, 28 Jul 2017 15:30:34 +0000 (17:30 +0200)
committerMarek Olšák <marek.olsak@amd.com>
Mon, 31 Jul 2017 10:49:30 +0000 (12:49 +0200)
X/GLX can't handle them. This removes almost 500 GLX visuals that were
incorrectly exposed.

Add an optional getCapability callback for querying what the loader can do.

I'm not splitting this patch, because it's already too small.

v2: also add the callback to __DRIimageLoaderExtension

Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
Cc: 17.2 <mesa-stable@lists.freedesktop.org>
include/GL/internal/dri_interface.h
src/egl/drivers/dri2/platform_android.c
src/gallium/state_trackers/dri/dri_screen.c

index a8f5af145df079143b54d1a4b4966e02b047bc93..c314a43faad09547cfb5310ec6158d48e1b611fd 100644 (file)
@@ -967,7 +967,15 @@ struct __DRIbufferRec {
 };
 
 #define __DRI_DRI2_LOADER "DRI_DRI2Loader"
-#define __DRI_DRI2_LOADER_VERSION 3
+#define __DRI_DRI2_LOADER_VERSION 4
+
+enum dri_loader_cap {
+   /* Whether the loader handles RGBA channel ordering correctly. If not,
+    * only BGRA ordering can be exposed.
+    */
+   DRI_LOADER_CAP_RGBA_ORDERING,
+};
+
 struct __DRIdri2LoaderExtensionRec {
     __DRIextension base;
 
@@ -1017,6 +1025,14 @@ struct __DRIdri2LoaderExtensionRec {
                                         int *width, int *height,
                                         unsigned int *attachments, int count,
                                         int *out_count, void *loaderPrivate);
+
+    /**
+     * Return a loader capability value. If the loader doesn't know the enum,
+     * it will return 0.
+     *
+     * \since 4
+     */
+    unsigned (*getCapability)(void *loaderPrivate, enum dri_loader_cap cap);
 };
 
 /**
@@ -1711,7 +1727,7 @@ struct __DRIimageList {
 };
 
 #define __DRI_IMAGE_LOADER "DRI_IMAGE_LOADER"
-#define __DRI_IMAGE_LOADER_VERSION 1
+#define __DRI_IMAGE_LOADER_VERSION 2
 
 struct __DRIimageLoaderExtensionRec {
     __DRIextension base;
@@ -1747,6 +1763,14 @@ struct __DRIimageLoaderExtensionRec {
      *                       into __DRIdri2ExtensionRec::createNewDrawable
      */
     void (*flushFrontBuffer)(__DRIdrawable *driDrawable, void *loaderPrivate);
+
+    /**
+     * Return a loader capability value. If the loader doesn't know the enum,
+     * it will return 0.
+     *
+     * \since 2
+     */
+    unsigned (*getCapability)(void *loaderPrivate, enum dri_loader_cap cap);
 };
 
 /**
index 300e2d9dbfbc84190d1f578d1aac5884ac7315d6..bae42412b576836bc2838ffb1ba89915aa9e4024 100644 (file)
@@ -1013,6 +1013,18 @@ droid_get_buffers_with_format(__DRIdrawable * driDrawable,
    return dri2_surf->buffers;
 }
 
+static unsigned
+droid_get_capability(void *loaderPrivate, enum dri_loader_cap cap)
+{
+   /* Note: loaderPrivate is _EGLDisplay* */
+   switch (cap) {
+   case DRI_LOADER_CAP_RGBA_ORDERING:
+      return 1;
+   default:
+      return 0;
+   }
+}
+
 static EGLBoolean
 droid_add_configs_for_visuals(_EGLDriver *drv, _EGLDisplay *dpy)
 {
@@ -1125,18 +1137,20 @@ static const struct dri2_egl_display_vtbl droid_display_vtbl = {
 };
 
 static const __DRIdri2LoaderExtension droid_dri2_loader_extension = {
-   .base = { __DRI_DRI2_LOADER, 3 },
+   .base = { __DRI_DRI2_LOADER, 4 },
 
    .getBuffers           = NULL,
    .flushFrontBuffer     = droid_flush_front_buffer,
    .getBuffersWithFormat = droid_get_buffers_with_format,
+   .getCapability        = droid_get_capability;
 };
 
 static const __DRIimageLoaderExtension droid_image_loader_extension = {
-   .base = { __DRI_IMAGE_LOADER, 1 },
+   .base = { __DRI_IMAGE_LOADER, 2 },
 
    .getBuffers          = droid_image_get_buffers,
    .flushFrontBuffer    = droid_flush_front_buffer,
+   .getCapability       = droid_get_capability,
 };
 
 static const __DRIextension *droid_dri2_loader_extensions[] = {
index 59a850b1423f27e3958c952630913d3f6ae759ca..890a8bff4c6f9aabea6a671ededc408f42cb389c 100644 (file)
@@ -124,6 +124,21 @@ dri_fill_st_options(struct dri_screen *screen)
    driComputeOptionsSha1(optionCache, options->config_options_sha1);
 }
 
+static unsigned
+dri_loader_get_cap(struct dri_screen *screen, enum dri_loader_cap cap)
+{
+   const __DRIdri2LoaderExtension *dri2_loader = screen->sPriv->dri2.loader;
+   const __DRIimageLoaderExtension *image_loader = screen->sPriv->image.loader;
+
+   if (dri2_loader && dri2_loader->base.version >= 4)
+      return dri2_loader->getCapability(screen->sPriv->loaderPrivate, cap);
+
+   if (image_loader && image_loader->base.version >= 2)
+      return image_loader->getCapability(screen->sPriv->loaderPrivate, cap);
+
+   return 0;
+}
+
 static const __DRIconfig **
 dri_fill_in_modes(struct dri_screen *screen)
 {
@@ -235,8 +250,15 @@ dri_fill_in_modes(struct dri_screen *screen)
 
    assert(ARRAY_SIZE(mesa_formats) == ARRAY_SIZE(pipe_formats));
 
+   /* Expose only BGRA ordering if the loader doesn't support RGBA ordering. */
+   unsigned num_formats;
+   if (dri_loader_get_cap(screen, DRI_LOADER_CAP_RGBA_ORDERING))
+      num_formats = ARRAY_SIZE(mesa_formats);
+   else
+      num_formats = 5;
+
    /* Add configs. */
-   for (format = 0; format < ARRAY_SIZE(mesa_formats); format++) {
+   for (format = 0; format < num_formats; format++) {
       __DRIconfig **new_configs = NULL;
       unsigned num_msaa_modes = 0; /* includes a single-sample mode */
       uint8_t msaa_modes[MSAA_VISUAL_MAX_SAMPLES];