st/dri: Always try to set up R5G6B5 configs.
authorMichel Dänzer <daenzer@vmware.com>
Fri, 12 Mar 2010 17:24:34 +0000 (18:24 +0100)
committerMichel Dänzer <daenzer@vmware.com>
Fri, 12 Mar 2010 17:52:07 +0000 (18:52 +0100)
Allows compiz to work in depth 16.

The DRI2 getBuffersWithFormat hook is only required for 16/32 bit depth
buffers, for colour buffers the only requirement is that the format matches
the drawable depth, which we can't check here.

(cherry picked from commit c50477c255a34444720fb944c54373462ef39fb9)

src/gallium/state_trackers/dri/dri_screen.c

index 60bc560049cf74332a6d54bbb3dc5bf96ef085fe..7ccad8f5dd6c52468c057e0075048c0e558f3135 100644 (file)
@@ -90,6 +90,9 @@ dri_fill_in_modes(struct dri_screen *screen,
                  unsigned pixel_bits)
 {
    __DRIconfig **configs = NULL;
+   __DRIconfig **configs_r5g6b5 = NULL;
+   __DRIconfig **configs_a8r8g8b8 = NULL;
+   __DRIconfig **configs_x8r8g8b8 = NULL;
    unsigned num_modes;
    uint8_t depth_bits_array[5];
    uint8_t stencil_bits_array[5];
@@ -127,25 +130,23 @@ dri_fill_in_modes(struct dri_screen *screen,
    pf_x8r8g8b8 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_B8G8R8X8_UNORM,
                                               PIPE_TEXTURE_2D,
                                               PIPE_TEXTURE_USAGE_RENDER_TARGET, 0);
-
-   /* we support buffers with different depths only if we can tell the driver
-    * the actual depth of each of them. */
-   if (screen->sPriv->dri2.loader
-       && (screen->sPriv->dri2.loader->base.version > 2)
-       && (screen->sPriv->dri2.loader->getBuffersWithFormat != NULL)) {
+   pf_r5g6b5 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_B5G6R5_UNORM,
+                                            PIPE_TEXTURE_2D,
+                                            PIPE_TEXTURE_USAGE_RENDER_TARGET, 0);
+
+   /* We can only get a 16 or 32 bit depth buffer with getBuffersWithFormat */
+   if (screen->sPriv->dri2.loader &&
+       (screen->sPriv->dri2.loader->base.version > 2) &&
+       (screen->sPriv->dri2.loader->getBuffersWithFormat != NULL)) {
       pf_z16 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_Z16_UNORM,
                                              PIPE_TEXTURE_2D,
                                              PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0);
       pf_z32 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_Z32_UNORM,
                                              PIPE_TEXTURE_2D,
                                              PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0);
-      pf_r5g6b5 = p_screen->is_format_supported(p_screen, PIPE_FORMAT_B5G6R5_UNORM,
-                                                PIPE_TEXTURE_2D,
-                                                PIPE_TEXTURE_USAGE_RENDER_TARGET, 0);
    } else {
       pf_z16 = FALSE;
       pf_z32 = FALSE;
-      pf_r5g6b5 = FALSE;
    }
 
    if (pf_z16) {
@@ -175,46 +176,48 @@ dri_fill_in_modes(struct dri_screen *screen,
    num_modes =
       depth_buffer_factor * back_buffer_factor * msaa_samples_factor * 4;
 
-   if (pixel_bits == 16 && pf_r5g6b5) {
-      configs = driCreateConfigs(GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
-                                depth_bits_array, stencil_bits_array,
-                                depth_buffer_factor, back_buffer_modes,
-                                back_buffer_factor,
-                                msaa_samples_array, msaa_samples_factor,
-                                GL_TRUE);
+   if (pf_r5g6b5)
+      configs_r5g6b5 = driCreateConfigs(GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
+                                        depth_bits_array, stencil_bits_array,
+                                        depth_buffer_factor, back_buffer_modes,
+                                        back_buffer_factor,
+                                        msaa_samples_array, msaa_samples_factor,
+                                        GL_TRUE);
+
+   if (pf_a8r8g8b8)
+      configs_a8r8g8b8 = driCreateConfigs(GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV,
+                                          depth_bits_array,
+                                          stencil_bits_array,
+                                          depth_buffer_factor,
+                                          back_buffer_modes,
+                                          back_buffer_factor,
+                                          msaa_samples_array,
+                                          msaa_samples_factor,
+                                          GL_TRUE);
+
+   if (pf_x8r8g8b8)
+      configs_x8r8g8b8 = driCreateConfigs(GL_BGR, GL_UNSIGNED_INT_8_8_8_8_REV,
+                                          depth_bits_array,
+                                          stencil_bits_array,
+                                          depth_buffer_factor,
+                                          back_buffer_modes,
+                                          back_buffer_factor,
+                                          msaa_samples_array,
+                                          msaa_samples_factor,
+                                          GL_TRUE);
+
+   if (pixel_bits == 16) {
+      configs = configs_r5g6b5;
+      if (configs_a8r8g8b8)
+         configs = configs ? driConcatConfigs(configs, configs_a8r8g8b8) : configs_a8r8g8b8;
+      if (configs_x8r8g8b8)
+        configs = configs ? driConcatConfigs(configs, configs_x8r8g8b8) : configs_x8r8g8b8;
    } else {
-      __DRIconfig **configs_a8r8g8b8 = NULL;
-      __DRIconfig **configs_x8r8g8b8 = NULL;
-
-      if (pf_a8r8g8b8)
-        configs_a8r8g8b8 = driCreateConfigs(GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV,
-                                            depth_bits_array,
-                                            stencil_bits_array,
-                                            depth_buffer_factor,
-                                            back_buffer_modes,
-                                            back_buffer_factor,
-                                            msaa_samples_array,
-                                             msaa_samples_factor,
-                                            GL_TRUE);
-      if (pf_x8r8g8b8)
-        configs_x8r8g8b8 = driCreateConfigs(GL_BGR, GL_UNSIGNED_INT_8_8_8_8_REV,
-                                            depth_bits_array,
-                                            stencil_bits_array,
-                                            depth_buffer_factor,
-                                            back_buffer_modes,
-                                            back_buffer_factor,
-                                            msaa_samples_array,
-                                             msaa_samples_factor,
-                                            GL_TRUE);
-
-      if (configs_a8r8g8b8 && configs_x8r8g8b8)
-        configs = driConcatConfigs(configs_x8r8g8b8, configs_a8r8g8b8);
-      else if (configs_a8r8g8b8)
-        configs = configs_a8r8g8b8;
-      else if (configs_x8r8g8b8)
-        configs = configs_x8r8g8b8;
-      else
-        configs = NULL;
+      configs = configs_a8r8g8b8;
+      if (configs_x8r8g8b8)
+        configs = configs ? driConcatConfigs(configs, configs_x8r8g8b8) : configs_x8r8g8b8;
+      if (configs_r5g6b5)
+         configs = configs ? driConcatConfigs(configs, configs_r5g6b5) : configs_r5g6b5;
    }
 
    if (configs == NULL) {