softpipe: Move st/python's malloc winsys to softpipe
authorJakob Bornecrantz <jakob@vmware.com>
Sun, 17 Jan 2010 14:18:26 +0000 (14:18 +0000)
committerJakob Bornecrantz <jakob@vmware.com>
Sun, 17 Jan 2010 16:44:39 +0000 (16:44 +0000)
Users of softpipe can still specify thier own winsys
but now there is a default one also that uses malloc.
This allows the malloc winsys to be shared with other
users of softpipe.

src/gallium/drivers/softpipe/Makefile
src/gallium/drivers/softpipe/SConscript
src/gallium/drivers/softpipe/sp_winsys.c [new file with mode: 0644]
src/gallium/drivers/softpipe/sp_winsys.h
src/gallium/state_trackers/python/st_softpipe_winsys.c

index bcb887a0b2614fa1f113a093287cf9d6324e18e1..e4ac49fa85f40a49f6f095ec13e4c68f3bd0d66b 100644 (file)
@@ -32,6 +32,7 @@ C_SOURCES = \
        sp_tex_tile_cache.c \
        sp_tile_cache.c \
        sp_surface.c \
-       sp_video_context.c
+       sp_video_context.c \
+       sp_winsys.c
 
 include ../../Makefile.template
index aac9edf44e6ad7c0f1c7c84dcd5adbab8d0ca707..3042e556c6417f7b07d5dc055f535afa9e0d0a70 100644 (file)
@@ -34,6 +34,7 @@ softpipe = env.ConvenienceLibrary(
                'sp_texture.c',
                'sp_tile_cache.c',
                'sp_video_context.c',
+               'sp_winsys.c'
        ])
 
 Export('softpipe')
diff --git a/src/gallium/drivers/softpipe/sp_winsys.c b/src/gallium/drivers/softpipe/sp_winsys.c
new file mode 100644 (file)
index 0000000..8169071
--- /dev/null
@@ -0,0 +1,245 @@
+/**************************************************************************
+ * 
+ * Copyright 2007 Tungsten Graphics, Inc., Bismarck, ND., USA
+ * All Rights Reserved.
+ * 
+ * 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 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
+ * THE COPYRIGHT HOLDERS, AUTHORS 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.
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ * 
+ * 
+ **************************************************************************/
+
+/**
+ * @file
+ * Malloc softpipe winsys. Uses malloc for all memory allocations.
+ * 
+ * @author Keith Whitwell
+ * @author Brian Paul
+ * @author Jose Fonseca
+ */
+
+
+#include "pipe/internal/p_winsys_screen.h"/* port to just p_screen */
+#include "pipe/p_format.h"
+#include "pipe/p_context.h"
+#include "pipe/p_inlines.h"
+#include "util/u_format.h"
+#include "util/u_math.h"
+#include "util/u_memory.h"
+#include "softpipe/sp_winsys.h"
+
+
+struct st_softpipe_buffer
+{
+   struct pipe_buffer base;
+   boolean userBuffer;  /** Is this a user-space buffer? */
+   void *data;
+   void *mapped;
+};
+
+
+/** Cast wrapper */
+static INLINE struct st_softpipe_buffer *
+st_softpipe_buffer( struct pipe_buffer *buf )
+{
+   return (struct st_softpipe_buffer *)buf;
+}
+
+
+static void *
+st_softpipe_buffer_map(struct pipe_winsys *winsys, 
+                       struct pipe_buffer *buf,
+                       unsigned flags)
+{
+   struct st_softpipe_buffer *st_softpipe_buf = st_softpipe_buffer(buf);
+   st_softpipe_buf->mapped = st_softpipe_buf->data;
+   return st_softpipe_buf->mapped;
+}
+
+
+static void
+st_softpipe_buffer_unmap(struct pipe_winsys *winsys, 
+                         struct pipe_buffer *buf)
+{
+   struct st_softpipe_buffer *st_softpipe_buf = st_softpipe_buffer(buf);
+   st_softpipe_buf->mapped = NULL;
+}
+
+
+static void
+st_softpipe_buffer_destroy(struct pipe_buffer *buf)
+{
+   struct st_softpipe_buffer *oldBuf = st_softpipe_buffer(buf);
+
+   if (oldBuf->data) {
+      if (!oldBuf->userBuffer)
+         align_free(oldBuf->data);
+
+      oldBuf->data = NULL;
+   }
+
+   FREE(oldBuf);
+}
+
+
+static void
+st_softpipe_flush_frontbuffer(struct pipe_winsys *winsys,
+                              struct pipe_surface *surf,
+                              void *context_private)
+{
+}
+
+
+
+static const char *
+st_softpipe_get_name(struct pipe_winsys *winsys)
+{
+   return "softpipe";
+}
+
+
+static struct pipe_buffer *
+st_softpipe_buffer_create(struct pipe_winsys *winsys, 
+                          unsigned alignment, 
+                          unsigned usage,
+                          unsigned size)
+{
+   struct st_softpipe_buffer *buffer = CALLOC_STRUCT(st_softpipe_buffer);
+
+   pipe_reference_init(&buffer->base.reference, 1);
+   buffer->base.alignment = alignment;
+   buffer->base.usage = usage;
+   buffer->base.size = size;
+
+   buffer->data = align_malloc(size, alignment);
+
+   return &buffer->base;
+}
+
+
+/**
+ * Create buffer which wraps user-space data.
+ */
+static struct pipe_buffer *
+st_softpipe_user_buffer_create(struct pipe_winsys *winsys, 
+                               void *ptr, 
+                               unsigned bytes)
+{
+   struct st_softpipe_buffer *buffer;
+   
+   buffer = CALLOC_STRUCT(st_softpipe_buffer);
+   if(!buffer)
+      return NULL;
+   
+   pipe_reference_init(&buffer->base.reference, 1);
+   buffer->base.size = bytes;
+   buffer->userBuffer = TRUE;
+   buffer->data = ptr;
+
+   return &buffer->base;
+}
+
+
+static struct pipe_buffer *
+st_softpipe_surface_buffer_create(struct pipe_winsys *winsys,
+                                  unsigned width, unsigned height,
+                                  enum pipe_format format,
+                                  unsigned usage,
+                                  unsigned tex_usage,
+                                  unsigned *stride)
+{
+   const unsigned alignment = 64;
+   unsigned nblocksy;
+
+   nblocksy = util_format_get_nblocksy(format, height);
+   *stride = align(util_format_get_stride(format, width), alignment);
+
+   return winsys->buffer_create(winsys, alignment,
+                                usage,
+                                *stride * nblocksy);
+}
+
+
+static void
+st_softpipe_fence_reference(struct pipe_winsys *winsys, 
+                            struct pipe_fence_handle **ptr,
+                            struct pipe_fence_handle *fence)
+{
+}
+
+
+static int
+st_softpipe_fence_signalled(struct pipe_winsys *winsys, 
+                            struct pipe_fence_handle *fence,
+                            unsigned flag)
+{
+   return 0;
+}
+
+
+static int
+st_softpipe_fence_finish(struct pipe_winsys *winsys, 
+                         struct pipe_fence_handle *fence,
+                         unsigned flag)
+{
+   return 0;
+}
+
+
+static void
+st_softpipe_destroy(struct pipe_winsys *winsys)
+{
+   FREE(winsys);
+}
+
+
+struct pipe_screen *
+softpipe_create_screen_malloc(void)
+{
+   static struct pipe_winsys *winsys;
+   struct pipe_screen *screen;
+
+   winsys = CALLOC_STRUCT(pipe_winsys);
+   if(!winsys)
+      return NULL;
+
+   winsys->destroy = st_softpipe_destroy;
+   
+   winsys->buffer_create = st_softpipe_buffer_create;
+   winsys->user_buffer_create = st_softpipe_user_buffer_create;
+   winsys->buffer_map = st_softpipe_buffer_map;
+   winsys->buffer_unmap = st_softpipe_buffer_unmap;
+   winsys->buffer_destroy = st_softpipe_buffer_destroy;
+
+   winsys->surface_buffer_create = st_softpipe_surface_buffer_create;
+
+   winsys->fence_reference = st_softpipe_fence_reference;
+   winsys->fence_signalled = st_softpipe_fence_signalled;
+   winsys->fence_finish = st_softpipe_fence_finish;
+
+   winsys->flush_frontbuffer = st_softpipe_flush_frontbuffer;
+   winsys->get_name = st_softpipe_get_name;
+
+   screen = softpipe_create_screen(winsys);
+   if(!screen)
+      st_softpipe_destroy(winsys);
+
+   return screen;
+}
index f203ded29eee72a6bdf674117faa2804d6ad1e9a..3042e01a05c9df1d245e8bdb44a657d649f6ee9a 100644 (file)
@@ -49,10 +49,17 @@ struct pipe_buffer;
 
 struct pipe_context *softpipe_create( struct pipe_screen * );
 
+/**
+ * Create a softpipe screen that uses the
+ * given winsys for allocating buffers.
+ */
+struct pipe_screen *softpipe_create_screen( struct pipe_winsys * );
 
-struct pipe_screen *
-softpipe_create_screen(struct pipe_winsys *);
-
+/**
+ * Create a softpipe screen that uses
+ * regular malloc to create all its buffers.
+ */
+struct pipe_screen *softpipe_create_screen_malloc(void);
 
 boolean
 softpipe_get_texture_buffer( struct pipe_texture *texture,
index a3294e877a62217e938f63bb2d60f6719afbdb9f..dfe3e465f7785ae001e7e97784b53d13c91bf101 100644 (file)
  * @author Jose Fonseca
  */
 
-
-#include "pipe/internal/p_winsys_screen.h"/* port to just p_screen */
-#include "pipe/p_format.h"
-#include "pipe/p_context.h"
-#include "pipe/p_inlines.h"
-#include "util/u_format.h"
-#include "util/u_math.h"
-#include "util/u_memory.h"
 #include "softpipe/sp_winsys.h"
 #include "st_winsys.h"
 
-
-struct st_softpipe_buffer
-{
-   struct pipe_buffer base;
-   boolean userBuffer;  /** Is this a user-space buffer? */
-   void *data;
-   void *mapped;
-};
-
-
-/** Cast wrapper */
-static INLINE struct st_softpipe_buffer *
-st_softpipe_buffer( struct pipe_buffer *buf )
-{
-   return (struct st_softpipe_buffer *)buf;
-}
-
-
-static void *
-st_softpipe_buffer_map(struct pipe_winsys *winsys, 
-                       struct pipe_buffer *buf,
-                       unsigned flags)
-{
-   struct st_softpipe_buffer *st_softpipe_buf = st_softpipe_buffer(buf);
-   st_softpipe_buf->mapped = st_softpipe_buf->data;
-   return st_softpipe_buf->mapped;
-}
-
-
-static void
-st_softpipe_buffer_unmap(struct pipe_winsys *winsys, 
-                         struct pipe_buffer *buf)
-{
-   struct st_softpipe_buffer *st_softpipe_buf = st_softpipe_buffer(buf);
-   st_softpipe_buf->mapped = NULL;
-}
-
-
-static void
-st_softpipe_buffer_destroy(struct pipe_buffer *buf)
-{
-   struct st_softpipe_buffer *oldBuf = st_softpipe_buffer(buf);
-
-   if (oldBuf->data) {
-      if (!oldBuf->userBuffer)
-         align_free(oldBuf->data);
-
-      oldBuf->data = NULL;
-   }
-
-   FREE(oldBuf);
-}
-
-
-static void
-st_softpipe_flush_frontbuffer(struct pipe_winsys *winsys,
-                              struct pipe_surface *surf,
-                              void *context_private)
-{
-}
-
-
-
-static const char *
-st_softpipe_get_name(struct pipe_winsys *winsys)
-{
-   return "softpipe";
-}
-
-
-static struct pipe_buffer *
-st_softpipe_buffer_create(struct pipe_winsys *winsys, 
-                          unsigned alignment, 
-                          unsigned usage,
-                          unsigned size)
-{
-   struct st_softpipe_buffer *buffer = CALLOC_STRUCT(st_softpipe_buffer);
-
-   pipe_reference_init(&buffer->base.reference, 1);
-   buffer->base.alignment = alignment;
-   buffer->base.usage = usage;
-   buffer->base.size = size;
-
-   buffer->data = align_malloc(size, alignment);
-
-   return &buffer->base;
-}
-
-
-/**
- * Create buffer which wraps user-space data.
- */
-static struct pipe_buffer *
-st_softpipe_user_buffer_create(struct pipe_winsys *winsys, 
-                               void *ptr, 
-                               unsigned bytes)
-{
-   struct st_softpipe_buffer *buffer;
-   
-   buffer = CALLOC_STRUCT(st_softpipe_buffer);
-   if(!buffer)
-      return NULL;
-   
-   pipe_reference_init(&buffer->base.reference, 1);
-   buffer->base.size = bytes;
-   buffer->userBuffer = TRUE;
-   buffer->data = ptr;
-
-   return &buffer->base;
-}
-
-
-static struct pipe_buffer *
-st_softpipe_surface_buffer_create(struct pipe_winsys *winsys,
-                                  unsigned width, unsigned height,
-                                  enum pipe_format format,
-                                  unsigned usage,
-                                  unsigned tex_usage,
-                                  unsigned *stride)
-{
-   const unsigned alignment = 64;
-   unsigned nblocksy;
-
-   nblocksy = util_format_get_nblocksy(format, height);
-   *stride = align(util_format_get_stride(format, width), alignment);
-
-   return winsys->buffer_create(winsys, alignment,
-                                usage,
-                                *stride * nblocksy);
-}
-
-
-static void
-st_softpipe_fence_reference(struct pipe_winsys *winsys, 
-                            struct pipe_fence_handle **ptr,
-                            struct pipe_fence_handle *fence)
-{
-}
-
-
-static int
-st_softpipe_fence_signalled(struct pipe_winsys *winsys, 
-                            struct pipe_fence_handle *fence,
-                            unsigned flag)
-{
-   return 0;
-}
-
-
-static int
-st_softpipe_fence_finish(struct pipe_winsys *winsys, 
-                         struct pipe_fence_handle *fence,
-                         unsigned flag)
-{
-   return 0;
-}
-
-
-static void
-st_softpipe_destroy(struct pipe_winsys *winsys)
-{
-   FREE(winsys);
-}
-
-
-static struct pipe_screen *
-st_softpipe_screen_create(void)
-{
-   static struct pipe_winsys *winsys;
-   struct pipe_screen *screen;
-
-   winsys = CALLOC_STRUCT(pipe_winsys);
-   if(!winsys)
-      return NULL;
-
-   winsys->destroy = st_softpipe_destroy;
-   
-   winsys->buffer_create = st_softpipe_buffer_create;
-   winsys->user_buffer_create = st_softpipe_user_buffer_create;
-   winsys->buffer_map = st_softpipe_buffer_map;
-   winsys->buffer_unmap = st_softpipe_buffer_unmap;
-   winsys->buffer_destroy = st_softpipe_buffer_destroy;
-
-   winsys->surface_buffer_create = st_softpipe_surface_buffer_create;
-
-   winsys->fence_reference = st_softpipe_fence_reference;
-   winsys->fence_signalled = st_softpipe_fence_signalled;
-   winsys->fence_finish = st_softpipe_fence_finish;
-
-   winsys->flush_frontbuffer = st_softpipe_flush_frontbuffer;
-   winsys->get_name = st_softpipe_get_name;
-
-   screen = softpipe_create_screen(winsys);
-   if(!screen)
-      st_softpipe_destroy(winsys);
-
-   return screen;
-}
-
-
-static struct pipe_context *
-st_softpipe_context_create(struct pipe_screen *screen)
-{
-   return softpipe_create(screen);
-}
-
-
 const struct st_winsys st_softpipe_winsys = {
-   &st_softpipe_screen_create,
-   &st_softpipe_context_create,
+   &softpipe_create_screen_malloc,
+   &softpipe_create,
 };