Mesa (master): graw: fix logic error in pixel format selection

Brian Paul brianp at kemper.freedesktop.org
Thu Jan 20 20:37:55 UTC 2011


Module: Mesa
Branch: master
Commit: 4ef955a12a526dcad388133b6dc8426a51054cdd
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=4ef955a12a526dcad388133b6dc8426a51054cdd

Author: Brian Paul <brianp at vmware.com>
Date:   Thu Jan 20 13:32:35 2011 -0700

graw: fix logic error in pixel format selection

The loop to choose a pixel format for the window was incrementing
'i' after we succeeded in creating the window so if we chose format[0]
for graw_create_window_and_screen() we were putting format[1] in
the pipe_resource template for creating the render target.

This only worked because of the order of the elements in the formats[]
array.

The graw_xlib.c code now properly compares the requested gallium pixel
format against the visual's color layout.

Update all the graw demos to fix the off-by-one-i error.

---

 src/gallium/targets/graw-xlib/graw_xlib.c |   20 +++++++++++++++++---
 src/gallium/tests/graw/clear.c            |   16 +++++++++-------
 src/gallium/tests/graw/fs-test.c          |   15 +++++++++------
 src/gallium/tests/graw/gs-test.c          |   15 +++++++++------
 src/gallium/tests/graw/quad-tex.c         |   16 ++++++++++------
 src/gallium/tests/graw/shader-leak.c      |   15 +++++++++------
 src/gallium/tests/graw/tri-gs.c           |   14 +++++++++-----
 src/gallium/tests/graw/tri-instanced.c    |   13 ++++++++-----
 src/gallium/tests/graw/tri.c              |   13 ++++++++-----
 src/gallium/tests/graw/vs-test.c          |   13 ++++++++-----
 10 files changed, 96 insertions(+), 54 deletions(-)

diff --git a/src/gallium/targets/graw-xlib/graw_xlib.c b/src/gallium/targets/graw-xlib/graw_xlib.c
index 578086f..b6d798e 100644
--- a/src/gallium/targets/graw-xlib/graw_xlib.c
+++ b/src/gallium/targets/graw-xlib/graw_xlib.c
@@ -66,9 +66,6 @@ graw_create_window_and_screen( int x,
    root = RootWindow( graw.display, scrnum );
 
 
-   if (format != PIPE_FORMAT_R8G8B8A8_UNORM)
-      goto fail;
-
    if (graw.display == NULL)
       goto fail;
 
@@ -88,6 +85,23 @@ graw_create_window_and_screen( int x,
       exit(1);
    }
 
+   /* See if the requirested pixel format matches the visual */
+   if (visinfo->red_mask == 0xff0000 &&
+       visinfo->green_mask == 0xff00 &&
+       visinfo->blue_mask == 0xff) {
+      if (format != PIPE_FORMAT_B8G8R8A8_UNORM)
+         goto fail;
+   }
+   else if (visinfo->red_mask == 0xff &&
+            visinfo->green_mask == 0xff00 &&
+            visinfo->blue_mask == 0xff0000) {
+      if (format != PIPE_FORMAT_R8G8B8A8_UNORM)
+         goto fail;
+   }
+   else {
+      goto fail;
+   }
+
    /* window attributes */
    attr.background_pixel = 0;
    attr.border_pixel = 0;
diff --git a/src/gallium/tests/graw/clear.c b/src/gallium/tests/graw/clear.c
index 1ff80ca..55cc008 100644
--- a/src/gallium/tests/graw/clear.c
+++ b/src/gallium/tests/graw/clear.c
@@ -2,6 +2,7 @@
  * any utility code, just the graw interface and gallium.
  */
 
+#include <stdio.h>
 #include "state_tracker/graw.h"
 #include "pipe/p_screen.h"
 #include "pipe/p_context.h"
@@ -48,16 +49,17 @@ static void init( void )
     * Also, no easy way of querying supported formats if the screen
     * cannot be created first.
     */
-   for (i = 0; 
-        window == NULL && formats[i] != PIPE_FORMAT_NONE;
-        i++) {
-      
-      screen = graw_create_window_and_screen(0,0,300,300,
+   for (i = 0; formats[i] != PIPE_FORMAT_NONE; i++) {
+      screen = graw_create_window_and_screen(0, 0, 300, 300,
                                              formats[i],
                                              &window);
+      if (window && screen)
+         break;
+   }
+   if (!screen || !window) {
+      fprintf(stderr, "Unable to create window\n");
+      exit(1);
    }
-   if (window == NULL)
-      exit(2);
    
    ctx = screen->context_create(screen, NULL);
    if (ctx == NULL)
diff --git a/src/gallium/tests/graw/fs-test.c b/src/gallium/tests/graw/fs-test.c
index 37be2d0..d21eb44 100644
--- a/src/gallium/tests/graw/fs-test.c
+++ b/src/gallium/tests/graw/fs-test.c
@@ -433,15 +433,18 @@ static void init( void )
     * Also, no easy way of querying supported formats if the screen
     * cannot be created first.
     */
-   for (i = 0; 
-        window == NULL && formats[i] != PIPE_FORMAT_NONE;
-        i++) {
-      
-      screen = graw_create_window_and_screen(0,0,WIDTH,HEIGHT,
+   for (i = 0; formats[i] != PIPE_FORMAT_NONE; i++) {
+      screen = graw_create_window_and_screen(0, 0, 300, 300,
                                              formats[i],
                                              &window);
+      if (window && screen)
+         break;
    }
-   
+   if (!screen || !window) {
+      fprintf(stderr, "Unable to create window\n");
+      exit(1);
+   }
+
    ctx = screen->context_create(screen, NULL);
    if (ctx == NULL)
       exit(3);
diff --git a/src/gallium/tests/graw/gs-test.c b/src/gallium/tests/graw/gs-test.c
index 812666a..0c65390 100644
--- a/src/gallium/tests/graw/gs-test.c
+++ b/src/gallium/tests/graw/gs-test.c
@@ -497,15 +497,18 @@ static void init( void )
     * Also, no easy way of querying supported formats if the screen
     * cannot be created first.
     */
-   for (i = 0; 
-        window == NULL && formats[i] != PIPE_FORMAT_NONE;
-        i++) {
-      
-      screen = graw_create_window_and_screen(0,0,WIDTH,HEIGHT,
+   for (i = 0; formats[i] != PIPE_FORMAT_NONE; i++) {
+      screen = graw_create_window_and_screen(0, 0, 300, 300,
                                              formats[i],
                                              &window);
+      if (window && screen)
+         break;
    }
-   
+   if (!screen || !window) {
+      fprintf(stderr, "Unable to create window\n");
+      exit(1);
+   }
+
    ctx = screen->context_create(screen, NULL);
    if (ctx == NULL)
       exit(3);
diff --git a/src/gallium/tests/graw/quad-tex.c b/src/gallium/tests/graw/quad-tex.c
index 952131d..58ca639 100644
--- a/src/gallium/tests/graw/quad-tex.c
+++ b/src/gallium/tests/graw/quad-tex.c
@@ -2,6 +2,7 @@
  * any utility code, just the graw interface and gallium.
  */
 
+#include <stdio.h>
 #include "state_tracker/graw.h"
 #include "pipe/p_screen.h"
 #include "pipe/p_context.h"
@@ -303,15 +304,18 @@ static void init( void )
     * Also, no easy way of querying supported formats if the screen
     * cannot be created first.
     */
-   for (i = 0; 
-        window == NULL && formats[i] != PIPE_FORMAT_NONE;
-        i++) {
-      
-      screen = graw_create_window_and_screen(0,0,300,300,
+   for (i = 0; formats[i] != PIPE_FORMAT_NONE; i++) {
+      screen = graw_create_window_and_screen(0, 0, 300, 300,
                                              formats[i],
                                              &window);
+      if (window && screen)
+         break;
    }
-   
+   if (!screen || !window) {
+      fprintf(stderr, "Unable to create window\n");
+      exit(1);
+   }
+
    ctx = screen->context_create(screen, NULL);
    if (ctx == NULL)
       exit(3);
diff --git a/src/gallium/tests/graw/shader-leak.c b/src/gallium/tests/graw/shader-leak.c
index b53f0a0..9af76f5 100644
--- a/src/gallium/tests/graw/shader-leak.c
+++ b/src/gallium/tests/graw/shader-leak.c
@@ -176,15 +176,18 @@ static void init( void )
     * Also, no easy way of querying supported formats if the screen
     * cannot be created first.
     */
-   for (i = 0; 
-        window == NULL && formats[i] != PIPE_FORMAT_NONE;
-        i++) {
-      
-      screen = graw_create_window_and_screen(0,0,300,300,
+   for (i = 0; formats[i] != PIPE_FORMAT_NONE; i++) {
+      screen = graw_create_window_and_screen(0, 0, 300, 300,
                                              formats[i],
                                              &window);
+      if (window && screen)
+         break;
    }
-   
+   if (!screen || !window) {
+      fprintf(stderr, "Unable to create window\n");
+      exit(1);
+   }
+
    ctx = screen->context_create(screen, NULL);
    if (ctx == NULL)
       exit(3);
diff --git a/src/gallium/tests/graw/tri-gs.c b/src/gallium/tests/graw/tri-gs.c
index 84ff3e6..a1a00b3 100644
--- a/src/gallium/tests/graw/tri-gs.c
+++ b/src/gallium/tests/graw/tri-gs.c
@@ -2,6 +2,7 @@
  * any utility code, just the graw interface and gallium.
  */
 
+#include <stdio.h>
 #include "state_tracker/graw.h"
 #include "pipe/p_screen.h"
 #include "pipe/p_context.h"
@@ -182,13 +183,16 @@ static void init( void )
     * Also, no easy way of querying supported formats if the screen
     * cannot be created first.
     */
-   for (i = 0; 
-        window == NULL && formats[i] != PIPE_FORMAT_NONE;
-        i++) {
-      
-      screen = graw_create_window_and_screen(0,0,300,300,
+   for (i = 0; formats[i] != PIPE_FORMAT_NONE; i++) {
+      screen = graw_create_window_and_screen(0, 0, 300, 300,
                                              formats[i],
                                              &window);
+      if (window && screen)
+         break;
+   }
+   if (!screen || !window) {
+      fprintf(stderr, "Unable to create window\n");
+      exit(1);
    }
    
    ctx = screen->context_create(screen, NULL);
diff --git a/src/gallium/tests/graw/tri-instanced.c b/src/gallium/tests/graw/tri-instanced.c
index f33c061..f61d8b9 100644
--- a/src/gallium/tests/graw/tri-instanced.c
+++ b/src/gallium/tests/graw/tri-instanced.c
@@ -234,13 +234,16 @@ static void init( void )
     * Also, no easy way of querying supported formats if the screen
     * cannot be created first.
     */
-   for (i = 0; 
-        window == NULL && formats[i] != PIPE_FORMAT_NONE;
-        i++) {
-      
-      screen = graw_create_window_and_screen(0,0,300,300,
+   for (i = 0; formats[i] != PIPE_FORMAT_NONE; i++) {
+      screen = graw_create_window_and_screen(0, 0, 300, 300,
                                              formats[i],
                                              &window);
+      if (window && screen)
+         break;
+   }
+   if (!screen || !window) {
+      fprintf(stderr, "Unable to create window\n");
+      exit(1);
    }
    
    ctx = screen->context_create(screen, NULL);
diff --git a/src/gallium/tests/graw/tri.c b/src/gallium/tests/graw/tri.c
index 2742c7c..006d61c 100644
--- a/src/gallium/tests/graw/tri.c
+++ b/src/gallium/tests/graw/tri.c
@@ -162,13 +162,16 @@ static void init( void )
     * Also, no easy way of querying supported formats if the screen
     * cannot be created first.
     */
-   for (i = 0; 
-        window == NULL && formats[i] != PIPE_FORMAT_NONE;
-        i++) {
-      
-      screen = graw_create_window_and_screen(0,0,300,300,
+   for (i = 0; formats[i] != PIPE_FORMAT_NONE; i++) {
+      screen = graw_create_window_and_screen(0, 0, 300, 300,
                                              formats[i],
                                              &window);
+      if (window && screen)
+         break;
+   }
+   if (!screen || !window) {
+      fprintf(stderr, "Unable to create window\n");
+      exit(1);
    }
    
    ctx = screen->context_create(screen, NULL);
diff --git a/src/gallium/tests/graw/vs-test.c b/src/gallium/tests/graw/vs-test.c
index 58908f3..1358fa8 100644
--- a/src/gallium/tests/graw/vs-test.c
+++ b/src/gallium/tests/graw/vs-test.c
@@ -384,13 +384,16 @@ static void init( void )
     * Also, no easy way of querying supported formats if the screen
     * cannot be created first.
     */
-   for (i = 0; 
-        window == NULL && formats[i] != PIPE_FORMAT_NONE;
-        i++) {
-      
-      screen = graw_create_window_and_screen(0,0,WIDTH,HEIGHT,
+   for (i = 0; formats[i] != PIPE_FORMAT_NONE; i++) {
+      screen = graw_create_window_and_screen(0, 0, 300, 300,
                                              formats[i],
                                              &window);
+      if (window && screen)
+         break;
+   }
+   if (!screen || !window) {
+      fprintf(stderr, "Unable to create window\n");
+      exit(1);
    }
    
    ctx = screen->context_create(screen, NULL);




More information about the mesa-commit mailing list