Hwc2TestProperties.h revision 2b1f53060ea8587a428f826cf7890354ff124722
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#ifndef _HWC2_TEST_PROPERTIES_H 18#define _HWC2_TEST_PROPERTIES_H 19 20#include <array> 21#include <vector> 22 23#define HWC2_INCLUDE_STRINGIFICATION 24#define HWC2_USE_CPP11 25#include <hardware/hwcomposer2.h> 26#undef HWC2_INCLUDE_STRINGIFICATION 27#undef HWC2_USE_CPP11 28 29enum class Hwc2TestCoverage { 30 Default = 0, 31 Basic, 32 Complete, 33}; 34 35 36class Hwc2TestContainer { 37public: 38 virtual ~Hwc2TestContainer() = default; 39 40 /* Resets the container */ 41 virtual void reset() = 0; 42 43 /* Attempts to advance to the next valid value. Returns true if one can be 44 * found */ 45 virtual bool advance() = 0; 46 47 virtual std::string dump() const = 0; 48}; 49 50 51template <class T> 52class Hwc2TestProperty : public Hwc2TestContainer { 53public: 54 Hwc2TestProperty(Hwc2TestCoverage coverage, 55 const std::vector<T>& completeList, const std::vector<T>& basicList, 56 const std::vector<T>& defaultList) 57 : Hwc2TestProperty((coverage == Hwc2TestCoverage::Complete)? completeList: 58 (coverage == Hwc2TestCoverage::Basic)? basicList : defaultList) { } 59 60 Hwc2TestProperty(const std::vector<T>& list) 61 : mList(list) { } 62 63 void reset() override 64 { 65 mListIdx = 0; 66 } 67 68 bool advance() override 69 { 70 if (mListIdx + 1 < mList.size()) { 71 mListIdx++; 72 return true; 73 } 74 reset(); 75 return false; 76 } 77 78 T get() const 79 { 80 return mList.at(mListIdx); 81 } 82 83protected: 84 const std::vector<T>& mList; 85 size_t mListIdx = 0; 86}; 87 88 89class Hwc2TestBlendMode : public Hwc2TestProperty<hwc2_blend_mode_t> { 90public: 91 Hwc2TestBlendMode(Hwc2TestCoverage coverage); 92 93 std::string dump() const override; 94 95protected: 96 static const std::vector<hwc2_blend_mode_t> mDefaultBlendModes; 97 static const std::vector<hwc2_blend_mode_t> mBasicBlendModes; 98 static const std::vector<hwc2_blend_mode_t> mCompleteBlendModes; 99}; 100 101 102class Hwc2TestComposition : public Hwc2TestProperty<hwc2_composition_t> { 103public: 104 Hwc2TestComposition(Hwc2TestCoverage coverage); 105 106 std::string dump() const override; 107 108protected: 109 static const std::vector<hwc2_composition_t> mDefaultCompositions; 110 static const std::vector<hwc2_composition_t> mBasicCompositions; 111 static const std::vector<hwc2_composition_t> mCompleteCompositions; 112}; 113 114 115class Hwc2TestDataspace : public Hwc2TestProperty<android_dataspace_t> { 116public: 117 Hwc2TestDataspace(Hwc2TestCoverage coverage); 118 119 std::string dump() const override; 120 121protected: 122 static const std::vector<android_dataspace_t> defaultDataspaces; 123 static const std::vector<android_dataspace_t> basicDataspaces; 124 static const std::vector<android_dataspace_t> completeDataspaces; 125}; 126 127 128class Hwc2TestPlaneAlpha : public Hwc2TestProperty<float> { 129public: 130 Hwc2TestPlaneAlpha(Hwc2TestCoverage coverage); 131 132 std::string dump() const override; 133 134protected: 135 static const std::vector<float> mDefaultPlaneAlphas; 136 static const std::vector<float> mBasicPlaneAlphas; 137 static const std::vector<float> mCompletePlaneAlphas; 138}; 139 140#endif /* ifndef _HWC2_TEST_PROPERTIES_H */ 141