1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
31 #include "p_context.h"
32 #include "p_defines.h"
42 * Convenience wrappers for screen buffer functions.
45 static INLINE struct pipe_buffer *
46 pipe_buffer_create( struct pipe_screen *screen,
47 unsigned alignment, unsigned usage, unsigned size )
49 return screen->buffer_create(screen, alignment, usage, size);
52 static INLINE struct pipe_buffer *
53 pipe_user_buffer_create( struct pipe_screen *screen, void *ptr, unsigned size )
55 return screen->user_buffer_create(screen, ptr, size);
59 pipe_buffer_map(struct pipe_screen *screen,
60 struct pipe_buffer *buf,
63 if(screen->buffer_map_range) {
65 unsigned length = buf->size;
66 return screen->buffer_map_range(screen, buf, offset, length, usage);
69 return screen->buffer_map(screen, buf, usage);
73 pipe_buffer_unmap(struct pipe_screen *screen,
74 struct pipe_buffer *buf)
76 screen->buffer_unmap(screen, buf);
80 pipe_buffer_map_range(struct pipe_screen *screen,
81 struct pipe_buffer *buf,
86 if(screen->buffer_map_range)
87 return screen->buffer_map_range(screen, buf, offset, length, usage);
90 map = screen->buffer_map(screen, buf, usage);
91 return map ? map + offset : NULL;
96 pipe_buffer_flush_mapped_range(struct pipe_screen *screen,
97 struct pipe_buffer *buf,
101 if(screen->buffer_flush_mapped_range)
102 screen->buffer_flush_mapped_range(screen, buf, offset, length);
106 pipe_buffer_write(struct pipe_screen *screen,
107 struct pipe_buffer *buf,
108 unsigned offset, unsigned size,
113 assert(offset < buf->size);
114 assert(offset + size <= buf->size);
116 map = pipe_buffer_map_range(screen, buf, offset, size, PIPE_BUFFER_USAGE_CPU_WRITE);
119 memcpy(map, data, size);
120 pipe_buffer_flush_mapped_range(screen, buf, offset, size);
121 pipe_buffer_unmap(screen, buf);
126 pipe_buffer_read(struct pipe_screen *screen,
127 struct pipe_buffer *buf,
128 unsigned offset, unsigned size,
133 assert(offset < buf->size);
134 assert(offset + size <= buf->size);
136 map = pipe_buffer_map_range(screen, buf, offset, size, PIPE_BUFFER_USAGE_CPU_READ);
139 memcpy(data, map, size);
140 pipe_buffer_unmap(screen, buf);
149 #endif /* P_INLINES_H */