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 | |
Marissa Wall | 600a73b | 2016-12-15 12:30:39 -0800 | [diff] [blame] | 35 | typedef struct { |
| 36 | int32_t width; |
| 37 | int32_t height; |
| 38 | } Area; |
| 39 | |
Marissa Wall | 6bd8bfd | 2016-12-15 12:25:31 -0800 | [diff] [blame] | 40 | |
Marissa Wall | ffc67da | 2016-12-15 12:26:09 -0800 | [diff] [blame] | 41 | class Hwc2TestContainer { |
Marissa Wall | 6bd8bfd | 2016-12-15 12:25:31 -0800 | [diff] [blame] | 42 | public: |
Marissa Wall | ffc67da | 2016-12-15 12:26:09 -0800 | [diff] [blame] | 43 | virtual ~Hwc2TestContainer() = default; |
| 44 | |
| 45 | /* Resets the container */ |
| 46 | virtual void reset() = 0; |
| 47 | |
| 48 | /* Attempts to advance to the next valid value. Returns true if one can be |
| 49 | * found */ |
| 50 | virtual bool advance() = 0; |
| 51 | |
| 52 | virtual std::string dump() const = 0; |
| 53 | }; |
| 54 | |
| 55 | |
| 56 | template <class T> |
| 57 | class Hwc2TestProperty : public Hwc2TestContainer { |
| 58 | public: |
| 59 | Hwc2TestProperty(Hwc2TestCoverage coverage, |
| 60 | const std::vector<T>& completeList, const std::vector<T>& basicList, |
| 61 | const std::vector<T>& defaultList) |
| 62 | : Hwc2TestProperty((coverage == Hwc2TestCoverage::Complete)? completeList: |
| 63 | (coverage == Hwc2TestCoverage::Basic)? basicList : defaultList) { } |
| 64 | |
Marissa Wall | 6bd8bfd | 2016-12-15 12:25:31 -0800 | [diff] [blame] | 65 | Hwc2TestProperty(const std::vector<T>& list) |
| 66 | : mList(list) { } |
| 67 | |
Marissa Wall | ffc67da | 2016-12-15 12:26:09 -0800 | [diff] [blame] | 68 | void reset() override |
Marissa Wall | 6bd8bfd | 2016-12-15 12:25:31 -0800 | [diff] [blame] | 69 | { |
| 70 | mListIdx = 0; |
| 71 | } |
| 72 | |
Marissa Wall | ffc67da | 2016-12-15 12:26:09 -0800 | [diff] [blame] | 73 | bool advance() override |
Marissa Wall | 6bd8bfd | 2016-12-15 12:25:31 -0800 | [diff] [blame] | 74 | { |
| 75 | if (mListIdx + 1 < mList.size()) { |
| 76 | mListIdx++; |
Marissa Wall | c57468f | 2016-12-15 12:31:12 -0800 | [diff] [blame] | 77 | updateDependents(); |
Marissa Wall | 6bd8bfd | 2016-12-15 12:25:31 -0800 | [diff] [blame] | 78 | return true; |
| 79 | } |
| 80 | reset(); |
Marissa Wall | c57468f | 2016-12-15 12:31:12 -0800 | [diff] [blame] | 81 | updateDependents(); |
Marissa Wall | 6bd8bfd | 2016-12-15 12:25:31 -0800 | [diff] [blame] | 82 | return false; |
| 83 | } |
| 84 | |
Marissa Wall | ffc67da | 2016-12-15 12:26:09 -0800 | [diff] [blame] | 85 | T get() const |
Marissa Wall | 6bd8bfd | 2016-12-15 12:25:31 -0800 | [diff] [blame] | 86 | { |
| 87 | return mList.at(mListIdx); |
| 88 | } |
| 89 | |
Marissa Wall | 6bd8bfd | 2016-12-15 12:25:31 -0800 | [diff] [blame] | 90 | protected: |
Marissa Wall | c57468f | 2016-12-15 12:31:12 -0800 | [diff] [blame] | 91 | /* If a derived class has dependents, override this function */ |
| 92 | virtual void updateDependents() { } |
| 93 | |
Marissa Wall | 6bd8bfd | 2016-12-15 12:25:31 -0800 | [diff] [blame] | 94 | const std::vector<T>& mList; |
| 95 | size_t mListIdx = 0; |
| 96 | }; |
| 97 | |
| 98 | |
Marissa Wall | c57468f | 2016-12-15 12:31:12 -0800 | [diff] [blame] | 99 | class Hwc2TestSourceCrop; |
| 100 | |
| 101 | class Hwc2TestBufferArea : public Hwc2TestProperty<Area> { |
| 102 | public: |
| 103 | Hwc2TestBufferArea(Hwc2TestCoverage coverage, const Area& displayArea); |
| 104 | |
| 105 | std::string dump() const override; |
| 106 | |
| 107 | void setDependent(Hwc2TestSourceCrop* sourceCrop); |
| 108 | |
| 109 | protected: |
| 110 | void update(); |
| 111 | void updateDependents() override; |
| 112 | |
| 113 | const std::vector<float>& mScalars; |
| 114 | static const std::vector<float> mDefaultScalars; |
| 115 | static const std::vector<float> mBasicScalars; |
| 116 | static const std::vector<float> mCompleteScalars; |
| 117 | |
| 118 | Area mDisplayArea; |
| 119 | |
| 120 | Hwc2TestSourceCrop* mSourceCrop = nullptr; |
| 121 | |
| 122 | std::vector<Area> mBufferAreas; |
| 123 | }; |
| 124 | |
| 125 | |
Marissa Wall | ee24278 | 2016-12-15 12:30:12 -0800 | [diff] [blame^] | 126 | class Hwc2TestColor; |
| 127 | |
Marissa Wall | ffc67da | 2016-12-15 12:26:09 -0800 | [diff] [blame] | 128 | class Hwc2TestBlendMode : public Hwc2TestProperty<hwc2_blend_mode_t> { |
| 129 | public: |
| 130 | Hwc2TestBlendMode(Hwc2TestCoverage coverage); |
| 131 | |
| 132 | std::string dump() const override; |
| 133 | |
Marissa Wall | ee24278 | 2016-12-15 12:30:12 -0800 | [diff] [blame^] | 134 | void setDependent(Hwc2TestColor* color); |
| 135 | |
Marissa Wall | ffc67da | 2016-12-15 12:26:09 -0800 | [diff] [blame] | 136 | protected: |
Marissa Wall | ee24278 | 2016-12-15 12:30:12 -0800 | [diff] [blame^] | 137 | void updateDependents() override; |
| 138 | |
| 139 | Hwc2TestColor* mColor = nullptr; |
| 140 | |
Marissa Wall | ffc67da | 2016-12-15 12:26:09 -0800 | [diff] [blame] | 141 | static const std::vector<hwc2_blend_mode_t> mDefaultBlendModes; |
| 142 | static const std::vector<hwc2_blend_mode_t> mBasicBlendModes; |
| 143 | static const std::vector<hwc2_blend_mode_t> mCompleteBlendModes; |
| 144 | }; |
| 145 | |
| 146 | |
Marissa Wall | ee24278 | 2016-12-15 12:30:12 -0800 | [diff] [blame^] | 147 | class Hwc2TestColor : public Hwc2TestProperty<hwc_color_t> { |
| 148 | public: |
| 149 | Hwc2TestColor(Hwc2TestCoverage coverage, |
| 150 | hwc2_blend_mode_t blendMode = HWC2_BLEND_MODE_NONE); |
| 151 | |
| 152 | std::string dump() const override; |
| 153 | |
| 154 | void updateBlendMode(hwc2_blend_mode_t blendMode); |
| 155 | |
| 156 | protected: |
| 157 | void update(); |
| 158 | |
| 159 | std::vector<hwc_color_t> mBaseColors; |
| 160 | static const std::vector<hwc_color_t> mDefaultBaseColors; |
| 161 | static const std::vector<hwc_color_t> mBasicBaseColors; |
| 162 | static const std::vector<hwc_color_t> mCompleteBaseColors; |
| 163 | |
| 164 | hwc2_blend_mode_t mBlendMode; |
| 165 | |
| 166 | std::vector<hwc_color_t> mColors; |
| 167 | }; |
| 168 | |
| 169 | |
Marissa Wall | 6bd8bfd | 2016-12-15 12:25:31 -0800 | [diff] [blame] | 170 | class Hwc2TestComposition : public Hwc2TestProperty<hwc2_composition_t> { |
| 171 | public: |
| 172 | Hwc2TestComposition(Hwc2TestCoverage coverage); |
| 173 | |
| 174 | std::string dump() const override; |
| 175 | |
| 176 | protected: |
| 177 | static const std::vector<hwc2_composition_t> mDefaultCompositions; |
| 178 | static const std::vector<hwc2_composition_t> mBasicCompositions; |
| 179 | static const std::vector<hwc2_composition_t> mCompleteCompositions; |
| 180 | }; |
| 181 | |
Marissa Wall | b72b5c9 | 2016-12-15 12:26:39 -0800 | [diff] [blame] | 182 | |
| 183 | class Hwc2TestDataspace : public Hwc2TestProperty<android_dataspace_t> { |
| 184 | public: |
| 185 | Hwc2TestDataspace(Hwc2TestCoverage coverage); |
| 186 | |
| 187 | std::string dump() const override; |
| 188 | |
| 189 | protected: |
| 190 | static const std::vector<android_dataspace_t> defaultDataspaces; |
| 191 | static const std::vector<android_dataspace_t> basicDataspaces; |
| 192 | static const std::vector<android_dataspace_t> completeDataspaces; |
| 193 | }; |
| 194 | |
Marissa Wall | 2b1f530 | 2016-12-15 12:27:20 -0800 | [diff] [blame] | 195 | |
Marissa Wall | 600a73b | 2016-12-15 12:30:39 -0800 | [diff] [blame] | 196 | class Hwc2TestDisplayFrame : public Hwc2TestProperty<hwc_rect_t> { |
| 197 | public: |
| 198 | Hwc2TestDisplayFrame(Hwc2TestCoverage coverage, const Area& displayArea); |
| 199 | |
| 200 | std::string dump() const override; |
| 201 | |
| 202 | protected: |
| 203 | void update(); |
| 204 | |
| 205 | const std::vector<hwc_frect_t>& mFrectScalars; |
| 206 | const static std::vector<hwc_frect_t> mDefaultFrectScalars; |
| 207 | const static std::vector<hwc_frect_t> mBasicFrectScalars; |
| 208 | const static std::vector<hwc_frect_t> mCompleteFrectScalars; |
| 209 | |
| 210 | Area mDisplayArea; |
| 211 | |
| 212 | std::vector<hwc_rect_t> mDisplayFrames; |
| 213 | }; |
| 214 | |
| 215 | |
Marissa Wall | 2b1f530 | 2016-12-15 12:27:20 -0800 | [diff] [blame] | 216 | class Hwc2TestPlaneAlpha : public Hwc2TestProperty<float> { |
| 217 | public: |
| 218 | Hwc2TestPlaneAlpha(Hwc2TestCoverage coverage); |
| 219 | |
| 220 | std::string dump() const override; |
| 221 | |
| 222 | protected: |
| 223 | static const std::vector<float> mDefaultPlaneAlphas; |
| 224 | static const std::vector<float> mBasicPlaneAlphas; |
| 225 | static const std::vector<float> mCompletePlaneAlphas; |
| 226 | }; |
| 227 | |
Marissa Wall | ac10819 | 2016-12-15 12:27:48 -0800 | [diff] [blame] | 228 | |
Marissa Wall | c57468f | 2016-12-15 12:31:12 -0800 | [diff] [blame] | 229 | class Hwc2TestSourceCrop : public Hwc2TestProperty<hwc_frect_t> { |
| 230 | public: |
| 231 | Hwc2TestSourceCrop(Hwc2TestCoverage coverage, const Area& bufferArea = {0, 0}); |
| 232 | |
| 233 | std::string dump() const override; |
| 234 | |
| 235 | void updateBufferArea(const Area& bufferArea); |
| 236 | |
| 237 | protected: |
| 238 | void update(); |
| 239 | |
| 240 | const std::vector<hwc_frect_t>& mFrectScalars; |
| 241 | const static std::vector<hwc_frect_t> mDefaultFrectScalars; |
| 242 | const static std::vector<hwc_frect_t> mBasicFrectScalars; |
| 243 | const static std::vector<hwc_frect_t> mCompleteFrectScalars; |
| 244 | |
| 245 | Area mBufferArea; |
| 246 | |
| 247 | std::vector<hwc_frect_t> mSourceCrops; |
| 248 | }; |
| 249 | |
| 250 | |
Marissa Wall | ac10819 | 2016-12-15 12:27:48 -0800 | [diff] [blame] | 251 | class Hwc2TestTransform : public Hwc2TestProperty<hwc_transform_t> { |
| 252 | public: |
| 253 | Hwc2TestTransform(Hwc2TestCoverage coverage); |
| 254 | |
| 255 | std::string dump() const override; |
| 256 | |
| 257 | protected: |
| 258 | static const std::vector<hwc_transform_t> mDefaultTransforms; |
| 259 | static const std::vector<hwc_transform_t> mBasicTransforms; |
| 260 | static const std::vector<hwc_transform_t> mCompleteTransforms; |
| 261 | }; |
| 262 | |
Marissa Wall | 6bd8bfd | 2016-12-15 12:25:31 -0800 | [diff] [blame] | 263 | #endif /* ifndef _HWC2_TEST_PROPERTIES_H */ |