graw: fix logic error in pixel format selection
authorBrian Paul <brianp@vmware.com>
Thu, 20 Jan 2011 20:32:35 +0000 (13:32 -0700)
committerBrian Paul <brianp@vmware.com>
Thu, 20 Jan 2011 20:37:26 +0000 (13:37 -0700)
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
src/gallium/tests/graw/clear.c
src/gallium/tests/graw/fs-test.c
src/gallium/tests/graw/gs-test.c
src/gallium/tests/graw/quad-tex.c
src/gallium/tests/graw/shader-leak.c
src/gallium/tests/graw/tri-gs.c
src/gallium/tests/graw/tri-instanced.c
src/gallium/tests/graw/tri.c
src/gallium/tests/graw/vs-test.c

index 578086f8f9a03b6139a6eeef2ee349601679a8c2..b6d798e577c262176b6fa8e6cd8c6e19dcfed253 100644 (file)
@@ -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;
index 1ff80cadeec3f534e571b143d49aa38127dfe542..55cc0087a09eee838e96c894f6fae23a62496a75 100644 (file)
@@ -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)
index 37be2d0830c74d8b54f5c84ba177cc8bee756e4f..d21eb44e1164c24f31ba33c7734ec8856a909113 100644 (file)
@@ -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);
index 812666a8c84a09cca0efe6ba047d14247fdb3d8a..0c65390e109c171a29696b2a228a985fb66951dd 100644 (file)
@@ -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);
index 952131d765bde0abdc0882353d4b8a51a698a42e..58ca639d2073c879fec739356ab55918addccb8a 100644 (file)
@@ -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);
index b53f0a046ca8c1750a368e824eada7039c2da337..9af76f51ea2d881cb5b4a85e38aaa514189c9902 100644 (file)
@@ -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);
index 84ff3e6773528b702bc0a7b208b61cea65fdcc71..a1a00b3209857fd80a76cc580cdef91396af4b89 100644 (file)
@@ -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);
index f33c061b22b861c72c2d49578f2f70aa6a7194ae..f61d8b9844d4eb7cadf03cc9a7f453f04d213953 100644 (file)
@@ -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);
index 2742c7c99e051162f480af0c5397316026f2580f..006d61ca88c8c237ddbe10ea46d9f867cd6e38f6 100644 (file)
@@ -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);
index 58908f38a23ed06485fb3a96e7015398e25100e1..1358fa85dfd82d7ea8eb9b075d9fea5f4cf47032 100644 (file)
@@ -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);