blob: 946f2fecb7c4d09bcd5cff5a30fa9c0d21f6caaa [file] [log] [blame] [view]
danakj253392e2017-07-27 23:41:581# //components/viz
2
3Viz - short for visuals - is the client library and service implementations for
4compositing and gpu presentation.
5
6See [//services/viz](../../services/viz/README.md) for more information about
7Viz overall.
8
9**Table of Contents**
101. [Terminology](#terminology)
112. [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)
163. [Naming guidelines with Mojo](#naming-guidelines)
17
18## Terminology
19
20**Mojo Interface**: The interface definition, found in a .mojom file. This is
21an abstract interface and can be thought of as a process/thread-independent C++
22abstract class.
23
24**Mojo Implementation**: The default implementation of a mojom interface for
25production. Many interfaces will only have a single implementation that we
26ship.
27
28**Alternate Mojo Implementations**: Secondary implementations of a mojom
29interface 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
34Clients. Most services in Chrome dont have these, and Clients find the service
35directly, but they are more common in Viz. Currently the Host is in the browser
36process. In a fully-realized mus+ash, the Host moves outside of Chrome to the
37window server.
38
39**Client**: All users of a Mojo interface who are not the Host. They will
40usually 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,
43that often also exposes or uses some privileged interfaces that Clients dont
44have. Generally prefer to use the Mojo interfaces directly, but sometimes we
45need another C++ helper around it.
46
47**Client-side Wrapper**: A C++ wrapper around a Mojo interface for use in
48Clients. Generally prefer to use the Mojo interface directly, but sometimes we
49need another C++ helper around it.
50
51**Host/Client-side Abstraction**: A C++ wrapper around a Mojo interface that is
52also a subclass of a C++ interface. Generally prefer to use the Mojo interfaces
53directly, but sometimes we need a higher-level C++ abstraction, usually because
54other subclasses cannot use the Mojo interface.
55
56
57## Directory Structure <a name="directory-structure"></a>
58To keep dependencies clear into the Viz source tree, all source code files
59should appear in leaf directories.
60
61### common <a name="directory-structure-common"></a>
62Data types and simple helpers that are used by the client library, or by
63clients directly, and by service implementations.
64
65### client <a name="directory-structure-client"></a>
66Client library for accessing Viz services. May be used from privileged (eg
67browser) or unprivileged (eg renderer) processes.
68
69| Can depend on: |
70|:---------------|
71| viz/common/ |
72
73### host <a name="directory-structure-host"></a>
74Privileged client library for owning and controlling Viz services. May only be
75used from privileged (eg browser) processes.
76
77This should not depend on other parts of Viz, as they are core data types and
78helpers 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>
85Service-side implementations of Viz Mojo interfaces, which are found in
86[//services/viz](https://cs.chromium.org/chromium/src/services/viz/). Each
87component of the service-side implementation is located in its own
88sub-directory.
89
90As of this writing, these service components may be instantiated and used
91directly from the browser process. But these services are intended to be
92abstracted away through Mojo interfaces so that they are able to live entirely
93outside 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
97a set of frames, from multiple clients, into a single backing store for display
98to the user. Also deals in getting screenshots of content by drawing to
99offscreen buffers.
100
101The top-level scheduler that coordinates when the compositor should draw, along
102with when clients should be submitting frames.
103
104This component is platform-agnostic, with any platform-specific details
105abstracted away from it. It accesses Gpu services through the command buffer as
106a client even though it is in the same process as the Gpu service in order to
107be 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
116platform-agnostic, this component provides implementations of platform-specific
117behaviour needed for the display compositor, and injected into it.
118
119Code here supports presentation of the backing store drawn by the display
120compositor (typically thought of as SwapBuffers), as well as the use of
121overlays.
122
kylechar78ed3872018-01-31 00:19:59123| Can depend on: |
124|:--------------------------------------|
125| viz/common/* |
126| viz/service/display/<some_interfaces> |
127
128Dependencies onto viz/service/display should generally only be for interfaces
129that the embedder must provide to the display.
danakj253392e2017-07-27 23:41:58130
131#### service/frame_sinks
132**Frame sinks**: This component implements the Mojo interfaces to send frames,
133resources, and other data types from ``viz/common/`` for display to the
134compositing service. It receives and organizes relationships between what should
135be composited.
136
kylechar78ed3872018-01-31 00:19:59137| 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/ |
danakj253392e2017-07-27 23:41:58144
Sadrul Habib Chowdhuryef1abe782017-08-01 17:20:38145#### service/gl
146**GL**: This component implements the Mojo interfaces for allocating (and
147deallocating) gpu memory buffers, setting up a channel for the command buffer,
148etc.
149
150| Can depend on: |
151|:----------------------|
152| viz/common/* |
153
danakj253392e2017-07-27 23:41:58154#### service/hit_test
155**Hit testing**: Service-side code to resolve input events to individual
156clients.
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
165from which other service interfaces are accessed.
166
167As the root of the service/ code structure, it instantiates and connects all
168other 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.
177It holds data received from frame sinks, and provides access to them for the
178display compositor.
179
180| Can depend on: |
181|:---------------|
182| viz/common/* |
183
184
185## Naming guidelines with Mojo <a name="naming-guidelines"></a>
186
187Viz makes extensive use of Mojo, and there are conflicting patterns with
188regard to naming types around Mojo interfaces in the codebase today. This aims
189to provide a standard to adhere to for future naming to increase our
190consistency within the team.
191
192For 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,
196and 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
200commonly use the Impl suffix, and we will repeat this here, as it’s already
201commonly 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
206rules as a default implementation, but is used for tests, or cases where we
207don’t have a simple default production implementation.
208* The descriptive prefix should describe what makes this implementation
209different 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
213utilities for using the Mojo interface. It only is meant to exist and be
214accessed in the privileged Host process. We prefix with Host to explain what
215makes this interface special and when it can be used. We do not suffix to be
216consistent with Clients.
217
218**Client-side Wrapper**: `ClientTimeTraveller`
219* This wraps the Mojo interface, providing a higher-level abstraction and
220utilities for using the Mojo interface. It may exist and be used in any Client
221in place of the Mojo interface. Prefer to use the Mojo interface directly when
222possible. We prefix with Client to explain in what situations it can be used.
223We do not suffix to avoid a TimeTravellerClientClient in the case where this
224class has itself a C++ client, as ClientTimeTravellerClient appeared to be a
225better 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
229named after. A prefix describing what makes this implementation special can
230refer to its use of the Mojo interface.