native.h revision 08e1076fd2d3f6fb879dd2529e7d035d6a399da2
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_buffer.h" 42#include "native_modeset.h" 43#include "native_wayland_bufmgr.h" 44 45/** 46 * Only color buffers are listed. The others are allocated privately through, 47 * for example, st_renderbuffer_alloc_storage(). 48 */ 49enum native_attachment { 50 NATIVE_ATTACHMENT_FRONT_LEFT, 51 NATIVE_ATTACHMENT_BACK_LEFT, 52 NATIVE_ATTACHMENT_FRONT_RIGHT, 53 NATIVE_ATTACHMENT_BACK_RIGHT, 54 55 NUM_NATIVE_ATTACHMENTS 56}; 57 58enum native_param_type { 59 /* 60 * Return TRUE if window/pixmap surfaces use the buffers of the native 61 * types. 62 */ 63 NATIVE_PARAM_USE_NATIVE_BUFFER, 64 65 /** 66 * Return TRUE if native_surface::present can preserve the buffer. 67 */ 68 NATIVE_PARAM_PRESERVE_BUFFER, 69 70 /** 71 * Return the maximum supported swap interval. 72 */ 73 NATIVE_PARAM_MAX_SWAP_INTERVAL 74}; 75 76/** 77 * Control how a surface presentation should happen. 78 */ 79struct native_present_control { 80 /**< the attachment to present */ 81 enum native_attachment natt; 82 83 /**< the contents of the presented attachment should be preserved */ 84 boolean preserve; 85 86 /**< wait until the given vsyncs has passed since the last presentation */ 87 uint swap_interval; 88}; 89 90struct native_surface { 91 /** 92 * Available for caller's use. 93 */ 94 void *user_data; 95 96 void (*destroy)(struct native_surface *nsurf); 97 98 /** 99 * Present the given buffer to the native engine. 100 */ 101 boolean (*present)(struct native_surface *nsurf, 102 const struct native_present_control *ctrl); 103 104 /** 105 * Validate the buffers of the surface. textures, if not NULL, points to an 106 * array of size NUM_NATIVE_ATTACHMENTS and the returned textures are owned 107 * by the caller. A sequence number is also returned. The caller can use 108 * it to check if anything has changed since the last call. Any of the 109 * pointers may be NULL and it indicates the caller has no interest in those 110 * values. 111 * 112 * If this function is called multiple times with different attachment 113 * masks, those not listed in the latest call might be destroyed. This 114 * behavior might change in the future. 115 */ 116 boolean (*validate)(struct native_surface *nsurf, uint attachment_mask, 117 unsigned int *seq_num, struct pipe_resource **textures, 118 int *width, int *height); 119 120 /** 121 * Wait until all native commands affecting the surface has been executed. 122 */ 123 void (*wait)(struct native_surface *nsurf); 124}; 125 126/** 127 * Describe a native display config. 128 */ 129struct native_config { 130 /* available buffers and their format */ 131 uint buffer_mask; 132 enum pipe_format color_format; 133 134 /* supported surface types */ 135 boolean window_bit; 136 boolean pixmap_bit; 137 boolean scanout_bit; 138 139 int native_visual_id; 140 int native_visual_type; 141 int level; 142 boolean transparent_rgb; 143 int transparent_rgb_values[3]; 144}; 145 146/** 147 * A pipe winsys abstracts the OS. A pipe screen abstracts the graphcis 148 * hardware. A native display consists of a pipe winsys, a pipe screen, and 149 * the native display server. 150 */ 151struct native_display { 152 /** 153 * The pipe screen of the native display. 154 */ 155 struct pipe_screen *screen; 156 157 /** 158 * Context used for copy operations. 159 */ 160 struct pipe_context *pipe; 161 162 /** 163 * Available for caller's use. 164 */ 165 void *user_data; 166 167 /** 168 * Initialize and create the pipe screen. 169 */ 170 boolean (*init_screen)(struct native_display *ndpy); 171 172 void (*destroy)(struct native_display *ndpy); 173 174 /** 175 * Query the parameters of the native display. 176 * 177 * The return value is defined by the parameter. 178 */ 179 int (*get_param)(struct native_display *ndpy, 180 enum native_param_type param); 181 182 /** 183 * Get the supported configs. The configs are owned by the display, but 184 * the returned array should be FREE()ed. 185 */ 186 const struct native_config **(*get_configs)(struct native_display *ndpy, 187 int *num_configs); 188 189 /** 190 * Get the color format of the pixmap. Required unless no config has 191 * pixmap_bit set. 192 */ 193 boolean (*get_pixmap_format)(struct native_display *ndpy, 194 EGLNativePixmapType pix, 195 enum pipe_format *format); 196 197 /** 198 * Copy the contents of the resource to the pixmap's front-left attachment. 199 * This is used to implement eglCopyBuffers. Required unless no config has 200 * pixmap_bit set. 201 */ 202 boolean (*copy_to_pixmap)(struct native_display *ndpy, 203 EGLNativePixmapType pix, 204 struct pipe_resource *src); 205 206 /** 207 * Create a window surface. Required unless no config has window_bit set. 208 */ 209 struct native_surface *(*create_window_surface)(struct native_display *ndpy, 210 EGLNativeWindowType win, 211 const struct native_config *nconf); 212 213 /** 214 * Create a pixmap surface. The native config may be NULL. In that case, a 215 * "best config" will be picked. Required unless no config has pixmap_bit 216 * set. 217 */ 218 struct native_surface *(*create_pixmap_surface)(struct native_display *ndpy, 219 EGLNativePixmapType pix, 220 const struct native_config *nconf); 221 222 const struct native_display_buffer *buffer; 223 const struct native_display_modeset *modeset; 224 const struct native_display_wayland_bufmgr *wayland_bufmgr; 225}; 226 227/** 228 * The handler for events that a native display may generate. The events are 229 * generated asynchronously and the handler may be called by any thread at any 230 * time. 231 */ 232struct native_event_handler { 233 /** 234 * This function is called when a surface needs to be validated. 235 */ 236 void (*invalid_surface)(struct native_display *ndpy, 237 struct native_surface *nsurf, 238 unsigned int seq_num); 239 240 struct pipe_screen *(*new_drm_screen)(struct native_display *ndpy, 241 const char *name, int fd); 242 struct pipe_screen *(*new_sw_screen)(struct native_display *ndpy, 243 struct sw_winsys *ws); 244 245 struct pipe_resource *(*lookup_egl_image)(struct native_display *ndpy, 246 void *egl_image); 247}; 248 249/** 250 * Test whether an attachment is set in the mask. 251 */ 252static INLINE boolean 253native_attachment_mask_test(uint mask, enum native_attachment att) 254{ 255 return !!(mask & (1 << att)); 256} 257 258/** 259 * Get the display copy context 260 */ 261static INLINE struct pipe_context * 262ndpy_get_copy_context(struct native_display *ndpy) 263{ 264 if (!ndpy->pipe) 265 ndpy->pipe = ndpy->screen->context_create(ndpy->screen, NULL); 266 return ndpy->pipe; 267} 268 269/** 270 * Free display screen and context resources 271 */ 272static INLINE void 273ndpy_uninit(struct native_display *ndpy) 274{ 275 if (ndpy->pipe) 276 ndpy->pipe->destroy(ndpy->pipe); 277 if (ndpy->screen) 278 ndpy->screen->destroy(ndpy->screen); 279} 280 281struct native_platform { 282 const char *name; 283 284 /** 285 * Create the native display and usually establish a connection to the 286 * display server. 287 * 288 * No event should be generated at this stage. 289 */ 290 struct native_display *(*create_display)(void *dpy, boolean use_sw); 291}; 292 293const struct native_platform * 294native_get_gdi_platform(const struct native_event_handler *event_handler); 295 296const struct native_platform * 297native_get_x11_platform(const struct native_event_handler *event_handler); 298 299const struct native_platform * 300native_get_wayland_platform(const struct native_event_handler *event_handler); 301 302const struct native_platform * 303native_get_drm_platform(const struct native_event_handler *event_handler); 304 305const struct native_platform * 306native_get_fbdev_platform(const struct native_event_handler *event_handler); 307 308const struct native_platform * 309native_get_android_platform(const struct native_event_handler *event_handler); 310 311#ifdef __cplusplus 312} 313#endif 314 315#endif /* _NATIVE_H_ */ 316