blob: a526137c4112642d1e9c00f7c8bb2f471982bd0e [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
19#include <composer-command-buffer/2.2/ComposerCommandBuffer.h>
Chia-I Wu96a098a2018-01-25 10:38:06 -080020#include <hidl/HidlTransportUtils.h>
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -080021
22namespace android {
23namespace hardware {
24namespace graphics {
25namespace composer {
26namespace V2_2 {
Chia-I Wu96a098a2018-01-25 10:38:06 -080027namespace vts {
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -080028
Dominik Laskowski0c415582018-04-02 15:35:00 -070029using details::canCastInterface;
30using details::getDescriptor;
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -080031
Dominik Laskowski0c415582018-04-02 15:35:00 -070032std::unique_ptr<ComposerClient> Composer::createClient() {
33 std::unique_ptr<ComposerClient> client;
34 getRaw()->createClient([&](const auto& tmpError, const auto& tmpClient) {
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -080035 ASSERT_EQ(Error::NONE, tmpError) << "failed to create client";
36 ALOGV("tmpClient is a %s", getDescriptor(&(*tmpClient)).c_str());
37 ASSERT_TRUE(canCastInterface(
38 &(*tmpClient), "android.hardware.graphics.composer@2.2::IComposerClient", false))
39 << "Cannot create 2.2 IComposerClient";
Dominik Laskowski0c415582018-04-02 15:35:00 -070040 client = std::make_unique<ComposerClient>(IComposerClient::castFrom(tmpClient, true));
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -080041 });
42
43 return client;
44}
45
Chia-I Wu76630c62018-05-22 12:52:36 -070046sp<IComposerClient> ComposerClient::getRaw() const {
47 return mClient;
48}
49
Dominik Laskowski0c415582018-04-02 15:35:00 -070050std::vector<IComposerClient::PerFrameMetadataKey> ComposerClient::getPerFrameMetadataKeys(
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -080051 Display display) {
52 std::vector<IComposerClient::PerFrameMetadataKey> keys;
Dominik Laskowski0c415582018-04-02 15:35:00 -070053 mClient->getPerFrameMetadataKeys(display, [&](const auto& tmpError, const auto& tmpKeys) {
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -080054 ASSERT_EQ(Error::NONE, tmpError) << "failed to get HDR metadata keys";
55 keys = tmpKeys;
56 });
57
58 return keys;
59}
60
Dominik Laskowski0c415582018-04-02 15:35:00 -070061void ComposerClient::execute(V2_1::vts::TestCommandReader* reader, CommandWriterBase* writer) {
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -080062 bool queueChanged = false;
63 uint32_t commandLength = 0;
64 hidl_vec<hidl_handle> commandHandles;
65 ASSERT_TRUE(writer->writeQueue(&queueChanged, &commandLength, &commandHandles));
66
67 if (queueChanged) {
Dominik Laskowski0c415582018-04-02 15:35:00 -070068 auto ret = mClient->setInputCommandQueue(*writer->getMQDescriptor());
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -080069 ASSERT_EQ(Error::NONE, static_cast<Error>(ret));
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -080070 }
71
Dominik Laskowski0c415582018-04-02 15:35:00 -070072 mClient->executeCommands(commandLength, commandHandles,
73 [&](const auto& tmpError, const auto& tmpOutQueueChanged,
74 const auto& tmpOutLength, const auto& tmpOutHandles) {
75 ASSERT_EQ(Error::NONE, tmpError);
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -080076
Dominik Laskowski0c415582018-04-02 15:35:00 -070077 if (tmpOutQueueChanged) {
78 mClient->getOutputCommandQueue(
79 [&](const auto& tmpError, const auto& tmpDescriptor) {
80 ASSERT_EQ(Error::NONE, tmpError);
81 reader->setMQDescriptor(tmpDescriptor);
82 });
83 }
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -080084
Dominik Laskowski0c415582018-04-02 15:35:00 -070085 ASSERT_TRUE(reader->readQueue(tmpOutLength, tmpOutHandles));
86 reader->parse();
87 });
Valerie Haucbe8e9a2018-09-17 10:58:03 -070088 reader->reset();
89 writer->reset();
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -080090}
91
Dominik Laskowski0c415582018-04-02 15:35:00 -070092Display ComposerClient::createVirtualDisplay_2_2(uint32_t width, uint32_t height,
93 PixelFormat formatHint,
94 uint32_t outputBufferSlotCount,
95 PixelFormat* outFormat) {
Peiyong Lina2acfa22018-03-28 12:09:42 -070096 Display display = 0;
Dominik Laskowski0c415582018-04-02 15:35:00 -070097 mClient->createVirtualDisplay_2_2(
Peiyong Lina2acfa22018-03-28 12:09:42 -070098 width, height, formatHint, outputBufferSlotCount,
99 [&](const auto& tmpError, const auto& tmpDisplay, const auto& tmpFormat) {
100 ASSERT_EQ(Error::NONE, tmpError) << "failed to create virtual display";
101 display = tmpDisplay;
102 *outFormat = tmpFormat;
103
104 ASSERT_TRUE(mDisplayResources.insert({display, DisplayResource(true)}).second)
105 << "duplicated virtual display id " << display;
106 });
107
108 return display;
109}
110
Dominik Laskowski0c415582018-04-02 15:35:00 -0700111bool ComposerClient::getClientTargetSupport_2_2(Display display, uint32_t width, uint32_t height,
112 PixelFormat format, Dataspace dataspace) {
113 Error error = mClient->getClientTargetSupport_2_2(display, width, height, format, dataspace);
Peiyong Lina2acfa22018-03-28 12:09:42 -0700114 return error == Error::NONE;
115}
116
Dominik Laskowski0c415582018-04-02 15:35:00 -0700117void ComposerClient::setPowerMode_2_2(Display display, IComposerClient::PowerMode mode) {
118 Error error = mClient->setPowerMode_2_2(display, mode);
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -0800119 ASSERT_TRUE(error == Error::NONE || error == Error::UNSUPPORTED) << "failed to set power mode";
120}
121
Dominik Laskowski0c415582018-04-02 15:35:00 -0700122void ComposerClient::setReadbackBuffer(Display display, const native_handle_t* buffer,
123 int32_t /* releaseFence */) {
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -0800124 // Ignoring fence, HIDL doesn't care
Dominik Laskowski0c415582018-04-02 15:35:00 -0700125 Error error = mClient->setReadbackBuffer(display, buffer, nullptr);
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -0800126 ASSERT_EQ(Error::NONE, error) << "failed to setReadbackBuffer";
127}
128
Dominik Laskowski0c415582018-04-02 15:35:00 -0700129void ComposerClient::getReadbackBufferAttributes(Display display, PixelFormat* outPixelFormat,
130 Dataspace* outDataspace) {
131 mClient->getReadbackBufferAttributes(
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -0800132 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
Dominik Laskowski0c415582018-04-02 15:35:00 -0700140void ComposerClient::getReadbackBufferFence(Display display, int32_t* outFence) {
Dominik Laskowski0c415582018-04-02 15:35:00 -0700141 mClient->getReadbackBufferFence(display, [&](const auto& tmpError, const auto& tmpHandle) {
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -0800142 ASSERT_EQ(Error::NONE, tmpError) << "failed to get readback fence";
Valerie Hau667f11a2018-08-01 12:58:44 -0700143 const native_handle_t* nativeFenceHandle = tmpHandle.getNativeHandle();
144 *outFence = dup(nativeFenceHandle->data[0]);
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -0800145 });
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -0800146}
147
Dominik Laskowski0c415582018-04-02 15:35:00 -0700148std::vector<ColorMode> ComposerClient::getColorModes(Display display) {
Chia-I Wu6c8257f2018-02-28 12:24:42 -0800149 std::vector<ColorMode> modes;
Dominik Laskowski0c415582018-04-02 15:35:00 -0700150 mClient->getColorModes_2_2(display, [&](const auto& tmpError, const auto& tmpModes) {
Chia-I Wu6c8257f2018-02-28 12:24:42 -0800151 ASSERT_EQ(Error::NONE, tmpError) << "failed to get color modes";
152 modes = tmpModes;
153 });
154 return modes;
155}
156
Dominik Laskowski0c415582018-04-02 15:35:00 -0700157std::vector<RenderIntent> ComposerClient::getRenderIntents(Display display, ColorMode mode) {
Chia-I Wu6c8257f2018-02-28 12:24:42 -0800158 std::vector<RenderIntent> intents;
Dominik Laskowski0c415582018-04-02 15:35:00 -0700159 mClient->getRenderIntents(display, mode, [&](const auto& tmpError, const auto& tmpIntents) {
160 ASSERT_EQ(Error::NONE, tmpError) << "failed to get render intents";
161 intents = tmpIntents;
162 });
Chia-I Wu6c8257f2018-02-28 12:24:42 -0800163 return intents;
164}
165
Dominik Laskowski0c415582018-04-02 15:35:00 -0700166void ComposerClient::setColorMode(Display display, ColorMode mode, RenderIntent intent) {
167 Error error = mClient->setColorMode_2_2(display, mode, intent);
Chia-I Wu6c8257f2018-02-28 12:24:42 -0800168 ASSERT_TRUE(error == Error::NONE || error == Error::UNSUPPORTED) << "failed to set color mode";
169}
170
Dominik Laskowski0c415582018-04-02 15:35:00 -0700171std::array<float, 16> ComposerClient::getDataspaceSaturationMatrix(Dataspace dataspace) {
Chia-I Wu6c8257f2018-02-28 12:24:42 -0800172 std::array<float, 16> matrix;
Dominik Laskowski0c415582018-04-02 15:35:00 -0700173 mClient->getDataspaceSaturationMatrix(
Chia-I Wu6c8257f2018-02-28 12:24:42 -0800174 dataspace, [&](const auto& tmpError, const auto& tmpMatrix) {
175 ASSERT_EQ(Error::NONE, tmpError) << "failed to get datasapce saturation matrix";
176 std::copy_n(tmpMatrix.data(), matrix.size(), matrix.begin());
177 });
178
179 return matrix;
180}
181
Valerie Hauc1dc3132019-06-13 09:49:44 -0700182Gralloc::Gralloc() {
183 [this] {
Marissa Wall53aff112019-06-20 13:49:21 -0700184 ALOGD("Attempting to initialize gralloc4");
185 ASSERT_NO_FATAL_FAILURE(mGralloc4 = std::make_shared<Gralloc4>("default", "default",
Valerie Hauc1dc3132019-06-13 09:49:44 -0700186 /*errOnFailure=*/false));
Marissa Wall53aff112019-06-20 13:49:21 -0700187 if (mGralloc4->getMapper() == nullptr || mGralloc4->getAllocator() == nullptr) {
188 mGralloc4 = nullptr;
189 ALOGD("Failed to initialize gralloc4, initializing gralloc3");
190 ASSERT_NO_FATAL_FAILURE(mGralloc3 = std::make_shared<Gralloc3>("default", "default",
191 /*errOnFailure=*/false));
192 if (mGralloc3->getMapper() == nullptr || mGralloc3->getAllocator() == nullptr) {
193 mGralloc3 = nullptr;
194 ALOGD("Failed to initialize gralloc3, initializing gralloc2_1");
195 mGralloc2_1 = std::make_shared<Gralloc2_1>(/*errOnFailure*/ false);
196 if (!mGralloc2_1->getMapper()) {
197 mGralloc2_1 = nullptr;
198 ALOGD("Failed to initialize gralloc2_1, initializing gralloc2");
199 ASSERT_NO_FATAL_FAILURE(mGralloc2 = std::make_shared<Gralloc2>());
200 }
Valerie Hauc1dc3132019-06-13 09:49:44 -0700201 }
202 }
203 }();
204}
205
206bool Gralloc::validateBufferSize(const native_handle_t* bufferHandle, uint32_t width,
207 uint32_t height, uint32_t layerCount, PixelFormat format,
208 uint64_t usage, uint32_t stride) {
Marissa Wall53aff112019-06-20 13:49:21 -0700209 if (mGralloc4) {
210 IMapper4::BufferDescriptorInfo info{};
211 info.width = width;
212 info.height = height;
213 info.layerCount = layerCount;
214 info.format = static_cast<android::hardware::graphics::common::V1_2::PixelFormat>(format);
215 info.usage = usage;
216 return mGralloc4->validateBufferSize(bufferHandle, info, stride);
217 } else if (mGralloc3) {
Valerie Hauc1dc3132019-06-13 09:49:44 -0700218 IMapper3::BufferDescriptorInfo info{};
219 info.width = width;
220 info.height = height;
221 info.layerCount = layerCount;
222 info.format = static_cast<android::hardware::graphics::common::V1_2::PixelFormat>(format);
223 info.usage = usage;
224 return mGralloc3->validateBufferSize(bufferHandle, info, stride);
225 } else if (mGralloc2_1) {
226 IMapper2_1::BufferDescriptorInfo info{};
227 info.width = width;
228 info.height = height;
229 info.layerCount = layerCount;
230 info.format = static_cast<android::hardware::graphics::common::V1_1::PixelFormat>(format);
231 info.usage = usage;
232 return mGralloc2_1->validateBufferSize(bufferHandle, info, stride);
233 } else {
234 return true;
235 }
236}
237
Chia-I Wu96a098a2018-01-25 10:38:06 -0800238} // namespace vts
Courtney Goeltzenleuchterbe92bb92018-01-11 08:50:03 -0800239} // namespace V2_2
240} // namespace composer
241} // namespace graphics
242} // namespace hardware
243} // namespace android