st/egl: Move sw screen creation to native helper.
authorChia-I Wu <olv@lunarg.com>
Fri, 4 Jun 2010 04:05:37 +0000 (12:05 +0800)
committerChia-I Wu <olv@lunarg.com>
Fri, 4 Jun 2010 04:12:50 +0000 (12:12 +0800)
The code is shared by ximage and gdi backend.

src/gallium/state_trackers/egl/Makefile
src/gallium/state_trackers/egl/common/native_helper.c
src/gallium/state_trackers/egl/common/native_helper.h
src/gallium/state_trackers/egl/gdi/native_gdi.c
src/gallium/state_trackers/egl/x11/native_ximage.c

index a3c1bb4346952ac46f4c2336495165da7f12e5e8..8933890323adc81a4a21d316f92cdefa4bd969fb 100644 (file)
@@ -5,6 +5,7 @@ common_INCLUDES = \
        -I. \
        -I$(TOP)/src/gallium/include \
        -I$(TOP)/src/gallium/auxiliary \
+       -I$(TOP)/src/gallium/drivers \
        -I$(TOP)/src/egl/main \
        -I$(TOP)/include
 
index 7832b2b693f572d904183a8cbe2d2e8ca12be663..206817ed666e237cfd558371380e1d920eccb972 100644 (file)
@@ -31,6 +31,9 @@
 #include "pipe/p_screen.h"
 #include "pipe/p_context.h"
 #include "pipe/p_state.h"
+#include "softpipe/sp_public.h"
+#include "llvmpipe/lp_public.h"
+#include "target-helpers/wrap_screen.h"
 
 #include "native_helper.h"
 
@@ -233,3 +236,18 @@ resource_surface_present(struct resource_surface *rsurf,
 
    return TRUE;
 }
+
+struct pipe_screen *
+native_create_sw_screen(struct sw_winsys *ws)
+{
+   struct pipe_screen *screen = NULL;
+
+#if defined(GALLIUM_LLVMPIPE)
+   if (!screen && !debug_get_bool_option("GALLIUM_NO_LLVM", FALSE))
+      screen = llvmpipe_create_screen(ws);
+#endif
+   if (!screen)
+      screen = softpipe_create_screen(ws);
+
+   return (screen) ? gallium_wrap_screen(screen) : NULL;
+}
index 62956d522018ec625b62c6e54913494eb4fa945d..25fafd046512334b78e425e8b3fd5b9bd0bf48d0 100644 (file)
@@ -68,3 +68,6 @@ boolean
 resource_surface_present(struct resource_surface *rsurf,
                          enum native_attachment which,
                          void *winsys_drawable_handle);
+
+struct pipe_screen *
+native_create_sw_screen(struct sw_winsys *ws);
index 29e89bcae804c2d0071952cb06957bdfa7cb7c9c..1791d198d50212b6d271a4374c76fc86110066f0 100644 (file)
@@ -32,9 +32,6 @@
 #include "util/u_memory.h"
 #include "util/u_format.h"
 #include "util/u_inlines.h"
-#include "target-helpers/wrap_screen.h"
-#include "llvmpipe/lp_public.h"
-#include "softpipe/sp_public.h"
 #include "gdi/gdi_sw_winsys.h"
 
 #include "common/native_helper.h"
@@ -369,32 +366,6 @@ gdi_create_display(HDC hDC, struct pipe_screen *screen,
    return &gdpy->base;
 }
 
-static struct pipe_screen *
-gdi_create_screen(void)
-{
-   struct sw_winsys *winsys;
-   struct pipe_screen *screen = NULL;
-
-   winsys = gdi_create_sw_winsys();
-   if (!winsys)
-      return NULL;
-
-#if defined(GALLIUM_LLVMPIPE)
-   if (!screen && !debug_get_bool_option("GALLIUM_NO_LLVM", FALSE))
-      screen = llvmpipe_create_screen(winsys);
-#endif
-   if (!screen)
-      screen = softpipe_create_screen(winsys);
-
-   if (!screen) {
-      if (winsys->destroy)
-         winsys->destroy(winsys);
-      return NULL;
-   }
-
-   return gallium_wrap_screen(screen);
-}
-
 struct native_probe *
 native_create_probe(EGLNativeDisplayType dpy)
 {
@@ -417,11 +388,19 @@ struct native_display *
 native_create_display(EGLNativeDisplayType dpy,
                       struct native_event_handler *event_handler)
 {
+   struct sw_winsys *winsys;
    struct pipe_screen *screen;
 
-   screen = gdi_create_screen();
-   if (!screen)
+   winsys = gdi_create_sw_winsys();
+   if (!winsys)
+      return NULL;
+
+   screen = native_create_sw_screen(winsys);
+   if (!screen) {
+      if (winsys->destroy)
+         winsys->destroy(winsys);
       return NULL;
+   }
 
    return gdi_create_display((HDC) dpy, screen, event_handler);
 }
index 3388fc61e141a751c004f9abcce7bbf5ad10d471..45679fc9b4e5f5dd08a4102f7aba72685c41b4c6 100644 (file)
 #include "pipe/p_compiler.h"
 #include "util/u_inlines.h"
 #include "state_tracker/xlib_sw_winsys.h"
-#include "target-helpers/wrap_screen.h"
 #include "util/u_debug.h"
-#include "softpipe/sp_public.h"
-#include "llvmpipe/lp_public.h"
 #include "egllog.h"
 
 #include "common/native_helper.h"
@@ -443,65 +440,12 @@ ximage_display_destroy(struct native_display *ndpy)
    FREE(xdpy);
 }
 
-
-/* Helper function to build a subset of a driver stack consisting of
- * one of the software rasterizers (cell, llvmpipe, softpipe) and the
- * xlib winsys.
- *
- * This function could be shared, but currently causes headaches for
- * the build systems, particularly scons if we try.
- *
- * Long term, want to avoid having global #defines for things like
- * GALLIUM_LLVMPIPE, GALLIUM_CELL, etc.  Scons already eliminates
- * those #defines, so things that are painful for it now are likely to
- * be painful for other build systems in the future.
- */
-static struct pipe_screen *
-swrast_xlib_create_screen( Display *display )
-{
-   struct sw_winsys *winsys;
-   struct pipe_screen *screen = NULL;
-
-   /* Create the underlying winsys, which performs presents to Xlib
-    * drawables:
-    */
-   winsys = xlib_create_sw_winsys( display );
-   if (winsys == NULL)
-      return NULL;
-
-   /* Create a software rasterizer on top of that winsys.  Use
-    * llvmpipe if it is available.
-    */
-#if defined(GALLIUM_LLVMPIPE)
-   if (screen == NULL &&
-       !debug_get_bool_option("GALLIUM_NO_LLVM", FALSE))
-      screen = llvmpipe_create_screen( winsys );
-#endif
-
-   if (screen == NULL)
-      screen = softpipe_create_screen( winsys );
-
-   if (screen == NULL)
-      goto fail;
-
-   /* Inject any wrapping layers we want to here:
-    */
-   return gallium_wrap_screen( screen );
-
-fail:
-   if (winsys)
-      winsys->destroy( winsys );
-
-   return NULL;
-}
-
-
-
 struct native_display *
 x11_create_ximage_display(EGLNativeDisplayType dpy,
                           struct native_event_handler *event_handler)
 {
    struct ximage_display *xdpy;
+   struct sw_winsys *winsys = NULL;
 
    xdpy = CALLOC_STRUCT(ximage_display);
    if (!xdpy)
@@ -521,12 +465,16 @@ x11_create_ximage_display(EGLNativeDisplayType dpy,
 
    xdpy->xscr_number = DefaultScreen(xdpy->dpy);
    xdpy->xscr = x11_screen_create(xdpy->dpy, xdpy->xscr_number);
-   if (!xdpy->xscr) {
-      FREE(xdpy);
-      return NULL;
-   }
+   if (!xdpy->xscr)
+      goto fail;
 
-   xdpy->base.screen = swrast_xlib_create_screen(xdpy->dpy);
+   winsys = xlib_create_sw_winsys(xdpy->dpy);
+   if (!winsys)
+      goto fail;
+
+   xdpy->base.screen = native_create_sw_screen(winsys);
+   if (!xdpy->base.screen)
+      goto fail;
 
    xdpy->base.destroy = ximage_display_destroy;
    xdpy->base.get_param = ximage_display_get_param;
@@ -537,4 +485,14 @@ x11_create_ximage_display(EGLNativeDisplayType dpy,
    xdpy->base.create_pixmap_surface = ximage_display_create_pixmap_surface;
 
    return &xdpy->base;
+
+fail:
+   if (winsys && winsys->destroy)
+      winsys->destroy(winsys);
+   if (xdpy->xscr)
+      x11_screen_destroy(xdpy->xscr);
+   if (xdpy->dpy && xdpy->own_dpy)
+      XCloseDisplay(xdpy->dpy);
+   FREE(xdpy);
+   return NULL;
 }