Adam Bodnar | 5bf9dc6 | 2019-05-24 09:20:04 -0700 | [diff] [blame] | 1 | /* |
| 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 Nair | 5932971 | 2022-01-13 07:59:37 -0800 | [diff] [blame] | 18 | #include "renderengine/impl/ExternalTexture.h" |
Adam Bodnar | 5bf9dc6 | 2019-05-24 09:20:04 -0700 | [diff] [blame] | 19 | |
| 20 | namespace android { |
| 21 | namespace hardware { |
| 22 | namespace graphics { |
| 23 | namespace composer { |
| 24 | namespace V2_2 { |
| 25 | namespace vts { |
| 26 | |
| 27 | using mapper::V2_1::IMapper; |
| 28 | using renderengine::DisplaySettings; |
| 29 | using renderengine::LayerSettings; |
Chong Zhang | 86e1aeb | 2019-10-22 15:49:46 -0700 | [diff] [blame] | 30 | using renderengine::RenderEngineCreationArgs; |
Adam Bodnar | 5bf9dc6 | 2019-05-24 09:20:04 -0700 | [diff] [blame] | 31 | |
Chong Zhang | 86e1aeb | 2019-10-22 15:49:46 -0700 | [diff] [blame] | 32 | TestRenderEngine::TestRenderEngine(const RenderEngineCreationArgs& args) { |
| 33 | mFormat = static_cast<common::V1_1::PixelFormat>(args.pixelFormat); |
| 34 | mRenderEngine = renderengine::RenderEngine::create(args); |
Adam Bodnar | 5bf9dc6 | 2019-05-24 09:20:04 -0700 | [diff] [blame] | 35 | } |
| 36 | |
Adam Bodnar | 6c3929c | 2020-02-18 13:21:26 -0800 | [diff] [blame] | 37 | TestRenderEngine::~TestRenderEngine() { |
| 38 | mRenderEngine.release(); |
| 39 | } |
| 40 | |
Adam Bodnar | 5bf9dc6 | 2019-05-24 09:20:04 -0700 | [diff] [blame] | 41 | void 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 | |
| 56 | void 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 | |
| 62 | void TestRenderEngine::drawLayers() { |
| 63 | base::unique_fd bufferFence; |
Vishnu Nair | 02da997 | 2020-01-17 13:39:08 -0800 | [diff] [blame] | 64 | |
Sally Qi | d515dba | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 65 | std::vector<renderengine::LayerSettings> compositionLayers; |
| 66 | compositionLayers.reserve(mCompositionLayers.size()); |
Vishnu Nair | 02da997 | 2020-01-17 13:39:08 -0800 | [diff] [blame] | 67 | std::transform(mCompositionLayers.begin(), mCompositionLayers.end(), |
Sally Qi | d515dba | 2021-10-12 18:53:23 +0000 | [diff] [blame] | 68 | std::back_insert_iterator(compositionLayers), |
| 69 | [](renderengine::LayerSettings& settings) -> renderengine::LayerSettings { |
| 70 | return settings; |
Vishnu Nair | 02da997 | 2020-01-17 13:39:08 -0800 | [diff] [blame] | 71 | }); |
Vishnu Nair | 5932971 | 2022-01-13 07:59:37 -0800 | [diff] [blame] | 72 | auto texture = std::make_shared<renderengine::impl::ExternalTexture>( |
| 73 | mGraphicBuffer, *mRenderEngine, renderengine::impl::ExternalTexture::Usage::WRITEABLE); |
Patrick Williams | af78e0a | 2022-08-16 22:20:43 +0000 | [diff] [blame] | 74 | 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 Bodnar | 5bf9dc6 | 2019-05-24 09:20:04 -0700 | [diff] [blame] | 80 | } |
| 81 | } |
| 82 | |
| 83 | void TestRenderEngine::checkColorBuffer(std::vector<V2_2::IComposerClient::Color>& expectedColors) { |
| 84 | void* bufferData; |
| 85 | ASSERT_EQ(0, mGraphicBuffer->lock(mGraphicBuffer->getUsage(), &bufferData)); |
Brian Lindahl | e887a25 | 2023-01-17 14:54:19 -0700 | [diff] [blame] | 86 | ReadbackHelper::compareColorBuffers(expectedColors, bufferData, mGraphicBuffer->getStride(), |
| 87 | mGraphicBuffer->getWidth(), mGraphicBuffer->getHeight(), |
| 88 | mFormat); |
Adam Bodnar | 5bf9dc6 | 2019-05-24 09:20:04 -0700 | [diff] [blame] | 89 | 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 |