vl: Adapt to dri changes.
[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 struct pipe_texture;
57 struct pipe_surface;
58 struct pipe_transfer;
59
60
61 /**
62 * Gallium screen/adapter context. Basically everything
63 * hardware-specific that doesn't actually require a rendering
64 * context.
65 */
66 struct pipe_screen {
67 struct pipe_winsys *winsys;
68
69 void (*destroy)( struct pipe_screen * );
70
71
72 const char *(*get_name)( struct pipe_screen * );
73
74 const char *(*get_vendor)( struct pipe_screen * );
75
76 /**
77 * Query an integer-valued capability/parameter/limit
78 * \param param one of PIPE_CAP_x
79 */
80 int (*get_param)( struct pipe_screen *, int param );
81
82 /**
83 * Query a float-valued capability/parameter/limit
84 * \param param one of PIPE_CAP_x
85 */
86 float (*get_paramf)( struct pipe_screen *, int param );
87
88 struct pipe_context * (*context_create)( struct pipe_screen *,
89 void *priv );
90
91 struct pipe_video_context * (*video_context_create)( struct pipe_screen *screen,
92 enum pipe_video_profile profile,
93 enum pipe_video_chroma_format chroma_format,
94 unsigned width, unsigned height, void *priv );
95
96 /**
97 * Check if the given pipe_format is supported as a texture or
98 * drawing surface.
99 * \param tex_usage bitmask of PIPE_TEXTURE_USAGE_*
100 * \param geom_flags bitmask of PIPE_TEXTURE_GEOM_*
101 */
102 boolean (*is_format_supported)( struct pipe_screen *,
103 enum pipe_format format,
104 enum pipe_texture_target target,
105 unsigned tex_usage,
106 unsigned geom_flags );
107
108 /**
109 * Create a new texture object, using the given template info.
110 */
111 struct pipe_texture * (*texture_create)(struct pipe_screen *,
112 const struct pipe_texture *templat);
113
114 /**
115 * Create a new texture object, using the given template info, but on top of
116 * existing memory.
117 *
118 * It is assumed that the buffer data is layed out according to the expected
119 * by the hardware. NULL will be returned if any inconsistency is found.
120 */
121 struct pipe_texture * (*texture_blanket)(struct pipe_screen *,
122 const struct pipe_texture *templat,
123 const unsigned *stride,
124 struct pipe_buffer *buffer);
125
126 void (*texture_destroy)(struct pipe_texture *pt);
127
128 /** Get a 2D surface which is a "view" into a texture
129 * \param usage bitmaks of PIPE_BUFFER_USAGE_* read/write flags
130 */
131 struct pipe_surface *(*get_tex_surface)(struct pipe_screen *,
132 struct pipe_texture *texture,
133 unsigned face, unsigned level,
134 unsigned zslice,
135 unsigned usage );
136
137 void (*tex_surface_destroy)(struct pipe_surface *);
138
139
140 /** Get a transfer object for transferring data to/from a texture */
141 struct pipe_transfer *(*get_tex_transfer)(struct pipe_screen *,
142 struct pipe_texture *texture,
143 unsigned face, unsigned level,
144 unsigned zslice,
145 enum pipe_transfer_usage usage,
146 unsigned x, unsigned y,
147 unsigned w, unsigned h);
148
149 void (*tex_transfer_destroy)(struct pipe_transfer *);
150
151 void *(*transfer_map)( struct pipe_screen *,
152 struct pipe_transfer *transfer );
153
154 void (*transfer_unmap)( struct pipe_screen *,
155 struct pipe_transfer *transfer );
156
157
158 /**
159 * Create a new buffer.
160 * \param alignment buffer start address alignment in bytes
161 * \param usage bitmask of PIPE_BUFFER_USAGE_x
162 * \param size size in bytes
163 */
164 struct pipe_buffer *(*buffer_create)( struct pipe_screen *screen,
165 unsigned alignment,
166 unsigned usage,
167 unsigned size );
168
169 /**
170 * Create a buffer that wraps user-space data.
171 *
172 * Effectively this schedules a delayed call to buffer_create
173 * followed by an upload of the data at *some point in the future*,
174 * or perhaps never. Basically the allocate/upload is delayed
175 * until the buffer is actually passed to hardware.
176 *
177 * The intention is to provide a quick way to turn regular data
178 * into a buffer, and secondly to avoid a copy operation if that
179 * data subsequently turns out to be only accessed by the CPU.
180 *
181 * Common example is OpenGL vertex buffers that are subsequently
182 * processed either by software TNL in the driver or by passing to
183 * hardware.
184 *
185 * XXX: What happens if the delayed call to buffer_create() fails?
186 *
187 * Note that ptr may be accessed at any time upto the time when the
188 * buffer is destroyed, so the data must not be freed before then.
189 */
190 struct pipe_buffer *(*user_buffer_create)(struct pipe_screen *screen,
191 void *ptr,
192 unsigned bytes);
193
194 /**
195 * Allocate storage for a display target surface.
196 *
197 * Often surfaces which are meant to be blitted to the front screen (i.e.,
198 * display targets) must be allocated with special characteristics, memory
199 * pools, or obtained directly from the windowing system.
200 *
201 * This callback is invoked by the pipe_screenwhen creating a texture marked
202 * with the PIPE_TEXTURE_USAGE_DISPLAY_TARGET flag to get the underlying
203 * buffer storage.
204 */
205 struct pipe_buffer *(*surface_buffer_create)(struct pipe_screen *screen,
206 unsigned width, unsigned height,
207 enum pipe_format format,
208 unsigned usage,
209 unsigned tex_usage,
210 unsigned *stride);
211
212
213 /**
214 * Map the entire data store of a buffer object into the client's address.
215 * flags is bitmask of PIPE_BUFFER_USAGE_CPU_READ/WRITE flags.
216 */
217 void *(*buffer_map)( struct pipe_screen *screen,
218 struct pipe_buffer *buf,
219 unsigned usage );
220 /**
221 * Map a subrange of the buffer data store into the client's address space.
222 *
223 * The returned pointer is always relative to buffer start, regardless of
224 * the specified range. This is different from the ARB_map_buffer_range
225 * semantics because we don't forbid multiple mappings of the same buffer
226 * (yet).
227 */
228 void *(*buffer_map_range)( struct pipe_screen *screen,
229 struct pipe_buffer *buf,
230 unsigned offset,
231 unsigned length,
232 unsigned usage);
233
234 /**
235 * Notify a range that was actually written into.
236 *
237 * Can only be used if the buffer was mapped with the
238 * PIPE_BUFFER_USAGE_CPU_WRITE and PIPE_BUFFER_USAGE_FLUSH_EXPLICIT flags
239 * set.
240 *
241 * The range is relative to the buffer start, regardless of the range
242 * specified to buffer_map_range. This is different from the
243 * ARB_map_buffer_range semantics because we don't forbid multiple mappings
244 * of the same buffer (yet).
245 *
246 */
247 void (*buffer_flush_mapped_range)( struct pipe_screen *screen,
248 struct pipe_buffer *buf,
249 unsigned offset,
250 unsigned length);
251
252 /**
253 * Unmap buffer.
254 *
255 * If the buffer was mapped with PIPE_BUFFER_USAGE_CPU_WRITE flag but not
256 * PIPE_BUFFER_USAGE_FLUSH_EXPLICIT then the pipe driver will
257 * assume that the whole buffer was written. This is mostly for backward
258 * compatibility purposes and may affect performance -- the state tracker
259 * should always specify exactly what got written while the buffer was
260 * mapped.
261 */
262 void (*buffer_unmap)( struct pipe_screen *screen,
263 struct pipe_buffer *buf );
264
265 void (*buffer_destroy)( struct pipe_buffer *buf );
266
267 /**
268 * Do any special operations to ensure buffer size is correct
269 */
270 void (*update_buffer)( struct pipe_screen *ws,
271 void *context_private );
272
273 /**
274 * Do any special operations to ensure frontbuffer contents are
275 * displayed, eg copy fake frontbuffer.
276 */
277 void (*flush_frontbuffer)( struct pipe_screen *screen,
278 struct pipe_surface *surf,
279 void *context_private );
280
281
282
283 /** Set ptr = fence, with reference counting */
284 void (*fence_reference)( struct pipe_screen *screen,
285 struct pipe_fence_handle **ptr,
286 struct pipe_fence_handle *fence );
287
288 /**
289 * Checks whether the fence has been signalled.
290 * \param flags driver-specific meaning
291 * \return zero on success.
292 */
293 int (*fence_signalled)( struct pipe_screen *screen,
294 struct pipe_fence_handle *fence,
295 unsigned flags );
296
297 /**
298 * Wait for the fence to finish.
299 * \param flags driver-specific meaning
300 * \return zero on success.
301 */
302 int (*fence_finish)( struct pipe_screen *screen,
303 struct pipe_fence_handle *fence,
304 unsigned flags );
305
306 };
307
308
309 #ifdef __cplusplus
310 }
311 #endif
312
313 #endif /* P_SCREEN_H */