blob: ccbc5b129253eaa64c12eb2ab587f47e677be44f [file] [log] [blame]
Daniel Nicoarad47f4a92017-05-30 15:38:30 -04001/*
2 * Copyright (C) 2017 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
Chia-I Wu96a098a2018-01-25 10:38:06 -080017#include <composer-vts/2.1/GraphicsComposerCallback.h>
Daniel Nicoarad47f4a92017-05-30 15:38:30 -040018
19namespace android {
20namespace hardware {
21namespace graphics {
22namespace composer {
23namespace V2_1 {
Chia-I Wu96a098a2018-01-25 10:38:06 -080024namespace vts {
Daniel Nicoarad47f4a92017-05-30 15:38:30 -040025
26void GraphicsComposerCallback::setVsyncAllowed(bool allowed) {
Chia-I Wu8b20c5c2018-01-25 11:18:10 -080027 std::lock_guard<std::mutex> lock(mMutex);
28 mVsyncAllowed = allowed;
Daniel Nicoarad47f4a92017-05-30 15:38:30 -040029}
30
31std::vector<Display> GraphicsComposerCallback::getDisplays() const {
Chia-I Wu8b20c5c2018-01-25 11:18:10 -080032 std::lock_guard<std::mutex> lock(mMutex);
Kui1 Wuada28502021-12-14 13:08:22 +080033 return mDisplays;
Daniel Nicoarad47f4a92017-05-30 15:38:30 -040034}
35
36int GraphicsComposerCallback::getInvalidHotplugCount() const {
Chia-I Wu8b20c5c2018-01-25 11:18:10 -080037 std::lock_guard<std::mutex> lock(mMutex);
38 return mInvalidHotplugCount;
Daniel Nicoarad47f4a92017-05-30 15:38:30 -040039}
40
41int GraphicsComposerCallback::getInvalidRefreshCount() const {
Chia-I Wu8b20c5c2018-01-25 11:18:10 -080042 std::lock_guard<std::mutex> lock(mMutex);
43 return mInvalidRefreshCount;
Daniel Nicoarad47f4a92017-05-30 15:38:30 -040044}
45
46int GraphicsComposerCallback::getInvalidVsyncCount() const {
Chia-I Wu8b20c5c2018-01-25 11:18:10 -080047 std::lock_guard<std::mutex> lock(mMutex);
48 return mInvalidVsyncCount;
Daniel Nicoarad47f4a92017-05-30 15:38:30 -040049}
50
Chia-I Wu8b20c5c2018-01-25 11:18:10 -080051Return<void> GraphicsComposerCallback::onHotplug(Display display, Connection connection) {
52 std::lock_guard<std::mutex> lock(mMutex);
Daniel Nicoarad47f4a92017-05-30 15:38:30 -040053
Kui1 Wuada28502021-12-14 13:08:22 +080054 auto it = std::find(mDisplays.begin(), mDisplays.end(), display);
Chia-I Wu8b20c5c2018-01-25 11:18:10 -080055 if (connection == Connection::CONNECTED) {
Kui1 Wuada28502021-12-14 13:08:22 +080056 if (it == mDisplays.end()) {
57 mDisplays.push_back(display);
58 } else {
Chia-I Wu8b20c5c2018-01-25 11:18:10 -080059 mInvalidHotplugCount++;
60 }
61 } else if (connection == Connection::DISCONNECTED) {
Kui1 Wuada28502021-12-14 13:08:22 +080062 if (it != mDisplays.end()) {
63 mDisplays.erase(it);
64 } else {
Chia-I Wu8b20c5c2018-01-25 11:18:10 -080065 mInvalidHotplugCount++;
66 }
Daniel Nicoarad47f4a92017-05-30 15:38:30 -040067 }
Daniel Nicoarad47f4a92017-05-30 15:38:30 -040068
Chia-I Wu8b20c5c2018-01-25 11:18:10 -080069 return Void();
Daniel Nicoarad47f4a92017-05-30 15:38:30 -040070}
71
72Return<void> GraphicsComposerCallback::onRefresh(Display display) {
Chia-I Wu8b20c5c2018-01-25 11:18:10 -080073 std::lock_guard<std::mutex> lock(mMutex);
Daniel Nicoarad47f4a92017-05-30 15:38:30 -040074
Kui1 Wuada28502021-12-14 13:08:22 +080075 auto it = std::find(mDisplays.begin(), mDisplays.end(), display);
76 if (it == mDisplays.end()) {
Chia-I Wu8b20c5c2018-01-25 11:18:10 -080077 mInvalidRefreshCount++;
78 }
Daniel Nicoarad47f4a92017-05-30 15:38:30 -040079
Chia-I Wu8b20c5c2018-01-25 11:18:10 -080080 return Void();
Daniel Nicoarad47f4a92017-05-30 15:38:30 -040081}
82
83Return<void> GraphicsComposerCallback::onVsync(Display display, int64_t) {
Chia-I Wu8b20c5c2018-01-25 11:18:10 -080084 std::lock_guard<std::mutex> lock(mMutex);
Daniel Nicoarad47f4a92017-05-30 15:38:30 -040085
Kui1 Wuada28502021-12-14 13:08:22 +080086 auto it = std::find(mDisplays.begin(), mDisplays.end(), display);
87 if (!mVsyncAllowed || it == mDisplays.end()) {
Chia-I Wu8b20c5c2018-01-25 11:18:10 -080088 mInvalidVsyncCount++;
89 }
Daniel Nicoarad47f4a92017-05-30 15:38:30 -040090
Chia-I Wu8b20c5c2018-01-25 11:18:10 -080091 return Void();
Daniel Nicoarad47f4a92017-05-30 15:38:30 -040092}
93
Chia-I Wu96a098a2018-01-25 10:38:06 -080094} // namespace vts
Daniel Nicoarad47f4a92017-05-30 15:38:30 -040095} // namespace V2_1
96} // namespace composer
97} // namespace graphics
98} // namespace hardware
99} // namespace android