pb_winsys.c

Go to the documentation of this file.
00001 /**************************************************************************
00002  *
00003  * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
00004  * All Rights Reserved.
00005  *
00006  * Permission is hereby granted, free of charge, to any person obtaining a
00007  * copy of this software and associated documentation files (the
00008  * "Software"), to deal in the Software without restriction, including
00009  * without limitation the rights to use, copy, modify, merge, publish,
00010  * distribute, sub license, and/or sell copies of the Software, and to
00011  * permit persons to whom the Software is furnished to do so, subject to
00012  * the following conditions:
00013  *
00014  * The above copyright notice and this permission notice (including the
00015  * next paragraph) shall be included in all copies or substantial portions
00016  * of the Software.
00017  *
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00019  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00020  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
00021  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
00022  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
00023  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
00024  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00025  *
00026  **************************************************************************/
00027 
00037 #include "pipe/p_winsys.h"
00038 #include "util/u_memory.h"
00039 
00040 #include "pb_buffer.h"
00041 
00042 
00052 struct pb_user_buffer 
00053 {
00054    struct pb_buffer base;
00055    void *data;
00056 };
00057 
00058 
00059 extern const struct pb_vtbl pb_user_buffer_vtbl;
00060 
00061 
00062 static INLINE struct pb_user_buffer *
00063 pb_user_buffer(struct pb_buffer *buf)
00064 {
00065    assert(buf);
00066    assert(buf->vtbl == &pb_user_buffer_vtbl);
00067    return (struct pb_user_buffer *)buf;
00068 }
00069 
00070 
00071 static void
00072 pb_user_buffer_destroy(struct pb_buffer *buf)
00073 {
00074    assert(buf);
00075    FREE(buf);
00076 }
00077 
00078 
00079 static void *
00080 pb_user_buffer_map(struct pb_buffer *buf, 
00081                    unsigned flags)
00082 {
00083    return pb_user_buffer(buf)->data;
00084 }
00085 
00086 
00087 static void
00088 pb_user_buffer_unmap(struct pb_buffer *buf)
00089 {
00090    /* No-op */
00091 }
00092 
00093 
00094 static void
00095 pb_user_buffer_get_base_buffer(struct pb_buffer *buf,
00096                                struct pb_buffer **base_buf,
00097                                unsigned *offset)
00098 {
00099    *base_buf = buf;
00100    *offset = 0;
00101 }
00102 
00103 
00104 const struct pb_vtbl 
00105 pb_user_buffer_vtbl = {
00106       pb_user_buffer_destroy,
00107       pb_user_buffer_map,
00108       pb_user_buffer_unmap,
00109       pb_user_buffer_get_base_buffer
00110 };
00111 
00112 
00113 static struct pipe_buffer *
00114 pb_winsys_user_buffer_create(struct pipe_winsys *winsys,
00115                              void *data, 
00116                              unsigned bytes) 
00117 {
00118    struct pb_user_buffer *buf = CALLOC_STRUCT(pb_user_buffer);
00119 
00120    if(!buf)
00121       return NULL;
00122    
00123    buf->base.base.refcount = 1;
00124    buf->base.base.size = bytes;
00125    buf->base.base.alignment = 0;
00126    buf->base.base.usage = 0;
00127 
00128    buf->base.vtbl = &pb_user_buffer_vtbl;   
00129    buf->data = data;
00130    
00131    return &buf->base.base;
00132 }
00133 
00134 
00135 static void *
00136 pb_winsys_buffer_map(struct pipe_winsys *winsys,
00137                      struct pipe_buffer *buf,
00138                      unsigned flags)
00139 {
00140    (void)winsys;
00141    return pb_map(pb_buffer(buf), flags);
00142 }
00143 
00144 
00145 static void
00146 pb_winsys_buffer_unmap(struct pipe_winsys *winsys,
00147                        struct pipe_buffer *buf)
00148 {
00149    (void)winsys;
00150    pb_unmap(pb_buffer(buf));
00151 }
00152 
00153 
00154 static void
00155 pb_winsys_buffer_destroy(struct pipe_winsys *winsys,
00156                          struct pipe_buffer *buf)
00157 {
00158    (void)winsys;
00159    pb_destroy(pb_buffer(buf));
00160 }
00161 
00162 
00163 void 
00164 pb_init_winsys(struct pipe_winsys *winsys)
00165 {
00166    winsys->user_buffer_create = pb_winsys_user_buffer_create;
00167    winsys->buffer_map = pb_winsys_buffer_map;
00168    winsys->buffer_unmap = pb_winsys_buffer_unmap;
00169    winsys->buffer_destroy = pb_winsys_buffer_destroy;
00170 }

Generated on Tue Sep 29 06:25:14 2009 for Gallium3D by  doxygen 1.5.4