blob: d8fb656b7bc6c9f814ec141e7acf9b76f8790fab [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
Chia-I Wu76630c62018-05-22 12:52:36 -070047sp<IComposerClient> ComposerClient::getRaw() const {
48 return mClient;
49}
50
Dominik Laskowski0c415582018-04-02 15:35:00 -070051std::vector<IComposerClient::PerFrameMetadataKey> ComposerClient::getPerFrameMetadataKeys(
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -080052 Display display) {
53 std::vector<IComposerClient::PerFrameMetadataKey> keys;
Dominik Laskowski0c415582018-04-02 15:35:00 -070054 mClient->getPerFrameMetadataKeys(display, [&](const auto& tmpError, const auto& tmpKeys) {
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -080055 ASSERT_EQ(Error::NONE, tmpError) << "failed to get HDR metadata keys";
56 keys = tmpKeys;
57 });
58
59 return keys;
60}
61
Dominik Laskowski0c415582018-04-02 15:35:00 -070062void ComposerClient::execute(V2_1::vts::TestCommandReader* reader, CommandWriterBase* writer) {
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -080063 bool queueChanged = false;
64 uint32_t commandLength = 0;
65 hidl_vec<hidl_handle> commandHandles;
66 ASSERT_TRUE(writer->writeQueue(&queueChanged, &commandLength, &commandHandles));
67
68 if (queueChanged) {
Dominik Laskowski0c415582018-04-02 15:35:00 -070069 auto ret = mClient->setInputCommandQueue(*writer->getMQDescriptor());
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -080070 ASSERT_EQ(Error::NONE, static_cast<Error>(ret));
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -080071 }
72
Dominik Laskowski0c415582018-04-02 15:35:00 -070073 mClient->executeCommands(commandLength, commandHandles,
74 [&](const auto& tmpError, const auto& tmpOutQueueChanged,
75 const auto& tmpOutLength, const auto& tmpOutHandles) {
76 ASSERT_EQ(Error::NONE, tmpError);
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -080077
Dominik Laskowski0c415582018-04-02 15:35:00 -070078 if (tmpOutQueueChanged) {
79 mClient->getOutputCommandQueue(
80 [&](const auto& tmpError, const auto& tmpDescriptor) {
81 ASSERT_EQ(Error::NONE, tmpError);
82 reader->setMQDescriptor(tmpDescriptor);
83 });
84 }
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -080085
Dominik Laskowski0c415582018-04-02 15:35:00 -070086 ASSERT_TRUE(reader->readQueue(tmpOutLength, tmpOutHandles));
87 reader->parse();
88 });
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -080089}
90
Dominik Laskowski0c415582018-04-02 15:35:00 -070091Display ComposerClient::createVirtualDisplay_2_2(uint32_t width, uint32_t height,
92 PixelFormat formatHint,
93 uint32_t outputBufferSlotCount,
94 PixelFormat* outFormat) {
Peiyong Lina2acfa22018-03-28 12:09:42 -070095 Display display = 0;
Dominik Laskowski0c415582018-04-02 15:35:00 -070096 mClient->createVirtualDisplay_2_2(
Peiyong Lina2acfa22018-03-28 12:09:42 -070097 width, height, formatHint, outputBufferSlotCount,
98 [&](const auto& tmpError, const auto& tmpDisplay, const auto& tmpFormat) {
99 ASSERT_EQ(Error::NONE, tmpError) << "failed to create virtual display";
100 display = tmpDisplay;
101 *outFormat = tmpFormat;
102
103 ASSERT_TRUE(mDisplayResources.insert({display, DisplayResource(true)}).second)
104 << "duplicated virtual display id " << display;
105 });
106
107 return display;
108}
109
Dominik Laskowski0c415582018-04-02 15:35:00 -0700110bool ComposerClient::getClientTargetSupport_2_2(Display display, uint32_t width, uint32_t height,
111 PixelFormat format, Dataspace dataspace) {
112 Error error = mClient->getClientTargetSupport_2_2(display, width, height, format, dataspace);
Peiyong Lina2acfa22018-03-28 12:09:42 -0700113 return error == Error::NONE;
114}
115
Dominik Laskowski0c415582018-04-02 15:35:00 -0700116void ComposerClient::setPowerMode_2_2(Display display, IComposerClient::PowerMode mode) {
117 Error error = mClient->setPowerMode_2_2(display, mode);
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -0800118 ASSERT_TRUE(error == Error::NONE || error == Error::UNSUPPORTED) << "failed to set power mode";
119}
120
Dominik Laskowski0c415582018-04-02 15:35:00 -0700121void ComposerClient::setReadbackBuffer(Display display, const native_handle_t* buffer,
122 int32_t /* releaseFence */) {
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -0800123 // Ignoring fence, HIDL doesn't care
Dominik Laskowski0c415582018-04-02 15:35:00 -0700124 Error error = mClient->setReadbackBuffer(display, buffer, nullptr);
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -0800125 ASSERT_EQ(Error::NONE, error) << "failed to setReadbackBuffer";
126}
127
Dominik Laskowski0c415582018-04-02 15:35:00 -0700128void ComposerClient::getReadbackBufferAttributes(Display display, PixelFormat* outPixelFormat,
129 Dataspace* outDataspace) {
130 mClient->getReadbackBufferAttributes(
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -0800131 display,
132 [&](const auto& tmpError, const auto& tmpOutPixelFormat, const auto& tmpOutDataspace) {
133 ASSERT_EQ(Error::NONE, tmpError) << "failed to get readback buffer attributes";
134 *outPixelFormat = tmpOutPixelFormat;
135 *outDataspace = tmpOutDataspace;
136 });
137}
138
Dominik Laskowski0c415582018-04-02 15:35:00 -0700139void ComposerClient::getReadbackBufferFence(Display display, int32_t* outFence) {
Dominik Laskowski0c415582018-04-02 15:35:00 -0700140 mClient->getReadbackBufferFence(display, [&](const auto& tmpError, const auto& tmpHandle) {
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -0800141 ASSERT_EQ(Error::NONE, tmpError) << "failed to get readback fence";
Valerie Hau667f11a2018-08-01 12:58:44 -0700142 const native_handle_t* nativeFenceHandle = tmpHandle.getNativeHandle();
143 *outFence = dup(nativeFenceHandle->data[0]);
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -0800144 });
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -0800145}
146
Dominik Laskowski0c415582018-04-02 15:35:00 -0700147std::vector<ColorMode> ComposerClient::getColorModes(Display display) {
Chia-I Wu6c8257f2018-02-28 12:24:42 -0800148 std::vector<ColorMode> modes;
Dominik Laskowski0c415582018-04-02 15:35:00 -0700149 mClient->getColorModes_2_2(display, [&](const auto& tmpError, const auto& tmpModes) {
Chia-I Wu6c8257f2018-02-28 12:24:42 -0800150 ASSERT_EQ(Error::NONE, tmpError) << "failed to get color modes";
151 modes = tmpModes;
152 });
153 return modes;
154}
155
Dominik Laskowski0c415582018-04-02 15:35:00 -0700156std::vector<RenderIntent> ComposerClient::getRenderIntents(Display display, ColorMode mode) {
Chia-I Wu6c8257f2018-02-28 12:24:42 -0800157 std::vector<RenderIntent> intents;
Dominik Laskowski0c415582018-04-02 15:35:00 -0700158 mClient->getRenderIntents(display, mode, [&](const auto& tmpError, const auto& tmpIntents) {
159 ASSERT_EQ(Error::NONE, tmpError) << "failed to get render intents";
160 intents = tmpIntents;
161 });
Chia-I Wu6c8257f2018-02-28 12:24:42 -0800162 return intents;
163}
164
Dominik Laskowski0c415582018-04-02 15:35:00 -0700165void ComposerClient::setColorMode(Display display, ColorMode mode, RenderIntent intent) {
166 Error error = mClient->setColorMode_2_2(display, mode, intent);
Chia-I Wu6c8257f2018-02-28 12:24:42 -0800167 ASSERT_TRUE(error == Error::NONE || error == Error::UNSUPPORTED) << "failed to set color mode";
168}
169
Dominik Laskowski0c415582018-04-02 15:35:00 -0700170std::array<float, 16> ComposerClient::getDataspaceSaturationMatrix(Dataspace dataspace) {
Chia-I Wu6c8257f2018-02-28 12:24:42 -0800171 std::array<float, 16> matrix;
Dominik Laskowski0c415582018-04-02 15:35:00 -0700172 mClient->getDataspaceSaturationMatrix(
Chia-I Wu6c8257f2018-02-28 12:24:42 -0800173 dataspace, [&](const auto& tmpError, const auto& tmpMatrix) {
174 ASSERT_EQ(Error::NONE, tmpError) << "failed to get datasapce saturation matrix";
175 std::copy_n(tmpMatrix.data(), matrix.size(), matrix.begin());
176 });
177
178 return matrix;
179}
180
Chia-I Wu96a098a2018-01-25 10:38:06 -0800181} // namespace vts
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -0800182} // namespace V2_2
183} // namespace composer
184} // namespace graphics
185} // namespace hardware
186} // namespace android