1 /*
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
17 #include <composer-vts/2.1/GraphicsComposerCallback.h>
18
19 namespace android {
20 namespace hardware {
21 namespace graphics {
22 namespace composer {
23 namespace V2_1 {
24 namespace vts {
25
setVsyncAllowed(bool allowed)26 void GraphicsComposerCallback::setVsyncAllowed(bool allowed) {
27 std::lock_guard<std::mutex> lock(mMutex);
28 mVsyncAllowed = allowed;
29 }
30
getDisplays() const31 std::vector<Display> GraphicsComposerCallback::getDisplays() const {
32 std::lock_guard<std::mutex> lock(mMutex);
33 return mDisplays;
34 }
35
getInvalidHotplugCount() const36 int GraphicsComposerCallback::getInvalidHotplugCount() const {
37 std::lock_guard<std::mutex> lock(mMutex);
38 return mInvalidHotplugCount;
39 }
40
getInvalidRefreshCount() const41 int GraphicsComposerCallback::getInvalidRefreshCount() const {
42 std::lock_guard<std::mutex> lock(mMutex);
43 return mInvalidRefreshCount;
44 }
45
getInvalidVsyncCount() const46 int GraphicsComposerCallback::getInvalidVsyncCount() const {
47 std::lock_guard<std::mutex> lock(mMutex);
48 return mInvalidVsyncCount;
49 }
50
onHotplug(Display display,Connection connection)51 Return<void> GraphicsComposerCallback::onHotplug(Display display, Connection connection) {
52 std::lock_guard<std::mutex> lock(mMutex);
53
54 auto it = std::find(mDisplays.begin(), mDisplays.end(), display);
55 if (connection == Connection::CONNECTED) {
56 if (it == mDisplays.end()) {
57 mDisplays.push_back(display);
58 } else {
59 mInvalidHotplugCount++;
60 }
61 } else if (connection == Connection::DISCONNECTED) {
62 if (it != mDisplays.end()) {
63 mDisplays.erase(it);
64 } else {
65 mInvalidHotplugCount++;
66 }
67 }
68
69 return Void();
70 }
71
onRefresh(Display display)72 Return<void> GraphicsComposerCallback::onRefresh(Display display) {
73 std::lock_guard<std::mutex> lock(mMutex);
74
75 auto it = std::find(mDisplays.begin(), mDisplays.end(), display);
76 if (it == mDisplays.end()) {
77 mInvalidRefreshCount++;
78 }
79
80 return Void();
81 }
82
onVsync(Display display,int64_t)83 Return<void> GraphicsComposerCallback::onVsync(Display display, int64_t) {
84 std::lock_guard<std::mutex> lock(mMutex);
85
86 auto it = std::find(mDisplays.begin(), mDisplays.end(), display);
87 if (!mVsyncAllowed || it == mDisplays.end()) {
88 mInvalidVsyncCount++;
89 }
90
91 return Void();
92 }
93
94 } // namespace vts
95 } // namespace V2_1
96 } // namespace composer
97 } // namespace graphics
98 } // namespace hardware
99 } // namespace android
100