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
00028 #ifndef P_INLINES_H
00029 #define P_INLINES_H
00030
00031 #include "p_context.h"
00032 #include "p_defines.h"
00033 #include "p_screen.h"
00034 #include "p_winsys.h"
00035
00036
00037 #ifdef __cplusplus
00038 extern "C" {
00039 #endif
00040
00041
00042
00043
00044
00045 static INLINE void *
00046 pipe_surface_map( struct pipe_surface *surf, unsigned flags )
00047 {
00048 if (surf->texture) {
00049 struct pipe_screen *screen = surf->texture->screen;
00050 return surf->texture->screen->surface_map( screen, surf, flags );
00051 }
00052 else {
00053 struct pipe_winsys *winsys = surf->winsys;
00054 char *map = (char *)winsys->buffer_map( winsys, surf->buffer, flags );
00055 if (map == NULL)
00056 return NULL;
00057 return (void *)(map + surf->offset);
00058 }
00059 }
00060
00061 static INLINE void
00062 pipe_surface_unmap( struct pipe_surface *surf )
00063 {
00064 if (surf->texture) {
00065 struct pipe_screen *screen = surf->texture->screen;
00066 surf->texture->screen->surface_unmap( screen, surf );
00067 }
00068 else {
00069 struct pipe_winsys *winsys = surf->winsys;
00070 winsys->buffer_unmap( winsys, surf->buffer );
00071 }
00072 }
00073
00074
00075
00081 static INLINE void
00082 pipe_surface_reference(struct pipe_surface **ptr, struct pipe_surface *surf)
00083 {
00084
00085 if (surf)
00086 surf->refcount++;
00087
00088 if (*ptr) {
00089
00090
00091
00092
00093 if ((*ptr)->texture) {
00094 struct pipe_screen *screen = (*ptr)->texture->screen;
00095 screen->tex_surface_release( screen, ptr );
00096 }
00097 else {
00098 struct pipe_winsys *winsys = (*ptr)->winsys;
00099 winsys->surface_release(winsys, ptr);
00100 }
00101
00102 assert(!*ptr);
00103 }
00104
00105 *ptr = surf;
00106 }
00107
00108
00109
00110
00111 static INLINE void
00112 winsys_buffer_reference(struct pipe_winsys *winsys,
00113 struct pipe_buffer **ptr,
00114 struct pipe_buffer *buf)
00115 {
00116 if (buf)
00117 buf->refcount++;
00118
00119 if (*ptr && --(*ptr)->refcount == 0)
00120 winsys->buffer_destroy( winsys, *ptr );
00121
00122 *ptr = buf;
00123 }
00124
00125
00126
00130 static INLINE void
00131 pipe_texture_reference(struct pipe_texture **ptr,
00132 struct pipe_texture *pt)
00133 {
00134 assert(ptr);
00135
00136 if (pt)
00137 pt->refcount++;
00138
00139 if (*ptr) {
00140 struct pipe_screen *screen = (*ptr)->screen;
00141 assert(screen);
00142 screen->texture_release(screen, ptr);
00143
00144 assert(!*ptr);
00145 }
00146
00147 *ptr = pt;
00148 }
00149
00150
00151 static INLINE void
00152 pipe_texture_release(struct pipe_texture **ptr)
00153 {
00154 struct pipe_screen *screen;
00155 assert(ptr);
00156 screen = (*ptr)->screen;
00157 screen->texture_release(screen, ptr);
00158 *ptr = NULL;
00159 }
00160
00161
00166 static INLINE struct pipe_buffer *
00167 pipe_buffer_create( struct pipe_screen *screen,
00168 unsigned alignment, unsigned usage, unsigned size )
00169 {
00170 return screen->winsys->buffer_create(screen->winsys, alignment, usage, size);
00171 }
00172
00173 static INLINE struct pipe_buffer *
00174 pipe_user_buffer_create( struct pipe_screen *screen, void *ptr, unsigned size )
00175 {
00176 return screen->winsys->user_buffer_create(screen->winsys, ptr, size);
00177 }
00178
00179 static INLINE void
00180 pipe_buffer_destroy( struct pipe_screen *screen, struct pipe_buffer *buf )
00181 {
00182 screen->winsys->buffer_destroy(screen->winsys, buf);
00183 }
00184
00185 static INLINE void *
00186 pipe_buffer_map(struct pipe_screen *screen,
00187 struct pipe_buffer *buf,
00188 unsigned usage)
00189 {
00190 return screen->winsys->buffer_map(screen->winsys, buf, usage);
00191 }
00192
00193 static INLINE void
00194 pipe_buffer_unmap(struct pipe_screen *screen,
00195 struct pipe_buffer *buf)
00196 {
00197 screen->winsys->buffer_unmap(screen->winsys, buf);
00198 }
00199
00200
00201
00202
00203 static INLINE void
00204 pipe_buffer_reference(struct pipe_screen *screen,
00205 struct pipe_buffer **ptr,
00206 struct pipe_buffer *buf)
00207 {
00208 winsys_buffer_reference(screen->winsys, ptr, buf);
00209 }
00210
00211
00212 #ifdef __cplusplus
00213 }
00214 #endif
00215
00216 #endif