blob: e2f267012f5e578a8ef6ed6b0a1d8c20d2f7044b [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
36void 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->mZOrder < rhs->mZOrder;
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
51void TestRenderEngine::initGraphicBuffer(uint32_t width, uint32_t height, uint32_t layerCount,
52 uint64_t usage) {
53 mGraphicBuffer =
54 new GraphicBuffer(width, height, static_cast<int32_t>(mFormat), layerCount, usage);
55}
56
57void TestRenderEngine::drawLayers() {
58 base::unique_fd bufferFence;
59 base::unique_fd readyFence;
60 mRenderEngine->drawLayers(mDisplaySettings, mCompositionLayers,
61 mGraphicBuffer->getNativeBuffer(), true, std::move(bufferFence),
62 &readyFence);
63 int fd = readyFence.release();
64 if (fd != -1) {
65 ASSERT_EQ(0, sync_wait(fd, -1));
66 ASSERT_EQ(0, close(fd));
67 }
68}
69
70void TestRenderEngine::checkColorBuffer(std::vector<V2_2::IComposerClient::Color>& expectedColors) {
71 void* bufferData;
72 ASSERT_EQ(0, mGraphicBuffer->lock(mGraphicBuffer->getUsage(), &bufferData));
73 ReadbackHelper::compareColorBuffers(expectedColors, bufferData, mGraphicBuffer->getStride(),
74 mGraphicBuffer->getWidth(), mGraphicBuffer->getHeight(),
75 mFormat);
76 ASSERT_EQ(0, mGraphicBuffer->unlock());
77}
78
79} // namespace vts
80} // namespace V2_2
81} // namespace composer
82} // namespace graphics
83} // namespace hardware
84} // namespace android