Understanding Hardware Acceleration on Mobile Browsers
Ariya Hidayat
Understanding Hardware Acceleration on Mobile Browsers Ariya - - PowerPoint PPT Presentation
Understanding Hardware Acceleration on Mobile Browsers Ariya Hidayat Magical Advice Use translate3d for hardware acceleration Challenges Game vs Web Game Text Textured objects Animation Physics Transformation Large but Still Bounded
Ariya Hidayat
Use translate3d for hardware acceleration
Animation Physics Textured objects Text Transformation
Images Text
Predictable contents (assets)
Mostly text
Mostly images
immediate
Initial response
Layout engine Network stack Graphics JavaScript engine User interface
Render Engine WebCore JavaScript Engine (JSC/V8) Client Interface HTML DOM CSS SVG Canvas
Network Unicode Clipboard Graphics Theme Events Thread Geolocation Timer
iOS Android CoreGraphics Skia Graphics stack GraphicsContext
CPU GPU
Vertices Matrix Rendered Textured
Transformation Textured triangles “Fixed” geometry Parallelism
http://epicgames.com/technology/epic-citadel http://www.rage.com/
http://www.trollquotes.org/619-super-spider-bat-troll-quote/
Path Triangle Rectangle Polygon Ellipse
Solid Dashed Dotted Textured
Solid None Gradient Textured
Only border Solid color fill Linear gradient fill Radial gradient fill 14x slower (depending on the dimension)
Curves Polygon
Multiple levels of transparency Perfect for parallelism
Involved pixel “blending” Often obstructed
Solid shadow Blur shadow 20x slower (depending on the blur radius)
http://www.w3.org/TR/CSS2/zindex.html Appendix E. Elaborate description of Stacking Contexts
12,000 pixels
Blur shadow
Scaling Rotation Perspective
Bye
Buffer
Hello!
Simple shape Solid color Curves Gradient brush Textured stroke Blur shadow Serif text Rotated Make it as an image
platformInit savePlatformState translate 0,0 translate 0,0 clip 1,0 0x6.95322e-310 fillRect 0,0 800x556 color ff ff ff ff restorePlatformState platformDestroy platformInit savePlatformState translate 0,0 translate 0,0 clip 1,0 0x6.95322e-310 fillRect 0,0 800x556 color ff ff ff ff restorePlatformState platformDestroy platformInit savePlatformState translate 0,0 translate 0,0 clip 1,0 0x6.95322e-310 fillRect 0,0 800x556 color ff ff ff ff fillRect 0,0 800x556 color ff ff ff ff
16:24:04.070 D/webcoreglue( 273): drawContent 11 ms 16:24:04.110 D/webcoreglue( 273): drawContent 13 ms 16:24:04.150 D/webcoreglue( 273): drawContent 13 ms 16:24:04.190 D/webcoreglue( 273): drawContent 10 ms 16:24:04.240 D/webcoreglue( 273): drawContent 10 ms 16:24:04.280 D/webcoreglue( 273): drawContent 13 ms 16:24:04.320 D/webcoreglue( 273): drawContent 13 ms 16:24:04.360 D/webcoreglue( 273): drawContent 13 ms 16:24:06.080 D/webcoreglue( 273): drawContent 12 ms 16:24:06.140 D/webcoreglue( 273): drawContent 10 ms 16:24:06.180 D/webcoreglue( 273): drawContent 13 ms 16:24:06.230 D/webcoreglue( 273): drawContent 14 ms 16:24:06.600 D/webcoreglue( 273): drawContent 26 ms 16:24:06.640 D/webcoreglue( 273): drawContent 13 ms 16:24:06.860 D/webcoreglue( 273): drawContent 33 ms 16:24:06.890 D/webcoreglue( 273): drawContent 12 ms 16:24:06.930 D/webcoreglue( 273): drawContent 13 ms 16:24:06.960 D/webcoreglue( 273): drawContent 13 ms 16:24:07.000 D/webcoreglue( 273): drawContent 13 ms
Tiles
Rendering User interaction Processor
when you pinch...
Web Page Rendering User interaction
Poor man’s indicator
Crisp but slow Fast but blurry
User pinches Smooth scaled Blocky (but fast!)
CPU GPU
.... ....
Streamed
What happens if the page background changes color?
Panning = Translation Zooming = Scaling
Y U NO position:fixed
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
Initialization Animation step “Hey, this is good stuff. Cache it as texture #42.” “Apply [operation] to texture #42.”
Not needed for CSS animation!
.someid {
}
Don’t do that
defaults write com.apple.Safari IncludeInternalDebugMenu 1
Composited layer Container layer No associated texture Overflow Texture (number = upload)
No reupload Upload
Opacity Position Size Animation Everything else!
“Hardware accelerated CSS”
@-webkit-keyframes box { 0% { -webkit-transform: background-color: blue; } 100% { -webkit-transform: background-color: green; } } Need a new texture uploaded to the GPU for every in-between color
Blended with
Viewport Hide the layer offscreen
Depending on user reaction
Prepare both animation and hide the “wrong” one
.... ....
Texture upload
Think of the GPU memory like a cache.
Drawing primitives Backing stores Layer & compositing
Traditional graphics programming has been always full of tricks. It will always be. There is no such
ariya.hidayat@gmail.com @AriyaHidayat ariya.ofilabs.com Wed 1:45 PM Office Hour