ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (c) 2021, 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 | |
ramindani | 458e53e | 2022-02-23 17:30:16 +0000 | [diff] [blame^] | 17 | #include "RenderEngineVts.h" |
Vishnu Nair | 5932971 | 2022-01-13 07:59:37 -0800 | [diff] [blame] | 18 | #include "renderengine/impl/ExternalTexture.h" |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 19 | |
| 20 | namespace aidl::android::hardware::graphics::composer3::vts { |
| 21 | |
| 22 | using ::android::hardware::graphics::mapper::V2_1::IMapper; |
| 23 | using ::android::renderengine::DisplaySettings; |
| 24 | using ::android::renderengine::LayerSettings; |
| 25 | using ::android::renderengine::RenderEngineCreationArgs; |
| 26 | |
| 27 | TestRenderEngine::TestRenderEngine(const RenderEngineCreationArgs& args) { |
| 28 | mFormat = static_cast<common::PixelFormat>(args.pixelFormat); |
| 29 | mRenderEngine = ::android::renderengine::RenderEngine::create(args); |
| 30 | } |
| 31 | |
| 32 | TestRenderEngine::~TestRenderEngine() { |
| 33 | mRenderEngine.release(); |
| 34 | } |
| 35 | |
| 36 | void TestRenderEngine::setRenderLayers(std::vector<std::shared_ptr<TestLayer>> layers) { |
| 37 | sort(layers.begin(), layers.end(), |
| 38 | [](const std::shared_ptr<TestLayer>& lhs, const std::shared_ptr<TestLayer>& rhs) -> bool { |
| 39 | return lhs->getZOrder() < rhs->getZOrder(); |
| 40 | }); |
| 41 | |
| 42 | if (!mCompositionLayers.empty()) { |
| 43 | mCompositionLayers.clear(); |
| 44 | } |
| 45 | for (auto& layer : layers) { |
| 46 | LayerSettings settings = layer->toRenderEngineLayerSettings(); |
| 47 | mCompositionLayers.push_back(settings); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | void TestRenderEngine::initGraphicBuffer(uint32_t width, uint32_t height, uint32_t layerCount, |
| 52 | uint64_t usage) { |
| 53 | mGraphicBuffer = ::android::sp<::android::GraphicBuffer>::make( |
| 54 | width, height, static_cast<int32_t>(mFormat), layerCount, usage); |
| 55 | } |
| 56 | |
| 57 | void TestRenderEngine::drawLayers() { |
| 58 | ::android::base::unique_fd bufferFence; |
| 59 | |
| 60 | std::vector<::android::renderengine::LayerSettings> compositionLayers; |
| 61 | compositionLayers.reserve(mCompositionLayers.size()); |
| 62 | std::transform(mCompositionLayers.begin(), mCompositionLayers.end(), |
| 63 | std::back_insert_iterator(compositionLayers), |
| 64 | [](::android::renderengine::LayerSettings& settings) |
| 65 | -> ::android::renderengine::LayerSettings { return settings; }); |
Vishnu Nair | 5932971 | 2022-01-13 07:59:37 -0800 | [diff] [blame] | 66 | auto texture = std::make_shared<::android::renderengine::impl::ExternalTexture>( |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 67 | mGraphicBuffer, *mRenderEngine, |
Vishnu Nair | 5932971 | 2022-01-13 07:59:37 -0800 | [diff] [blame] | 68 | ::android::renderengine::impl::ExternalTexture::Usage::WRITEABLE); |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 69 | auto [status, readyFence] = mRenderEngine |
| 70 | ->drawLayers(mDisplaySettings, compositionLayers, texture, |
| 71 | true, std::move(bufferFence)) |
| 72 | .get(); |
| 73 | int fd = readyFence.release(); |
| 74 | if (fd != -1) { |
| 75 | ASSERT_EQ(0, sync_wait(fd, -1)); |
| 76 | ASSERT_EQ(0, close(fd)); |
| 77 | } |
| 78 | } |
| 79 | |
Alec Mouri | 3e037cf | 2022-01-24 08:58:28 -0800 | [diff] [blame] | 80 | void TestRenderEngine::checkColorBuffer(const std::vector<Color>& expectedColors) { |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 81 | void* bufferData; |
Alec Mouri | 3e037cf | 2022-01-24 08:58:28 -0800 | [diff] [blame] | 82 | int32_t bytesPerPixel = -1; |
| 83 | int32_t bytesPerStride = -1; |
| 84 | ASSERT_EQ(0, mGraphicBuffer->lock(static_cast<uint32_t>(mGraphicBuffer->getUsage()), |
| 85 | &bufferData, &bytesPerPixel, &bytesPerStride)); |
| 86 | const uint32_t stride = (bytesPerPixel > 0 && bytesPerStride > 0) |
| 87 | ? static_cast<uint32_t>(bytesPerStride / bytesPerPixel) |
| 88 | : mGraphicBuffer->getStride(); |
| 89 | ReadbackHelper::compareColorBuffers(expectedColors, bufferData, stride, |
| 90 | mGraphicBuffer->getWidth(), mGraphicBuffer->getHeight(), |
| 91 | mFormat); |
ramindani | bab8ba9 | 2021-11-18 01:24:11 +0000 | [diff] [blame] | 92 | ASSERT_EQ(::android::OK, mGraphicBuffer->unlock()); |
| 93 | } |
| 94 | |
Ady Abraham | 3192f3d | 2021-12-03 16:08:56 -0800 | [diff] [blame] | 95 | } // namespace aidl::android::hardware::graphics::composer3::vts |