From c611da821a5d28063ffe79c26d27ae89e1784ba0 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Fri, 10 Jul 2020 18:20:33 -0700 Subject: poll_events: align rectangles to even boundaries The current rectinsert code does this, but it does it in the absolute root window coordinate space. In preparation for dropping all the alignment stuff out of rectinsert, do the alignment at the rectinsert caller and do it in the rrect-relative coordinate space. --- recordmydesktop/src/rmd_poll_events.c | 43 +++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/recordmydesktop/src/rmd_poll_events.c b/recordmydesktop/src/rmd_poll_events.c index 349aeba..96730fd 100644 --- a/recordmydesktop/src/rmd_poll_events.c +++ b/recordmydesktop/src/rmd_poll_events.c @@ -97,6 +97,43 @@ static int clip_event_area(XDamageNotifyEvent *e, XRectangle *cliprect, XRectang } +/* Try align xrect to even boundaries relative to cliprect, + * this is done for the UV routines which operate at 2x2 rgb pixel granularity. + */ +static void uv_align(XRectangle *cliprect, XRectangle *xrect) { + XRectangle rel; + + rel.x = xrect->x - cliprect->x; + rel.y = xrect->y - cliprect->y; + + if (rel.x % 2) { + rel.x -= 1; + rel.width = xrect->width + 1; + } else { + rel.width = xrect->width; + } + + if (rel.y % 2) { + rel.y -= 1; + rel.height = xrect->height + 1; + } else { + rel.height = xrect->height; + } + + /* XXX: note when cliprect prevents an even width, we can't do anything + * about it. rmd could force even-sized recording windows to prevent + * this, but that would be kind of annoying. For now it's assumed + * the UV routines will handle the exception - which might temporarily + * mean they just lop the odd row/column off the edge. + */ + if (rel.width % 2 && rel.width + rel.x < cliprect->x + cliprect->width) + rel.width++; + + if (rel.height % 2 && rel.height + rel.y < cliprect->y + cliprect->height) + rel.height++; +} + + void rmdInitEventsPolling(ProgData *pdata) { Window root_return, parent_return, @@ -198,8 +235,10 @@ void rmdEventLoop(ProgData *pdata) { XDamageNotifyEvent *e = (XDamageNotifyEvent *)&event; XRectangle xrect; - if (clip_event_area(e, &pdata->brwin.rrect, &xrect)) - inserts += rmdRectInsert(&pdata->rect_root,&xrect); + if (clip_event_area(e, &pdata->brwin.rrect, &xrect)) { + uv_align(&pdata->brwin.rrect, &xrect); + inserts += rmdRectInsert(&pdata->rect_root, &xrect); + } } } } -- cgit v1.2.1