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

Cross platform mobile development
Cross platform mobile developmentCross platform mobile development
Cross platform mobile developmentPeter Friese
 
NodeJS guide for beginners
NodeJS guide for beginnersNodeJS guide for beginners
NodeJS guide for beginnersEnoch Joshua
 
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Edureka!
 
Introduction to Docker
Introduction to DockerIntroduction to Docker
Introduction to DockerLuong Vo
 
Hardware Acceleration in WebKit
Hardware Acceleration in WebKitHardware Acceleration in WebKit
Hardware Acceleration in WebKitJoone Hur
 
Développement mobile multi-plateforme avec Flutter
Développement mobile multi-plateforme avec FlutterDéveloppement mobile multi-plateforme avec Flutter
Développement mobile multi-plateforme avec Fluttererick G
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation洪 鹏发
 
Web development using javaScript, React js, Node js, HTML, CSS and SQL
Web development using javaScript, React js, Node js, HTML, CSS and SQLWeb development using javaScript, React js, Node js, HTML, CSS and SQL
Web development using javaScript, React js, Node js, HTML, CSS and SQLJayant Surana
 
Nuxt.JS Introdruction
Nuxt.JS IntrodructionNuxt.JS Introdruction
Nuxt.JS IntrodructionDavid Ličen
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.jsRob O'Doherty
 
도메인 주도 설계의 본질
도메인 주도 설계의 본질도메인 주도 설계의 본질
도메인 주도 설계의 본질Young-Ho Cho
 

What's hot (20)

Cross platform mobile development
Cross platform mobile developmentCross platform mobile development
Cross platform mobile development
 
NodeJS guide for beginners
NodeJS guide for beginnersNodeJS guide for beginners
NodeJS guide for beginners
 
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
 
Node.js Basics
Node.js Basics Node.js Basics
Node.js Basics
 
Introduction to Docker
Introduction to DockerIntroduction to Docker
Introduction to Docker
 
Express js
Express jsExpress js
Express js
 
Nodejs
NodejsNodejs
Nodejs
 
React Native
React NativeReact Native
React Native
 
Hardware Acceleration in WebKit
Hardware Acceleration in WebKitHardware Acceleration in WebKit
Hardware Acceleration in WebKit
 
Développement mobile multi-plateforme avec Flutter
Développement mobile multi-plateforme avec FlutterDéveloppement mobile multi-plateforme avec Flutter
Développement mobile multi-plateforme avec Flutter
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation
 
Web development using javaScript, React js, Node js, HTML, CSS and SQL
Web development using javaScript, React js, Node js, HTML, CSS and SQLWeb development using javaScript, React js, Node js, HTML, CSS and SQL
Web development using javaScript, React js, Node js, HTML, CSS and SQL
 
Rendering engine
Rendering engineRendering engine
Rendering engine
 
Nuxt.JS Introdruction
Nuxt.JS IntrodructionNuxt.JS Introdruction
Nuxt.JS Introdruction
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
JavaScript Promises
JavaScript PromisesJavaScript Promises
JavaScript Promises
 
도메인 주도 설계의 본질
도메인 주도 설계의 본질도메인 주도 설계의 본질
도메인 주도 설계의 본질
 
Express node js
Express node jsExpress node js
Express node js
 
Introduction Node.js
Introduction Node.jsIntroduction Node.js
Introduction Node.js
 
Android performance
Android performanceAndroid performance
Android performance
 

Viewers also liked

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 Revolutionjuanjosanchezpenas
 
WebKit and GStreamer
WebKit and GStreamerWebKit and GStreamer
WebKit and GStreamercalvaris
 
Mobile Browser Internal (Blink Rendering Engine)
Mobile Browser Internal (Blink Rendering Engine)Mobile Browser Internal (Blink Rendering Engine)
Mobile Browser Internal (Blink Rendering Engine)Hyungwook Lee
 
Android Chromium Rendering Pipeline
Android Chromium Rendering PipelineAndroid Chromium Rendering Pipeline
Android Chromium Rendering PipelineHyungwook Lee
 
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 QtWebKitAriya Hidayat
 
WebKit2 And You (GUADEC 2013)
WebKit2 And You (GUADEC 2013)WebKit2 And You (GUADEC 2013)
WebKit2 And You (GUADEC 2013)Igalia
 
FrontTalks: Вадим Макеев (Opera Software), «Зачем Опере Вебкит, или Опиум для...
FrontTalks: Вадим Макеев (Opera Software), «Зачем Опере Вебкит, или Опиум для...FrontTalks: Вадим Макеев (Opera Software), «Зачем Опере Вебкит, или Опиум для...
FrontTalks: Вадим Макеев (Opera Software), «Зачем Опере Вебкит, или Опиум для...Yandex
 
WebKit vs. the mobile Web
WebKit vs. the mobile WebWebKit vs. the mobile Web
WebKit vs. the mobile WebJosh Tumath
 
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 revolutionjuanjosanchezpenas
 
Measuring Web Performance - 自己満足で終わらないためのパフォーマンス計測 -
Measuring Web Performance - 自己満足で終わらないためのパフォーマンス計測 -Measuring Web Performance - 自己満足で終わらないためのパフォーマンス計測 -
Measuring Web Performance - 自己満足で終わらないためのパフォーマンス計測 -Koji Ishimoto
 
WebKitGtk+ Project
WebKitGtk+ ProjectWebKitGtk+ Project
WebKitGtk+ ProjectJoone Hur
 
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 sunnatMuhammad Tariq
 
Understanding Hardware Acceleration on Mobile Browsers
Understanding Hardware Acceleration on Mobile BrowsersUnderstanding Hardware Acceleration on Mobile Browsers
Understanding Hardware Acceleration on Mobile BrowsersAriya Hidayat
 
Presentasi narkoba2013
Presentasi narkoba2013Presentasi narkoba2013
Presentasi narkoba2013Kodrat Hidayat
 

Viewers also liked (20)

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
 
Mobile Browser Internal (Blink Rendering Engine)
Mobile Browser Internal (Blink Rendering Engine)Mobile Browser Internal (Blink Rendering Engine)
Mobile Browser Internal (Blink Rendering Engine)
 
Android Chromium Rendering Pipeline
Android Chromium Rendering PipelineAndroid Chromium Rendering Pipeline
Android Chromium Rendering Pipeline
 
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
 

Similar to Understanding Webkit Rendering

Document Object Model
Document Object ModelDocument Object Model
Document Object Modelchomas kandar
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Modelchomas 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 JPACheng Ta Yeh
 
Introduction to Web Programming
Introduction to Web ProgrammingIntroduction to Web Programming
Introduction to Web ProgrammingYnon Perek
 
Understanding the dom by Benedict Ayiko
Understanding the dom by Benedict AyikoUnderstanding the dom by Benedict Ayiko
Understanding the dom by Benedict AyikoDamalie Wasukira
 
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 apiAlexander Zeitler
 
Custom Android Code Templates
Custom Android Code TemplatesCustom Android Code Templates
Custom Android Code Templatesmurphonic
 
Build and Deploy Sites Using Features
Build and Deploy Sites Using Features Build and Deploy Sites Using Features
Build and Deploy Sites Using Features Phase2
 
Polymer and web component
Polymer and web componentPolymer and web component
Polymer and web componentImam Raza
 
Familiar HTML5 - 事例とサンプルコードから学ぶ 身近で普通に使わているHTML5
Familiar HTML5 - 事例とサンプルコードから学ぶ 身近で普通に使わているHTML5Familiar HTML5 - 事例とサンプルコードから学ぶ 身近で普通に使わているHTML5
Familiar HTML5 - 事例とサンプルコードから学ぶ 身近で普通に使わているHTML5Sadaaki HIRAI
 
Modular applications with montage components
Modular applications with montage componentsModular applications with montage components
Modular applications with montage componentsBenoit Marchant
 
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...Jesse Cravens
 
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を考えるSadaaki HIRAI
 
J Query(04 12 2008) Foiaz
J Query(04 12 2008) FoiazJ Query(04 12 2008) Foiaz
J Query(04 12 2008) Foiaztestingphase
 
Exploring Critical Rendering Path
Exploring Critical Rendering PathExploring Critical Rendering Path
Exploring Critical Rendering PathRaphael Amorim
 
Jdbc Dao it-slideshares.blogspot.com
Jdbc Dao it-slideshares.blogspot.comJdbc Dao it-slideshares.blogspot.com
Jdbc Dao it-slideshares.blogspot.comphanleson
 

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 BrowsersAriya 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 AnalysisAriya 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 QtWebKitAriya Hidayat
 
Analyzing the Performance of Mobile Web
Analyzing the Performance of Mobile WebAnalyzing the Performance of Mobile Web
Analyzing the Performance of Mobile WebAriya Hidayat
 
Hybrid Apps (Native + Web) using WebKit
Hybrid Apps (Native + Web) using WebKitHybrid Apps (Native + Web) using WebKit
Hybrid Apps (Native + Web) using WebKitAriya Hidayat
 
Hybrid Apps (Native + Web) using WebKit
Hybrid Apps (Native + Web) using WebKitHybrid Apps (Native + Web) using WebKit
Hybrid Apps (Native + Web) using WebKitAriya Hidayat
 
Efficient Graphics with Qt
Efficient Graphics with QtEfficient Graphics with Qt
Efficient Graphics with QtAriya Hidayat
 
Writing Tools using WebKit
Writing Tools using WebKitWriting Tools using WebKit
Writing Tools using WebKitAriya 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

Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 

Recently uploaded (20)

Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 

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