danakj | 253392e | 2017-07-27 23:41:58 | [diff] [blame] | 1 | # //components/viz |
| 2 | |
| 3 | Viz - short for visuals - is the client library and service implementations for |
| 4 | compositing and gpu presentation. |
| 5 | |
| 6 | See [//services/viz](../../services/viz/README.md) for more information about |
| 7 | Viz overall. |
| 8 | |
Weiliang Chen | a4b4b2d | 2018-04-11 23:07:27 | [diff] [blame] | 9 | For understanding compositing related terminology, check out |
| 10 | [//cc](../../cc/README.md). For understanding display compositor's position in |
| 11 | the graphics stack, check out |
| 12 | [Compositor Stack slides](https://docs.google.com/presentation/d/1ou3qdnFhKdjR6gKZgDwx3YHDwVUF7y8eoqM3rhErMMQ/edit?usp=sharing). |
| 13 | For more comprehensive list of design docs relating to Viz, check out |
| 14 | [WIP list of design doc](https://crbug.com/821901). |
| 15 | |
danakj | 253392e | 2017-07-27 23:41:58 | [diff] [blame] | 16 | **Table of Contents** |
| 17 | 1. [Terminology](#terminology) |
| 18 | 2. [Directory structure](#directory-structure) |
| 19 | 1. [common](#directory-structure-common) |
| 20 | 2. [client](#directory-structure-client) |
| 21 | 3. [host](#directory-structure-host) |
| 22 | 4. [service](#directory-structure-service) |
| 23 | 3. [Naming guidelines with Mojo](#naming-guidelines) |
| 24 | |
| 25 | ## Terminology |
| 26 | |
| 27 | **Mojo Interface**: The interface definition, found in a .mojom file. This is |
| 28 | an abstract interface and can be thought of as a process/thread-independent C++ |
| 29 | abstract class. |
| 30 | |
| 31 | **Mojo Implementation**: The default implementation of a mojom interface for |
| 32 | production. Many interfaces will only have a single implementation that we |
| 33 | ship. |
| 34 | |
| 35 | **Alternate Mojo Implementations**: Secondary implementations of a mojom |
| 36 | interface for platform-specific details, for tests, etc. |
| 37 | |
| 38 | **Service**: Where Mojo implementations live and run. |
| 39 | |
| 40 | **Host**: A privileged process that provides access to viz Mojo interfaces for |
| 41 | Clients. Most services in Chrome don’t have these, and Clients find the service |
| 42 | directly, but they are more common in Viz. Currently the Host is in the browser |
| 43 | process. In a fully-realized mus+ash, the Host moves outside of Chrome to the |
| 44 | window server. |
| 45 | |
| 46 | **Client**: All users of a Mojo interface who are not the Host. They will |
| 47 | usually need to go through the Host to gain access to the Mojo interface. |
| 48 | |
| 49 | **Host-side Wrapper**: A C++ wrapper around a Mojo interface for use in Hosts, |
| 50 | that often also exposes or uses some privileged interfaces that Clients don’t |
| 51 | have. Generally prefer to use the Mojo interfaces directly, but sometimes we |
| 52 | need another C++ helper around it. |
| 53 | |
| 54 | **Client-side Wrapper**: A C++ wrapper around a Mojo interface for use in |
| 55 | Clients. Generally prefer to use the Mojo interface directly, but sometimes we |
| 56 | need another C++ helper around it. |
| 57 | |
| 58 | **Host/Client-side Abstraction**: A C++ wrapper around a Mojo interface that is |
| 59 | also a subclass of a C++ interface. Generally prefer to use the Mojo interfaces |
| 60 | directly, but sometimes we need a higher-level C++ abstraction, usually because |
| 61 | other subclasses cannot use the Mojo interface. |
| 62 | |
| 63 | |
| 64 | ## Directory Structure <a name="directory-structure"></a> |
| 65 | To keep dependencies clear into the Viz source tree, all source code files |
| 66 | should appear in leaf directories. |
| 67 | |
| 68 | ### common <a name="directory-structure-common"></a> |
| 69 | Data types and simple helpers that are used by the client library, or by |
| 70 | clients directly, and by service implementations. |
| 71 | |
| 72 | ### client <a name="directory-structure-client"></a> |
| 73 | Client library for accessing Viz services. May be used from privileged (eg |
danakj | 7b631be | 2018-05-25 19:14:20 | [diff] [blame] | 74 | browser) or unprivileged (eg renderer) processes. The client library should |
| 75 | remain agnostic about *how* to communicate with viz (in other words should not |
| 76 | use mojo bindings), as some viz clients use mojo but others use it in-process |
| 77 | or via other IPC mechanisms. |
danakj | 253392e | 2017-07-27 23:41:58 | [diff] [blame] | 78 | |
| 79 | | Can depend on: | |
| 80 | |:---------------| |
| 81 | | viz/common/ | |
| 82 | |
| 83 | ### host <a name="directory-structure-host"></a> |
| 84 | Privileged client library for owning and controlling Viz services. May only be |
| 85 | used from privileged (eg browser) processes. |
| 86 | |
| 87 | This should not depend on other parts of Viz, as they are core data types and |
| 88 | helpers only, and can be used from anywhere else in Viz. |
| 89 | |
| 90 | | Can depend on: | |
| 91 | |:---------------| |
| 92 | | viz/common/ | |
| 93 | |
| 94 | ### service <a name="directory-structure-service"></a> |
| 95 | Service-side implementations of Viz Mojo interfaces, which are found in |
| 96 | [//services/viz](https://cs.chromium.org/chromium/src/services/viz/). Each |
| 97 | component of the service-side implementation is located in its own |
| 98 | sub-directory. |
| 99 | |
| 100 | As of this writing, these service components may be instantiated and used |
| 101 | directly from the browser process. But these services are intended to be |
| 102 | abstracted away through Mojo interfaces so that they are able to live entirely |
| 103 | outside the browser process, and gain in-process access to the Gpu. |
| 104 | |
| 105 | #### service/display |
| 106 | **Display compositor**: The display compositor uses Gpu or software to composite |
| 107 | a set of frames, from multiple clients, into a single backing store for display |
| 108 | to the user. Also deals in getting screenshots of content by drawing to |
| 109 | offscreen buffers. |
| 110 | |
| 111 | The top-level scheduler that coordinates when the compositor should draw, along |
| 112 | with when clients should be submitting frames. |
| 113 | |
| 114 | This component is platform-agnostic, with any platform-specific details |
| 115 | abstracted away from it. It accesses Gpu services through the command buffer as |
| 116 | a client even though it is in the same process as the Gpu service in order to |
| 117 | be scheduled as a peer among other clients. |
| 118 | |
| 119 | | Can depend on: | |
| 120 | |:----------------------| |
| 121 | | viz/common/* | |
| 122 | | viz/service/surfaces/ | |
| 123 | |
| 124 | #### service/display_embedder |
| 125 | **Platform details for display compositor**: While the display compositor is |
| 126 | platform-agnostic, this component provides implementations of platform-specific |
| 127 | behaviour needed for the display compositor, and injected into it. |
| 128 | |
| 129 | Code here supports presentation of the backing store drawn by the display |
| 130 | compositor (typically thought of as SwapBuffers), as well as the use of |
| 131 | overlays. |
| 132 | |
kylechar | 78ed387 | 2018-01-31 00:19:59 | [diff] [blame] | 133 | | Can depend on: | |
| 134 | |:--------------------------------------| |
| 135 | | viz/common/* | |
| 136 | | viz/service/display/<some_interfaces> | |
| 137 | |
| 138 | Dependencies onto viz/service/display should generally only be for interfaces |
| 139 | that the embedder must provide to the display. |
danakj | 253392e | 2017-07-27 23:41:58 | [diff] [blame] | 140 | |
| 141 | #### service/frame_sinks |
| 142 | **Frame sinks**: This component implements the Mojo interfaces to send frames, |
| 143 | resources, and other data types from ``viz/common/`` for display to the |
| 144 | compositing service. It receives and organizes relationships between what should |
| 145 | be composited. |
| 146 | |
kylechar | 78ed387 | 2018-01-31 00:19:59 | [diff] [blame] | 147 | | Can depend on: | |
| 148 | |:------------------------------| |
| 149 | | viz/common/* | |
| 150 | | viz/service/display/ | |
| 151 | | viz/service/display_embedder/ | |
| 152 | | viz/service/hit_test/ | |
| 153 | | viz/service/surfaces/ | |
danakj | 253392e | 2017-07-27 23:41:58 | [diff] [blame] | 154 | |
Sadrul Habib Chowdhury | ef1abe78 | 2017-08-01 17:20:38 | [diff] [blame] | 155 | #### service/gl |
| 156 | **GL**: This component implements the Mojo interfaces for allocating (and |
| 157 | deallocating) gpu memory buffers, setting up a channel for the command buffer, |
| 158 | etc. |
| 159 | |
| 160 | | Can depend on: | |
| 161 | |:----------------------| |
| 162 | | viz/common/* | |
| 163 | |
danakj | 253392e | 2017-07-27 23:41:58 | [diff] [blame] | 164 | #### service/hit_test |
| 165 | **Hit testing**: Service-side code to resolve input events to individual |
| 166 | clients. |
| 167 | |
| 168 | | Can depend on: | |
| 169 | |:----------------------| |
| 170 | | viz/common/* | |
| 171 | | viz/service/surfaces/ | |
| 172 | |
| 173 | #### service/main |
| 174 | **Main**: TODO(fsamuel): This will hold implementation of the root interface |
| 175 | from which other service interfaces are accessed. |
| 176 | |
| 177 | As the root of the service/ code structure, it instantiates and connects all |
| 178 | other parts of Viz. |
| 179 | |
| 180 | | Can depend on: | |
| 181 | |:---------------| |
| 182 | | viz/common/* | |
| 183 | | viz/service/* | |
| 184 | |
| 185 | #### service/surfaces |
| 186 | **Surfaces**: This component acts like the data model for the compositing service. |
| 187 | It holds data received from frame sinks, and provides access to them for the |
| 188 | display compositor. |
| 189 | |
| 190 | | Can depend on: | |
| 191 | |:---------------| |
| 192 | | viz/common/* | |
| 193 | |
| 194 | |
| 195 | ## Naming guidelines with Mojo <a name="naming-guidelines"></a> |
| 196 | |
| 197 | Viz makes extensive use of Mojo, and there are conflicting patterns with |
| 198 | regard to naming types around Mojo interfaces in the codebase today. This aims |
| 199 | to provide a standard to adhere to for future naming to increase our |
| 200 | consistency within the team. |
| 201 | |
| 202 | For a given mojo service called `TimeTraveller`, we would use the following. |
| 203 | |
| 204 | **Mojo Interface**: `mojom::TimeTraveller` |
| 205 | * This is the abstract interface definition. It comes with no prefix or suffix, |
| 206 | and lives in a (sometimes nested) mojom namespace. |
| 207 | |
| 208 | **Mojo Implementation**: `TimeTravellerImpl` |
| 209 | * This is the implementation of the interface. For other C++ interfaces we |
| 210 | commonly use the Impl suffix, and we will repeat this here, as it’s already |
| 211 | commonly used and is well understood. |
| 212 | * If there will be multiple implementations, see below. |
| 213 | |
| 214 | **Alternative Mojo Implementation**: `DescriptivePrefixTimeTravellerImpl` |
| 215 | * This is a non-default implementation of the interface. It follows the same |
| 216 | rules as a default implementation, but is used for tests, or cases where we |
| 217 | don’t have a simple default production implementation. |
| 218 | * The descriptive prefix should describe what makes this implementation |
| 219 | different from others, as such why it exists. |
| 220 | |
| 221 | **Host-side Wrapper**: `HostTimeTraveller` |
| 222 | * This wraps the Mojo interface, providing a higher-level abstraction and |
| 223 | utilities for using the Mojo interface. It only is meant to exist and be |
| 224 | accessed in the privileged Host process. We prefix with Host to explain what |
| 225 | makes this interface special and when it can be used. We do not suffix to be |
| 226 | consistent with Clients. |
| 227 | |
| 228 | **Client-side Wrapper**: `ClientTimeTraveller` |
| 229 | * This wraps the Mojo interface, providing a higher-level abstraction and |
| 230 | utilities for using the Mojo interface. It may exist and be used in any Client |
| 231 | in place of the Mojo interface. Prefer to use the Mojo interface directly when |
| 232 | possible. We prefix with Client to explain in what situations it can be used. |
| 233 | We do not suffix to avoid a TimeTravellerClientClient in the case where this |
| 234 | class has itself a C++ client, as ClientTimeTravellerClient appeared to be a |
| 235 | better option of the two. |
| 236 | |
| 237 | **Host/Client-side Abstraction**: `OtherAbstractionName` |
| 238 | * This is a case of an object implementing a C++ interface, which it should be |
| 239 | named after. A prefix describing what makes this implementation special can |
| 240 | refer to its use of the Mojo interface. |