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