blob: 1700b2ade97c65816994e2a1f87be82bde2ed2ae [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>
Vishnu Nair59329712022-01-13 07:59:37 -080018#include "renderengine/impl/ExternalTexture.h"
Adam Bodnar5bf9dc62019-05-24 09:20:04 -070019
20namespace android {
21namespace hardware {
22namespace graphics {
23namespace composer {
24namespace V2_2 {
25namespace vts {
26
27using mapper::V2_1::IMapper;
28using renderengine::DisplaySettings;
29using renderengine::LayerSettings;
Chong Zhang86e1aeb2019-10-22 15:49:46 -070030using renderengine::RenderEngineCreationArgs;
Adam Bodnar5bf9dc62019-05-24 09:20:04 -070031
Chong Zhang86e1aeb2019-10-22 15:49:46 -070032TestRenderEngine::TestRenderEngine(const RenderEngineCreationArgs& args) {
33 mFormat = static_cast<common::V1_1::PixelFormat>(args.pixelFormat);
34 mRenderEngine = renderengine::RenderEngine::create(args);
Adam Bodnar5bf9dc62019-05-24 09:20:04 -070035}
36
Adam Bodnar6c3929c2020-02-18 13:21:26 -080037TestRenderEngine::~TestRenderEngine() {
38 mRenderEngine.release();
39}
40
Adam Bodnar5bf9dc62019-05-24 09:20:04 -070041void TestRenderEngine::setRenderLayers(std::vector<std::shared_ptr<TestLayer>> layers) {
42 sort(layers.begin(), layers.end(),
43 [](const std::shared_ptr<TestLayer>& lhs, const std::shared_ptr<TestLayer>& rhs) -> bool {
44 return lhs->mZOrder < rhs->mZOrder;
45 });
46
47 if (!mCompositionLayers.empty()) {
48 mCompositionLayers.clear();
49 }
50 for (auto& layer : layers) {
51 LayerSettings settings = layer->toRenderEngineLayerSettings();
52 mCompositionLayers.push_back(settings);
53 }
54}
55
56void TestRenderEngine::initGraphicBuffer(uint32_t width, uint32_t height, uint32_t layerCount,
57 uint64_t usage) {
58 mGraphicBuffer =
59 new GraphicBuffer(width, height, static_cast<int32_t>(mFormat), layerCount, usage);
60}
61
62void TestRenderEngine::drawLayers() {
63 base::unique_fd bufferFence;
Vishnu Nair02da9972020-01-17 13:39:08 -080064
Sally Qid515dba2021-10-12 18:53:23 +000065 std::vector<renderengine::LayerSettings> compositionLayers;
66 compositionLayers.reserve(mCompositionLayers.size());
Vishnu Nair02da9972020-01-17 13:39:08 -080067 std::transform(mCompositionLayers.begin(), mCompositionLayers.end(),
Sally Qid515dba2021-10-12 18:53:23 +000068 std::back_insert_iterator(compositionLayers),
69 [](renderengine::LayerSettings& settings) -> renderengine::LayerSettings {
70 return settings;
Vishnu Nair02da9972020-01-17 13:39:08 -080071 });
Vishnu Nair59329712022-01-13 07:59:37 -080072 auto texture = std::make_shared<renderengine::impl::ExternalTexture>(
73 mGraphicBuffer, *mRenderEngine, renderengine::impl::ExternalTexture::Usage::WRITEABLE);
Patrick Williamsaf78e0a2022-08-16 22:20:43 +000074 auto result = mRenderEngine
75 ->drawLayers(mDisplaySettings, compositionLayers, texture, true,
76 std::move(bufferFence))
77 .get();
78 if (result.ok()) {
79 result.value()->waitForever(LOG_TAG);
Adam Bodnar5bf9dc62019-05-24 09:20:04 -070080 }
81}
82
83void TestRenderEngine::checkColorBuffer(std::vector<V2_2::IComposerClient::Color>& expectedColors) {
84 void* bufferData;
85 ASSERT_EQ(0, mGraphicBuffer->lock(mGraphicBuffer->getUsage(), &bufferData));
Brian Lindahle887a252023-01-17 14:54:19 -070086 ReadbackHelper::compareColorBuffers(expectedColors, bufferData, mGraphicBuffer->getStride(),
87 mGraphicBuffer->getWidth(), mGraphicBuffer->getHeight(),
88 mFormat);
Adam Bodnar5bf9dc62019-05-24 09:20:04 -070089 ASSERT_EQ(0, mGraphicBuffer->unlock());
90}
91
92} // namespace vts
93} // namespace V2_2
94} // namespace composer
95} // namespace graphics
96} // namespace hardware
97} // namespace android