[cairo] Performance stroking lines

Peter Clifton pcjc2 at cam.ac.uk
Wed Nov 14 14:35:16 PST 2007


Hi,

I'm trying to port an application (gschem, from the gEDA suite) to use
cairo for its internal drawing. This isn't an easy task, as the code
relied quite a lot on XOR drawing for rubber-banding operations.

This aside (having commented much of that code out), I've hit what might
be a show stopper. Dragging components around (admittedly as fast as I
could) consumes a lot of CPU time. (Can be about 50/50 Xorg / gschem on
one of my two cores. T2500?)

I've got a fast (ish) PC, but many of our users run recycled hardware.

I'm thinking I might have missed something basic. I'm drawing from the
expose handler (when GTK / GDK will pass me an X11 surface which it has
"redirected" to a back buffer).

I create a cairo surface from this using the appropriate gdk function,
and start drawing.

I've also tried another tactic.. creating a cairo image surface the same
size as my screen, rendering onto that and then using it as an source to
copy onto the GDK provided surface.


Can anyone advise of the "proper" way to do this (am I doing something
wrong?), and whether there are techniques to speedup dragging of blocks
of drawing over each other. This is component moving I'm testing, not
the true rubberbanding yet (where connected lines actually change shape
as I drag things).

Inkscape seems to consume similar CPU power dragging a single rectangle
- so perhaps its some issue with nice anti-aliased rendering just taking
more CPU power. That said, another electronics app I have installed is
able to drag components fast and barely register on my CPU graph.

I checked the code (which uses QCanvas / QPainter) for any obvious
frame-rate limiting in the app, but couldn't see anything. (My eyes
bleed trying to follow that code, not sure its the C++, QT or the app's
coding style which is making it difficult though!)


One big speedup I'm sure I'll get eventually is using pango / cairo for
text rendering. at present, text is made up of short(ish) line-segments
in the CAD database. (IE. the lines which make up the text are part of
the design.) I'll try to port this eventually, but is there any way to
speed up the current model?


Here is the tops of some oprofiles for the cases I mentioned. Although
the testing isn't very scientific (yet), I wonder if it the general
trend might hint at any mistakes I'm making.

(GDK double buffering off, cairo image surface)

samples  %        image name               app name                 symbol name
141133   40.5637  processor                processor                (no symbols)
11720     3.3685  libcairo.so.2.11.5       gschem                   fbRasterizeEdges
9128      2.6235  oprofiled                oprofiled                (no symbols)
4068      1.1692  libfb.so                 Xorg                     fbCopyAreammx
3931      1.1298  vmlinux-debug-2.6.22-14-generic vmlinux-debug-2.6.22-14-generic read_hpet
3690      1.0606  libc-2.6.1.so            gschem                   memcpy
3680      1.0577  libcairo.so.2.11.5       gschem                   _cairo_pixman_composite_solid_mask_nx8x8888mmx
2509      0.7211  libc-2.6.1.so            gschem                   _int_malloc
2471      0.7102  libc-2.6.1.so            Xorg                     memcpy
2395      0.6884  libcairo.so.2.11.5       gschem                   _cairo_pixman_composite
2345      0.6740  gschem                   gschem                   o_redraw
2261      0.6498  libgeda.so.30.0.2        gschem                   SCREENabs
2168      0.6231  libcairo.so.2.11.5       gschem                   _cairo_traps_tessellate_convex_quad
2100      0.6036  libcairo.so.2.11.5       gschem                   _cairo_traps_add_trap_from_points
2058      0.5915  libpthread-2.6.1.so      gschem                   pthread_mutex_lock
2045      0.5878  libcairo.so.2.11.5       gschem                   FbComputeCompositeRegion
2019      0.5803  libcairo.so.2.11.5       gschem                   __i686.get_pc_thunk.bx
1906      0.5478  oprofile                 oprofile                 (no symbols)
1896      0.5449  libgdk-x11-2.0.so.0.1200.0 gschem                   gdk_cairo_set_source_color
1881      0.5406  libcairo.so.2.11.5       gschem                   cairo_matrix_transform_distance
1749      0.5027  libpthread-2.6.1.so      gschem                   __pthread_mutex_unlock_usercnt
1720      0.4944  vmlinux-debug-2.6.22-14-generic vmlinux-debug-2.6.22-14-generic __copy_to_user_ll
1710      0.4915  libcairo.so.2.11.5       gschem                   _cairo_pixman_render_edge_init
1684      0.4840  ipw3945                  ipw3945                  (no symbols)
1498      0.4305  libcairo.so.2.11.5       gschem                   _cairo_path_fixed_interpret
1487      0.4274  libcairo.so.2.11.5       gschem                   _cairo_color_double_to_short
1421      0.4084  libc-2.6.1.so            gschem                   _int_free
1411      0.4055  libcairo.so.2.11.5       gschem                   _cairo_rectilinear_stroker_emit_segments
1353      0.3889  libcairo.so.2.11.5       gschem                   _cairo_pixman_render_sample_floor_y
1317      0.3785  libcairo.so.2.11.5       gschem                   _cairo_pixman_image_set_transform
1283      0.3688  libcairo.so.2.11.5       gschem                   cairo_matrix_transform_point
1260      0.3621  libm-2.6.1.so            gschem                   sin
1251      0.3596  libcairo.so.2.11.5       gschem                   _cairo_pen_init


(GDK Double buffering on, cairo image surface)

90623    21.7340  processor                processor                (no symbols)
24089     5.7772  libfb.so                 Xorg                     fbCopyAreammx
16343     3.9195  libfb.so                 Xorg                     fbRasterizeEdges
16316     3.9130  libfb.so                 Xorg                     fbCompositeSolidMask_nx8x8888mmx
5002      1.1996  oprofiled                oprofiled                (no symbols)
4212      1.0102  libc-2.6.1.so            gschem                   memcpy
3949      0.9471  vmlinux-debug-2.6.22-14-generic vmlinux-debug-2.6.22-14-generic read_hpet
3265      0.7830  libpthread-2.6.1.so      gschem                   pthread_mutex_lock
3003      0.7202  libfb.so                 Xorg                     fbComposite
2976      0.7137  oprofile                 oprofile                 (no symbols)
2878      0.6902  gschem                   gschem                   o_redraw
2764      0.6629  Xorg                     Xorg                     RenderEdgeInit


(GDK Double buffering on, cairo direct on to X11 provided surface)


71402    17.6780  0              0  processor                processor                (no symbols)
20296     5.0250  0              0  libfb.so                 Xorg                     fbRasterizeEdges
11612     2.8749  0              0  oprofiled                oprofiled                (no symbols)
5681      1.4065  0              0  libfb.so                 Xorg                     fbCompositeSolidMask_nx8x8888mmx
4449      1.1015  0              0  libc-2.6.1.so            gschem                   memcpy
4003      0.9911  0              0  vmlinux-debug-2.6.22-14-generic vmlinux-debug-2.6.22-14-generic read_hpet
3506      0.8680  0              0  libfb.so                 Xorg                     fbComposite
3450      0.8542  0              0  libpthread-2.6.1.so      gschem                   pthread_mutex_lock
3283      0.8128  139       9.1568  Xorg                     Xorg                     RenderEdgeInit
3159      0.7821  0              0  libc-2.6.1.so            Xorg                     _int_malloc
3092      0.7655  0              0  gschem                   gschem                   o_redraw
2961      0.7331  0              0  ipw3945                  ipw3945                  (no symbols)
2929      0.7252  0              0  oprofile                 oprofile                 (no symbols)
2913      0.7212  93        6.1265  Xorg                     Xorg                     __divdi3
2851      0.7059  0              0  libpthread-2.6.1.so      gschem                   __pthread_mutex_unlock_usercnt
2775      0.6870  0              0  libfb.so                 Xorg                     fbCopyAreammx
2720      0.6734  0              0  Xorg                     Xorg                     __i686.get_pc_thunk.bx
2675      0.6623  274      18.0501  libgeda.so.30.0.2        gschem                   SCREENabs
2620      0.6487  0              0  Xorg                     Xorg                     miComputeCompositeRegion
2511      0.6217  0              0  libcairo.so.2.11.5       gschem                   _cairo_traps_add_trap_from_points
2422      0.5996  293      19.3017  libgdk-x11-2.0.so.0.1200.0 gschem                   gdk_cairo_set_source_color
2371      0.5870  0              0  libcairo.so.2.11.5       gschem                   _cairo_fixed_from_double
2345      0.5806  232      15.2833  Xorg                     Xorg                     RenderSampleFloorY
2344      0.5803  0              0  libcairo.so.2.11.5       gschem                   _cairo_traps_tessellate_convex_quad
2337      0.5786  0              0  Xorg                     Xorg                     XaceHook
2333      0.5776  0              0  libcairo.so.2.11.5       gschem                   __i686.get_pc_thunk.bx
2330      0.5769  0              0  libfb.so                 Xorg                     fbSolidFillmmx
2242      0.5551  0              0  Xorg                     Xorg                     miLineFixedX
2224      0.5506  0              0  libcairo.so.2.11.5       gschem                   cairo_matrix_transform_distance
2207      0.5464  0              0  libcairo.so.2.11.5       gschem                   _cairo_xlib_surface_set_attributes
2160      0.5348  0              0  libcairo.so.2.11.5       gschem                   cairo_matrix_multiply
2151      0.5326  0              0  libcairo.so.2.11.5       gschem                   cairo_matrix_init
2132      0.5278  0              0  libfb.so                 Xorg                     fbValidateGC
2096      0.5189  0              0  libfb.so                 Xorg                     fbSolid
1994      0.4937  0              0  libc-2.6.1.so            Xorg                     _int_free
1983      0.4910  0              0  libcairo.so.2.11.5       gschem                   _cairo_color_double_to_short
1955      0.4840  0              0  Xorg                     Xorg                     ReadRequestFromClient
1816      0.4496  0              0  libcairo.so.2.11.5       gschem                   _cairo_restrict_value
1782      0.4412  113       7.4440  Xorg                     Xorg                     RenderSampleCeilY
1719      0.4256  1         0.0659  libfb.so                 Xorg                     fbRasterizeTrapezoid
1677      0.4152  0              0  Xorg                     Xorg                     SecurityLookupIDByType
1672      0.4140  0              0  libcairo.so.2.11.5       gschem                   cairo_matrix_transform_point
1671      0.4137  0              0  libxaa.so                Xorg                     XAAComposite
1652      0.4090  0              0  Xorg                     Xorg                     CompositePicture


Best wishes,

-- 
Peter Clifton

Electrical Engineering Division,
Engineering Department,
University of Cambridge,
9, JJ Thomson Avenue,
Cambridge
CB3 0FA

Tel: +44 (0)7729 980173 - (No signal in the lab!)



More information about the cairo mailing list