fdb7a2a6c62c7aebbeb08a7e0036e4ef915d2a17
[platform/upstream/efl.git] / src / lib / ecore_x / xcb / ecore_xcb_damage.c
1 #include "ecore_xcb_private.h"
2 # ifdef ECORE_XCB_DAMAGE
3 #  include <xcb/damage.h>
4 # endif
5
6 /* local variables */
7 static Eina_Bool _damage_avail = EINA_FALSE;
8
9 /* external variables */
10 int _ecore_xcb_event_damage = -1;
11
12 void
13 _ecore_xcb_damage_init(void)
14 {
15    LOGFN(__FILE__, __LINE__, __FUNCTION__);
16
17 #ifdef ECORE_XCB_DAMAGE
18    xcb_prefetch_extension_data(_ecore_xcb_conn, &xcb_damage_id);
19 #endif
20 }
21
22 void
23 _ecore_xcb_damage_finalize(void)
24 {
25 #ifdef ECORE_XCB_DAMAGE
26    const xcb_query_extension_reply_t *ext_reply;
27 #endif
28
29    LOGFN(__FILE__, __LINE__, __FUNCTION__);
30
31 #ifdef ECORE_XCB_DAMAGE
32    ext_reply = xcb_get_extension_data(_ecore_xcb_conn, &xcb_damage_id);
33    if ((ext_reply) && (ext_reply->present))
34      {
35         xcb_damage_query_version_cookie_t cookie;
36         xcb_damage_query_version_reply_t *reply;
37
38         cookie =
39           xcb_damage_query_version_unchecked(_ecore_xcb_conn,
40                                              XCB_DAMAGE_MAJOR_VERSION,
41                                              XCB_DAMAGE_MINOR_VERSION);
42         reply = xcb_damage_query_version_reply(_ecore_xcb_conn, cookie, NULL);
43         if (reply)
44           {
45              _damage_avail = EINA_TRUE;
46              free(reply);
47           }
48
49         if (_damage_avail)
50           _ecore_xcb_event_damage = ext_reply->first_event;
51      }
52 #endif
53 }
54
55 /**
56  * @defgroup Ecore_X_Damage_Group X Damage Extension Functions
57  * @ingroup Ecore_X_Group
58  *
59  * Functions related to the X Damage Extension.
60  */
61
62 EAPI Eina_Bool
63 ecore_x_damage_query(void)
64 {
65    return _damage_avail;
66 }
67
68 /**
69  * Create a damage object
70  *
71  * @param drawable The drawable to monitor
72  * @param level The level of the damage report
73  * @return The damage object
74  *
75  * Creates a damage object to monitor changes to @p drawable,
76  * with the level @p level.
77  *
78  * @ingroup Ecore_X_Damage_Group
79  */
80 EAPI Ecore_X_Damage
81 ecore_x_damage_new(Ecore_X_Drawable            drawable,
82                    Ecore_X_Damage_Report_Level level)
83 {
84    Ecore_X_Damage damage = 0;
85
86    LOGFN(__FILE__, __LINE__, __FUNCTION__);
87    CHECK_XCB_CONN;
88
89    if (!_damage_avail) return 0;
90
91 #ifdef ECORE_XCB_DAMAGE
92    damage = xcb_generate_id(_ecore_xcb_conn);
93    xcb_damage_create(_ecore_xcb_conn, damage, drawable, level);
94 //   ecore_x_flush();
95 #endif
96
97    return damage;
98 }
99
100 /**
101  * Destroy a damage object
102  *
103  * @param damage The damage object to destroy
104  *
105  * Destroys the damage object @p damage
106  *
107  * @ingroup Ecore_X_Damage_Group
108  */
109 EAPI void
110 ecore_x_damage_free(Ecore_X_Damage damage)
111 {
112    LOGFN(__FILE__, __LINE__, __FUNCTION__);
113    CHECK_XCB_CONN;
114
115    if (!_damage_avail) return;
116
117 #ifdef ECORE_XCB_DAMAGE
118    xcb_damage_destroy(_ecore_xcb_conn, damage);
119 //   ecore_x_flush();
120 #endif
121 }
122
123 /**
124  * Synchronously modifies the region
125  *
126  * @param damage The damage object to destroy
127  * @param repair The repair region
128  * @param parts The parts region
129  *
130  * Synchronously modifies the regions in the following manner:
131  * If @p repair is @c XCB_NONE:
132  *   1) parts = damage
133  *   2) damage = \<empty\>
134  * Otherwise:
135  *   1) parts = damage INTERSECT repair
136  *   2) damage = damage - parts
137  *   3) Generate DamageNotify for remaining damage areas
138  *
139  * @ingroup Ecore_X_Damage_Group
140  */
141 EAPI void
142 ecore_x_damage_subtract(Ecore_X_Damage damage,
143                         Ecore_X_Region repair,
144                         Ecore_X_Region parts)
145 {
146    LOGFN(__FILE__, __LINE__, __FUNCTION__);
147    CHECK_XCB_CONN;
148
149    if (!_damage_avail) return;
150
151 #ifdef ECORE_XCB_DAMAGE
152    xcb_damage_subtract(_ecore_xcb_conn, damage, repair, parts);
153 //   ecore_x_flush();
154 #endif
155 }
156