blob: 20f7548beafca43bbe64d3f95d8503e418c94971 [file] [log] [blame]
Peiyong Line9d809e2020-04-14 13:10:48 -07001/*
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
Marc Kassisbdf7e4b2022-11-04 17:26:48 +010023#include <aidl/android/hardware/graphics/common/Hdr.h>
Leon Scroggins III2e1aa182021-12-01 17:33:12 -050024#include <aidl/android/hardware/graphics/composer3/Composition.h>
Leon Scroggins III5967aec2021-12-29 11:14:22 -050025#include <aidl/android/hardware/graphics/composer3/DisplayCapability.h>
ramindani0cd1d8d2023-06-13 13:43:23 -070026#include <aidl/android/hardware/graphics/composer3/DisplayConfiguration.h>
ramindania04b8a52023-08-07 18:49:47 -070027#include <aidl/android/hardware/graphics/composer3/VrrConfig.h>
Leon Scroggins III2e1aa182021-12-01 17:33:12 -050028
Peiyong Line9d809e2020-04-14 13:10:48 -070029#define ERROR_HAS_CHANGES 5
30
31namespace android {
32namespace hardware::graphics::composer::hal {
33
34namespace types = android::hardware::graphics::common;
35namespace V2_1 = android::hardware::graphics::composer::V2_1;
36namespace V2_2 = android::hardware::graphics::composer::V2_2;
37namespace V2_3 = android::hardware::graphics::composer::V2_3;
38namespace V2_4 = android::hardware::graphics::composer::V2_4;
ramindani0cd1d8d2023-06-13 13:43:23 -070039namespace V3_0 = ::aidl::android::hardware::graphics::composer3;
Peiyong Line9d809e2020-04-14 13:10:48 -070040
41using types::V1_0::ColorTransform;
42using types::V1_0::Transform;
43using types::V1_1::RenderIntent;
44using types::V1_2::ColorMode;
45using types::V1_2::Dataspace;
Peiyong Line9d809e2020-04-14 13:10:48 -070046using types::V1_2::PixelFormat;
47
48using V2_1::Error;
49using V2_4::IComposer;
50using V2_4::IComposerCallback;
51using V2_4::IComposerClient;
52using V2_4::VsyncPeriodChangeTimeline;
53using V2_4::VsyncPeriodNanos;
54
55using Attribute = IComposerClient::Attribute;
56using BlendMode = IComposerClient::BlendMode;
Peiyong Line9d809e2020-04-14 13:10:48 -070057using Connection = IComposerCallback::Connection;
58using ContentType = IComposerClient::ContentType;
59using Capability = IComposer::Capability;
Peiyong Lindfc3f7c2020-05-07 20:15:50 -070060using ClientTargetProperty = IComposerClient::ClientTargetProperty;
Peiyong Line9d809e2020-04-14 13:10:48 -070061using DisplayRequest = IComposerClient::DisplayRequest;
62using DisplayType = IComposerClient::DisplayType;
63using HWConfigId = V2_1::Config;
64using HWDisplayId = V2_1::Display;
65using HWError = V2_1::Error;
66using HWLayerId = V2_1::Layer;
67using LayerGenericMetadataKey = IComposerClient::LayerGenericMetadataKey;
68using LayerRequest = IComposerClient::LayerRequest;
69using PerFrameMetadata = IComposerClient::PerFrameMetadata;
70using PerFrameMetadataKey = IComposerClient::PerFrameMetadataKey;
71using PerFrameMetadataBlob = IComposerClient::PerFrameMetadataBlob;
72using PowerMode = IComposerClient::PowerMode;
73using Vsync = IComposerClient::Vsync;
74using VsyncPeriodChangeConstraints = IComposerClient::VsyncPeriodChangeConstraints;
Marc Kassisbdf7e4b2022-11-04 17:26:48 +010075using Hdr = aidl::android::hardware::graphics::common::Hdr;
ramindani0cd1d8d2023-06-13 13:43:23 -070076using DisplayConfiguration = V3_0::DisplayConfiguration;
ramindania04b8a52023-08-07 18:49:47 -070077using VrrConfig = V3_0::VrrConfig;
Peiyong Line9d809e2020-04-14 13:10:48 -070078
79} // namespace hardware::graphics::composer::hal
80
81inline bool hasChangesError(hardware::graphics::composer::hal::Error error) {
82 return ERROR_HAS_CHANGES == static_cast<int32_t>(error);
83}
84
85inline std::string to_string(hardware::graphics::composer::hal::Attribute attribute) {
86 switch (attribute) {
87 case hardware::graphics::composer::hal::Attribute::INVALID:
88 return "Invalid";
89 case hardware::graphics::composer::hal::Attribute::WIDTH:
90 return "Width";
91 case hardware::graphics::composer::hal::Attribute::HEIGHT:
92 return "Height";
93 case hardware::graphics::composer::hal::Attribute::VSYNC_PERIOD:
94 return "VsyncPeriod";
95 case hardware::graphics::composer::hal::Attribute::DPI_X:
96 return "DpiX";
97 case hardware::graphics::composer::hal::Attribute::DPI_Y:
98 return "DpiY";
99 default:
100 return "Unknown";
101 }
102}
103
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500104inline std::string to_string(
105 aidl::android::hardware::graphics::composer3::Composition composition) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700106 switch (composition) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500107 case aidl::android::hardware::graphics::composer3::Composition::INVALID:
Peiyong Line9d809e2020-04-14 13:10:48 -0700108 return "Invalid";
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500109 case aidl::android::hardware::graphics::composer3::Composition::CLIENT:
Peiyong Line9d809e2020-04-14 13:10:48 -0700110 return "Client";
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500111 case aidl::android::hardware::graphics::composer3::Composition::DEVICE:
Peiyong Line9d809e2020-04-14 13:10:48 -0700112 return "Device";
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500113 case aidl::android::hardware::graphics::composer3::Composition::SOLID_COLOR:
Peiyong Line9d809e2020-04-14 13:10:48 -0700114 return "SolidColor";
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500115 case aidl::android::hardware::graphics::composer3::Composition::CURSOR:
Peiyong Line9d809e2020-04-14 13:10:48 -0700116 return "Cursor";
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500117 case aidl::android::hardware::graphics::composer3::Composition::SIDEBAND:
Peiyong Line9d809e2020-04-14 13:10:48 -0700118 return "Sideband";
Leon Scroggins III09c25412021-12-02 14:49:56 -0500119 case aidl::android::hardware::graphics::composer3::Composition::DISPLAY_DECORATION:
120 return "DisplayDecoration";
ramindanic1945cb2023-02-03 13:28:15 -0800121 case aidl::android::hardware::graphics::composer3::Composition::REFRESH_RATE_INDICATOR:
122 return "RefreshRateIndicator";
Peiyong Line9d809e2020-04-14 13:10:48 -0700123 default:
124 return "Unknown";
125 }
126}
127
Leon Scroggins III515f0382021-12-29 11:17:04 -0500128inline std::string to_string(
129 aidl::android::hardware::graphics::composer3::DisplayCapability displayCapability) {
130 switch (displayCapability) {
131 case aidl::android::hardware::graphics::composer3::DisplayCapability::INVALID:
132 return "Invalid";
133 case aidl::android::hardware::graphics::composer3::DisplayCapability::
134 SKIP_CLIENT_COLOR_TRANSFORM:
135 return "SkipColorTransform";
136 case aidl::android::hardware::graphics::composer3::DisplayCapability::DOZE:
137 return "Doze";
138 case aidl::android::hardware::graphics::composer3::DisplayCapability::BRIGHTNESS:
139 return "Brightness";
140 case aidl::android::hardware::graphics::composer3::DisplayCapability::PROTECTED_CONTENTS:
141 return "ProtectedContents";
142 case aidl::android::hardware::graphics::composer3::DisplayCapability::AUTO_LOW_LATENCY_MODE:
143 return "AutoLowLatencyMode";
144 case aidl::android::hardware::graphics::composer3::DisplayCapability::SUSPEND:
145 return "Suspend";
Leon Scroggins IIIe7c51c62022-02-01 15:53:54 -0500146 case aidl::android::hardware::graphics::composer3::DisplayCapability::DISPLAY_IDLE_TIMER:
147 return "DisplayIdleTimer";
Leon Scroggins III515f0382021-12-29 11:17:04 -0500148 default:
149 return "Unknown";
150 }
151}
152
ramindania04b8a52023-08-07 18:49:47 -0700153inline std::string to_string(
154 const std::optional<aidl::android::hardware::graphics::composer3::VrrConfig>& vrrConfig) {
155 if (vrrConfig) {
156 std::ostringstream out;
157 out << "{minFrameIntervalNs=" << vrrConfig->minFrameIntervalNs << ", ";
158 out << "frameIntervalPowerHints={";
159 if (vrrConfig->frameIntervalPowerHints) {
160 const auto& powerHint = *vrrConfig->frameIntervalPowerHints;
161 for (size_t i = 0; i < powerHint.size(); i++) {
162 if (i > 0) out << ", ";
163 out << "[frameIntervalNs=" << powerHint[i]->frameIntervalNs
164 << ", averageRefreshPeriodNs=" << powerHint[i]->averageRefreshPeriodNs << "]";
165 }
166 }
167 out << "}, ";
168 out << "notifyExpectedPresentConfig={";
169 if (vrrConfig->notifyExpectedPresentConfig) {
170 out << "notifyExpectedPresentHeadsUpNs="
171 << vrrConfig->notifyExpectedPresentConfig->notifyExpectedPresentHeadsUpNs
172 << ", notifyExpectedPresentTimeoutNs="
173 << vrrConfig->notifyExpectedPresentConfig->notifyExpectedPresentTimeoutNs;
174 }
175 out << "}}";
176 return out.str();
177 }
178 return "N/A";
179}
180
Peiyong Line9d809e2020-04-14 13:10:48 -0700181inline 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
212inline 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
Dominik Laskowskie70461a2022-08-30 14:42:01 -0700216// For utils::Dumper ADL.
Dominik Laskowski03cfce82022-11-02 12:13:29 -0400217namespace hardware::graphics::composer {
218namespace V2_2 {
Dominik Laskowskie70461a2022-08-30 14:42:01 -0700219
Peiyong Line9d809e2020-04-14 13:10:48 -0700220inline std::string to_string(hardware::graphics::composer::hal::PowerMode mode) {
221 switch (mode) {
222 case hardware::graphics::composer::hal::PowerMode::OFF:
223 return "Off";
Peiyong Line9d809e2020-04-14 13:10:48 -0700224 case hardware::graphics::composer::hal::PowerMode::DOZE:
225 return "Doze";
226 case hardware::graphics::composer::hal::PowerMode::ON:
227 return "On";
Peiyong Lin65248e02020-04-18 21:15:07 -0700228 case hardware::graphics::composer::hal::PowerMode::DOZE_SUSPEND:
229 return "DozeSuspend";
230 case hardware::graphics::composer::hal::PowerMode::ON_SUSPEND:
231 return "OnSuspend";
Peiyong Line9d809e2020-04-14 13:10:48 -0700232 default:
233 return "Unknown";
234 }
235}
236
Dominik Laskowski03cfce82022-11-02 12:13:29 -0400237} // namespace V2_2
238
239namespace V2_1 {
Dominik Laskowskie70461a2022-08-30 14:42:01 -0700240
Ady Abraham4f960d12021-10-13 16:59:49 -0700241inline 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
Dominik Laskowski03cfce82022-11-02 12:13:29 -0400252} // namespace V2_1
253} // namespace hardware::graphics::composer
Peiyong Line9d809e2020-04-14 13:10:48 -0700254} // namespace android