• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

client/H12-Nov-2020-1,9981,342

common/H12-Nov-2020-24,72717,774

demo/H12-Nov-2020-975667

host/H12-Nov-2020-6,5914,772

service/H12-Nov-2020-103,16775,828

test/H12-Nov-2020-126120

BUILD.gnH A D07-Nov-20201.5 KiB5848

DEPSH A D07-Nov-2020442 2016

OWNERSH A D07-Nov-20201.2 KiB6249

PRESUBMIT.pyH A D07-Nov-2020571 1710

README.mdH A D07-Nov-202010.4 KiB254198

presubmit_checks.pyH A D07-Nov-202011.5 KiB311243

viz.gniH A D07-Nov-20201.5 KiB5951

README.md

1# //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
9For 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
16**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 don’t 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 don’t
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
74browser) 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.
78
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
133The source code is split into two build targets,
134``components/viz/service:service`` and
135``components/viz/service:gpu_service_dependencies``. The latter is
136code that requires being run in the gpu process, thus could not work
137if the viz service is located elsewhere. This is forward-looking code
138as the viz service is moving into the gpu process always.
139
140| Can depend on:                        |
141|:--------------------------------------|
142| viz/common/*                          |
143| viz/service/display/<some_interfaces> |
144
145Dependencies onto viz/service/display should generally only be for interfaces
146that the embedder must provide to the display.
147
148#### service/frame_sinks
149**Frame sinks**: This component implements the Mojo interfaces to send frames,
150resources, and other data types from ``viz/common/`` for display to the
151compositing service. It receives and organizes relationships between what should
152be composited.
153
154| Can depend on:                |
155|:------------------------------|
156| viz/common/*                  |
157| viz/service/display/          |
158| viz/service/display_embedder/ |
159| viz/service/hit_test/         |
160| viz/service/surfaces/         |
161
162#### service/gl
163**GL**: This component implements the Mojo interfaces for allocating (and
164deallocating) gpu memory buffers, setting up a channel for the command buffer,
165etc.
166
167Similar to ``service/display_embedder`` this is split into two targets in
168the build system. Code that must run in the gpu process is compiled in
169the ``components/viz/service:gpu_service_dependencies`` build target,
170and the rest is compiled in ``components/viz/service:service``. As all
171code moves to the gpu process, these two build targets will merge.
172
173| Can depend on:        |
174|:----------------------|
175| viz/common/*          |
176
177#### service/hit_test
178**Hit testing**: Service-side code to resolve input events to individual
179clients.
180
181| Can depend on:        |
182|:----------------------|
183| viz/common/*          |
184| viz/service/surfaces/ |
185
186#### service/main
187**Main**: TODO(fsamuel): This will hold implementation of the root interface
188from which other service interfaces are accessed.
189
190As the root of the service/ code structure, it instantiates and connects all
191other parts of Viz.
192
193| Can depend on: |
194|:---------------|
195| viz/common/*   |
196| viz/service/*  |
197
198#### service/surfaces
199**Surfaces**: This component acts like the data model for the compositing service.
200It holds data received from frame sinks, and provides access to them for the
201display compositor.
202
203| Can depend on: |
204|:---------------|
205| viz/common/*   |
206
207
208## Naming guidelines with Mojo <a name="naming-guidelines"></a>
209
210Viz makes extensive use of Mojo, and there are conflicting patterns with
211regard to naming types around Mojo interfaces in the codebase today. This aims
212to provide a standard to adhere to for future naming to increase our
213consistency within the team.
214
215For a given mojo service called `TimeTraveller`, we would use the following.
216
217**Mojo Interface**: `mojom::TimeTraveller`
218* This is the abstract interface definition. It comes with no prefix or suffix,
219and lives in a (sometimes nested) mojom namespace.
220
221**Mojo Implementation**: `TimeTravellerImpl`
222* This is the implementation of the interface. For other C++ interfaces we
223commonly use the Impl suffix, and we will repeat this here, as it’s already
224commonly used and is well understood.
225* If there will be multiple implementations, see below.
226
227**Alternative Mojo Implementation**: `DescriptivePrefixTimeTravellerImpl`
228* This is a non-default implementation of the interface. It follows the same
229rules as a default implementation, but is used for tests, or cases where we
230don’t have a simple default production implementation.
231* The descriptive prefix should describe what makes this implementation
232different from others, as such why it exists.
233
234**Host-side Wrapper**: `HostTimeTraveller`
235* This wraps the Mojo interface, providing a higher-level abstraction and
236utilities for using the Mojo interface. It only is meant to exist and be
237accessed in the privileged Host process. We prefix with Host to explain what
238makes this interface special and when it can be used. We do not suffix to be
239consistent with Clients.
240
241**Client-side Wrapper**: `ClientTimeTraveller`
242* This wraps the Mojo interface, providing a higher-level abstraction and
243utilities for using the Mojo interface. It may exist and be used in any Client
244in place of the Mojo interface. Prefer to use the Mojo interface directly when
245possible. We prefix with Client to explain in what situations it can be used.
246We do not suffix to avoid a TimeTravellerClientClient in the case where this
247class has itself a C++ client, as ClientTimeTravellerClient appeared to be a
248better option of the two.
249
250**Host/Client-side Abstraction**: `OtherAbstractionName`
251* This is a case of an object implementing a C++ interface, which it should be
252named after. A prefix describing what makes this implementation special can
253refer to its use of the Mojo interface.
254