st/egl: add support for null platform
authorChia-I Wu <olv@lunarg.com>
Tue, 20 Sep 2011 06:01:45 +0000 (14:01 +0800)
committerChia-I Wu <olv@lunarg.com>
Tue, 20 Sep 2011 09:44:20 +0000 (17:44 +0800)
The backend calls null_sw_create() to create sw_winsys.  And that is
pretty much it...

configure.ac
src/gallium/state_trackers/egl/Makefile
src/gallium/state_trackers/egl/common/egl_g3d.c
src/gallium/state_trackers/egl/common/native.h
src/gallium/state_trackers/egl/null/native_null.c [new file with mode: 0644]
src/gallium/targets/egl-static/Makefile

index a686a11aa195941c315b66666a61ec7adb3550df..b2606bf647a51e89c30aaf16292e8773a0c89270 100644 (file)
@@ -1636,6 +1636,9 @@ yes)
         if test "$plat" = "fbdev"; then
                 GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS sw/fbdev"
         fi
+        if test "$plat" = "null"; then
+                GALLIUM_WINSYS_DIRS="$GALLIUM_WINSYS_DIRS sw/null"
+        fi
        if test "$plat" = "wayland"; then
                PKG_CHECK_MODULES([WAYLAND], [wayland-client wayland-server],, \
                                  [AC_MSG_ERROR([cannot find libwayland-client])])
index 1c970222c1f97a54059c8491995e819f518553ba..876f196cf6bd23981b6b4f0cd394284e126b9f67 100644 (file)
@@ -44,8 +44,13 @@ fbdev_SOURCES = $(wildcard fbdev/*.c)
 fbdev_OBJECTS = $(fbdev_SOURCES:.c=.o)
 
 
-ALL_INCLUDES = $(common_INCLUDES) $(x11_INCLUDES) $(drm_INCLUDES) $(fbdev_INCLUDES)
-ALL_SOURCES = $(common_SOURCES) $(x11_SOURCES) $(drm_SOURCES) $(fbdev_SOURCES)
+null_INCLUDES = -I$(TOP)/src/gallium/winsys/sw
+null_SOURCES = $(wildcard null/*.c)
+null_OBJECTS = $(null_SOURCES:.c=.o)
+
+
+ALL_INCLUDES = $(common_INCLUDES) $(x11_INCLUDES) $(drm_INCLUDES) $(fbdev_INCLUDES) $(null_INCLUDES)
+ALL_SOURCES = $(common_SOURCES) $(x11_SOURCES) $(drm_SOURCES) $(fbdev_SOURCES) $(null_SOURCES)
 
 EGL_OBJECTS = $(common_OBJECTS)
 EGL_CPPFLAGS = $(common_INCLUDES)
@@ -68,6 +73,10 @@ ifneq ($(findstring fbdev, $(EGL_PLATFORMS)),)
 EGL_OBJECTS += $(fbdev_OBJECTS)
 EGL_CPPFLAGS += -DHAVE_FBDEV_BACKEND
 endif
+ifneq ($(findstring null, $(EGL_PLATFORMS)),)
+EGL_OBJECTS += $(null_OBJECTS)
+EGL_CPPFLAGS += -DHAVE_NULL_BACKEND
+endif
 
 ##### TARGETS #####
 
@@ -111,4 +120,7 @@ $(drm_OBJECTS): %.o: %.c
 $(fbdev_OBJECTS): %.o: %.c
        $(call egl-cc,fbdev)
 
+$(null_OBJECTS): %.o: %.c
+       $(call egl-cc,null)
+
 sinclude depend
index 1023849ed024825075c33017ba12255206c1efe3..4cab4b23d42f968e22ffe0233f4283d3c4a77c98 100644 (file)
@@ -130,6 +130,12 @@ egl_g3d_get_platform(_EGLDriver *drv, _EGLPlatformType plat)
          plat_name = "FBDEV";
 #ifdef HAVE_FBDEV_BACKEND
          nplat = native_get_fbdev_platform(&egl_g3d_native_event_handler);
+#endif
+         break;
+      case _EGL_PLATFORM_NULL:
+         plat_name = "NULL";
+#ifdef HAVE_NULL_BACKEND
+         nplat = native_get_null_platform(&egl_g3d_native_event_handler);
 #endif
          break;
       case _EGL_PLATFORM_ANDROID:
index 3b77cba073bec0e947c998db9b4ed7ea8e442753..ee24c220e79c9139b3143e13f6f2af2e55817ba0 100644 (file)
@@ -319,6 +319,9 @@ native_get_drm_platform(const struct native_event_handler *event_handler);
 const struct native_platform *
 native_get_fbdev_platform(const struct native_event_handler *event_handler);
 
+const struct native_platform *
+native_get_null_platform(const struct native_event_handler *event_handler);
+
 const struct native_platform *
 native_get_android_platform(const struct native_event_handler *event_handler);
 
diff --git a/src/gallium/state_trackers/egl/null/native_null.c b/src/gallium/state_trackers/egl/null/native_null.c
new file mode 100644 (file)
index 0000000..9cfd7ac
--- /dev/null
@@ -0,0 +1,190 @@
+/*
+ * Mesa 3-D graphics library
+ * Version:  7.12
+ *
+ * Copyright (C) 2011 LunarG Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Chia-I Wu <olv@lunarg.com>
+ */
+
+/**
+ * For NULL window system,
+ *
+ *  - the only valid native display is EGL_DEFAULT_DISPLAY
+ *  - there is no window or pixmap
+ */
+
+#include "util/u_memory.h"
+#include "null/null_sw_winsys.h"
+#include "common/native.h"
+
+struct null_display {
+   struct native_display base;
+
+   const struct native_event_handler *event_handler;
+
+   struct native_config *configs;
+   int num_configs;
+};
+
+static INLINE struct null_display *
+null_display(const struct native_display *ndpy)
+{
+   return (struct null_display *) ndpy;
+}
+
+static const struct native_config **
+null_display_get_configs(struct native_display *ndpy, int *num_configs)
+{
+   struct null_display *null = null_display(ndpy);
+   const struct native_config **configs;
+   int i;
+
+   configs = MALLOC(sizeof(*configs) * null->num_configs);
+   if (configs) {
+      for (i = 0; i < null->num_configs; i++)
+         configs[i] = &null->configs[i];
+      if (num_configs)
+         *num_configs = null->num_configs;
+   }
+
+   return configs;
+}
+
+static int
+null_display_get_param(struct native_display *ndpy,
+                      enum native_param_type param)
+{
+   return 0;
+}
+
+static void
+null_display_destroy(struct native_display *ndpy)
+{
+   struct null_display *null = null_display(ndpy);
+
+   FREE(null->configs);
+   ndpy_uninit(&null->base);
+   FREE(null);
+}
+
+static boolean
+null_display_init_config(struct native_display *ndpy)
+{
+   const enum pipe_format color_formats[] =  {
+      PIPE_FORMAT_B8G8R8A8_UNORM,
+      PIPE_FORMAT_B8G8R8X8_UNORM,
+      PIPE_FORMAT_B5G6R5_UNORM,
+      PIPE_FORMAT_NONE
+   };
+   struct null_display *null = null_display(ndpy);
+   int i;
+
+   null->configs = CALLOC(Elements(color_formats) - 1, sizeof(*null->configs));
+   if (!null->configs)
+      return FALSE;
+
+   /* add configs */
+   for (i = 0; color_formats[i] != PIPE_FORMAT_NONE; i++) {
+      if (null->base.screen->is_format_supported(null->base.screen,
+               color_formats[i], PIPE_TEXTURE_2D, 0,
+               PIPE_BIND_RENDER_TARGET)) {
+         struct native_config *nconf = &null->configs[null->num_configs];
+
+         nconf->color_format = color_formats[i];
+         nconf->buffer_mask = 1 << NATIVE_ATTACHMENT_BACK_LEFT;
+         null->num_configs++;
+      }
+   }
+
+   return TRUE;
+}
+
+static boolean
+null_display_init_screen(struct native_display *ndpy)
+{
+   struct null_display *null = null_display(ndpy);
+   struct sw_winsys *ws;
+
+   ws = null_sw_create();
+   if (!ws)
+      return FALSE;
+
+   null->base.screen = null->event_handler->new_sw_screen(&null->base, ws);
+   if (!null->base.screen) {
+      if (ws->destroy)
+         ws->destroy(ws);
+      return FALSE;
+   }
+
+   if (!null_display_init_config(&null->base)) {
+      ndpy_uninit(&null->base);
+      return FALSE;
+   }
+
+   return TRUE;
+}
+
+static struct native_display *
+null_display_create(const struct native_event_handler *event_handler)
+{
+   struct null_display *null;
+
+   null = CALLOC_STRUCT(null_display);
+   if (!null)
+      return NULL;
+
+   null->event_handler = event_handler;
+
+   null->base.init_screen = null_display_init_screen;
+   null->base.destroy = null_display_destroy;
+   null->base.get_param = null_display_get_param;
+   null->base.get_configs = null_display_get_configs;
+
+   return &null->base;
+}
+
+static const struct native_event_handler *null_event_handler;
+
+static struct native_display *
+native_create_display(void *dpy, boolean use_sw)
+{
+   struct native_display *ndpy = NULL;
+
+   /* the only valid display is NULL */
+   if (!dpy)
+      ndpy = null_display_create(null_event_handler);
+
+   return ndpy;
+}
+
+static const struct native_platform null_platform = {
+   "NULL", /* name */
+   native_create_display
+};
+
+const struct native_platform *
+native_get_null_platform(const struct native_event_handler *event_handler)
+{
+   null_event_handler = event_handler;
+   return &null_platform;
+}
index 1583ab181ea9de25d3a7b4ca5663054c73fbbc03..2c07455ee4a48c60b0cbeab200747eefdea4ab3e 100644 (file)
@@ -63,6 +63,9 @@ endif
 ifneq ($(findstring fbdev, $(EGL_PLATFORMS)),)
 egl_LIBS += $(TOP)/src/gallium/winsys/sw/fbdev/libfbdev.a
 endif
+ifneq ($(findstring null, $(EGL_PLATFORMS)),)
+egl_LIBS += $(TOP)/src/gallium/winsys/sw/null/libws_null.a
+endif
 
 # st/mesa
 ifneq ($(filter $(GL_LIB), $(EGL_CLIENT_APIS)),)