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