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