<div dir="ltr">From what I can see, my issue boils down to CAIRO_OPERATOR_SOURCE not behaving as I would expect, with the use of an xcb backed surface.<br>Namely, after doing a cairo_pop_group_to_source(), if I <span style="font-size:small;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE), based on the docs I would expect the alpha channel to be copied from the intermediate pattern/surface as-is to the destination, with no blending. I actually observe this when the destination is *not* an xcb derived surface (I'm playing with a png one now, using the sample program I included).<br></span><br>With an xcb backed surface like in my original program, setting the operator to CAIRO_OPERATOR_SOURCE results in a solid black background.<br><br>Specifically, my case is this:<span style="text-decoration-style:initial;text-decoration-color:initial;font-family:monospace,monospace;float:none;display:inline"><br></span><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br>   // BEGIN render loop   </span><div><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">   cairo_push_group(cairo);</span><br style="text-decoration-style:initial;text-decoration-color:initial"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">   cairo_set_source_rgba(cairo, 0.8, 0, 0, 0.1);</span><br style="text-decoration-style:initial;text-decoration-color:initial"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br>   // draw (lots of) stuff</span><br style="text-decoration-style:initial;text-decoration-color:initial"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br>   // END render loop</span><br style="text-decoration-style:initial;text-decoration-color:initial"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">   cairo_pop_group_to_source(</span><wbr style="text-decoration-style:initial;text-decoration-color:initial"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">cairo);<br></span>   cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE);<br style="text-decoration-style:initial;text-decoration-color:initial"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">   cairo_paint(cairo);<br></span>   // reset operator to CAIRO_OPERATOR_OVER<br style="text-decoration-style:initial;text-decoration-color:initial"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">   xcb_flush(xcon);</span><br style="text-decoration-style:initial;text-decoration-color:initial"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">   sleep(1);</span><br><br>I've been looking into cairo-xcb / xcb specifics regarding this, but any cluesticks that could be provided would be appreciated.<br><br>Cheers,<br>-Ryan<br><br><br><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote"><span style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Hello,</span><br style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial"><span style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">I've recently been using cairo + xcb to build a new application. I've hit a problem supporting transparency / alpha-blending, where I want to allow users to set the background window with an alpha value and have the root x11 window show through that. The raw transparency piece works fine and is easy in cairo + xcb, but I'm struggling with my main render loop -- it seems to add / accumulate the alpha values with each render, and doesn't remove previously drawn content with alpha values. I have more details below including a fully functioning prototype with my layout setup (also below and in a gist), but here's what I've been trying after much google'ing and searching the archives:</span><br style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial"><span style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">My main render loop looks roughly like this (and I understand why this would accumulate opaqueness over time):</span><br style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial"><span style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">   // BEGIN render loop<br></span>   cairo_push_group(cairo);<br>   clear_background();<br>   // draw (lots of) stuff<br>   // END render loop<br>   cairo_pop_group_to_source(<wbr>cairo);<br>   cairo_paint(cairo);<br>   xcb_flush(xcon);<br>   sleep(1);<br style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial"><span style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">where clear_background() is:</span><br style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial">   cairo_set_source_rgba(cairo, 0.8, 0, 0, 0.1);<br>   cairo_paint(cairo);<br style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial"><span style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">With that loop, as-is, I can see why the alpha values are accumulating with each render.</span><br style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial"><span style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">To compensate, I've tried the following based on the cairo site's documentation, and browsing the archives, but with no success:</span><br style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial"><span style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">   1. </span><span style="font-family:monospace,monospace;text-decoration-style:initial;text-decoration-color:initial;font-size:small;float:none;display:inline">cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE); (and subsequent resets to *_OVER)<br></span><span style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">      I've tried this before the cairo_paint() at the END of the loop, as well as in the BEGIN loop (both before and after the cairo_push_group()).<br></span><span style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">      My understanding is that this copies the alpha from SOURCE as-is, with no blending, but I'm not observing that in the results, regardless of where I place it (and tweak the timing to confirm each step).<br></span><span style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">      Use of it *always* results in a black background, which makes me think I have something larger out-of-whack.</span><br style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial"><span style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">   2. I've looked at other operators, but none seem applicable (and I've tested most in various setups like the above).</span><br style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial"><span style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">   3. Using cairo_mask() / cairo_mask_surface() when using cairo_pop_group() (the raw one, returning a cairo_pattern_t) to render after the pop, but that also fails.</span><br style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial"><span style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">My ultimate goals are basically these:</span><br style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial"><span style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">   1. Have the window always reset to a consistent background of rgba = 0.8/0/0/0.1<br></span><span style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">   2. Don't 'accumulate' alpha artifacts from the widgets drawn in the loop each time</span><br style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial"><span style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">My sample code below illustrates what I'm trying and my setup.<br></span><span style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">It draws a 200 x 200 pixel window (at x,y = 200,200).<br></span><span style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">It has an initial background of rgba = 0.8/0/0/0.1,<br></span><span style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">and a 50x50 pixel green square in the top left (rgba=0/1/0/0.5).<br></span><span style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Every second it redraws, and moves the square towards the bottom right.</span><br style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial"><span style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">IDEALLY:<br></span><span style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">   1. The background is *always* rgba = 0.8/0/0/0.1<br></span><span style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">   2. Only one square (the most recent) is shown with rgba = 0/1/0/0.5</span><br style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial"><span style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">BUT what I observe (trying lots of variants):<br></span><span style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">   1. The background gets more opaque with each render, eventually becoming solid<br></span><span style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">   2. The previous renders of the green square persist and aren't cleared</span><br style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial"><span style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">The code is below, along with build instructions, and available at:<br></span><span style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">   </span><a href="https://gist.github.com/ryanflannery/1649ce3dd45cb6e16088931262283386" target="_blank" style="color:rgb(17,85,204);font-family:monospace,monospace;font-size:12.8px">https://gist.github.com/<wbr>ryanflannery/<wbr>1649ce3dd45cb6e160889312622833<wbr>86</a><br style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial"><span style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Note the example includes a great deal of XCB setup, including logic to handle tiling window managers (my use case). I doubt that's of interest here, but I'm including it for completeness (but below the main cairo logic).</span><br style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial"><span style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Any feedback appreciated (on this or other conventions I have!)</span><br style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial"><span style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Cheers,<br></span><span style="font-family:monospace,monospace;font-size:12.8px;text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">-Ryan</span></blockquote></div></div>