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