<div dir="ltr">If you keep your visible rectangles in a list you only need to call gdk_widget_draw_area() with coordinates of a rectangle either added or removed from your list. When adding you need to redraw the new area, and when removing you need to &quot;heal&quot; the area that the rectangle previously occupied. In your expose event you should clip your cairo drawing to the area that is being exposed, and then loop and draw all rectangles in your list. (I&#39;m still wondering whether it is faster to manually check whether the bounding box of the drawn objects fall within the bounding box of the exposed area, or simply to rely on cairo doing it efficiently.) <br>
<br>Hopefully this will be fast enough.<br><br>Regards,<br>Dov<br><br><div class="gmail_quote">On Wed, Aug 18, 2010 at 16:49, Benjamin Otte <span dir="ltr">&lt;<a href="mailto:otte@redhat.com">otte@redhat.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">A Gtk widget&#39;s expose event always prompts you to repaint all of the<br>
region provided completely. You cannot assume anything about what you<br>
previously rendered.<br>
<br>
So if you render everything with Cairo, what you usually want to for<br>
creating your Cairo context is run code like this:<br>
<br>
cr = gdk_cairo_create (event-&gt;window);<br>
gdk_cairo_region (cr, event-&gt;region);<br>
cairo_clip (cr);<br>
<br>
Then you end up with a region that is properly clipped to the area that<br>
actually needs to be repainted. But of course, you will still need to<br>
paint everything in that given region.<br>
Cairo will however be smart enough to ignore rectangles that are outside<br>
of that region automatically, because they are clipped.<br>
<br>
If that still doesn&#39;t turn out to be fast enough, you could maintain a<br>
backing surface that you update and then just cairo_paint() to the<br>
screen in the expose event. But I would be surprised if a few rectangles<br>
caused any trouble.<br>
<font color="#888888"><br>
Benjamin<br>
</font><div><div></div><div class="h5"><br>
<br>
On Wed, 2010-08-18 at 11:46 +0100, James Morris wrote:<br>
&gt; Hi,<br>
&gt;<br>
&gt; I&#39;m having some difficulty with understanding cairo and gtk and clipping.<br>
&gt;<br>
&gt; I need to draw rectangles that appear and disappear over time. I&#39;ve<br>
&gt; setup a gtk timeout which calls gtk_queue_draw on the window and the<br>
&gt; drawable in use by cairo as the surface - this provokes my expose<br>
&gt; event handler to be called. Here I call gdk_cairo_create, do my<br>
&gt; drawing, and then cairo_destroy.<br>
&gt;<br>
&gt; I asked about this on gtk-app-devel and had some responses but still<br>
&gt; seem to be stuck with erasure of what has been previously drawn each<br>
&gt; time something new is drawn (ie a new rectangle appears after some<br>
&gt; period of time has elapsed, drawing it erases all past rectangles).<br>
&gt;<br>
&gt; The solution seemed to be clipping. So I clip_preserve the rectangle<br>
&gt; and then fill it, but still everything else is erased.<br>
&gt;<br>
&gt; It was suggested I could dispense with the timeout. I don&#39;t think so,<br>
&gt; as the rectangles are dictated by another thread which only provides<br>
&gt; the dimensions of a rectangle when it should appear/disappear (getting<br>
&gt; this information in advance is not possible).<br>
&gt;<br>
&gt; My first working approach was to store in a list all the rectangles<br>
&gt; current in existence (and remove them when the disappear). Then on<br>
&gt; each call to the expose event handler the surface background and every<br>
&gt; rectangle would be drawn. With the timeout set at 33ms, and on average<br>
&gt; 200 rectangles appearing/disappearing per second, this approach proved<br>
&gt; too expensive of CPU resources. I decided then to try GDK and<br>
&gt; performance was a *lot* better and satisfactory, but then I discovered<br>
&gt; the GDK drawing and GDKGC functions are deprecated, hence a return to<br>
&gt; Cairo.<br>
&gt;<br>
&gt; Can anyone advise here please?<br>
&gt;<br>
&gt; Cheers,<br>
&gt; James<br>
&gt; --<br>
&gt; cairo mailing list<br>
&gt; <a href="mailto:cairo@cairographics.org">cairo@cairographics.org</a><br>
&gt; <a href="http://lists.cairographics.org/mailman/listinfo/cairo" target="_blank">http://lists.cairographics.org/mailman/listinfo/cairo</a><br>
<br>
<br>
--<br>
cairo mailing list<br>
<a href="mailto:cairo@cairographics.org">cairo@cairographics.org</a><br>
<a href="http://lists.cairographics.org/mailman/listinfo/cairo" target="_blank">http://lists.cairographics.org/mailman/listinfo/cairo</a><br>
</div></div></blockquote></div><br></div>