---
# System prepended metadata

title: SetNeedsCommit in cc
tags: [Chromium-Graphics, elkurin-daily-note]

---

# SetNeedsCommit in cc

[LayerTreeHost::SetNeedsCommit](https://source.chromium.org/chromium/chromium/src/+/main:cc/trees/layer_tree_host.cc;l=717;drc=f4a00cc248dd2dc8ec8759fb51620d47b5114090) requests that the next maine frame update performs a full commit synchronization.  
Today, let's check when it's called and where it goes.

## Call from UI
There are three ways to call SetNeeds from ui side.  
[Compositor::ScheduleDraw](https://source.chromium.org/chromium/chromium/src/+/main:ui/compositor/compositor.cc;l=378;drc=f4a00cc248dd2dc8ec8759fb51620d47b5114090), [Compositor::ScheduleFullRedraw](https://source.chromium.org/chromium/chromium/src/+/main:ui/compositor/compositor.cc;l=421;drc=f4a00cc248dd2dc8ec8759fb51620d47b5114090) and [Compositor::ScheduleRedrawRect](https://source.chromium.org/chromium/chromium/src/+/main:ui/compositor/compositor.cc;l=424;drc=f4a00cc248dd2dc8ec8759fb51620d47b5114090).

### SheduleDraw
ScheduleDraw is called when [background color is updated](https://source.chromium.org/chromium/chromium/src/+/main:ui/compositor/compositor.cc;l=524;drc=f4a00cc248dd2dc8ec8759fb51620d47b5114090), [fast rounded corner is flipped](https://source.chromium.org/chromium/chromium/src/+/main:ui/compositor/layer.cc;l=841;drc=f4a00cc248dd2dc8ec8759fb51620d47b5114090), [bounds is set](https://source.chromium.org/chromium/chromium/src/+/main:ui/compositor/layer.cc;l=1595;drc=f4a00cc248dd2dc8ec8759fb51620d47b5114090), [opacity is set](https://source.chromium.org/chromium/chromium/src/+/main:ui/compositor/layer.cc;l=1652;drc=f4a00cc248dd2dc8ec8759fb51620d47b5114090), [transformation is set](https://source.chromium.org/chromium/chromium/src/+/main:ui/views/view.cc;l=711;drc=f4a00cc248dd2dc8ec8759fb51620d47b5114090).  

Also, it's requested o [View::InvalidateLayout](https://source.chromium.org/chromium/chromium/src/+/main:ui/views/view.cc;l=900;drc=f4a00cc248dd2dc8ec8759fb51620d47b5114090).  
This is called from [DesktopWindowTreeHostPlatform::ScheduleRelayout](https://source.chromium.org/chromium/chromium/src/+/main:ui/views/widget/desktop_aura/desktop_window_tree_host_platform.cc;l=1036;drc=f4a00cc248dd2dc8ec8759fb51620d47b5114090) which is called on [SetFullscreen](https://source.chromium.org/chromium/chromium/src/+/main:ui/views/widget/desktop_aura/desktop_window_tree_host_platform.cc;l=753;drc=f4a00cc248dd2dc8ec8759fb51620d47b5114090), [OnWindowStateChanged](https://source.chromium.org/chromium/chromium/src/+/main:ui/views/widget/desktop_aura/desktop_window_tree_host_platform.cc;l=886;drc=f4a00cc248dd2dc8ec8759fb51620d47b5114090) and [OnActivationChanged](https://source.chromium.org/chromium/chromium/src/+/main:ui/views/widget/desktop_aura/desktop_window_tree_host_platform.cc;l=936;drc=f4a00cc248dd2dc8ec8759fb51620d47b5114090).

### ScheduleRedrawRect
ScheduleRedrawRect is called from [OnDamageRect](https://source.chromium.org/chromium/chromium/src/+/main:ui/aura/window_tree_host_platform.cc;l=244;drc=f4a00cc248dd2dc8ec8759fb51620d47b5114090).  
`damage_rect` which is gfx::Rect is specified as the damaged area and that rect will be set by [SetNeedsRedrawRect](https://source.chromium.org/chromium/chromium/src/+/main:cc/trees/layer_tree_host.cc;l=744;drc=f4a00cc248dd2dc8ec8759fb51620d47b5114090).

### ScheduleFullRedraw
SchedulFullRedraw is a bit similar to SheduelRedrawRect but it marks all area as damaged.  
Here, `device_viewport_rect` represents the all area.  
This is called on setting display property or display security has changed.

## What happens on SetNeedsCommit
[LayerTreeHost::SetNeedsCommit](https://source.chromium.org/chromium/chromium/src/+/main:cc/trees/layer_tree_host.cc;l=717;drc=f4a00cc248dd2dc8ec8759fb51620d47b5114090) request proxy to set needs commit.  
If [`commit_requested_`](https://source.chromium.org/chromium/chromium/src/+/main:cc/trees/single_thread_proxy.cc;l=295;drc=f4a00cc248dd2dc8ec8759fb51620d47b5114090) is not set yet, it [SetNeedsBeginMainFrame](https://source.chromium.org/chromium/chromium/src/+/main:cc/scheduler/scheduler.cc;l=159;drc=f4a00cc248dd2dc8ec8759fb51620d47b5114090) and this value is used to check whether we should send begin main frame.  
If so, [SchedulerStateMachine::NextAction](https://source.chromium.org/chromium/chromium/src/+/main:cc/scheduler/scheduler_state_machine.cc;l=701;drc=f4a00cc248dd2dc8ec8759fb51620d47b5114090) returns [SEND_BEGIN_MAIN_FRAME](https://source.chromium.org/chromium/chromium/src/+/main:cc/scheduler/scheduler_state_machine.h;l=137;drc=f4a00cc248dd2dc8ec8759fb51620d47b5114090) as an action.  
On [ProcessScheduledActions](https://source.chromium.org/chromium/chromium/src/+/main:cc/scheduler/scheduler.cc;l=901;drc=f4a00cc248dd2dc8ec8759fb51620d47b5114090), it will call [ScheduledActionSendBeginMainFrame](https://source.chromium.org/chromium/chromium/src/+/main:cc/trees/single_thread_proxy.cc;l=980;drc=f4a00cc248dd2dc8ec8759fb51620d47b5114090) to post [BeginMainFrame](https://source.chromium.org/chromium/chromium/src/+/main:cc/trees/single_thread_proxy.cc;l=1024;drc=f4a00cc248dd2dc8ec8759fb51620d47b5114090) task.  
At this point, `commit_requested_` is reset to false.  

So, if commit is requested before the previous commit is still waiting to kick BeginMainFrame, it won't produce new frame.