blob: e6cceb82ebc634e2e8c730deb01f7b923cab08a7 [file] [log] [blame]
Marissa Wallbad1bc72017-02-21 14:33:46 -08001/*
2 * Copyright (C) 2016 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 <sstream>
David Hanna Jr3f056022017-07-27 19:19:15 -070018#include <sys/stat.h>
Marissa Wallbad1bc72017-02-21 14:33:46 -080019
20#include "Hwc2TestVirtualDisplay.h"
21
David Hanna Jr3f056022017-07-27 19:19:15 -070022#define DIR_NAME "images"
23
Marissa Wallbad1bc72017-02-21 14:33:46 -080024Hwc2TestVirtualDisplay::Hwc2TestVirtualDisplay(
25 Hwc2TestCoverage coverage)
26 : mDisplayDimension(coverage)
27{
David Hanna Jr3f056022017-07-27 19:19:15 -070028 mDisplayDimension.setDependent(&mOutputBuffer);
29 mDisplayDimension.setDependent(&mExpectedBuffer);
Marissa Wallbad1bc72017-02-21 14:33:46 -080030}
31
32std::string Hwc2TestVirtualDisplay::dump() const
33{
34 std::stringstream dmp;
35
36 dmp << "virtual display: \n";
37
38 mDisplayDimension.dump();
39
40 return dmp.str();
41}
42
David Hanna Jr3f056022017-07-27 19:19:15 -070043int Hwc2TestVirtualDisplay::getOutputBuffer(buffer_handle_t* outHandle,
Marissa Wallbad1bc72017-02-21 14:33:46 -080044 android::base::unique_fd* outAcquireFence)
45{
46 int32_t acquireFence;
David Hanna Jr3f056022017-07-27 19:19:15 -070047 int ret = mOutputBuffer.getOutputBuffer(outHandle, &acquireFence);
Marissa Wallbad1bc72017-02-21 14:33:46 -080048 outAcquireFence->reset(acquireFence);
49 return ret;
50}
51
52void Hwc2TestVirtualDisplay::reset()
53{
54 return mDisplayDimension.reset();
55}
56
57bool Hwc2TestVirtualDisplay::advance()
58{
59 return mDisplayDimension.advance();
60}
61
62UnsignedArea Hwc2TestVirtualDisplay::getDisplayDimension() const
63{
64 return mDisplayDimension.get();
65}
David Hanna Jr3f056022017-07-27 19:19:15 -070066
67int Hwc2TestVirtualDisplay::verifyOutputBuffer(const Hwc2TestLayers* testLayers,
68 const std::vector<hwc2_layer_t>* allLayers,
69 const std::set<hwc2_layer_t>* clearLayers)
70{
71 int ret = mExpectedBuffer.generateExpectedBuffer(testLayers, allLayers,
72 clearLayers);
73 if (ret)
74 return ret;
75
76 ComparatorResult::get().CompareBuffers(mOutputBuffer.graphicBuffer(),
77 mExpectedBuffer.graphicBuffer());
78
79 return 0;
80}
81
82int Hwc2TestVirtualDisplay::writeBuffersToFile(std::string name)
83{
84 std::ostringstream expectedPath;
85 std::ostringstream resultPath;
86 int ret = mkdir(DIR_NAME, DEFFILEMODE);
87 if (ret && errno != EEXIST)
88 return ret;
89
90 expectedPath << DIR_NAME << "/expected-" << name << ".png";
91 resultPath << DIR_NAME << "/result-" << name << ".png";
92
93 if (!mExpectedBuffer.writeBufferToFile(expectedPath.str()) ||
94 !mOutputBuffer.writeBufferToFile(resultPath.str()))
95 return -1;
96
97 return 0;
98}