Merge branch 'mesa_7_6_branch'
[mesa.git] / src / gallium / winsys / g3dvl / xsp_winsys.c
index 68be2c2ea3afca16a8d6b81ab2fc68d3302b6cb1..37d60ce5406224280606dcafe0235202cbe8aa50 100644 (file)
@@ -1,10 +1,12 @@
 #include "vl_winsys.h"
 #include <X11/Xutil.h>
-#include <pipe/p_winsys.h>
+#include <pipe/internal/p_winsys_screen.h>
 #include <pipe/p_state.h>
 #include <pipe/p_inlines.h>
 #include <util/u_memory.h>
+#include <util/u_math.h>
 #include <softpipe/sp_winsys.h>
+#include <softpipe/sp_texture.h>
 
 /* pipe_winsys implementation */
 
@@ -37,7 +39,7 @@ static struct pipe_buffer* xsp_buffer_create(struct pipe_winsys *pws, unsigned a
        assert(pws);
 
        buffer = calloc(1, sizeof(struct xsp_buffer));
-       buffer->base.refcount = 1;
+       pipe_reference_init(&buffer->base.reference, 1);
        buffer->base.alignment = alignment;
        buffer->base.usage = usage;
        buffer->base.size = size;
@@ -53,7 +55,7 @@ static struct pipe_buffer* xsp_user_buffer_create(struct pipe_winsys *pws, void
        assert(pws);
 
        buffer = calloc(1, sizeof(struct xsp_buffer));
-       buffer->base.refcount = 1;
+       pipe_reference_init(&buffer->base.reference, 1);
        buffer->base.size = size;
        buffer->is_user_buffer = TRUE;
        buffer->data = data;
@@ -96,73 +98,29 @@ static void xsp_buffer_destroy(struct pipe_winsys *pws, struct pipe_buffer *buff
        free(xsp_buf);
 }
 
-static struct pipe_surface* xsp_surface_alloc(struct pipe_winsys *pws)
-{
-       struct pipe_surface *surface;
-
-       assert(pws);
-
-       surface = calloc(1, sizeof(struct pipe_surface));
-       surface->refcount = 1;
-       surface->winsys = pws;
-
-       return surface;
-}
-
-/* Borrowed from Mesa's xm_winsys */
-static unsigned int round_up(unsigned n, unsigned multiple)
-{
-   return (n + multiple - 1) & ~(multiple - 1);
-}
-
-static int xsp_surface_alloc_storage
+static struct pipe_buffer* xsp_surface_buffer_create
 (
        struct pipe_winsys *pws,
-       struct pipe_surface *surface,
        unsigned width,
        unsigned height,
        enum pipe_format format,
-       unsigned flags,
-       unsigned tex_usage
+       unsigned usage,
+       unsigned tex_usage,
+       unsigned *stride
 )
 {
        const unsigned int ALIGNMENT = 1;
+       struct pipe_format_block block;
+       unsigned nblocksx, nblocksy;
 
-       assert(pws);
-       assert(surface);
-
-       surface->width = width;
-       surface->height = height;
-       surface->format = format;
-       pf_get_block(format, &surface->block);
-       surface->nblocksx = pf_get_nblocksx(&surface->block, width);
-       surface->nblocksy = pf_get_nblocksy(&surface->block, height);
-       surface->stride = round_up(surface->nblocksx * surface->block.size, ALIGNMENT);
-       surface->usage = flags;
-       surface->buffer = pws->buffer_create(pws, ALIGNMENT, PIPE_BUFFER_USAGE_PIXEL, surface->stride * surface->nblocksy);
-
-       return 0;
-}
-
-static void xsp_surface_release(struct pipe_winsys *pws, struct pipe_surface **surface)
-{
-       struct pipe_surface *s;
-
-       assert(pws);
-       assert(surface);
-       assert(*surface);
-
-       s = *surface;
-
-       s->refcount--;
-
-       if (s->refcount == 0)
-       {
-               winsys_buffer_reference(pws, &s->buffer, NULL);
-               free(s);
-       }
+       pf_get_block(format, &block);
+       nblocksx = pf_get_nblocksx(&block, width);
+       nblocksy = pf_get_nblocksy(&block, height);
+       *stride = align(nblocksx * block.size, ALIGNMENT);
 
-       *surface = NULL;
+       return pws->buffer_create(pws, ALIGNMENT,
+                                 usage,
+                                 *stride * nblocksy);
 }
 
 static void xsp_fence_reference(struct pipe_winsys *pws, struct pipe_fence_handle **ptr, struct pipe_fence_handle *fence)
@@ -206,7 +164,7 @@ static void xsp_flush_frontbuffer(struct pipe_winsys *pws, struct pipe_surface *
        xsp_winsys->fbimage.width = surface->width;
        xsp_winsys->fbimage.height = surface->height;
        xsp_winsys->fbimage.bytes_per_line = surface->width * (xsp_winsys->fbimage.bits_per_pixel >> 3);
-       xsp_winsys->fbimage.data = pipe_surface_map(surface, 0);
+       xsp_winsys->fbimage.data = ((struct xsp_buffer *)softpipe_texture(surface->texture)->buffer)->data + surface->offset;
 
        XPutImage
        (
@@ -222,7 +180,6 @@ static void xsp_flush_frontbuffer(struct pipe_winsys *pws, struct pipe_surface *
                surface->height
        );
        XFlush(xsp_context->display);
-       pipe_surface_unmap(surface);
 }
 
 static const char* xsp_get_name(struct pipe_winsys *pws)
@@ -273,9 +230,7 @@ struct pipe_context* create_pipe_context(Display *display, int screen)
        xsp_winsys->base.buffer_map = xsp_buffer_map;
        xsp_winsys->base.buffer_unmap = xsp_buffer_unmap;
        xsp_winsys->base.buffer_destroy = xsp_buffer_destroy;
-       xsp_winsys->base.surface_alloc = xsp_surface_alloc;
-       xsp_winsys->base.surface_alloc_storage = xsp_surface_alloc_storage;
-       xsp_winsys->base.surface_release = xsp_surface_release;
+       xsp_winsys->base.surface_buffer_create = xsp_surface_buffer_create;
        xsp_winsys->base.fence_reference = xsp_fence_reference;
        xsp_winsys->base.fence_signalled = xsp_fence_signalled;
        xsp_winsys->base.fence_finish = xsp_fence_finish;
@@ -307,7 +262,7 @@ struct pipe_context* create_pipe_context(Display *display, int screen)
        }
 
        sp_screen = softpipe_create_screen((struct pipe_winsys*)xsp_winsys);
-       sp_pipe = softpipe_create(sp_screen, (struct pipe_winsys*)xsp_winsys, NULL);
+       sp_pipe = softpipe_create(sp_screen);
 
        xsp_context = calloc(1, sizeof(struct xsp_context));
        xsp_context->display = display;