# CompositorFrame in Code
The concept of Compositor Frame appears a lot but haven't checked its implementation.
Let's check [CompositorFrame](https://source.chromium.org/chromium/chromium/src/+/main:components/viz/common/quads/compositor_frame.h;l=26;drc=8ba1bad80dc22235693a0dd41fe55c0fd2dbdabd).
## Overview
Compositor frame is a complete output of the compositor meant for display. Each compositor creates one compositor frame and submits it.
The class [CompositorFrame](https://source.chromium.org/chromium/chromium/src/+/main:components/viz/common/quads/compositor_frame.h;l=26;drc=8ba1bad80dc22235693a0dd41fe55c0fd2dbdabd) is its representation.
There are 3 data stored in this class: metadata, resource_list and render_pass_list.
`metadata` is [CompositorFrameMetadata](https://source.chromium.org/chromium/chromium/src/+/main:components/viz/common/quads/compositor_frame_metadata.h;l=66;drc=8e78783dc1f7007bad46d657c9f332614e240fd8) which stores a lot of information required for compositor such as [device_scale_factor](https://source.chromium.org/chromium/chromium/src/+/main:components/viz/common/quads/compositor_frame_metadata.h;l=78;drc=8e78783dc1f7007bad46d657c9f332614e240fd8).
`resource_list` is a vector of [TransferableResource](https://source.chromium.org/chromium/chromium/src/+/main:components/viz/common/resources/transferable_resource.h;l=33;drc=8e78783dc1f7007bad46d657c9f332614e240fd8).
`render_pass_list` is a vector of [CompositorRenderPass](https://source.chromium.org/chromium/chromium/src/+/main:components/viz/common/quads/compositor_render_pass.h;l=51;drc=8e78783dc1f7007bad46d657c9f332614e240fd8) which representa a render pass that is submitted from the UI or renderer. This list is in the order that will be drawn.
## Who Creates CompositorFrame
Compositor frame is an output of cc, so it's created in cc.
Let's dig in a bit deeper.
In cc, [LayerTreeHostImpl::GenerateCompositorFrame](https://source.chromium.org/chromium/chromium/src/+/main:cc/trees/layer_tree_host_impl.cc;l=2634;drc=8e78783dc1f7007bad46d657c9f332614e240fd8) generates the CompositorFrame based on [FrameData](https://source.chromium.org/chromium/chromium/src/+/main:cc/trees/layer_tree_host_impl.h;l=203;drc=8e78783dc1f7007bad46d657c9f332614e240fd8) which contains the render pass list.
This is dispatched from the main thread (not impl thread) by [SingleThreadProxy::ScheduledActionDrawIfPossible](https://source.chromium.org/chromium/chromium/src/+/main:cc/trees/single_thread_proxy.cc;l=1165;drc=8e78783dc1f7007bad46d657c9f332614e240fd8).
FrameData is constructed here from its last active begin frmae ack and origin frame.
The latest begin frame info is stored in [cc::Scheduler](https://source.chromium.org/chromium/chromium/src/+/main:cc/scheduler/scheduler.h;l=308-310;drc=8e78783dc1f7007bad46d657c9f332614e240fd8) and updated on each BeginFrame cycle.
cc::Scheduler is one of many schedulers exising alog with blink scheduler, viz::DisplayScheduler, gpu shceduler and the browser UI task scheduler.
### BeginFrameAck
[BeginFrameAck](https://source.chromium.org/chromium/chromium/src/+/main:components/viz/common/frame_sinks/begin_frame_args.h;l=256;drc=80eab8abba53228b3c8f5c3fc959599dda3bcab1) represents an event that acknowledge the BeginFrame completion and sent to BeginFrameObserver.
It carries [BeginFrameId](https://source.chromium.org/chromium/chromium/src/+/main:components/viz/common/frame_sinks/begin_frame_args.h;l=53;drc=8e78783dc1f7007bad46d657c9f332614e240fd8) that is a union of `source_id` and `sequence_number`.