1 /*
2 * Copyright (C) 2018 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 #include <composer-vts/2.3/ComposerVts.h>
18
19 #include <VtsHalHidlTargetTestBase.h>
20
21 namespace android {
22 namespace hardware {
23 namespace graphics {
24 namespace composer {
25 namespace V2_3 {
26 namespace vts {
27
28 using V2_1::Error;
29
Composer()30 Composer::Composer() : Composer(::testing::VtsHalHidlTargetTestBase::getService<IComposer>()) {}
31
Composer(const std::string & name)32 Composer::Composer(const std::string& name)
33 : Composer(::testing::VtsHalHidlTargetTestBase::getService<IComposer>(name)) {}
34
Composer(const sp<IComposer> & composer)35 Composer::Composer(const sp<IComposer>& composer)
36 : V2_2::vts::Composer(composer), mComposer(composer) {}
37
createClient()38 std::unique_ptr<ComposerClient> Composer::createClient() {
39 std::unique_ptr<ComposerClient> client;
40 mComposer->createClient_2_3([&client](const auto& tmpError, const auto& tmpClient) {
41 ASSERT_EQ(Error::NONE, tmpError) << "failed to create client";
42 client = std::make_unique<ComposerClient>(tmpClient);
43 });
44
45 return client;
46 }
47
getRaw() const48 sp<IComposerClient> ComposerClient::getRaw() const {
49 return mClient;
50 }
51
getDisplayIdentificationData(Display display,uint8_t * outPort,std::vector<uint8_t> * outData)52 bool ComposerClient::getDisplayIdentificationData(Display display, uint8_t* outPort,
53 std::vector<uint8_t>* outData) {
54 bool supported = true;
55 mClient->getDisplayIdentificationData(
56 display, [&](const auto& tmpError, const auto& tmpPort, const auto& tmpData) {
57 if (tmpError == Error::UNSUPPORTED) {
58 supported = false;
59 return;
60 }
61 ASSERT_EQ(Error::NONE, tmpError) << "failed to get display identification data";
62
63 *outPort = tmpPort;
64 *outData = tmpData;
65 ASSERT_FALSE(outData->empty()) << "data is empty";
66 });
67
68 return supported;
69 }
70
getColorModes_2_3(Display display)71 std::vector<ColorMode> ComposerClient::getColorModes_2_3(Display display) {
72 std::vector<ColorMode> modes;
73 mClient->getColorModes_2_3(display, [&](const auto& tmpError, const auto& tmpModes) {
74 ASSERT_EQ(Error::NONE, tmpError) << "failed to get color modes";
75 modes = tmpModes;
76 });
77 return modes;
78 }
79
setColorMode_2_3(Display display,ColorMode mode,RenderIntent intent)80 void ComposerClient::setColorMode_2_3(Display display, ColorMode mode, RenderIntent intent) {
81 Error error = mClient->setColorMode_2_3(display, mode, intent);
82 ASSERT_TRUE(error == Error::NONE || error == Error::UNSUPPORTED) << "failed to set color mode";
83 }
84
getRenderIntents_2_3(Display display,ColorMode mode)85 std::vector<RenderIntent> ComposerClient::getRenderIntents_2_3(Display display, ColorMode mode) {
86 std::vector<RenderIntent> intents;
87 mClient->getRenderIntents_2_3(display, mode, [&](const auto& tmpError, const auto& tmpIntents) {
88 ASSERT_EQ(Error::NONE, tmpError) << "failed to get render intents";
89 intents = tmpIntents;
90 });
91 return intents;
92 }
93
getReadbackBufferAttributes_2_3(Display display,PixelFormat * outPixelFormat,Dataspace * outDataspace)94 void ComposerClient::getReadbackBufferAttributes_2_3(Display display, PixelFormat* outPixelFormat,
95 Dataspace* outDataspace) {
96 mClient->getReadbackBufferAttributes_2_3(
97 display,
98 [&](const auto& tmpError, const auto& tmpOutPixelFormat, const auto& tmpOutDataspace) {
99 ASSERT_EQ(Error::NONE, tmpError) << "failed to get readback buffer attributes";
100 *outPixelFormat = tmpOutPixelFormat;
101 *outDataspace = tmpOutDataspace;
102 });
103 }
104
getClientTargetSupport_2_3(Display display,uint32_t width,uint32_t height,PixelFormat format,Dataspace dataspace)105 bool ComposerClient::getClientTargetSupport_2_3(Display display, uint32_t width, uint32_t height,
106 PixelFormat format, Dataspace dataspace) {
107 Error error = mClient->getClientTargetSupport_2_3(display, width, height, format, dataspace);
108 return error == Error::NONE;
109 }
110
getPerFrameMetadataKeys_2_3(Display display)111 std::vector<IComposerClient::PerFrameMetadataKey> ComposerClient::getPerFrameMetadataKeys_2_3(
112 Display display) {
113 std::vector<IComposerClient::PerFrameMetadataKey> keys;
114 mClient->getPerFrameMetadataKeys_2_3(display, [&](const auto& tmpError, const auto& tmpKeys) {
115 ASSERT_EQ(Error::NONE, tmpError) << "failed to get perFrameMetadataKeys";
116 keys = tmpKeys;
117 });
118 return keys;
119 }
120
getHdrCapabilities_2_3(Display display,float * outMaxLuminance,float * outMaxAverageLuminance,float * outMinLuminance)121 std::vector<Hdr> ComposerClient::getHdrCapabilities_2_3(Display display, float* outMaxLuminance,
122 float* outMaxAverageLuminance,
123 float* outMinLuminance) {
124 std::vector<Hdr> types;
125 mClient->getHdrCapabilities_2_3(
126 display, [&](const auto& tmpError, const auto& tmpTypes, const auto& tmpMaxLuminance,
127 const auto& tmpMaxAverageLuminance, const auto& tmpMinLuminance) {
128 ASSERT_EQ(Error::NONE, tmpError) << "failed to get HDR capabilities";
129 types = tmpTypes;
130 *outMaxLuminance = tmpMaxLuminance;
131 *outMaxAverageLuminance = tmpMaxAverageLuminance;
132 *outMinLuminance = tmpMinLuminance;
133 });
134
135 return types;
136 }
137
getDisplayedContentSamplingAttributes(uint64_t display,PixelFormat & format,Dataspace & dataspace,hidl_bitfield<IComposerClient::FormatColorComponent> & componentMask)138 Error ComposerClient::getDisplayedContentSamplingAttributes(
139 uint64_t display, PixelFormat& format, Dataspace& dataspace,
140 hidl_bitfield<IComposerClient::FormatColorComponent>& componentMask) {
141 auto error = Error::BAD_PARAMETER;
142 mClient->getDisplayedContentSamplingAttributes(
143 display, [&](const auto& tmpError, const auto& tmpFormat, const auto& tmpDataspace,
144 const auto& tmpComponentMask) {
145 error = tmpError;
146 format = tmpFormat;
147 dataspace = tmpDataspace;
148 componentMask = tmpComponentMask;
149 });
150 return error;
151 }
152
setDisplayedContentSamplingEnabled(uint64_t display,IComposerClient::DisplayedContentSampling enable,hidl_bitfield<IComposerClient::FormatColorComponent> componentMask,uint64_t maxFrames)153 Error ComposerClient::setDisplayedContentSamplingEnabled(
154 uint64_t display, IComposerClient::DisplayedContentSampling enable,
155 hidl_bitfield<IComposerClient::FormatColorComponent> componentMask, uint64_t maxFrames) {
156 return mClient->setDisplayedContentSamplingEnabled(display, enable, componentMask, maxFrames);
157 }
158
getDisplayedContentSample(uint64_t display,uint64_t maxFrames,uint64_t timestamp,uint64_t & frameCount,hidl_vec<uint64_t> & sampleComponent0,hidl_vec<uint64_t> & sampleComponent1,hidl_vec<uint64_t> & sampleComponent2,hidl_vec<uint64_t> & sampleComponent3)159 Error ComposerClient::getDisplayedContentSample(uint64_t display, uint64_t maxFrames,
160 uint64_t timestamp, uint64_t& frameCount,
161 hidl_vec<uint64_t>& sampleComponent0,
162 hidl_vec<uint64_t>& sampleComponent1,
163 hidl_vec<uint64_t>& sampleComponent2,
164 hidl_vec<uint64_t>& sampleComponent3) {
165 auto error = Error::BAD_PARAMETER;
166 mClient->getDisplayedContentSample(
167 display, maxFrames, timestamp,
168 [&](const auto& tmpError, const auto& tmpFrameCount, const auto& tmpSamples0,
169 const auto& tmpSamples1, const auto& tmpSamples2, const auto& tmpSamples3) {
170 error = tmpError;
171 frameCount = tmpFrameCount;
172 sampleComponent0 = tmpSamples0;
173 sampleComponent1 = tmpSamples1;
174 sampleComponent2 = tmpSamples2;
175 sampleComponent3 = tmpSamples3;
176 });
177 return error;
178 }
179
getDisplayCapabilities(Display display,std::vector<IComposerClient::DisplayCapability> * outCapabilities)180 Error ComposerClient::getDisplayCapabilities(
181 Display display, std::vector<IComposerClient::DisplayCapability>* outCapabilities) {
182 std::vector<IComposerClient::DisplayCapability> capabilities;
183 Error error = Error::NONE;
184 mClient->getDisplayCapabilities(display,
185 [&](const auto& tmpError, const auto& tmpCapabilities) {
186 error = tmpError;
187 *outCapabilities = tmpCapabilities;
188 });
189
190 return error;
191 }
192
getDisplayBrightnessSupport(Display display)193 bool ComposerClient::getDisplayBrightnessSupport(Display display) {
194 bool support = false;
195 mClient->getDisplayBrightnessSupport(
196 display, [&](const auto& /*error*/, const auto& tmpSupport) { support = tmpSupport; });
197 return support;
198 }
199
setDisplayBrightness(Display display,float brightness)200 Error ComposerClient::setDisplayBrightness(Display display, float brightness) {
201 return mClient->setDisplayBrightness(display, brightness);
202 }
203
204 } // namespace vts
205 } // namespace V2_3
206 } // namespace composer
207 } // namespace graphics
208 } // namespace hardware
209 } // namespace android
210