p_inlines.h

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 
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 /* XXX: these are a kludge.  will fix when all surfaces are views into
00043  * textures, and free-floating winsys surfaces go away.
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    /* bump the refcount first */
00085    if (surf) 
00086       surf->refcount++;
00087 
00088    if (*ptr) {
00089 
00090       /* There are currently two sorts of surfaces... This needs to be
00091        * fixed so that all surfaces are views into a texture.
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 /* XXX: thread safety issues!
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 /* XXX when we're using this everywhere, get rid of
00201  * winsys_buffer_reference() above.
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 /* P_INLINES_H */

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