native.h revision 287c94ea4987033f9c99a2f91c5750c9083504ca
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 OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
24 */
25
26#ifndef _NATIVE_H_
27#define _NATIVE_H_
28
29#include "EGL/egl.h"  /* for EGL native types */
30#include "GL/gl.h" /* for GL types needed by __GLcontextModes */
31#include "GL/internal/glcore.h"  /* for __GLcontextModes */
32
33#include "pipe/p_compiler.h"
34#include "pipe/p_screen.h"
35#include "pipe/p_context.h"
36#include "pipe/p_state.h"
37
38#include "native_probe.h"
39#include "native_modeset.h"
40
41/**
42 * Only color buffers are listed.  The others are allocated privately through,
43 * for example, st_renderbuffer_alloc_storage().
44 */
45enum native_attachment {
46   NATIVE_ATTACHMENT_FRONT_LEFT,
47   NATIVE_ATTACHMENT_BACK_LEFT,
48   NATIVE_ATTACHMENT_FRONT_RIGHT,
49   NATIVE_ATTACHMENT_BACK_RIGHT,
50
51   NUM_NATIVE_ATTACHMENTS
52};
53
54enum native_param_type {
55   /*
56    * Return TRUE if window/pixmap surfaces use the buffers of the native
57    * types.
58    */
59   NATIVE_PARAM_USE_NATIVE_BUFFER
60};
61
62struct native_surface {
63   /**
64    * Available for caller's use.
65    */
66   void *user_data;
67
68   void (*destroy)(struct native_surface *nsurf);
69
70   /**
71    * Swap the front and back buffers so that the back buffer is visible.  It
72    * is no-op if the surface is single-buffered.  The contents of the back
73    * buffer after swapping may or may not be preserved.
74    */
75   boolean (*swap_buffers)(struct native_surface *nsurf);
76
77   /**
78    * Make the front buffer visible.  In some native displays, changes to the
79    * front buffer might not be visible immediately and require manual flush.
80    */
81   boolean (*flush_frontbuffer)(struct native_surface *nsurf);
82
83   /**
84    * Validate the buffers of the surface.  textures, if not NULL, points to an
85    * array of size NUM_NATIVE_ATTACHMENTS and the returned textures are owned
86    * by the caller.  A sequence number is also returned.  The caller can use
87    * it to check if anything has changed since the last call. Any of the
88    * pointers may be NULL and it indicates the caller has no interest in those
89    * values.
90    *
91    * If this function is called multiple times with different attachment
92    * masks, those not listed in the latest call might be destroyed.  This
93    * behavior might change in the future.
94    */
95   boolean (*validate)(struct native_surface *nsurf, uint attachment_mask,
96                       unsigned int *seq_num, struct pipe_resource **textures,
97                       int *width, int *height);
98
99   /**
100    * Wait until all native commands affecting the surface has been executed.
101    */
102   void (*wait)(struct native_surface *nsurf);
103};
104
105struct native_config {
106   /* __GLcontextModes should go away some day */
107   __GLcontextModes mode;
108   enum pipe_format color_format;
109   enum pipe_format depth_format;
110   enum pipe_format stencil_format;
111
112   /* treat it as an additional flag to mode.drawableType */
113   boolean scanout_bit;
114};
115
116/**
117 * A pipe winsys abstracts the OS.  A pipe screen abstracts the graphcis
118 * hardware.  A native display consists of a pipe winsys, a pipe screen, and
119 * the native display server.
120 */
121struct native_display {
122   /**
123    * The pipe screen of the native display.
124    */
125   struct pipe_screen *screen;
126
127   /**
128    * Available for caller's use.
129    */
130   void *user_data;
131
132   void (*destroy)(struct native_display *ndpy);
133
134   /**
135    * Query the parameters of the native display.
136    *
137    * The return value is defined by the parameter.
138    */
139   int (*get_param)(struct native_display *ndpy,
140                    enum native_param_type param);
141
142   /**
143    * Get the supported configs.  The configs are owned by the display, but
144    * the returned array should be free()ed.
145    *
146    * The configs will be converted to EGL config by
147    * _eglConfigFromContextModesRec and validated by _eglValidateConfig.
148    * Those failing to pass the test will be skipped.
149    */
150   const struct native_config **(*get_configs)(struct native_display *ndpy,
151                                               int *num_configs);
152
153   /**
154    * Test if a pixmap is supported by the given config.  Required unless no
155    * config has GLX_PIXMAP_BIT set.
156    *
157    * This function is usually called to find a config that supports a given
158    * pixmap.  Thus, it is usually called with the same pixmap in a row.
159    */
160   boolean (*is_pixmap_supported)(struct native_display *ndpy,
161                                  EGLNativePixmapType pix,
162                                  const struct native_config *nconf);
163
164
165   /**
166    * Create a window surface.  Required unless no config has GLX_WINDOW_BIT
167    * set.
168    */
169   struct native_surface *(*create_window_surface)(struct native_display *ndpy,
170                                                   EGLNativeWindowType win,
171                                                   const struct native_config *nconf);
172
173   /**
174    * Create a pixmap surface.  Required unless no config has GLX_PIXMAP_BIT
175    * set.
176    */
177   struct native_surface *(*create_pixmap_surface)(struct native_display *ndpy,
178                                                   EGLNativePixmapType pix,
179                                                   const struct native_config *nconf);
180
181   const struct native_display_modeset *modeset;
182};
183
184/**
185 * The handler for events that a native display may generate.  The events are
186 * generated asynchronously and the handler may be called by any thread at any
187 * time.
188 */
189struct native_event_handler {
190   /**
191    * This function is called when a surface needs to be validated.
192    */
193   void (*invalid_surface)(struct native_display *ndpy,
194                           struct native_surface *nsurf,
195                           unsigned int seq_num);
196};
197
198/**
199 * Test whether an attachment is set in the mask.
200 */
201static INLINE boolean
202native_attachment_mask_test(uint mask, enum native_attachment att)
203{
204   return !!(mask & (1 << att));
205}
206
207const char *
208native_get_name(void);
209
210struct native_display *
211native_create_display(EGLNativeDisplayType dpy,
212                      struct native_event_handler *handler);
213
214#endif /* _NATIVE_H_ */
215