blob: 74ed1c37c57c9de3958a93489f9c6b02d071458f [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
Weiliang Chena4b4b2d2018-04-11 23:07:279For understanding compositing related terminology, check out
10[//cc](../../cc/README.md). For understanding display compositor's position in
11the graphics stack, check out
12[Compositor Stack slides](https://docs.google.com/presentation/d/1ou3qdnFhKdjR6gKZgDwx3YHDwVUF7y8eoqM3rhErMMQ/edit?usp=sharing).
13For more comprehensive list of design docs relating to Viz, check out
14[WIP list of design doc](https://crbug.com/821901).
15
danakj253392e2017-07-27 23:41:5816**Table of Contents**
171. [Terminology](#terminology)
182. [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)
233. [Naming guidelines with Mojo](#naming-guidelines)
24
25## Terminology
26
27**Mojo Interface**: The interface definition, found in a .mojom file. This is
28an abstract interface and can be thought of as a process/thread-independent C++
29abstract class.
30
31**Mojo Implementation**: The default implementation of a mojom interface for
32production. Many interfaces will only have a single implementation that we
33ship.
34
35**Alternate Mojo Implementations**: Secondary implementations of a mojom
36interface 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
41Clients. Most services in Chrome dont have these, and Clients find the service
42directly, but they are more common in Viz. Currently the Host is in the browser
43process. In a fully-realized mus+ash, the Host moves outside of Chrome to the
44window server.
45
46**Client**: All users of a Mojo interface who are not the Host. They will
47usually 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,
50that often also exposes or uses some privileged interfaces that Clients dont
51have. Generally prefer to use the Mojo interfaces directly, but sometimes we
52need another C++ helper around it.
53
54**Client-side Wrapper**: A C++ wrapper around a Mojo interface for use in
55Clients. Generally prefer to use the Mojo interface directly, but sometimes we
56need another C++ helper around it.
57
58**Host/Client-side Abstraction**: A C++ wrapper around a Mojo interface that is
59also a subclass of a C++ interface. Generally prefer to use the Mojo interfaces
60directly, but sometimes we need a higher-level C++ abstraction, usually because
61other subclasses cannot use the Mojo interface.
62
63
64## Directory Structure <a name="directory-structure"></a>
65To keep dependencies clear into the Viz source tree, all source code files
66should appear in leaf directories.
67
68### common <a name="directory-structure-common"></a>
69Data types and simple helpers that are used by the client library, or by
70clients directly, and by service implementations.
71
72### client <a name="directory-structure-client"></a>
73Client library for accessing Viz services. May be used from privileged (eg
danakj7b631be2018-05-25 19:14:2074browser) or unprivileged (eg renderer) processes. The client library should
75remain agnostic about *how* to communicate with viz (in other words should not
76use mojo bindings), as some viz clients use mojo but others use it in-process
77or via other IPC mechanisms.
danakj253392e2017-07-27 23:41:5878
79| Can depend on: |
80|:---------------|
81| viz/common/ |
82
83### host <a name="directory-structure-host"></a>
84Privileged client library for owning and controlling Viz services. May only be
85used from privileged (eg browser) processes.
86
87This should not depend on other parts of Viz, as they are core data types and
88helpers 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>
95Service-side implementations of Viz Mojo interfaces, which are found in
96[//services/viz](https://cs.chromium.org/chromium/src/services/viz/). Each
97component of the service-side implementation is located in its own
98sub-directory.
99
100As of this writing, these service components may be instantiated and used
101directly from the browser process. But these services are intended to be
102abstracted away through Mojo interfaces so that they are able to live entirely
103outside 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
107a set of frames, from multiple clients, into a single backing store for display
108to the user. Also deals in getting screenshots of content by drawing to
109offscreen buffers.
110
111The top-level scheduler that coordinates when the compositor should draw, along
112with when clients should be submitting frames.
113
114This component is platform-agnostic, with any platform-specific details
115abstracted away from it. It accesses Gpu services through the command buffer as
116a client even though it is in the same process as the Gpu service in order to
117be 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
126platform-agnostic, this component provides implementations of platform-specific
127behaviour needed for the display compositor, and injected into it.
128
129Code here supports presentation of the backing store drawn by the display
130compositor (typically thought of as SwapBuffers), as well as the use of
131overlays.
132
kylechar78ed3872018-01-31 00:19:59133| Can depend on: |
134|:--------------------------------------|
135| viz/common/* |
136| viz/service/display/<some_interfaces> |
137
138Dependencies onto viz/service/display should generally only be for interfaces
139that the embedder must provide to the display.
danakj253392e2017-07-27 23:41:58140
141#### service/frame_sinks
142**Frame sinks**: This component implements the Mojo interfaces to send frames,
143resources, and other data types from ``viz/common/`` for display to the
144compositing service. It receives and organizes relationships between what should
145be composited.
146
kylechar78ed3872018-01-31 00:19:59147| 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/ |
danakj253392e2017-07-27 23:41:58154
Sadrul Habib Chowdhuryef1abe782017-08-01 17:20:38155#### service/gl
156**GL**: This component implements the Mojo interfaces for allocating (and
157deallocating) gpu memory buffers, setting up a channel for the command buffer,
158etc.
159
160| Can depend on: |
161|:----------------------|
162| viz/common/* |
163
danakj253392e2017-07-27 23:41:58164#### service/hit_test
165**Hit testing**: Service-side code to resolve input events to individual
166clients.
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
175from which other service interfaces are accessed.
176
177As the root of the service/ code structure, it instantiates and connects all
178other 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.
187It holds data received from frame sinks, and provides access to them for the
188display compositor.
189
190| Can depend on: |
191|:---------------|
192| viz/common/* |
193
194
195## Naming guidelines with Mojo <a name="naming-guidelines"></a>
196
197Viz makes extensive use of Mojo, and there are conflicting patterns with
198regard to naming types around Mojo interfaces in the codebase today. This aims
199to provide a standard to adhere to for future naming to increase our
200consistency within the team.
201
202For 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,
206and 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
210commonly use the Impl suffix, and we will repeat this here, as it’s already
211commonly 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
216rules as a default implementation, but is used for tests, or cases where we
217don’t have a simple default production implementation.
218* The descriptive prefix should describe what makes this implementation
219different 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
223utilities for using the Mojo interface. It only is meant to exist and be
224accessed in the privileged Host process. We prefix with Host to explain what
225makes this interface special and when it can be used. We do not suffix to be
226consistent with Clients.
227
228**Client-side Wrapper**: `ClientTimeTraveller`
229* This wraps the Mojo interface, providing a higher-level abstraction and
230utilities for using the Mojo interface. It may exist and be used in any Client
231in place of the Mojo interface. Prefer to use the Mojo interface directly when
232possible. We prefix with Client to explain in what situations it can be used.
233We do not suffix to avoid a TimeTravellerClientClient in the case where this
234class has itself a C++ client, as ClientTimeTravellerClient appeared to be a
235better 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
239named after. A prefix describing what makes this implementation special can
240refer to its use of the Mojo interface.