blob: ee6e886d124750edd78bbbe5c9b61ba5daaa24c6 [file] [log] [blame]
Jamie Gennisd1700752013-10-14 12:22:52 -07001/*
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
20namespace android {
21
22EventControlThread::EventControlThread(const sp<SurfaceFlinger>& flinger):
23 mFlinger(flinger),
24 mVsyncEnabled(false) {
25}
26
27void EventControlThread::setVsyncEnabled(bool enabled) {
28 Mutex::Autolock lock(mMutex);
29 mVsyncEnabled = enabled;
30 mCond.signal();
31}
32
33bool EventControlThread::threadLoop() {
34 Mutex::Autolock lock(mMutex);
35
36 bool vsyncEnabled = mVsyncEnabled;
37
Fabien Sanglard9d96de42016-10-11 00:15:18 +000038#ifdef USE_HWC2
Dan Stoza9e56aa02015-11-02 13:00:03 -080039 mFlinger->setVsyncEnabled(HWC_DISPLAY_PRIMARY, mVsyncEnabled);
Fabien Sanglard9d96de42016-10-11 00:15:18 +000040#else
41 mFlinger->eventControl(HWC_DISPLAY_PRIMARY, SurfaceFlinger::EVENT_VSYNC,
42 mVsyncEnabled);
43#endif
Jamie Gennisd1700752013-10-14 12:22:52 -070044
45 while (true) {
46 status_t err = mCond.wait(mMutex);
47 if (err != NO_ERROR) {
48 ALOGE("error waiting for new events: %s (%d)",
49 strerror(-err), err);
50 return false;
51 }
52
53 if (vsyncEnabled != mVsyncEnabled) {
Fabien Sanglard9d96de42016-10-11 00:15:18 +000054#ifdef USE_HWC2
Dan Stoza9e56aa02015-11-02 13:00:03 -080055 mFlinger->setVsyncEnabled(HWC_DISPLAY_PRIMARY, mVsyncEnabled);
Fabien Sanglard9d96de42016-10-11 00:15:18 +000056#else
57 mFlinger->eventControl(HWC_DISPLAY_PRIMARY,
58 SurfaceFlinger::EVENT_VSYNC, mVsyncEnabled);
59#endif
Jamie Gennisd1700752013-10-14 12:22:52 -070060 vsyncEnabled = mVsyncEnabled;
61 }
62 }
63
64 return false;
65}
66
67} // namespace android