# What is Viz?
I've been reading codes under //components/viz, but what is viz responsible for overall?
Let's see the bigger picture.
## Viz service
Viz service is a collection of subservices: compositing, gl, hit testing, and media.
[//service/viz](https://source.chromium.org/chromium/chromium/src/+/main:services/viz/) contains the APIs to communicate with viz service.
There are two types of APIs, one is "privileged" and the other is "public".
Privileged APIs are used from privileged, the client implemented by Chrome. Public APIs can be called from outside for example Blink. Some of them are expesed as a stable public API.
For example, [display_private.mojom](https://source.chromium.org/chromium/chromium/src/+/main:services/viz/privileged/mojom/compositing/display_private.mojom) contains a private API for privileged clients to talk to display.
This is implemented in [viz::RootCompositorFrameSinkImpl](https://source.chromium.org/chromium/chromium/src/+/main:components/viz/service/frame_sinks/root_compositor_frame_sink_impl.h;l=45;drc=82af9937ec9e38900710886efe58b5bc4b3667b1) which is in //components/viz/service and called, for example, from [ui::Compositor](https://source.chromium.org/chromium/chromium/src/+/main:ui/compositor/compositor.cc;l=331;drc=e5f8ff312fe542f39c7d34b4440f18d1500b15f9).
The subservices implementations are in different directories.
- compositing and hit-testing -> //components/viz
- command buffer -> [//gpu](https://source.chromium.org/chromium/chromium/src/+/main:gpu/)
- media -> [//media](https://source.chromium.org/chromium/chromium/src/+/main:media/)
However, this location is for short term and will be migrated into //service/viz once the content module has been removed.
## //comonents/viz
//components/viz a one of the subservices described above which is reponsible for compositing and gpu presentation.
### Display Compositor
The display compositor uses GPU or software to composite a set of frames from multiple clients.
It combines frames submitted to the viz service through frame sinks into a single GPU or software resource.
This is in [//components/viz/service/display](https://source.chromium.org/chromium/chromium/src/+/main:components/viz/service/display/).
This directory does not contain platform-specific presentation details.
It's abstracted behind [OutputSurface](https://source.chromium.org/chromium/chromium/src/+/main:components/viz/service/display/output_surface.h) / [SoftwareOutputDevice](https://source.chromium.org/chromium/chromium/src/+/main:components/viz/service/display/software_output_device.h).
OutputSurface is extended by
- SkiaOutputSurface: gpu rendering
- SoftwareOutputSurface: software rendering
- OutputSurfaceUnified: ChromeOS unified desktop display (fake display)
- SynchronousLayerTreeFrameSink: third party Blink
Some platform-specific implementation of display compositor stays in [//components/vize/service/display_embedder](https://source.chromium.org/chromium/chromium/src/+/main:components/viz/service/display_embedder/).
It accesses GPU services through the command buffer even though **it is in the same process as GPU** so that it can act in the same way as other clients.
### Mojo impl
Frame sink implements the Mojo interfaces to send frames, resources and other data types from /viz/common/.
The impl is in [//components/viz/service/frame_sinks](https://source.chromium.org/chromium/chromium/src/+/main:components/viz/service/frame_sinks/).
For example, [viz::RootCompositorFrameSinkImpl](https://source.chromium.org/chromium/chromium/src/+/main:components/viz/service/frame_sinks/root_compositor_frame_sink_impl.h;l=45;drc=82af9937ec9e38900710886efe58b5bc4b3667b1), the one we checked above, is in [//components/viz/service/frame_sinkds/root_compositor_frame_sink_impl](https://source.chromium.org/chromium/chromium/src/+/main:components/viz/service/frame_sinks/root_compositor_frame_sink_impl.h;l=45?q=RootCompositorFrameSinkImpl&ss=chromium%2Fchromium%2Fsrc:components%2Fviz%2Fservice%2Fframe_sinks%2F).
On the other hand, //components/viz/service/frame_sinks/video_capture implements Mojo interfaces to capture frames. It provides a capture pipeline where asynchronous GPU readback is executed.
//components/viz/service/gl impelments the Mojo interfaces for allocating GPU memory buffers.
### Surfaces
[//components/viz/service/surfaces](https://source.chromium.org/chromium/chromium/src/+/main:components/viz/service/surfaces/) holds the data received from frame sinks (mojo interface) and provides access to them for the display compositor.
Here, the data is for example [viz::Surface](https://source.chromium.org/chromium/chromium/src/+/main:components/viz/service/surfaces/surface.h;l=98;drc=e3f42a1ef6e5a8fe14caf2699393895b9bdf349b) which represents a sequence of CompositorFrames.
It contains a corresponding surface id and active frame data to identify the current frame.
THe pending frames are stored as circular dequeue named `uncommited_frames_`.
This is managed from [viz::SurfaceManager](https://source.chromium.org/chromium/chromium/src/+/main:components/viz/service/surfaces/surface_manager.h;l=52;drc=e63cbaf6fdcfdac0f04883d956b00e83330bd0a2).
Surface can created via [SurfaceManager::CreateSurface](https://source.chromium.org/chromium/chromium/src/+/main:components/viz/service/surfaces/surface_manager.cc;l=110;drc=e63cbaf6fdcfdac0f04883d956b00e83330bd0a2) who is called in mojo API [SubmitCompositorFrame in compositor_frame_sink.mojom](https://source.chromium.org/chromium/chromium/src/+/main:services/viz/public/mojom/compositing/compositor_frame_sink.mojom;l=72;drc=e5f8ff312fe542f39c7d34b4440f18d1500b15f9).
## Note
[//gpu](https://source.chromium.org/chromium/chromium/src/+/main:gpu/) and [//media](https://source.chromium.org/chromium/chromium/src/+/main:media/) might be a great area to study.
Especially, [/media/README.md](https://source.chromium.org/chromium/chromium/src/+/main:media/README.md) looks great.