blob: 9a035f653937b53747b71cfb1a306450b177dd23 [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
90void ComposerClient_v2_2::setPowerMode_2_2(Display display, V2_2::IComposerClient::PowerMode mode) {
91 Error error = mClient_v2_2->setPowerMode_2_2(display, mode);
92 ASSERT_TRUE(error == Error::NONE || error == Error::UNSUPPORTED) << "failed to set power mode";
93}
94
95void ComposerClient_v2_2::setReadbackBuffer(Display display, const native_handle_t* buffer,
96 int32_t /* releaseFence */) {
97 // Ignoring fence, HIDL doesn't care
98 Error error = mClient_v2_2->setReadbackBuffer(display, buffer, nullptr);
99 ASSERT_EQ(Error::NONE, error) << "failed to setReadbackBuffer";
100}
101
102void ComposerClient_v2_2::getReadbackBufferAttributes(Display display, PixelFormat* outPixelFormat,
103 Dataspace* outDataspace) {
104 mClient_v2_2->getReadbackBufferAttributes(
105 display,
106 [&](const auto& tmpError, const auto& tmpOutPixelFormat, const auto& tmpOutDataspace) {
107 ASSERT_EQ(Error::NONE, tmpError) << "failed to get readback buffer attributes";
108 *outPixelFormat = tmpOutPixelFormat;
109 *outDataspace = tmpOutDataspace;
110 });
111}
112
113void ComposerClient_v2_2::getReadbackBufferFence(Display display, int32_t* outFence) {
114 hidl_handle handle;
115 mClient_v2_2->getReadbackBufferFence(display, [&](const auto& tmpError, const auto& tmpHandle) {
116 ASSERT_EQ(Error::NONE, tmpError) << "failed to get readback fence";
117 handle = tmpHandle;
118 });
119 *outFence = 0;
120}
121
Chia-I Wu6c8257f2018-02-28 12:24:42 -0800122std::vector<ColorMode> ComposerClient_v2_2::getColorModes(Display display) {
123 std::vector<ColorMode> modes;
124 mClient_v2_2->getColorModes_2_2(display, [&](const auto& tmpError, const auto& tmpModes) {
125 ASSERT_EQ(Error::NONE, tmpError) << "failed to get color modes";
126 modes = tmpModes;
127 });
128 return modes;
129}
130
131std::vector<RenderIntent> ComposerClient_v2_2::getRenderIntents(Display display, ColorMode mode) {
132 std::vector<RenderIntent> intents;
133 mClient_v2_2->getRenderIntents(
134 display, mode, [&](const auto& tmpError, const auto& tmpIntents) {
135 ASSERT_EQ(Error::NONE, tmpError) << "failed to get render intents";
136 intents = tmpIntents;
137 });
138 return intents;
139}
140
141void ComposerClient_v2_2::setColorMode(Display display, ColorMode mode, RenderIntent intent) {
142 Error error = mClient_v2_2->setColorMode_2_2(display, mode, intent);
143 ASSERT_TRUE(error == Error::NONE || error == Error::UNSUPPORTED) << "failed to set color mode";
144}
145
146std::array<float, 16> ComposerClient_v2_2::getDataspaceSaturationMatrix(Dataspace dataspace) {
147 std::array<float, 16> matrix;
148 mClient_v2_2->getDataspaceSaturationMatrix(
149 dataspace, [&](const auto& tmpError, const auto& tmpMatrix) {
150 ASSERT_EQ(Error::NONE, tmpError) << "failed to get datasapce saturation matrix";
151 std::copy_n(tmpMatrix.data(), matrix.size(), matrix.begin());
152 });
153
154 return matrix;
155}
156
Chia-I Wu96a098a2018-01-25 10:38:06 -0800157} // namespace vts
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -0800158} // namespace V2_2
159} // namespace composer
160} // namespace graphics
161} // namespace hardware
162} // namespace android