blob: d53494325afe425227afc80c2d6a6437e3b9dd67 [file] [log] [blame]
ramindani1cb794e2021-10-13 20:45:23 +00001/**
2 * Copyright (c) 2021, 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
ramindani458e53e2022-02-23 17:30:16 +000017#include "GraphicsComposerCallback.h"
ramindani1cb794e2021-10-13 20:45:23 +000018#include <log/log_main.h>
Midas Chiena0b56bd2022-01-13 23:27:33 +080019#include <utils/Timers.h>
ramindani1cb794e2021-10-13 20:45:23 +000020
21#pragma push_macro("LOG_TAG")
22#undef LOG_TAG
23#define LOG_TAG "GraphicsComposerCallback"
24
25namespace aidl::android::hardware::graphics::composer3::vts {
26
27void GraphicsComposerCallback::setVsyncAllowed(bool allowed) {
28 std::scoped_lock lock(mMutex);
29 mVsyncAllowed = allowed;
30}
31
32std::vector<int64_t> GraphicsComposerCallback::getDisplays() const {
33 std::scoped_lock lock(mMutex);
ramindani7ce70fe2022-02-10 18:08:09 +000034 return mDisplays;
ramindani1cb794e2021-10-13 20:45:23 +000035}
36
37int32_t GraphicsComposerCallback::getInvalidHotplugCount() const {
38 std::scoped_lock lock(mMutex);
39 return mInvalidHotplugCount;
40}
41
42int32_t GraphicsComposerCallback::getInvalidRefreshCount() const {
43 std::scoped_lock lock(mMutex);
44 return mInvalidRefreshCount;
45}
46
47int32_t GraphicsComposerCallback::getInvalidVsyncCount() const {
48 std::scoped_lock lock(mMutex);
49 return mInvalidVsyncCount;
50}
51
52int32_t GraphicsComposerCallback::getInvalidVsyncPeriodChangeCount() const {
53 std::scoped_lock lock(mMutex);
54 return mInvalidVsyncPeriodChangeCount;
55}
56
57int32_t GraphicsComposerCallback::getInvalidSeamlessPossibleCount() const {
58 std::scoped_lock lock(mMutex);
59 return mInvalidSeamlessPossibleCount;
60}
61
Midas Chiena0b56bd2022-01-13 23:27:33 +080062int32_t GraphicsComposerCallback::getVsyncIdleCount() const {
63 std::scoped_lock lock(mMutex);
64 return mVsyncIdleCount;
65}
66
67int64_t GraphicsComposerCallback::getVsyncIdleTime() const {
68 std::scoped_lock lock(mMutex);
69 return mVsyncIdleTime;
70}
71
ramindani1cb794e2021-10-13 20:45:23 +000072std::optional<VsyncPeriodChangeTimeline>
73GraphicsComposerCallback::takeLastVsyncPeriodChangeTimeline() {
74 std::scoped_lock lock(mMutex);
75
76 std::optional<VsyncPeriodChangeTimeline> ret;
77 ret.swap(mTimeline);
78
79 return ret;
80}
81
82::ndk::ScopedAStatus GraphicsComposerCallback::onHotplug(int64_t in_display, bool in_connected) {
83 std::scoped_lock lock(mMutex);
ramindani7ce70fe2022-02-10 18:08:09 +000084
85 const auto it = std::find(mDisplays.begin(), mDisplays.end(), in_display);
ramindani1cb794e2021-10-13 20:45:23 +000086 if (in_connected) {
ramindani7ce70fe2022-02-10 18:08:09 +000087 if (it == mDisplays.end()) {
88 mDisplays.push_back(in_display);
89 } else {
ramindani1cb794e2021-10-13 20:45:23 +000090 mInvalidHotplugCount++;
91 }
92 } else {
ramindani7ce70fe2022-02-10 18:08:09 +000093 if (it != mDisplays.end()) {
94 mDisplays.erase(it);
95 } else {
ramindani1cb794e2021-10-13 20:45:23 +000096 mInvalidHotplugCount++;
97 }
98 }
99 return ::ndk::ScopedAStatus::ok();
100}
101
ramindani7ce70fe2022-02-10 18:08:09 +0000102::ndk::ScopedAStatus GraphicsComposerCallback::onRefresh(int64_t in_display) {
ramindani1cb794e2021-10-13 20:45:23 +0000103 std::scoped_lock lock(mMutex);
104
ramindani7ce70fe2022-02-10 18:08:09 +0000105 const auto it = std::find(mDisplays.begin(), mDisplays.end(), in_display);
106 if (it == mDisplays.end()) {
ramindani1cb794e2021-10-13 20:45:23 +0000107 mInvalidRefreshCount++;
108 }
109
110 return ::ndk::ScopedAStatus::ok();
111}
112
113::ndk::ScopedAStatus GraphicsComposerCallback::onVsync(int64_t in_display, int64_t in_timestamp,
114 int32_t in_vsyncPeriodNanos) {
115 std::scoped_lock lock(mMutex);
ramindani7ce70fe2022-02-10 18:08:09 +0000116
117 const auto it = std::find(mDisplays.begin(), mDisplays.end(), in_display);
118 if (!mVsyncAllowed || it == mDisplays.end()) {
ramindani1cb794e2021-10-13 20:45:23 +0000119 mInvalidVsyncCount++;
120 }
121
122 ALOGV("%ld, %d", static_cast<long>(in_timestamp), in_vsyncPeriodNanos);
123
124 return ::ndk::ScopedAStatus::ok();
125}
126
127::ndk::ScopedAStatus GraphicsComposerCallback::onVsyncPeriodTimingChanged(
128 int64_t in_display,
129 const ::aidl::android::hardware::graphics::composer3::VsyncPeriodChangeTimeline&
130 in_updatedTimeline) {
131 std::scoped_lock lock(mMutex);
ramindani7ce70fe2022-02-10 18:08:09 +0000132
133 const auto it = std::find(mDisplays.begin(), mDisplays.end(), in_display);
134 if (it == mDisplays.end()) {
ramindani1cb794e2021-10-13 20:45:23 +0000135 mInvalidVsyncPeriodChangeCount++;
136 }
137 mTimeline = in_updatedTimeline;
138
139 return ::ndk::ScopedAStatus::ok();
140}
141
142::ndk::ScopedAStatus GraphicsComposerCallback::onSeamlessPossible(int64_t in_display) {
143 std::scoped_lock lock(mMutex);
ramindani7ce70fe2022-02-10 18:08:09 +0000144
145 const auto it = std::find(mDisplays.begin(), mDisplays.end(), in_display);
146 if (it != mDisplays.end()) {
ramindani1cb794e2021-10-13 20:45:23 +0000147 mInvalidSeamlessPossibleCount++;
148 }
149 return ::ndk::ScopedAStatus::ok();
150}
151
Midas Chiena0b56bd2022-01-13 23:27:33 +0800152::ndk::ScopedAStatus GraphicsComposerCallback::onVsyncIdle(int64_t in_display) {
153 std::scoped_lock lock(mMutex);
ramindani7ce70fe2022-02-10 18:08:09 +0000154
155 const auto it = std::find(mDisplays.begin(), mDisplays.end(), in_display);
156 if (it != mDisplays.end()) {
Midas Chiena0b56bd2022-01-13 23:27:33 +0800157 mVsyncIdleCount++;
158 mVsyncIdleTime = systemTime();
159 }
160 return ::ndk::ScopedAStatus::ok();
161}
162
ramindani1cb794e2021-10-13 20:45:23 +0000163} // namespace aidl::android::hardware::graphics::composer3::vts