• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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>
18 #include <sys/stat.h>
19 
20 #include "Hwc2TestVirtualDisplay.h"
21 
22 #define DIR_NAME "images"
23 
Hwc2TestVirtualDisplay(Hwc2TestCoverage coverage)24 Hwc2TestVirtualDisplay::Hwc2TestVirtualDisplay(
25         Hwc2TestCoverage coverage)
26     : mDisplayDimension(coverage)
27 {
28     mDisplayDimension.setDependent(&mOutputBuffer);
29     mDisplayDimension.setDependent(&mExpectedBuffer);
30 }
31 
dump() const32 std::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 
getOutputBuffer(buffer_handle_t * outHandle,android::base::unique_fd * outAcquireFence)43 int Hwc2TestVirtualDisplay::getOutputBuffer(buffer_handle_t* outHandle,
44         android::base::unique_fd* outAcquireFence)
45 {
46     int32_t acquireFence;
47     int ret = mOutputBuffer.getOutputBuffer(outHandle, &acquireFence);
48     outAcquireFence->reset(acquireFence);
49     return ret;
50 }
51 
reset()52 void Hwc2TestVirtualDisplay::reset()
53 {
54     return mDisplayDimension.reset();
55 }
56 
advance()57 bool Hwc2TestVirtualDisplay::advance()
58 {
59     return mDisplayDimension.advance();
60 }
61 
getDisplayDimension() const62 UnsignedArea Hwc2TestVirtualDisplay::getDisplayDimension() const
63 {
64     return mDisplayDimension.get();
65 }
66 
verifyOutputBuffer(const Hwc2TestLayers * testLayers,const std::vector<hwc2_layer_t> * allLayers,const std::set<hwc2_layer_t> * clearLayers)67 int 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 
writeBuffersToFile(std::string name)82 int 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 }
99