blob: 1ead138efc2d3dec461a3957c9d52136c9b894f8 [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);
33 return std::vector<Display>(mDisplays.begin(), mDisplays.end());
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
Chia-I Wu8b20c5c2018-01-25 11:18:10 -080054 if (connection == Connection::CONNECTED) {
55 if (!mDisplays.insert(display).second) {
56 mInvalidHotplugCount++;
57 }
58 } else if (connection == Connection::DISCONNECTED) {
59 if (!mDisplays.erase(display)) {
60 mInvalidHotplugCount++;
61 }
Daniel Nicoarad47f4a92017-05-30 15:38:30 -040062 }
Daniel Nicoarad47f4a92017-05-30 15:38:30 -040063
Chia-I Wu8b20c5c2018-01-25 11:18:10 -080064 return Void();
Daniel Nicoarad47f4a92017-05-30 15:38:30 -040065}
66
67Return<void> GraphicsComposerCallback::onRefresh(Display display) {
Chia-I Wu8b20c5c2018-01-25 11:18:10 -080068 std::lock_guard<std::mutex> lock(mMutex);
Daniel Nicoarad47f4a92017-05-30 15:38:30 -040069
Chia-I Wu8b20c5c2018-01-25 11:18:10 -080070 if (mDisplays.count(display) == 0) {
71 mInvalidRefreshCount++;
72 }
Daniel Nicoarad47f4a92017-05-30 15:38:30 -040073
Chia-I Wu8b20c5c2018-01-25 11:18:10 -080074 return Void();
Daniel Nicoarad47f4a92017-05-30 15:38:30 -040075}
76
77Return<void> GraphicsComposerCallback::onVsync(Display display, int64_t) {
Chia-I Wu8b20c5c2018-01-25 11:18:10 -080078 std::lock_guard<std::mutex> lock(mMutex);
Daniel Nicoarad47f4a92017-05-30 15:38:30 -040079
Chia-I Wu8b20c5c2018-01-25 11:18:10 -080080 if (!mVsyncAllowed || mDisplays.count(display) == 0) {
81 mInvalidVsyncCount++;
82 }
Daniel Nicoarad47f4a92017-05-30 15:38:30 -040083
Chia-I Wu8b20c5c2018-01-25 11:18:10 -080084 return Void();
Daniel Nicoarad47f4a92017-05-30 15:38:30 -040085}
86
Chia-I Wu96a098a2018-01-25 10:38:06 -080087} // namespace vts
Daniel Nicoarad47f4a92017-05-30 15:38:30 -040088} // namespace V2_1
89} // namespace composer
90} // namespace graphics
91} // namespace hardware
92} // namespace android