From Contents to Pixels HTML Parser DOM CSS Parser HTML Style Sheets DOM Tree Style Rules Render Tree Render Layout Paint http://www.html5rocks.com/en/tutorials/internals/howbrowserswork 8
DOM Tree vs Render Tree HTMLDocument HTMLBodyElement HTMLParagraphElement RenderRoot RenderBody RenderText tree structure/navigation metrics (box model) hit testing RenderStyle computed style many:1 10
Style Recalc vs Layout document.getElementById('box').style.top = '100px'; Aggregated “dirty” area document.getElementById('box').style.backgroundColor = 'red'; No layout necessary, metrics are not flagged as “changed” 11
GPU Physical Limitations • Memory: Can’t store too much stuff • Speed: Quad-core CPU can do certain operations better • Bandwidth: Data transfer can be the bottleneck • Power: Electrons always need energy 26
Immediate vs Retained draw the shape at (x, y) x = x + 10 blit the buffer at (x, y) x = x + 10 For every animation tick... At the beginning... draw the shape onto a buffer Off main thread 28
Animation Mechanics Initialization Animation step “Hey, this is good stuff. Cache it as texture #42.” “Apply [operation] to texture #42.” Animation loop 29
By Force transform: translateZ(0) Not needed for CSS animation! .someid { animation-name: somekeyframeanimation; animation-duration: 7s; transform: translateZ(0); } Don’t do that 32
Color Transition @keyframes box { 0% { transform: background-color: blue; } 100% { transform: background-color: green; } } Need a new texture uploaded to the GPU for every in-between color 49
Timer Latency Depending on user reaction Animation end triggers the JavaScript callback JavaScript code kicks the next animation Prepare both animation and hide the “wrong” one 51
Thank You [email protected] @AriyaHidayat ariya.ofilabs.com Background artwork from http://kde-look.org/content/show.php/Sin+Flow?content=139751 CC BY-NC-SA speakerdeck.com/ariya 57