mesa: merge gallium-0.2 into gallium-master-merge
[mesa.git] / src / gallium / include / pipe / p_screen.h
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
28 /**
29 * @file
30 *
31 * Screen, Adapter or GPU
32 *
33 * These are driver functions/facilities that are context independent.
34 */
35
36
37 #ifndef P_SCREEN_H
38 #define P_SCREEN_H
39
40
41 #include "pipe/p_compiler.h"
42 #include "pipe/p_format.h"
43 #include "pipe/p_defines.h"
44
45
46
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50
51
52 /** Opaque type */
53 struct pipe_fence_handle;
54 struct pipe_winsys;
55 struct pipe_buffer;
56
57
58 /**
59 * Gallium screen/adapter context. Basically everything
60 * hardware-specific that doesn't actually require a rendering
61 * context.
62 */
63 struct pipe_screen {
64 struct pipe_winsys *winsys;
65
66 void (*destroy)( struct pipe_screen * );
67
68
69 const char *(*get_name)( struct pipe_screen * );
70
71 const char *(*get_vendor)( struct pipe_screen * );
72
73 /**
74 * Query an integer-valued capability/parameter/limit
75 * \param param one of PIPE_CAP_x
76 */
77 int (*get_param)( struct pipe_screen *, int param );
78
79 /**
80 * Query a float-valued capability/parameter/limit
81 * \param param one of PIPE_CAP_x
82 */
83 float (*get_paramf)( struct pipe_screen *, int param );
84
85 /**
86 * Check if the given pipe_format is supported as a texture or
87 * drawing surface.
88 * \param tex_usage bitmask of PIPE_TEXTURE_USAGE_*
89 * \param flags bitmask of PIPE_TEXTURE_GEOM_*
90 */
91 boolean (*is_format_supported)( struct pipe_screen *,
92 enum pipe_format format,
93 enum pipe_texture_target target,
94 unsigned tex_usage,
95 unsigned geom_flags );
96
97 /**
98 * Create a new texture object, using the given template info.
99 */
100 struct pipe_texture * (*texture_create)(struct pipe_screen *,
101 const struct pipe_texture *templat);
102
103 /**
104 * Create a new texture object, using the given template info, but on top of
105 * existing memory.
106 *
107 * It is assumed that the buffer data is layed out according to the expected
108 * by the hardware. NULL will be returned if any inconsistency is found.
109 */
110 struct pipe_texture * (*texture_blanket)(struct pipe_screen *,
111 const struct pipe_texture *templat,
112 const unsigned *stride,
113 struct pipe_buffer *buffer);
114
115 void (*texture_release)(struct pipe_screen *,
116 struct pipe_texture **pt);
117
118 /** Get a surface which is a "view" into a texture */
119 struct pipe_surface *(*get_tex_surface)(struct pipe_screen *,
120 struct pipe_texture *texture,
121 unsigned face, unsigned level,
122 unsigned zslice,
123 unsigned usage );
124
125 /* Surfaces allocated by the above must be released here:
126 */
127 void (*tex_surface_release)( struct pipe_screen *,
128 struct pipe_surface ** );
129
130
131 void *(*surface_map)( struct pipe_screen *,
132 struct pipe_surface *surface,
133 unsigned flags );
134
135 void (*surface_unmap)( struct pipe_screen *,
136 struct pipe_surface *surface );
137
138
139 /**
140 * Buffer management. Buffer attributes are mostly fixed over its lifetime.
141 *
142 */
143 struct pipe_buffer *(*buffer_create)( struct pipe_screen *screen,
144 unsigned alignment,
145 unsigned usage,
146 unsigned size );
147
148 /**
149 * Create a buffer that wraps user-space data.
150 *
151 * Effectively this schedules a delayed call to buffer_create
152 * followed by an upload of the data at *some point in the future*,
153 * or perhaps never. Basically the allocate/upload is delayed
154 * until the buffer is actually passed to hardware.
155 *
156 * The intention is to provide a quick way to turn regular data
157 * into a buffer, and secondly to avoid a copy operation if that
158 * data subsequently turns out to be only accessed by the CPU.
159 *
160 * Common example is OpenGL vertex buffers that are subsequently
161 * processed either by software TNL in the driver or by passing to
162 * hardware.
163 *
164 * XXX: What happens if the delayed call to buffer_create() fails?
165 *
166 * Note that ptr may be accessed at any time upto the time when the
167 * buffer is destroyed, so the data must not be freed before then.
168 */
169 struct pipe_buffer *(*user_buffer_create)(struct pipe_screen *screen,
170 void *ptr,
171 unsigned bytes);
172
173 /**
174 * Allocate storage for a display target surface.
175 *
176 * Often surfaces which are meant to be blitted to the front screen (i.e.,
177 * display targets) must be allocated with special characteristics, memory
178 * pools, or obtained directly from the windowing system.
179 *
180 * This callback is invoked by the pipe_screenwhen creating a texture marked
181 * with the PIPE_TEXTURE_USAGE_DISPLAY_TARGET flag to get the underlying
182 * buffer storage.
183 */
184 struct pipe_buffer *(*surface_buffer_create)(struct pipe_screen *screen,
185 unsigned width, unsigned height,
186 enum pipe_format format,
187 unsigned usage,
188 unsigned *stride);
189
190
191 /**
192 * Map the entire data store of a buffer object into the client's address.
193 * flags is bitmask of PIPE_BUFFER_USAGE_CPU_READ/WRITE flags.
194 */
195 void *(*buffer_map)( struct pipe_screen *screen,
196 struct pipe_buffer *buf,
197 unsigned usage );
198
199 void (*buffer_unmap)( struct pipe_screen *screen,
200 struct pipe_buffer *buf );
201
202 void (*buffer_destroy)( struct pipe_screen *screen,
203 struct pipe_buffer *buf );
204
205
206 /**
207 * Do any special operations to ensure frontbuffer contents are
208 * displayed, eg copy fake frontbuffer.
209 */
210 void (*flush_frontbuffer)( struct pipe_screen *screen,
211 struct pipe_surface *surf,
212 void *context_private );
213
214
215
216 /** Set ptr = fence, with reference counting */
217 void (*fence_reference)( struct pipe_screen *screen,
218 struct pipe_fence_handle **ptr,
219 struct pipe_fence_handle *fence );
220
221 /**
222 * Checks whether the fence has been signalled.
223 * \param flags driver-specific meaning
224 * \return zero on success.
225 */
226 int (*fence_signalled)( struct pipe_screen *screen,
227 struct pipe_fence_handle *fence,
228 unsigned flag );
229
230 /**
231 * Wait for the fence to finish.
232 * \param flags driver-specific meaning
233 * \return zero on success.
234 */
235 int (*fence_finish)( struct pipe_screen *screen,
236 struct pipe_fence_handle *fence,
237 unsigned flag );
238
239 };
240
241
242 #ifdef __cplusplus
243 }
244 #endif
245
246 #endif /* P_SCREEN_H */