Merge remote branch 'upstream/gallium-0.1' into nouveau-gallium-0.1
[mesa.git] / src / gallium / include / pipe / p_winsys.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 * This is the interface that Gallium3D requires any window system
31 * hosting it to implement. This is the only include file in Gallium3D
32 * which is public.
33 */
34
35 #ifndef P_WINSYS_H
36 #define P_WINSYS_H
37
38
39 #include "p_format.h"
40
41
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45
46
47 /** Opaque type */
48 struct pipe_fence_handle;
49
50 struct pipe_surface;
51
52
53 /**
54 * Gallium3D drivers are (meant to be!) independent of both GL and the
55 * window system. The window system provides a buffer manager and a
56 * set of additional hooks for things like command buffer submission,
57 * etc.
58 *
59 * There clearly has to be some agreement between the window system
60 * driver and the hardware driver about the format of command buffers,
61 * etc.
62 */
63 struct pipe_winsys
64 {
65 /** Returns name of this winsys interface */
66 const char *(*get_name)( struct pipe_winsys *sws );
67
68 /**
69 * Do any special operations to ensure frontbuffer contents are
70 * displayed, eg copy fake frontbuffer.
71 */
72 void (*flush_frontbuffer)( struct pipe_winsys *sws,
73 struct pipe_surface *surf,
74 void *context_private );
75
76
77 /** allocate a new surface (no context dependency) */
78 struct pipe_surface *(*surface_alloc)(struct pipe_winsys *ws);
79
80 /**
81 * Allocate storage for a pipe_surface.
82 * Returns 0 if succeeds.
83 * XXX: flags is unused and will be removed someday.
84 */
85 int (*surface_alloc_storage)(struct pipe_winsys *ws,
86 struct pipe_surface *surf,
87 unsigned width, unsigned height,
88 enum pipe_format format,
89 unsigned flags);
90
91 void (*surface_release)(struct pipe_winsys *ws, struct pipe_surface **s);
92
93
94 /**
95 * Buffer management. Buffer attributes are mostly fixed over its lifetime.
96 *
97 * Remember that gallium gets to choose the interface it needs, and the
98 * window systems must then implement that interface (rather than the
99 * other way around...).
100 *
101 * usage is a bitmask of PIPE_BUFFER_USAGE_PIXEL/VERTEX/INDEX/CONSTANT. This
102 * usage argument is only an optimization hint, not a guarantee, therefore
103 * proper behavior must be observed in all circumstances.
104 *
105 * alignment indicates the client's alignment requirements, eg for
106 * SSE instructions.
107 */
108 struct pipe_buffer *(*buffer_create)( struct pipe_winsys *sws,
109 unsigned alignment,
110 unsigned usage,
111 unsigned size );
112
113 /**
114 * Create a buffer that wraps user-space data.
115 *
116 * Effectively this schedules a delayed call to buffer_create
117 * followed by an upload of the data at *some point in the future*,
118 * or perhaps never. Basically the allocate/upload is delayed
119 * until the buffer is actually passed to hardware.
120 *
121 * The intention is to provide a quick way to turn regular data
122 * into a buffer, and secondly to avoid a copy operation if that
123 * data subsequently turns out to be only accessed by the CPU.
124 *
125 * Common example is OpenGL vertex buffers that are subsequently
126 * processed either by software TNL in the driver or by passing to
127 * hardware.
128 *
129 * XXX: What happens if the delayed call to buffer_create() fails?
130 *
131 * Note that ptr may be accessed at any time upto the time when the
132 * buffer is destroyed, so the data must not be freed before then.
133 */
134 struct pipe_buffer *(*user_buffer_create)(struct pipe_winsys *sws,
135 void *ptr,
136 unsigned bytes);
137
138 /**
139 * Map the entire data store of a buffer object into the client's address.
140 * flags is bitmask of PIPE_BUFFER_USAGE_CPU_READ/WRITE flags.
141 */
142 void *(*buffer_map)( struct pipe_winsys *sws,
143 struct pipe_buffer *buf,
144 unsigned usage );
145
146 void (*buffer_unmap)( struct pipe_winsys *sws,
147 struct pipe_buffer *buf );
148
149 void (*buffer_destroy)( struct pipe_winsys *sws,
150 struct pipe_buffer *buf );
151
152
153 /** Set ptr = fence, with reference counting */
154 void (*fence_reference)( struct pipe_winsys *sws,
155 struct pipe_fence_handle **ptr,
156 struct pipe_fence_handle *fence );
157
158 /**
159 * Checks whether the fence has been signalled.
160 *
161 * The meaning of flag is pipe-driver specific.
162 *
163 * Returns zero if it has.
164 */
165 int (*fence_signalled)( struct pipe_winsys *sws,
166 struct pipe_fence_handle *fence,
167 unsigned flag );
168
169 /**
170 * Wait for the fence to finish.
171 *
172 * The meaning of flag is pipe-driver specific.
173 *
174 * Returns zero on success.
175 */
176 int (*fence_finish)( struct pipe_winsys *sws,
177 struct pipe_fence_handle *fence,
178 unsigned flag );
179
180
181 };
182
183
184 #ifdef __cplusplus
185 }
186 #endif
187
188 #endif /* P_WINSYS_H */