native.h revision a5f4338fc4f9b4500c5754de237f77549b3cedf8
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
31#include "pipe/p_compiler.h"
32#include "pipe/p_screen.h"
33#include "pipe/p_context.h"
34#include "pipe/p_state.h"
35#include "state_tracker/sw_winsys.h"
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
41#include "native_modeset.h"
42
43/**
44 * Only color buffers are listed.  The others are allocated privately through,
45 * for example, st_renderbuffer_alloc_storage().
46 */
47enum native_attachment {
48   NATIVE_ATTACHMENT_FRONT_LEFT,
49   NATIVE_ATTACHMENT_BACK_LEFT,
50   NATIVE_ATTACHMENT_FRONT_RIGHT,
51   NATIVE_ATTACHMENT_BACK_RIGHT,
52
53   NUM_NATIVE_ATTACHMENTS
54};
55
56enum native_param_type {
57   /*
58    * Return TRUE if window/pixmap surfaces use the buffers of the native
59    * types.
60    */
61   NATIVE_PARAM_USE_NATIVE_BUFFER,
62
63   /**
64    * Return TRUE if native_surface::present can preserve the buffer.
65    */
66   NATIVE_PARAM_PRESERVE_BUFFER,
67
68   /**
69    * Return the maximum supported swap interval.
70    */
71   NATIVE_PARAM_MAX_SWAP_INTERVAL
72};
73
74struct native_surface {
75   /**
76    * Available for caller's use.
77    */
78   void *user_data;
79
80   void (*destroy)(struct native_surface *nsurf);
81
82   /**
83    * Present the given buffer to the native engine.
84    */
85   boolean (*present)(struct native_surface *nsurf,
86                      enum native_attachment natt,
87                      boolean preserve,
88                      uint swap_interval);
89
90   /**
91    * Validate the buffers of the surface.  textures, if not NULL, points to an
92    * array of size NUM_NATIVE_ATTACHMENTS and the returned textures are owned
93    * by the caller.  A sequence number is also returned.  The caller can use
94    * it to check if anything has changed since the last call. Any of the
95    * pointers may be NULL and it indicates the caller has no interest in those
96    * values.
97    *
98    * If this function is called multiple times with different attachment
99    * masks, those not listed in the latest call might be destroyed.  This
100    * behavior might change in the future.
101    */
102   boolean (*validate)(struct native_surface *nsurf, uint attachment_mask,
103                       unsigned int *seq_num, struct pipe_resource **textures,
104                       int *width, int *height);
105
106   /**
107    * Wait until all native commands affecting the surface has been executed.
108    */
109   void (*wait)(struct native_surface *nsurf);
110};
111
112/**
113 * Describe a native display config.
114 */
115struct native_config {
116   /* available buffers and their format */
117   uint buffer_mask;
118   enum pipe_format color_format;
119
120   /* supported surface types */
121   boolean window_bit;
122   boolean pixmap_bit;
123   boolean scanout_bit;
124
125   int native_visual_id;
126   int native_visual_type;
127   int level;
128   int samples;
129   boolean slow_config;
130   boolean transparent_rgb;
131   int transparent_rgb_values[3];
132};
133
134/**
135 * A pipe winsys abstracts the OS.  A pipe screen abstracts the graphcis
136 * hardware.  A native display consists of a pipe winsys, a pipe screen, and
137 * the native display server.
138 */
139struct native_display {
140   /**
141    * The pipe screen of the native display.
142    */
143   struct pipe_screen *screen;
144
145   /**
146    * Available for caller's use.
147    */
148   void *user_data;
149
150   void (*destroy)(struct native_display *ndpy);
151
152   /**
153    * Query the parameters of the native display.
154    *
155    * The return value is defined by the parameter.
156    */
157   int (*get_param)(struct native_display *ndpy,
158                    enum native_param_type param);
159
160   /**
161    * Get the supported configs.  The configs are owned by the display, but
162    * the returned array should be FREE()ed.
163    */
164   const struct native_config **(*get_configs)(struct native_display *ndpy,
165                                               int *num_configs);
166
167   /**
168    * Test if a pixmap is supported by the given config.  Required unless no
169    * config has pixmap_bit set.
170    *
171    * This function is usually called to find a config that supports a given
172    * pixmap.  Thus, it is usually called with the same pixmap in a row.
173    */
174   boolean (*is_pixmap_supported)(struct native_display *ndpy,
175                                  EGLNativePixmapType pix,
176                                  const struct native_config *nconf);
177
178
179   /**
180    * Create a window surface.  Required unless no config has window_bit set.
181    */
182   struct native_surface *(*create_window_surface)(struct native_display *ndpy,
183                                                   EGLNativeWindowType win,
184                                                   const struct native_config *nconf);
185
186   /**
187    * Create a pixmap surface.  Required unless no config has pixmap_bit set.
188    */
189   struct native_surface *(*create_pixmap_surface)(struct native_display *ndpy,
190                                                   EGLNativePixmapType pix,
191                                                   const struct native_config *nconf);
192
193   const struct native_display_modeset *modeset;
194};
195
196/**
197 * The handler for events that a native display may generate.  The events are
198 * generated asynchronously and the handler may be called by any thread at any
199 * time.
200 */
201struct native_event_handler {
202   /**
203    * This function is called when a surface needs to be validated.
204    */
205   void (*invalid_surface)(struct native_display *ndpy,
206                           struct native_surface *nsurf,
207                           unsigned int seq_num);
208
209   struct pipe_screen *(*new_drm_screen)(struct native_display *ndpy,
210                                         const char *name, int fd);
211   struct pipe_screen *(*new_sw_screen)(struct native_display *ndpy,
212                                        struct sw_winsys *ws);
213};
214
215/**
216 * Test whether an attachment is set in the mask.
217 */
218static INLINE boolean
219native_attachment_mask_test(uint mask, enum native_attachment att)
220{
221   return !!(mask & (1 << att));
222}
223
224struct native_platform {
225   const char *name;
226
227   struct native_display *(*create_display)(void *dpy,
228                                            struct native_event_handler *handler,
229                                            void *user_data);
230};
231
232const struct native_platform *
233native_get_gdi_platform(void);
234
235const struct native_platform *
236native_get_x11_platform(void);
237
238const struct native_platform *
239native_get_drm_platform(void);
240
241const struct native_platform *
242native_get_fbdev_platform(void);
243
244#ifdef __cplusplus
245}
246#endif
247
248#endif /* _NATIVE_H_ */
249