1 /*
2 * Copyright 2020 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 #pragma once
18
19 #include <android/hardware/graphics/common/1.1/types.h>
20 #include <android/hardware/graphics/composer/2.4/IComposer.h>
21 #include <android/hardware/graphics/composer/2.4/IComposerClient.h>
22
23 #include <aidl/android/hardware/graphics/common/DisplayHotplugEvent.h>
24 #include <aidl/android/hardware/graphics/common/Hdr.h>
25 #include <aidl/android/hardware/graphics/composer3/Composition.h>
26 #include <aidl/android/hardware/graphics/composer3/DisplayCapability.h>
27 #include <aidl/android/hardware/graphics/composer3/DisplayConfiguration.h>
28 #include <aidl/android/hardware/graphics/composer3/VrrConfig.h>
29
30 #define ERROR_HAS_CHANGES 5
31
32 namespace android {
33 namespace hardware::graphics::composer::hal {
34
35 namespace types = android::hardware::graphics::common;
36 namespace V2_1 = android::hardware::graphics::composer::V2_1;
37 namespace V2_2 = android::hardware::graphics::composer::V2_2;
38 namespace V2_3 = android::hardware::graphics::composer::V2_3;
39 namespace V2_4 = android::hardware::graphics::composer::V2_4;
40 namespace V3_0 = ::aidl::android::hardware::graphics::composer3;
41
42 using types::V1_0::ColorTransform;
43 using types::V1_0::Transform;
44 using types::V1_1::RenderIntent;
45 using types::V1_2::ColorMode;
46 using types::V1_2::Dataspace;
47 using types::V1_2::PixelFormat;
48
49 using V2_1::Error;
50 using V2_4::IComposer;
51 using V2_4::IComposerCallback;
52 using V2_4::IComposerClient;
53 using V2_4::VsyncPeriodChangeTimeline;
54 using V2_4::VsyncPeriodNanos;
55
56 using Attribute = IComposerClient::Attribute;
57 using BlendMode = IComposerClient::BlendMode;
58 using Connection = IComposerCallback::Connection;
59 using ContentType = IComposerClient::ContentType;
60 using Capability = IComposer::Capability;
61 using ClientTargetProperty = IComposerClient::ClientTargetProperty;
62 using DisplayHotplugEvent = aidl::android::hardware::graphics::common::DisplayHotplugEvent;
63 using DisplayRequest = IComposerClient::DisplayRequest;
64 using DisplayType = IComposerClient::DisplayType;
65 using HWConfigId = V2_1::Config;
66 using HWDisplayId = V2_1::Display;
67 using HWError = V2_1::Error;
68 using HWLayerId = V2_1::Layer;
69 using LayerGenericMetadataKey = IComposerClient::LayerGenericMetadataKey;
70 using LayerRequest = IComposerClient::LayerRequest;
71 using PerFrameMetadata = IComposerClient::PerFrameMetadata;
72 using PerFrameMetadataKey = IComposerClient::PerFrameMetadataKey;
73 using PerFrameMetadataBlob = IComposerClient::PerFrameMetadataBlob;
74 using PowerMode = IComposerClient::PowerMode;
75 using Vsync = IComposerClient::Vsync;
76 using VsyncPeriodChangeConstraints = IComposerClient::VsyncPeriodChangeConstraints;
77 using Hdr = aidl::android::hardware::graphics::common::Hdr;
78 using DisplayConfiguration = V3_0::DisplayConfiguration;
79 using VrrConfig = V3_0::VrrConfig;
80
81 } // namespace hardware::graphics::composer::hal
82
hasChangesError(hardware::graphics::composer::hal::Error error)83 inline bool hasChangesError(hardware::graphics::composer::hal::Error error) {
84 return ERROR_HAS_CHANGES == static_cast<int32_t>(error);
85 }
86
to_string(hardware::graphics::composer::hal::Attribute attribute)87 inline std::string to_string(hardware::graphics::composer::hal::Attribute attribute) {
88 switch (attribute) {
89 case hardware::graphics::composer::hal::Attribute::INVALID:
90 return "Invalid";
91 case hardware::graphics::composer::hal::Attribute::WIDTH:
92 return "Width";
93 case hardware::graphics::composer::hal::Attribute::HEIGHT:
94 return "Height";
95 case hardware::graphics::composer::hal::Attribute::VSYNC_PERIOD:
96 return "VsyncPeriod";
97 case hardware::graphics::composer::hal::Attribute::DPI_X:
98 return "DpiX";
99 case hardware::graphics::composer::hal::Attribute::DPI_Y:
100 return "DpiY";
101 default:
102 return "Unknown";
103 }
104 }
105
to_string(aidl::android::hardware::graphics::composer3::Composition composition)106 inline std::string to_string(
107 aidl::android::hardware::graphics::composer3::Composition composition) {
108 switch (composition) {
109 case aidl::android::hardware::graphics::composer3::Composition::INVALID:
110 return "Invalid";
111 case aidl::android::hardware::graphics::composer3::Composition::CLIENT:
112 return "Client";
113 case aidl::android::hardware::graphics::composer3::Composition::DEVICE:
114 return "Device";
115 case aidl::android::hardware::graphics::composer3::Composition::SOLID_COLOR:
116 return "SolidColor";
117 case aidl::android::hardware::graphics::composer3::Composition::CURSOR:
118 return "Cursor";
119 case aidl::android::hardware::graphics::composer3::Composition::SIDEBAND:
120 return "Sideband";
121 case aidl::android::hardware::graphics::composer3::Composition::DISPLAY_DECORATION:
122 return "DisplayDecoration";
123 case aidl::android::hardware::graphics::composer3::Composition::REFRESH_RATE_INDICATOR:
124 return "RefreshRateIndicator";
125 default:
126 return "Unknown";
127 }
128 }
129
to_string(aidl::android::hardware::graphics::composer3::DisplayCapability displayCapability)130 inline std::string to_string(
131 aidl::android::hardware::graphics::composer3::DisplayCapability displayCapability) {
132 switch (displayCapability) {
133 case aidl::android::hardware::graphics::composer3::DisplayCapability::INVALID:
134 return "Invalid";
135 case aidl::android::hardware::graphics::composer3::DisplayCapability::
136 SKIP_CLIENT_COLOR_TRANSFORM:
137 return "SkipColorTransform";
138 case aidl::android::hardware::graphics::composer3::DisplayCapability::DOZE:
139 return "Doze";
140 case aidl::android::hardware::graphics::composer3::DisplayCapability::BRIGHTNESS:
141 return "Brightness";
142 case aidl::android::hardware::graphics::composer3::DisplayCapability::PROTECTED_CONTENTS:
143 return "ProtectedContents";
144 case aidl::android::hardware::graphics::composer3::DisplayCapability::AUTO_LOW_LATENCY_MODE:
145 return "AutoLowLatencyMode";
146 case aidl::android::hardware::graphics::composer3::DisplayCapability::SUSPEND:
147 return "Suspend";
148 case aidl::android::hardware::graphics::composer3::DisplayCapability::DISPLAY_IDLE_TIMER:
149 return "DisplayIdleTimer";
150 default:
151 return "Unknown";
152 }
153 }
154
to_string(const std::optional<aidl::android::hardware::graphics::composer3::VrrConfig> & vrrConfig)155 inline std::string to_string(
156 const std::optional<aidl::android::hardware::graphics::composer3::VrrConfig>& vrrConfig) {
157 if (vrrConfig) {
158 std::ostringstream out;
159 out << "{minFrameIntervalNs=" << vrrConfig->minFrameIntervalNs << ", ";
160 out << "frameIntervalPowerHints={";
161 if (vrrConfig->frameIntervalPowerHints) {
162 const auto& powerHint = *vrrConfig->frameIntervalPowerHints;
163 for (size_t i = 0; i < powerHint.size(); i++) {
164 if (i > 0) out << ", ";
165 out << "[frameIntervalNs=" << powerHint[i]->frameIntervalNs
166 << ", averageRefreshPeriodNs=" << powerHint[i]->averageRefreshPeriodNs << "]";
167 }
168 }
169 out << "}, ";
170 out << "notifyExpectedPresentConfig={";
171 if (vrrConfig->notifyExpectedPresentConfig) {
172 out << "headsUpNs=" << vrrConfig->notifyExpectedPresentConfig->headsUpNs
173 << ", timeoutNs=" << vrrConfig->notifyExpectedPresentConfig->timeoutNs;
174 }
175 out << "}}";
176 return out.str();
177 }
178 return "N/A";
179 }
180
to_string(hardware::graphics::composer::hal::V2_4::Error error)181 inline std::string to_string(hardware::graphics::composer::hal::V2_4::Error error) {
182 // 5 is reserved for historical reason, during validation 5 means has changes.
183 if (ERROR_HAS_CHANGES == static_cast<int32_t>(error)) {
184 return "HasChanges";
185 }
186 switch (error) {
187 case hardware::graphics::composer::hal::V2_4::Error::NONE:
188 return "None";
189 case hardware::graphics::composer::hal::V2_4::Error::BAD_CONFIG:
190 return "BadConfig";
191 case hardware::graphics::composer::hal::V2_4::Error::BAD_DISPLAY:
192 return "BadDisplay";
193 case hardware::graphics::composer::hal::V2_4::Error::BAD_LAYER:
194 return "BadLayer";
195 case hardware::graphics::composer::hal::V2_4::Error::BAD_PARAMETER:
196 return "BadParameter";
197 case hardware::graphics::composer::hal::V2_4::Error::NO_RESOURCES:
198 return "NoResources";
199 case hardware::graphics::composer::hal::V2_4::Error::NOT_VALIDATED:
200 return "NotValidated";
201 case hardware::graphics::composer::hal::V2_4::Error::UNSUPPORTED:
202 return "Unsupported";
203 case hardware::graphics::composer::hal::V2_4::Error::SEAMLESS_NOT_ALLOWED:
204 return "SeamlessNotAllowed";
205 case hardware::graphics::composer::hal::V2_4::Error::SEAMLESS_NOT_POSSIBLE:
206 return "SeamlessNotPossible";
207 default:
208 return "Unknown";
209 }
210 }
211
to_string(hardware::graphics::composer::hal::Error error)212 inline std::string to_string(hardware::graphics::composer::hal::Error error) {
213 return to_string(static_cast<hardware::graphics::composer::hal::V2_4::Error>(error));
214 }
215
216 // For utils::Dumper ADL.
217 namespace hardware::graphics::composer {
218 namespace V2_2 {
219
to_string(hardware::graphics::composer::hal::PowerMode mode)220 inline std::string to_string(hardware::graphics::composer::hal::PowerMode mode) {
221 switch (mode) {
222 case hardware::graphics::composer::hal::PowerMode::OFF:
223 return "Off";
224 case hardware::graphics::composer::hal::PowerMode::DOZE:
225 return "Doze";
226 case hardware::graphics::composer::hal::PowerMode::ON:
227 return "On";
228 case hardware::graphics::composer::hal::PowerMode::DOZE_SUSPEND:
229 return "DozeSuspend";
230 case hardware::graphics::composer::hal::PowerMode::ON_SUSPEND:
231 return "OnSuspend";
232 default:
233 return "Unknown";
234 }
235 }
236
237 } // namespace V2_2
238
239 namespace V2_1 {
240
to_string(hardware::graphics::composer::hal::Vsync vsync)241 inline std::string to_string(hardware::graphics::composer::hal::Vsync vsync) {
242 switch (vsync) {
243 case hardware::graphics::composer::hal::Vsync::ENABLE:
244 return "Enable";
245 case hardware::graphics::composer::hal::Vsync::DISABLE:
246 return "Disable";
247 default:
248 return "Unknown";
249 }
250 }
251
252 } // namespace V2_1
253 } // namespace hardware::graphics::composer
254 } // namespace android
255