Merge branch 'mesa_7_6_branch'
[mesa.git] / src / gallium / include / pipe / internal / p_winsys_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 * 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 "pipe/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 void (*destroy)( struct pipe_winsys *ws );
66
67 /** Returns name of this winsys interface */
68 const char *(*get_name)( struct pipe_winsys *ws );
69
70 /**
71 * Do any special operations to ensure buffer size is correct
72 */
73 void (*update_buffer)( struct pipe_winsys *ws,
74 void *context_private );
75 /**
76 * Do any special operations to ensure frontbuffer contents are
77 * displayed, eg copy fake frontbuffer.
78 */
79 void (*flush_frontbuffer)( struct pipe_winsys *ws,
80 struct pipe_surface *surf,
81 void *context_private );
82
83
84 /**
85 * Buffer management. Buffer attributes are mostly fixed over its lifetime.
86 *
87 * Remember that gallium gets to choose the interface it needs, and the
88 * window systems must then implement that interface (rather than the
89 * other way around...).
90 *
91 * usage is a bitmask of PIPE_BUFFER_USAGE_PIXEL/VERTEX/INDEX/CONSTANT. This
92 * usage argument is only an optimization hint, not a guarantee, therefore
93 * proper behavior must be observed in all circumstances.
94 *
95 * alignment indicates the client's alignment requirements, eg for
96 * SSE instructions.
97 */
98 struct pipe_buffer *(*buffer_create)( struct pipe_winsys *ws,
99 unsigned alignment,
100 unsigned usage,
101 unsigned size );
102
103 /**
104 * Create a buffer that wraps user-space data.
105 *
106 * Effectively this schedules a delayed call to buffer_create
107 * followed by an upload of the data at *some point in the future*,
108 * or perhaps never. Basically the allocate/upload is delayed
109 * until the buffer is actually passed to hardware.
110 *
111 * The intention is to provide a quick way to turn regular data
112 * into a buffer, and secondly to avoid a copy operation if that
113 * data subsequently turns out to be only accessed by the CPU.
114 *
115 * Common example is OpenGL vertex buffers that are subsequently
116 * processed either by software TNL in the driver or by passing to
117 * hardware.
118 *
119 * XXX: What happens if the delayed call to buffer_create() fails?
120 *
121 * Note that ptr may be accessed at any time upto the time when the
122 * buffer is destroyed, so the data must not be freed before then.
123 */
124 struct pipe_buffer *(*user_buffer_create)(struct pipe_winsys *ws,
125 void *ptr,
126 unsigned bytes);
127
128 /**
129 * Allocate storage for a display target surface.
130 *
131 * Often surfaces which are meant to be blitted to the front screen (i.e.,
132 * display targets) must be allocated with special characteristics, memory
133 * pools, or obtained directly from the windowing system.
134 *
135 * This callback is invoked by the pipe_screenwhen creating a texture marked
136 * with the PIPE_TEXTURE_USAGE_DISPLAY_TARGET flag to get the underlying
137 * buffer storage.
138 */
139 struct pipe_buffer *(*surface_buffer_create)(struct pipe_winsys *ws,
140 unsigned width, unsigned height,
141 enum pipe_format format,
142 unsigned usage,
143 unsigned tex_usage,
144 unsigned *stride);
145
146
147 /**
148 * Map the entire data store of a buffer object into the client's address.
149 * flags is bitmask of PIPE_BUFFER_USAGE_CPU_READ/WRITE flags.
150 */
151 void *(*buffer_map)( struct pipe_winsys *ws,
152 struct pipe_buffer *buf,
153 unsigned usage );
154
155 void (*buffer_unmap)( struct pipe_winsys *ws,
156 struct pipe_buffer *buf );
157
158 void (*buffer_destroy)( struct pipe_buffer *buf );
159
160
161 /** Set ptr = fence, with reference counting */
162 void (*fence_reference)( struct pipe_winsys *ws,
163 struct pipe_fence_handle **ptr,
164 struct pipe_fence_handle *fence );
165
166 /**
167 * Checks whether the fence has been signalled.
168 * \param flags driver-specific meaning
169 * \return zero on success.
170 */
171 int (*fence_signalled)( struct pipe_winsys *ws,
172 struct pipe_fence_handle *fence,
173 unsigned flag );
174
175 /**
176 * Wait for the fence to finish.
177 * \param flags driver-specific meaning
178 * \return zero on success.
179 */
180 int (*fence_finish)( struct pipe_winsys *ws,
181 struct pipe_fence_handle *fence,
182 unsigned flag );
183
184 };
185
186 #ifdef __cplusplus
187 }
188 #endif
189
190 #endif /* P_WINSYS_H */