Tizen 2.1 base
[framework/uifw/ecore.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  *
58  * Functions related to the X Damage Extension.
59  */
60
61 EAPI Eina_Bool
62 ecore_x_damage_query(void)
63 {
64    return _damage_avail;
65 }
66
67 /**
68  * Create a damage object
69  *
70  * @param drawable The drawable to monitor
71  * @param level The level of the damage report
72  * @return The damage object
73  *
74  * Creates a damage object to monitor changes to @p drawable,
75  * with the level @p level.
76  *
77  * @ingroup Ecore_X_Damage_Group
78  */
79 EAPI Ecore_X_Damage
80 ecore_x_damage_new(Ecore_X_Drawable            drawable,
81                    Ecore_X_Damage_Report_Level level)
82 {
83    Ecore_X_Damage damage = 0;
84
85    LOGFN(__FILE__, __LINE__, __FUNCTION__);
86    CHECK_XCB_CONN;
87
88    if (!_damage_avail) return 0;
89
90 #ifdef ECORE_XCB_DAMAGE
91    damage = xcb_generate_id(_ecore_xcb_conn);
92    xcb_damage_create(_ecore_xcb_conn, damage, drawable, level);
93 //   ecore_x_flush();
94 #endif
95
96    return damage;
97 }
98
99 /**
100  * Destroy a damage object
101  *
102  * @param damage The damage object to destroy
103  *
104  * Destroys the damage object @p damage
105  *
106  * @ingroup Ecore_X_Damage_Group
107  */
108 EAPI void
109 ecore_x_damage_free(Ecore_X_Damage damage)
110 {
111    LOGFN(__FILE__, __LINE__, __FUNCTION__);
112    CHECK_XCB_CONN;
113
114    if (!_damage_avail) return;
115
116 #ifdef ECORE_XCB_DAMAGE
117    xcb_damage_destroy(_ecore_xcb_conn, damage);
118 //   ecore_x_flush();
119 #endif
120 }
121
122 /**
123  * Synchronously modifies the region
124  *
125  * @param damage The damage object to destroy
126  * @param repair The repair region
127  * @param parts The parts region
128  *
129  * Synchronously modifies the regions in the following manner:
130  * If @p repair is @c XCB_NONE:
131  *   1) parts = damage
132  *   2) damage = \<empty\>
133  * Otherwise:
134  *   1) parts = damage INTERSECT repair
135  *   2) damage = damage - parts
136  *   3) Generate DamageNotify for remaining damage areas
137  *
138  * @ingroup Ecore_X_Damage_Group
139  */
140 EAPI void
141 ecore_x_damage_subtract(Ecore_X_Damage damage,
142                         Ecore_X_Region repair,
143                         Ecore_X_Region parts)
144 {
145    LOGFN(__FILE__, __LINE__, __FUNCTION__);
146    CHECK_XCB_CONN;
147
148    if (!_damage_avail) return;
149
150 #ifdef ECORE_XCB_DAMAGE
151    xcb_damage_subtract(_ecore_xcb_conn, damage, repair, parts);
152 //   ecore_x_flush();
153 #endif
154 }
155