by derefr · 10y ago · 0 comments
Is CSS effectively "free", or is this just not a complex-enough example to start to see problems?
Far from being "free" unfortunately. Especially if it is made on CPU side. But modern browsers are trying to use GPU for that. GPU has a primitive operation: render triangle with three colors at corners. So for non-trivial gradients you will need (on CPU side) to do so called triangulation to produce meshes containing such triangles: http://www.svgopen.org/2011/papers/18-Advanced_Gradients_for.... And then you need to send that mesh to GPU for batch rendering. Quite complex machinery.
Flash and Java were trying to do all that on CPU side. But with high DPI monitors (like 300 PPI Retina - 9 times more pixels on screens) CPU rasterization is not the option anymore.
https://www.chromium.org/developers/design-documents/gpu-acc...
(I actually spoke with them personally about this while I was still at Google, but there's the design doc. It's been 2 years, so perhaps the internals have changed, but this was also the situation in WebKit at the time as well.)
And you do see weird pixelation effects - try rendering some text to a div and then animating 'transform: scale()'. You lose font antialiasing during the animation, which is why many sites that do this will fade out the text first, animate only the bounding box, and then fade the text back in.
http://www.keithclark.co.uk/labs/css-fps/nojs/
Edit: The site seems to be overloaded. Here's an archive:
https://web.archive.org/web/20160702222211/http://keithclark...
For me, it doesn't run well on FF, but neatly in Chrome. Huge difference.
What a time to be alive.
Not strictly true; it's also possible to animate SVGs using ECMAScript or SMIL: https://www.w3.org/TR/SVG/animate.html
The difference is SVG + CSS is a better abstraction for creating illustrations than crazy CSS gradient and box shadow hacks.
That would depend on your browser. Because AFAIK there is nothing in the CSS spec that guarantees any minimum performance.
So don't count on it being fast!