| File: | cdk/x11/cdkglcontext-x11.c |
| Warning: | line 418, column 26 2nd function call argument is an uninitialized value |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* CDK - The GIMP Drawing Kit | |||
| 2 | * | |||
| 3 | * cdkglcontext-x11.c: X11 specific OpenGL wrappers | |||
| 4 | * | |||
| 5 | * Copyright © 2014 Emmanuele Bassi | |||
| 6 | * | |||
| 7 | * This library is free software; you can redistribute it and/or | |||
| 8 | * modify it under the terms of the GNU Library General Public | |||
| 9 | * License as published by the Free Software Foundation; either | |||
| 10 | * version 2 of the License, or (at your option) any later version. | |||
| 11 | * | |||
| 12 | * This library is distributed in the hope that it will be useful, | |||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
| 15 | * Library General Public License for more details. | |||
| 16 | * | |||
| 17 | * You should have received a copy of the GNU Library General Public | |||
| 18 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | |||
| 19 | */ | |||
| 20 | ||||
| 21 | #include "config.h" | |||
| 22 | ||||
| 23 | #include "cdkglcontext-x11.h" | |||
| 24 | #include "cdkdisplay-x11.h" | |||
| 25 | #include "cdkscreen-x11.h" | |||
| 26 | ||||
| 27 | #include "cdkx11display.h" | |||
| 28 | #include "cdkx11glcontext.h" | |||
| 29 | #include "cdkx11screen.h" | |||
| 30 | #include "cdkx11window.h" | |||
| 31 | #include "cdkx11visual.h" | |||
| 32 | #include "cdkvisualprivate.h" | |||
| 33 | #include "cdkx11property.h" | |||
| 34 | #include <X11/Xatom.h> | |||
| 35 | ||||
| 36 | #include "cdkinternals.h" | |||
| 37 | ||||
| 38 | #include "cdkintl.h" | |||
| 39 | ||||
| 40 | #include <cairo/cairo-xlib.h> | |||
| 41 | ||||
| 42 | #include <epoxy/glx.h> | |||
| 43 | ||||
| 44 | G_DEFINE_TYPE (CdkX11GLContext, cdk_x11_gl_context, CDK_TYPE_GL_CONTEXT)static void cdk_x11_gl_context_init (CdkX11GLContext *self); static void cdk_x11_gl_context_class_init (CdkX11GLContextClass *klass ); static GType cdk_x11_gl_context_get_type_once (void); static gpointer cdk_x11_gl_context_parent_class = ((void*)0); static gint CdkX11GLContext_private_offset; static void cdk_x11_gl_context_class_intern_init (gpointer klass) { cdk_x11_gl_context_parent_class = g_type_class_peek_parent (klass); if (CdkX11GLContext_private_offset != 0) g_type_class_adjust_private_offset (klass, &CdkX11GLContext_private_offset); cdk_x11_gl_context_class_init ((CdkX11GLContextClass*) klass); } __attribute__ ((__unused__ )) static inline gpointer cdk_x11_gl_context_get_instance_private (CdkX11GLContext *self) { return (((gpointer) ((guint8*) (self ) + (glong) (CdkX11GLContext_private_offset)))); } GType cdk_x11_gl_context_get_type (void) { static GType static_g_define_type_id = 0; if ((__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id) == sizeof (gpointer), "Expression evaluates to false"); (void) ( 0 ? (gpointer) * (&static_g_define_type_id) : ((void*)0)) ; (!(__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id ) == sizeof (gpointer), "Expression evaluates to false"); __typeof__ (*(&static_g_define_type_id)) gapg_temp_newval; __typeof__ ((&static_g_define_type_id)) gapg_temp_atomic = (&static_g_define_type_id ); __atomic_load (gapg_temp_atomic, &gapg_temp_newval, 5) ; gapg_temp_newval; })) && g_once_init_enter_pointer ( &static_g_define_type_id)); })) ) { GType g_define_type_id = cdk_x11_gl_context_get_type_once (); (__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id) == sizeof (gpointer) , "Expression evaluates to false"); 0 ? (void) (*(&static_g_define_type_id ) = (g_define_type_id)) : (void) 0; g_once_init_leave_pointer ((&static_g_define_type_id), (gpointer) (guintptr) (g_define_type_id )); })) ; } return static_g_define_type_id; } __attribute__ ( (__noinline__)) static GType cdk_x11_gl_context_get_type_once (void) { GType g_define_type_id = g_type_register_static_simple ((cdk_gl_context_get_type ()), g_intern_static_string ("CdkX11GLContext" ), sizeof (CdkX11GLContextClass), (GClassInitFunc)(void (*)(void )) cdk_x11_gl_context_class_intern_init, sizeof (CdkX11GLContext ), (GInstanceInitFunc)(void (*)(void)) cdk_x11_gl_context_init , (GTypeFlags) 0); { {{};} } return g_define_type_id; } | |||
| 45 | ||||
| 46 | typedef struct { | |||
| 47 | CdkDisplay *display; | |||
| 48 | ||||
| 49 | GLXDrawable glx_drawable; | |||
| 50 | ||||
| 51 | Window dummy_xwin; | |||
| 52 | GLXWindow dummy_glx; | |||
| 53 | ||||
| 54 | guint32 last_frame_counter; | |||
| 55 | } DrawableInfo; | |||
| 56 | ||||
| 57 | static void | |||
| 58 | drawable_info_free (gpointer data_) | |||
| 59 | { | |||
| 60 | DrawableInfo *data = data_; | |||
| 61 | Display *dpy; | |||
| 62 | ||||
| 63 | cdk_x11_display_error_trap_push (data->display); | |||
| 64 | ||||
| 65 | dpy = cdk_x11_display_get_xdisplay (data->display); | |||
| 66 | ||||
| 67 | if (data->glx_drawable) | |||
| 68 | glXDestroyWindowepoxy_glXDestroyWindow (dpy, data->glx_drawable); | |||
| 69 | ||||
| 70 | if (data->dummy_glx) | |||
| 71 | glXDestroyWindowepoxy_glXDestroyWindow (dpy, data->dummy_glx); | |||
| 72 | ||||
| 73 | if (data->dummy_xwin) | |||
| 74 | XDestroyWindow (dpy, data->dummy_xwin); | |||
| 75 | ||||
| 76 | cdk_x11_display_error_trap_pop_ignored (data->display); | |||
| 77 | ||||
| 78 | g_slice_free (DrawableInfo, data)do { if (1) g_slice_free1 (sizeof (DrawableInfo), (data)); else (void) ((DrawableInfo*) 0 == (data)); } while (0); | |||
| 79 | } | |||
| 80 | ||||
| 81 | static DrawableInfo * | |||
| 82 | get_glx_drawable_info (CdkWindow *window) | |||
| 83 | { | |||
| 84 | return g_object_get_data (G_OBJECT (window)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((window)), (((GType) ((20) << (2)))))))), "-cdk-x11-window-glx-info"); | |||
| 85 | } | |||
| 86 | ||||
| 87 | static void | |||
| 88 | set_glx_drawable_info (CdkWindow *window, | |||
| 89 | DrawableInfo *info) | |||
| 90 | { | |||
| 91 | g_object_set_data_full (G_OBJECT (window)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((window)), (((GType) ((20) << (2)))))))), "-cdk-x11-window-glx-info", | |||
| 92 | info, | |||
| 93 | drawable_info_free); | |||
| 94 | } | |||
| 95 | ||||
| 96 | static void | |||
| 97 | maybe_wait_for_vblank (CdkDisplay *display, | |||
| 98 | GLXDrawable drawable) | |||
| 99 | { | |||
| 100 | CdkX11Display *display_x11 = CDK_X11_DISPLAY (display)((((CdkX11Display*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((display)), ((cdk_x11_display_get_type())))))); | |||
| 101 | Display *dpy = cdk_x11_display_get_xdisplay (display); | |||
| 102 | ||||
| 103 | if (display_x11->has_glx_sync_control) | |||
| 104 | { | |||
| 105 | gint64 ust, msc, sbc; | |||
| 106 | ||||
| 107 | glXGetSyncValuesOMLepoxy_glXGetSyncValuesOML (dpy, drawable, &ust, &msc, &sbc); | |||
| 108 | glXWaitForMscOMLepoxy_glXWaitForMscOML (dpy, drawable, | |||
| 109 | 0, 2, (msc + 1) % 2, | |||
| 110 | &ust, &msc, &sbc); | |||
| 111 | } | |||
| 112 | else if (display_x11->has_glx_video_sync) | |||
| 113 | { | |||
| 114 | guint32 current_count; | |||
| 115 | ||||
| 116 | glXGetVideoSyncSGIepoxy_glXGetVideoSyncSGI (¤t_count); | |||
| 117 | glXWaitVideoSyncSGIepoxy_glXWaitVideoSyncSGI (2, (current_count + 1) % 2, ¤t_count); | |||
| 118 | } | |||
| 119 | } | |||
| 120 | ||||
| 121 | void | |||
| 122 | cdk_x11_window_invalidate_for_new_frame (CdkWindow *window, | |||
| 123 | cairo_region_t *update_area) | |||
| 124 | { | |||
| 125 | cairo_rectangle_int_t window_rect; | |||
| 126 | CdkDisplay *display = cdk_window_get_display (window); | |||
| 127 | CdkX11Display *display_x11 = CDK_X11_DISPLAY (display)((((CdkX11Display*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((display)), ((cdk_x11_display_get_type())))))); | |||
| 128 | Display *dpy = cdk_x11_display_get_xdisplay (display); | |||
| 129 | CdkX11GLContext *context_x11; | |||
| 130 | unsigned int buffer_age; | |||
| 131 | gboolean invalidate_all; | |||
| 132 | ||||
| 133 | /* Minimal update is ok if we're not drawing with gl */ | |||
| 134 | if (window->gl_paint_context == NULL((void*)0)) | |||
| 135 | return; | |||
| 136 | ||||
| 137 | context_x11 = CDK_X11_GL_CONTEXT (window->gl_paint_context)((((CdkX11GLContext*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((window->gl_paint_context)), ((cdk_x11_gl_context_get_type ())))))); | |||
| 138 | ||||
| 139 | buffer_age = 0; | |||
| 140 | ||||
| 141 | context_x11->do_blit_swap = FALSE(0); | |||
| 142 | ||||
| 143 | if (display_x11->has_glx_buffer_age) | |||
| 144 | { | |||
| 145 | cdk_gl_context_make_current (window->gl_paint_context); | |||
| 146 | glXQueryDrawableepoxy_glXQueryDrawable(dpy, context_x11->drawable, | |||
| 147 | GLX_BACK_BUFFER_AGE_EXT0x20F4, &buffer_age); | |||
| 148 | } | |||
| 149 | ||||
| 150 | ||||
| 151 | invalidate_all = FALSE(0); | |||
| 152 | if (buffer_age >= 4) | |||
| 153 | { | |||
| 154 | cairo_rectangle_int_t whole_window = { 0, 0, cdk_window_get_width (window), cdk_window_get_height (window) }; | |||
| 155 | ||||
| 156 | if (cdk_gl_context_has_framebuffer_blit (window->gl_paint_context) && | |||
| 157 | cairo_region_contains_rectangle (update_area, &whole_window) != CAIRO_REGION_OVERLAP_IN) | |||
| 158 | { | |||
| 159 | context_x11->do_blit_swap = TRUE(!(0)); | |||
| 160 | } | |||
| 161 | else | |||
| 162 | invalidate_all = TRUE(!(0)); | |||
| 163 | } | |||
| 164 | else | |||
| 165 | { | |||
| 166 | if (buffer_age == 0) | |||
| 167 | { | |||
| 168 | invalidate_all = TRUE(!(0)); | |||
| 169 | } | |||
| 170 | if (buffer_age >= 2) | |||
| 171 | { | |||
| 172 | if (window->old_updated_area[0]) | |||
| 173 | cairo_region_union (update_area, window->old_updated_area[0]); | |||
| 174 | else | |||
| 175 | invalidate_all = TRUE(!(0)); | |||
| 176 | } | |||
| 177 | if (buffer_age >= 3) | |||
| 178 | { | |||
| 179 | if (window->old_updated_area[1]) | |||
| 180 | cairo_region_union (update_area, window->old_updated_area[1]); | |||
| 181 | else | |||
| 182 | invalidate_all = TRUE(!(0)); | |||
| 183 | } | |||
| 184 | } | |||
| 185 | ||||
| 186 | if (invalidate_all) | |||
| 187 | { | |||
| 188 | window_rect.x = 0; | |||
| 189 | window_rect.y = 0; | |||
| 190 | window_rect.width = cdk_window_get_width (window); | |||
| 191 | window_rect.height = cdk_window_get_height (window); | |||
| 192 | ||||
| 193 | /* If nothing else is known, repaint everything so that the back | |||
| 194 | buffer is fully up-to-date for the swapbuffer */ | |||
| 195 | cairo_region_union_rectangle (update_area, &window_rect); | |||
| 196 | } | |||
| 197 | ||||
| 198 | } | |||
| 199 | ||||
| 200 | static void | |||
| 201 | cdk_gl_blit_region (CdkWindow *window, cairo_region_t *region) | |||
| 202 | { | |||
| 203 | int n_rects, i; | |||
| 204 | int scale = cdk_window_get_scale_factor (window); | |||
| 205 | int wh = cdk_window_get_height (window); | |||
| 206 | cairo_rectangle_int_t rect; | |||
| 207 | ||||
| 208 | n_rects = cairo_region_num_rectangles (region); | |||
| 209 | for (i = 0; i < n_rects; i++) | |||
| 210 | { | |||
| 211 | cairo_region_get_rectangle (region, i, &rect); | |||
| 212 | glScissorepoxy_glScissor (rect.x * scale, (wh - rect.y - rect.height) * scale, rect.width * scale, rect.height * scale); | |||
| 213 | glBlitFramebufferepoxy_glBlitFramebuffer (rect.x * scale, (wh - rect.y - rect.height) * scale, (rect.x + rect.width) * scale, (wh - rect.y) * scale, | |||
| 214 | rect.x * scale, (wh - rect.y - rect.height) * scale, (rect.x + rect.width) * scale, (wh - rect.y) * scale, | |||
| 215 | GL_COLOR_BUFFER_BIT0x00004000, GL_NEAREST0x2600); | |||
| 216 | } | |||
| 217 | } | |||
| 218 | ||||
| 219 | static void | |||
| 220 | cdk_x11_gl_context_end_frame (CdkGLContext *context, | |||
| 221 | cairo_region_t *painted, | |||
| 222 | cairo_region_t *damage G_GNUC_UNUSED__attribute__ ((__unused__))) | |||
| 223 | { | |||
| 224 | CdkX11GLContext *context_x11 = CDK_X11_GL_CONTEXT (context)((((CdkX11GLContext*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((context)), ((cdk_x11_gl_context_get_type ())))))); | |||
| 225 | CdkWindow *window = cdk_gl_context_get_window (context); | |||
| 226 | CdkDisplay *display = cdk_gl_context_get_display (context); | |||
| 227 | Display *dpy = cdk_x11_display_get_xdisplay (display); | |||
| 228 | CdkX11Display *display_x11 = CDK_X11_DISPLAY (display)((((CdkX11Display*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((display)), ((cdk_x11_display_get_type())))))); | |||
| 229 | DrawableInfo *info; | |||
| 230 | GLXDrawable drawable; | |||
| 231 | ||||
| 232 | cdk_gl_context_make_current (context); | |||
| 233 | ||||
| 234 | info = get_glx_drawable_info (window); | |||
| 235 | ||||
| 236 | drawable = context_x11->drawable; | |||
| 237 | ||||
| 238 | CDK_NOTE (OPENGL,do { if ((_cdk_debug_flags & CDK_DEBUG_OPENGL)) { g_message ("Flushing GLX buffers for drawable %lu (window: %lu), frame sync: %s" , (unsigned long) drawable, (unsigned long) cdk_x11_window_get_xid (window), context_x11->do_frame_sync ? "yes" : "no"); }; } while (0) | |||
| 239 | g_message ("Flushing GLX buffers for drawable %lu (window: %lu), frame sync: %s",do { if ((_cdk_debug_flags & CDK_DEBUG_OPENGL)) { g_message ("Flushing GLX buffers for drawable %lu (window: %lu), frame sync: %s" , (unsigned long) drawable, (unsigned long) cdk_x11_window_get_xid (window), context_x11->do_frame_sync ? "yes" : "no"); }; } while (0) | |||
| 240 | (unsigned long) drawable,do { if ((_cdk_debug_flags & CDK_DEBUG_OPENGL)) { g_message ("Flushing GLX buffers for drawable %lu (window: %lu), frame sync: %s" , (unsigned long) drawable, (unsigned long) cdk_x11_window_get_xid (window), context_x11->do_frame_sync ? "yes" : "no"); }; } while (0) | |||
| 241 | (unsigned long) cdk_x11_window_get_xid (window),do { if ((_cdk_debug_flags & CDK_DEBUG_OPENGL)) { g_message ("Flushing GLX buffers for drawable %lu (window: %lu), frame sync: %s" , (unsigned long) drawable, (unsigned long) cdk_x11_window_get_xid (window), context_x11->do_frame_sync ? "yes" : "no"); }; } while (0) | |||
| 242 | context_x11->do_frame_sync ? "yes" : "no"))do { if ((_cdk_debug_flags & CDK_DEBUG_OPENGL)) { g_message ("Flushing GLX buffers for drawable %lu (window: %lu), frame sync: %s" , (unsigned long) drawable, (unsigned long) cdk_x11_window_get_xid (window), context_x11->do_frame_sync ? "yes" : "no"); }; } while (0); | |||
| 243 | ||||
| 244 | /* if we are going to wait for the vertical refresh manually | |||
| 245 | * we need to flush pending redraws, and we also need to wait | |||
| 246 | * for that to finish, otherwise we are going to tear. | |||
| 247 | * | |||
| 248 | * obviously, this condition should not be hit if we have | |||
| 249 | * GLX_SGI_swap_control, and we ask the driver to do the right | |||
| 250 | * thing. | |||
| 251 | */ | |||
| 252 | if (context_x11->do_frame_sync) | |||
| 253 | { | |||
| 254 | guint32 end_frame_counter = 0; | |||
| 255 | gboolean has_counter = display_x11->has_glx_video_sync; | |||
| 256 | gboolean can_wait = display_x11->has_glx_video_sync || display_x11->has_glx_sync_control; | |||
| 257 | ||||
| 258 | if (display_x11->has_glx_video_sync) | |||
| 259 | glXGetVideoSyncSGIepoxy_glXGetVideoSyncSGI (&end_frame_counter); | |||
| 260 | ||||
| 261 | if (context_x11->do_frame_sync && !display_x11->has_glx_swap_interval) | |||
| 262 | { | |||
| 263 | glFinishepoxy_glFinish (); | |||
| 264 | ||||
| 265 | if (has_counter && can_wait) | |||
| 266 | { | |||
| 267 | guint32 last_counter = info != NULL((void*)0) ? info->last_frame_counter : 0; | |||
| 268 | ||||
| 269 | if (last_counter == end_frame_counter) | |||
| 270 | maybe_wait_for_vblank (display, drawable); | |||
| 271 | } | |||
| 272 | else if (can_wait) | |||
| 273 | maybe_wait_for_vblank (display, drawable); | |||
| 274 | } | |||
| 275 | } | |||
| 276 | ||||
| 277 | if (context_x11->do_blit_swap) | |||
| 278 | { | |||
| 279 | glDrawBufferepoxy_glDrawBuffer(GL_FRONT0x0404); | |||
| 280 | glReadBufferepoxy_glReadBuffer(GL_BACK0x0405); | |||
| 281 | cdk_gl_blit_region (window, painted); | |||
| 282 | glDrawBufferepoxy_glDrawBuffer(GL_BACK0x0405); | |||
| 283 | glFlushepoxy_glFlush(); | |||
| 284 | ||||
| 285 | if (cdk_gl_context_has_frame_terminator (context)) | |||
| 286 | glFrameTerminatorGREMEDYepoxy_glFrameTerminatorGREMEDY (); | |||
| 287 | } | |||
| 288 | else | |||
| 289 | glXSwapBuffersepoxy_glXSwapBuffers (dpy, drawable); | |||
| 290 | ||||
| 291 | if (context_x11->do_frame_sync && info != NULL((void*)0) && display_x11->has_glx_video_sync) | |||
| 292 | glXGetVideoSyncSGIepoxy_glXGetVideoSyncSGI (&info->last_frame_counter); | |||
| 293 | } | |||
| 294 | ||||
| 295 | typedef struct { | |||
| 296 | Display *display; | |||
| 297 | GLXDrawable drawable; | |||
| 298 | gboolean y_inverted; | |||
| 299 | } CdkGLXPixmap; | |||
| 300 | ||||
| 301 | static void | |||
| 302 | glx_pixmap_destroy (void *data) | |||
| 303 | { | |||
| 304 | CdkGLXPixmap *glx_pixmap = data; | |||
| 305 | ||||
| 306 | glXDestroyPixmapepoxy_glXDestroyPixmap (glx_pixmap->display, glx_pixmap->drawable); | |||
| 307 | ||||
| 308 | g_slice_free (CdkGLXPixmap, glx_pixmap)do { if (1) g_slice_free1 (sizeof (CdkGLXPixmap), (glx_pixmap )); else (void) ((CdkGLXPixmap*) 0 == (glx_pixmap)); } while ( 0); | |||
| 309 | } | |||
| 310 | ||||
| 311 | static CdkGLXPixmap * | |||
| 312 | glx_pixmap_get (cairo_surface_t *surface, guint texture_target) | |||
| 313 | { | |||
| 314 | Display *display = cairo_xlib_surface_get_display (surface); | |||
| 315 | Screen *screen = cairo_xlib_surface_get_screen (surface); | |||
| 316 | Visual *visual = cairo_xlib_surface_get_visual (surface); | |||
| 317 | CdkGLXPixmap *glx_pixmap; | |||
| 318 | GLXFBConfig *fbconfigs, config; | |||
| 319 | int nfbconfigs; | |||
| 320 | XVisualInfo *visinfo; | |||
| 321 | VisualID visualid; | |||
| 322 | int i, value; | |||
| 323 | gboolean y_inverted; | |||
| 324 | gboolean with_alpha; | |||
| 325 | guint target = 0; | |||
| 326 | guint format = 0; | |||
| 327 | int pixmap_attributes[] = { | |||
| 328 | GLX_TEXTURE_TARGET_EXT0x20D6, 0, | |||
| 329 | GLX_TEXTURE_FORMAT_EXT0x20D5, 0, | |||
| 330 | None0L | |||
| 331 | }; | |||
| 332 | ||||
| 333 | if (visual == NULL((void*)0)) | |||
| 334 | return NULL((void*)0); | |||
| 335 | ||||
| 336 | with_alpha = cairo_surface_get_content (surface) == CAIRO_CONTENT_COLOR_ALPHA; | |||
| 337 | ||||
| 338 | y_inverted = FALSE(0); | |||
| 339 | fbconfigs = glXGetFBConfigsepoxy_glXGetFBConfigs (display, XScreenNumberOfScreen (screen), &nfbconfigs); | |||
| 340 | for (i = 0; i < nfbconfigs; i++) | |||
| 341 | { | |||
| 342 | visinfo = glXGetVisualFromFBConfigepoxy_glXGetVisualFromFBConfig (display, fbconfigs[i]); | |||
| 343 | if (!visinfo) | |||
| 344 | continue; | |||
| 345 | ||||
| 346 | visualid = visinfo->visualid; | |||
| 347 | XFree (visinfo); | |||
| 348 | ||||
| 349 | if (visualid != XVisualIDFromVisual (visual)) | |||
| 350 | continue; | |||
| 351 | ||||
| 352 | glXGetFBConfigAttribepoxy_glXGetFBConfigAttrib (display, fbconfigs[i], GLX_DRAWABLE_TYPE0x8010, &value); | |||
| 353 | if (!(value & GLX_PIXMAP_BIT0x00000002)) | |||
| 354 | continue; | |||
| 355 | ||||
| 356 | glXGetFBConfigAttribepoxy_glXGetFBConfigAttrib (display, fbconfigs[i], | |||
| 357 | GLX_BIND_TO_TEXTURE_TARGETS_EXT0x20D3, | |||
| 358 | &value); | |||
| 359 | if (texture_target == GL_TEXTURE_2D0x0DE1) | |||
| 360 | { | |||
| 361 | if (value & GLX_TEXTURE_2D_BIT_EXT0x00000002) | |||
| 362 | target = GLX_TEXTURE_2D_EXT0x20DC; | |||
| 363 | else | |||
| 364 | continue; | |||
| 365 | } | |||
| 366 | else if (texture_target == GL_TEXTURE_RECTANGLE_ARB0x84F5) | |||
| 367 | { | |||
| 368 | if (value & GLX_TEXTURE_RECTANGLE_BIT_EXT0x00000004) | |||
| 369 | target = GLX_TEXTURE_RECTANGLE_EXT0x20DD; | |||
| 370 | else | |||
| 371 | continue; | |||
| 372 | } | |||
| 373 | else | |||
| 374 | continue; | |||
| 375 | ||||
| 376 | if (!with_alpha) | |||
| 377 | { | |||
| 378 | glXGetFBConfigAttribepoxy_glXGetFBConfigAttrib (display, fbconfigs[i], | |||
| 379 | GLX_BIND_TO_TEXTURE_RGB_EXT0x20D0, | |||
| 380 | &value); | |||
| 381 | if (!value) | |||
| 382 | continue; | |||
| 383 | ||||
| 384 | format = GLX_TEXTURE_FORMAT_RGB_EXT0x20D9; | |||
| 385 | } | |||
| 386 | else | |||
| 387 | { | |||
| 388 | glXGetFBConfigAttribepoxy_glXGetFBConfigAttrib (display, fbconfigs[i], | |||
| 389 | GLX_BIND_TO_TEXTURE_RGBA_EXT0x20D1, | |||
| 390 | &value); | |||
| 391 | if (!value) | |||
| 392 | continue; | |||
| 393 | ||||
| 394 | format = GLX_TEXTURE_FORMAT_RGBA_EXT0x20DA; | |||
| 395 | } | |||
| 396 | ||||
| 397 | glXGetFBConfigAttribepoxy_glXGetFBConfigAttrib (display, fbconfigs[i], | |||
| 398 | GLX_Y_INVERTED_EXT0x20D4, | |||
| 399 | &value); | |||
| 400 | if (value == TRUE(!(0))) | |||
| 401 | y_inverted = TRUE(!(0)); | |||
| 402 | ||||
| 403 | config = fbconfigs[i]; | |||
| 404 | break; | |||
| 405 | } | |||
| 406 | ||||
| 407 | XFree (fbconfigs); | |||
| 408 | ||||
| 409 | if (i == nfbconfigs) | |||
| 410 | return NULL((void*)0); | |||
| 411 | ||||
| 412 | pixmap_attributes[1] = target; | |||
| 413 | pixmap_attributes[3] = format; | |||
| 414 | ||||
| 415 | glx_pixmap = g_slice_new0 (CdkGLXPixmap)((CdkGLXPixmap*) g_slice_alloc0 (sizeof (CdkGLXPixmap))); | |||
| 416 | glx_pixmap->y_inverted = y_inverted; | |||
| 417 | glx_pixmap->display = display; | |||
| 418 | glx_pixmap->drawable = glXCreatePixmapepoxy_glXCreatePixmap (display, config, | |||
| ||||
| 419 | cairo_xlib_surface_get_drawable (surface), | |||
| 420 | pixmap_attributes); | |||
| 421 | ||||
| 422 | return glx_pixmap; | |||
| 423 | } | |||
| 424 | ||||
| 425 | static gboolean | |||
| 426 | cdk_x11_gl_context_texture_from_surface (CdkGLContext *paint_context, | |||
| 427 | cairo_surface_t *surface, | |||
| 428 | cairo_region_t *region) | |||
| 429 | { | |||
| 430 | CdkGLXPixmap *glx_pixmap; | |||
| 431 | double device_x_offset, device_y_offset; | |||
| 432 | cairo_rectangle_int_t rect; | |||
| 433 | int n_rects, i; | |||
| 434 | CdkWindow *window; | |||
| 435 | int unscaled_window_height; | |||
| 436 | int window_scale; | |||
| 437 | unsigned int texture_id; | |||
| 438 | gboolean use_texture_rectangle; | |||
| 439 | guint target; | |||
| 440 | double sx, sy; | |||
| 441 | float uscale, vscale; | |||
| 442 | CdkTexturedQuad *quads; | |||
| 443 | CdkX11Display *display_x11; | |||
| 444 | ||||
| 445 | display_x11 = CDK_X11_DISPLAY (cdk_gl_context_get_display (paint_context))((((CdkX11Display*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((cdk_gl_context_get_display (paint_context))), ((cdk_x11_display_get_type ())))))); | |||
| 446 | if (!display_x11->has_glx_texture_from_pixmap) | |||
| ||||
| 447 | return FALSE(0); | |||
| 448 | ||||
| 449 | if (cairo_surface_get_type (surface) != CAIRO_SURFACE_TYPE_XLIB) | |||
| 450 | return FALSE(0); | |||
| 451 | ||||
| 452 | use_texture_rectangle = cdk_gl_context_use_texture_rectangle (paint_context); | |||
| 453 | if (use_texture_rectangle) | |||
| 454 | target = GL_TEXTURE_RECTANGLE_ARB0x84F5; | |||
| 455 | else | |||
| 456 | target = GL_TEXTURE_2D0x0DE1; | |||
| 457 | ||||
| 458 | glx_pixmap = glx_pixmap_get (surface, target); | |||
| 459 | if (glx_pixmap == NULL((void*)0)) | |||
| 460 | return FALSE(0); | |||
| 461 | ||||
| 462 | CDK_NOTE (OPENGL, g_message ("Using GLX_EXT_texture_from_pixmap to draw surface"))do { if ((_cdk_debug_flags & CDK_DEBUG_OPENGL)) { g_message ("Using GLX_EXT_texture_from_pixmap to draw surface"); }; } while (0); | |||
| 463 | ||||
| 464 | window = cdk_gl_context_get_window (paint_context)->impl_window; | |||
| 465 | window_scale = cdk_window_get_scale_factor (window); | |||
| 466 | cdk_window_get_unscaled_size (window, NULL((void*)0), &unscaled_window_height); | |||
| 467 | ||||
| 468 | sx = sy = 1; | |||
| 469 | cairo_surface_get_device_scale (window->current_paint.surface, &sx, &sy); | |||
| 470 | cairo_surface_get_device_offset (surface, &device_x_offset, &device_y_offset); | |||
| 471 | ||||
| 472 | /* Ensure all the X stuff are synced before we read it back via texture-from-pixmap */ | |||
| 473 | glXWaitXepoxy_glXWaitX(); | |||
| 474 | ||||
| 475 | glGenTexturesepoxy_glGenTextures (1, &texture_id); | |||
| 476 | glBindTextureepoxy_glBindTexture (target, texture_id); | |||
| 477 | ||||
| 478 | glTexParameteriepoxy_glTexParameteri (target, GL_TEXTURE_WRAP_S0x2802, GL_CLAMP_TO_EDGE0x812F); | |||
| 479 | glTexParameteriepoxy_glTexParameteri (target, GL_TEXTURE_WRAP_T0x2803, GL_CLAMP_TO_EDGE0x812F); | |||
| 480 | glTexParameteriepoxy_glTexParameteri (target, GL_TEXTURE_MIN_FILTER0x2801, GL_NEAREST0x2600); | |||
| 481 | glTexParameteriepoxy_glTexParameteri (target, GL_TEXTURE_MAG_FILTER0x2800, GL_NEAREST0x2600); | |||
| 482 | ||||
| 483 | glXBindTexImageEXTepoxy_glXBindTexImageEXT (glx_pixmap->display, glx_pixmap->drawable, | |||
| 484 | GLX_FRONT_LEFT_EXT0x20DE, NULL((void*)0)); | |||
| 485 | ||||
| 486 | glEnableepoxy_glEnable (GL_SCISSOR_TEST0x0C11); | |||
| 487 | ||||
| 488 | n_rects = cairo_region_num_rectangles (region); | |||
| 489 | quads = g_new (CdkTexturedQuad, n_rects)((CdkTexturedQuad *) g_malloc_n ((n_rects), sizeof (CdkTexturedQuad ))); | |||
| 490 | ||||
| 491 | #define FLIP_Y(_y) (unscaled_window_height - (_y)) | |||
| 492 | ||||
| 493 | cairo_region_get_extents (region, &rect); | |||
| 494 | glScissorepoxy_glScissor (rect.x * window_scale, FLIP_Y((rect.y + rect.height) * window_scale), | |||
| 495 | rect.width * window_scale, rect.height * window_scale); | |||
| 496 | ||||
| 497 | for (i = 0; i < n_rects; i++) | |||
| 498 | { | |||
| 499 | int src_x, src_y, src_height, src_width; | |||
| 500 | ||||
| 501 | cairo_region_get_rectangle (region, i, &rect); | |||
| 502 | ||||
| 503 | src_x = rect.x * sx + device_x_offset; | |||
| 504 | src_y = rect.y * sy + device_y_offset; | |||
| 505 | src_width = rect.width * sx; | |||
| 506 | src_height = rect.height * sy; | |||
| 507 | ||||
| 508 | if (use_texture_rectangle) | |||
| 509 | { | |||
| 510 | uscale = 1.0; | |||
| 511 | vscale = 1.0; | |||
| 512 | } | |||
| 513 | else | |||
| 514 | { | |||
| 515 | uscale = 1.0 / cairo_xlib_surface_get_width (surface); | |||
| 516 | vscale = 1.0 / cairo_xlib_surface_get_height (surface); | |||
| 517 | } | |||
| 518 | ||||
| 519 | { | |||
| 520 | CdkTexturedQuad quad = { | |||
| 521 | rect.x * window_scale, FLIP_Y(rect.y * window_scale), | |||
| 522 | (rect.x + rect.width) * window_scale, FLIP_Y((rect.y + rect.height) * window_scale), | |||
| 523 | uscale * src_x, vscale * src_y, | |||
| 524 | uscale * (src_x + src_width), vscale * (src_y + src_height), | |||
| 525 | }; | |||
| 526 | ||||
| 527 | quads[i] = quad; | |||
| 528 | } | |||
| 529 | } | |||
| 530 | ||||
| 531 | #undef FLIP_Y | |||
| 532 | ||||
| 533 | cdk_gl_texture_quads (paint_context, target, n_rects, quads, FALSE(0)); | |||
| 534 | g_free (quads); | |||
| 535 | ||||
| 536 | glDisableepoxy_glDisable (GL_SCISSOR_TEST0x0C11); | |||
| 537 | ||||
| 538 | glXReleaseTexImageEXTepoxy_glXReleaseTexImageEXT (glx_pixmap->display, glx_pixmap->drawable, | |||
| 539 | GLX_FRONT_LEFT_EXT0x20DE); | |||
| 540 | ||||
| 541 | glDeleteTexturesepoxy_glDeleteTextures (1, &texture_id); | |||
| 542 | ||||
| 543 | glx_pixmap_destroy(glx_pixmap); | |||
| 544 | ||||
| 545 | return TRUE(!(0)); | |||
| 546 | } | |||
| 547 | ||||
| 548 | static XVisualInfo * | |||
| 549 | find_xvisinfo_for_fbconfig (CdkDisplay *display, | |||
| 550 | GLXFBConfig config) | |||
| 551 | { | |||
| 552 | Display *dpy = cdk_x11_display_get_xdisplay (display); | |||
| 553 | ||||
| 554 | return glXGetVisualFromFBConfigepoxy_glXGetVisualFromFBConfig (dpy, config); | |||
| 555 | } | |||
| 556 | ||||
| 557 | static GLXContext | |||
| 558 | create_gl3_context (CdkDisplay *display, | |||
| 559 | GLXFBConfig config, | |||
| 560 | CdkGLContext *share, | |||
| 561 | int profile, | |||
| 562 | int flags, | |||
| 563 | int major, | |||
| 564 | int minor) | |||
| 565 | { | |||
| 566 | int attrib_list[] = { | |||
| 567 | GLX_CONTEXT_PROFILE_MASK_ARB0x9126, profile, | |||
| 568 | GLX_CONTEXT_MAJOR_VERSION_ARB0x2091, major, | |||
| 569 | GLX_CONTEXT_MINOR_VERSION_ARB0x2092, minor, | |||
| 570 | GLX_CONTEXT_FLAGS_ARB0x2094, flags, | |||
| 571 | None0L, | |||
| 572 | }; | |||
| 573 | GLXContext res; | |||
| 574 | ||||
| 575 | CdkX11GLContext *share_x11 = NULL((void*)0); | |||
| 576 | ||||
| 577 | if (share != NULL((void*)0)) | |||
| 578 | share_x11 = CDK_X11_GL_CONTEXT (share)((((CdkX11GLContext*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((share)), ((cdk_x11_gl_context_get_type ())))))); | |||
| 579 | ||||
| 580 | cdk_x11_display_error_trap_push (display); | |||
| 581 | ||||
| 582 | res = glXCreateContextAttribsARBepoxy_glXCreateContextAttribsARB (cdk_x11_display_get_xdisplay (display), | |||
| 583 | config, | |||
| 584 | share_x11 != NULL((void*)0) ? share_x11->glx_context : NULL((void*)0), | |||
| 585 | True1, | |||
| 586 | attrib_list); | |||
| 587 | ||||
| 588 | if (cdk_x11_display_error_trap_pop (display)) | |||
| 589 | return NULL((void*)0); | |||
| 590 | ||||
| 591 | return res; | |||
| 592 | } | |||
| 593 | ||||
| 594 | static GLXContext | |||
| 595 | create_legacy_context (CdkDisplay *display, | |||
| 596 | GLXFBConfig config, | |||
| 597 | CdkGLContext *share) | |||
| 598 | { | |||
| 599 | CdkX11GLContext *share_x11 = NULL((void*)0); | |||
| 600 | GLXContext res; | |||
| 601 | ||||
| 602 | if (share != NULL((void*)0)) | |||
| 603 | share_x11 = CDK_X11_GL_CONTEXT (share)((((CdkX11GLContext*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((share)), ((cdk_x11_gl_context_get_type ())))))); | |||
| 604 | ||||
| 605 | cdk_x11_display_error_trap_push (display); | |||
| 606 | ||||
| 607 | res = glXCreateNewContextepoxy_glXCreateNewContext (cdk_x11_display_get_xdisplay (display), | |||
| 608 | config, | |||
| 609 | GLX_RGBA_TYPE0x8014, | |||
| 610 | share_x11 != NULL((void*)0) ? share_x11->glx_context : NULL((void*)0), | |||
| 611 | TRUE(!(0))); | |||
| 612 | ||||
| 613 | if (cdk_x11_display_error_trap_pop (display)) | |||
| 614 | return NULL((void*)0); | |||
| 615 | ||||
| 616 | return res; | |||
| 617 | } | |||
| 618 | ||||
| 619 | static gboolean | |||
| 620 | cdk_x11_gl_context_realize (CdkGLContext *context, | |||
| 621 | GError **error) | |||
| 622 | { | |||
| 623 | CdkX11Display *display_x11; | |||
| 624 | CdkDisplay *display; | |||
| 625 | CdkX11GLContext *context_x11; | |||
| 626 | GLXWindow drawable; | |||
| 627 | XVisualInfo *xvisinfo; | |||
| 628 | Display *dpy; | |||
| 629 | DrawableInfo *info; | |||
| 630 | CdkGLContext *share; | |||
| 631 | CdkWindow *window; | |||
| 632 | gboolean debug_bit, compat_bit, legacy_bit, es_bit; | |||
| 633 | int major, minor, flags; | |||
| 634 | ||||
| 635 | window = cdk_gl_context_get_window (context); | |||
| 636 | display = cdk_window_get_display (window); | |||
| 637 | dpy = cdk_x11_display_get_xdisplay (display); | |||
| 638 | context_x11 = CDK_X11_GL_CONTEXT (context)((((CdkX11GLContext*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((context)), ((cdk_x11_gl_context_get_type ())))))); | |||
| 639 | display_x11 = CDK_X11_DISPLAY (display)((((CdkX11Display*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((display)), ((cdk_x11_display_get_type())))))); | |||
| 640 | share = cdk_gl_context_get_shared_context (context); | |||
| 641 | ||||
| 642 | cdk_gl_context_get_required_version (context, &major, &minor); | |||
| 643 | debug_bit = cdk_gl_context_get_debug_enabled (context); | |||
| 644 | compat_bit = cdk_gl_context_get_forward_compatible (context); | |||
| 645 | ||||
| 646 | /* If there is no glXCreateContextAttribsARB() then we default to legacy */ | |||
| 647 | legacy_bit = !display_x11->has_glx_create_context || | |||
| 648 | (_cdk_gl_flags & CDK_GL_LEGACY) != 0; | |||
| 649 | ||||
| 650 | es_bit = ((_cdk_gl_flags & CDK_GL_GLES) != 0 || | |||
| 651 | (share != NULL((void*)0) && cdk_gl_context_get_use_es (share))) && | |||
| 652 | (display_x11->has_glx_create_context && display_x11->has_glx_create_es2_context); | |||
| 653 | ||||
| 654 | /* We cannot share legacy contexts with core profile ones, so the | |||
| 655 | * shared context is the one that decides if we're going to create | |||
| 656 | * a legacy context or not. | |||
| 657 | */ | |||
| 658 | if (share != NULL((void*)0) && cdk_gl_context_is_legacy (share)) | |||
| 659 | legacy_bit = TRUE(!(0)); | |||
| 660 | ||||
| 661 | flags = 0; | |||
| 662 | if (debug_bit) | |||
| 663 | flags |= GLX_CONTEXT_DEBUG_BIT_ARB0x00000001; | |||
| 664 | if (compat_bit) | |||
| 665 | flags |= GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB0x00000002; | |||
| 666 | ||||
| 667 | CDK_NOTE (OPENGL,do { if ((_cdk_debug_flags & CDK_DEBUG_OPENGL)) { g_message ("Creating GLX context (version:%d.%d, debug:%s, forward:%s, legacy:%s, es:%s)" , major, minor, debug_bit ? "yes" : "no", compat_bit ? "yes" : "no", legacy_bit ? "yes" : "no", es_bit ? "yes" : "no"); }; } while (0) | |||
| 668 | g_message ("Creating GLX context (version:%d.%d, debug:%s, forward:%s, legacy:%s, es:%s)",do { if ((_cdk_debug_flags & CDK_DEBUG_OPENGL)) { g_message ("Creating GLX context (version:%d.%d, debug:%s, forward:%s, legacy:%s, es:%s)" , major, minor, debug_bit ? "yes" : "no", compat_bit ? "yes" : "no", legacy_bit ? "yes" : "no", es_bit ? "yes" : "no"); }; } while (0) | |||
| 669 | major, minor,do { if ((_cdk_debug_flags & CDK_DEBUG_OPENGL)) { g_message ("Creating GLX context (version:%d.%d, debug:%s, forward:%s, legacy:%s, es:%s)" , major, minor, debug_bit ? "yes" : "no", compat_bit ? "yes" : "no", legacy_bit ? "yes" : "no", es_bit ? "yes" : "no"); }; } while (0) | |||
| 670 | debug_bit ? "yes" : "no",do { if ((_cdk_debug_flags & CDK_DEBUG_OPENGL)) { g_message ("Creating GLX context (version:%d.%d, debug:%s, forward:%s, legacy:%s, es:%s)" , major, minor, debug_bit ? "yes" : "no", compat_bit ? "yes" : "no", legacy_bit ? "yes" : "no", es_bit ? "yes" : "no"); }; } while (0) | |||
| 671 | compat_bit ? "yes" : "no",do { if ((_cdk_debug_flags & CDK_DEBUG_OPENGL)) { g_message ("Creating GLX context (version:%d.%d, debug:%s, forward:%s, legacy:%s, es:%s)" , major, minor, debug_bit ? "yes" : "no", compat_bit ? "yes" : "no", legacy_bit ? "yes" : "no", es_bit ? "yes" : "no"); }; } while (0) | |||
| 672 | legacy_bit ? "yes" : "no",do { if ((_cdk_debug_flags & CDK_DEBUG_OPENGL)) { g_message ("Creating GLX context (version:%d.%d, debug:%s, forward:%s, legacy:%s, es:%s)" , major, minor, debug_bit ? "yes" : "no", compat_bit ? "yes" : "no", legacy_bit ? "yes" : "no", es_bit ? "yes" : "no"); }; } while (0) | |||
| 673 | es_bit ? "yes" : "no"))do { if ((_cdk_debug_flags & CDK_DEBUG_OPENGL)) { g_message ("Creating GLX context (version:%d.%d, debug:%s, forward:%s, legacy:%s, es:%s)" , major, minor, debug_bit ? "yes" : "no", compat_bit ? "yes" : "no", legacy_bit ? "yes" : "no", es_bit ? "yes" : "no"); }; } while (0); | |||
| 674 | ||||
| 675 | /* If we have access to GLX_ARB_create_context_profile then we can ask for | |||
| 676 | * a compatibility profile; if we don't, then we have to fall back to the | |||
| 677 | * old GLX 1.3 API. | |||
| 678 | */ | |||
| 679 | if (legacy_bit && !CDK_X11_DISPLAY (display)((((CdkX11Display*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((display)), ((cdk_x11_display_get_type()))))))->has_glx_create_context) | |||
| 680 | { | |||
| 681 | CDK_NOTE (OPENGL, g_message ("Creating legacy GL context on request"))do { if ((_cdk_debug_flags & CDK_DEBUG_OPENGL)) { g_message ("Creating legacy GL context on request"); }; } while (0); | |||
| 682 | context_x11->glx_context = create_legacy_context (display, context_x11->glx_config, share); | |||
| 683 | } | |||
| 684 | else | |||
| 685 | { | |||
| 686 | int profile; | |||
| 687 | ||||
| 688 | if (es_bit) | |||
| 689 | profile = GLX_CONTEXT_ES2_PROFILE_BIT_EXT0x00000004; | |||
| 690 | else | |||
| 691 | profile = legacy_bit ? GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB0x00000002 | |||
| 692 | : GLX_CONTEXT_CORE_PROFILE_BIT_ARB0x00000001; | |||
| 693 | ||||
| 694 | /* We need to tweak the version, otherwise we may end up requesting | |||
| 695 | * a compatibility context with a minimum version of 3.2, which is | |||
| 696 | * an error | |||
| 697 | */ | |||
| 698 | if (legacy_bit) | |||
| 699 | { | |||
| 700 | major = 3; | |||
| 701 | minor = 0; | |||
| 702 | } | |||
| 703 | ||||
| 704 | CDK_NOTE (OPENGL, g_message ("Creating GL3 context"))do { if ((_cdk_debug_flags & CDK_DEBUG_OPENGL)) { g_message ("Creating GL3 context"); }; } while (0); | |||
| 705 | context_x11->glx_context = create_gl3_context (display, | |||
| 706 | context_x11->glx_config, | |||
| 707 | share, | |||
| 708 | profile, flags, major, minor); | |||
| 709 | ||||
| 710 | /* Fall back to legacy in case the GL3 context creation failed */ | |||
| 711 | if (context_x11->glx_context == NULL((void*)0)) | |||
| 712 | { | |||
| 713 | CDK_NOTE (OPENGL, g_message ("Creating fallback legacy context"))do { if ((_cdk_debug_flags & CDK_DEBUG_OPENGL)) { g_message ("Creating fallback legacy context"); }; } while (0); | |||
| 714 | context_x11->glx_context = create_legacy_context (display, context_x11->glx_config, share); | |||
| 715 | legacy_bit = TRUE(!(0)); | |||
| 716 | es_bit = FALSE(0); | |||
| 717 | } | |||
| 718 | } | |||
| 719 | ||||
| 720 | if (context_x11->glx_context == NULL((void*)0)) | |||
| 721 | { | |||
| 722 | g_set_error_literal (error, CDK_GL_ERROR(cdk_gl_error_quark ()), | |||
| 723 | CDK_GL_ERROR_NOT_AVAILABLE, | |||
| 724 | _("Unable to create a GL context")((char *) g_dgettext ("ctk30", "Unable to create a GL context" ))); | |||
| 725 | return FALSE(0); | |||
| 726 | } | |||
| 727 | ||||
| 728 | /* Ensure that any other context is created with a legacy bit set */ | |||
| 729 | cdk_gl_context_set_is_legacy (context, legacy_bit); | |||
| 730 | ||||
| 731 | /* Ensure that any other context is created with a ES bit set */ | |||
| 732 | cdk_gl_context_set_use_es (context, es_bit); | |||
| 733 | ||||
| 734 | xvisinfo = find_xvisinfo_for_fbconfig (display, context_x11->glx_config); | |||
| 735 | ||||
| 736 | info = get_glx_drawable_info (window->impl_window); | |||
| 737 | if (info == NULL((void*)0)) | |||
| 738 | { | |||
| 739 | XSetWindowAttributes attrs; | |||
| 740 | unsigned long mask; | |||
| 741 | ||||
| 742 | cdk_x11_display_error_trap_push (display); | |||
| 743 | ||||
| 744 | info = g_slice_new0 (DrawableInfo)((DrawableInfo*) g_slice_alloc0 (sizeof (DrawableInfo))); | |||
| 745 | info->display = display; | |||
| 746 | info->last_frame_counter = 0; | |||
| 747 | ||||
| 748 | attrs.override_redirect = True1; | |||
| 749 | attrs.colormap = XCreateColormap (dpy, DefaultRootWindow (dpy)((&((_XPrivDisplay)(dpy))->screens[(((_XPrivDisplay)(dpy ))->default_screen)])->root), xvisinfo->visual, AllocNone0); | |||
| 750 | attrs.border_pixel = 0; | |||
| 751 | mask = CWOverrideRedirect(1L<<9) | CWColormap(1L<<13) | CWBorderPixel(1L<<3); | |||
| 752 | info->dummy_xwin = XCreateWindow (dpy, DefaultRootWindow (dpy)((&((_XPrivDisplay)(dpy))->screens[(((_XPrivDisplay)(dpy ))->default_screen)])->root), | |||
| 753 | -100, -100, 1, 1, | |||
| 754 | 0, | |||
| 755 | xvisinfo->depth, | |||
| 756 | CopyFromParent0L, | |||
| 757 | xvisinfo->visual, | |||
| 758 | mask, | |||
| 759 | &attrs); | |||
| 760 | XMapWindow(dpy, info->dummy_xwin); | |||
| 761 | ||||
| 762 | if (CDK_X11_DISPLAY (display)((((CdkX11Display*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((display)), ((cdk_x11_display_get_type()))))))->glx_version >= 13) | |||
| 763 | { | |||
| 764 | info->glx_drawable = glXCreateWindowepoxy_glXCreateWindow (dpy, context_x11->glx_config, | |||
| 765 | cdk_x11_window_get_xid (window->impl_window), | |||
| 766 | NULL((void*)0)); | |||
| 767 | info->dummy_glx = glXCreateWindowepoxy_glXCreateWindow (dpy, context_x11->glx_config, info->dummy_xwin, NULL((void*)0)); | |||
| 768 | } | |||
| 769 | ||||
| 770 | if (cdk_x11_display_error_trap_pop (display)) | |||
| 771 | { | |||
| 772 | g_set_error_literal (error, CDK_GL_ERROR(cdk_gl_error_quark ()), | |||
| 773 | CDK_GL_ERROR_NOT_AVAILABLE, | |||
| 774 | _("Unable to create a GL context")((char *) g_dgettext ("ctk30", "Unable to create a GL context" ))); | |||
| 775 | ||||
| 776 | XFree (xvisinfo); | |||
| 777 | drawable_info_free (info); | |||
| 778 | glXDestroyContextepoxy_glXDestroyContext (dpy, context_x11->glx_context); | |||
| 779 | context_x11->glx_context = NULL((void*)0); | |||
| 780 | ||||
| 781 | return FALSE(0); | |||
| 782 | } | |||
| 783 | ||||
| 784 | set_glx_drawable_info (window->impl_window, info); | |||
| 785 | } | |||
| 786 | ||||
| 787 | XFree (xvisinfo); | |||
| 788 | ||||
| 789 | if (context_x11->is_attached) | |||
| 790 | drawable = info->glx_drawable ? info->glx_drawable : cdk_x11_window_get_xid (window->impl_window); | |||
| 791 | else | |||
| 792 | drawable = info->dummy_glx ? info->dummy_glx : info->dummy_xwin; | |||
| 793 | ||||
| 794 | context_x11->is_direct = glXIsDirectepoxy_glXIsDirect (dpy, context_x11->glx_context); | |||
| 795 | context_x11->drawable = drawable; | |||
| 796 | ||||
| 797 | CDK_NOTE (OPENGL,do { if ((_cdk_debug_flags & CDK_DEBUG_OPENGL)) { g_message ("Realized GLX context[%p], %s", context_x11->glx_context , context_x11->is_direct ? "direct" : "indirect"); }; } while (0) | |||
| 798 | g_message ("Realized GLX context[%p], %s",do { if ((_cdk_debug_flags & CDK_DEBUG_OPENGL)) { g_message ("Realized GLX context[%p], %s", context_x11->glx_context , context_x11->is_direct ? "direct" : "indirect"); }; } while (0) | |||
| 799 | context_x11->glx_context,do { if ((_cdk_debug_flags & CDK_DEBUG_OPENGL)) { g_message ("Realized GLX context[%p], %s", context_x11->glx_context , context_x11->is_direct ? "direct" : "indirect"); }; } while (0) | |||
| 800 | context_x11->is_direct ? "direct" : "indirect"))do { if ((_cdk_debug_flags & CDK_DEBUG_OPENGL)) { g_message ("Realized GLX context[%p], %s", context_x11->glx_context , context_x11->is_direct ? "direct" : "indirect"); }; } while (0); | |||
| 801 | ||||
| 802 | return TRUE(!(0)); | |||
| 803 | } | |||
| 804 | ||||
| 805 | static void | |||
| 806 | cdk_x11_gl_context_dispose (GObject *gobject) | |||
| 807 | { | |||
| 808 | CdkX11GLContext *context_x11 = CDK_X11_GL_CONTEXT (gobject)((((CdkX11GLContext*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((gobject)), ((cdk_x11_gl_context_get_type ())))))); | |||
| 809 | ||||
| 810 | if (context_x11->glx_context != NULL((void*)0)) | |||
| 811 | { | |||
| 812 | CdkGLContext *context = CDK_GL_CONTEXT (gobject)((((CdkGLContext*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((gobject)), ((cdk_gl_context_get_type ())))))); | |||
| 813 | CdkDisplay *display = cdk_gl_context_get_display (context); | |||
| 814 | Display *dpy = cdk_x11_display_get_xdisplay (display); | |||
| 815 | ||||
| 816 | if (glXGetCurrentContextepoxy_glXGetCurrentContext () == context_x11->glx_context) | |||
| 817 | glXMakeContextCurrentepoxy_glXMakeContextCurrent (dpy, None0L, None0L, NULL((void*)0)); | |||
| 818 | ||||
| 819 | CDK_NOTE (OPENGL, g_message ("Destroying GLX context"))do { if ((_cdk_debug_flags & CDK_DEBUG_OPENGL)) { g_message ("Destroying GLX context"); }; } while (0); | |||
| 820 | glXDestroyContextepoxy_glXDestroyContext (dpy, context_x11->glx_context); | |||
| 821 | context_x11->glx_context = NULL((void*)0); | |||
| 822 | } | |||
| 823 | ||||
| 824 | G_OBJECT_CLASS (cdk_x11_gl_context_parent_class)((((GObjectClass*) (void *) g_type_check_class_cast ((GTypeClass *) ((cdk_x11_gl_context_parent_class)), (((GType) ((20) << (2))))))))->dispose (gobject); | |||
| 825 | } | |||
| 826 | ||||
| 827 | static void | |||
| 828 | cdk_x11_gl_context_class_init (CdkX11GLContextClass *klass) | |||
| 829 | { | |||
| 830 | CdkGLContextClass *context_class = CDK_GL_CONTEXT_CLASS (klass)((((CdkGLContextClass*) (void *) g_type_check_class_cast ((GTypeClass *) ((klass)), ((cdk_gl_context_get_type ())))))); | |||
| 831 | GObjectClass *gobject_class = G_OBJECT_CLASS (klass)((((GObjectClass*) (void *) g_type_check_class_cast ((GTypeClass *) ((klass)), (((GType) ((20) << (2)))))))); | |||
| 832 | ||||
| 833 | context_class->realize = cdk_x11_gl_context_realize; | |||
| 834 | context_class->end_frame = cdk_x11_gl_context_end_frame; | |||
| 835 | context_class->texture_from_surface = cdk_x11_gl_context_texture_from_surface; | |||
| 836 | ||||
| 837 | gobject_class->dispose = cdk_x11_gl_context_dispose; | |||
| 838 | } | |||
| 839 | ||||
| 840 | static void | |||
| 841 | cdk_x11_gl_context_init (CdkX11GLContext *self) | |||
| 842 | { | |||
| 843 | self->do_frame_sync = TRUE(!(0)); | |||
| 844 | } | |||
| 845 | ||||
| 846 | gboolean | |||
| 847 | cdk_x11_screen_init_gl (CdkScreen *screen) | |||
| 848 | { | |||
| 849 | CdkDisplay *display = cdk_screen_get_display (screen); | |||
| 850 | CdkX11Display *display_x11 = CDK_X11_DISPLAY (display)((((CdkX11Display*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((display)), ((cdk_x11_display_get_type())))))); | |||
| 851 | Display *dpy; | |||
| 852 | int error_base, event_base; | |||
| 853 | int screen_num; | |||
| 854 | ||||
| 855 | if (display_x11->have_glx) | |||
| 856 | return TRUE(!(0)); | |||
| 857 | ||||
| 858 | if (_cdk_gl_flags & CDK_GL_DISABLE) | |||
| 859 | return FALSE(0); | |||
| 860 | ||||
| 861 | dpy = cdk_x11_display_get_xdisplay (display); | |||
| 862 | ||||
| 863 | if (!epoxy_has_glx (dpy)) | |||
| 864 | return FALSE(0); | |||
| 865 | ||||
| 866 | if (!glXQueryExtensionepoxy_glXQueryExtension (dpy, &error_base, &event_base)) | |||
| 867 | return FALSE(0); | |||
| 868 | ||||
| 869 | screen_num = CDK_X11_SCREEN (screen)((((CdkX11Screen*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((screen)), ((cdk_x11_screen_get_type ()))))))->screen_num; | |||
| 870 | ||||
| 871 | display_x11->have_glx = TRUE(!(0)); | |||
| 872 | ||||
| 873 | display_x11->glx_version = epoxy_glx_version (dpy, screen_num); | |||
| 874 | display_x11->glx_error_base = error_base; | |||
| 875 | display_x11->glx_event_base = event_base; | |||
| 876 | ||||
| 877 | display_x11->has_glx_create_context = | |||
| 878 | epoxy_has_glx_extension (dpy, screen_num, "GLX_ARB_create_context_profile"); | |||
| 879 | display_x11->has_glx_create_es2_context = | |||
| 880 | epoxy_has_glx_extension (dpy, screen_num, "GLX_EXT_create_context_es2_profile"); | |||
| 881 | display_x11->has_glx_swap_interval = | |||
| 882 | epoxy_has_glx_extension (dpy, screen_num, "GLX_SGI_swap_control"); | |||
| 883 | display_x11->has_glx_texture_from_pixmap = | |||
| 884 | epoxy_has_glx_extension (dpy, screen_num, "GLX_EXT_texture_from_pixmap"); | |||
| 885 | display_x11->has_glx_video_sync = | |||
| 886 | epoxy_has_glx_extension (dpy, screen_num, "GLX_SGI_video_sync"); | |||
| 887 | display_x11->has_glx_buffer_age = | |||
| 888 | epoxy_has_glx_extension (dpy, screen_num, "GLX_EXT_buffer_age"); | |||
| 889 | display_x11->has_glx_sync_control = | |||
| 890 | epoxy_has_glx_extension (dpy, screen_num, "GLX_OML_sync_control"); | |||
| 891 | display_x11->has_glx_multisample = | |||
| 892 | epoxy_has_glx_extension (dpy, screen_num, "GLX_ARB_multisample"); | |||
| 893 | display_x11->has_glx_visual_rating = | |||
| 894 | epoxy_has_glx_extension (dpy, screen_num, "GLX_EXT_visual_rating"); | |||
| 895 | ||||
| 896 | CDK_NOTE (OPENGL,do { if ((_cdk_debug_flags & CDK_DEBUG_OPENGL)) { g_message ("GLX version %d.%d found\n" " - Vendor: %s\n" " - Checked extensions:\n" "\t* GLX_ARB_create_context_profile: %s\n" "\t* GLX_EXT_create_context_es2_profile: %s\n" "\t* GLX_SGI_swap_control: %s\n" "\t* GLX_EXT_texture_from_pixmap: %s\n" "\t* GLX_SGI_video_sync: %s\n" "\t* GLX_EXT_buffer_age: %s\n" "\t* GLX_OML_sync_control: %s", display_x11->glx_version / 10, display_x11->glx_version % 10, epoxy_glXGetClientString (dpy, 0x1), display_x11->has_glx_create_context ? "yes" : "no", display_x11->has_glx_create_es2_context ? "yes" : "no" , display_x11->has_glx_swap_interval ? "yes" : "no", display_x11 ->has_glx_texture_from_pixmap ? "yes" : "no", display_x11-> has_glx_video_sync ? "yes" : "no", display_x11->has_glx_buffer_age ? "yes" : "no", display_x11->has_glx_sync_control ? "yes" : "no"); }; } while (0) | |||
| 897 | g_message ("GLX version %d.%d found\n"do { if ((_cdk_debug_flags & CDK_DEBUG_OPENGL)) { g_message ("GLX version %d.%d found\n" " - Vendor: %s\n" " - Checked extensions:\n" "\t* GLX_ARB_create_context_profile: %s\n" "\t* GLX_EXT_create_context_es2_profile: %s\n" "\t* GLX_SGI_swap_control: %s\n" "\t* GLX_EXT_texture_from_pixmap: %s\n" "\t* GLX_SGI_video_sync: %s\n" "\t* GLX_EXT_buffer_age: %s\n" "\t* GLX_OML_sync_control: %s", display_x11->glx_version / 10, display_x11->glx_version % 10, epoxy_glXGetClientString (dpy, 0x1), display_x11->has_glx_create_context ? "yes" : "no", display_x11->has_glx_create_es2_context ? "yes" : "no" , display_x11->has_glx_swap_interval ? "yes" : "no", display_x11 ->has_glx_texture_from_pixmap ? "yes" : "no", display_x11-> has_glx_video_sync ? "yes" : "no", display_x11->has_glx_buffer_age ? "yes" : "no", display_x11->has_glx_sync_control ? "yes" : "no"); }; } while (0) | |||
| 898 | " - Vendor: %s\n"do { if ((_cdk_debug_flags & CDK_DEBUG_OPENGL)) { g_message ("GLX version %d.%d found\n" " - Vendor: %s\n" " - Checked extensions:\n" "\t* GLX_ARB_create_context_profile: %s\n" "\t* GLX_EXT_create_context_es2_profile: %s\n" "\t* GLX_SGI_swap_control: %s\n" "\t* GLX_EXT_texture_from_pixmap: %s\n" "\t* GLX_SGI_video_sync: %s\n" "\t* GLX_EXT_buffer_age: %s\n" "\t* GLX_OML_sync_control: %s", display_x11->glx_version / 10, display_x11->glx_version % 10, epoxy_glXGetClientString (dpy, 0x1), display_x11->has_glx_create_context ? "yes" : "no", display_x11->has_glx_create_es2_context ? "yes" : "no" , display_x11->has_glx_swap_interval ? "yes" : "no", display_x11 ->has_glx_texture_from_pixmap ? "yes" : "no", display_x11-> has_glx_video_sync ? "yes" : "no", display_x11->has_glx_buffer_age ? "yes" : "no", display_x11->has_glx_sync_control ? "yes" : "no"); }; } while (0) | |||
| 899 | " - Checked extensions:\n"do { if ((_cdk_debug_flags & CDK_DEBUG_OPENGL)) { g_message ("GLX version %d.%d found\n" " - Vendor: %s\n" " - Checked extensions:\n" "\t* GLX_ARB_create_context_profile: %s\n" "\t* GLX_EXT_create_context_es2_profile: %s\n" "\t* GLX_SGI_swap_control: %s\n" "\t* GLX_EXT_texture_from_pixmap: %s\n" "\t* GLX_SGI_video_sync: %s\n" "\t* GLX_EXT_buffer_age: %s\n" "\t* GLX_OML_sync_control: %s", display_x11->glx_version / 10, display_x11->glx_version % 10, epoxy_glXGetClientString (dpy, 0x1), display_x11->has_glx_create_context ? "yes" : "no", display_x11->has_glx_create_es2_context ? "yes" : "no" , display_x11->has_glx_swap_interval ? "yes" : "no", display_x11 ->has_glx_texture_from_pixmap ? "yes" : "no", display_x11-> has_glx_video_sync ? "yes" : "no", display_x11->has_glx_buffer_age ? "yes" : "no", display_x11->has_glx_sync_control ? "yes" : "no"); }; } while (0) | |||
| 900 | "\t* GLX_ARB_create_context_profile: %s\n"do { if ((_cdk_debug_flags & CDK_DEBUG_OPENGL)) { g_message ("GLX version %d.%d found\n" " - Vendor: %s\n" " - Checked extensions:\n" "\t* GLX_ARB_create_context_profile: %s\n" "\t* GLX_EXT_create_context_es2_profile: %s\n" "\t* GLX_SGI_swap_control: %s\n" "\t* GLX_EXT_texture_from_pixmap: %s\n" "\t* GLX_SGI_video_sync: %s\n" "\t* GLX_EXT_buffer_age: %s\n" "\t* GLX_OML_sync_control: %s", display_x11->glx_version / 10, display_x11->glx_version % 10, epoxy_glXGetClientString (dpy, 0x1), display_x11->has_glx_create_context ? "yes" : "no", display_x11->has_glx_create_es2_context ? "yes" : "no" , display_x11->has_glx_swap_interval ? "yes" : "no", display_x11 ->has_glx_texture_from_pixmap ? "yes" : "no", display_x11-> has_glx_video_sync ? "yes" : "no", display_x11->has_glx_buffer_age ? "yes" : "no", display_x11->has_glx_sync_control ? "yes" : "no"); }; } while (0) | |||
| 901 | "\t* GLX_EXT_create_context_es2_profile: %s\n"do { if ((_cdk_debug_flags & CDK_DEBUG_OPENGL)) { g_message ("GLX version %d.%d found\n" " - Vendor: %s\n" " - Checked extensions:\n" "\t* GLX_ARB_create_context_profile: %s\n" "\t* GLX_EXT_create_context_es2_profile: %s\n" "\t* GLX_SGI_swap_control: %s\n" "\t* GLX_EXT_texture_from_pixmap: %s\n" "\t* GLX_SGI_video_sync: %s\n" "\t* GLX_EXT_buffer_age: %s\n" "\t* GLX_OML_sync_control: %s", display_x11->glx_version / 10, display_x11->glx_version % 10, epoxy_glXGetClientString (dpy, 0x1), display_x11->has_glx_create_context ? "yes" : "no", display_x11->has_glx_create_es2_context ? "yes" : "no" , display_x11->has_glx_swap_interval ? "yes" : "no", display_x11 ->has_glx_texture_from_pixmap ? "yes" : "no", display_x11-> has_glx_video_sync ? "yes" : "no", display_x11->has_glx_buffer_age ? "yes" : "no", display_x11->has_glx_sync_control ? "yes" : "no"); }; } while (0) | |||
| 902 | "\t* GLX_SGI_swap_control: %s\n"do { if ((_cdk_debug_flags & CDK_DEBUG_OPENGL)) { g_message ("GLX version %d.%d found\n" " - Vendor: %s\n" " - Checked extensions:\n" "\t* GLX_ARB_create_context_profile: %s\n" "\t* GLX_EXT_create_context_es2_profile: %s\n" "\t* GLX_SGI_swap_control: %s\n" "\t* GLX_EXT_texture_from_pixmap: %s\n" "\t* GLX_SGI_video_sync: %s\n" "\t* GLX_EXT_buffer_age: %s\n" "\t* GLX_OML_sync_control: %s", display_x11->glx_version / 10, display_x11->glx_version % 10, epoxy_glXGetClientString (dpy, 0x1), display_x11->has_glx_create_context ? "yes" : "no", display_x11->has_glx_create_es2_context ? "yes" : "no" , display_x11->has_glx_swap_interval ? "yes" : "no", display_x11 ->has_glx_texture_from_pixmap ? "yes" : "no", display_x11-> has_glx_video_sync ? "yes" : "no", display_x11->has_glx_buffer_age ? "yes" : "no", display_x11->has_glx_sync_control ? "yes" : "no"); }; } while (0) | |||
| 903 | "\t* GLX_EXT_texture_from_pixmap: %s\n"do { if ((_cdk_debug_flags & CDK_DEBUG_OPENGL)) { g_message ("GLX version %d.%d found\n" " - Vendor: %s\n" " - Checked extensions:\n" "\t* GLX_ARB_create_context_profile: %s\n" "\t* GLX_EXT_create_context_es2_profile: %s\n" "\t* GLX_SGI_swap_control: %s\n" "\t* GLX_EXT_texture_from_pixmap: %s\n" "\t* GLX_SGI_video_sync: %s\n" "\t* GLX_EXT_buffer_age: %s\n" "\t* GLX_OML_sync_control: %s", display_x11->glx_version / 10, display_x11->glx_version % 10, epoxy_glXGetClientString (dpy, 0x1), display_x11->has_glx_create_context ? "yes" : "no", display_x11->has_glx_create_es2_context ? "yes" : "no" , display_x11->has_glx_swap_interval ? "yes" : "no", display_x11 ->has_glx_texture_from_pixmap ? "yes" : "no", display_x11-> has_glx_video_sync ? "yes" : "no", display_x11->has_glx_buffer_age ? "yes" : "no", display_x11->has_glx_sync_control ? "yes" : "no"); }; } while (0) | |||
| 904 | "\t* GLX_SGI_video_sync: %s\n"do { if ((_cdk_debug_flags & CDK_DEBUG_OPENGL)) { g_message ("GLX version %d.%d found\n" " - Vendor: %s\n" " - Checked extensions:\n" "\t* GLX_ARB_create_context_profile: %s\n" "\t* GLX_EXT_create_context_es2_profile: %s\n" "\t* GLX_SGI_swap_control: %s\n" "\t* GLX_EXT_texture_from_pixmap: %s\n" "\t* GLX_SGI_video_sync: %s\n" "\t* GLX_EXT_buffer_age: %s\n" "\t* GLX_OML_sync_control: %s", display_x11->glx_version / 10, display_x11->glx_version % 10, epoxy_glXGetClientString (dpy, 0x1), display_x11->has_glx_create_context ? "yes" : "no", display_x11->has_glx_create_es2_context ? "yes" : "no" , display_x11->has_glx_swap_interval ? "yes" : "no", display_x11 ->has_glx_texture_from_pixmap ? "yes" : "no", display_x11-> has_glx_video_sync ? "yes" : "no", display_x11->has_glx_buffer_age ? "yes" : "no", display_x11->has_glx_sync_control ? "yes" : "no"); }; } while (0) | |||
| 905 | "\t* GLX_EXT_buffer_age: %s\n"do { if ((_cdk_debug_flags & CDK_DEBUG_OPENGL)) { g_message ("GLX version %d.%d found\n" " - Vendor: %s\n" " - Checked extensions:\n" "\t* GLX_ARB_create_context_profile: %s\n" "\t* GLX_EXT_create_context_es2_profile: %s\n" "\t* GLX_SGI_swap_control: %s\n" "\t* GLX_EXT_texture_from_pixmap: %s\n" "\t* GLX_SGI_video_sync: %s\n" "\t* GLX_EXT_buffer_age: %s\n" "\t* GLX_OML_sync_control: %s", display_x11->glx_version / 10, display_x11->glx_version % 10, epoxy_glXGetClientString (dpy, 0x1), display_x11->has_glx_create_context ? "yes" : "no", display_x11->has_glx_create_es2_context ? "yes" : "no" , display_x11->has_glx_swap_interval ? "yes" : "no", display_x11 ->has_glx_texture_from_pixmap ? "yes" : "no", display_x11-> has_glx_video_sync ? "yes" : "no", display_x11->has_glx_buffer_age ? "yes" : "no", display_x11->has_glx_sync_control ? "yes" : "no"); }; } while (0) | |||
| 906 | "\t* GLX_OML_sync_control: %s",do { if ((_cdk_debug_flags & CDK_DEBUG_OPENGL)) { g_message ("GLX version %d.%d found\n" " - Vendor: %s\n" " - Checked extensions:\n" "\t* GLX_ARB_create_context_profile: %s\n" "\t* GLX_EXT_create_context_es2_profile: %s\n" "\t* GLX_SGI_swap_control: %s\n" "\t* GLX_EXT_texture_from_pixmap: %s\n" "\t* GLX_SGI_video_sync: %s\n" "\t* GLX_EXT_buffer_age: %s\n" "\t* GLX_OML_sync_control: %s", display_x11->glx_version / 10, display_x11->glx_version % 10, epoxy_glXGetClientString (dpy, 0x1), display_x11->has_glx_create_context ? "yes" : "no", display_x11->has_glx_create_es2_context ? "yes" : "no" , display_x11->has_glx_swap_interval ? "yes" : "no", display_x11 ->has_glx_texture_from_pixmap ? "yes" : "no", display_x11-> has_glx_video_sync ? "yes" : "no", display_x11->has_glx_buffer_age ? "yes" : "no", display_x11->has_glx_sync_control ? "yes" : "no"); }; } while (0) | |||
| 907 | display_x11->glx_version / 10,do { if ((_cdk_debug_flags & CDK_DEBUG_OPENGL)) { g_message ("GLX version %d.%d found\n" " - Vendor: %s\n" " - Checked extensions:\n" "\t* GLX_ARB_create_context_profile: %s\n" "\t* GLX_EXT_create_context_es2_profile: %s\n" "\t* GLX_SGI_swap_control: %s\n" "\t* GLX_EXT_texture_from_pixmap: %s\n" "\t* GLX_SGI_video_sync: %s\n" "\t* GLX_EXT_buffer_age: %s\n" "\t* GLX_OML_sync_control: %s", display_x11->glx_version / 10, display_x11->glx_version % 10, epoxy_glXGetClientString (dpy, 0x1), display_x11->has_glx_create_context ? "yes" : "no", display_x11->has_glx_create_es2_context ? "yes" : "no" , display_x11->has_glx_swap_interval ? "yes" : "no", display_x11 ->has_glx_texture_from_pixmap ? "yes" : "no", display_x11-> has_glx_video_sync ? "yes" : "no", display_x11->has_glx_buffer_age ? "yes" : "no", display_x11->has_glx_sync_control ? "yes" : "no"); }; } while (0) | |||
| 908 | display_x11->glx_version % 10,do { if ((_cdk_debug_flags & CDK_DEBUG_OPENGL)) { g_message ("GLX version %d.%d found\n" " - Vendor: %s\n" " - Checked extensions:\n" "\t* GLX_ARB_create_context_profile: %s\n" "\t* GLX_EXT_create_context_es2_profile: %s\n" "\t* GLX_SGI_swap_control: %s\n" "\t* GLX_EXT_texture_from_pixmap: %s\n" "\t* GLX_SGI_video_sync: %s\n" "\t* GLX_EXT_buffer_age: %s\n" "\t* GLX_OML_sync_control: %s", display_x11->glx_version / 10, display_x11->glx_version % 10, epoxy_glXGetClientString (dpy, 0x1), display_x11->has_glx_create_context ? "yes" : "no", display_x11->has_glx_create_es2_context ? "yes" : "no" , display_x11->has_glx_swap_interval ? "yes" : "no", display_x11 ->has_glx_texture_from_pixmap ? "yes" : "no", display_x11-> has_glx_video_sync ? "yes" : "no", display_x11->has_glx_buffer_age ? "yes" : "no", display_x11->has_glx_sync_control ? "yes" : "no"); }; } while (0) | |||
| 909 | glXGetClientString (dpy, GLX_VENDOR),do { if ((_cdk_debug_flags & CDK_DEBUG_OPENGL)) { g_message ("GLX version %d.%d found\n" " - Vendor: %s\n" " - Checked extensions:\n" "\t* GLX_ARB_create_context_profile: %s\n" "\t* GLX_EXT_create_context_es2_profile: %s\n" "\t* GLX_SGI_swap_control: %s\n" "\t* GLX_EXT_texture_from_pixmap: %s\n" "\t* GLX_SGI_video_sync: %s\n" "\t* GLX_EXT_buffer_age: %s\n" "\t* GLX_OML_sync_control: %s", display_x11->glx_version / 10, display_x11->glx_version % 10, epoxy_glXGetClientString (dpy, 0x1), display_x11->has_glx_create_context ? "yes" : "no", display_x11->has_glx_create_es2_context ? "yes" : "no" , display_x11->has_glx_swap_interval ? "yes" : "no", display_x11 ->has_glx_texture_from_pixmap ? "yes" : "no", display_x11-> has_glx_video_sync ? "yes" : "no", display_x11->has_glx_buffer_age ? "yes" : "no", display_x11->has_glx_sync_control ? "yes" : "no"); }; } while (0) | |||
| 910 | display_x11->has_glx_create_context ? "yes" : "no",do { if ((_cdk_debug_flags & CDK_DEBUG_OPENGL)) { g_message ("GLX version %d.%d found\n" " - Vendor: %s\n" " - Checked extensions:\n" "\t* GLX_ARB_create_context_profile: %s\n" "\t* GLX_EXT_create_context_es2_profile: %s\n" "\t* GLX_SGI_swap_control: %s\n" "\t* GLX_EXT_texture_from_pixmap: %s\n" "\t* GLX_SGI_video_sync: %s\n" "\t* GLX_EXT_buffer_age: %s\n" "\t* GLX_OML_sync_control: %s", display_x11->glx_version / 10, display_x11->glx_version % 10, epoxy_glXGetClientString (dpy, 0x1), display_x11->has_glx_create_context ? "yes" : "no", display_x11->has_glx_create_es2_context ? "yes" : "no" , display_x11->has_glx_swap_interval ? "yes" : "no", display_x11 ->has_glx_texture_from_pixmap ? "yes" : "no", display_x11-> has_glx_video_sync ? "yes" : "no", display_x11->has_glx_buffer_age ? "yes" : "no", display_x11->has_glx_sync_control ? "yes" : "no"); }; } while (0) | |||
| 911 | display_x11->has_glx_create_es2_context ? "yes" : "no",do { if ((_cdk_debug_flags & CDK_DEBUG_OPENGL)) { g_message ("GLX version %d.%d found\n" " - Vendor: %s\n" " - Checked extensions:\n" "\t* GLX_ARB_create_context_profile: %s\n" "\t* GLX_EXT_create_context_es2_profile: %s\n" "\t* GLX_SGI_swap_control: %s\n" "\t* GLX_EXT_texture_from_pixmap: %s\n" "\t* GLX_SGI_video_sync: %s\n" "\t* GLX_EXT_buffer_age: %s\n" "\t* GLX_OML_sync_control: %s", display_x11->glx_version / 10, display_x11->glx_version % 10, epoxy_glXGetClientString (dpy, 0x1), display_x11->has_glx_create_context ? "yes" : "no", display_x11->has_glx_create_es2_context ? "yes" : "no" , display_x11->has_glx_swap_interval ? "yes" : "no", display_x11 ->has_glx_texture_from_pixmap ? "yes" : "no", display_x11-> has_glx_video_sync ? "yes" : "no", display_x11->has_glx_buffer_age ? "yes" : "no", display_x11->has_glx_sync_control ? "yes" : "no"); }; } while (0) | |||
| 912 | display_x11->has_glx_swap_interval ? "yes" : "no",do { if ((_cdk_debug_flags & CDK_DEBUG_OPENGL)) { g_message ("GLX version %d.%d found\n" " - Vendor: %s\n" " - Checked extensions:\n" "\t* GLX_ARB_create_context_profile: %s\n" "\t* GLX_EXT_create_context_es2_profile: %s\n" "\t* GLX_SGI_swap_control: %s\n" "\t* GLX_EXT_texture_from_pixmap: %s\n" "\t* GLX_SGI_video_sync: %s\n" "\t* GLX_EXT_buffer_age: %s\n" "\t* GLX_OML_sync_control: %s", display_x11->glx_version / 10, display_x11->glx_version % 10, epoxy_glXGetClientString (dpy, 0x1), display_x11->has_glx_create_context ? "yes" : "no", display_x11->has_glx_create_es2_context ? "yes" : "no" , display_x11->has_glx_swap_interval ? "yes" : "no", display_x11 ->has_glx_texture_from_pixmap ? "yes" : "no", display_x11-> has_glx_video_sync ? "yes" : "no", display_x11->has_glx_buffer_age ? "yes" : "no", display_x11->has_glx_sync_control ? "yes" : "no"); }; } while (0) | |||
| 913 | display_x11->has_glx_texture_from_pixmap ? "yes" : "no",do { if ((_cdk_debug_flags & CDK_DEBUG_OPENGL)) { g_message ("GLX version %d.%d found\n" " - Vendor: %s\n" " - Checked extensions:\n" "\t* GLX_ARB_create_context_profile: %s\n" "\t* GLX_EXT_create_context_es2_profile: %s\n" "\t* GLX_SGI_swap_control: %s\n" "\t* GLX_EXT_texture_from_pixmap: %s\n" "\t* GLX_SGI_video_sync: %s\n" "\t* GLX_EXT_buffer_age: %s\n" "\t* GLX_OML_sync_control: %s", display_x11->glx_version / 10, display_x11->glx_version % 10, epoxy_glXGetClientString (dpy, 0x1), display_x11->has_glx_create_context ? "yes" : "no", display_x11->has_glx_create_es2_context ? "yes" : "no" , display_x11->has_glx_swap_interval ? "yes" : "no", display_x11 ->has_glx_texture_from_pixmap ? "yes" : "no", display_x11-> has_glx_video_sync ? "yes" : "no", display_x11->has_glx_buffer_age ? "yes" : "no", display_x11->has_glx_sync_control ? "yes" : "no"); }; } while (0) | |||
| 914 | display_x11->has_glx_video_sync ? "yes" : "no",do { if ((_cdk_debug_flags & CDK_DEBUG_OPENGL)) { g_message ("GLX version %d.%d found\n" " - Vendor: %s\n" " - Checked extensions:\n" "\t* GLX_ARB_create_context_profile: %s\n" "\t* GLX_EXT_create_context_es2_profile: %s\n" "\t* GLX_SGI_swap_control: %s\n" "\t* GLX_EXT_texture_from_pixmap: %s\n" "\t* GLX_SGI_video_sync: %s\n" "\t* GLX_EXT_buffer_age: %s\n" "\t* GLX_OML_sync_control: %s", display_x11->glx_version / 10, display_x11->glx_version % 10, epoxy_glXGetClientString (dpy, 0x1), display_x11->has_glx_create_context ? "yes" : "no", display_x11->has_glx_create_es2_context ? "yes" : "no" , display_x11->has_glx_swap_interval ? "yes" : "no", display_x11 ->has_glx_texture_from_pixmap ? "yes" : "no", display_x11-> has_glx_video_sync ? "yes" : "no", display_x11->has_glx_buffer_age ? "yes" : "no", display_x11->has_glx_sync_control ? "yes" : "no"); }; } while (0) | |||
| 915 | display_x11->has_glx_buffer_age ? "yes" : "no",do { if ((_cdk_debug_flags & CDK_DEBUG_OPENGL)) { g_message ("GLX version %d.%d found\n" " - Vendor: %s\n" " - Checked extensions:\n" "\t* GLX_ARB_create_context_profile: %s\n" "\t* GLX_EXT_create_context_es2_profile: %s\n" "\t* GLX_SGI_swap_control: %s\n" "\t* GLX_EXT_texture_from_pixmap: %s\n" "\t* GLX_SGI_video_sync: %s\n" "\t* GLX_EXT_buffer_age: %s\n" "\t* GLX_OML_sync_control: %s", display_x11->glx_version / 10, display_x11->glx_version % 10, epoxy_glXGetClientString (dpy, 0x1), display_x11->has_glx_create_context ? "yes" : "no", display_x11->has_glx_create_es2_context ? "yes" : "no" , display_x11->has_glx_swap_interval ? "yes" : "no", display_x11 ->has_glx_texture_from_pixmap ? "yes" : "no", display_x11-> has_glx_video_sync ? "yes" : "no", display_x11->has_glx_buffer_age ? "yes" : "no", display_x11->has_glx_sync_control ? "yes" : "no"); }; } while (0) | |||
| 916 | display_x11->has_glx_sync_control ? "yes" : "no"))do { if ((_cdk_debug_flags & CDK_DEBUG_OPENGL)) { g_message ("GLX version %d.%d found\n" " - Vendor: %s\n" " - Checked extensions:\n" "\t* GLX_ARB_create_context_profile: %s\n" "\t* GLX_EXT_create_context_es2_profile: %s\n" "\t* GLX_SGI_swap_control: %s\n" "\t* GLX_EXT_texture_from_pixmap: %s\n" "\t* GLX_SGI_video_sync: %s\n" "\t* GLX_EXT_buffer_age: %s\n" "\t* GLX_OML_sync_control: %s", display_x11->glx_version / 10, display_x11->glx_version % 10, epoxy_glXGetClientString (dpy, 0x1), display_x11->has_glx_create_context ? "yes" : "no", display_x11->has_glx_create_es2_context ? "yes" : "no" , display_x11->has_glx_swap_interval ? "yes" : "no", display_x11 ->has_glx_texture_from_pixmap ? "yes" : "no", display_x11-> has_glx_video_sync ? "yes" : "no", display_x11->has_glx_buffer_age ? "yes" : "no", display_x11->has_glx_sync_control ? "yes" : "no"); }; } while (0); | |||
| 917 | ||||
| 918 | return TRUE(!(0)); | |||
| 919 | } | |||
| 920 | ||||
| 921 | #define MAX_GLX_ATTRS30 30 | |||
| 922 | ||||
| 923 | static gboolean | |||
| 924 | find_fbconfig_for_visual (CdkDisplay *display, | |||
| 925 | CdkVisual *visual, | |||
| 926 | GLXFBConfig *fb_config_out, | |||
| 927 | GError **error) | |||
| 928 | { | |||
| 929 | static int attrs[MAX_GLX_ATTRS30]; | |||
| 930 | Display *dpy = cdk_x11_display_get_xdisplay (display); | |||
| 931 | GLXFBConfig *configs; | |||
| 932 | int n_configs, i; | |||
| 933 | gboolean use_rgba; | |||
| 934 | gboolean retval = FALSE(0); | |||
| 935 | VisualID xvisual_id = XVisualIDFromVisual(cdk_x11_visual_get_xvisual (visual)); | |||
| 936 | ||||
| 937 | i = 0; | |||
| 938 | attrs[i++] = GLX_DRAWABLE_TYPE0x8010; | |||
| 939 | attrs[i++] = GLX_WINDOW_BIT0x00000001; | |||
| 940 | ||||
| 941 | attrs[i++] = GLX_RENDER_TYPE0x8011; | |||
| 942 | attrs[i++] = GLX_RGBA_BIT0x00000001; | |||
| 943 | ||||
| 944 | attrs[i++] = GLX_DOUBLEBUFFER5; | |||
| 945 | attrs[i++] = GL_TRUE1; | |||
| 946 | ||||
| 947 | attrs[i++] = GLX_RED_SIZE8; | |||
| 948 | attrs[i++] = 1; | |||
| 949 | attrs[i++] = GLX_GREEN_SIZE9; | |||
| 950 | attrs[i++] = 1; | |||
| 951 | attrs[i++] = GLX_BLUE_SIZE10; | |||
| 952 | attrs[i++] = 1; | |||
| 953 | ||||
| 954 | use_rgba = (visual == cdk_screen_get_rgba_visual (cdk_display_get_default_screen (display))); | |||
| 955 | if (use_rgba) | |||
| 956 | { | |||
| 957 | attrs[i++] = GLX_ALPHA_SIZE11; | |||
| 958 | attrs[i++] = 1; | |||
| 959 | } | |||
| 960 | else | |||
| 961 | { | |||
| 962 | attrs[i++] = GLX_ALPHA_SIZE11; | |||
| 963 | attrs[i++] = GLX_DONT_CARE0xFFFFFFFF; | |||
| 964 | } | |||
| 965 | ||||
| 966 | attrs[i++] = None0L; | |||
| 967 | ||||
| 968 | g_assert (i < MAX_GLX_ATTRS)do { if (i < 30) ; else g_assertion_message_expr ("Cdk", "cdkglcontext-x11.c" , 968, ((const char*) (__func__)), "i < MAX_GLX_ATTRS"); } while (0); | |||
| 969 | ||||
| 970 | configs = glXChooseFBConfigepoxy_glXChooseFBConfig (dpy, DefaultScreen (dpy)(((_XPrivDisplay)(dpy))->default_screen), attrs, &n_configs); | |||
| 971 | if (configs == NULL((void*)0) || n_configs == 0) | |||
| 972 | { | |||
| 973 | g_set_error_literal (error, CDK_GL_ERROR(cdk_gl_error_quark ()), | |||
| 974 | CDK_GL_ERROR_UNSUPPORTED_FORMAT, | |||
| 975 | _("No available configurations for the given pixel format")((char *) g_dgettext ("ctk30", "No available configurations for the given pixel format" ))); | |||
| 976 | return FALSE(0); | |||
| 977 | } | |||
| 978 | ||||
| 979 | for (i = 0; i < n_configs; i++) | |||
| 980 | { | |||
| 981 | XVisualInfo *visinfo; | |||
| 982 | ||||
| 983 | visinfo = glXGetVisualFromFBConfigepoxy_glXGetVisualFromFBConfig (dpy, configs[i]); | |||
| 984 | if (visinfo == NULL((void*)0)) | |||
| 985 | continue; | |||
| 986 | ||||
| 987 | if (visinfo->visualid != xvisual_id) | |||
| 988 | { | |||
| 989 | XFree (visinfo); | |||
| 990 | continue; | |||
| 991 | } | |||
| 992 | ||||
| 993 | if (fb_config_out != NULL((void*)0)) | |||
| 994 | *fb_config_out = configs[i]; | |||
| 995 | ||||
| 996 | XFree (visinfo); | |||
| 997 | retval = TRUE(!(0)); | |||
| 998 | goto out; | |||
| 999 | } | |||
| 1000 | ||||
| 1001 | g_set_error (error, CDK_GL_ERROR(cdk_gl_error_quark ()), | |||
| 1002 | CDK_GL_ERROR_UNSUPPORTED_FORMAT, | |||
| 1003 | _("No available configurations for the given RGBA pixel format")((char *) g_dgettext ("ctk30", "No available configurations for the given RGBA pixel format" ))); | |||
| 1004 | ||||
| 1005 | out: | |||
| 1006 | XFree (configs); | |||
| 1007 | ||||
| 1008 | return retval; | |||
| 1009 | } | |||
| 1010 | ||||
| 1011 | struct glvisualinfo { | |||
| 1012 | int supports_gl; | |||
| 1013 | int double_buffer; | |||
| 1014 | int stereo; | |||
| 1015 | int alpha_size; | |||
| 1016 | int depth_size; | |||
| 1017 | int stencil_size; | |||
| 1018 | int num_multisample; | |||
| 1019 | int visual_caveat; | |||
| 1020 | }; | |||
| 1021 | ||||
| 1022 | static gboolean | |||
| 1023 | visual_compatible (const CdkVisual *a, const CdkVisual *b) | |||
| 1024 | { | |||
| 1025 | return a->type == b->type && | |||
| 1026 | a->depth == b->depth && | |||
| 1027 | a->red_mask == b->red_mask && | |||
| 1028 | a->green_mask == b->green_mask && | |||
| 1029 | a->blue_mask == b->blue_mask && | |||
| 1030 | a->colormap_size == b->colormap_size && | |||
| 1031 | a->bits_per_rgb == b->bits_per_rgb; | |||
| 1032 | } | |||
| 1033 | ||||
| 1034 | static gboolean | |||
| 1035 | visual_is_rgba (const CdkVisual *visual) | |||
| 1036 | { | |||
| 1037 | return | |||
| 1038 | visual->depth == 32 && | |||
| 1039 | visual->red_mask == 0xff0000 && | |||
| 1040 | visual->green_mask == 0x00ff00 && | |||
| 1041 | visual->blue_mask == 0x0000ff; | |||
| 1042 | } | |||
| 1043 | ||||
| 1044 | /* This picks a compatible (as in has the same X visual details) visual | |||
| 1045 | that has "better" characteristics on the GL side */ | |||
| 1046 | static CdkVisual * | |||
| 1047 | pick_better_visual_for_gl (CdkX11Screen *x11_screen, | |||
| 1048 | struct glvisualinfo *gl_info, | |||
| 1049 | CdkVisual *compatible) | |||
| 1050 | { | |||
| 1051 | CdkVisual *visual; | |||
| 1052 | int i; | |||
| 1053 | gboolean want_alpha = visual_is_rgba (compatible); | |||
| 1054 | ||||
| 1055 | /* First look for "perfect match", i.e: | |||
| 1056 | * supports gl | |||
| 1057 | * double buffer | |||
| 1058 | * alpha iff visual is an rgba visual | |||
| 1059 | * no unnecessary stuff | |||
| 1060 | */ | |||
| 1061 | for (i = 0; i < x11_screen->nvisuals; i++) | |||
| 1062 | { | |||
| 1063 | visual = x11_screen->visuals[i]; | |||
| 1064 | if (visual_compatible (visual, compatible) && | |||
| 1065 | gl_info[i].supports_gl && | |||
| 1066 | gl_info[i].double_buffer && | |||
| 1067 | !gl_info[i].stereo && | |||
| 1068 | (want_alpha ? (gl_info[i].alpha_size > 0) : (gl_info[i].alpha_size == 0)) && | |||
| 1069 | (gl_info[i].depth_size == 0) && | |||
| 1070 | (gl_info[i].stencil_size == 0) && | |||
| 1071 | (gl_info[i].num_multisample == 0) && | |||
| 1072 | (gl_info[i].visual_caveat == GLX_NONE_EXT0x8000)) | |||
| 1073 | return visual; | |||
| 1074 | } | |||
| 1075 | ||||
| 1076 | if (!want_alpha) | |||
| 1077 | { | |||
| 1078 | /* Next, allow alpha even if we don't want it: */ | |||
| 1079 | for (i = 0; i < x11_screen->nvisuals; i++) | |||
| 1080 | { | |||
| 1081 | visual = x11_screen->visuals[i]; | |||
| 1082 | if (visual_compatible (visual, compatible) && | |||
| 1083 | gl_info[i].supports_gl && | |||
| 1084 | gl_info[i].double_buffer && | |||
| 1085 | !gl_info[i].stereo && | |||
| 1086 | (gl_info[i].depth_size == 0) && | |||
| 1087 | (gl_info[i].stencil_size == 0) && | |||
| 1088 | (gl_info[i].num_multisample == 0) && | |||
| 1089 | (gl_info[i].visual_caveat == GLX_NONE_EXT0x8000)) | |||
| 1090 | return visual; | |||
| 1091 | } | |||
| 1092 | } | |||
| 1093 | ||||
| 1094 | /* Next, allow depth and stencil buffers: */ | |||
| 1095 | for (i = 0; i < x11_screen->nvisuals; i++) | |||
| 1096 | { | |||
| 1097 | visual = x11_screen->visuals[i]; | |||
| 1098 | if (visual_compatible (visual, compatible) && | |||
| 1099 | gl_info[i].supports_gl && | |||
| 1100 | gl_info[i].double_buffer && | |||
| 1101 | !gl_info[i].stereo && | |||
| 1102 | (gl_info[i].num_multisample == 0) && | |||
| 1103 | (gl_info[i].visual_caveat == GLX_NONE_EXT0x8000)) | |||
| 1104 | return visual; | |||
| 1105 | } | |||
| 1106 | ||||
| 1107 | /* Next, allow multisample: */ | |||
| 1108 | for (i = 0; i < x11_screen->nvisuals; i++) | |||
| 1109 | { | |||
| 1110 | visual = x11_screen->visuals[i]; | |||
| 1111 | if (visual_compatible (visual, compatible) && | |||
| 1112 | gl_info[i].supports_gl && | |||
| 1113 | gl_info[i].double_buffer && | |||
| 1114 | !gl_info[i].stereo && | |||
| 1115 | (gl_info[i].visual_caveat == GLX_NONE_EXT0x8000)) | |||
| 1116 | return visual; | |||
| 1117 | } | |||
| 1118 | ||||
| 1119 | return compatible; | |||
| 1120 | } | |||
| 1121 | ||||
| 1122 | static gboolean | |||
| 1123 | get_cached_gl_visuals (CdkDisplay *display, int *system, int *rgba) | |||
| 1124 | { | |||
| 1125 | gboolean found; | |||
| 1126 | Atom type_return; | |||
| 1127 | gint format_return; | |||
| 1128 | gulong nitems_return; | |||
| 1129 | gulong bytes_after_return; | |||
| 1130 | guchar *data = NULL((void*)0); | |||
| 1131 | Display *dpy; | |||
| 1132 | ||||
| 1133 | dpy = cdk_x11_display_get_xdisplay (display); | |||
| 1134 | ||||
| 1135 | found = FALSE(0); | |||
| 1136 | ||||
| 1137 | cdk_x11_display_error_trap_push (display); | |||
| 1138 | if (XGetWindowProperty (dpy, DefaultRootWindow (dpy)((&((_XPrivDisplay)(dpy))->screens[(((_XPrivDisplay)(dpy ))->default_screen)])->root), | |||
| 1139 | cdk_x11_get_xatom_by_name_for_display (display, "CDK_VISUALS"), | |||
| 1140 | 0, 2, False0, XA_INTEGER((Atom) 19), &type_return, | |||
| 1141 | &format_return, &nitems_return, | |||
| 1142 | &bytes_after_return, &data) == Success0) | |||
| 1143 | { | |||
| 1144 | if (type_return == XA_INTEGER((Atom) 19) && | |||
| 1145 | format_return == 32 && | |||
| 1146 | nitems_return == 2 && | |||
| 1147 | data != NULL((void*)0)) | |||
| 1148 | { | |||
| 1149 | long *visuals = (long *) data; | |||
| 1150 | ||||
| 1151 | *system = (int)visuals[0]; | |||
| 1152 | *rgba = (int)visuals[1]; | |||
| 1153 | found = TRUE(!(0)); | |||
| 1154 | } | |||
| 1155 | } | |||
| 1156 | cdk_x11_display_error_trap_pop_ignored (display); | |||
| 1157 | ||||
| 1158 | if (data) | |||
| 1159 | XFree (data); | |||
| 1160 | ||||
| 1161 | return found; | |||
| 1162 | } | |||
| 1163 | ||||
| 1164 | static void | |||
| 1165 | save_cached_gl_visuals (CdkDisplay *display, int system, int rgba) | |||
| 1166 | { | |||
| 1167 | long visualdata[2]; | |||
| 1168 | Display *dpy; | |||
| 1169 | ||||
| 1170 | dpy = cdk_x11_display_get_xdisplay (display); | |||
| 1171 | ||||
| 1172 | visualdata[0] = system; | |||
| 1173 | visualdata[1] = rgba; | |||
| 1174 | ||||
| 1175 | cdk_x11_display_error_trap_push (display); | |||
| 1176 | XChangeProperty (dpy, DefaultRootWindow (dpy)((&((_XPrivDisplay)(dpy))->screens[(((_XPrivDisplay)(dpy ))->default_screen)])->root), | |||
| 1177 | cdk_x11_get_xatom_by_name_for_display (display, "CDK_VISUALS"), | |||
| 1178 | XA_INTEGER((Atom) 19), 32, PropModeReplace0, | |||
| 1179 | (unsigned char *)visualdata, 2); | |||
| 1180 | cdk_x11_display_error_trap_pop_ignored (display); | |||
| 1181 | } | |||
| 1182 | ||||
| 1183 | void | |||
| 1184 | _cdk_x11_screen_update_visuals_for_gl (CdkScreen *screen) | |||
| 1185 | { | |||
| 1186 | CdkX11Screen *x11_screen; | |||
| 1187 | CdkDisplay *display; | |||
| 1188 | CdkX11Display *display_x11; | |||
| 1189 | Display *dpy; | |||
| 1190 | struct glvisualinfo *gl_info; | |||
| 1191 | int i; | |||
| 1192 | int system_visual_id, rgba_visual_id; | |||
| 1193 | ||||
| 1194 | x11_screen = CDK_X11_SCREEN (screen)((((CdkX11Screen*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((screen)), ((cdk_x11_screen_get_type ())))))); | |||
| 1195 | display = x11_screen->display; | |||
| 1196 | display_x11 = CDK_X11_DISPLAY (display)((((CdkX11Display*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((display)), ((cdk_x11_display_get_type())))))); | |||
| 1197 | dpy = cdk_x11_display_get_xdisplay (display); | |||
| 1198 | ||||
| 1199 | /* We save the default visuals as a property on the root window to avoid | |||
| 1200 | having to initialize GL each time, as it may not be used later. */ | |||
| 1201 | if (get_cached_gl_visuals (display, &system_visual_id, &rgba_visual_id)) | |||
| 1202 | { | |||
| 1203 | for (i = 0; i < x11_screen->nvisuals; i++) | |||
| 1204 | { | |||
| 1205 | CdkVisual *visual = x11_screen->visuals[i]; | |||
| 1206 | int visual_id = cdk_x11_visual_get_xvisual (visual)->visualid; | |||
| 1207 | ||||
| 1208 | if (visual_id == system_visual_id) | |||
| 1209 | x11_screen->system_visual = visual; | |||
| 1210 | if (visual_id == rgba_visual_id) | |||
| 1211 | x11_screen->rgba_visual = visual; | |||
| 1212 | } | |||
| 1213 | ||||
| 1214 | return; | |||
| 1215 | } | |||
| 1216 | ||||
| 1217 | if (!cdk_x11_screen_init_gl (screen)) | |||
| 1218 | return; | |||
| 1219 | ||||
| 1220 | gl_info = g_new0 (struct glvisualinfo, x11_screen->nvisuals)((struct glvisualinfo *) g_malloc0_n ((x11_screen->nvisuals ), sizeof (struct glvisualinfo))); | |||
| 1221 | ||||
| 1222 | for (i = 0; i < x11_screen->nvisuals; i++) | |||
| 1223 | { | |||
| 1224 | XVisualInfo *visual_list; | |||
| 1225 | XVisualInfo visual_template; | |||
| 1226 | int nxvisuals; | |||
| 1227 | ||||
| 1228 | visual_template.screen = x11_screen->screen_num; | |||
| 1229 | visual_template.visualid = cdk_x11_visual_get_xvisual (x11_screen->visuals[i])->visualid; | |||
| 1230 | visual_list = XGetVisualInfo (x11_screen->xdisplay, VisualIDMask0x1| VisualScreenMask0x2, &visual_template, &nxvisuals); | |||
| 1231 | ||||
| 1232 | if (visual_list == NULL((void*)0)) | |||
| 1233 | continue; | |||
| 1234 | ||||
| 1235 | glXGetConfigepoxy_glXGetConfig (dpy, &visual_list[0], GLX_USE_GL1, &gl_info[i].supports_gl); | |||
| 1236 | glXGetConfigepoxy_glXGetConfig (dpy, &visual_list[0], GLX_DOUBLEBUFFER5, &gl_info[i].double_buffer); | |||
| 1237 | glXGetConfigepoxy_glXGetConfig (dpy, &visual_list[0], GLX_STEREO6, &gl_info[i].stereo); | |||
| 1238 | glXGetConfigepoxy_glXGetConfig (dpy, &visual_list[0], GLX_ALPHA_SIZE11, &gl_info[i].alpha_size); | |||
| 1239 | glXGetConfigepoxy_glXGetConfig (dpy, &visual_list[0], GLX_DEPTH_SIZE12, &gl_info[i].depth_size); | |||
| 1240 | glXGetConfigepoxy_glXGetConfig (dpy, &visual_list[0], GLX_STENCIL_SIZE13, &gl_info[i].stencil_size); | |||
| 1241 | ||||
| 1242 | if (display_x11->has_glx_multisample) | |||
| 1243 | glXGetConfigepoxy_glXGetConfig(dpy, &visual_list[0], GLX_SAMPLE_BUFFERS_ARB100000, &gl_info[i].num_multisample); | |||
| 1244 | ||||
| 1245 | if (display_x11->has_glx_visual_rating) | |||
| 1246 | glXGetConfigepoxy_glXGetConfig(dpy, &visual_list[0], GLX_VISUAL_CAVEAT_EXT0x20, &gl_info[i].visual_caveat); | |||
| 1247 | else | |||
| 1248 | gl_info[i].visual_caveat = GLX_NONE_EXT0x8000; | |||
| 1249 | ||||
| 1250 | XFree (visual_list); | |||
| 1251 | } | |||
| 1252 | ||||
| 1253 | x11_screen->system_visual = pick_better_visual_for_gl (x11_screen, gl_info, x11_screen->system_visual); | |||
| 1254 | if (x11_screen->rgba_visual) | |||
| 1255 | x11_screen->rgba_visual = pick_better_visual_for_gl (x11_screen, gl_info, x11_screen->rgba_visual); | |||
| 1256 | ||||
| 1257 | g_free (gl_info); | |||
| 1258 | ||||
| 1259 | save_cached_gl_visuals (display, | |||
| 1260 | cdk_x11_visual_get_xvisual (x11_screen->system_visual)->visualid, | |||
| 1261 | x11_screen->rgba_visual ? cdk_x11_visual_get_xvisual (x11_screen->rgba_visual)->visualid : 0); | |||
| 1262 | } | |||
| 1263 | ||||
| 1264 | CdkGLContext * | |||
| 1265 | cdk_x11_window_create_gl_context (CdkWindow *window, | |||
| 1266 | gboolean attached, | |||
| 1267 | CdkGLContext *share, | |||
| 1268 | GError **error) | |||
| 1269 | { | |||
| 1270 | CdkDisplay *display; | |||
| 1271 | CdkX11GLContext *context; | |||
| 1272 | CdkVisual *visual; | |||
| 1273 | GLXFBConfig config; | |||
| 1274 | ||||
| 1275 | display = cdk_window_get_display (window); | |||
| 1276 | ||||
| 1277 | if (!cdk_x11_screen_init_gl (cdk_window_get_screen (window))) | |||
| 1278 | { | |||
| 1279 | g_set_error_literal (error, CDK_GL_ERROR(cdk_gl_error_quark ()), | |||
| 1280 | CDK_GL_ERROR_NOT_AVAILABLE, | |||
| 1281 | _("No GL implementation is available")((char *) g_dgettext ("ctk30", "No GL implementation is available" ))); | |||
| 1282 | return NULL((void*)0); | |||
| 1283 | } | |||
| 1284 | ||||
| 1285 | visual = cdk_window_get_visual (window); | |||
| 1286 | if (!find_fbconfig_for_visual (display, visual, &config, error)) | |||
| 1287 | return NULL((void*)0); | |||
| 1288 | ||||
| 1289 | context = g_object_new (CDK_TYPE_X11_GL_CONTEXT(cdk_x11_gl_context_get_type ()), | |||
| 1290 | "display", display, | |||
| 1291 | "window", window, | |||
| 1292 | "shared-context", share, | |||
| 1293 | NULL((void*)0)); | |||
| 1294 | ||||
| 1295 | context->glx_config = config; | |||
| 1296 | context->is_attached = attached; | |||
| 1297 | ||||
| 1298 | return CDK_GL_CONTEXT (context)((((CdkGLContext*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((context)), ((cdk_gl_context_get_type ())))))); | |||
| 1299 | } | |||
| 1300 | ||||
| 1301 | gboolean | |||
| 1302 | cdk_x11_display_make_gl_context_current (CdkDisplay *display, | |||
| 1303 | CdkGLContext *context) | |||
| 1304 | { | |||
| 1305 | CdkX11GLContext *context_x11; | |||
| 1306 | Display *dpy = cdk_x11_display_get_xdisplay (display); | |||
| 1307 | gboolean do_frame_sync = FALSE(0); | |||
| 1308 | ||||
| 1309 | if (context == NULL((void*)0)) | |||
| 1310 | { | |||
| 1311 | glXMakeContextCurrentepoxy_glXMakeContextCurrent (dpy, None0L, None0L, NULL((void*)0)); | |||
| 1312 | return TRUE(!(0)); | |||
| 1313 | } | |||
| 1314 | ||||
| 1315 | context_x11 = CDK_X11_GL_CONTEXT (context)((((CdkX11GLContext*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((context)), ((cdk_x11_gl_context_get_type ())))))); | |||
| 1316 | if (context_x11->glx_context == NULL((void*)0)) | |||
| 1317 | { | |||
| 1318 | g_critical ("No GLX context associated to the CdkGLContext; you must " | |||
| 1319 | "call cdk_gl_context_realize() first."); | |||
| 1320 | return FALSE(0); | |||
| 1321 | } | |||
| 1322 | ||||
| 1323 | CDK_NOTE (OPENGL,do { if ((_cdk_debug_flags & CDK_DEBUG_OPENGL)) { g_message ("Making GLX context current to drawable %lu", (unsigned long ) context_x11->drawable); }; } while (0) | |||
| 1324 | g_message ("Making GLX context current to drawable %lu",do { if ((_cdk_debug_flags & CDK_DEBUG_OPENGL)) { g_message ("Making GLX context current to drawable %lu", (unsigned long ) context_x11->drawable); }; } while (0) | |||
| 1325 | (unsigned long) context_x11->drawable))do { if ((_cdk_debug_flags & CDK_DEBUG_OPENGL)) { g_message ("Making GLX context current to drawable %lu", (unsigned long ) context_x11->drawable); }; } while (0); | |||
| 1326 | ||||
| 1327 | if (!glXMakeContextCurrentepoxy_glXMakeContextCurrent (dpy, context_x11->drawable, context_x11->drawable, | |||
| 1328 | context_x11->glx_context)) | |||
| 1329 | { | |||
| 1330 | CDK_NOTE (OPENGL,do { if ((_cdk_debug_flags & CDK_DEBUG_OPENGL)) { g_message ("Making GLX context current failed"); }; } while (0) | |||
| 1331 | g_message ("Making GLX context current failed"))do { if ((_cdk_debug_flags & CDK_DEBUG_OPENGL)) { g_message ("Making GLX context current failed"); }; } while (0); | |||
| 1332 | return FALSE(0); | |||
| 1333 | } | |||
| 1334 | ||||
| 1335 | if (context_x11->is_attached && CDK_X11_DISPLAY (display)((((CdkX11Display*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((display)), ((cdk_x11_display_get_type()))))))->has_glx_swap_interval) | |||
| 1336 | { | |||
| 1337 | CdkWindow *window; | |||
| 1338 | CdkScreen *screen; | |||
| 1339 | ||||
| 1340 | window = cdk_gl_context_get_window (context); | |||
| 1341 | ||||
| 1342 | /* If the WM is compositing there is no particular need to delay | |||
| 1343 | * the swap when drawing on the offscreen, rendering to the screen | |||
| 1344 | * happens later anyway, and its up to the compositor to sync that | |||
| 1345 | * to the vblank. */ | |||
| 1346 | screen = cdk_window_get_screen (window); | |||
| 1347 | do_frame_sync = ! cdk_screen_is_composited (screen); | |||
| 1348 | ||||
| 1349 | if (do_frame_sync != context_x11->do_frame_sync) | |||
| 1350 | { | |||
| 1351 | context_x11->do_frame_sync = do_frame_sync; | |||
| 1352 | ||||
| 1353 | if (do_frame_sync) | |||
| 1354 | glXSwapIntervalSGIepoxy_glXSwapIntervalSGI (1); | |||
| 1355 | else | |||
| 1356 | glXSwapIntervalSGIepoxy_glXSwapIntervalSGI (0); | |||
| 1357 | } | |||
| 1358 | } | |||
| 1359 | ||||
| 1360 | return TRUE(!(0)); | |||
| 1361 | } | |||
| 1362 | ||||
| 1363 | /** | |||
| 1364 | * cdk_x11_display_get_glx_version: | |||
| 1365 | * @display: a #CdkDisplay | |||
| 1366 | * @major: (out): return location for the GLX major version | |||
| 1367 | * @minor: (out): return location for the GLX minor version | |||
| 1368 | * | |||
| 1369 | * Retrieves the version of the GLX implementation. | |||
| 1370 | * | |||
| 1371 | * Returns: %TRUE if GLX is available | |||
| 1372 | * | |||
| 1373 | * Since: 3.16 | |||
| 1374 | */ | |||
| 1375 | gboolean | |||
| 1376 | cdk_x11_display_get_glx_version (CdkDisplay *display, | |||
| 1377 | gint *major, | |||
| 1378 | gint *minor) | |||
| 1379 | { | |||
| 1380 | g_return_val_if_fail (CDK_IS_DISPLAY (display), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((display)); GType __t = ((cdk_display_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Cdk", ((const char*) (__func__ )), "CDK_IS_DISPLAY (display)"); return ((0)); } } while (0); | |||
| 1381 | ||||
| 1382 | if (!CDK_IS_X11_DISPLAY (display)(((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) ( (display)); GType __t = ((cdk_x11_display_get_type())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; }))))) | |||
| 1383 | return FALSE(0); | |||
| 1384 | ||||
| 1385 | if (!cdk_x11_screen_init_gl (cdk_display_get_default_screen (display))) | |||
| 1386 | return FALSE(0); | |||
| 1387 | ||||
| 1388 | if (major != NULL((void*)0)) | |||
| 1389 | *major = CDK_X11_DISPLAY (display)((((CdkX11Display*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((display)), ((cdk_x11_display_get_type()))))))->glx_version / 10; | |||
| 1390 | if (minor != NULL((void*)0)) | |||
| 1391 | *minor = CDK_X11_DISPLAY (display)((((CdkX11Display*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((display)), ((cdk_x11_display_get_type()))))))->glx_version % 10; | |||
| 1392 | ||||
| 1393 | return TRUE(!(0)); | |||
| 1394 | } |