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