33
웹브라우저 엔진의 구조와 원리 ( Understanding Open Source Rendering Engine ) 이형욱 ([email protected]) 시스템스컴퓨팅G / NAVER LABS 2014-05

[D2 오픈세미나]2.browser engine 이형욱_20140523

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: [D2 오픈세미나]2.browser engine 이형욱_20140523

웹브라우저엔진의구조와원리( Understanding Open Source Rendering Engine )

이형욱 ([email protected])

시스템스컴퓨팅G / NAVER LABS

2014-05

Page 2: [D2 오픈세미나]2.browser engine 이형욱_20140523

2

0. Contents

Chapter 1: How browsers work

① Browser at High Level② Major Browser’s Rendering Engine③ Summary of browser main flows.④ HTML Parser⑤ Render Tree⑥ Layout ⑦ Paint

Chapter 2: Advanced Rendering Technology① Types of rendering path② Software Rendering Path③ Hardware Rendering Path④ Threaded Compositor⑤ Threaded Rasterization

Chapter 3: How to improve rendering performance① Understanding Dev Tools② CSS properties by style operation required③ Use layers to improve performance④ Layers in WebKit⑤ Cost of multi layers⑥ Paul’s Guideline for Animation

Page 3: [D2 오픈세미나]2.browser engine 이형욱_20140523

3

Chapter 1, How browsers work

Page 4: [D2 오픈세미나]2.browser engine 이형욱_20140523

4

1. Browser at High Level

Co

de C

ove

rag

e

10%

90%

UI

Browser Engine

Rendering Engine

Network I/OJavaScript

EngineGraphics

Stack

Data

Persiste

nce

Page 5: [D2 오픈세미나]2.browser engine 이형욱_20140523

5

2. Major Browser’s Rendering Engine

Page 6: [D2 오픈세미나]2.browser engine 이형욱_20140523

6

<html><head>

<title> NAVER </title></head><body>

<div><h1> Hello </h1><p> World </p>

</div></body>

</html>

3. Summary of browser main flows.

Page 7: [D2 오픈세미나]2.browser engine 이형욱_20140523

7

DOM: Document Object Model- Document = HTML, well-formed XML- Object Model = Data + Method

Standard way for accessing and manipulating documents.

+

4. HTML Parser (1/2): DOM

Page 8: [D2 오픈세미나]2.browser engine 이형욱_20140523

8

HEAD

TITLE

NAVER

BODY

DIV

H1 P

HTML

Hello World

<html><head>

<title> NAVER </title></head><body>

<div><h1> Hello </h1><p> World </p>

</div></body>

</html>

4. HTML Parser (2/2): Example

Page 9: [D2 오픈세미나]2.browser engine 이형욱_20140523

9

5. Render Tree (1/4): CSS Box model

html, address,blockquote,body, dd, div,dl, dt, fieldset, form,frame, frameset,h1, h2, h3, h4,h5, h6, noframes,ol, p, ul, center,dir, hr, menu, pre { display: block;}

* Default display property: inline

Default style sheet for HTML 4

The way the box is layed out is determined by Box type: inline, block Box dimensions: width, height Positioning scheme: static, absolute, fixed, relative External information: image size / view port size

Page 10: [D2 오픈세미나]2.browser engine 이형욱_20140523

10

5. Render Tree (2/4): Visual formatting Model

< Relative Positioning >< Normal Flow >

< Block formatting context >

< Inline formatting context >

Page 11: [D2 오픈세미나]2.browser engine 이형욱_20140523

11

HTML

CSS

DOMTree

StyleRules

RendererTreeLookup

5. Render Tree (3/4): Render Tree flows

Page 12: [D2 오픈세미나]2.browser engine 이형욱_20140523

12

HEAD

TITLE

NAVER

BODY

DIV

H1 P

HTML

Hello World

Block

Block

Block

Block Block

Inline Inline

5. Render Tree (4/4): Example

Page 13: [D2 오픈세미나]2.browser engine 이형욱_20140523

13

6. Layout (1/2): Algorithm Overview

1. CSS 2.1 Visual formatting Model.

1) Normal Flow① Block formatting contexts② Inline formatting contexts③ Relative positioning

2) Floats3) Absolute positioning

2. Global and incremental layout

3. Dirty bit system

4. Asynchronous and Synchronous layout

dirty

< Incremental layout >

Page 14: [D2 오픈세미나]2.browser engine 이형욱_20140523

14

6. Layout (2/2): Example

HEAD

TITLE

NAVER

BODY

DIV

H1 P

HTML

Hello World

Block

Block

Block

Block Block

Inline Inline

(0, 0, 1024, 768)

(0, 0, 1024, 768)

(0, 0, 1024, 55)

(10, 20, 1024, 37) (10, 80, 1024, 18)

Page 15: [D2 오픈세미나]2.browser engine 이형욱_20140523

15

7. Paint

Block (html)

Block (body)

Block (div)

Block (h1) Block (p)

Inline (hello) Inline (world)

(0, 0, 1024, 768)

(0, 0, 1024, 768)

(0, 0, 1024, 55)

(10, 20, 1024, 37) (10, 80, 1024, 18) 1024

768<div>

Page 16: [D2 오픈세미나]2.browser engine 이형욱_20140523

16

Chapter 2, Advanced Rendering Technology

Page 17: [D2 오픈세미나]2.browser engine 이형욱_20140523

17

1. Non-composited SW rendering (Traditional)

2. Composited SW rendering

3. Composited GPU rendering

1. Types of rendering path

Page 18: [D2 오픈세미나]2.browser engine 이형욱_20140523

18

2. Rendering Path : Software Rendering Path

1. Renderer Process에서 skia를 이용하여 bitmap을 생성 (필요 시 compositing)

2. Shared Memory를 이용하여 Browser Process에 전달하여 화면에 Update.

Page 19: [D2 오픈세미나]2.browser engine 이형욱_20140523

19

2. Rendering Path : Hardware Rendering Path

1. 각 Layer 별 bitmap을 생성 (Render Layer traversing)

2. Textures upload into Video memory

3. Compositor에서 Layer 순서에 맞게 Texture를 drawing하여 화면에 Update

Page 20: [D2 오픈세미나]2.browser engine 이형욱_20140523

20

3. Rendering (1/2): Ideal

Page 21: [D2 오픈세미나]2.browser engine 이형욱_20140523

21

3. Rendering (2/2): Real

Page 22: [D2 오픈세미나]2.browser engine 이형욱_20140523

22

4. Threaded Compositor

Page 23: [D2 오픈세미나]2.browser engine 이형욱_20140523

23

5. Threaded Rasterization

Page 24: [D2 오픈세미나]2.browser engine 이형욱_20140523

24

Chapter 3, How to improve rendering performance

Page 25: [D2 오픈세미나]2.browser engine 이형욱_20140523

25

1. Understanding Dev Tools

Page 26: [D2 오픈세미나]2.browser engine 이형욱_20140523

26

https://docs.google.com/spreadsheet/pub?key=0ArK1Uipy0SbDdHVLc1ozTFlja1dhb25QNGhJMXN5MXc&single=true&gid=0&output=html

2. CSS properties by style operation required

Page 27: [D2 오픈세미나]2.browser engine 이형욱_20140523

27

3. Use layers to improve performance

< Multi layer mode using translate3d>

< Single layer mode>

Page 28: [D2 오픈세미나]2.browser engine 이형욱_20140523

28

4. Layers in WebKit

1. It's the root object for the page. <html>

2. CSS position properties (relative, absolute or a

transform)

3. It is transparent

4. Has overflow, an alpha mask or reflection

5. Has a CSS filter

6. <canvas>

7. <video>

Page 29: [D2 오픈세미나]2.browser engine 이형욱_20140523

29

• Compositing 처리시 필요한 Memory 사용량 및 작업량 증가

5. Cost of multi layers

<Layer를 너무 많이 사용할 경우 Compositing 시간이 오래 걸림>

Page 30: [D2 오픈세미나]2.browser engine 이형욱_20140523

30

1. Use “opacity, translate, rotate and scale”

2. Use reqeustAnimateFrame. Avoid setTimeout, setInterval

3. Use Browser Optimized CSS animation. Avoid Jqueryanimate()

6. Paul’s Guideline for Animation

< Paul Irish >

Page 31: [D2 오픈세미나]2.browser engine 이형욱_20140523

31

Page 32: [D2 오픈세미나]2.browser engine 이형욱_20140523

32

Appendix #1: Vocabulary

Page 33: [D2 오픈세미나]2.browser engine 이형욱_20140523

33

Appendix #2: References

1. http://www.w3.org/TR/CSS2/

2. http://www.w3.org/TR/DOM-Level-2-Core/core.html

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

4. http://deview.kr/2013/detail.nhn?topicSeq=5

5. http://www.slideshare.net/joone/hardware-acceleration-in-webkit

6. http://dev.chromium.org/developers/design-documents/multi-process-architecture

7. http://dev.chromium.org/developers/design-documents/displaying-a-web-page-in-

chrome

8. http://dev.chromium.org/developers/design-documents/inter-process-communication

9. http://dev.chromium.org/developers/design-documents/multi-process-resource-

loading

10. http://dev.chromium.org/developers/design-documents/gpu-accelerated-

compositing-in-chrome

11. http://dev.chromium.org/developers/design-documents/compositor-thread-

architecture

12. http://dev.chromium.org/developers/design-documents/impl-side-painting