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