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