Android系统中关于VSYNC的简介
92HWComposer::HWComposer(
93 const sp<SurfaceFlinger>&flinger,
94 EventHandler& handler)
95 : mFlinger(flinger),
96 mFbDev(0), mHwc(0), mNumDisplays(1),
97 mCBContext(new cb_context),
98 mEventHandler(handler),
99 mVSyncCount(0),mDebugForceFakeVSync(false)
100{
101 for (size_t i =0 ; i<MAX_DISPLAYS ; i++){
102 mLists[i] = 0;
103 }
104
105 char value[PROPERTY_VALUE_MAX];
106 property_get("debug.sf.no_hw_vsync", value, "0");
107 mDebugForceFakeVSync = atoi(value);
108
109 boolneedVSyncThread = true;
110
111 // Note: some devices may insist that theFB HAL be opened before HWC.
112 int fberr = loadFbHalModule();
113 loadHwcModule();
114
115 if (mFbDev && mHwc &&hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_1)) {
116 // close FB HAL if we don't needed it.
117 // FIXME: this is temporary until we'renot forced to open FB HAL
118 // before HWC.
119 framebuffer_close(mFbDev);
120 mFbDev = NULL;
121 }
122
123 // If we have no HWC, or a pre-1.1 HWC, anFB dev is mandatory.
124 if ((!mHwc || !hwcHasApiVersion(mHwc,HWC_DEVICE_API_VERSION_1_1))
125 && !mFbDev) {
126 ALOGE("ERROR: failed to openframebuffer (%s), aborting",
127 strerror(-fberr));
128 abort();
129 }
130
131 // these display IDs are always reserved
132 for (size_t i=0 ;i<NUM_PHYSICAL_DISPLAYS ; i++) {
133 mAllocatedDisplayIDs.markBit(i);
134 }
135
136 if (mHwc) {
137 ALOGI("Using %s version%u.%u", HWC_HARDWARE_COMPOSER,
138 (hwcApiVersion(mHwc) >> 24)& 0xff,
139 (hwcApiVersion(mHwc) >> 16)& 0xff);
140 if (mHwc->registerProcs) {
141 mCBContext->hwc = this;
142 mCBContext->procs.invalidate= &hook_invalidate;
143 mCBContext->procs.vsync= &hook_vsync;
144 if (hwcHasApiVersion(mHwc,HWC_DEVICE_API_VERSION_1_1))
145 mCBContext->procs.hotplug =&hook_hotplug;
146 else
147 mCBContext->procs.hotplug =NULL;
148 memset(mCBContext->procs.zero,0, sizeof(mCBContext->procs.zero));
149 mHwc->registerProcs(mHwc,&mCBContext->procs);
150 }
151
152 // don't need avsync thread if we have a hardware composer
153 needVSyncThread= false;
154 // always turn vsync off when we start
155 eventControl(HWC_DISPLAY_PRIMARY,HWC_EVENT_VSYNC, 0);
156
157 // the number of displays we actuallyhave depends on the
158 // hw composer version
159 if (hwcHasApiVersion(mHwc,HWC_DEVICE_API_VERSION_1_EXP)) {
160 // 1.?? adds support for virtualdisplays
161 mNumDisplays = MAX_DISPLAYS;
162 } else if (hwcHasApiVersion(mHwc,HWC_DEVICE_API_VERSION_1_1)) {
163 // 1.1 adds support for multipledisplays
164 mNumDisplays = MAX_DISPLAYS;
165 } else {
166 mNumDisplays = 1;
167 }
168 }
169
170 if (mFbDev) {
171 ALOG_ASSERT(!(mHwc &&hwcHasApiVersion(mHwc, HWC_DEVICE_API_VERSION_1_1)),
172 "should only have fbdev ifno hwc or hwc is 1.0");
173
174 DisplayData&disp(mDisplayData[HWC_DISPLAY_PRIMARY]);
175 disp.connected = true;
176 disp.width = mFbDev->width;
177 disp.height = mFbDev->height;
178 disp.format = mFbDev->format;
179 disp.xdpi = mFbDev->xdpi;
180 disp.ydpi = mFbDev->ydpi;
181 if (disp.refresh == 0) {
182 disp.refresh = nsecs_t(1e9 /mFbDev->fps);
183 ALOGW("getting VSYNC periodfrom fb HAL: %lld", disp.refresh);
184 }
185 if (disp.refresh == 0) {
18