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