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