r300: half float support
[mesa.git] / src / gallium / state_trackers / egl_g3d / common / native.h
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.8
4 *
5 * Copyright (C) 2009-2010 Chia-I Wu <olv@0xlab.org>
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 #ifndef _NATIVE_H_
26 #define _NATIVE_H_
27
28 #include "EGL/egl.h" /* for EGL native types */
29 #include "GL/gl.h" /* for GL types needed by __GLcontextModes */
30 #include "GL/internal/glcore.h" /* for __GLcontextModes */
31
32 #include "pipe/p_compiler.h"
33 #include "pipe/p_screen.h"
34 #include "pipe/p_context.h"
35 #include "pipe/p_state.h"
36
37 /**
38 * Only color buffers are listed. The others are allocated privately through,
39 * for example, st_renderbuffer_alloc_storage().
40 */
41 enum native_attachment {
42 NATIVE_ATTACHMENT_FRONT_LEFT,
43 NATIVE_ATTACHMENT_BACK_LEFT,
44 NATIVE_ATTACHMENT_FRONT_RIGHT,
45 NATIVE_ATTACHMENT_BACK_RIGHT,
46
47 NUM_NATIVE_ATTACHMENTS
48 };
49
50 /**
51 * Enumerations for probe results.
52 */
53 enum native_probe_result {
54 NATIVE_PROBE_UNKNOWN,
55 NATIVE_PROBE_FALLBACK,
56 NATIVE_PROBE_SUPPORTED,
57 NATIVE_PROBE_EXACT,
58 };
59
60 /**
61 * A probe object for display probe.
62 */
63 struct native_probe {
64 int magic;
65 EGLNativeDisplayType display;
66 void *data;
67
68 void (*destroy)(struct native_probe *nprobe);
69 };
70
71 struct native_surface {
72 void (*destroy)(struct native_surface *nsurf);
73
74 /**
75 * Swap the front and back buffers so that the back buffer is visible. It
76 * is no-op if the surface is single-buffered. The contents of the back
77 * buffer after swapping may or may not be preserved.
78 */
79 boolean (*swap_buffers)(struct native_surface *nsurf);
80
81 /**
82 * Make the front buffer visible. In some native displays, changes to the
83 * front buffer might not be visible immediately and require manual flush.
84 */
85 boolean (*flush_frontbuffer)(struct native_surface *nsurf);
86
87 /**
88 * Validate the buffers of the surface. textures, if not NULL, points to an
89 * array of size NUM_NATIVE_ATTACHMENTS and the returned textures are owned
90 * by the caller. A sequence number is also returned. The caller can use
91 * it to check if anything has changed since the last call. Any of the
92 * pointers may be NULL and it indicates the caller has no interest in those
93 * values.
94 *
95 * If this function is called multiple times with different attachment
96 * masks, those not listed in the latest call might be destroyed. This
97 * behavior might change in the future.
98 */
99 boolean (*validate)(struct native_surface *nsurf, uint attachment_mask,
100 unsigned int *seq_num, struct pipe_texture **textures,
101 int *width, int *height);
102
103 /**
104 * Wait until all native commands affecting the surface has been executed.
105 */
106 void (*wait)(struct native_surface *nsurf);
107 };
108
109 struct native_config {
110 /* __GLcontextModes should go away some day */
111 __GLcontextModes mode;
112 enum pipe_format color_format;
113 enum pipe_format depth_format;
114 enum pipe_format stencil_format;
115
116 /* treat it as an additional flag to mode.drawableType */
117 boolean scanout_bit;
118 };
119
120 struct native_connector {
121 int dummy;
122 };
123
124 struct native_mode {
125 const char *desc;
126 int width, height;
127 int refresh_rate;
128 };
129
130 struct native_display_modeset;
131
132 /**
133 * A pipe winsys abstracts the OS. A pipe screen abstracts the graphcis
134 * hardware. A native display consists of a pipe winsys, a pipe screen, and
135 * the native display server.
136 */
137 struct native_display {
138 /**
139 * The pipe screen of the native display.
140 *
141 * Note that the "flush_frontbuffer" and "update_buffer" callbacks will be
142 * overridden.
143 */
144 struct pipe_screen *screen;
145
146 void (*destroy)(struct native_display *ndpy);
147
148 /**
149 * Get the supported configs. The configs are owned by the display, but
150 * the returned array should be free()ed.
151 *
152 * The configs will be converted to EGL config by
153 * _eglConfigFromContextModesRec and validated by _eglValidateConfig.
154 * Those failing to pass the test will be skipped.
155 */
156 const struct native_config **(*get_configs)(struct native_display *ndpy,
157 int *num_configs);
158
159 /**
160 * Test if a pixmap is supported by the given config. Required unless no
161 * config has GLX_PIXMAP_BIT set.
162 *
163 * This function is usually called to find a config that supports a given
164 * pixmap. Thus, it is usually called with the same pixmap in a row.
165 */
166 boolean (*is_pixmap_supported)(struct native_display *ndpy,
167 EGLNativePixmapType pix,
168 const struct native_config *nconf);
169
170 /**
171 * Create a pipe context.
172 */
173 struct pipe_context *(*create_context)(struct native_display *ndpy,
174 void *context_private);
175
176 /**
177 * Create a window surface. Required unless no config has GLX_WINDOW_BIT
178 * set.
179 */
180 struct native_surface *(*create_window_surface)(struct native_display *ndpy,
181 EGLNativeWindowType win,
182 const struct native_config *nconf);
183
184 /**
185 * Create a pixmap surface. Required unless no config has GLX_PIXMAP_BIT
186 * set.
187 */
188 struct native_surface *(*create_pixmap_surface)(struct native_display *ndpy,
189 EGLNativePixmapType pix,
190 const struct native_config *nconf);
191
192 /**
193 * Create a pbuffer surface. Required unless no config has GLX_PBUFFER_BIT
194 * set.
195 */
196 struct native_surface *(*create_pbuffer_surface)(struct native_display *ndpy,
197 const struct native_config *nconf,
198 uint width, uint height);
199
200 const struct native_display_modeset *modeset;
201 };
202
203 /**
204 * Mode setting interface of the native display. It exposes the mode setting
205 * capabilities of the underlying graphics hardware.
206 */
207 struct native_display_modeset {
208 /**
209 * Get the available physical connectors and the number of CRTCs.
210 */
211 const struct native_connector **(*get_connectors)(struct native_display *ndpy,
212 int *num_connectors,
213 int *num_crtcs);
214
215 /**
216 * Get the current supported modes of a connector. The returned modes may
217 * change every time this function is called and those from previous calls
218 * might become invalid.
219 */
220 const struct native_mode **(*get_modes)(struct native_display *ndpy,
221 const struct native_connector *nconn,
222 int *num_modes);
223
224 /**
225 * Create a scan-out surface. Required unless no config has
226 * GLX_SCREEN_BIT_MESA set.
227 */
228 struct native_surface *(*create_scanout_surface)(struct native_display *ndpy,
229 const struct native_config *nconf,
230 uint width, uint height);
231
232 /**
233 * Program the CRTC to output the surface to the given connectors with the
234 * given mode. When surface is not given, the CRTC is disabled.
235 *
236 * This interface does not export a way to query capabilities of the CRTCs.
237 * The native display usually needs to dynamically map the index to a CRTC
238 * that supports the given connectors.
239 */
240 boolean (*program)(struct native_display *ndpy, int crtc_idx,
241 struct native_surface *nsurf, uint x, uint y,
242 const struct native_connector **nconns, int num_nconns,
243 const struct native_mode *nmode);
244 };
245
246 /**
247 * Test whether an attachment is set in the mask.
248 */
249 static INLINE boolean
250 native_attachment_mask_test(uint mask, enum native_attachment att)
251 {
252 return !!(mask & (1 << att));
253 }
254
255 /**
256 * Return a probe object for the given display.
257 *
258 * Note that the returned object may be cached and used by different native
259 * display modules. It allows fast probing when multiple modules probe the
260 * same display.
261 */
262 struct native_probe *
263 native_create_probe(EGLNativeDisplayType dpy);
264
265 /**
266 * Probe the probe object.
267 */
268 enum native_probe_result
269 native_get_probe_result(struct native_probe *nprobe);
270
271 const char *
272 native_get_name(void);
273
274 struct native_display *
275 native_create_display(EGLNativeDisplayType dpy);
276
277 #endif /* _NATIVE_H_ */