blob: d910169bfb582abbc27fb6d5a4922eaf9aa54703 [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;
29
30TestRenderEngine::TestRenderEngine(common::V1_1::PixelFormat hwcFormat,
31 uint32_t renderEngineFeatures) {
32 mFormat = hwcFormat;
33 mRenderEngine = renderengine::RenderEngine::create(
34 static_cast<int32_t>(mFormat), renderEngineFeatures, mMaxFrameBufferAcquireBuffers);
35}
36
37void TestRenderEngine::setRenderLayers(std::vector<std::shared_ptr<TestLayer>> layers) {
38 sort(layers.begin(), layers.end(),
39 [](const std::shared_ptr<TestLayer>& lhs, const std::shared_ptr<TestLayer>& rhs) -> bool {
40 return lhs->mZOrder < rhs->mZOrder;
41 });
42
43 if (!mCompositionLayers.empty()) {
44 mCompositionLayers.clear();
45 }
46 for (auto& layer : layers) {
47 LayerSettings settings = layer->toRenderEngineLayerSettings();
48 mCompositionLayers.push_back(settings);
49 }
50}
51
52void TestRenderEngine::initGraphicBuffer(uint32_t width, uint32_t height, uint32_t layerCount,
53 uint64_t usage) {
54 mGraphicBuffer =
55 new GraphicBuffer(width, height, static_cast<int32_t>(mFormat), layerCount, usage);
56}
57
58void TestRenderEngine::drawLayers() {
59 base::unique_fd bufferFence;
60 base::unique_fd readyFence;
61 mRenderEngine->drawLayers(mDisplaySettings, mCompositionLayers,
62 mGraphicBuffer->getNativeBuffer(), true, std::move(bufferFence),
63 &readyFence);
64 int fd = readyFence.release();
65 if (fd != -1) {
66 ASSERT_EQ(0, sync_wait(fd, -1));
67 ASSERT_EQ(0, close(fd));
68 }
69}
70
71void TestRenderEngine::checkColorBuffer(std::vector<V2_2::IComposerClient::Color>& expectedColors) {
72 void* bufferData;
73 ASSERT_EQ(0, mGraphicBuffer->lock(mGraphicBuffer->getUsage(), &bufferData));
74 ReadbackHelper::compareColorBuffers(expectedColors, bufferData, mGraphicBuffer->getStride(),
75 mGraphicBuffer->getWidth(), mGraphicBuffer->getHeight(),
76 mFormat);
77 ASSERT_EQ(0, mGraphicBuffer->unlock());
78}
79
80} // namespace vts
81} // namespace V2_2
82} // namespace composer
83} // namespace graphics
84} // namespace hardware
85} // namespace android