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