eolian: rename is_ref API to is_ptr to match syntax
[platform/upstream/efl.git] / src / lib / ecore_x / xlib / ecore_x_present.c
1 #ifdef HAVE_CONFIG_H
2 # include <config.h>
3 #endif /* ifdef HAVE_CONFIG_H */
4
5 #include <stdlib.h>
6
7 #include "ecore_x_private.h"
8 #include "Ecore_X.h"
9
10 int _ecore_x_present_major = 0;
11 static Eina_Bool _ecore_x_present_exists = EINA_FALSE;
12
13 void
14 _ecore_x_present_init(void)
15 {
16    ECORE_X_EVENT_PRESENT_CONFIGURE = ecore_event_type_new();
17    ECORE_X_EVENT_PRESENT_COMPLETE = ecore_event_type_new();
18    ECORE_X_EVENT_PRESENT_IDLE = ecore_event_type_new();
19 #ifdef ECORE_XPRESENT
20    LOGFN(__FILE__, __LINE__, __FUNCTION__);
21    _ecore_x_present_exists = XPresentQueryExtension(_ecore_x_disp, &_ecore_x_present_major, NULL, NULL);
22 #endif
23 }
24
25 #ifdef ECORE_XPRESENT
26 #define SET(X) e->X = ev->X
27
28 static void
29 _present_configure(XPresentConfigureNotifyEvent *ev)
30 {
31    Ecore_X_Event_Present_Configure *e;
32
33    e = calloc(1, sizeof(Ecore_X_Event_Present_Configure));
34    if (!e) return;
35
36    e->win = ev->window;
37    SET(x), SET(y);
38    SET(width), SET(height);
39    SET(off_x), SET(off_y);
40    SET(pixmap_width), SET(pixmap_height);
41    SET(pixmap_flags);
42
43    ecore_event_add(ECORE_X_EVENT_PRESENT_CONFIGURE, e, NULL, NULL);
44 }
45
46 static void
47 _present_complete(XPresentCompleteNotifyEvent *ev)
48 {
49    unsigned int mode[] =
50    {
51     [PresentCompleteModeCopy] = ECORE_X_PRESENT_COMPLETE_MODE_COPY,
52     [PresentCompleteModeFlip] = ECORE_X_PRESENT_COMPLETE_MODE_FLIP,
53     [PresentCompleteModeSkip] = ECORE_X_PRESENT_COMPLETE_MODE_SKIP,
54    };
55    Ecore_X_Event_Present_Complete *e;
56
57    e = calloc(1, sizeof(Ecore_X_Event_Present_Complete));
58    if (!e) return;
59
60    e->win = ev->window;
61    e->serial = ev->serial_number;
62    SET(ust), SET(msc);
63    e->kind = (ev->kind == 1); //libXpresent doesn't expose this...
64    e->mode = mode[ev->mode];
65    ecore_event_add(ECORE_X_EVENT_PRESENT_COMPLETE, e, NULL, NULL);
66 }
67
68 static void
69 _present_idle(XPresentIdleNotifyEvent *ev)
70 {
71    Ecore_X_Event_Present_Idle *e;
72
73    e = calloc(1, sizeof(Ecore_X_Event_Present_Idle));
74    if (!e) return;
75
76    e->win = ev->window;
77    e->serial = ev->serial_number;
78    SET(pixmap);
79    SET(idle_fence);
80    ecore_event_add(ECORE_X_EVENT_PRESENT_IDLE, e, NULL, NULL);
81 }
82 #undef SET
83
84 void
85 _ecore_x_present_handler(XGenericEvent *ge)
86 {
87    XGenericEventCookie *gec = (XGenericEventCookie*)ge;
88
89    if (XGetEventData(_ecore_x_disp, gec))
90      {
91         switch (gec->evtype)
92           {
93            case PresentConfigureNotify:
94              _present_configure(gec->data);
95              break;
96            case PresentCompleteNotify:
97              _present_complete(gec->data);
98              break;
99            case PresentIdleNotify:
100              _present_idle(gec->data);
101              break;
102            default: break;
103           }
104      }
105    XFreeEventData(_ecore_x_disp, gec);
106 }
107 #endif
108
109 EAPI void
110 ecore_x_present_select_events(Ecore_X_Window win, unsigned int events)
111 {
112 #ifdef ECORE_XPRESENT
113    XPresentSelectInput(_ecore_x_disp, win, events);
114    if (_ecore_xlib_sync) ecore_x_sync();
115 #else
116    (void)win;
117    (void)events;
118 #endif
119 }
120
121 EAPI void
122 ecore_x_present_notify_msc(Ecore_X_Window win, unsigned int serial, unsigned long long target_msc, unsigned long long divisor, unsigned long long remainder)
123 {
124 #ifdef ECORE_XPRESENT
125    XPresentNotifyMSC(_ecore_x_disp, win, serial, target_msc, divisor, remainder);
126    if (_ecore_xlib_sync) ecore_x_sync();
127 #else
128    (void)win;
129    (void)serial;
130    (void)target_msc;
131    (void)divisor;
132    (void)remainder;
133 #endif
134 }
135
136 EAPI void
137 ecore_x_present_pixmap(Ecore_X_Window win, Ecore_X_Pixmap pixmap, unsigned int serial, Ecore_X_Region valid,
138                        Ecore_X_Region update, int x_off, int y_off, Ecore_X_Randr_Crtc target_crtc,
139                        Ecore_X_Sync_Fence wait_fence, Ecore_X_Sync_Fence idle_fence, unsigned int options,
140                        unsigned long long target_msc, unsigned long long divisor, unsigned long long remainder,
141                        Ecore_X_Present *notifies, int num_notifies)
142 {
143 #ifdef ECORE_XPRESENT
144    XPresentPixmap(_ecore_x_disp, win, pixmap, serial, valid, update,
145                   x_off, y_off, target_crtc, wait_fence, idle_fence, options, target_msc,
146                   divisor, remainder, (XPresentNotify*)notifies, num_notifies);
147    if (_ecore_xlib_sync) ecore_x_sync();
148 #else
149    (void)win;
150    (void)pixmap;
151    (void)serial;
152    (void)valid;
153    (void)update,
154    (void)x_off;
155    (void)y_off;
156    (void)target_crtc;
157    (void)wait_fence;
158    (void)idle_fence;
159    (void)options;
160    (void)target_msc,
161    (void)divisor;
162    (void)remainder;
163    (void)notifies;
164    (void)num_notifies;
165 #endif
166 }
167
168 EAPI Eina_Bool
169 ecore_x_present_exists(void)
170 {
171    return _ecore_x_present_exists;
172 }