Mobile Development 14 min read

Understanding VSync and Its Implementation in Android

The article explains VSync’s origin, how it prevents screen tearing by synchronizing frame rendering with display refresh, and details Android’s implementation—including hardware and virtual VSync, Choreographer, Triple Buffer, key classes like VsyncTracker and VSyncDispatcher, and the offset/duration concepts introduced in Android S.

OPPO Kernel Craftsman
OPPO Kernel Craftsman
OPPO Kernel Craftsman
Understanding VSync and Its Implementation in Android

The article introduces the origin of Vertical Synchronization (VSync), explaining that screen tearing occurs when a new frame starts being scanned before the previous frame has finished. VSync was created by GPU vendors to provide a signal (TE or VBlank) that synchronizes frame rendering with screen refresh, preventing tearing.

It describes the traditional display pipeline consisting of rendering (CPU/GPU), a frame buffer with back‑buffer and front‑buffer, and the screen. The back‑buffer holds newly rendered data, which becomes the front‑buffer when displayed.

In Android, VSync is a core part of the display system. Since Android 4.1 (Project Butter), VSync is used together with Choreographer and Triple Buffer to improve smoothness. The system aligns app drawing and SurfaceFlinger composition to the VSync signal, reducing jank (frame drops).

The article explains VSync virtualization: a software component (DisplayVSync/VsyncController) generates a virtual VSync based on a reference point and period, optionally synchronizing with hardware VSync. Synchronization is achieved via fence mechanisms; PresentFence signals indicate the actual hardware VSync time, allowing the system to calibrate the virtual VSync.

Distribution of VSync signals to apps and SurfaceFlinger is performed via a high‑performance Domain Socket (BitTube). Apps request VSync through the requestNextVsync binder call, which propagates through EventThread, CallbackRepeater, and VSyncDispatchTimerQueue to the hardware or virtual source.

Key Android classes involved are:

VsyncTracker – predicts future VSync timestamps using past hardware VSync data.

VsyncDispatcher – registers callbacks and dispatches VSync events via VSyncDispatchTimerQueue.

VSyncController – forwards hardware VSync and PresentFence signals through a VSyncReactor.

The article also covers VSync offset and duration concepts introduced in Android S. Offset represents the phase difference between software VSync (app or sf) and hardware VSync, while duration measures the time between app VSync and sf VSync (app duration) and between sf VSync and the screen TE (sf duration). These parameters affect latency, power consumption, and buffer management.

In summary, Android’s VSync architecture consists of hardware VSync signals, virtualized VSync for app and SurfaceFlinger, Choreographer for timing, Triple Buffer for reduced jank, and a sophisticated distribution mechanism that ensures synchronized rendering across the system.

graphicsAndroidSynchronizationChoreographerdisplayVSync
OPPO Kernel Craftsman
Written by

OPPO Kernel Craftsman

Sharing Linux kernel-related cutting-edge technology, technical articles, technical news, and curated tutorials

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.