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