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