aboutsummaryrefslogtreecommitdiffstats
path: root/legacy/ecore/src/lib/ecore_x/xlib/ecore_x_sync.c
blob: bc2bb1feaedcccac62eea449fbf09174cc80c794 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
 * XSync code
 */

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* ifdef HAVE_CONFIG_H */

#include "Ecore.h"
#include "ecore_x_private.h"
#include "Ecore_X.h"
#include "Ecore_X_Atoms.h"

EAPI Ecore_X_Sync_Alarm
ecore_x_sync_alarm_new(Ecore_X_Sync_Counter counter)
{
   Ecore_X_Sync_Alarm alarm;
   XSyncAlarmAttributes values;
   XSyncValue init;

   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   XSyncIntToValue(&init, 0);
   XSyncSetCounter(_ecore_x_disp, counter, init);

   values.trigger.counter = counter;
   values.trigger.value_type = XSyncAbsolute;
   XSyncIntToValue(&values.trigger.wait_value, 1);
   values.trigger.test_type = XSyncPositiveComparison;

   XSyncIntToValue(&values.delta,              1);

   values.events = True;

   alarm = XSyncCreateAlarm(_ecore_x_disp,
                            XSyncCACounter |
                            XSyncCAValueType |
                            XSyncCAValue |
                            XSyncCATestType |
                            XSyncCADelta |
                            XSyncCAEvents,
                            &values);

   ecore_x_sync();
   return alarm;
} /* ecore_x_sync_alarm_new */

EAPI Eina_Bool
ecore_x_sync_alarm_free(Ecore_X_Sync_Alarm alarm)
{
   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   return XSyncDestroyAlarm(_ecore_x_disp, alarm);
} /* ecore_x_sync_alarm_free */

EAPI Eina_Bool
ecore_x_sync_counter_query(Ecore_X_Sync_Counter counter, unsigned int *val)
{
   XSyncValue value;

   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   if (XSyncQueryCounter(_ecore_x_disp, counter, &value))
     {
        *val = (unsigned int)XSyncValueLow32(value);
        return EINA_TRUE;
     }

   return EINA_FALSE;
} /* ecore_x_sync_counter_query */

EAPI Ecore_X_Sync_Counter
ecore_x_sync_counter_new(int val)
{
   XSyncCounter counter;
   XSyncValue v;

   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   XSyncIntToValue(&v, val);
   counter = XSyncCreateCounter(_ecore_x_disp, v);
   return counter;
} /* ecore_x_sync_counter_new */

EAPI void
ecore_x_sync_counter_free(Ecore_X_Sync_Counter counter)
{
   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   XSyncDestroyCounter(_ecore_x_disp, counter);
} /* ecore_x_sync_counter_free */

EAPI void
ecore_x_sync_counter_inc(Ecore_X_Sync_Counter counter, int by)
{
   XSyncValue v;

   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   XSyncIntToValue(&v, by);
   XSyncChangeCounter(_ecore_x_disp, counter, v);
} /* ecore_x_sync_counter_inc */

EAPI void
ecore_x_sync_counter_val_wait(Ecore_X_Sync_Counter counter, int val)
{
   XSyncWaitCondition cond;
   XSyncValue v, v2;

   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   XSyncQueryCounter(_ecore_x_disp, counter, &v);
   XSyncIntToValue(&v,  val);
   XSyncIntToValue(&v2, val + 1);
   cond.trigger.counter = counter;
   cond.trigger.value_type = XSyncAbsolute;
   cond.trigger.wait_value = v;
   cond.trigger.test_type = XSyncPositiveComparison;
   cond.event_threshold = v2;
   XSyncAwait(_ecore_x_disp, &cond, 1);
//   XSync(_ecore_x_disp, False); // dont need this
} /* ecore_x_sync_counter_val_wait */

EAPI void
ecore_x_sync_counter_set(Ecore_X_Sync_Counter counter, int val)
{
   XSyncValue v;

   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   XSyncIntToValue(&v, val);
   XSyncSetCounter(_ecore_x_disp, counter, v);
}

EAPI void
ecore_x_sync_counter_2_set(Ecore_X_Sync_Counter counter, int val_hi, unsigned int val_lo)
{
   XSyncValue v;

   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   XSyncIntsToValue(&v, val_lo, val_hi);
   XSyncSetCounter(_ecore_x_disp, counter, v);
}

EAPI Eina_Bool
ecore_x_sync_counter_2_query(Ecore_X_Sync_Counter counter, int *val_hi, unsigned int *val_lo)
{
   XSyncValue value;

   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   if (XSyncQueryCounter(_ecore_x_disp, counter, &value))
     {
        *val_lo = (unsigned int)XSyncValueLow32(value);
        *val_hi = (int)XSyncValueHigh32(value);
        return EINA_TRUE;
     }
   return EINA_FALSE;
}