Surfaces

Goals

Surfaces are a concept to allow graphical embedding of heterogeneous untrusting clients efficiently into one scene.

  • embedding - the core concept of a surface is that it may contain references to surfaces from the same client or different clients

  • heterogeneous - rendering to a surface does not require that a client use a specific library or toolkit, only that it be able to speak the surface protocol

  • untrusting - a client does not have to trust its embedding or embedded clients in order to render into a surface.  Having access to a surface from another client does not provide any access to that surface’s contents.

  • efficiently - rendering to a surface should have minimal overhead compared to rendering directly to the native screen and should be equally efficient regardless of the embedding depth.

Use cases

In Chromium, we can use surfaces for many of the embedding cases we have today:

  • embedding a blink-rendered tab in the browser’s UI

  • embedding a plugin or video within a page

  • embedding an iframe rendered from one process into an iframe rendered in a different process

Concepts

A Surface is a fixed size rectangle that can be rendered into by submitting frames.  A client can create a surface by asking the SurfaceManager to construct one for a client (possibly itself) to render into.  A Surface can be identified by two IDs generated by the SurfaceManager - one for identifying the surface when issuing frames to render to the surface, one to identify the surface when rendering from it to embed.

A Frame is a series of quads to draw, some of which may reference other surfaces.  A frame also contains a set of resources and associated synchronization points.  Here’s a (rough) outline of the structure of a frame:

  • List of prerequisite sequence numbers for the frame

  • List of resources with associated synchronization points

  • List of passes, each of which contains

    • Transform of the pass

    • Damage and output rects

    • List of quads within the pass, each of which has

      • Transform / rect / clip state / opacity / blend mode / etc (may be shared with other quads)

      • Material - maybe solid color, texture, surface, etc

      • Material-specific properties such as color, texture ID, surface ID

The act of submitting a frame generates an implicit sequence number that can be used to synchronize presentation with other frames, potentially submitted by other clients.  A surface identifier + sequence number tuple unique identifies a frame for all clients of an instance of the service (and there will typically only be one surface service in the system).

A Display is a physical display (when Chromium is the operating system) or a native OS window object (when Chromium is running inside another operating system).  The surface service provides a surface for each display for a designated client to issue frames to.  In the case of Chromium running on windows, for example, the surface service would generate a surface identifier for each top-level HWND and provide them to the browser UI code to render into.

Of particular note is that on Mac we can construct a display wrapping an IOSurface for each tab and let CoreAnimation composite the tabs with the browser UI.  This does not provide the bandwidth benefits of ÜberCompositor but it does allow everything outside of the browser process to use the same presentation path as platforms using Aura/ÜberCompositor and reduce a lot of platform-specific complexity in our code.

Processing model

For clients:

Whenever a client wants to update the rendering of a surface it owns, it generates a new frame and submits it to the SurfaceManager.  This frame may contain quads that references surfaces being embedded by this client.  A client does not have to issue a new frame whenever a surface it embeds updates its rendering.  Issuing a frame also transfers ownership of resources (GL textures, software shared memory buffers).

Whenever a client wants to start embedding another client, it first generates an appropriately sized surface through the SurfaceManager and then sends it to the client.  The embedding client can start immediately issuing frames referencing the new surface or it may wait to receive an acknowledgement from the embedded client that the surface is ready, depending on the desired application semantics.

Resizing is analogous to creating a new surface.

For the service:

Whenever the manager receives a new frame, it performs some sanity checks on the frame (i.e. making sure it only references frames that the client should be referencing) and then saves it in the surface’s potential frame list along.  Whenever this frame’s prerequisites are satisfied, it is moved into the eligible frame list for the surface.  Only one frame can be rendered for a given surface at a time, but a client is allowed to pipeline multiple frames.

Whenever a display is ready for a new frame and something has changed, the service aggregates frames from the surfaces that contribute to that display and then renders them.  The aggregation algorithm is simple:

  1. Start with the most recent eligible frame issued to the surface associated with the display

  2. Iterate through the quads in the frame in draw order, keeping track of the current clip and transform

    1. If the quad is not a reference to another surface, draw it

    2. If the quad is a reference to another surface, find the most recent eligible frame issued to the referenced surface

      1. If there is no such frame, or if this surface has already been visited in this aggregation (i.e. there’s a cycle) skip the surface quad

      2. Otherwise, recursively repeat this algorithm from step 2

When the service knows that it will never render from a given frame again - for instance if it has started rendering a newer frame for a given surface or if the embedding client has told the manager that it wants to destroy a surface - the service sends an acknowledgement to the client with a set of resources to return to the client along with associated synchronization points.

SurfaceService structure

The SurfaceManager keeps track of all surfaces created in the system.  For each surface, it keeps track of:

  • The client that created the surface and will be embedding (rendering from) the surface

  • The client that will be rendering into the surface (may be the same as the creator)

  • List of submitted frames for the given surface

The ResourceProvider keeps track of resources that the service has ownership of and how to return ownership to clients.  For GL textures, for instance, this means managing mailboxes.

The DisplayManager keeps track of all displays that the surface service is responsible for rendering into.  For each display, the DisplayManager owns a surface used to render into the display as well as some state for hit testing against surfaces and determining which surfaces contributed to the display’s last produced frame.

There is only one instance of each of the Manager types in an instance of the service.

A SurfaceAggregator implements the aggregation algorithm and knows how to submit an aggregated frame to a renderer.  Aggregators are (nearly) stateless and can be created whenever necessary.

A Renderer translates an aggregated frame into draw commands appropriate for a given display.  In GPU rendering mode, this means GL draw calls and a swap into the display.  In software rendering mode, this means skia calls into the appropriate SkCanvas.

Synchronization

Resource synchronization is the same as it is with ÜberCompositor, with the slight simplification that the pipeline depth is not influenced by the nesting level of the embedding.

Clients can optionally synchronize frames with each other using the prerequisite / postrequisite synchronization points.  This has to be done with care but can be useful to do things like prevent resize guttering.  99% of the use cases in Chromium will not require any explicit synchronization between different surfaces - in nearly all cases it’s perfectly fine (and desirable) to let clients render independently of each other.

Here’s an example of a possible gutter prevention algorithm.  Assume that client Alice is embedding client Bob and wants to resize its surface for Bob from 100x100 to 200x200.  If Bob responds fast enough to Alice’s resize message, Alice wants to make sure that Bob shows up at 200x200 in the same frame as Alice’s decorations.

Start conditions:

Alice is embedding Bob.  Alice owns a 100x100 surface that Bob is rendering into.  Alice and Bob both have pending frames referencing the 100x100 surface.

Sequence for Alice:

  • Alice decides to resize Bob to 200x200 and change decorations that Alice is rendering.

  • Alice requests a new 200x200 surface from the SurfaceManager

  • Alice sends Bob a resize request and a handle to the new 200x200 surface

  • Alice starts a timeout

    • If Bob responds to the resize message before the timeout:

      • Alice issues the first frame referencing the 200x200 surface with a prerequisite sequence number that it got from Bob

    • If Bob doesn’t respond before the timeout:

      • Alice issues a frame referencing the 100x100 surface and appropriate quads to stretch or gutter as appropriate

  • Regardless of when the resize response comes in, Alice issues a destroy call for the 100x100 surface to the SurfaceManager after starting to issues frames referencing the 200x200 surface.

Sequence for Bob:

  • Bob receives a resize message with the new surface identifier

  • Bob issues a new frame appropriate for a 200x200 surface which generates a sequence number for the frame

  • Bob sends a resize response to Alice with this sequence number

End conditions:

Alice and Bob are referencing a 200x200 surface

The SurfaceManager knows that the 100x100 surface can be destroyed as soon as the service no longer needs it.

If Bob is slow to respond, Alice may stall or submit one or more frames that gutter.  However if Bob responds fast enough the service can guarantee using the sequence numbers that the new frame from Bob and the new decorations from Alice show up on screen at the same time.

Surfaces的更多相关文章

  1. <<Differential Geometry of Curves and Surfaces>>笔记

    <Differential Geometry of Curves and Surfaces> by Manfredo P. do Carmo real line Rinterval I== ...

  2. Parametric Curves and Surfaces

    Parametric Curves and Surfaces eryar@163.com Abstract. This paper is concerned with parametric curve ...

  3. Render OpenCascade Geometry Surfaces in OpenSceneGraph

    在OpenSceneGraph中绘制OpenCascade的曲面 Render OpenCascade Geometry Surfaces in OpenSceneGraph eryar@163.co ...

  4. Rendering Transparent 3D Surfaces in WPF with C#(转载)

    Rendering Transparent 3D Surfaces in WPF with C# The primary problems that arise when rendering semi ...

  5. <Differential Geometry of Curves and Surfaces>(by Manfredo P. do Carmo) Notes

    <Differential Geometry of Curves and Surfaces> by Manfredo P. do Carmo real line Rinterval I== ...

  6. 图书源代码下载: Modern Differential Geometry of CURVES and SURFACES with Mathematica

    http://alpha01.dm.unito.it/personalpages/abbena/gray/ Contents   1. Curves in the Plane |   2. Famou ...

  7. uva414 - Machined Surfaces

    uva414 - Machined Surfaces /* 水题,值得一提的是,getline使用时注意不能让它多吃回车键,处理方法可以用getchar. */ #include <iostre ...

  8. UVa 414 - Machined Surfaces

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=94&page=s ...

  9. 414 - Machined Surfaces

    Sample Input (character "B" for ease of reading. The actual input file will use the ASCII- ...

随机推荐

  1. [JZOJ 5437] [NOIP2017提高A组集训10.31] Sequence 解题报告 (KMP)

    题目链接: http://172.16.0.132/senior/#main/show/5437 题目: 题解: 发现满足上述性质并且仅当A序列的子序列的差分序列与B序列的差分序列相同 于是我们把A变 ...

  2. jQuery学习(七)——使用JQ完成下拉列表左右选择

    1.需求:实现以下功能 2.步骤分析: 第一步:确定事件(鼠标单击事件click) 第二步:获取左侧下拉列表被选中的option($(“#left option:selected”)) [假设左侧se ...

  3. QT笔记 -- (2) 文件相关操作、中文路径乱码

    1.显示文件对话框,选择一个目录,显示选中目录中的所有图片的代码如下 主要class: QFileDialog QStringList QFileInfoList QDir void open(){ ...

  4. c# 02-18 值类型 引用类型 字符串的不可变性 字符串的处理方法

    1值类型 直接把值存在栈中 栈的特点是后进先出 int double decimal char struct enum bool 2 引用类型 把值存在堆中,把地址存在栈中: string 自定义的类 ...

  5. shell脚本执行的三种方式

    (1)  bash script_name 或 sh script_name    推荐使用此方法,script_name 不需要执行权限亦可执行.   (2) path/script_name 或 ...

  6. Python内置数据结构之列表list

    1. Python的数据类型简介 数据结构是以某种方式(如通过编号)组合起来的数据元素(如数.字符乃至其他数据结构)集合.在Python中,最基本的数据结构为序列(sequence). Python内 ...

  7. IDEA创建Maven项目显示一直加载中的问题

    使用IDEA这款工具创建Maven项目的时候出现过下面这种情况: 红色区域即maven骨架加载不出来... 或 loading loading loading ... 有时候需要很长一段时间才能加载出 ...

  8. SPA SEO SSR三者有什么区别

    SPA通俗的说就是单页面应用(single page application) 优点 页面之间的切换非常快 一定程度减少了后端服务器的压力 后端程序只需要提供api,不需要客户端到底是web端还是手机 ...

  9. UVA-10003 Cutting Sticks 动态规划 找分界点k的动规

    题目链接:https://cn.vjudge.net/problem/UVA-10003 题意 有根棍子,上面有些分割点(n<50),每次按分割点切割棍子时,费用为当前棍子的长度. 问有什么样的 ...

  10. BZOJ 1085 / LOJ 2151 [SCOI2005]骑士精神 (剪枝/A*迭代搜索)

    题目大意:略 直接爆搜会T,我们优化一下,统计出当前棋盘和目标棋盘不同的位置的数量k,那么当前棋盘变成目标棋盘最少的移动次数是k-1 每次选择一个最大深度ma,那么如果当前走了dep步,显然必须保证d ...