blob: d0bc68979b12261c05289006db84f95cad09265a [file] [log] [blame]
ramindanibab8ba92021-11-18 01:24:11 +00001/**
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
ramindani458e53e2022-02-23 17:30:16 +000017#include "RenderEngineVts.h"
Vishnu Nair59329712022-01-13 07:59:37 -080018#include "renderengine/impl/ExternalTexture.h"
ramindanibab8ba92021-11-18 01:24:11 +000019
20namespace aidl::android::hardware::graphics::composer3::vts {
21
22using ::android::hardware::graphics::mapper::V2_1::IMapper;
23using ::android::renderengine::DisplaySettings;
24using ::android::renderengine::LayerSettings;
25using ::android::renderengine::RenderEngineCreationArgs;
26
27TestRenderEngine::TestRenderEngine(const RenderEngineCreationArgs& args) {
28 mFormat = static_cast<common::PixelFormat>(args.pixelFormat);
29 mRenderEngine = ::android::renderengine::RenderEngine::create(args);
30}
31
Jason Macnak5eb07e32024-10-01 15:40:33 -070032TestRenderEngine::~TestRenderEngine() {}
ramindanibab8ba92021-11-18 01:24:11 +000033
34void TestRenderEngine::setRenderLayers(std::vector<std::shared_ptr<TestLayer>> layers) {
35 sort(layers.begin(), layers.end(),
36 [](const std::shared_ptr<TestLayer>& lhs, const std::shared_ptr<TestLayer>& rhs) -> bool {
37 return lhs->getZOrder() < rhs->getZOrder();
38 });
39
40 if (!mCompositionLayers.empty()) {
41 mCompositionLayers.clear();
42 }
43 for (auto& layer : layers) {
44 LayerSettings settings = layer->toRenderEngineLayerSettings();
45 mCompositionLayers.push_back(settings);
46 }
47}
48
49void TestRenderEngine::initGraphicBuffer(uint32_t width, uint32_t height, uint32_t layerCount,
50 uint64_t usage) {
51 mGraphicBuffer = ::android::sp<::android::GraphicBuffer>::make(
52 width, height, static_cast<int32_t>(mFormat), layerCount, usage);
53}
54
55void TestRenderEngine::drawLayers() {
56 ::android::base::unique_fd bufferFence;
57
58 std::vector<::android::renderengine::LayerSettings> compositionLayers;
59 compositionLayers.reserve(mCompositionLayers.size());
60 std::transform(mCompositionLayers.begin(), mCompositionLayers.end(),
61 std::back_insert_iterator(compositionLayers),
62 [](::android::renderengine::LayerSettings& settings)
63 -> ::android::renderengine::LayerSettings { return settings; });
Vishnu Nair59329712022-01-13 07:59:37 -080064 auto texture = std::make_shared<::android::renderengine::impl::ExternalTexture>(
ramindanibab8ba92021-11-18 01:24:11 +000065 mGraphicBuffer, *mRenderEngine,
Vishnu Nair59329712022-01-13 07:59:37 -080066 ::android::renderengine::impl::ExternalTexture::Usage::WRITEABLE);
Patrick Williamsaf78e0a2022-08-16 22:20:43 +000067 auto result = mRenderEngine
68 ->drawLayers(mDisplaySettings, compositionLayers, texture, true,
69 std::move(bufferFence))
70 .get();
71 if (result.ok()) {
72 result.value()->waitForever(LOG_TAG);
ramindanibab8ba92021-11-18 01:24:11 +000073 }
74}
75
Alec Mouri3e037cf2022-01-24 08:58:28 -080076void TestRenderEngine::checkColorBuffer(const std::vector<Color>& expectedColors) {
Brian Lindahle887a252023-01-17 14:54:19 -070077 void* bufferData;
78 int32_t bytesPerPixel = -1;
79 int32_t bytesPerStride = -1;
80 ASSERT_EQ(0, mGraphicBuffer->lock(static_cast<uint32_t>(mGraphicBuffer->getUsage()),
81 &bufferData, &bytesPerPixel, &bytesPerStride));
82 const uint32_t stride = (bytesPerPixel > 0 && bytesPerStride > 0)
83 ? static_cast<uint32_t>(bytesPerStride / bytesPerPixel)
84 : mGraphicBuffer->getStride();
85 ReadbackHelper::compareColorBuffers(expectedColors, bufferData, stride,
86 mGraphicBuffer->getWidth(), mGraphicBuffer->getHeight(),
87 mFormat);
88 ASSERT_EQ(::android::OK, mGraphicBuffer->unlock());
ramindanibab8ba92021-11-18 01:24:11 +000089}
90
Ady Abraham3192f3d2021-12-03 16:08:56 -080091} // namespace aidl::android::hardware::graphics::composer3::vts