Top Banner
CHROME INTERNALS: PAINT AND COMPOSITION by Dzmitry Varabei
27

CHROME INTERNALS: PAINT AND COMPOSITION by Dzmitry Varabei.

Dec 15, 2015

Download

Documents

Miles Damon
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CHROME INTERNALS: PAINT AND COMPOSITION by Dzmitry Varabei.

CHROME INTERNALS: PAINT AND COMPOSITION

by Dzmitry Varabei

Page 2: CHROME INTERNALS: PAINT AND COMPOSITION by Dzmitry Varabei.

Demo

Page 3: CHROME INTERNALS: PAINT AND COMPOSITION by Dzmitry Varabei.

Page Rendering Cycle

• Parse HTML and CSS files• Build the DOM

Page 4: CHROME INTERNALS: PAINT AND COMPOSITION by Dzmitry Varabei.

Nodes and the DOM tree

<html> <body> <div> Hello </div> </body></html>

HTMLDocument HTMLHTMLElement HTMLBodyElement HTMLDivElement Text("Hello")

Page 5: CHROME INTERNALS: PAINT AND COMPOSITION by Dzmitry Varabei.

Page Rendering Cycle

• Parse HTML and CSS files• Build the DOM• Calculate CSS property values• Build the rendering tree

Page 6: CHROME INTERNALS: PAINT AND COMPOSITION by Dzmitry Varabei.

RenderObject Tree

This is a data structure that helps the browser perform layout tasks. display:none<head><script><style>

anonymous line box:before

Page 7: CHROME INTERNALS: PAINT AND COMPOSITION by Dzmitry Varabei.

Page Rendering Cycle

• Parse HTML and CSS files• Build the DOM• Calculate CSS property values• Build the rendering tree• Calculate layout• Paint• Composite• Draw the final screen image onto the screen

Page 8: CHROME INTERNALS: PAINT AND COMPOSITION by Dzmitry Varabei.

Display refresh rate

~ 60Hzor

~16.6ms to make a frame

Page 9: CHROME INTERNALS: PAINT AND COMPOSITION by Dzmitry Varabei.

console> chrome.exe --enable-threaded-compositing --force-compositing-mode --enable-impl-side-painting --enable-skia-benchmarking --allow-webui-compositing

Google Chrome Canary

Page 10: CHROME INTERNALS: PAINT AND COMPOSITION by Dzmitry Varabei.

Trace Event Profiling Tool

about://tracing/

Read more: http://dev.chromium.org/developers/how-tos/trace-event-profiling-tool

Page 11: CHROME INTERNALS: PAINT AND COMPOSITION by Dzmitry Varabei.

Demo – CSS Paint Order

Page 12: CHROME INTERNALS: PAINT AND COMPOSITION by Dzmitry Varabei.

Paint

The phase of rendering where RenderObjects make calls into the GraphicsContext API to make a visual representation of themselves

Page 13: CHROME INTERNALS: PAINT AND COMPOSITION by Dzmitry Varabei.

Skia Graphics Engine

Skia is the open source C++ graphics library for drawing Text, Geometries, and Images.

https://code.google.com/p/skia/

Page 14: CHROME INTERNALS: PAINT AND COMPOSITION by Dzmitry Varabei.

Skia is currently used in

Google Chrome

Mozilla Firefox

Chrome OS

Android Sublime Text 3

Page 15: CHROME INTERNALS: PAINT AND COMPOSITION by Dzmitry Varabei.

Skia Debugger - Demo

Page 17: CHROME INTERNALS: PAINT AND COMPOSITION by Dzmitry Varabei.

What cause complex painting?

• image decodes/resizes• box-shadow (essentially improved over the past 2 years)• border-radius• border-radius + box-shadow

Read more: CSS Paint Times and Page Render Weight

Page 18: CHROME INTERNALS: PAINT AND COMPOSITION by Dzmitry Varabei.

Software mode VS Accelerated compositing mode

Page 19: CHROME INTERNALS: PAINT AND COMPOSITION by Dzmitry Varabei.

Composition

Page 20: CHROME INTERNALS: PAINT AND COMPOSITION by Dzmitry Varabei.

Accelerated compositing mode

Layer bitmaps are transferred to the GPU, combined ("composited"), and drawn on the screen.

Page 21: CHROME INTERNALS: PAINT AND COMPOSITION by Dzmitry Varabei.

Layer

Layer: section of the page, subtree of the DOM. Painted independently, composited on the GPU, and can stretch, move, and fade without repainting.

Page 22: CHROME INTERNALS: PAINT AND COMPOSITION by Dzmitry Varabei.

Which elements have their own layer?

• Root page object• Canvas• Video element• plugins (flash and etc)• Elements with CSS properties: TranslateZ,

Translate3d, Opacity, ScaleZ, RotateZ...• 2D Transforms do not create layer

Page 23: CHROME INTERNALS: PAINT AND COMPOSITION by Dzmitry Varabei.

The cost of too many layers:

Additional GPU and memory usage

Page 24: CHROME INTERNALS: PAINT AND COMPOSITION by Dzmitry Varabei.

Render profiling tools

• Show FPS • Show paint rectangles• Continuous page repainting• Show composited layer borders• Timeline -> Frames

Page 25: CHROME INTERNALS: PAINT AND COMPOSITION by Dzmitry Varabei.

Questions?

Page 27: CHROME INTERNALS: PAINT AND COMPOSITION by Dzmitry Varabei.

Thanks!

[email protected]