SlideShare a Scribd company logo
1 of 82
Download to read offline
Understanding
                        WebKit Rendering


                             Ariya Hidayat




Sunday, October 7, 12
whoami




Sunday, October 7, 12
Sunday, October 7, 12
WebKit




Sunday, October 7, 12
WebKit is Everywhere




Sunday, October 7, 12
Browser at a High Level


                                        User Interface




                                                                    Data Persistence
                                     Browser Engine




                                     Render Engine



                        Networking     JavaScript        Graphics
                           I/O           Engine           Stack




Sunday, October 7, 12
WebKit Components

                                              Render Engine
                                                  CSS
                                DOM                                  SVG



                    HTML                                                         Canvas

                                                 WebCore




                           Client Interface                JavaScript Engine (JSC/V8)



Sunday, October 7, 12
Platform Abstraction

                        Networking
                                     Thread         Geolocation    Timer
                           I/O

                                         Client Interface

                        Clipboard    Events           Theme       Graphics




                                        API Calls
                                         Events

                                             Port
                                      (Chrome, Safari, etc.)


Sunday, October 7, 12
Layout




Sunday, October 7, 12
From Contents to Pixels


                                                        DOM

                                                                       Render
                                                                       Layout
                                   HTML                 DOM
                   HTML
                                   Parser               Tree

                                                                       Render                 Paint
                                                                        Tree

                   Style            CSS                 Style
                  Sheets           Parser               Rules



                           http://www.html5rocks.com/en/tutorials/internals/howbrowserswork


Sunday, October 7, 12
DOM Tree


                        <html><body><p>Hello</p></body></html>



           HTMLDocument

                   HTMLBodyElement

                        HTMLParagraphElement           attributes, children, contents




Sunday, October 7, 12
HTML Parsing


                                                           tag

                                                         <html><body><p>Hello</p></body></html>
      Loader                         Tokenizer
                                                                        text



                                                                                              DOM Tree
  May come in chunks
                                          Tree Builder




                                                                          Section 12.2 in HTML Specification

          http://www.whatwg.org/specs/web-apps/current-work/multipage/parsing.html#parsing


Sunday, October 7, 12
DOM Tree vs Render Tree



            HTMLDocument                                    RenderRoot

                 HTMLBodyElement                                RenderBody

                        HTMLParagraphElement                           RenderText




                                There is no Render* for display:none



Sunday, October 7, 12
“Attach” Process

                        Historical: Node is invisible, attach it to the main view to make it visible



                                                          View




                                           1:1                               many:1
            Node/Element                             RenderObject                       RenderStyle
                                                 tree structure/navigation
              <div>42</div>                                                             computed style
                                                    metrics (box model)
                                                         hit testing


                                                                                           another tree structure



Sunday, October 7, 12
Sunday, October 7, 12
It’s a forest!




Sunday, October 7, 12
Effects of Style Recalc and 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”

Sunday, October 7, 12
Getting the Right Style
                                                                          Stylesheet List


          HTMLDocument
                                                                    p { color: blue }
                 HTMLBodyElement
                        HTMLParagraphElement


                  DOM Tree


                                                           RenderStyle




                CSS Style Selector: id, class, tags, ...




Sunday, October 7, 12
Minimizing Layout

                                             Element

                              clientHeight
                                                         focus()
                              clientLeft
                                                         getBoundingClientRect()
                              clientTop
                                                         getClientRects()
                              clientWidth
                                                         scrollByLines()
                              offsetHeight
                                                         scrollByPages()
                              offsetLeft
                                                         scrollHeight
                              offsetParent
                                                         scrollIntoView()
                              offsetTop
                                                         scrollIntoViewIfNeeded()
                              offsetWidth
                              scrollLeft
                              scrollTop
                              scrollWidth
                              innerText
                              outerText



                        http://gent.ilcore.com/2011/03/how-not-to-trigger-layout-in-webkit.html

    http://code.google.com/p/chromium/source/search?q=%22-%3EupdateLayoutIgnorePendingStylesheets()%22


Sunday, October 7, 12
Painting




Sunday, October 7, 12
Goals of Painting

       • “Visualize” all RenderObjects (again, tree traversal)


       • All painting commands go to GraphicsContext abstraction


       • Important
                                                  Optimizations
             • Clipped to the visible viewport


             • Back-to-front

                            Transparency &
                                clipping




Sunday, October 7, 12
CSS Painting: 10 Stages

                               http://www.w3.org/TR/CSS2/zindex.html

                        Appendix E. Elaborate description of Stacking Contexts




                                  •
                                   Background
                                  •
                                   Floats
                                  •
                                   Foreground
                                  •
                                   Selection                 Done by the render objects
                                  •
                                   Outline                      (in the render tree)




Sunday, October 7, 12
Graphics Abstraction

                                                       Chromium
                                                        Android               Qt
                                         Mac & iOS
           GraphicsContext



                                                            Skia

                                       CoreGraphics
                                                                           QPainter



                                                                   graphics stack




                    Native controls,
                                              RenderTheme
                  e.g. form elements

Sunday, October 7, 12
Painting Flow: Browser vs WebKit

                        Browser                                                           WebKit


                             User scrolls
                             the viewport

                                                      Request painting, GraphicsContext
                                                                                              Sometimes to the
                                                                                               backing store



                                                                       Style change


                                        Mark “dirty” area




Sunday, October 7, 12
Path is Everything




Sunday, October 7, 12
Stroke = Outline




                    Solid   Dashed   Dotted   Textured


Sunday, October 7, 12
Brush = Fill




             None       Solid   Gradient   Textured




Sunday, October 7, 12
Gradient = Non-uniform Pixel Values




Sunday, October 7, 12
Drawing Time: Solid vs Gradient



                         Only border

                                                    14x slower
                        Solid color fill   (depending on the dimension)

             Linear gradient fill

             Radial gradient fill




Sunday, October 7, 12
Path Approximation


                    Curves




                             Polygon




Sunday, October 7, 12
Antialiasing


                        Multiple levels of transparency




Sunday, October 7, 12
Transformation




                   Scaling
                                        Perspective
                             Rotation




Sunday, October 7, 12
Text Rasterization




Sunday, October 7, 12
Font Atlas


                        Buffer




                                 Bye




Sunday, October 7, 12
Simple to Complex



                                     ell o!
                                    H


                   Simple shape
                    Solid color       Curves
                                  Gradient brush
                                  Textured stroke
                                   Blur shadow
                                     Serif text
                                     Rotated



Sunday, October 7, 12
Simple to Complex



                                                           ell o!
                                                          H


                   Simple shape
                    Solid color                             Curves
                                                        Gradient brush
                                                        Textured stroke
                                                         Blur shadow
                                                           Serif text
                                  Make it as an image
                                                           Rotated



Sunday, October 7, 12
Hardware Acceleration




Sunday, October 7, 12
Game vs Web




Sunday, October 7, 12
Game


                                                          Text




                                                                 Textured
                                                                  objects
                        Animation




                               Transformation   Physics




Sunday, October 7, 12
Large Area, but Still Bounded




Sunday, October 7, 12
Web Page




                               Images

                        Text




Sunday, October 7, 12
Challenges




        Predictable contents (assets)   ✔
         Mostly text                          ✔
         Mostly images                  ✔
         Initial response                   immediate



Sunday, October 7, 12
SoC = System-on-a-Chip




                                CPU   GPU




Sunday, October 7, 12
GPU Workflow




                          Matrix




               Vertices            Rendered   Textured




Sunday, October 7, 12
Optimized for Games

                              “Fixed” geometry


                             Transformation


                             Textured triangles




                                     Parallelism




Sunday, October 7, 12
Powerful Capabilities




            http://epicgames.com/technology/   http://www.rage.com/
                        epic-citadel



Sunday, October 7, 12
http://www.trollquotes.org/619-super-spider-bat-troll-quote/
Sunday, October 7, 12
Fundamental 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




Sunday, October 7, 12
Traffic Congestion




Sunday, October 7, 12
Efficient Use of GPU




                 Drawing      Backing     Layer &
                 primitives    stores   compositing


Sunday, October 7, 12
Maps




                        Tile




Sunday, October 7, 12
Pinch to Zoom




         when you pinch...




Sunday, October 7, 12
Responsive Interface



                                                 decoupled
                        Rendering

                                Processor

                                        User interaction


Sunday, October 7, 12
Rendering vs Interaction



                                                            Screen
                                    Backing Store
                        Rendering




     Web Page                                       User interaction




Sunday, October 7, 12
Checkerboard Pattern




Sunday, October 7, 12
Progressive Rendering


                        Fast but blurry




                                          Crisp but slow


Sunday, October 7, 12
Perceived Responsiveness


                        User pinches




                                                        Smooth scaled

                                   Blocky (but fast!)




Sunday, October 7, 12
Tiling System




                                 Texture upload


                          ....                ....



                    CPU                              GPU


Sunday, October 7, 12
Tile Transformation




            Panning = Translation   Zooming = Scaling

Sunday, October 7, 12
Checkerboard Pattern




Sunday, October 7, 12
Typical Animation




                        opacity, movement, scaling, rotation, ...




Sunday, October 7, 12
Principles of Fluid Animation



                             At the beginning, push as many
                        1
                            resources as possible to the GPU


                        2    During the animation, minimize
                                  CPU-GPU interaction




Sunday, October 7, 12
Immediate vs Retained
                                   At the beginning...

                                                    draw the shape onto a
                                                            buffer



                               For every animation tick...

                                                    blit the buffer at (x,
                  draw the shape at (x, y)
                                                              y)
                         x = x + 10
                                                          x = x + 10

                                                             Off main thread



Sunday, October 7, 12
Mechanics of Animation

                                         “Hey, this is good stuff. Cache it as texture




                        Initialization




                                            “Apply [operation] to texture #42.”




                    Animation step



Sunday, October 7, 12
Elements = Layer




Sunday, October 7, 12
Logical 3-D




Sunday, October 7, 12
Compositing By Force

                        -webkit-transform: translateZ(0)



                             Not needed for CSS

                                        .someid {
                        -webkit-animation-name: somekeyframeanimation;
                               -webkit-animation-duration: 7s;
                              -webkit-transform: translateZ(0);
                                            }


                                        Don’t do that

Sunday, October 7, 12
Magical Advice
                         Use translate3d for
                        hardware acceleration




Sunday, October 7, 12
Magical Advice
                         Use translate3d for
                        hardware acceleration




Sunday, October 7, 12
Debugging in Safari


              defaults write com.apple.Safari IncludeInternalDebugMenu 1




Sunday, October 7, 12
Compositing Indicators

                                Texture (number = upload)


                                   Composited layer



                                 No associated texture


                                     Container layer


                                        Overflow




Sunday, October 7, 12
Avoid Texture Reupload


                        No reupload                     Upload



                           Opacity
                           Position                Everything else!
                            Size
                          Animation



                                 “Hardware accelerated CSS”



Sunday, October 7, 12
Examples




Sunday, October 7, 12
Color Transition

                        @-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


Sunday, October 7, 12
Color Transition: The Trick




                              Blended with




                                         http://jsfiddle.net/79AVn
Sunday, October 7, 12
Prepare and Reuse




                                   Hide the layer
                                     offscreen




                        Viewport




Sunday, October 7, 12
Timer Latency

                                                              Depending
                                                               on user




                        Animation end triggers the JavaScript callback
                          JavaScript code kicks the next animation


                                             Prepare both
                                         animation and hide the
                                              “wrong” one


Sunday, October 7, 12
Avoid Overcapacity




                                   ....        ....




                        Think of the GPU memory like a cache.




Sunday, October 7, 12
Conclusion




Sunday, October 7, 12
Rendering Aspects




Sunday, October 7, 12
There is No Silver Bullet




Sunday, October 7, 12
Thank You



                        ariya.hidayat@gmail.com



                        ariya.ofilabs.com



                        @AriyaHidayat




Sunday, October 7, 12

More Related Content

What's hot

What's hot (20)

Basic of HTML, CSS(StyleSheet), JavaScript(js), Bootstrap, JSON & AngularJS
Basic of HTML, CSS(StyleSheet), JavaScript(js), Bootstrap, JSON & AngularJSBasic of HTML, CSS(StyleSheet), JavaScript(js), Bootstrap, JSON & AngularJS
Basic of HTML, CSS(StyleSheet), JavaScript(js), Bootstrap, JSON & AngularJS
 
(Fast) Introduction to HTML & CSS
(Fast) Introduction to HTML & CSS (Fast) Introduction to HTML & CSS
(Fast) Introduction to HTML & CSS
 
JavaScript and BOM events
JavaScript and BOM eventsJavaScript and BOM events
JavaScript and BOM events
 
AngularJS Directives
AngularJS DirectivesAngularJS Directives
AngularJS Directives
 
jQuery
jQueryjQuery
jQuery
 
NodeJS for Beginner
NodeJS for BeginnerNodeJS for Beginner
NodeJS for Beginner
 
Bootstrap 4 Tutorial PDF for Beginners - Learn Step by Step
Bootstrap 4 Tutorial PDF for Beginners - Learn Step by StepBootstrap 4 Tutorial PDF for Beginners - Learn Step by Step
Bootstrap 4 Tutorial PDF for Beginners - Learn Step by Step
 
Node.js Express Framework
Node.js Express FrameworkNode.js Express Framework
Node.js Express Framework
 
CSS
CSSCSS
CSS
 
Introduction to CSS3
Introduction to CSS3Introduction to CSS3
Introduction to CSS3
 
Express JS
Express JSExpress JS
Express JS
 
Html5 Basics
Html5 BasicsHtml5 Basics
Html5 Basics
 
Aula 02
Aula 02Aula 02
Aula 02
 
Html basics
Html basicsHtml basics
Html basics
 
Getting started with Redux js
Getting started with Redux jsGetting started with Redux js
Getting started with Redux js
 
Intro to HTML & CSS
Intro to HTML & CSSIntro to HTML & CSS
Intro to HTML & CSS
 
Rendering engine
Rendering engineRendering engine
Rendering engine
 
Jquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript BasicsJquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript Basics
 
HTML (Web) basics for a beginner
HTML (Web) basics for a beginnerHTML (Web) basics for a beginner
HTML (Web) basics for a beginner
 
GitBlit plugin for Gerrit Code Review
GitBlit plugin for Gerrit Code ReviewGitBlit plugin for Gerrit Code Review
GitBlit plugin for Gerrit Code Review
 

Viewers also liked

WebKit, HTML5 media and GStreamer on multiple platforms
WebKit, HTML5 media and GStreamer on multiple platforms WebKit, HTML5 media and GStreamer on multiple platforms
WebKit, HTML5 media and GStreamer on multiple platforms
philn2
 
Introduction to QtWebKit
Introduction to QtWebKitIntroduction to QtWebKit
Introduction to QtWebKit
Ariya Hidayat
 
WebKit vs. the mobile Web
WebKit vs. the mobile WebWebKit vs. the mobile Web
WebKit vs. the mobile Web
Josh Tumath
 
WebKitGtk+ Project
WebKitGtk+ ProjectWebKitGtk+ Project
WebKitGtk+ Project
Joone Hur
 

Viewers also liked (20)

Hardware Acceleration in WebKit
Hardware Acceleration in WebKitHardware Acceleration in WebKit
Hardware Acceleration in WebKit
 
WebKit and Blink: Bridging the Gap Between the Kernel and the HTML5 Revolution
WebKit and Blink: Bridging the Gap Between the Kernel and the HTML5 RevolutionWebKit and Blink: Bridging the Gap Between the Kernel and the HTML5 Revolution
WebKit and Blink: Bridging the Gap Between the Kernel and the HTML5 Revolution
 
WebKit and GStreamer
WebKit and GStreamerWebKit and GStreamer
WebKit and GStreamer
 
WebKit, HTML5 media and GStreamer on multiple platforms
WebKit, HTML5 media and GStreamer on multiple platforms WebKit, HTML5 media and GStreamer on multiple platforms
WebKit, HTML5 media and GStreamer on multiple platforms
 
Introduction to QtWebKit
Introduction to QtWebKitIntroduction to QtWebKit
Introduction to QtWebKit
 
WebKit2 And You (GUADEC 2013)
WebKit2 And You (GUADEC 2013)WebKit2 And You (GUADEC 2013)
WebKit2 And You (GUADEC 2013)
 
FrontTalks: Вадим Макеев (Opera Software), «Зачем Опере Вебкит, или Опиум для...
FrontTalks: Вадим Макеев (Opera Software), «Зачем Опере Вебкит, или Опиум для...FrontTalks: Вадим Макеев (Opera Software), «Зачем Опере Вебкит, или Опиум для...
FrontTalks: Вадим Макеев (Opera Software), «Зачем Опере Вебкит, или Опиум для...
 
WebKit vs. the mobile Web
WebKit vs. the mobile WebWebKit vs. the mobile Web
WebKit vs. the mobile Web
 
פיתוח אפליקציות Webkit לדפדפנים סלולריים Ppt
פיתוח אפליקציות Webkit לדפדפנים סלולריים Pptפיתוח אפליקציות Webkit לדפדפנים סלולריים Ppt
פיתוח אפליקציות Webkit לדפדפנים סלולריים Ppt
 
WebKit and Blink: open development powering the HTML5 revolution
WebKit and Blink: open development powering the HTML5 revolutionWebKit and Blink: open development powering the HTML5 revolution
WebKit and Blink: open development powering the HTML5 revolution
 
Measuring Web Performance - 自己満足で終わらないためのパフォーマンス計測 -
Measuring Web Performance - 自己満足で終わらないためのパフォーマンス計測 -Measuring Web Performance - 自己満足で終わらないためのパフォーマンス計測 -
Measuring Web Performance - 自己満足で終わらないためのパフォーマンス計測 -
 
WebKit, why it matters (PDF version)
WebKit, why it matters (PDF version)WebKit, why it matters (PDF version)
WebKit, why it matters (PDF version)
 
WebKitGtk+ Project
WebKitGtk+ ProjectWebKitGtk+ Project
WebKitGtk+ Project
 
Guides To Analyzing WebKit Performance
Guides To Analyzing WebKit PerformanceGuides To Analyzing WebKit Performance
Guides To Analyzing WebKit Performance
 
Quran as guidance
Quran as guidanceQuran as guidance
Quran as guidance
 
Guidance from the noble Quran edited by shaykh mufti afzal hoosen elias
Guidance from the noble Quran edited by shaykh mufti afzal hoosen eliasGuidance from the noble Quran edited by shaykh mufti afzal hoosen elias
Guidance from the noble Quran edited by shaykh mufti afzal hoosen elias
 
Irfan e hidayat az ifadat imam e ahle sunnat
Irfan e hidayat az ifadat imam e ahle sunnatIrfan e hidayat az ifadat imam e ahle sunnat
Irfan e hidayat az ifadat imam e ahle sunnat
 
Understanding Hardware Acceleration on Mobile Browsers
Understanding Hardware Acceleration on Mobile BrowsersUnderstanding Hardware Acceleration on Mobile Browsers
Understanding Hardware Acceleration on Mobile Browsers
 
Presentasi narkoba2013
Presentasi narkoba2013Presentasi narkoba2013
Presentasi narkoba2013
 
[KOR][E-Kor-Seminar 2014][2/8] Webkit EFL (Ryuan)
[KOR][E-Kor-Seminar 2014][2/8] Webkit EFL (Ryuan)[KOR][E-Kor-Seminar 2014][2/8] Webkit EFL (Ryuan)
[KOR][E-Kor-Seminar 2014][2/8] Webkit EFL (Ryuan)
 

Similar to Understanding Webkit Rendering

Document Object Model
Document Object ModelDocument Object Model
Document Object Model
chomas kandar
 
Integrate Spring MVC with RequireJS & Backbone.js & Spring Data JPA
Integrate Spring MVC with RequireJS & Backbone.js & Spring Data JPAIntegrate Spring MVC with RequireJS & Backbone.js & Spring Data JPA
Integrate Spring MVC with RequireJS & Backbone.js & Spring Data JPA
Cheng Ta Yeh
 
Single page applications mit asp.net mvc und der asp.net web api
Single page applications mit asp.net mvc und der asp.net web apiSingle page applications mit asp.net mvc und der asp.net web api
Single page applications mit asp.net mvc und der asp.net web api
Alexander Zeitler
 
Custom Android Code Templates
Custom Android Code TemplatesCustom Android Code Templates
Custom Android Code Templates
murphonic
 
J Query(04 12 2008) Foiaz
J Query(04 12 2008) FoiazJ Query(04 12 2008) Foiaz
J Query(04 12 2008) Foiaz
testingphase
 

Similar to Understanding Webkit Rendering (20)

Document Object Model
Document Object ModelDocument Object Model
Document Object Model
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Model
 
Integrate Spring MVC with RequireJS & Backbone.js & Spring Data JPA
Integrate Spring MVC with RequireJS & Backbone.js & Spring Data JPAIntegrate Spring MVC with RequireJS & Backbone.js & Spring Data JPA
Integrate Spring MVC with RequireJS & Backbone.js & Spring Data JPA
 
Introduction to Web Programming
Introduction to Web ProgrammingIntroduction to Web Programming
Introduction to Web Programming
 
Understanding the dom by Benedict Ayiko
Understanding the dom by Benedict AyikoUnderstanding the dom by Benedict Ayiko
Understanding the dom by Benedict Ayiko
 
Single page applications mit asp.net mvc und der asp.net web api
Single page applications mit asp.net mvc und der asp.net web apiSingle page applications mit asp.net mvc und der asp.net web api
Single page applications mit asp.net mvc und der asp.net web api
 
Custom Android Code Templates
Custom Android Code TemplatesCustom Android Code Templates
Custom Android Code Templates
 
Build and Deploy Sites Using Features
Build and Deploy Sites Using Features Build and Deploy Sites Using Features
Build and Deploy Sites Using Features
 
IOC + Javascript
IOC + JavascriptIOC + Javascript
IOC + Javascript
 
Polymer and web component
Polymer and web componentPolymer and web component
Polymer and web component
 
Familiar HTML5 - 事例とサンプルコードから学ぶ 身近で普通に使わているHTML5
Familiar HTML5 - 事例とサンプルコードから学ぶ 身近で普通に使わているHTML5Familiar HTML5 - 事例とサンプルコードから学ぶ 身近で普通に使わているHTML5
Familiar HTML5 - 事例とサンプルコードから学ぶ 身近で普通に使わているHTML5
 
Modular applications with montage components
Modular applications with montage componentsModular applications with montage components
Modular applications with montage components
 
ActiveDOM
ActiveDOMActiveDOM
ActiveDOM
 
Client Server 3.0 - 6 Ways JavaScript is Revolutionizing the Client/Server Re...
Client Server 3.0 - 6 Ways JavaScript is Revolutionizing the Client/Server Re...Client Server 3.0 - 6 Ways JavaScript is Revolutionizing the Client/Server Re...
Client Server 3.0 - 6 Ways JavaScript is Revolutionizing the Client/Server Re...
 
It is not HTML5. but ... / HTML5ではないサイトからHTML5を考える
It is not HTML5. but ... / HTML5ではないサイトからHTML5を考えるIt is not HTML5. but ... / HTML5ではないサイトからHTML5を考える
It is not HTML5. but ... / HTML5ではないサイトからHTML5を考える
 
HTML literals, the JSX of the platform
HTML literals, the JSX of the platformHTML literals, the JSX of the platform
HTML literals, the JSX of the platform
 
J Query(04 12 2008) Foiaz
J Query(04 12 2008) FoiazJ Query(04 12 2008) Foiaz
J Query(04 12 2008) Foiaz
 
Exploring Critical Rendering Path
Exploring Critical Rendering PathExploring Critical Rendering Path
Exploring Critical Rendering Path
 
Jdbc Dao it-slideshares.blogspot.com
Jdbc Dao it-slideshares.blogspot.comJdbc Dao it-slideshares.blogspot.com
Jdbc Dao it-slideshares.blogspot.com
 
Web components
Web componentsWeb components
Web components
 

More from Ariya Hidayat

Understanding Hardware Acceleration on Mobile Browsers
Understanding Hardware Acceleration on Mobile BrowsersUnderstanding Hardware Acceleration on Mobile Browsers
Understanding Hardware Acceleration on Mobile Browsers
Ariya Hidayat
 
JavaScript Parser Infrastructure for Code Quality Analysis
JavaScript Parser Infrastructure for Code Quality AnalysisJavaScript Parser Infrastructure for Code Quality Analysis
JavaScript Parser Infrastructure for Code Quality Analysis
Ariya Hidayat
 
Build HTML5 App (Intel Elements 2011)
Build HTML5 App (Intel Elements 2011)Build HTML5 App (Intel Elements 2011)
Build HTML5 App (Intel Elements 2011)
Ariya Hidayat
 
Hybrid Apps (Native + Web) via QtWebKit
Hybrid Apps (Native + Web) via QtWebKitHybrid Apps (Native + Web) via QtWebKit
Hybrid Apps (Native + Web) via QtWebKit
Ariya Hidayat
 
Efficient Graphics with Qt
Efficient Graphics with QtEfficient Graphics with Qt
Efficient Graphics with Qt
Ariya Hidayat
 

More from Ariya Hidayat (9)

Understanding Hardware Acceleration on Mobile Browsers
Understanding Hardware Acceleration on Mobile BrowsersUnderstanding Hardware Acceleration on Mobile Browsers
Understanding Hardware Acceleration on Mobile Browsers
 
JavaScript Parser Infrastructure for Code Quality Analysis
JavaScript Parser Infrastructure for Code Quality AnalysisJavaScript Parser Infrastructure for Code Quality Analysis
JavaScript Parser Infrastructure for Code Quality Analysis
 
Build HTML5 App (Intel Elements 2011)
Build HTML5 App (Intel Elements 2011)Build HTML5 App (Intel Elements 2011)
Build HTML5 App (Intel Elements 2011)
 
Hybrid Apps (Native + Web) via QtWebKit
Hybrid Apps (Native + Web) via QtWebKitHybrid Apps (Native + Web) via QtWebKit
Hybrid Apps (Native + Web) via QtWebKit
 
Analyzing the Performance of Mobile Web
Analyzing the Performance of Mobile WebAnalyzing the Performance of Mobile Web
Analyzing the Performance of Mobile Web
 
Hybrid Apps (Native + Web) using WebKit
Hybrid Apps (Native + Web) using WebKitHybrid Apps (Native + Web) using WebKit
Hybrid Apps (Native + Web) using WebKit
 
Hybrid Apps (Native + Web) using WebKit
Hybrid Apps (Native + Web) using WebKitHybrid Apps (Native + Web) using WebKit
Hybrid Apps (Native + Web) using WebKit
 
Efficient Graphics with Qt
Efficient Graphics with QtEfficient Graphics with Qt
Efficient Graphics with Qt
 
Writing Tools using WebKit
Writing Tools using WebKitWriting Tools using WebKit
Writing Tools using WebKit
 

Recently uploaded

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Recently uploaded (20)

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

Understanding Webkit Rendering

  • 1. Understanding WebKit Rendering Ariya Hidayat Sunday, October 7, 12
  • 6. Browser at a High Level User Interface Data Persistence Browser Engine Render Engine Networking JavaScript Graphics I/O Engine Stack Sunday, October 7, 12
  • 7. WebKit Components Render Engine CSS DOM SVG HTML Canvas WebCore Client Interface JavaScript Engine (JSC/V8) Sunday, October 7, 12
  • 8. Platform Abstraction Networking Thread Geolocation Timer I/O Client Interface Clipboard Events Theme Graphics API Calls Events Port (Chrome, Safari, etc.) Sunday, October 7, 12
  • 10. From Contents to Pixels DOM Render Layout HTML DOM HTML Parser Tree Render Paint Tree Style CSS Style Sheets Parser Rules http://www.html5rocks.com/en/tutorials/internals/howbrowserswork Sunday, October 7, 12
  • 11. DOM Tree <html><body><p>Hello</p></body></html> HTMLDocument HTMLBodyElement HTMLParagraphElement attributes, children, contents Sunday, October 7, 12
  • 12. HTML Parsing tag <html><body><p>Hello</p></body></html> Loader Tokenizer text DOM Tree May come in chunks Tree Builder Section 12.2 in HTML Specification http://www.whatwg.org/specs/web-apps/current-work/multipage/parsing.html#parsing Sunday, October 7, 12
  • 13. DOM Tree vs Render Tree HTMLDocument RenderRoot HTMLBodyElement RenderBody HTMLParagraphElement RenderText There is no Render* for display:none Sunday, October 7, 12
  • 14. “Attach” Process Historical: Node is invisible, attach it to the main view to make it visible View 1:1 many:1 Node/Element RenderObject RenderStyle tree structure/navigation <div>42</div> computed style metrics (box model) hit testing another tree structure Sunday, October 7, 12
  • 16. It’s a forest! Sunday, October 7, 12
  • 17. Effects of Style Recalc and 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” Sunday, October 7, 12
  • 18. Getting the Right Style Stylesheet List HTMLDocument p { color: blue } HTMLBodyElement HTMLParagraphElement DOM Tree RenderStyle CSS Style Selector: id, class, tags, ... Sunday, October 7, 12
  • 19. Minimizing Layout Element clientHeight focus() clientLeft getBoundingClientRect() clientTop getClientRects() clientWidth scrollByLines() offsetHeight scrollByPages() offsetLeft scrollHeight offsetParent scrollIntoView() offsetTop scrollIntoViewIfNeeded() offsetWidth scrollLeft scrollTop scrollWidth innerText outerText http://gent.ilcore.com/2011/03/how-not-to-trigger-layout-in-webkit.html http://code.google.com/p/chromium/source/search?q=%22-%3EupdateLayoutIgnorePendingStylesheets()%22 Sunday, October 7, 12
  • 21. Goals of Painting • “Visualize” all RenderObjects (again, tree traversal) • All painting commands go to GraphicsContext abstraction • Important Optimizations • Clipped to the visible viewport • Back-to-front Transparency & clipping Sunday, October 7, 12
  • 22. CSS Painting: 10 Stages http://www.w3.org/TR/CSS2/zindex.html Appendix E. Elaborate description of Stacking Contexts • Background • Floats • Foreground • Selection Done by the render objects • Outline (in the render tree) Sunday, October 7, 12
  • 23. Graphics Abstraction Chromium Android Qt Mac & iOS GraphicsContext Skia CoreGraphics QPainter graphics stack Native controls, RenderTheme e.g. form elements Sunday, October 7, 12
  • 24. Painting Flow: Browser vs WebKit Browser WebKit User scrolls the viewport Request painting, GraphicsContext Sometimes to the backing store Style change Mark “dirty” area Sunday, October 7, 12
  • 25. Path is Everything Sunday, October 7, 12
  • 26. Stroke = Outline Solid Dashed Dotted Textured Sunday, October 7, 12
  • 27. Brush = Fill None Solid Gradient Textured Sunday, October 7, 12
  • 28. Gradient = Non-uniform Pixel Values Sunday, October 7, 12
  • 29. Drawing Time: Solid vs Gradient Only border 14x slower Solid color fill (depending on the dimension) Linear gradient fill Radial gradient fill Sunday, October 7, 12
  • 30. Path Approximation Curves Polygon Sunday, October 7, 12
  • 31. Antialiasing Multiple levels of transparency Sunday, October 7, 12
  • 32. Transformation Scaling Perspective Rotation Sunday, October 7, 12
  • 34. Font Atlas Buffer Bye Sunday, October 7, 12
  • 35. Simple to Complex ell o! H Simple shape Solid color Curves Gradient brush Textured stroke Blur shadow Serif text Rotated Sunday, October 7, 12
  • 36. Simple to Complex ell o! H Simple shape Solid color Curves Gradient brush Textured stroke Blur shadow Serif text Make it as an image Rotated Sunday, October 7, 12
  • 38. Game vs Web Sunday, October 7, 12
  • 39. Game Text Textured objects Animation Transformation Physics Sunday, October 7, 12
  • 40. Large Area, but Still Bounded Sunday, October 7, 12
  • 41. Web Page Images Text Sunday, October 7, 12
  • 42. Challenges Predictable contents (assets) ✔ Mostly text ✔ Mostly images ✔ Initial response immediate Sunday, October 7, 12
  • 43. SoC = System-on-a-Chip CPU GPU Sunday, October 7, 12
  • 44. GPU Workflow Matrix Vertices Rendered Textured Sunday, October 7, 12
  • 45. Optimized for Games “Fixed” geometry Transformation Textured triangles Parallelism Sunday, October 7, 12
  • 46. Powerful Capabilities http://epicgames.com/technology/ http://www.rage.com/ epic-citadel Sunday, October 7, 12
  • 48. Fundamental 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 Sunday, October 7, 12
  • 50. Efficient Use of GPU Drawing Backing Layer & primitives stores compositing Sunday, October 7, 12
  • 51. Maps Tile Sunday, October 7, 12
  • 52. Pinch to Zoom when you pinch... Sunday, October 7, 12
  • 53. Responsive Interface decoupled Rendering Processor User interaction Sunday, October 7, 12
  • 54. Rendering vs Interaction Screen Backing Store Rendering Web Page User interaction Sunday, October 7, 12
  • 56. Progressive Rendering Fast but blurry Crisp but slow Sunday, October 7, 12
  • 57. Perceived Responsiveness User pinches Smooth scaled Blocky (but fast!) Sunday, October 7, 12
  • 58. Tiling System Texture upload .... .... CPU GPU Sunday, October 7, 12
  • 59. Tile Transformation Panning = Translation Zooming = Scaling Sunday, October 7, 12
  • 61. Typical Animation opacity, movement, scaling, rotation, ... Sunday, October 7, 12
  • 62. Principles of Fluid Animation At the beginning, push as many 1 resources as possible to the GPU 2 During the animation, minimize CPU-GPU interaction Sunday, October 7, 12
  • 63. Immediate vs Retained At the beginning... draw the shape onto a buffer For every animation tick... blit the buffer at (x, draw the shape at (x, y) y) x = x + 10 x = x + 10 Off main thread Sunday, October 7, 12
  • 64. Mechanics of Animation “Hey, this is good stuff. Cache it as texture Initialization “Apply [operation] to texture #42.” Animation step Sunday, October 7, 12
  • 65. Elements = Layer Sunday, October 7, 12
  • 67. Compositing By Force -webkit-transform: translateZ(0) Not needed for CSS .someid { -webkit-animation-name: somekeyframeanimation; -webkit-animation-duration: 7s; -webkit-transform: translateZ(0); } Don’t do that Sunday, October 7, 12
  • 68. Magical Advice Use translate3d for hardware acceleration Sunday, October 7, 12
  • 69. Magical Advice Use translate3d for hardware acceleration Sunday, October 7, 12
  • 70. Debugging in Safari defaults write com.apple.Safari IncludeInternalDebugMenu 1 Sunday, October 7, 12
  • 71. Compositing Indicators Texture (number = upload) Composited layer No associated texture Container layer Overflow Sunday, October 7, 12
  • 72. Avoid Texture Reupload No reupload Upload Opacity Position Everything else! Size Animation “Hardware accelerated CSS” Sunday, October 7, 12
  • 74. Color Transition @-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 Sunday, October 7, 12
  • 75. Color Transition: The Trick Blended with http://jsfiddle.net/79AVn Sunday, October 7, 12
  • 76. Prepare and Reuse Hide the layer offscreen Viewport Sunday, October 7, 12
  • 77. Timer Latency Depending on user Animation end triggers the JavaScript callback JavaScript code kicks the next animation Prepare both animation and hide the “wrong” one Sunday, October 7, 12
  • 78. Avoid Overcapacity .... .... Think of the GPU memory like a cache. Sunday, October 7, 12
  • 81. There is No Silver Bullet Sunday, October 7, 12
  • 82. Thank You ariya.hidayat@gmail.com ariya.ofilabs.com @AriyaHidayat Sunday, October 7, 12