blob: 357c7725afbd36c24a3a90d43db4dc3dd4e4e1f5 [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
48std::vector<IComposerClient::PerFrameMetadataKey> ComposerClient_v2_2::getPerFrameMetadataKeys(
49 Display display) {
50 std::vector<IComposerClient::PerFrameMetadataKey> keys;
51 mClient_v2_2->getPerFrameMetadataKeys(display, [&](const auto& tmpError, const auto& tmpKeys) {
52 ASSERT_EQ(Error::NONE, tmpError) << "failed to get HDR metadata keys";
53 keys = tmpKeys;
54 });
55
56 return keys;
57}
58
Chia-I Wu96a098a2018-01-25 10:38:06 -080059void ComposerClient_v2_2::execute_v2_2(V2_1::vts::TestCommandReader* reader,
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -080060 V2_2::CommandWriterBase* writer) {
61 bool queueChanged = false;
62 uint32_t commandLength = 0;
63 hidl_vec<hidl_handle> commandHandles;
64 ASSERT_TRUE(writer->writeQueue(&queueChanged, &commandLength, &commandHandles));
65
66 if (queueChanged) {
67 auto ret = mClient_v2_2->setInputCommandQueue(*writer->getMQDescriptor());
68 ASSERT_EQ(Error::NONE, static_cast<Error>(ret));
69 return;
70 }
71
72 mClient_v2_2->executeCommands(commandLength, commandHandles,
73 [&](const auto& tmpError, const auto& tmpOutQueueChanged,
74 const auto& tmpOutLength, const auto& tmpOutHandles) {
75 ASSERT_EQ(Error::NONE, tmpError);
76
77 if (tmpOutQueueChanged) {
78 mClient_v2_2->getOutputCommandQueue(
79 [&](const auto& tmpError, const auto& tmpDescriptor) {
80 ASSERT_EQ(Error::NONE, tmpError);
81 reader->setMQDescriptor(tmpDescriptor);
82 });
83 }
84
85 ASSERT_TRUE(reader->readQueue(tmpOutLength, tmpOutHandles));
86 reader->parse();
87 });
88}
89
Peiyong Lina2acfa22018-03-28 12:09:42 -070090Display ComposerClient_v2_2::createVirtualDisplay_2_2(uint32_t width, uint32_t height,
91 PixelFormat formatHint,
92 uint32_t outputBufferSlotCount,
93 PixelFormat* outFormat) {
94 Display display = 0;
95 mClient_v2_2->createVirtualDisplay_2_2(
96 width, height, formatHint, outputBufferSlotCount,
97 [&](const auto& tmpError, const auto& tmpDisplay, const auto& tmpFormat) {
98 ASSERT_EQ(Error::NONE, tmpError) << "failed to create virtual display";
99 display = tmpDisplay;
100 *outFormat = tmpFormat;
101
102 ASSERT_TRUE(mDisplayResources.insert({display, DisplayResource(true)}).second)
103 << "duplicated virtual display id " << display;
104 });
105
106 return display;
107}
108
109bool ComposerClient_v2_2::getClientTargetSupport_2_2(Display display, uint32_t width,
110 uint32_t height, PixelFormat format,
111 Dataspace dataspace) {
112 Error error =
113 mClient_v2_2->getClientTargetSupport_2_2(display, width, height, format, dataspace);
114 return error == Error::NONE;
115}
116
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -0800117void ComposerClient_v2_2::setPowerMode_2_2(Display display, V2_2::IComposerClient::PowerMode mode) {
118 Error error = mClient_v2_2->setPowerMode_2_2(display, mode);
119 ASSERT_TRUE(error == Error::NONE || error == Error::UNSUPPORTED) << "failed to set power mode";
120}
121
122void ComposerClient_v2_2::setReadbackBuffer(Display display, const native_handle_t* buffer,
123 int32_t /* releaseFence */) {
124 // Ignoring fence, HIDL doesn't care
125 Error error = mClient_v2_2->setReadbackBuffer(display, buffer, nullptr);
126 ASSERT_EQ(Error::NONE, error) << "failed to setReadbackBuffer";
127}
128
129void ComposerClient_v2_2::getReadbackBufferAttributes(Display display, PixelFormat* outPixelFormat,
130 Dataspace* outDataspace) {
131 mClient_v2_2->getReadbackBufferAttributes(
132 display,
133 [&](const auto& tmpError, const auto& tmpOutPixelFormat, const auto& tmpOutDataspace) {
134 ASSERT_EQ(Error::NONE, tmpError) << "failed to get readback buffer attributes";
135 *outPixelFormat = tmpOutPixelFormat;
136 *outDataspace = tmpOutDataspace;
137 });
138}
139
140void ComposerClient_v2_2::getReadbackBufferFence(Display display, int32_t* outFence) {
141 hidl_handle handle;
142 mClient_v2_2->getReadbackBufferFence(display, [&](const auto& tmpError, const auto& tmpHandle) {
143 ASSERT_EQ(Error::NONE, tmpError) << "failed to get readback fence";
144 handle = tmpHandle;
145 });
146 *outFence = 0;
147}
148
Chia-I Wu6c8257f2018-02-28 12:24:42 -0800149std::vector<ColorMode> ComposerClient_v2_2::getColorModes(Display display) {
150 std::vector<ColorMode> modes;
151 mClient_v2_2->getColorModes_2_2(display, [&](const auto& tmpError, const auto& tmpModes) {
152 ASSERT_EQ(Error::NONE, tmpError) << "failed to get color modes";
153 modes = tmpModes;
154 });
155 return modes;
156}
157
158std::vector<RenderIntent> ComposerClient_v2_2::getRenderIntents(Display display, ColorMode mode) {
159 std::vector<RenderIntent> intents;
160 mClient_v2_2->getRenderIntents(
161 display, mode, [&](const auto& tmpError, const auto& tmpIntents) {
162 ASSERT_EQ(Error::NONE, tmpError) << "failed to get render intents";
163 intents = tmpIntents;
164 });
165 return intents;
166}
167
168void ComposerClient_v2_2::setColorMode(Display display, ColorMode mode, RenderIntent intent) {
169 Error error = mClient_v2_2->setColorMode_2_2(display, mode, intent);
170 ASSERT_TRUE(error == Error::NONE || error == Error::UNSUPPORTED) << "failed to set color mode";
171}
172
173std::array<float, 16> ComposerClient_v2_2::getDataspaceSaturationMatrix(Dataspace dataspace) {
174 std::array<float, 16> matrix;
175 mClient_v2_2->getDataspaceSaturationMatrix(
176 dataspace, [&](const auto& tmpError, const auto& tmpMatrix) {
177 ASSERT_EQ(Error::NONE, tmpError) << "failed to get datasapce saturation matrix";
178 std::copy_n(tmpMatrix.data(), matrix.size(), matrix.begin());
179 });
180
181 return matrix;
182}
183
Chia-I Wu96a098a2018-01-25 10:38:06 -0800184} // namespace vts
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -0800185} // namespace V2_2
186} // namespace composer
187} // namespace graphics
188} // namespace hardware
189} // namespace android