1 /*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "EventControlThread.h"
18 #include "SurfaceFlinger.h"
19
20 namespace android {
21
EventControlThread(const sp<SurfaceFlinger> & flinger)22 EventControlThread::EventControlThread(const sp<SurfaceFlinger>& flinger):
23 mFlinger(flinger),
24 mVsyncEnabled(false) {
25 }
26
setVsyncEnabled(bool enabled)27 void EventControlThread::setVsyncEnabled(bool enabled) {
28 Mutex::Autolock lock(mMutex);
29 mVsyncEnabled = enabled;
30 mCond.signal();
31 }
32
threadLoop()33 bool EventControlThread::threadLoop() {
34 Mutex::Autolock lock(mMutex);
35
36 bool vsyncEnabled = mVsyncEnabled;
37
38 mFlinger->eventControl(HWC_DISPLAY_PRIMARY, SurfaceFlinger::EVENT_VSYNC,
39 mVsyncEnabled);
40
41 while (true) {
42 status_t err = mCond.wait(mMutex);
43 if (err != NO_ERROR) {
44 ALOGE("error waiting for new events: %s (%d)",
45 strerror(-err), err);
46 return false;
47 }
48
49 if (vsyncEnabled != mVsyncEnabled) {
50 mFlinger->eventControl(HWC_DISPLAY_PRIMARY,
51 SurfaceFlinger::EVENT_VSYNC, mVsyncEnabled);
52 vsyncEnabled = mVsyncEnabled;
53 }
54 }
55
56 return false;
57 }
58
59 } // namespace android
60