[cairo] Flickering on some scaling-values

Bryce Harrington bryce at osg.samsung.com
Thu Aug 21 12:55:07 PDT 2014


On Thu, Aug 21, 2014 at 11:44:11AM +0200, Andreas Wittmann wrote:
> Hi Mailinglist!
> 
> I'm new to cairo so this is maybe a simple question but i haven't
> found any answers using the internet. I'm using Linux/Debian and the
> newest cairo-release 1.12.16 (But my/this problem will also occur on
> previous releases!)
> 
> wxWidgets is also used, i'm using a simple render-function which
> looks like this and which is called from the wxWidgets-framework:
> 
> void BasicDrawPane::render(wxDC&  dc2)
> {
>     cairo_t* cairo_image = gdk_cairo_create((GdkWindow*)dc.GetHandle());
>     cairo_t *cr = cairo_image;
> 
>     cairo_scale(cr, global_scale_x, global_scale_y);
>     cairo_translate(cr, 0.5, 0.5);
> 
>     cairo_rectangle(cr, 0.0, 0.0, rect.width / global_scale_x,
> rect.height / global_scale_y);
>     cairo_set_source_rgb(cr, 255, 255, 255);
>     cairo_fill(cr);
> 
>      // drawing some shapes ...
> 
>     cairo_destroy(cairo_image);
> }
> 
> The shapes will be drawn (eg. from a mouse-event) without any
> flickering if the global-scales (global_scale_x, global_scale_y) are
> NOT 2.0, 4.0, 6.0, 8.0, 10.0, ... and so on. A value of eg. 2.1
> would work without any flickering.
> 
> Could anybody please give me some direction on how to solve this
> problem or why it happens?

First step is to determine what backend you're using, since each backend
can potentially redefine how the scaling function works.  Assuming
you're either using the image backend or something which just falls back
to the image backend's scaling function, what you'll want to study is
_cairo_gstate_scale.  It's not evident to me how having even integers
for the scale would produce weird behavior, but stepping through that
routine in a debugger might elicit some clues.

My guess is that there is an optimization going on which triggers only
when the scale is an even integer.  However poking around in the matrix
code I'm not spotting any such optimization so not really sure on that.

Btw, both scaling and translation are implemented under the hood as
matrix transformations.  Those two calls are just convenience wrappers
for manipulating the matrix.  So you can check that those two calls are
operating correctly by examining the matrix after the translation.
 
> The translation is used for drawing thin lines.

I assume since you're pointing out the translation, that it only
flickers when this is being done?  If so, then you might not need it; I
believe that trick only applies to strokes, so if you're just doing a
fill on a rect and not stroking it, you probably don't need to do that.

Btw, you might want to recheck your test case against current git, since
much has changed since the last release.

Bryce

> Thanks!
> regards
> Andreas
> -- 
> cairo mailing list
> cairo at cairographics.org
> http://lists.cairographics.org/mailman/listinfo/cairo


More information about the cairo mailing list