d5b0c6663ad7d7d66fbe225b9e9155842c49470a
[framework/uifw/ecore.git] / src / lib / ecore_x / xcb / ecore_xcb_damage.c
1 /*
2  * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
3  */
4
5 #include "ecore_xcb_private.h"
6
7
8 /**
9  * @defgroup Ecore_X_Damage_Group X Damage Extension Functions
10  *
11  * Functions related to the X Damage extension.
12  */
13
14
15 #ifdef ECORE_XCB_DAMAGE
16 static uint8_t _damage_available = 0;
17 static xcb_damage_query_version_cookie_t _ecore_xcb_damage_init_cookie;
18 #endif /* ECORE_XCB_DAMAGE */
19
20
21 /* To avoid round trips, the initialization is separated in 2
22    functions: _ecore_xcb_damage_init and
23    _ecore_xcb_damage_init_finalize. The first one gets the cookies and
24    the second one gets the replies. */
25
26 void
27 _ecore_x_damage_init(const xcb_query_extension_reply_t *reply)
28 {
29 #ifdef ECORE_XCB_DAMAGE
30    if (reply && (reply->present))
31       _ecore_xcb_damage_init_cookie = xcb_damage_query_version_unchecked(_ecore_xcb_conn, 1, 1);
32 #endif /* ECORE_XCB_DAMAGE */
33 }
34
35 void
36 _ecore_x_damage_init_finalize(void)
37 {
38 #ifdef ECORE_XCB_DAMAGE
39    xcb_damage_query_version_reply_t *reply;
40
41    reply = xcb_damage_query_version_reply(_ecore_xcb_conn,
42                                           _ecore_xcb_damage_init_cookie,
43                                           NULL);
44    if (reply)
45      {
46         if (reply->major_version >= 1)
47           _damage_available = 1;
48         free(reply);
49      }
50 #endif /* ECORE_XCB_DAMAGE */
51 }
52
53
54 /**
55  * Return whether the Damage Extension is available.
56  * @return 1 if the Damage Extension is available, 0 if not.
57  *
58  * Return 1 if the X server supports the Damage Extension version 1.0,
59  * 0 otherwise.
60  * @ingroup Ecore_X_Damage_Group
61  */
62 EAPI int
63 ecore_x_damage_query(void)
64 {
65 #ifdef ECORE_XCB_DAMAGE
66    return _damage_available;
67 #else
68    return 0;
69 #endif /* ECORE_XCB_DAMAGE */
70 }
71
72
73 /**
74  * Creates a damage object.
75  * @param drawable The drawable to monotor.
76  * @param level    The level of the damage report.
77  * @return         The damage object.
78  *
79  * Creates a damage object to monitor changes to @p drawable, with the
80  * level @p level.
81  * @ingroup Ecore_X_Damage_Group
82  */
83 EAPI Ecore_X_Damage
84 ecore_x_damage_new(Ecore_X_Drawable            drawable,
85                    Ecore_X_Damage_Report_Level level)
86 {
87    Ecore_X_Damage damage = 0;
88
89 #ifdef ECORE_XCB_DAMAGE
90    damage = xcb_generate_id(_ecore_xcb_conn);
91    xcb_damage_create(_ecore_xcb_conn, damage, drawable, level);
92 #endif /* ECORE_XCB_DAMAGE */
93
94    return damage;
95 }
96
97
98 /**
99  * Destroys a damage object.
100  * @param damage The damage object to destroy.
101  *
102  * Destroys the damage object @p damage.
103  * @ingroup Ecore_X_Damage_Group
104  */
105 EAPI void
106 ecore_x_damage_del(Ecore_X_Damage damage)
107 {
108 #ifdef ECORE_XCB_DAMAGE
109    xcb_damage_destroy(_ecore_xcb_conn, damage);
110 #endif /* ECORE_XCB_DAMAGE */
111 }
112
113
114 /**
115  * Synchronously modifies the region.
116  * @param damage The damage object to destroy.
117  * @param repair The repair region.
118  * @param parts  The parts region.
119  *
120  * Synchronously modifies the regions in the following manner:
121  * If @p repair is @c XCB_NONE:
122  *   1) parts = damage
123  *   2) damage = <empty>
124  * Otherwise:
125  *   1) parts = damage INTERSECT repair
126  *   2) damage = damage - parts
127  *   3) Generate DamageNotify for remaining damage areas
128  * @ingroup Ecore_X_Damage_Group
129  */
130 EAPI void
131 ecore_x_damage_subtract(Ecore_X_Damage damage,
132                         Ecore_X_Region repair,
133                         Ecore_X_Region parts)
134 {
135 #ifdef ECORE_XCB_DAMAGE
136    xcb_damage_subtract(_ecore_xcb_conn, damage, repair, parts);
137 #endif /* ECORE_XCB_DAMAGE */
138 }