gallium: Add a dumb drm/kms winsys backed swrast provider
authorGiovanni Campagna <gcampagna@src.gnome.org>
Wed, 23 Jul 2014 18:37:31 +0000 (19:37 +0100)
committerEmil Velikov <emil.l.velikov@gmail.com>
Wed, 30 Jul 2014 15:33:09 +0000 (16:33 +0100)
Add a new winsys and target that can be used with a dri2 state tracker
and loader instead of drisw. This allows to use gbm as a dri2/image
loader and avoid the extra copy from the backbuffer to the shadow
frontbuffer.

The new driver is called "kms_swrast", and is loaded by gbm as a
fallback, because it is only useful with the gbm platform (as no buffer
sharing is possible)

To force select the driver set the environment variable
GBM_ALWAYS_SOFTWARE

[Emil Velikov]
 - Rebase on top of gallium megadriver.
 - s/text/test/ in configure.ac (Spotted by Andreas Pokorny).
 - Add scons support for winsys/sw/kms-dri and fix the build.
 - Provide separate DriverAPI, due to different InitScreen hook.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
14 files changed:
configure.ac
docs/relnotes/10.3.html
src/gallium/SConscript
src/gallium/auxiliary/target-helpers/inline_drm_helper.h
src/gallium/state_trackers/dri/dri2.c
src/gallium/state_trackers/dri/dri_screen.h
src/gallium/targets/dri/Makefile.am
src/gallium/targets/dri/SConscript
src/gallium/winsys/Makefile.am
src/gallium/winsys/sw/kms-dri/Makefile.am [new file with mode: 0644]
src/gallium/winsys/sw/kms-dri/SConscript [new file with mode: 0644]
src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.c [new file with mode: 0644]
src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.h [new file with mode: 0644]
src/gbm/backends/dri/gbm_dri.c

index 6b0d43fd81997fcf40e53fdb6a4692b5b878bfb7..29426fcbf00e5b9d4b195f0d33917f7d588a587c 100644 (file)
@@ -1998,6 +1998,10 @@ if test -n "$with_gallium_drivers"; then
             if test "x$enable_dri" = xyes; then
                 GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS dri/swrast"
             fi
+
+            if test "x$have_libdrm" = xyes; then
+                GALLIUM_TARGET_DIRS="$GALLIUM_TARGET_DIRS dri/kms-swrast"
+            fi
             ;;
         *)
             AC_MSG_ERROR([Unknown Gallium driver: $driver])
@@ -2234,6 +2238,7 @@ AC_CONFIG_FILES([Makefile
                src/gallium/winsys/svga/drm/Makefile
                src/gallium/winsys/sw/dri/Makefile
                src/gallium/winsys/sw/fbdev/Makefile
+               src/gallium/winsys/sw/kms-dri/Makefile
                src/gallium/winsys/sw/null/Makefile
                src/gallium/winsys/sw/wayland/Makefile
                src/gallium/winsys/sw/wrapper/Makefile
index 1f4e1da7be1d9b8345a92b433c277eda0b31ac08..9a7423030d5b05dfb514439eebdd2a017282c525 100644 (file)
@@ -59,6 +59,8 @@ Note: some of the new features are only available with certain drivers.
 <li>GL_ARB_fragment_layer_viewport on nv50, nvc0, llvmpipe, r600</li>
 <li>GL_AMD_vertex_shader_viewport_index on i965/gen7+, r600</li>
 <li>GL_ARB_clear_texture on i965</li>
+<li>A new software rasterizer driver (kms_swrast_dri.so) that works with
+DRM drivers that don't have a full-fledged GEM (such as qxl or simpledrm)</li>
 </ul>
 
 
index 8d9849e00099a20f20aa537064c668ccbf8472c3..cb617200752bbd258d1b1d9d45bb081e8ae18794 100644 (file)
@@ -70,6 +70,10 @@ if env['dri']:
         'winsys/sw/dri/SConscript',
     ])
 
+    SConscript([
+        'winsys/sw/kms-dri/SConscript',
+    ])
+
     SConscript([
         'winsys/svga/drm/SConscript',
     ])
index 5656ef076cf1756638aa93eeb59eb3fbc44ce7e8..751ceb1e70ebbf2db1331b6e4a1ef2d94233c3b3 100644 (file)
@@ -8,6 +8,11 @@
 #include "dri_screen.h"
 #endif
 
+#if GALLIUM_SOFTPIPE
+#include "target-helpers/inline_sw_helper.h"
+#include "sw/kms-dri/kms_dri_sw_winsys.h"
+#endif
+
 #if GALLIUM_I915
 #include "i915/drm/i915_drm_public.h"
 #include "i915/i915_public.h"
@@ -53,6 +58,33 @@ static char* driver_name = NULL;
 
 /* XXX: We need to teardown the winsys if *screen_create() fails. */
 
+#if defined(GALLIUM_SOFTPIPE)
+#if defined(DRI_TARGET)
+
+const __DRIextension **__driDriverGetExtensions_kms_swrast(void);
+
+PUBLIC const __DRIextension **__driDriverGetExtensions_kms_swrast(void)
+{
+   globalDriverAPI = &dri_kms_driver_api;
+   return galliumdrm_driver_extensions;
+}
+
+struct pipe_screen *
+kms_swrast_create_screen(int fd)
+{
+   struct sw_winsys *sws;
+   struct pipe_screen *screen;
+
+   sws = kms_dri_create_winsys(fd);
+   if (!sws)
+      return NULL;
+
+   screen = sw_screen_create(sws);
+   return screen ? debug_screen_wrap(screen) : NULL;
+}
+#endif
+#endif
+
 #if defined(GALLIUM_I915)
 #if defined(DRI_TARGET)
 
index fcca48752299ef2e874e78d8be7cfbe68bc2efbb..f70b723a07b57a9093bfca2db05715fbb2cd9872 100644 (file)
@@ -1297,6 +1297,48 @@ fail:
    return NULL;
 }
 
+/**
+ * This is the driver specific part of the createNewScreen entry point.
+ *
+ * Returns the struct gl_config supported by this driver.
+ */
+static const __DRIconfig **
+dri_kms_init_screen(__DRIscreen * sPriv)
+{
+#if GALLIUM_STATIC_TARGETS
+   const __DRIconfig **configs;
+   struct dri_screen *screen;
+   struct pipe_screen *pscreen = NULL;
+
+   screen = CALLOC_STRUCT(dri_screen);
+   if (!screen)
+      return NULL;
+
+   screen->sPriv = sPriv;
+   screen->fd = sPriv->fd;
+
+   sPriv->driverPrivate = (void *)screen;
+
+   pscreen = kms_swrast_create_screen(screen->fd);
+   sPriv->extensions = dri_screen_extensions;
+
+   /* dri_init_screen_helper checks pscreen for us */
+   configs = dri_init_screen_helper(screen, pscreen, "swrast");
+   if (!configs)
+      goto fail;
+
+   screen->auto_fake_front = dri_with_format(sPriv);
+   screen->broken_invalidate = !sPriv->dri2.useInvalidate;
+   screen->lookup_egl_image = dri2_lookup_egl_image;
+
+   return configs;
+fail:
+   dri_destroy_screen_helper(screen);
+   FREE(screen);
+#endif // GALLIUM_STATIC_TARGETS
+   return NULL;
+}
+
 static boolean
 dri2_create_buffer(__DRIscreen * sPriv,
                    __DRIdrawable * dPriv,
@@ -1335,6 +1377,27 @@ const struct __DriverAPIRec galliumdrm_driver_api = {
    .ReleaseBuffer  = dri2_release_buffer,
 };
 
+/**
+ * DRI driver virtual function table.
+ *
+ * KMS/DRM version of the DriverAPI above sporting a different InitScreen
+ * hook. The latter is used to explicitly initialise the kms_swrast driver
+ * rather than selecting the approapriate driver as suggested by the loader.
+ */
+const struct __DriverAPIRec dri_kms_driver_api = {
+   .InitScreen = dri_kms_init_screen,
+   .DestroyScreen = dri_destroy_screen,
+   .CreateContext = dri_create_context,
+   .DestroyContext = dri_destroy_context,
+   .CreateBuffer = dri2_create_buffer,
+   .DestroyBuffer = dri_destroy_buffer,
+   .MakeCurrent = dri_make_current,
+   .UnbindContext = dri_unbind_context,
+
+   .AllocateBuffer = dri2_allocate_buffer,
+   .ReleaseBuffer  = dri2_release_buffer,
+};
+
 /* This is the table of extensions that the loader will dlsym() for. */
 const __DRIextension *galliumdrm_driver_extensions[] = {
     &driCoreExtension.base,
index f421b68aed736251e5e5b28de0a3406e8cff018f..993ad2abe0975d1586bc038de72d0bf0f16c6a10 100644 (file)
@@ -146,6 +146,9 @@ dri_destroy_screen_helper(struct dri_screen * screen);
 void
 dri_destroy_screen(__DRIscreen * sPriv);
 
+extern struct pipe_screen *kms_swrast_create_screen(int fd);
+extern const struct __DriverAPIRec dri_kms_driver_api;
+
 extern const struct __DriverAPIRec galliumdrm_driver_api;
 extern const __DRIextension *galliumdrm_driver_extensions[];
 extern const struct __DriverAPIRec galliumsw_driver_api;
index 0816b8c9b25212a5206e94b945ce6f3686fdb0ca..c7fe4106ab01978820262932fa0de6ebbf64dae2 100644 (file)
@@ -146,6 +146,12 @@ STATIC_TARGET_CPPFLAGS += -DGALLIUM_SOFTPIPE
 STATIC_TARGET_LIB_DEPS += \
        $(top_builddir)/src/gallium/winsys/sw/dri/libswdri.la \
        $(top_builddir)/src/gallium/drivers/softpipe/libsoftpipe.la
+
+if HAVE_DRI2
+MEGADRIVERS += kms_swrast
+STATIC_TARGET_LIB_DEPS += \
+       $(top_builddir)/src/gallium/winsys/sw/kms-dri/libswkmsdri.la
+endif
 endif
 
 if NEED_GALLIUM_LLVMPIPE_DRIVER
index faf370f2c34e3efe542946b875dca1010565c779..8cb90b3153f203c46f37d7bf14d8a884a7dbb5eb 100644 (file)
@@ -36,6 +36,7 @@ env.Prepend(LIBS = [
     svgadrm,
     svga,
     ws_dri,
+    ws_kms_dri,
     softpipe,
     libloader,
     mesa,
@@ -55,6 +56,9 @@ module = env.LoadableModule(
 env.Command('vmwgfx_dri.so', 'gallium_dri.so', "ln -f ${SOURCE} ${TARGET}")
 # swrast_dri.so
 env.Command('swrast_dri.so', 'gallium_dri.so', "ln -f ${SOURCE} ${TARGET}")
+# kms_swrast_dri.so
+env.Command('kms_swrast_dri.so', 'gallium_dri.so', "ln -f ${SOURCE} ${TARGET}")
 
 env.Alias('dri-vmwgfx', module)
 env.Alias('dri-swrast', module)
+env.Alias('dri-kms-swrast', module)
index 7c4e5ad564c17dd1a4d4601e4cb8aa93c3641081..4c01afdee200190763a7f0687b49f9c6fbaf3cf2 100644 (file)
@@ -30,6 +30,10 @@ if HAVE_DRISW
 SUBDIRS += sw/dri
 endif
 
+if HAVE_DRI2
+SUBDIRS += sw/kms-dri
+endif
+
 if HAVE_EGL_PLATFORM_FBDEV
 SUBDIRS += sw/fbdev
 endif
diff --git a/src/gallium/winsys/sw/kms-dri/Makefile.am b/src/gallium/winsys/sw/kms-dri/Makefile.am
new file mode 100644 (file)
index 0000000..cb3b61d
--- /dev/null
@@ -0,0 +1,32 @@
+# Copyright © 2012 Intel Corporation
+#             2013 Red Hat, 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 (including the next
+# paragraph) 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.
+
+include $(top_srcdir)/src/gallium/Automake.inc
+
+AM_CFLAGS = \
+       $(GALLIUM_WINSYS_CFLAGS) \
+       $(LIBDRM_CFLAGS)
+
+noinst_LTLIBRARIES = libswkmsdri.la
+
+libswkmsdri_la_SOURCES = kms_dri_sw_winsys.c
diff --git a/src/gallium/winsys/sw/kms-dri/SConscript b/src/gallium/winsys/sw/kms-dri/SConscript
new file mode 100644 (file)
index 0000000..0a6c335
--- /dev/null
@@ -0,0 +1,26 @@
+#######################################################################
+# SConscript for kms-dri winsys
+
+
+Import('*')
+
+if env['platform'] not in ('linux'):
+    Return()
+
+env = env.Clone()
+
+env.PkgUseModules('DRM')
+
+env.Append(CPPPATH = [
+#    'include',
+    '#/src/gallium/include',
+    '#/src/gallium/auxiliary',
+])
+
+ws_kms_dri = env.ConvenienceLibrary(
+    target = 'ws_kms_dri',
+    source = [
+       'kms_dri_sw_winsys.c',
+    ]
+)
+Export('ws_kms_dri')
diff --git a/src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.c b/src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.c
new file mode 100644 (file)
index 0000000..e21c4c2
--- /dev/null
@@ -0,0 +1,312 @@
+/**************************************************************************
+ *
+ * Copyright 2009, VMware, Inc.
+ * All Rights Reserved.
+ * Copyright 2010 George Sapountzis <gsapountzis@gmail.com>
+ *           2013 Red Hat, 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, sub license, 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 (including the
+ * next paragraph) 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS 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.
+ *
+ **************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <string.h>
+#include <limits.h>
+
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <unistd.h>
+#include <dlfcn.h>
+#include <xf86drm.h>
+
+#include "pipe/p_compiler.h"
+#include "pipe/p_format.h"
+#include "util/u_inlines.h"
+#include "util/u_format.h"
+#include "util/u_math.h"
+#include "util/u_memory.h"
+#include "util/u_double_list.h"
+
+#include "state_tracker/sw_winsys.h"
+#include "state_tracker/drm_driver.h"
+
+#if 0
+#define DEBUG(msg, ...) fprintf(stderr, msg, __VA_ARGS__)
+#else
+#define DEBUG(msg, ...)
+#endif
+
+struct sw_winsys;
+
+struct sw_winsys *kms_dri_create_winsys(int fd);
+
+struct kms_sw_displaytarget
+{
+   enum pipe_format format;
+   unsigned width;
+   unsigned height;
+   unsigned stride;
+   unsigned size;
+
+   uint32_t handle;
+   void *mapped;
+
+   int ref_count;
+   struct list_head link;
+};
+
+struct kms_sw_winsys
+{
+   struct sw_winsys base;
+
+   int fd;
+   struct list_head bo_list;
+};
+
+static INLINE struct kms_sw_displaytarget *
+kms_sw_displaytarget( struct sw_displaytarget *dt )
+{
+   return (struct kms_sw_displaytarget *)dt;
+}
+
+static INLINE struct kms_sw_winsys *
+kms_sw_winsys( struct sw_winsys *ws )
+{
+   return (struct kms_sw_winsys *)ws;
+}
+
+
+static boolean
+kms_sw_is_displaytarget_format_supported( struct sw_winsys *ws,
+                                          unsigned tex_usage,
+                                          enum pipe_format format )
+{
+   /* TODO: check visuals or other sensible thing here */
+   return TRUE;
+}
+
+static struct sw_displaytarget *
+kms_sw_displaytarget_create(struct sw_winsys *ws,
+                            unsigned tex_usage,
+                            enum pipe_format format,
+                            unsigned width, unsigned height,
+                            unsigned alignment,
+                            unsigned *stride)
+{
+   struct kms_sw_winsys *kms_sw = kms_sw_winsys(ws);
+   struct kms_sw_displaytarget *kms_sw_dt;
+   struct drm_mode_create_dumb create_req;
+   struct drm_mode_destroy_dumb destroy_req;
+   int ret;
+
+   kms_sw_dt = CALLOC_STRUCT(kms_sw_displaytarget);
+   if(!kms_sw_dt)
+      goto no_dt;
+
+   kms_sw_dt->ref_count = 1;
+
+   kms_sw_dt->format = format;
+   kms_sw_dt->width = width;
+   kms_sw_dt->height = height;
+
+   create_req.bpp = 32;
+   create_req.width = width;
+   create_req.height = height;
+   create_req.handle = 0;
+   ret = drmIoctl(kms_sw->fd, DRM_IOCTL_MODE_CREATE_DUMB, &create_req);
+   if (ret)
+      goto free_bo;
+
+   kms_sw_dt->stride = create_req.pitch;
+   kms_sw_dt->size = create_req.size;
+   kms_sw_dt->handle = create_req.handle;
+
+   list_add(&kms_sw_dt->link, &kms_sw->bo_list);
+
+   DEBUG("KMS-DEBUG: created buffer %u (size %u)\n", kms_sw_dt->handle, kms_sw_dt->size);
+
+   *stride = kms_sw_dt->stride;
+   return (struct sw_displaytarget *)kms_sw_dt;
+
+ free_bo:
+   memset(&destroy_req, 0, sizeof destroy_req);
+   destroy_req.handle = create_req.handle;
+   drmIoctl(kms_sw->fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_req);
+   FREE(kms_sw_dt);
+ no_dt:
+   return NULL;
+}
+
+static void
+kms_sw_displaytarget_destroy(struct sw_winsys *ws,
+                             struct sw_displaytarget *dt)
+{
+   struct kms_sw_winsys *kms_sw = kms_sw_winsys(ws);
+   struct kms_sw_displaytarget *kms_sw_dt = kms_sw_displaytarget(dt);
+   struct drm_mode_destroy_dumb destroy_req;
+
+   kms_sw_dt->ref_count --;
+   if (kms_sw_dt->ref_count > 0)
+      return;
+
+   memset(&destroy_req, 0, sizeof destroy_req);
+   destroy_req.handle = kms_sw_dt->handle;
+   drmIoctl(kms_sw->fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_req);
+
+   list_del(&kms_sw_dt->link);
+
+   DEBUG("KMS-DEBUG: destroyed buffer %u\n", kms_sw_dt->handle);
+
+   FREE(kms_sw_dt);
+}
+
+static void *
+kms_sw_displaytarget_map(struct sw_winsys *ws,
+                         struct sw_displaytarget *dt,
+                         unsigned flags)
+{
+   struct kms_sw_winsys *kms_sw = kms_sw_winsys(ws);
+   struct kms_sw_displaytarget *kms_sw_dt = kms_sw_displaytarget(dt);
+   struct drm_mode_map_dumb map_req;
+   int prot, ret;
+
+   memset(&map_req, 0, sizeof map_req);
+   map_req.handle = kms_sw_dt->handle;
+   ret = drmIoctl(kms_sw->fd, DRM_IOCTL_MODE_MAP_DUMB, &map_req);
+   if (ret)
+      return NULL;
+
+   prot = (flags == PIPE_TRANSFER_READ) ? PROT_READ : (PROT_READ | PROT_WRITE);
+   kms_sw_dt->mapped = mmap(0, kms_sw_dt->size, prot, MAP_SHARED,
+                            kms_sw->fd, map_req.offset);
+
+   if (kms_sw_dt->mapped == MAP_FAILED)
+      return NULL;
+
+   DEBUG("KMS-DEBUG: mapped buffer %u (size %u) at %p\n",
+         kms_sw_dt->handle, kms_sw_dt->size, kms_sw_dt->mapped);
+
+   return kms_sw_dt->mapped;
+}
+
+static void
+kms_sw_displaytarget_unmap(struct sw_winsys *ws,
+                           struct sw_displaytarget *dt)
+{
+   struct kms_sw_displaytarget *kms_sw_dt = kms_sw_displaytarget(dt);
+
+   DEBUG("KMS-DEBUG: unmapped buffer %u (was %p)\n", kms_sw_dt->handle, kms_sw_dt->mapped);
+
+   munmap(kms_sw_dt->mapped, kms_sw_dt->size);
+   kms_sw_dt->mapped = NULL;
+}
+
+static struct sw_displaytarget *
+kms_sw_displaytarget_from_handle(struct sw_winsys *ws,
+                                 const struct pipe_resource *templ,
+                                 struct winsys_handle *whandle,
+                                 unsigned *stride)
+{
+   struct kms_sw_winsys *kms_sw = kms_sw_winsys(ws);
+   struct kms_sw_displaytarget *kms_sw_dt;
+
+   LIST_FOR_EACH_ENTRY(kms_sw_dt, &kms_sw->bo_list, link) {
+      if (kms_sw_dt->handle == whandle->handle) {
+         kms_sw_dt->ref_count++;
+
+         DEBUG("KMS-DEBUG: imported buffer %u (size %u)\n", kms_sw_dt->handle, kms_sw_dt->size);
+
+         *stride = kms_sw_dt->stride;
+         return (struct sw_displaytarget *)kms_sw_dt;
+      }
+   }
+
+   assert(0);
+   return NULL;
+}
+
+static boolean
+kms_sw_displaytarget_get_handle(struct sw_winsys *winsys,
+                                struct sw_displaytarget *dt,
+                                struct winsys_handle *whandle)
+{
+   struct kms_sw_displaytarget *kms_sw_dt = kms_sw_displaytarget(dt);
+
+   assert(whandle->type == DRM_API_HANDLE_TYPE_SHARED);
+   whandle->handle = kms_sw_dt->handle;
+   whandle->stride = kms_sw_dt->stride;
+   return TRUE;
+}
+
+static void
+kms_sw_displaytarget_display(struct sw_winsys *ws,
+                             struct sw_displaytarget *dt,
+                             void *context_private,
+                             struct pipe_box *box)
+{
+   /* This function should not be called, instead the dri2 loader should
+      handle swap buffers internally.
+   */
+   assert(0);
+}
+
+
+static void
+kms_destroy_sw_winsys(struct sw_winsys *winsys)
+{
+   FREE(winsys);
+}
+
+struct sw_winsys *
+kms_dri_create_winsys(int fd)
+{
+   struct kms_sw_winsys *ws;
+
+   ws = CALLOC_STRUCT(kms_sw_winsys);
+   if (!ws)
+      return NULL;
+
+   ws->fd = fd;
+   list_inithead(&ws->bo_list);
+
+   ws->base.destroy = kms_destroy_sw_winsys;
+
+   ws->base.is_displaytarget_format_supported = kms_sw_is_displaytarget_format_supported;
+
+   /* screen texture functions */
+   ws->base.displaytarget_create = kms_sw_displaytarget_create;
+   ws->base.displaytarget_destroy = kms_sw_displaytarget_destroy;
+   ws->base.displaytarget_from_handle = kms_sw_displaytarget_from_handle;
+   ws->base.displaytarget_get_handle = kms_sw_displaytarget_get_handle;
+
+   /* texture functions */
+   ws->base.displaytarget_map = kms_sw_displaytarget_map;
+   ws->base.displaytarget_unmap = kms_sw_displaytarget_unmap;
+
+   ws->base.displaytarget_display = kms_sw_displaytarget_display;
+
+   return &ws->base;
+}
+
+/* vim: set sw=3 ts=8 sts=3 expandtab: */
\ No newline at end of file
diff --git a/src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.h b/src/gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.h
new file mode 100644 (file)
index 0000000..e276a72
--- /dev/null
@@ -0,0 +1,37 @@
+/**************************************************************************
+ *
+ * Copyright 2009, VMware, Inc.
+ * All Rights Reserved.
+ * Copyright 2010 George Sapountzis <gsapountzis@gmail.com>
+ *           2013 Red Hat, 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, sub license, 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 (including the
+ * next paragraph) 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 NON-INFRINGEMENT.
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS 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.
+ *
+ **************************************************************************/
+
+#ifndef KMS_DRI_SW_WINSYS
+#define KMS_DRI_SW_WINSYS
+
+struct sw_winsys;
+
+struct sw_winsys *kms_dri_create_winsys(int fd);
+
+#endif
index 7b28be1ba0fadb1efddd77da5fdaa7550f050ab9..258e8a84a6e7e881edbce4f6818b106dad687dba 100644 (file)
@@ -403,12 +403,13 @@ dri_load_driver_swrast(struct gbm_dri_device *dri)
 }
 
 static int
-dri_screen_create(struct gbm_dri_device *dri)
+dri_screen_create_dri2(struct gbm_dri_device *dri,
+                       const char *driver_name)
 {
    const __DRIextension **extensions;
    int ret = 0;
 
-   dri->base.driver_name = loader_get_driver_for_fd(dri->base.base.fd, 0);
+   dri->base.driver_name = driver_name;
    if (dri->base.driver_name == NULL)
       return -1;
 
@@ -490,6 +491,35 @@ dri_screen_create_swrast(struct gbm_dri_device *dri)
    return 0;
 }
 
+static int
+dri_screen_create(struct gbm_dri_device *dri)
+{
+   const char *driver_name;
+
+   driver_name = loader_get_driver_for_fd(dri->base.base.fd, 0);
+   if (!driver_name)
+      return -1;
+
+   return dri_screen_create_dri2(dri, driver_name);
+}
+
+static int
+dri_screen_create_sw(struct gbm_dri_device *dri)
+{
+   const char *driver_name;
+   int ret;
+
+   driver_name = strdup("kms_swrast");
+   if (!driver_name)
+      return -errno;
+
+   ret = dri_screen_create_dri2(dri, driver_name);
+   if (ret == 0)
+      return ret;
+
+   return dri_screen_create_swrast(dri);
+}
+
 static int
 gbm_dri_is_format_supported(struct gbm_device *gbm,
                             uint32_t format,
@@ -920,9 +950,9 @@ dri_device_create(int fd)
    if (!force_sw) {
       ret = dri_screen_create(dri);
       if (ret)
-         ret = dri_screen_create_swrast(dri);
+         ret = dri_screen_create_sw(dri);
    } else {
-      ret = dri_screen_create_swrast(dri);
+      ret = dri_screen_create_sw(dri);
    }
 
    if (ret)