Daniel Nicoara | d47f4a9 | 2017-05-30 15:38:30 -0400 | [diff] [blame] | 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 "GraphicsComposerCallback.h" |
| 18 | |
| 19 | namespace android { |
| 20 | namespace hardware { |
| 21 | namespace graphics { |
| 22 | namespace composer { |
| 23 | namespace V2_1 { |
| 24 | namespace tests { |
| 25 | |
| 26 | void GraphicsComposerCallback::setVsyncAllowed(bool allowed) { |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame^] | 27 | std::lock_guard<std::mutex> lock(mMutex); |
| 28 | mVsyncAllowed = allowed; |
Daniel Nicoara | d47f4a9 | 2017-05-30 15:38:30 -0400 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | std::vector<Display> GraphicsComposerCallback::getDisplays() const { |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame^] | 32 | std::lock_guard<std::mutex> lock(mMutex); |
| 33 | return std::vector<Display>(mDisplays.begin(), mDisplays.end()); |
Daniel Nicoara | d47f4a9 | 2017-05-30 15:38:30 -0400 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | int GraphicsComposerCallback::getInvalidHotplugCount() const { |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame^] | 37 | std::lock_guard<std::mutex> lock(mMutex); |
| 38 | return mInvalidHotplugCount; |
Daniel Nicoara | d47f4a9 | 2017-05-30 15:38:30 -0400 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | int GraphicsComposerCallback::getInvalidRefreshCount() const { |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame^] | 42 | std::lock_guard<std::mutex> lock(mMutex); |
| 43 | return mInvalidRefreshCount; |
Daniel Nicoara | d47f4a9 | 2017-05-30 15:38:30 -0400 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | int GraphicsComposerCallback::getInvalidVsyncCount() const { |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame^] | 47 | std::lock_guard<std::mutex> lock(mMutex); |
| 48 | return mInvalidVsyncCount; |
Daniel Nicoara | d47f4a9 | 2017-05-30 15:38:30 -0400 | [diff] [blame] | 49 | } |
| 50 | |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame^] | 51 | Return<void> GraphicsComposerCallback::onHotplug(Display display, Connection connection) { |
| 52 | std::lock_guard<std::mutex> lock(mMutex); |
Daniel Nicoara | d47f4a9 | 2017-05-30 15:38:30 -0400 | [diff] [blame] | 53 | |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame^] | 54 | 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 Nicoara | d47f4a9 | 2017-05-30 15:38:30 -0400 | [diff] [blame] | 62 | } |
Daniel Nicoara | d47f4a9 | 2017-05-30 15:38:30 -0400 | [diff] [blame] | 63 | |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame^] | 64 | return Void(); |
Daniel Nicoara | d47f4a9 | 2017-05-30 15:38:30 -0400 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | Return<void> GraphicsComposerCallback::onRefresh(Display display) { |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame^] | 68 | std::lock_guard<std::mutex> lock(mMutex); |
Daniel Nicoara | d47f4a9 | 2017-05-30 15:38:30 -0400 | [diff] [blame] | 69 | |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame^] | 70 | if (mDisplays.count(display) == 0) { |
| 71 | mInvalidRefreshCount++; |
| 72 | } |
Daniel Nicoara | d47f4a9 | 2017-05-30 15:38:30 -0400 | [diff] [blame] | 73 | |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame^] | 74 | return Void(); |
Daniel Nicoara | d47f4a9 | 2017-05-30 15:38:30 -0400 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | Return<void> GraphicsComposerCallback::onVsync(Display display, int64_t) { |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame^] | 78 | std::lock_guard<std::mutex> lock(mMutex); |
Daniel Nicoara | d47f4a9 | 2017-05-30 15:38:30 -0400 | [diff] [blame] | 79 | |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame^] | 80 | if (!mVsyncAllowed || mDisplays.count(display) == 0) { |
| 81 | mInvalidVsyncCount++; |
| 82 | } |
Daniel Nicoara | d47f4a9 | 2017-05-30 15:38:30 -0400 | [diff] [blame] | 83 | |
Chia-I Wu | 8b20c5c | 2018-01-25 11:18:10 -0800 | [diff] [blame^] | 84 | return Void(); |
Daniel Nicoara | d47f4a9 | 2017-05-30 15:38:30 -0400 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | } // namespace tests |
| 88 | } // namespace V2_1 |
| 89 | } // namespace composer |
| 90 | } // namespace graphics |
| 91 | } // namespace hardware |
| 92 | } // namespace android |