gallium/targets/d3dadapter9: drop the libdrm prefix for drm.h
[mesa.git] / src / gallium / targets / graw-xlib / graw_xlib.c
index 41120ba3c70f1b78ffba2eee73f9064fee811b69..db2637bd3c923883068733c75aa244d321e8ff82 100644 (file)
@@ -1,25 +1,13 @@
 #include "pipe/p_compiler.h"
 #include "pipe/p_context.h"
+#include "pipe/p_screen.h"
 #include "util/u_debug.h"
 #include "util/u_memory.h"
-#include "target-helpers/wrap_screen.h"
-#include "state_tracker/xlib_sw_winsys.h"
-
-#ifdef GALLIUM_SOFTPIPE
-#include "softpipe/sp_public.h"
-#endif
-
-#ifdef GALLIUM_LLVMPIPE
-#include "llvmpipe/lp_public.h"
-#endif
-
-/* Haven't figured out a decent way to build the helper code yet -
- * #include it here temporarily.
- */
-#include "sw/sw_public.h"
-#include "sw/sw.c"
-
+#include "target-helpers/inline_sw_helper.h"
+#include "target-helpers/inline_debug_helper.h"
+#include "state_tracker/xlibsw_api.h"
 #include "state_tracker/graw.h"
+#include "sw/xlib/xlib_sw_winsys.h"
 
 #include <X11/Xlib.h>
 #include <X11/Xlibint.h>
@@ -35,8 +23,6 @@ static struct {
 static struct pipe_screen *
 graw_create_screen( void )
 {
-   const char *default_driver;
-   const char *driver;
    struct pipe_screen *screen = NULL;
    struct sw_winsys *winsys = NULL;
 
@@ -47,35 +33,14 @@ graw_create_screen( void )
    if (winsys == NULL)
       return NULL;
 
-#if defined(GALLIUM_LLVMPIPE)
-   default_driver = "llvmpipe";
-#elif defined(GALLIUM_SOFTPIPE)
-   default_driver = "softpipe";
-#else
-   default_driver = "";
-#endif
-
-   driver = debug_get_option("GALLIUM_DRIVER", default_driver);
-
-#if defined(GALLIUM_LLVMPIPE)
-   if (screen == NULL && strcmp(driver, "llvmpipe") == 0)
-      screen = llvmpipe_create_screen( winsys );
-#endif
-
-#if defined(GALLIUM_SOFTPIPE)
-   if (screen == NULL)
-      screen = softpipe_create_screen( winsys );
-#endif
+   screen = sw_screen_create( winsys );
 
    /* Inject any wrapping layers we want to here:
     */
-   return gallium_wrap_screen( screen );
+   return debug_screen_wrap( screen );
 }
 
 
-
-
 struct pipe_screen *
 graw_create_window_and_screen( int x,
                                int y,
@@ -102,9 +67,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;
 
@@ -124,6 +86,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_BGRA8888_UNORM)
+         goto fail;
+   }
+   else if (visinfo->red_mask == 0xff &&
+            visinfo->green_mask == 0xff00 &&
+            visinfo->blue_mask == 0xff0000) {
+      if (format != PIPE_FORMAT_RGBA8888_UNORM)
+         goto fail;
+   }
+   else {
+      goto fail;
+   }
+
    /* window attributes */
    attr.background_pixel = 0;
    attr.border_pixel = 0;
@@ -169,18 +148,16 @@ graw_create_window_and_screen( int x,
    if (screen == NULL)
       goto fail;
 
-   XFree(visinfo);
+   free(visinfo);
    return screen;
 
 fail:
    if (screen)
       screen->destroy(screen);
 
-   if (xlib_handle)
-      FREE(xlib_handle);
+   FREE(xlib_handle);
 
-   if (visinfo)
-      XFree(visinfo);
+   free(visinfo);
 
    if (win)
       XDestroyWindow(graw.display, win);