Generation and treatment of 1.1 VSync
In the previous section Projectbutter we learned about the new features in the Android 4.1 display system, one of which is to join the VSync synchronization. From the theoretical point of view, we analyze the necessity and operation mechanism of adopting this mechanism, then how to implement the Surfaceflinger concretely?
Let's think about what you should consider:
· Generation and distribution of vsync signals
If there is a hardware initiative to send this signal, it is the best, otherwise you have to use software timing simulation to generate
· Processing of VSync Signal
When the signal is produced, surfaceflinger how to respond in the shortest time, the specific processing flow is how
Generation and distribution of 1.1.1 VSync signals
There is a Displayhardware folder under the Android source Surfaceflinger directory where Hwcomposer's primary responsibility is to generate vsync signals.
/*frameworks/native/services/surfaceflinger/displayhardware/hwcomposer.cpp*/
Hwcomposer::hwcomposer (const sp<surfaceflinger>& flinger,eventhandler& handler, nsecs_t refreshPeriod )
: Mflinger (Flinger), Mmodule (0), MHWC (0), mlist (0), mcapacity (0), mnumovlayers (0),
Mnumfblayers (0), mdpy (Egl_no_display), Msur (Egl_no_surface),
Meventhandler (handler), Mrefreshperiod (RefreshPeriod),
Mvsynccount (0), Mdebugforcefakevsync (false)
{
Charvalue[property_value_max];
Property_get ("Debug.sf.no_hw_vsync", Value, "0"); System Properties
Mdebugforcefakevsync =atoi (value);
Whether a software simulation is required for bool Needvsyncthread =false;//VSync
int err = Hw_get_module (hwc_hardware_module_id, &mmodule);//Load HAL Module
if (err = = 0) {
Err = Hwc_open (Mmodule, &MHWC);//Open module
if (err = = 0) {
if (Mhwc->registerprocs) {//Registration hardware Device event callback
Mcbcontext.hwc= this;
MCBContext.procs.invalidate = &hook_invalidate;
MCBContext.procs.vsync = &hook_vsync;
Mhwc->registerprocs (MHWC, &mcbcontext.procs);
memset (mCBContext.procs.zero, 0, sizeof (MCBContext.procs.zero));
}
if (mhwc->common.version >= hwc_device_api_version_0_3) {
if (Mdebugforcefakevsync) {//For debugging
Mhwc->methods->eventcontrol (MHWC, Hwc_event_vsync, 0);
}
else {//It is possible to support VSync hardware modules that were added after this version, and older versions still require software simulations
Needvsyncthread = true;
}
}
} else {
Needvsyncthread =true; Hardware module turned on failed with software emulation only
}
if (needvsyncthread) {
Mvsyncthread = new Vsyncthread (*this);//Create a thread that generates a VSYNC signal
}
}