Marissa Wall | 6bd8bfd | 2016-12-15 12:25:31 -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 | #ifndef _HWC2_TEST_PROPERTIES_H |
| 18 | #define _HWC2_TEST_PROPERTIES_H |
| 19 | |
Marissa Wall | ffc67da | 2016-12-15 12:26:09 -0800 | [diff] [blame] | 20 | #include <array> |
Marissa Wall | 6bd8bfd | 2016-12-15 12:25:31 -0800 | [diff] [blame] | 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 | |
| 29 | enum class Hwc2TestCoverage { |
| 30 | Default = 0, |
| 31 | Basic, |
| 32 | Complete, |
| 33 | }; |
| 34 | |
| 35 | |
Marissa Wall | ffc67da | 2016-12-15 12:26:09 -0800 | [diff] [blame] | 36 | class Hwc2TestContainer { |
Marissa Wall | 6bd8bfd | 2016-12-15 12:25:31 -0800 | [diff] [blame] | 37 | public: |
Marissa Wall | ffc67da | 2016-12-15 12:26:09 -0800 | [diff] [blame] | 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 | |
| 51 | template <class T> |
| 52 | class Hwc2TestProperty : public Hwc2TestContainer { |
| 53 | public: |
| 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 | |
Marissa Wall | 6bd8bfd | 2016-12-15 12:25:31 -0800 | [diff] [blame] | 60 | Hwc2TestProperty(const std::vector<T>& list) |
| 61 | : mList(list) { } |
| 62 | |
Marissa Wall | ffc67da | 2016-12-15 12:26:09 -0800 | [diff] [blame] | 63 | void reset() override |
Marissa Wall | 6bd8bfd | 2016-12-15 12:25:31 -0800 | [diff] [blame] | 64 | { |
| 65 | mListIdx = 0; |
| 66 | } |
| 67 | |
Marissa Wall | ffc67da | 2016-12-15 12:26:09 -0800 | [diff] [blame] | 68 | bool advance() override |
Marissa Wall | 6bd8bfd | 2016-12-15 12:25:31 -0800 | [diff] [blame] | 69 | { |
| 70 | if (mListIdx + 1 < mList.size()) { |
| 71 | mListIdx++; |
| 72 | return true; |
| 73 | } |
| 74 | reset(); |
| 75 | return false; |
| 76 | } |
| 77 | |
Marissa Wall | ffc67da | 2016-12-15 12:26:09 -0800 | [diff] [blame] | 78 | T get() const |
Marissa Wall | 6bd8bfd | 2016-12-15 12:25:31 -0800 | [diff] [blame] | 79 | { |
| 80 | return mList.at(mListIdx); |
| 81 | } |
| 82 | |
Marissa Wall | 6bd8bfd | 2016-12-15 12:25:31 -0800 | [diff] [blame] | 83 | protected: |
| 84 | const std::vector<T>& mList; |
| 85 | size_t mListIdx = 0; |
| 86 | }; |
| 87 | |
| 88 | |
Marissa Wall | ffc67da | 2016-12-15 12:26:09 -0800 | [diff] [blame] | 89 | class Hwc2TestBlendMode : public Hwc2TestProperty<hwc2_blend_mode_t> { |
| 90 | public: |
| 91 | Hwc2TestBlendMode(Hwc2TestCoverage coverage); |
| 92 | |
| 93 | std::string dump() const override; |
| 94 | |
| 95 | protected: |
| 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 | |
Marissa Wall | 6bd8bfd | 2016-12-15 12:25:31 -0800 | [diff] [blame] | 102 | class Hwc2TestComposition : public Hwc2TestProperty<hwc2_composition_t> { |
| 103 | public: |
| 104 | Hwc2TestComposition(Hwc2TestCoverage coverage); |
| 105 | |
| 106 | std::string dump() const override; |
| 107 | |
| 108 | protected: |
| 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 | |
Marissa Wall | b72b5c9 | 2016-12-15 12:26:39 -0800 | [diff] [blame^] | 114 | |
| 115 | class Hwc2TestDataspace : public Hwc2TestProperty<android_dataspace_t> { |
| 116 | public: |
| 117 | Hwc2TestDataspace(Hwc2TestCoverage coverage); |
| 118 | |
| 119 | std::string dump() const override; |
| 120 | |
| 121 | protected: |
| 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 | |
Marissa Wall | 6bd8bfd | 2016-12-15 12:25:31 -0800 | [diff] [blame] | 127 | #endif /* ifndef _HWC2_TEST_PROPERTIES_H */ |