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