Remove context dependencies in winsys layer.
[mesa.git] / src / mesa / 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 #ifndef P_WINSYS_H
29 #define P_WINSYS_H
30
31
32 /**
33 * \file
34 * This is the interface that Gallium3D requires any window system
35 * hosting it to implement. This is the only include file in Gallium3D
36 * which is public.
37 */
38
39
40 /** Opaque type for a buffer */
41 struct pipe_buffer_handle;
42
43 /**
44 * Gallium3D drivers are (meant to be!) independent of both GL and the
45 * window system. The window system provides a buffer manager and a
46 * set of additional hooks for things like command buffer submission,
47 * etc.
48 *
49 * There clearly has to be some agreement between the window system
50 * driver and the hardware driver about the format of command buffers,
51 * etc.
52 */
53
54
55 struct pipe_region;
56 struct pipe_surface;
57
58 /** Opaque type */
59 struct pipe_buffer_handle;
60
61 struct pipe_winsys
62 {
63 /** Returns name of this winsys interface */
64 const char *(*get_name)( struct pipe_winsys *sws );
65
66 /** Wait for any buffered rendering to finish */
67 void (*wait_idle)( struct pipe_winsys *sws, void *context_private );
68
69 /**
70 * Do any special operations to ensure frontbuffer contents are
71 * displayed, eg copy fake frontbuffer.
72 */
73 void (*flush_frontbuffer)( struct pipe_winsys *sws,
74 struct pipe_surface *surf,
75 void *context_private );
76
77 /** Debug output */
78 void (*printf)( struct pipe_winsys *sws,
79 const char *, ... );
80
81
82 /**
83 * flags is bitmask of PIPE_SURFACE_FLAG_RENDER, PIPE_SURFACE_FLAG_TEXTURE
84 */
85 struct pipe_region *(*region_alloc)(struct pipe_winsys *ws,
86 unsigned cpp, unsigned width,
87 unsigned height, unsigned flags);
88
89 void (*region_release)(struct pipe_winsys *ws, struct pipe_region **r);
90
91
92 /** allocate a new surface (no context dependency) */
93 struct pipe_surface *(*surface_alloc)(struct pipe_winsys *ws,
94 unsigned format);
95
96 void (*surface_release)(struct pipe_winsys *ws, struct pipe_surface **s);
97
98 /**
99 * The buffer manager is modeled after the dri_bufmgr interface, which
100 * in turn is modeled after the ARB_vertex_buffer_object extension,
101 * but this is the subset that gallium cares about. Remember that
102 * gallium gets to choose the interface it needs, and the window
103 * systems must then implement that interface (rather than the
104 * other way around...).
105 */
106 struct pipe_buffer_handle *(*buffer_create)(struct pipe_winsys *sws,
107 unsigned alignment );
108
109 /** Create a buffer that wraps user-space data */
110 struct pipe_buffer_handle *(*user_buffer_create)(struct pipe_winsys *sws,
111 void *ptr,
112 unsigned bytes);
113
114
115 /**
116 * Map the entire data store of a buffer object into the client's address.
117 * flags is bitmask of PIPE_BUFFER_FLAG_READ/WRITE.
118 */
119 void *(*buffer_map)( struct pipe_winsys *sws,
120 struct pipe_buffer_handle *buf,
121 unsigned flags );
122
123 void (*buffer_unmap)( struct pipe_winsys *sws,
124 struct pipe_buffer_handle *buf );
125
126 /** Set ptr = buf, with reference counting */
127 void (*buffer_reference)( struct pipe_winsys *sws,
128 struct pipe_buffer_handle **ptr,
129 struct pipe_buffer_handle *buf );
130
131 /**
132 * Create the data store of a buffer and optionally initialize it.
133 *
134 * usage is a bitmask of PIPE_BUFFER_USAGE_PIXEL/VERTEX/INDEX/CONSTANT. This
135 * usage argument is only an optimization hint, not a guarantee, therefore
136 * proper behavior must be observed in all circumstances.
137 */
138 void (*buffer_data)(struct pipe_winsys *sws,
139 struct pipe_buffer_handle *buf,
140 unsigned size, const void *data,
141 unsigned usage);
142
143 /** Modify some or all of the data contained in a buffer's data store */
144 void (*buffer_subdata)(struct pipe_winsys *sws,
145 struct pipe_buffer_handle *buf,
146 unsigned long offset,
147 unsigned long size,
148 const void *data);
149
150 /** Query some or all of the data contained in a buffer's data store */
151 void (*buffer_get_subdata)(struct pipe_winsys *sws,
152 struct pipe_buffer_handle *buf,
153 unsigned long offset,
154 unsigned long size,
155 void *data);
156
157 };
158
159
160
161 #endif /* P_WINSYS_H */