1 #include "e_mod_comp_shared_types.h"
2 #include "e_mod_comp.h"
3 #include "e_mod_comp_atoms.h"
4 #include "e_mod_comp_debug.h"
6 #include <X11/extensions/hwc.h>
8 #include "hwcomp_debug.h"
9 #include "hwcomp_util.h"
13 #define E_HWCOMP_COMP_COUNTDOWN 30
14 #define E_HWCOMP_SET_COUNTDOWN 1
16 static Eina_Bool _hwc_available = EINA_FALSE;
17 static int _hwc_max_layer;
18 static int _hwc_major, _hwc_minor;
19 static Ecore_X_Display *_display = NULL;
20 static int _hwc_op_code;
23 hwcomp_util_hwcomp_enable(Ecore_X_Window win)
25 int hwc_event, hwc_error;
29 if (!_display) _display = ecore_x_display_get();
31 if (XQueryExtension(_display, HWC_NAME, &_hwc_op_code, &hwc_event, &hwc_error))
33 HWCQueryVersion(_display, &_hwc_major, &_hwc_minor);
34 if (!HWCOpen(_display, 0, &_hwc_max_layer)) /* TODO: Get active CRTC */
36 _hwc_available = EINA_FALSE;
39 HWCSelectInput(_display, win, HWCAllEvents);
40 _hwc_available = EINA_TRUE;
43 _hwc_available = EINA_FALSE;
47 hwcomp_util_display_get(void)
53 hwcomp_util_hwcomp_query(void)
55 return _hwc_available;
59 hwcomp_util_max_layer_get(void)
61 return _hwc_max_layer;
65 hwcomp_util_max_layer_set(int maxLayer)
67 _hwc_max_layer = maxLayer;
71 hwcomp_util_get_event_data(Ecore_X_Event_Generic *e)
75 if (e->extension == _hwc_op_code && e->evtype == HWCConfigureNotify)
77 HWCConfigureNotifyCookie *data = (HWCConfigureNotifyCookie *)e->data;
78 return data->maxLayer;
84 hwcomp_util_turn_composite(E_Comp_HWComp *hwcomp, Eina_Bool on)
87 E_Comp_Canvas *canvas = hwcomp->canvas;
88 Eina_Bool manual_render_set = !on;
90 if (ecore_evas_manual_render_get(canvas->ee) != manual_render_set)
91 ecore_evas_manual_render_set(canvas->ee, manual_render_set);
95 hwcomp_util_check_fullcomp_mode(E_Comp_Win *cw)
97 Eina_Bool ret = EINA_FALSE;
100 if (STATE_INSET_CHECK(cw) && cw->bd->lock_user_location)
103 /* Resizing of window */
107 /* Moving of window */
108 if ((STATE_INSET_CHECK(cw) || CLASS_ICONIC_CHECK(cw)) &&
111 cw->hwc.geo_changed--;
116 if (cw->bd->client.e.state.ly.curr_ly)
123 hwcomp_util_border_name_get(E_Border *bd)
125 if (!bd) return NULL;
127 if (bd->client.icccm.name && strcmp(bd->client.icccm.name, "NORMAL_WINDOW"))
128 return bd->client.icccm.name;
129 else if (bd->client.netwm.name)
130 return bd->client.netwm.name;
131 else if (bd->client.icccm.class)
132 return bd->client.icccm.class;
138 hwcomp_util_dec_set_countdown(E_Comp_HWComp_Drawable *d)
140 if (d->set_countdown <= 0) return;
146 hwcomp_util_reset_set_countdown(E_Comp_HWComp_Drawable *d)
148 d->set_countdown = E_HWCOMP_SET_COUNTDOWN;
152 hwcomp_util_dec_comp_countdown(E_Comp_HWComp_Drawable *d)
154 if (d->comp_countdown <= 0) return;
160 hwcomp_util_reset_comp_countdown(E_Comp_HWComp_Drawable *d)
162 d->comp_countdown = E_HWCOMP_COMP_COUNTDOWN;
166 hwcomp_util_update_check_region(E_Comp_HWComp_Update *hwc_update, E_Comp_Win *cw, int w, int h, int max_w, int max_h)
168 Eina_Bool ret = EINA_FALSE;
170 int max = max_w*max_h/2;
172 _hwcomp_dbg_elbf(ELBT_COMP, 0, 0, "%15.15s| d:%p (%dx%d)", "HWC:WIN REGION",
173 cw->bd->client.win, w, h);
179 #if OPTIMIZED_HWC_MOBILE
188 hwcomp_util_update_countdown(E_Comp_HWComp_Update *hwc_update, E_Comp_Win *cw)
190 E_Comp_HWComp_Drawable *hwc_drawable = NULL;
192 int num_drawable = 0;
194 if (hwc_update->update_mode != E_HWCOMP_USE_HYBRIDCOMP_MODE) return;
196 num_drawable = hwc_update->num_drawable;
198 for (i = 0; i < num_drawable; i++)
200 hwc_drawable = hwc_update->hwc_drawable[i];
202 if (hwc_drawable && hwc_drawable->cw == cw)
204 if (hwc_drawable->set_drawable)
206 hwcomp_util_reset_comp_countdown(hwc_drawable);
208 if (i != 0 && hwc_drawable->first_update)
210 hwc_drawable->set_drawable = EINA_FALSE;
211 hwc_drawable->first_update = 0;
216 if (hwc_drawable->region_update)
218 hwcomp_util_dec_set_countdown(hwc_drawable);
219 hwc_drawable->region_update = EINA_FALSE;
222 _hwcomp_dbg_elbf(ELBT_COMP, 0, 0, "%15.15s| client.win: %p set:%d set_cnt:%d comp_cnt:%d fu(%d)",
223 "HWC:CW Update", cw->bd->client.win, hwc_drawable->set_drawable, hwc_drawable->set_countdown, hwc_drawable->comp_countdown, hwc_drawable->first_update);
229 hwcomp_util_update_check_resized(E_Comp_HWComp_Update *hwc_update)
233 for (i = 0; i < hwc_update->num_drawable; i++)
235 if (hwc_update->hwc_drawable[i]->resized)
243 hwcomp_util_update_unset_resized(E_Comp_HWComp_Update *hwc_update, E_Comp_Win *cw)
246 for (i = 0; i < hwc_update->num_drawable; i++)
248 if (cw == hwc_update->hwc_drawable[i]->cw)
250 if (hwc_update->hwc_drawable[i]->resized)
252 hwc_update->hwc_drawable[i]->resized = EINA_FALSE;
260 hwcomp_util_update_set_resized(E_Comp_HWComp_Update *hwc_update, E_Comp_Win *cw)
264 for (i = 0; i < hwc_update->num_drawable; i++)
266 if (cw == hwc_update->hwc_drawable[i]->cw)
268 hwc_update->hwc_drawable[i]->resized = EINA_TRUE;
275 hwcomp_util_update_check_comp(E_Comp_HWComp_Update *hwc_update)
277 return hwc_update->comp_update;
281 hwcomp_util_update_set_comp(E_Comp_HWComp_Update *hwc_update, Eina_Bool comp_update)
283 if (hwc_update->comp_update == comp_update) return;
285 hwc_update->comp_update = comp_update;
290 hwcomp_util_update_compare_drawables(E_Comp_HWComp_Update *cur_hwc_update, E_Comp_HWComp_Update *new_hwc_update)
292 E_Comp_HWComp_Drawable *cur_d = NULL;
293 E_Comp_HWComp_Drawable *new_d = NULL;
296 if (cur_hwc_update->num_drawable != new_hwc_update->num_drawable)
299 for (i = 0; i < cur_hwc_update->num_drawable; i++)
301 cur_d = cur_hwc_update->hwc_drawable[i];
302 new_d = new_hwc_update->hwc_drawable[i];
304 if (cur_d->d != new_d->d)
307 #if OPTIMIZED_HWC_MOBILE
308 if (cur_hwc_update->ime_present && new_hwc_update->ime_present)
310 _hwcomp_dbg_elbf(ELBT_COMP, 0, 0, "%15.15s|ime_old(%d,%d,%d,%d)->ime_new(%d,%d,%d,%d)", "HWC:IME",
311 cur_hwc_update->ime_rect.x, cur_hwc_update->ime_rect.y, cur_hwc_update->ime_rect.w, cur_hwc_update->ime_rect.h,
312 new_hwc_update->ime_rect.x, new_hwc_update->ime_rect.y, new_hwc_update->ime_rect.w, new_hwc_update->ime_rect.h);
314 if (cur_hwc_update->ime_rect.x != new_hwc_update->ime_rect.x)
317 if (cur_hwc_update->ime_rect.y != new_hwc_update->ime_rect.y)
320 if (cur_hwc_update->ime_rect.w != new_hwc_update->ime_rect.w)
323 if (cur_hwc_update->ime_rect.h != new_hwc_update->ime_rect.h)
332 hwcomp_util_update_migrate_drawables(E_Comp_HWComp_Update *cur_hwc_update, E_Comp_HWComp_Update *new_hwc_update)
334 E_Comp_HWComp_Drawable *cur_d = NULL;
335 E_Comp_HWComp_Drawable *new_d = NULL;
338 for (i = 0; i < new_hwc_update->num_drawable; i++)
340 new_d = new_hwc_update->hwc_drawable[i];
341 for (j = 0; j < cur_hwc_update->num_drawable; j++)
343 cur_d = cur_hwc_update->hwc_drawable[i];
344 if (cur_d->d == new_d->d)
346 new_d->comp_countdown = cur_d->comp_countdown;
347 new_d->set_countdown = cur_d->set_countdown;
348 new_d->set_drawable = cur_d->set_drawable;
349 new_d->first_update = cur_d->first_update;
350 new_d->update_count = cur_d->update_count;
359 hwcomp_util_update_destroy_drawable(E_Comp_HWComp_Update *hwc_update)
362 E_Comp_Win *hide_cw = NULL;
363 E_Comp_HWComp_Drawable *hwc_drawable = NULL;
365 for (i = 1; i < hwc_update->num_drawable; i++)
367 hwc_drawable = hwc_update->hwc_drawable[i];
368 hide_cw = hwc_drawable->cw;
369 if (hwc_update->update_mode == E_HWCOMP_USE_HYBRIDCOMP_MODE &&
370 hide_cw->hwc.set_drawable == EINA_FALSE)
371 e_mod_comp_win_hwcomp_mask_objs_hide(hide_cw);
374 if (hwc_update->hwc_drawable)
376 for (i = 0; i < hwc_update->num_overlays; i++)
378 if (!hwc_update->hwc_drawable[i])
380 E_FREE(hwc_update->hwc_drawable[i]);
381 hwc_update->hwc_drawable[i] = NULL;
384 E_FREE(hwc_update->hwc_drawable);
385 hwc_update->hwc_drawable = NULL;
390 hwcomp_util_update_create_drawable(E_Comp_HWComp_Update *hwc_update)
393 int num = hwc_update->num_overlays;
395 hwc_update->hwc_drawable = E_NEW(E_Comp_HWComp_Drawable *, num);
396 E_CHECK_RETURN(hwc_update->hwc_drawable, 0);
397 memset(hwc_update->hwc_drawable, 0x0, num * sizeof(E_Comp_HWComp_Drawable *));
399 for (i = 0; i < num; i++)
401 hwc_update->hwc_drawable[i] = E_NEW(E_Comp_HWComp_Drawable, 1);
402 if (!hwc_update->hwc_drawable[i]) goto fail;
407 hwcomp_util_update_destroy_drawable(hwc_update);
413 hwcomp_util_update_clear_drawable(E_Comp_HWComp_Update *hwc_update)
417 for (i = 0; i < hwc_update->num_overlays; i++)
419 memset(hwc_update->hwc_drawable[i], 0x0, sizeof(E_Comp_HWComp_Drawable));
424 hwcomp_util_update_destroy(E_Comp_HWComp_Update *hwc_update)
426 if (!hwc_update) return;
428 hwcomp_util_update_destroy_drawable(hwc_update);
434 EAPI E_Comp_HWComp_Update *
435 hwcomp_util_update_create(E_Comp_HWComp *hwcomp, int num)
437 E_Comp_HWComp_Update *hwc_update = NULL;
438 Eina_Bool ret = EINA_FALSE;
440 hwc_update = E_NEW(E_Comp_HWComp_Update, 1);
441 E_CHECK_RETURN(hwc_update, 0);
443 hwc_update->update_mode = E_HWCOMP_USE_INVALID;
444 hwc_update->num_overlays = num;
445 ret = hwcomp_util_update_create_drawable(hwc_update);
446 if (ret == EINA_FALSE)
448 hwcomp_util_update_destroy(hwc_update);
451 hwc_update->num_drawable = 0;
452 hwc_update->comp_update = EINA_FALSE;
454 hwc_update->hwcomp = hwcomp;
460 hwcomp_util_update_clear(E_Comp_HWComp_Update *hwc_update)
463 E_Comp_Win *hide_cw = NULL;
464 E_Comp_HWComp_Drawable *hwc_drawable = NULL;
466 for (i = 1; i < hwc_update->num_drawable; i++)
468 hwc_drawable = hwc_update->hwc_drawable[i];
469 hide_cw = hwc_drawable->cw;
470 e_mod_comp_win_hwcomp_mask_objs_hide(hide_cw);
473 hwc_update->update_mode = E_HWCOMP_USE_INVALID;
474 hwc_update->num_drawable = 0;
475 hwc_update->comp_update = EINA_FALSE;
476 hwcomp_util_update_clear_drawable(hwc_update);
480 hwcomp_util_update_reset_maskobj(E_Comp_HWComp_Update *hwc_update)
484 E_Comp_Win *hide_cw = NULL;
485 E_Comp_HWComp_Drawable *hwc_drawable = NULL;
487 for (i = 1; i < hwc_update->num_drawable; i++)
489 hwc_drawable = hwc_update->hwc_drawable[i];
490 hide_cw = hwc_drawable->cw;
492 e_mod_comp_win_hwcomp_mask_objs_hide(hide_cw);
497 hwcomp_util_set_hybrid_composite(E_Comp_HWComp_Update *hwc_update)
501 E_Comp_HWComp_Drawable *hwc_drawable = NULL;
504 for (i = 1; i < hwc_update->num_drawable; i++)
506 hwc_drawable = hwc_update->hwc_drawable[i];
507 hwc_drawable->set_drawable = EINA_TRUE;
508 hwc_drawable->first_update = 1;
509 hwcomp_util_reset_comp_countdown(hwc_drawable);
510 hwcomp_util_reset_set_countdown(hwc_drawable);
513 #endif /* End of USE_HWC */