blob: 00946cef6110fd66ee9496436755dde19cf6a6ab [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
17#include <VtsHalHidlTargetTestBase.h>
18#include <hidl/HidlTransportUtils.h>
19
20#include <composer-command-buffer/2.2/ComposerCommandBuffer.h>
21#include "2.2/VtsHalGraphicsComposerTestUtils.h"
22
23namespace android {
24namespace hardware {
25namespace graphics {
26namespace composer {
27namespace V2_2 {
28namespace tests {
29
30using android::hardware::graphics::composer::V2_2::IComposerClient;
31using android::hardware::details::getDescriptor;
32using android::hardware::details::canCastInterface;
33
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
59void ComposerClient_v2_2::execute_v2_2(V2_1::tests::TestCommandReader* reader,
60 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
122} // namespace tests
123} // namespace V2_2
124} // namespace composer
125} // namespace graphics
126} // namespace hardware
127} // namespace android