Draw multiple paths & performance

1,057 views
Skip to first unread message

hub...@gmail.com

unread,
Dec 11, 2015, 5:19:05 AM12/11/15
to skia-discuss
Hi,

I am working on a project where we want to be able to draw many paths (a few hundered up to a few thousand) with a different color. The problem we have is that the naive implementation by simply calling canvas->drawPath(path,paint) is too slow. If we discard the coloring of the paths and draw all with the same color, i.e. we call drawPath() only once, Skia is really fast. So I am wondering if there is a way to improve the performance, without signficantly reducing the number of calls to drawPath(), or is there a way to color indivdual parts of a Path differently.

Thanks in advance for you help!

Max

Cary Clark

unread,
Dec 11, 2015, 7:27:01 AM12/11/15
to skia-d...@googlegroups.com
Are the paths made up of lines or curves? Are the colored paths overlapping? Does the color have transparency? Are the paths filled or framed? How many colors are there?

We can be helpful if you can post an example that demonstrates what you're trying to do.

Take a look at fiddle.skia.org. If you can create a slow example there, we can analyze it and let you know if there are any techniques available to speed it up.

Cary

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To post to this group, send email to skia-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/skia-discuss.
For more options, visit https://groups.google.com/d/optout.

hub...@gmail.com

unread,
Dec 11, 2015, 9:41:51 AM12/11/15
to skia-discuss
Hi Cary,

Thank you very much for your quick reply!

The paths are made up of lines, and the paths might be overlapping. The color does not have to have transparency, however it would be nice. The paths are not filled, they simple lines. The number of different colors is usually 12 (to distinguish the different paths visually). 

This is kind of what we do (without the nonsene paths ;-) ):

void draw(SkCanvas* canvas) {

    for(int i = 0; i < 1000; i++) {
   SkPaint p;
    p.setAntiAlias(true);
    p.setStyle(SkPaint::kStroke_Style);
        
   SkPath path;
        
    SkScalar x = 0.0 + 2*i;
        SkScalar y = 0.0;
        
        if(i%2)
   p.setColor(SK_ColorRED);
else
   p.setColor(SK_ColorBLUE);

        path.moveTo(x, y);
   for (int j = 1; j < 100; j++) {            
        path.lineTo(x+j, y + 0.5*j);
            
        }
        canvas->drawPath(path,p);
    }
}

So we have a paint object for each path, and draw each path separately. 

I hope this made my question clearer.

Thank you!

Cary Clark

unread,
Dec 11, 2015, 11:36:59 AM12/11/15
to skia-d...@googlegroups.com
Can you create 12 paths, construct your geometry there, then draw each of the 12 with a different color?

Robert Phillips

unread,
Dec 11, 2015, 12:30:27 PM12/11/15
to skia-d...@googlegroups.com
Would SkCanvas::drawPoints(kLines_PointMode, ...) work for your use case ?

hub...@gmail.com

unread,
Dec 19, 2015, 8:06:16 AM12/19/15
to skia-discuss
Hi Cary, Hi Robert,

sorry for my late reply. Meanwhile I tried your suggestions. Carys approach works great for us. Thanks again!

Cheers
Max
Reply all
Reply to author
Forward
0 new messages