blob: ae9e430545c521ae49257c7c2d91c3d2257b985e [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
Dominik Laskowski0c415582018-04-02 15:35:00 -070030using details::canCastInterface;
31using details::getDescriptor;
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -080032
Dominik Laskowski0c415582018-04-02 15:35:00 -070033std::unique_ptr<ComposerClient> Composer::createClient() {
34 std::unique_ptr<ComposerClient> client;
35 getRaw()->createClient([&](const auto& tmpError, const auto& tmpClient) {
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -080036 ASSERT_EQ(Error::NONE, tmpError) << "failed to create client";
37 ALOGV("tmpClient is a %s", getDescriptor(&(*tmpClient)).c_str());
38 ASSERT_TRUE(canCastInterface(
39 &(*tmpClient), "android.hardware.graphics.composer@2.2::IComposerClient", false))
40 << "Cannot create 2.2 IComposerClient";
Dominik Laskowski0c415582018-04-02 15:35:00 -070041 client = std::make_unique<ComposerClient>(IComposerClient::castFrom(tmpClient, true));
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -080042 });
43
44 return client;
45}
46
Dominik Laskowski0c415582018-04-02 15:35:00 -070047std::vector<IComposerClient::PerFrameMetadataKey> ComposerClient::getPerFrameMetadataKeys(
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -080048 Display display) {
49 std::vector<IComposerClient::PerFrameMetadataKey> keys;
Dominik Laskowski0c415582018-04-02 15:35:00 -070050 mClient->getPerFrameMetadataKeys(display, [&](const auto& tmpError, const auto& tmpKeys) {
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -080051 ASSERT_EQ(Error::NONE, tmpError) << "failed to get HDR metadata keys";
52 keys = tmpKeys;
53 });
54
55 return keys;
56}
57
Dominik Laskowski0c415582018-04-02 15:35:00 -070058void ComposerClient::execute(V2_1::vts::TestCommandReader* reader, CommandWriterBase* writer) {
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -080059 bool queueChanged = false;
60 uint32_t commandLength = 0;
61 hidl_vec<hidl_handle> commandHandles;
62 ASSERT_TRUE(writer->writeQueue(&queueChanged, &commandLength, &commandHandles));
63
64 if (queueChanged) {
Dominik Laskowski0c415582018-04-02 15:35:00 -070065 auto ret = mClient->setInputCommandQueue(*writer->getMQDescriptor());
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -080066 ASSERT_EQ(Error::NONE, static_cast<Error>(ret));
67 return;
68 }
69
Dominik Laskowski0c415582018-04-02 15:35:00 -070070 mClient->executeCommands(commandLength, commandHandles,
71 [&](const auto& tmpError, const auto& tmpOutQueueChanged,
72 const auto& tmpOutLength, const auto& tmpOutHandles) {
73 ASSERT_EQ(Error::NONE, tmpError);
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -080074
Dominik Laskowski0c415582018-04-02 15:35:00 -070075 if (tmpOutQueueChanged) {
76 mClient->getOutputCommandQueue(
77 [&](const auto& tmpError, const auto& tmpDescriptor) {
78 ASSERT_EQ(Error::NONE, tmpError);
79 reader->setMQDescriptor(tmpDescriptor);
80 });
81 }
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -080082
Dominik Laskowski0c415582018-04-02 15:35:00 -070083 ASSERT_TRUE(reader->readQueue(tmpOutLength, tmpOutHandles));
84 reader->parse();
85 });
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -080086}
87
Dominik Laskowski0c415582018-04-02 15:35:00 -070088Display ComposerClient::createVirtualDisplay_2_2(uint32_t width, uint32_t height,
89 PixelFormat formatHint,
90 uint32_t outputBufferSlotCount,
91 PixelFormat* outFormat) {
Peiyong Lina2acfa22018-03-28 12:09:42 -070092 Display display = 0;
Dominik Laskowski0c415582018-04-02 15:35:00 -070093 mClient->createVirtualDisplay_2_2(
Peiyong Lina2acfa22018-03-28 12:09:42 -070094 width, height, formatHint, outputBufferSlotCount,
95 [&](const auto& tmpError, const auto& tmpDisplay, const auto& tmpFormat) {
96 ASSERT_EQ(Error::NONE, tmpError) << "failed to create virtual display";
97 display = tmpDisplay;
98 *outFormat = tmpFormat;
99
100 ASSERT_TRUE(mDisplayResources.insert({display, DisplayResource(true)}).second)
101 << "duplicated virtual display id " << display;
102 });
103
104 return display;
105}
106
Dominik Laskowski0c415582018-04-02 15:35:00 -0700107bool ComposerClient::getClientTargetSupport_2_2(Display display, uint32_t width, uint32_t height,
108 PixelFormat format, Dataspace dataspace) {
109 Error error = mClient->getClientTargetSupport_2_2(display, width, height, format, dataspace);
Peiyong Lina2acfa22018-03-28 12:09:42 -0700110 return error == Error::NONE;
111}
112
Dominik Laskowski0c415582018-04-02 15:35:00 -0700113void ComposerClient::setPowerMode_2_2(Display display, IComposerClient::PowerMode mode) {
114 Error error = mClient->setPowerMode_2_2(display, mode);
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -0800115 ASSERT_TRUE(error == Error::NONE || error == Error::UNSUPPORTED) << "failed to set power mode";
116}
117
Dominik Laskowski0c415582018-04-02 15:35:00 -0700118void ComposerClient::setReadbackBuffer(Display display, const native_handle_t* buffer,
119 int32_t /* releaseFence */) {
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -0800120 // Ignoring fence, HIDL doesn't care
Dominik Laskowski0c415582018-04-02 15:35:00 -0700121 Error error = mClient->setReadbackBuffer(display, buffer, nullptr);
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -0800122 ASSERT_EQ(Error::NONE, error) << "failed to setReadbackBuffer";
123}
124
Dominik Laskowski0c415582018-04-02 15:35:00 -0700125void ComposerClient::getReadbackBufferAttributes(Display display, PixelFormat* outPixelFormat,
126 Dataspace* outDataspace) {
127 mClient->getReadbackBufferAttributes(
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -0800128 display,
129 [&](const auto& tmpError, const auto& tmpOutPixelFormat, const auto& tmpOutDataspace) {
130 ASSERT_EQ(Error::NONE, tmpError) << "failed to get readback buffer attributes";
131 *outPixelFormat = tmpOutPixelFormat;
132 *outDataspace = tmpOutDataspace;
133 });
134}
135
Dominik Laskowski0c415582018-04-02 15:35:00 -0700136void ComposerClient::getReadbackBufferFence(Display display, int32_t* outFence) {
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -0800137 hidl_handle handle;
Dominik Laskowski0c415582018-04-02 15:35:00 -0700138 mClient->getReadbackBufferFence(display, [&](const auto& tmpError, const auto& tmpHandle) {
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -0800139 ASSERT_EQ(Error::NONE, tmpError) << "failed to get readback fence";
140 handle = tmpHandle;
141 });
142 *outFence = 0;
143}
144
Dominik Laskowski0c415582018-04-02 15:35:00 -0700145std::vector<ColorMode> ComposerClient::getColorModes(Display display) {
Chia-I Wu6c8257f2018-02-28 12:24:42 -0800146 std::vector<ColorMode> modes;
Dominik Laskowski0c415582018-04-02 15:35:00 -0700147 mClient->getColorModes_2_2(display, [&](const auto& tmpError, const auto& tmpModes) {
Chia-I Wu6c8257f2018-02-28 12:24:42 -0800148 ASSERT_EQ(Error::NONE, tmpError) << "failed to get color modes";
149 modes = tmpModes;
150 });
151 return modes;
152}
153
Dominik Laskowski0c415582018-04-02 15:35:00 -0700154std::vector<RenderIntent> ComposerClient::getRenderIntents(Display display, ColorMode mode) {
Chia-I Wu6c8257f2018-02-28 12:24:42 -0800155 std::vector<RenderIntent> intents;
Dominik Laskowski0c415582018-04-02 15:35:00 -0700156 mClient->getRenderIntents(display, mode, [&](const auto& tmpError, const auto& tmpIntents) {
157 ASSERT_EQ(Error::NONE, tmpError) << "failed to get render intents";
158 intents = tmpIntents;
159 });
Chia-I Wu6c8257f2018-02-28 12:24:42 -0800160 return intents;
161}
162
Dominik Laskowski0c415582018-04-02 15:35:00 -0700163void ComposerClient::setColorMode(Display display, ColorMode mode, RenderIntent intent) {
164 Error error = mClient->setColorMode_2_2(display, mode, intent);
Chia-I Wu6c8257f2018-02-28 12:24:42 -0800165 ASSERT_TRUE(error == Error::NONE || error == Error::UNSUPPORTED) << "failed to set color mode";
166}
167
Dominik Laskowski0c415582018-04-02 15:35:00 -0700168std::array<float, 16> ComposerClient::getDataspaceSaturationMatrix(Dataspace dataspace) {
Chia-I Wu6c8257f2018-02-28 12:24:42 -0800169 std::array<float, 16> matrix;
Dominik Laskowski0c415582018-04-02 15:35:00 -0700170 mClient->getDataspaceSaturationMatrix(
Chia-I Wu6c8257f2018-02-28 12:24:42 -0800171 dataspace, [&](const auto& tmpError, const auto& tmpMatrix) {
172 ASSERT_EQ(Error::NONE, tmpError) << "failed to get datasapce saturation matrix";
173 std::copy_n(tmpMatrix.data(), matrix.size(), matrix.begin());
174 });
175
176 return matrix;
177}
178
Chia-I Wu96a098a2018-01-25 10:38:06 -0800179} // namespace vts
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -0800180} // namespace V2_2
181} // namespace composer
182} // namespace graphics
183} // namespace hardware
184} // namespace android