3 ms·
> Browser vendors with cross-platform drawing kits just don't invest the same kind of effort into drawing lines and circles. As a result, large <canvas> areas s
by pcwalton 14y ago
> Browser vendors with cross-platform drawing kits just don't invest the same kind of effort into drawing lines and circles. As a result, large <canvas> areas seem laggy on most browsers, whereas native apps “just work”. (“Are the graphics pre-computed?”)
This is incorrect. Firefox and Safari use Core Graphics (Quartz) just as Mac native apps do. Things like lines and circles go through the exact same SSE-accelerated routines. I don't know off the top of my head whether Chrome uses Skia or Core Graphics on the Mac, but either way, its blitting routines use SSE optimizations as well.
- checker659 14y agoYes, Skia makes use of SSE2/3. He pulled that right out of his ass.
- stevejohnson 14y agoTechnical reasons aside, the canvas tag is still orders of magnitude slower than writing Core Graphics by hand. Personally I'd say almost unacceptably slow, but YMMV. You succeeded in picking out a minor technical inaccuracy, but not in addressing the point the author was making about rendering performance.
- ccgus 14y agoOne of the reasons it's slow is because CG bitmap contexts are pre-multiplied, but the Canvas spec requires things to be not-premultiplied, so there's a bit of extra math that needs to happen w/ Canvas vs. straight CG/Quartz.
- daeken 14y ago> the Canvas spec requires things to be not-premultiplied It does, but unfortunately neither Webkit nor Gecko respect this. Take a PNG with an alpha channel and draw it to a canvas over a white div then read back the pixels; you get the pixels premultiplied by the white behind it. Same with other backing colors. There are cases where it won't premultiply, but unfortunately they're a minority. (The reason I ran across this particular case is that I use PNGs to compress data, and using the alpha channel to store data is impossible because of the premultiplication.)
- gdubs 14y agoWell, of course browsers are going to render ultimately with the platform's native drawing functions -- which have undoubtably been optimized. The issue is the high-level of abstraction between the description of what is to be drawn, and the drawing calls themselves. This is fine for a majority of tasks, but when it becomes a bottleneck your hands are pretty tied. Native apps have much more direct control over threading, vector processing, audio devices, networking, etc.