Marissa Wall | bad1bc7 | 2017-02-21 14:33:46 -0800 | [diff] [blame] | 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> |
David Hanna Jr | 3f05602 | 2017-07-27 19:19:15 -0700 | [diff] [blame^] | 18 | #include <sys/stat.h> |
Marissa Wall | bad1bc7 | 2017-02-21 14:33:46 -0800 | [diff] [blame] | 19 | |
| 20 | #include "Hwc2TestVirtualDisplay.h" |
| 21 | |
David Hanna Jr | 3f05602 | 2017-07-27 19:19:15 -0700 | [diff] [blame^] | 22 | #define DIR_NAME "images" |
| 23 | |
Marissa Wall | bad1bc7 | 2017-02-21 14:33:46 -0800 | [diff] [blame] | 24 | Hwc2TestVirtualDisplay::Hwc2TestVirtualDisplay( |
| 25 | Hwc2TestCoverage coverage) |
| 26 | : mDisplayDimension(coverage) |
| 27 | { |
David Hanna Jr | 3f05602 | 2017-07-27 19:19:15 -0700 | [diff] [blame^] | 28 | mDisplayDimension.setDependent(&mOutputBuffer); |
| 29 | mDisplayDimension.setDependent(&mExpectedBuffer); |
Marissa Wall | bad1bc7 | 2017-02-21 14:33:46 -0800 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | 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 | |
David Hanna Jr | 3f05602 | 2017-07-27 19:19:15 -0700 | [diff] [blame^] | 43 | int Hwc2TestVirtualDisplay::getOutputBuffer(buffer_handle_t* outHandle, |
Marissa Wall | bad1bc7 | 2017-02-21 14:33:46 -0800 | [diff] [blame] | 44 | android::base::unique_fd* outAcquireFence) |
| 45 | { |
| 46 | int32_t acquireFence; |
David Hanna Jr | 3f05602 | 2017-07-27 19:19:15 -0700 | [diff] [blame^] | 47 | int ret = mOutputBuffer.getOutputBuffer(outHandle, &acquireFence); |
Marissa Wall | bad1bc7 | 2017-02-21 14:33:46 -0800 | [diff] [blame] | 48 | outAcquireFence->reset(acquireFence); |
| 49 | return ret; |
| 50 | } |
| 51 | |
| 52 | void Hwc2TestVirtualDisplay::reset() |
| 53 | { |
| 54 | return mDisplayDimension.reset(); |
| 55 | } |
| 56 | |
| 57 | bool Hwc2TestVirtualDisplay::advance() |
| 58 | { |
| 59 | return mDisplayDimension.advance(); |
| 60 | } |
| 61 | |
| 62 | UnsignedArea Hwc2TestVirtualDisplay::getDisplayDimension() const |
| 63 | { |
| 64 | return mDisplayDimension.get(); |
| 65 | } |
David Hanna Jr | 3f05602 | 2017-07-27 19:19:15 -0700 | [diff] [blame^] | 66 | |
| 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 | |
| 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 | } |