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 #define ERROR_HAS_CHANGES 5
24 
25 namespace android {
26 namespace hardware::graphics::composer::hal {
27 
28 namespace types = android::hardware::graphics::common;
29 namespace V2_1 = android::hardware::graphics::composer::V2_1;
30 namespace V2_2 = android::hardware::graphics::composer::V2_2;
31 namespace V2_3 = android::hardware::graphics::composer::V2_3;
32 namespace V2_4 = android::hardware::graphics::composer::V2_4;
33 
34 using types::V1_0::ColorTransform;
35 using types::V1_0::Transform;
36 using types::V1_1::RenderIntent;
37 using types::V1_2::ColorMode;
38 using types::V1_2::Dataspace;
39 using types::V1_2::Hdr;
40 using types::V1_2::PixelFormat;
41 
42 using V2_1::Error;
43 using V2_4::IComposer;
44 using V2_4::IComposerCallback;
45 using V2_4::IComposerClient;
46 using V2_4::VsyncPeriodChangeTimeline;
47 using V2_4::VsyncPeriodNanos;
48 
49 using Attribute = IComposerClient::Attribute;
50 using BlendMode = IComposerClient::BlendMode;
51 using Color = IComposerClient::Color;
52 using Composition = IComposerClient::Composition;
53 using Connection = IComposerCallback::Connection;
54 using ContentType = IComposerClient::ContentType;
55 using Capability = IComposer::Capability;
56 using ClientTargetProperty = IComposerClient::ClientTargetProperty;
57 using DisplayCapability = IComposerClient::DisplayCapability;
58 using DisplayRequest = IComposerClient::DisplayRequest;
59 using DisplayType = IComposerClient::DisplayType;
60 using HWConfigId = V2_1::Config;
61 using HWDisplayId = V2_1::Display;
62 using HWError = V2_1::Error;
63 using HWLayerId = V2_1::Layer;
64 using LayerGenericMetadataKey = IComposerClient::LayerGenericMetadataKey;
65 using LayerRequest = IComposerClient::LayerRequest;
66 using PerFrameMetadata = IComposerClient::PerFrameMetadata;
67 using PerFrameMetadataKey = IComposerClient::PerFrameMetadataKey;
68 using PerFrameMetadataBlob = IComposerClient::PerFrameMetadataBlob;
69 using PowerMode = IComposerClient::PowerMode;
70 using Vsync = IComposerClient::Vsync;
71 using VsyncPeriodChangeConstraints = IComposerClient::VsyncPeriodChangeConstraints;
72 
73 } // namespace hardware::graphics::composer::hal
74 
hasChangesError(hardware::graphics::composer::hal::Error error)75 inline bool hasChangesError(hardware::graphics::composer::hal::Error error) {
76     return ERROR_HAS_CHANGES == static_cast<int32_t>(error);
77 }
78 
to_string(hardware::graphics::composer::hal::Attribute attribute)79 inline std::string to_string(hardware::graphics::composer::hal::Attribute attribute) {
80     switch (attribute) {
81         case hardware::graphics::composer::hal::Attribute::INVALID:
82             return "Invalid";
83         case hardware::graphics::composer::hal::Attribute::WIDTH:
84             return "Width";
85         case hardware::graphics::composer::hal::Attribute::HEIGHT:
86             return "Height";
87         case hardware::graphics::composer::hal::Attribute::VSYNC_PERIOD:
88             return "VsyncPeriod";
89         case hardware::graphics::composer::hal::Attribute::DPI_X:
90             return "DpiX";
91         case hardware::graphics::composer::hal::Attribute::DPI_Y:
92             return "DpiY";
93         default:
94             return "Unknown";
95     }
96 }
97 
to_string(hardware::graphics::composer::hal::Composition composition)98 inline std::string to_string(hardware::graphics::composer::hal::Composition composition) {
99     switch (composition) {
100         case hardware::graphics::composer::hal::Composition::INVALID:
101             return "Invalid";
102         case hardware::graphics::composer::hal::Composition::CLIENT:
103             return "Client";
104         case hardware::graphics::composer::hal::Composition::DEVICE:
105             return "Device";
106         case hardware::graphics::composer::hal::Composition::SOLID_COLOR:
107             return "SolidColor";
108         case hardware::graphics::composer::hal::Composition::CURSOR:
109             return "Cursor";
110         case hardware::graphics::composer::hal::Composition::SIDEBAND:
111             return "Sideband";
112         default:
113             return "Unknown";
114     }
115 }
116 
to_string(hardware::graphics::composer::hal::V2_4::Error error)117 inline std::string to_string(hardware::graphics::composer::hal::V2_4::Error error) {
118     // 5 is reserved for historical reason, during validation 5 means has changes.
119     if (ERROR_HAS_CHANGES == static_cast<int32_t>(error)) {
120         return "HasChanges";
121     }
122     switch (error) {
123         case hardware::graphics::composer::hal::V2_4::Error::NONE:
124             return "None";
125         case hardware::graphics::composer::hal::V2_4::Error::BAD_CONFIG:
126             return "BadConfig";
127         case hardware::graphics::composer::hal::V2_4::Error::BAD_DISPLAY:
128             return "BadDisplay";
129         case hardware::graphics::composer::hal::V2_4::Error::BAD_LAYER:
130             return "BadLayer";
131         case hardware::graphics::composer::hal::V2_4::Error::BAD_PARAMETER:
132             return "BadParameter";
133         case hardware::graphics::composer::hal::V2_4::Error::NO_RESOURCES:
134             return "NoResources";
135         case hardware::graphics::composer::hal::V2_4::Error::NOT_VALIDATED:
136             return "NotValidated";
137         case hardware::graphics::composer::hal::V2_4::Error::UNSUPPORTED:
138             return "Unsupported";
139         case hardware::graphics::composer::hal::V2_4::Error::SEAMLESS_NOT_ALLOWED:
140             return "SeamlessNotAllowed";
141         case hardware::graphics::composer::hal::V2_4::Error::SEAMLESS_NOT_POSSIBLE:
142             return "SeamlessNotPossible";
143         default:
144             return "Unknown";
145     }
146 }
147 
to_string(hardware::graphics::composer::hal::Error error)148 inline std::string to_string(hardware::graphics::composer::hal::Error error) {
149     return to_string(static_cast<hardware::graphics::composer::hal::V2_4::Error>(error));
150 }
151 
to_string(hardware::graphics::composer::hal::PowerMode mode)152 inline std::string to_string(hardware::graphics::composer::hal::PowerMode mode) {
153     switch (mode) {
154         case hardware::graphics::composer::hal::PowerMode::OFF:
155             return "Off";
156         case hardware::graphics::composer::hal::PowerMode::DOZE:
157             return "Doze";
158         case hardware::graphics::composer::hal::PowerMode::ON:
159             return "On";
160         case hardware::graphics::composer::hal::PowerMode::DOZE_SUSPEND:
161             return "DozeSuspend";
162         case hardware::graphics::composer::hal::PowerMode::ON_SUSPEND:
163             return "OnSuspend";
164         default:
165             return "Unknown";
166     }
167 }
168 
169 } // namespace android
170