The generation and processing of Surfaceflinger (a) VSync signal in the Android GUI system

Source: Internet
Author: User
Tags new features

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

}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.