Advanced AOSP Subsystems
3 min read

VSYNC

Overview

VSYNC (Vertical Synchronization) is the fundamental timing signal that governs the entire Android graphics pipeline. It ensures that applications produce frames and SurfaceFlinger composites them in perfect alignment with the physical display's refresh cycle, eliminating screen tearing and minimizing latency.

Hardware VSYNC from Display

The source of truth for VSYNC is the physical display hardware. When the screen finishes drawing the last scanline of a frame and returns to the top to begin the next frame, it generates a hardware interrupt.

The Hardware Composer (HWC) captures this interrupt and relays it to SurfaceFlinger. Historically, applications would wait directly for this hardware pulse, but this approach proved inflexible and prone to latency.

Software VSYNC (DispSync)

To gain finer control over timing, Android uses a software phase-locked loop (PLL) known as DispSync.

Instead of routing raw hardware interrupts directly to applications, SurfaceFlinger uses DispSync to model the hardware's frequency and phase. SurfaceFlinger periodically samples the hardware VSYNC to calibrate DispSync, and then generates highly predictable, synthetic VSYNC signals.

This abstraction allows Android to generate VSYNC signals in the future and apply calculated offsets, giving the OS the ability to finely tune the scheduling pipeline.

VSYNC Offsets: App and SurfaceFlinger

To minimize input-to-display latency, Android splits the synthetic VSYNC into two distinct signals: VSYNC-App and VSYNC-SF.

  • VSYNC-App: Sent to the application's Choreographer. It tells the app to start measuring, laying out, and drawing the UI.
  • VSYNC-SF: Sent to SurfaceFlinger. It tells the compositor to acquire the newly drawn buffers from the apps and composite them for the screen.

By utilizing phase offsets, SurfaceFlinger can schedule these events sequentially rather than simultaneously. For example, if a display refreshes every 16.6ms (60Hz):

  1. VSYNC-App fires at t=0. The app begins drawing.
  2. VSYNC-SF fires at t=8ms (an 8ms offset). SurfaceFlinger wakes up, grabs the frame the app just finished, composites it, and sends it to the display just in time for the t=16.6ms physical refresh.

This pipelining reduces perceived latency compared to making SurfaceFlinger wait an entire frame cycle to composite the app's output.

VSYNC Modulation for Variable Refresh Rate

Modern Android devices feature Variable Refresh Rate (VRR) displays (e.g., smoothly transitioning between 10Hz, 60Hz, and 120Hz).

VSYNC modulation dynamically adjusts the VSYNC frequency based on the content on screen. If the user is reading static text, SurfaceFlinger instructs the HWC to drop the refresh rate to 10Hz, heavily saving battery. The moment the user touches the screen, SurfaceFlinger spikes the VSYNC frequency to 120Hz, ensuring instantaneous Choreographer wakeups and ultra-smooth scrolling.

To inspect the active VSYNC signals and offsets, use the dumpsys command:

adb shell dumpsys SurfaceFlinger | grep -A 20 DispSync

This output details the current phase offsets, the physical hardware refresh rate, and the exact timing model currently active in the system.