00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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
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 }