---
# System prepended metadata

title: When we produce new frame
tags: [Chromium-Graphics, elkurin-daily-note]

---

# When we produce new frame

We predict whether we need to produce frame in [OnStateUpdate](https://source.chromium.org/chromium/chromium/src/+/main:ui/aura/window_tree_host_platform.cc;l=330-344;drc=f4a00cc248dd2dc8ec8759fb51620d47b5114090) from state updates and visibility.  
Then in what condition it does actually produce a frame?

This is a code reading note for learning purpose.

## Seq id
seq id is set on [SkiaRenderer::SwapBuffers](https://source.chromium.org/chromium/chromium/src/+/main:components/viz/service/display/skia_renderer.cc;l=1232;drc=f4a00cc248dd2dc8ec8759fb51620d47b5114090).  
This is set to [parent sequence's local_surface_id](https://source.chromium.org/chromium/chromium/src/+/main:components/viz/service/display/display.cc;l=1014;drc=f4a00cc248dd2dc8ec8759fb51620d47b5114090).  

## Needs commit
[needs_commit](https://source.chromium.org/chromium/chromium/src/+/main:ui/ozone/platform/wayland/host/wayland_frame_manager.cc;l=289;drc=896c8affa4958aefe0ab750cdc4a69b15d97816d) calculates whether the incoming frame should be committed.  
`needs_commit` is calculated per subsurface contained in the WaylandFrame in the reverse order.  
If a subsurface needs to commit, [WaylandSurface::Commit](https://source.chromium.org/chromium/chromium/src/+/main:ui/ozone/platform/wayland/host/wayland_surface.cc;l=306;drc=f4a00cc248dd2dc8ec8759fb51620d47b5114090) is called and sends `wl_surface_commit` message.

[ConfigureAndShowSurface](https://source.chromium.org/chromium/chromium/src/+/main:ui/ozone/platform/wayland/host/wayland_subsurface.cc;l=129;drc=f4a00cc248dd2dc8ec8759fb51620d47b5114090) sets up `wl_subsurface` by stacking order of subsurfaces.  
It returns whether or not changes require a commit to `wl_surface`.  
1. [WaylandSubsurface::Show](https://source.chromium.org/chromium/chromium/src/+/main:ui/ozone/platform/wayland/host/wayland_subsurface.cc;l=58;drc=f4a00cc248dd2dc8ec8759fb51620d47b5114090) returns false if the frame is already visible. `visible_` becomes true by `Show` and false by `Hide`.
2. true if origin is changed (<- this may not be needed)
3. true if clip is changed
4. true if transform is changed
5. true if below frame or above frame is changed

[ApplySurfaceConfigure](https://source.chromium.org/chromium/chromium/src/+/main:ui/ozone/platform/wayland/host/wayland_frame_manager.cc;l=340;drc=f4a00cc248dd2dc8ec8759fb51620d47b5114090) calculates `need_commit` again.  
This configures surface without committing `wl_surface` and returns if we should commit to the `wl_surface`.  
`need_commit` is true if
- [WaylandSurface::AttachBuffer](https://source.chromium.org/chromium/chromium/src/+/main:ui/ozone/platform/wayland/host/wayland_surface.cc;l=279;drc=f4a00cc248dd2dc8ec8759fb51620d47b5114090) returns true + frame callback is null. AttachBuffer returns true if buffer id is different between `state_` and `pending_state_`.
- if presentation is non-null
- calculatres [ApplyPendingState](https://source.chromium.org/chromium/chromium/src/+/main:ui/ozone/platform/wayland/host/wayland_surface.cc;l=451;drc=f4a00cc248dd2dc8ec8759fb51620d47b5114090): if the state has been changed for example: buffer id, color space, transform, opacity, use blending, priority hint, input region, opaque region, background color, rounded clip boiunds, clip rect, contains video...


