static ClutterX11FilterReturn on_x_event_filter (XEvent *xev, ClutterEvent *cev, gpointer data) { ClutterX11TexturePixmap *texture; ClutterX11TexturePixmapPrivate *priv; Display *dpy; texture = CLUTTER_X11_TEXTURE_PIXMAP (data); g_return_val_if_fail (CLUTTER_X11_IS_TEXTURE_PIXMAP (texture), \ CLUTTER_X11_FILTER_CONTINUE); dpy = clutter_x11_get_default_display(); priv = texture->priv; if (xev->type == _damage_event_base + XDamageNotify) { XserverRegion parts; gint i, r_count; XRectangle *r_damage; XRectangle r_bounds; XDamageNotifyEvent *dev = (XDamageNotifyEvent*)xev; if (dev->drawable != priv->damage_drawable) return CLUTTER_X11_FILTER_CONTINUE; clutter_x11_trap_x_errors (); /* * Retrieve the damaged region and break it down into individual * rectangles so we do not have to update the whole shebang. */ parts = XFixesCreateRegion (dpy, 0, 0); XDamageSubtract (dpy, priv->damage, None, parts); r_damage = XFixesFetchRegionAndBounds (dpy, parts, &r_count, &r_bounds); clutter_x11_untrap_x_errors (); if (r_damage) { for (i = 0; i < r_count; ++i) clutter_x11_texture_pixmap_update_area (texture, r_damage[i].x, r_damage[i].y, r_damage[i].width, r_damage[i].height); XFree (r_damage); } XFixesDestroyRegion (dpy, parts); } return CLUTTER_X11_FILTER_CONTINUE; }
EAPI Ecore_X_Rectangle * ecore_x_region_fetch(Ecore_X_Region region, int *num, Ecore_X_Rectangle *bounds){ #ifdef ECORE_XFIXES Ecore_X_Rectangle *rects; XRectangle *xrect, xbound; LOGFN(__FILE__, __LINE__, __FUNCTION__); xrect = XFixesFetchRegionAndBounds(_ecore_x_disp, region, num, &xbound); rects = _ecore_x_rectangle_x_to_ecore(xrect, *num); (*bounds).x = xbound.x; (*bounds).y = xbound.y; (*bounds).width = xbound.width; (*bounds).height = xbound.height; return rects; #else /* ifdef ECORE_XFIXES */ return NULL; #endif /* ifdef ECORE_XFIXES */ } /* ecore_x_region_fetch */
static void process_damage_event (CoglTexturePixmapX11 *tex_pixmap, XDamageNotifyEvent *damage_event) { CoglTexture *tex = COGL_TEXTURE (tex_pixmap); Display *display; enum { DO_NOTHING, NEEDS_SUBTRACT, NEED_BOUNDING_BOX } handle_mode; const CoglWinsysVtable *winsys; _COGL_GET_CONTEXT (ctxt, NO_RETVAL); display = cogl_xlib_renderer_get_display (ctxt->display->renderer); COGL_NOTE (TEXTURE_PIXMAP, "Damage event received for %p", tex_pixmap); switch (tex_pixmap->damage_report_level) { case COGL_TEXTURE_PIXMAP_X11_DAMAGE_RAW_RECTANGLES: /* For raw rectangles we don't need do look at the damage region at all because the damage area is directly given in the event struct and the reporting of events is not affected by clearing the damage region */ handle_mode = DO_NOTHING; break; case COGL_TEXTURE_PIXMAP_X11_DAMAGE_DELTA_RECTANGLES: case COGL_TEXTURE_PIXMAP_X11_DAMAGE_NON_EMPTY: /* For delta rectangles and non empty we'll query the damage region for the bounding box */ handle_mode = NEED_BOUNDING_BOX; break; case COGL_TEXTURE_PIXMAP_X11_DAMAGE_BOUNDING_BOX: /* For bounding box we need to clear the damage region but we don't actually care what it was because the damage event itself contains the bounding box of the region */ handle_mode = NEEDS_SUBTRACT; break; default: g_assert_not_reached (); } /* If the damage already covers the whole rectangle then we don't need to request the bounding box of the region because we're going to update the whole texture anyway. */ if (cogl_damage_rectangle_is_whole (&tex_pixmap->damage_rect, tex->width, tex->height)) { if (handle_mode != DO_NOTHING) XDamageSubtract (display, tex_pixmap->damage, None, None); } else if (handle_mode == NEED_BOUNDING_BOX) { XserverRegion parts; int r_count; XRectangle r_bounds; XRectangle *r_damage; /* We need to extract the damage region so we can get the bounding box */ parts = XFixesCreateRegion (display, 0, 0); XDamageSubtract (display, tex_pixmap->damage, None, parts); r_damage = XFixesFetchRegionAndBounds (display, parts, &r_count, &r_bounds); cogl_damage_rectangle_union (&tex_pixmap->damage_rect, r_bounds.x, r_bounds.y, r_bounds.width, r_bounds.height); if (r_damage) XFree (r_damage); XFixesDestroyRegion (display, parts); } else { if (handle_mode == NEEDS_SUBTRACT) /* We still need to subtract from the damage region but we don't care what the region actually was */ XDamageSubtract (display, tex_pixmap->damage, None, None); cogl_damage_rectangle_union (&tex_pixmap->damage_rect, damage_event->area.x, damage_event->area.y, damage_event->area.width, damage_event->area.height); } if (tex_pixmap->winsys) { /* If we're using the texture from pixmap extension then there's no point in getting the region and we can just mark that the texture needs updating */ winsys = _cogl_texture_pixmap_x11_get_winsys (tex_pixmap); winsys->texture_pixmap_x11_damage_notify (tex_pixmap); } }