gallium: Cross-platform debugging helpers.
[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 #include "p_format.h"
33
34 /**
35 * \file
36 * This is the interface that Gallium3D requires any window system
37 * hosting it to implement. This is the only include file in Gallium3D
38 * which is public.
39 */
40
41
42 /** Opaque type */
43 struct pipe_fence_handle;
44
45 struct pipe_surface;
46
47
48 /**
49 * Gallium3D drivers are (meant to be!) independent of both GL and the
50 * window system. The window system provides a buffer manager and a
51 * set of additional hooks for things like command buffer submission,
52 * etc.
53 *
54 * There clearly has to be some agreement between the window system
55 * driver and the hardware driver about the format of command buffers,
56 * etc.
57 */
58 struct pipe_winsys
59 {
60 /** Returns name of this winsys interface */
61 const char *(*get_name)( struct pipe_winsys *sws );
62
63 /**
64 * Do any special operations to ensure frontbuffer contents are
65 * displayed, eg copy fake frontbuffer.
66 */
67 void (*flush_frontbuffer)( struct pipe_winsys *sws,
68 struct pipe_surface *surf,
69 void *context_private );
70
71 /** Debug output */
72 void (*printf)( struct pipe_winsys *sws,
73 const char *, ... );
74
75
76 /** allocate a new surface (no context dependency) */
77 struct pipe_surface *(*surface_alloc)(struct pipe_winsys *ws);
78
79 /**
80 * Allocate storage for a pipe_surface.
81 * Returns 0 if succeeds.
82 */
83 int (*surface_alloc_storage)(struct pipe_winsys *ws,
84 struct pipe_surface *surf,
85 unsigned width, unsigned height,
86 enum pipe_format format,
87 unsigned flags);
88
89 void (*surface_release)(struct pipe_winsys *ws, struct pipe_surface **s);
90
91
92 /**
93 * Buffer management. Buffer attributes are mostly fixed over its lifetime.
94 *
95 * Remember that gallium gets to choose the interface it needs, and the
96 * window systems must then implement that interface (rather than the
97 * other way around...).
98 *
99 * usage is a bitmask of PIPE_BUFFER_USAGE_PIXEL/VERTEX/INDEX/CONSTANT. This
100 * usage argument is only an optimization hint, not a guarantee, therefore
101 * proper behavior must be observed in all circumstances.
102 */
103 struct pipe_buffer *(*buffer_create)( struct pipe_winsys *sws,
104 unsigned alignment,
105 unsigned usage,
106 unsigned size );
107
108 /** Create a buffer that wraps user-space data */
109 struct pipe_buffer *(*user_buffer_create)(struct pipe_winsys *sws,
110 void *ptr,
111 unsigned bytes);
112
113 /**
114 * Map the entire data store of a buffer object into the client's address.
115 * flags is bitmask of PIPE_BUFFER_FLAG_READ/WRITE.
116 */
117 void *(*buffer_map)( struct pipe_winsys *sws,
118 struct pipe_buffer *buf,
119 unsigned usage );
120
121 void (*buffer_unmap)( struct pipe_winsys *sws,
122 struct pipe_buffer *buf );
123
124 void (*buffer_destroy)( struct pipe_winsys *sws,
125 struct pipe_buffer *buf );
126
127
128 /** Set ptr = fence, with reference counting */
129 void (*fence_reference)( struct pipe_winsys *sws,
130 struct pipe_fence_handle **ptr,
131 struct pipe_fence_handle *fence );
132
133 /**
134 * Checks whether the fence has been signalled.
135 *
136 * The meaning of flag is pipe-driver specific.
137 *
138 * Returns zero if it has.
139 */
140 int (*fence_signalled)( struct pipe_winsys *sws,
141 struct pipe_fence_handle *fence,
142 unsigned flag );
143
144 /**
145 * Wait for the fence to finish.
146 *
147 * The meaning of flag is pipe-driver specific.
148 *
149 * Returns zero on success.
150 */
151 int (*fence_finish)( struct pipe_winsys *sws,
152 struct pipe_fence_handle *fence,
153 unsigned flag );
154
155
156 };
157
158
159
160 #endif /* P_WINSYS_H */