blob: 6a320712793837b419d94768dcf75cec3f80d88e [file] [log] [blame]
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -08001/*
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
Chia-I Wu96a098a2018-01-25 10:38:06 -080017#include <composer-vts/2.2/ComposerVts.h>
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -080018
Chia-I Wu96a098a2018-01-25 10:38:06 -080019#include <VtsHalHidlTargetTestBase.h>
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -080020#include <composer-command-buffer/2.2/ComposerCommandBuffer.h>
Chia-I Wu96a098a2018-01-25 10:38:06 -080021#include <hidl/HidlTransportUtils.h>
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -080022
23namespace android {
24namespace hardware {
25namespace graphics {
26namespace composer {
27namespace V2_2 {
Chia-I Wu96a098a2018-01-25 10:38:06 -080028namespace vts {
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -080029
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -080030using android::hardware::details::canCastInterface;
Chia-I Wu8b20c5c2018-01-25 11:18:10 -080031using android::hardware::details::getDescriptor;
32using android::hardware::graphics::composer::V2_2::IComposerClient;
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -080033
34std::unique_ptr<ComposerClient_v2_2> Composer_v2_2::createClient_v2_2() {
35 std::unique_ptr<ComposerClient_v2_2> client;
36 mComposer->createClient([&](const auto& tmpError, const auto& tmpClient) {
37 ASSERT_EQ(Error::NONE, tmpError) << "failed to create client";
38 ALOGV("tmpClient is a %s", getDescriptor(&(*tmpClient)).c_str());
39 ASSERT_TRUE(canCastInterface(
40 &(*tmpClient), "android.hardware.graphics.composer@2.2::IComposerClient", false))
41 << "Cannot create 2.2 IComposerClient";
42 client = std::make_unique<ComposerClient_v2_2>(IComposerClient::castFrom(tmpClient, true));
43 });
44
45 return client;
46}
47
Chia-I Wu09782442018-05-22 10:58:48 -070048sp<V2_2::IComposerClient> ComposerClient_v2_2::getRaw() const {
49 return mClient_v2_2;
50}
51
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -080052std::vector<IComposerClient::PerFrameMetadataKey> ComposerClient_v2_2::getPerFrameMetadataKeys(
53 Display display) {
54 std::vector<IComposerClient::PerFrameMetadataKey> keys;
55 mClient_v2_2->getPerFrameMetadataKeys(display, [&](const auto& tmpError, const auto& tmpKeys) {
56 ASSERT_EQ(Error::NONE, tmpError) << "failed to get HDR metadata keys";
57 keys = tmpKeys;
58 });
59
60 return keys;
61}
62
Chia-I Wu96a098a2018-01-25 10:38:06 -080063void ComposerClient_v2_2::execute_v2_2(V2_1::vts::TestCommandReader* reader,
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -080064 V2_2::CommandWriterBase* writer) {
65 bool queueChanged = false;
66 uint32_t commandLength = 0;
67 hidl_vec<hidl_handle> commandHandles;
68 ASSERT_TRUE(writer->writeQueue(&queueChanged, &commandLength, &commandHandles));
69
70 if (queueChanged) {
71 auto ret = mClient_v2_2->setInputCommandQueue(*writer->getMQDescriptor());
72 ASSERT_EQ(Error::NONE, static_cast<Error>(ret));
73 return;
74 }
75
76 mClient_v2_2->executeCommands(commandLength, commandHandles,
77 [&](const auto& tmpError, const auto& tmpOutQueueChanged,
78 const auto& tmpOutLength, const auto& tmpOutHandles) {
79 ASSERT_EQ(Error::NONE, tmpError);
80
81 if (tmpOutQueueChanged) {
82 mClient_v2_2->getOutputCommandQueue(
83 [&](const auto& tmpError, const auto& tmpDescriptor) {
84 ASSERT_EQ(Error::NONE, tmpError);
85 reader->setMQDescriptor(tmpDescriptor);
86 });
87 }
88
89 ASSERT_TRUE(reader->readQueue(tmpOutLength, tmpOutHandles));
90 reader->parse();
91 });
92}
93
Peiyong Lina2acfa22018-03-28 12:09:42 -070094Display ComposerClient_v2_2::createVirtualDisplay_2_2(uint32_t width, uint32_t height,
95 PixelFormat formatHint,
96 uint32_t outputBufferSlotCount,
97 PixelFormat* outFormat) {
98 Display display = 0;
99 mClient_v2_2->createVirtualDisplay_2_2(
100 width, height, formatHint, outputBufferSlotCount,
101 [&](const auto& tmpError, const auto& tmpDisplay, const auto& tmpFormat) {
102 ASSERT_EQ(Error::NONE, tmpError) << "failed to create virtual display";
103 display = tmpDisplay;
104 *outFormat = tmpFormat;
105
106 ASSERT_TRUE(mDisplayResources.insert({display, DisplayResource(true)}).second)
107 << "duplicated virtual display id " << display;
108 });
109
110 return display;
111}
112
113bool ComposerClient_v2_2::getClientTargetSupport_2_2(Display display, uint32_t width,
114 uint32_t height, PixelFormat format,
115 Dataspace dataspace) {
116 Error error =
117 mClient_v2_2->getClientTargetSupport_2_2(display, width, height, format, dataspace);
118 return error == Error::NONE;
119}
120
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -0800121void ComposerClient_v2_2::setPowerMode_2_2(Display display, V2_2::IComposerClient::PowerMode mode) {
122 Error error = mClient_v2_2->setPowerMode_2_2(display, mode);
123 ASSERT_TRUE(error == Error::NONE || error == Error::UNSUPPORTED) << "failed to set power mode";
124}
125
126void ComposerClient_v2_2::setReadbackBuffer(Display display, const native_handle_t* buffer,
127 int32_t /* releaseFence */) {
128 // Ignoring fence, HIDL doesn't care
129 Error error = mClient_v2_2->setReadbackBuffer(display, buffer, nullptr);
130 ASSERT_EQ(Error::NONE, error) << "failed to setReadbackBuffer";
131}
132
133void ComposerClient_v2_2::getReadbackBufferAttributes(Display display, PixelFormat* outPixelFormat,
134 Dataspace* outDataspace) {
135 mClient_v2_2->getReadbackBufferAttributes(
136 display,
137 [&](const auto& tmpError, const auto& tmpOutPixelFormat, const auto& tmpOutDataspace) {
138 ASSERT_EQ(Error::NONE, tmpError) << "failed to get readback buffer attributes";
139 *outPixelFormat = tmpOutPixelFormat;
140 *outDataspace = tmpOutDataspace;
141 });
142}
143
144void ComposerClient_v2_2::getReadbackBufferFence(Display display, int32_t* outFence) {
145 hidl_handle handle;
146 mClient_v2_2->getReadbackBufferFence(display, [&](const auto& tmpError, const auto& tmpHandle) {
147 ASSERT_EQ(Error::NONE, tmpError) << "failed to get readback fence";
148 handle = tmpHandle;
149 });
150 *outFence = 0;
151}
152
Chia-I Wu6c8257f2018-02-28 12:24:42 -0800153std::vector<ColorMode> ComposerClient_v2_2::getColorModes(Display display) {
154 std::vector<ColorMode> modes;
155 mClient_v2_2->getColorModes_2_2(display, [&](const auto& tmpError, const auto& tmpModes) {
156 ASSERT_EQ(Error::NONE, tmpError) << "failed to get color modes";
157 modes = tmpModes;
158 });
159 return modes;
160}
161
162std::vector<RenderIntent> ComposerClient_v2_2::getRenderIntents(Display display, ColorMode mode) {
163 std::vector<RenderIntent> intents;
164 mClient_v2_2->getRenderIntents(
165 display, mode, [&](const auto& tmpError, const auto& tmpIntents) {
166 ASSERT_EQ(Error::NONE, tmpError) << "failed to get render intents";
167 intents = tmpIntents;
168 });
169 return intents;
170}
171
172void ComposerClient_v2_2::setColorMode(Display display, ColorMode mode, RenderIntent intent) {
173 Error error = mClient_v2_2->setColorMode_2_2(display, mode, intent);
174 ASSERT_TRUE(error == Error::NONE || error == Error::UNSUPPORTED) << "failed to set color mode";
175}
176
177std::array<float, 16> ComposerClient_v2_2::getDataspaceSaturationMatrix(Dataspace dataspace) {
178 std::array<float, 16> matrix;
179 mClient_v2_2->getDataspaceSaturationMatrix(
180 dataspace, [&](const auto& tmpError, const auto& tmpMatrix) {
181 ASSERT_EQ(Error::NONE, tmpError) << "failed to get datasapce saturation matrix";
182 std::copy_n(tmpMatrix.data(), matrix.size(), matrix.begin());
183 });
184
185 return matrix;
186}
187
Chia-I Wu96a098a2018-01-25 10:38:06 -0800188} // namespace vts
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -0800189} // namespace V2_2
190} // namespace composer
191} // namespace graphics
192} // namespace hardware
193} // namespace android