"Initial commit to Gerrit"
[profile/ivi/cogl.git] / cogl / cogl-xlib.c
1 /*
2  * Cogl
3  *
4  * An object oriented GL/GLES Abstraction/Utility Layer
5  *
6  * Copyright (C) 2010,2011 Intel Corporation.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  *
23  * Authors:
24  *  Robert Bragg <robert@linux.intel.com>
25  *
26  */
27
28 #ifdef HAVE_CONFIG_H
29 #include "config.h"
30 #endif
31
32 #include <cogl-xlib.h>
33
34 #include <cogl-internal.h>
35 #include <cogl-handle.h>
36 #include <cogl-context-private.h>
37 #include <cogl-framebuffer-private.h>
38 #include <cogl-display-private.h>
39 #include <cogl-renderer-private.h>
40 #include <cogl-xlib-renderer-private.h>
41
42 #include <X11/Xlib.h>
43 #include <X11/extensions/Xdamage.h>
44
45 #include "cogl-xlib.h"
46
47 /* FIXME: when we remove the last X11 based Clutter backend then we
48  * will get rid of these functions and instead rely on the equivalent
49  * _cogl_xlib_renderer API
50  */
51
52 /* This can't be in the Cogl context because it can be set before
53    context is created */
54 static Display *_cogl_xlib_display = NULL;
55
56 Display *
57 cogl_xlib_get_display (void)
58 {
59   _COGL_GET_CONTEXT (ctx, NULL);
60
61   return cogl_xlib_renderer_get_display (ctx->display->renderer);
62 }
63
64 void
65 cogl_xlib_set_display (Display *display)
66 {
67   /* This can only be called once before the Cogl context is created */
68   g_assert (_cogl_xlib_display == NULL);
69
70   _cogl_xlib_display = display;
71 }
72
73 /* These three functions are wrappers around the equivalent renderer
74    functions. They can be removed once all xlib-based backends in
75    Clutter know about the renderer */
76 CoglFilterReturn
77 cogl_xlib_handle_event (XEvent *xevent)
78 {
79   _COGL_GET_CONTEXT (ctx, COGL_FILTER_CONTINUE);
80
81   /* Pass the event on to the renderer */
82   return cogl_xlib_renderer_handle_event (ctx->display->renderer, xevent);
83 }
84
85 void
86 _cogl_xlib_query_damage_extension (void)
87 {
88   int damage_error;
89
90   _COGL_GET_CONTEXT (ctxt, NO_RETVAL);
91
92   /* Check whether damage events are supported on this display */
93   if (!XDamageQueryExtension (cogl_xlib_get_display (),
94                               &ctxt->damage_base,
95                               &damage_error))
96     ctxt->damage_base = -1;
97 }
98
99 int
100 _cogl_xlib_get_damage_base (void)
101 {
102   CoglX11Renderer *x11_renderer;
103   _COGL_GET_CONTEXT (ctxt, -1);
104
105   x11_renderer =
106     (CoglX11Renderer *) _cogl_xlib_renderer_get_data (ctxt->display->renderer);
107   return x11_renderer->damage_base;
108 }