成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

Life of a Pixel 2018

Miracle / 2640人閱讀

摘要:將操作記錄為一列。在列表上進(jìn)行操作被稱為光柵化。能夠運(yùn)行產(chǎn)生位圖的命令加速光柵化注意到此時(shí)像素并不在屏幕上。因此,線程將劃分為。根據(jù)與的距離確定的優(yōu)先級(jí)。被包裝在一個(gè)中,該對(duì)象被提交給瀏覽器進(jìn)程。

This talk is about how Chrome turns web content into pixels.  The entire process is called "rendering".
We"ll describe what we mean by content, and what we mean by pixels, and then we"ll explain the magic in between.

這個(gè)演講主要介紹chrome是如何把web content轉(zhuǎn)成像素點(diǎn)的,整個(gè)過程被稱為“rendering”。
我們首先描述什么叫做content,然后再介紹pixels,然后解釋其中的魔法。

Chrome"s architecture is constantly evolving.  This talk connects high-level concepts (which change slowly) to specific classes (which change frequently).
The details are based primarily on what is currently shipping in the canary channel (M69), but a few of the biggest future refactorings are mentioned in passing.

chrome的架構(gòu)在不斷發(fā)展。這個(gè)演講將高級(jí)概念(變化緩慢)與特定類(經(jīng)常變化)聯(lián)系起來。細(xì)節(jié)基于canary(M69),一些比較大的未來的重構(gòu)也會(huì)被提到。

"Content" is the generic term in Chromium for all of the code inside a webpage or the frontend of a web application.
It"s made of text, markup (surrounding the text), styles (defining how markup is rendered), and script (which can modify all of the above dynamically).
There are other kinds of content, which we won"t cover here.

"Content"是最通用的Chromium的術(shù)語,指的是網(wǎng)頁內(nèi)部或者是網(wǎng)絡(luò)應(yīng)用的前端代碼。它由text,markup(環(huán)繞于文本),style(決定標(biāo)記如何渲染),以及script(能夠動(dòng)態(tài)地改變上述提到的內(nèi)容)。同時(shí)也有其他的content,但是我們?cè)谶@里暫時(shí)不做介紹。

A real webpage is just thousands of lines of HTML, CSS, and JavaScript delivered in plain text over the network.
There"s no notion of compilation or packaging as you might find on other kinds of software platforms - the webpage"s source code is the input to the renderer.

一個(gè)真實(shí)的網(wǎng)頁由成千行的純文本的HTML,CSS以及JavaScript通過網(wǎng)絡(luò)提供。你可能在其他軟件平臺(tái)找不到compilation或者packaging的概念,網(wǎng)頁的源代碼是renderer的輸入。

Architecturally, the "content" namespace in the Chromium C++ codebase is responsible for everything in the red box.
Contrast with tab strip, address bar, navigation buttons, menus, etc. which live outside of "content".
Key to Chrome"s security model: rendering happens in a sandboxed process.

從架構(gòu)上說,”content“在Chromium C++ 代碼的命名空間負(fù)責(zé)紅框中的所有內(nèi)容。
對(duì)比而言,標(biāo)簽條,地址欄,導(dǎo)航按鈕,菜單,在”content“之外。
Chrome安全模型的關(guān)鍵是,在沙盒進(jìn)程中進(jìn)行渲染。

At the other end of the pipeline we have to get pixels onto the screen using the graphics libraries provided by the underlying operating system.
On most platforms today, that"s a standardized API called "OpenGL". On Windows there"s an extra translation into DirectX. In the future, we may support newer APIs such as Vulkan.
These libraries provide low-level graphics primitives like "textures" and "shaders", and let you do things like "draw a polygon at these coordinates into a buffer of virtual pixels". But obviously they don"t understand anything about the web or HTML or CSS.

在管道的另一邊,我們要利用操作系統(tǒng)下提供的圖形庫把像素點(diǎn)放置在屏幕上?,F(xiàn)今,在大多數(shù)的平臺(tái)上,有一個(gè)標(biāo)準(zhǔn)API叫做”O(jiān)penGL”。在Windows上,有額外到DirectX的轉(zhuǎn)換。在將來,我們會(huì)支持新的API(類似Vulkan)。
這些庫提供了低級(jí)圖形基元(primitive),類似“紋理(texture)”以及“著色器(shader)”,讓你能夠做類似“在這些坐標(biāo)處繪制一個(gè)多邊形到虛擬像素緩沖區(qū)”這樣的操作。但是顯然他們并不理解任何和HTML和CSS相關(guān)的事情。

So the goal of rendering can be stated as: turn HTML / CSS / JavaScript into the right OpenGL calls to display the pixels.
But keep in mind a second goal as we describe the pipeline: We also want the right intermediate data structures to update the rendering efficiently after it"s produced, and answer queries about it from script or other parts of the system.

所以渲染的目標(biāo)可以描述為:將HTML/CSS/JavaScript轉(zhuǎn)化為正確的OpenGL的調(diào)用來展示像素。
但是要記住,我們描述這個(gè)管道的第二個(gè)目標(biāo)是:我們同樣想知道正確的中間數(shù)據(jù)生成后有效地更新,并且能在腳本或者系統(tǒng)的其他部分回答有關(guān)它的查詢。

We break the pipeline into multiple "lifecycle stages", generating those intermediate outputs.
We"ll first describe each stage of a working pipeline, then come back to the notion of efficient updating and introduce some concepts for optimization.

我們將管道分成多個(gè)“生命周期階段”,產(chǎn)生中間輸出。我們首先描述工作流水線的每個(gè)階段,然后回到有效更新的概念,再介紹優(yōu)化相關(guān)的概念。

HTML tags impose a semantically meaningful hierarchical structure on the document.  For example, a 
may contain two paragraphs, each with text. So the first step is to parse those tags to build an object model that reflects this structure.

HTML標(biāo)簽在文檔上強(qiáng)加了語義上有意義的層次結(jié)構(gòu)。 例如,

可能包含兩個(gè)段落,每個(gè)段落都帶有文本。 因此,第一步是解析這些標(biāo)簽以構(gòu)建反映此結(jié)構(gòu)的對(duì)象模型。

If you"ve taken computer science classes you may recognize this as a "tree".

如果你上過計(jì)算機(jī)科學(xué)的課程,那么你就能認(rèn)出來它是一棵樹。

The DOM serves double duty as both the internal representation of the page, and the API exposed to script for querying or modifying the rendering.
The JavaScript engine (V8) exposes DOM web APIs as thin wrappers around the real DOM tree through a system called "bindings".

DOM具有雙重功能,它既能作為頁面的內(nèi)部展示,也能作為查詢和更改呈現(xiàn)的腳本的公開API。Javascript引擎(V8)通過一個(gè)系統(tǒng)叫做“bindings”把真實(shí)的DOM tree封裝成一個(gè)輕量的wrapper。

Having built the DOM tree, the next step is to process the CSS styles.
A CSS selector selects a subset of DOM elements that its property declarations should apply to.

構(gòu)建了DOM tree以后,下一步是處理CSS styles。一個(gè)CSS選擇器選擇它屬性聲明了應(yīng)當(dāng)應(yīng)用的DOM元素的子集。

Style properties are the knobs by which web authors can influence the rendering of DOM elements.
There are hundreds of style properties.

作者可以通過Style屬性影響DOM元素的渲染。style屬性有幾百個(gè)。

Furthermore, it"s not trivial to determine which elements a style rule selects.
Some elements may be selected by more than one rule, with conflicting declarations for a particular style property.

此外,確定樣式規(guī)則選擇哪些元素并非易事。
某些元素可能由多個(gè)規(guī)則選擇,并且具有特定樣式屬性的沖突聲明。

The layout stage runs after the style recalc stage.
First, the layout tree is constructed. Then, we walk the layout tree, filling in the geometry data, and processing side effects of the geometry.

layout階段在style重計(jì)算階段以后進(jìn)行。首先,layout tree構(gòu)建,然后我們遍歷這個(gè)layout tree,填充幾何數(shù)據(jù),然后處理幾何產(chǎn)生的副作用。

Today, layout objects contain both inputs and outputs of the layout stage, without a clean separation between them.
For example, the LayoutObject acquires ownership of its element"s ComputedStyle object.
A new layout system called LayoutNG is expected to simplify the architecture, and make it easier to build new layout algorithms.

如今,layout對(duì)象包括layout階段的輸入和輸出,它們之間的區(qū)分沒有那么清晰。
比如,LayoutObject獲取它元素的 ComputedStyle 對(duì)象的所有權(quán)。一個(gè)新的layout系統(tǒng)叫做LayoutNG,被期望用來簡(jiǎn)化架構(gòu),構(gòu)建新的更簡(jiǎn)單的layout算法。

Now that we understand the geometry of our layout objects, it"s time to paint them.
Paint records paint operations into a list of display items.
A paint operation might be something like "draw a rectangle at these coordinates, in this color".
There may be multiple display items for each layout object, corresponding to different parts of its visual appearance, like the background, foreground, outline, etc.
This is just a recording that can be played back later. We"ll see why that"s useful in a bit.

現(xiàn)在我們理解了layout object的幾何形狀,接下來就是繪制它們。
paint將paint操作記錄為一列display item。一個(gè)paint操作類似于“在這些坐標(biāo)用這個(gè)顏色繪制一個(gè)矩形”。對(duì)于每個(gè)layout object也許有多個(gè)display item,對(duì)應(yīng)視覺外觀的不同部分,比如背景,前景,輪廓等。~~~


It"s important to paint elements in the right order, so that they stack correctly when they overlap.
The order can be controlled by style.
以正確的順序paint element非常重要,只有這樣才能在元素覆蓋的時(shí)候正常顯示。這個(gè)順序能被style所控制。

It"s even possible for an element to be partly in front of and partly behind another element.
That"s because paint runs in multiple phases, and each paint phase does its own traversal of a subtree.

一個(gè)元素部分在另外一個(gè)元素的前面或者后面是可能的。因?yàn)閜aint在不同階段運(yùn)行,每次的paint階段做了自己子樹的遍歷。

The paint operations in the display item list are executed by a process called rasterization.
Each cell in the resulting bitmap holds values for four color channels.

在display item列表上進(jìn)行paint操作被稱為rasterization(光柵化)。位圖上的每個(gè)像素點(diǎn)存著四個(gè)顏色通道的值。

The rastered bitmap is stored in memory, typically GPU memory referenced by an OpenGL texture object.
The GPU can also run the commands that produce the bitmap ("accelerated rasterization").
Note that these pixels are not yet on the screen!

光柵化的位圖在內(nèi)存中存儲(chǔ),通常是被OpenGL紋理對(duì)象引用的GPU內(nèi)存。
GPU能夠運(yùn)行產(chǎn)生位圖的命令(“加速光柵化”)
注意到此時(shí)像素并不在屏幕上。

Rasterization issues OpenGL calls through a library called Skia. Skia provides a layer of abstraction around the hardware, and understands more complex things like paths and Bezier curves.
Skia is open-source and maintained by Google. It ships in the Chrome binary but lives in a separate code repository. It"s also used by other products such as the Android OS.
Skia"s GPU-accelerated codepath builds its own buffer of drawing operations, which is flushed at the end of the raster task.

Rasterization通過一個(gè)Skia的庫產(chǎn)生OpenGL調(diào)用,Skia圍繞硬件提供了一層抽象,能理解類似路徑和貝塞爾曲線等更復(fù)雜的事情。
Skia開源且由谷歌維護(hù)。它附帶在chrome二進(jìn)制文件中,但是屬于一個(gè)多帶帶的代碼庫,同時(shí)也被其他產(chǎn)品,比如安卓系統(tǒng)使用。
Skia的GPU加速代碼路徑構(gòu)建了它獨(dú)立的繪制操作緩沖區(qū),它會(huì)在光柵化任務(wù)結(jié)束的時(shí)候刷新。

Recall that the renderer process is sandboxed, so it can"t make system calls directly.
GL calls issued by Skia are actually proxied into a different process using a "command buffer".
The GPU process receives the command buffer and issues the "real" GL calls through a set of function pointers.
Besides escaping the renderer sandbox, isolating GL in the GPU process protects us from unstable or insecure graphics drivers.

回顧之前說的渲染進(jìn)程在沙盒中,所以并不能直接進(jìn)行系統(tǒng)調(diào)用。
Skia發(fā)起的GL調(diào)用使用“command buffer”被代理給了另一個(gè)不同的進(jìn)程。
GPU進(jìn)程接受command buffer然后通過函數(shù)指針發(fā)起“真正”的GL調(diào)用。
逃離沙盒進(jìn)程,GPU進(jìn)程中獨(dú)立的GL將從不穩(wěn)定和不安全的圖形驅(qū)動(dòng)中保護(hù)我們。

Those GL function pointers are initialized by dynamic lookup from the system"s shared OpenGL library - or the ANGLE library on Windows.
ANGLE is another library built by Google; its job is to translate OpenGL to DirectX, which is Microsoft"s API for accelerated graphics on Windows.
There are also OpenGL drivers for Windows, but historically they have not been very high quality.

這些GL函數(shù)指針通過系統(tǒng)的共享OpenGL庫(或Windows上的ANGLE庫)進(jìn)行動(dòng)態(tài)查找來初始化。
ANGLE是Google建立的另一個(gè)庫; 它的工作是將OpenGL轉(zhuǎn)換為DirectX,這是微軟在Windows上加速圖形的API。
Windows也有OpenGL驅(qū)動(dòng)程序,但從歷史上看,它們的質(zhì)量并不高。

Moving raster to the GPU process will improve performance.
It"s also needed to support Vulkan.
把光柵化移動(dòng)到GPU進(jìn)程能夠改善性能。它同時(shí)需要支持Vulkan

We have now gone all the way from content to pixels in memory.
But note that the rendering is not static.
Running the full pipeline is expensive
現(xiàn)在我們已經(jīng)走完在內(nèi)存中從content到pixels的全程了。但是渲染本身不是靜態(tài)的,走完管道全程總是代價(jià)昂貴的。

Change is modelled as animation frames.
Each frame is a complete rendering of the state of the content at a particular point in time.

Certain style properties cause a layer to be created for a layout object.
If a layout object doesn"t have a layer, it paints into the layer of the nearest ancestor that has one.
特定的樣式屬性會(huì)為layout對(duì)象創(chuàng)建layer。如果一個(gè)layout對(duì)象本身并沒有l(wèi)ayer,那么它將被繪制到最近的祖先節(jié)點(diǎn)上。

Building the layer tree is a new lifecycle stage on the main thread. Today, this happens before paint, and each layer is painted separately.

構(gòu)建layer tree是主線程上的新生命周期階段。如今,這發(fā)生在paint之前,每層都是多帶帶paint的。


After paint is finished, the commit updates a copy of the layer tree on the compositor thread, to match the state of the tree on the main thread.

paint結(jié)束后,commit將更新compositor線程上的layer tree的拷貝,以匹配主線程上tree的狀態(tài)。

Recall: raster is the step after paint, which turns paint ops into bitmaps.
Layers can be large - rastering the whole layer is expensive, and unnecessary if only part of it is visible.
So the compositor thread divides the layer into tiles.
Tiles are the unit of raster work. Tiles are rastered with a pool of dedicated raster threads. Tiles are prioritized based on their distance from the viewport.
(Not shown: a layer actually has multiple tilings for different resolutions.)

回想一下:raster在paint之后,它將paint ops轉(zhuǎn)換為位圖。
layer可能很大 - 整個(gè)layer都光柵化的成本很高,如果只有部分可見則不必要全部光柵化。
因此,compositor線程將layer劃分為tiles。
tiles是raster work的基本單位。 專門的raster線程池對(duì)tiles進(jìn)行光柵化。 根據(jù)tiles與viewport的距離確定tiles的優(yōu)先級(jí)。
(未顯示:layer實(shí)際上有不同分辨率的多個(gè)tilings。)

Once all the tiles are rastered, the compositor thread generates "draw quads". A quad is like a command to draw a tile in a particular location on the screen, taking into account all the transformations applied by the layer tree. Each quad references the tile"s rastered output in memory (remember, no pixels are on the screen yet).
The quads are wrapped up in a compositor frame object which gets submitted to the browser process.

一旦所有tiles都被光柵化,compositor線程就會(huì)生成“draw quads”。 quads類似一個(gè)命令,考慮了圖層樹應(yīng)用的所有變換在屏幕上的特定位置繪制tile。 每個(gè)quads在內(nèi)存中引用了tile的光柵輸出(請(qǐng)記住,屏幕上還沒有像素)。
quads被包裝在一個(gè)compositor frame object中,該對(duì)象被提交給瀏覽器進(jìn)程。

The compositor thread has two copies of the tree, so that it can raster tiles from a new commit while drawing the previous commit.

合成器線程有兩個(gè)樹的副本,因此它可以在繪制上一次commit時(shí),對(duì)新的commit進(jìn)行光柵化tiles。

The browser process runs a component called the display compositor, inside a service called "viz" (short for visuals).
The display compositor aggregates compositor frames submitted from all the renderer processes, along with frames from the browser UI outside of the WebContents. Then it issues the GL calls to draw the quad resources, which go to the GPU process just like the GL calls from the raster workers.
On most platforms the display compositor"s output is double-buffered, so the quads draw into a backbuffer, and a "swap" command makes it visible.
(On OS X we do something a little different with CoreAnimation.)
Finally our pixels are on the screen. :)
瀏覽器進(jìn)程在名為“viz”(visual的簡(jiǎn)稱)的service中運(yùn)行一個(gè)名為display compositor的組件。
display compositor聚合從所有renderer進(jìn)程提交的compositor frame,以及來自WebContents外部的browser UI的frame。 然后它發(fā)起GL調(diào)用來繪制quad資源,這些資源就像來自raster worker的GL調(diào)用一樣進(jìn)入GPU進(jìn)程。
在大多數(shù)平臺(tái)上,display compositor的輸出是雙緩沖的,因此quads繪制到backbuffer,“swap”命令使其可見。
(在OS X上,我們使用CoreAnimation做了一些不同的事情。)
最后我們的像素在屏幕上。:)

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/97623.html

相關(guān)文章

  • 圖像格式PPM/PGM/PBM剖析及代碼實(shí)現(xiàn) -- 視頻和圖像編程基礎(chǔ)之一

    摘要:可移植像素圖格式,灰度圖格式,位圖格式的介紹簡(jiǎn)介可移植像素圖格式,可移植灰度圖格式和可移植位圖格式是便于跨平臺(tái)的圖像格式。每個(gè)文件的開頭兩個(gè)字節(jié)碼作為文件描述符,指出具體格式和編碼形式。 可移植像素圖格式 PPM,灰度圖格式 PGM,位圖格式 PBM 的介紹 簡(jiǎn)介 可移植像素圖格式(PPM),可移植灰度圖格式(PGM)和可移植位圖格式(PBM)是便于跨平臺(tái)的圖像格式。有時(shí)候也被統(tǒng)稱為 ...

    Zachary 評(píng)論0 收藏0
  • [Leetcode] Game of Life 生命游戲

    摘要:思路普通解法,遍歷每一個(gè)細(xì)胞求值,用一個(gè)的矩陣存放結(jié)果。求值過程,稍微分析一下可知,其實(shí)就是按照以下的矩陣進(jìn)行結(jié)果是可數(shù)的。 According to the Wikipedias article: The Game of Life, also knownsimply as Life, is a cellular automaton devised by the Britishmath...

    android_c 評(píng)論0 收藏0
  • [LeetCode] 289. Game of Life

    Problem According to the Wikipedias article: The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970. Given a board with m ...

    Ajian 評(píng)論0 收藏0
  • 頁面基礎(chǔ)布局相關(guān)知識(shí) --- 居中&經(jīng)典布局

    摘要:子元素固定高寬子元素不定高寬缺點(diǎn)需要設(shè)置子元素寬度包括百分比等非固定寬度也可以原理是的縮寫,意為彈性布局,用來為盒狀模型提供最大的靈活性。路途未完,行囊已空衣裳破裂污損,人已精疲力竭。拋棄顏色形狀等干擾代碼實(shí)際布局 前言 PS: 這些只是個(gè)人學(xué)習(xí),僅供思路參考,可能會(huì)有缺陷,并且都在chrome中測(cè)試,不一定適用其他瀏覽器,而且不考慮IE的,切記!! PS: 2018/03/23修改,...

    zebrayoung 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

最新活動(dòng)
閱讀需要支付1元查看
<