blob: 2d4cc7d80e75e9329d1ccdba4fd6ae1ce98d7e55 [file] [log] [blame]
Adam Bodnar5bf9dc62019-05-24 09:20:04 -07001/*
2 * Copyright 2019 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 <composer-vts/2.2/RenderEngineVts.h>
18
19namespace android {
20namespace hardware {
21namespace graphics {
22namespace composer {
23namespace V2_2 {
24namespace vts {
25
26using mapper::V2_1::IMapper;
27using renderengine::DisplaySettings;
28using renderengine::LayerSettings;
Chong Zhang86e1aeb2019-10-22 15:49:46 -070029using renderengine::RenderEngineCreationArgs;
Adam Bodnar5bf9dc62019-05-24 09:20:04 -070030
Chong Zhang86e1aeb2019-10-22 15:49:46 -070031TestRenderEngine::TestRenderEngine(const RenderEngineCreationArgs& args) {
32 mFormat = static_cast<common::V1_1::PixelFormat>(args.pixelFormat);
33 mRenderEngine = renderengine::RenderEngine::create(args);
Adam Bodnar5bf9dc62019-05-24 09:20:04 -070034}
35
Adam Bodnar6c3929c2020-02-18 13:21:26 -080036TestRenderEngine::~TestRenderEngine() {
37 mRenderEngine.release();
38}
39
Adam Bodnar5bf9dc62019-05-24 09:20:04 -070040void TestRenderEngine::setRenderLayers(std::vector<std::shared_ptr<TestLayer>> layers) {
41 sort(layers.begin(), layers.end(),
42 [](const std::shared_ptr<TestLayer>& lhs, const std::shared_ptr<TestLayer>& rhs) -> bool {
43 return lhs->mZOrder < rhs->mZOrder;
44 });
45
46 if (!mCompositionLayers.empty()) {
47 mCompositionLayers.clear();
48 }
49 for (auto& layer : layers) {
50 LayerSettings settings = layer->toRenderEngineLayerSettings();
51 mCompositionLayers.push_back(settings);
52 }
53}
54
55void TestRenderEngine::initGraphicBuffer(uint32_t width, uint32_t height, uint32_t layerCount,
56 uint64_t usage) {
57 mGraphicBuffer =
58 new GraphicBuffer(width, height, static_cast<int32_t>(mFormat), layerCount, usage);
59}
60
61void TestRenderEngine::drawLayers() {
62 base::unique_fd bufferFence;
Vishnu Nair02da9972020-01-17 13:39:08 -080063
Sally Qid515dba2021-10-12 18:53:23 +000064 std::vector<renderengine::LayerSettings> compositionLayers;
65 compositionLayers.reserve(mCompositionLayers.size());
Vishnu Nair02da9972020-01-17 13:39:08 -080066 std::transform(mCompositionLayers.begin(), mCompositionLayers.end(),
Sally Qid515dba2021-10-12 18:53:23 +000067 std::back_insert_iterator(compositionLayers),
68 [](renderengine::LayerSettings& settings) -> renderengine::LayerSettings {
69 return settings;
Vishnu Nair02da9972020-01-17 13:39:08 -080070 });
Alec Mouri2a6ef4e2021-04-16 16:36:21 +000071 auto texture = std::make_shared<renderengine::ExternalTexture>(
72 mGraphicBuffer, *mRenderEngine, renderengine::ExternalTexture::Usage::WRITEABLE);
Sally Qia56868b2021-08-17 17:11:30 -070073 auto [status, readyFence] = mRenderEngine
Sally Qid515dba2021-10-12 18:53:23 +000074 ->drawLayers(mDisplaySettings, compositionLayers, texture,
75 true, std::move(bufferFence))
Sally Qia56868b2021-08-17 17:11:30 -070076 .get();
Adam Bodnar5bf9dc62019-05-24 09:20:04 -070077 int fd = readyFence.release();
78 if (fd != -1) {
79 ASSERT_EQ(0, sync_wait(fd, -1));
80 ASSERT_EQ(0, close(fd));
81 }
82}
83
84void TestRenderEngine::checkColorBuffer(std::vector<V2_2::IComposerClient::Color>& expectedColors) {
85 void* bufferData;
86 ASSERT_EQ(0, mGraphicBuffer->lock(mGraphicBuffer->getUsage(), &bufferData));
87 ReadbackHelper::compareColorBuffers(expectedColors, bufferData, mGraphicBuffer->getStride(),
88 mGraphicBuffer->getWidth(), mGraphicBuffer->getHeight(),
89 mFormat);
90 ASSERT_EQ(0, mGraphicBuffer->unlock());
91}
92
93} // namespace vts
94} // namespace V2_2
95} // namespace composer
96} // namespace graphics
97} // namespace hardware
98} // namespace android