Hwc2TestProperties.h revision 563030b4402f4b9aa08cece732f2a4a756a0f72c
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 31enum class Hwc2TestCoverage { 32 Default = 0, 33 Basic, 34 Complete, 35}; 36 37enum 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 51typedef struct { 52 int32_t width; 53 int32_t height; 54} Area; 55 56 57class Hwc2TestContainer { 58public: 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; 69 70 /* Returns true if the container supports the given composition type */ 71 virtual bool isSupported(hwc2_composition_t composition) = 0; 72}; 73 74 75template <class T> 76class Hwc2TestProperty : public Hwc2TestContainer { 77public: 78 Hwc2TestProperty(Hwc2TestCoverage coverage, 79 const std::vector<T>& completeList, const std::vector<T>& basicList, 80 const std::vector<T>& defaultList, 81 const std::array<bool, 6>& compositionSupport) 82 : Hwc2TestProperty((coverage == Hwc2TestCoverage::Complete)? completeList: 83 (coverage == Hwc2TestCoverage::Basic)? basicList : defaultList, 84 compositionSupport) { } 85 86 Hwc2TestProperty(const std::vector<T>& list, 87 const std::array<bool, 6>& compositionSupport) 88 : mList(list), 89 mCompositionSupport(compositionSupport) { } 90 91 void reset() override 92 { 93 mListIdx = 0; 94 } 95 96 bool advance() override 97 { 98 if (mListIdx + 1 < mList.size()) { 99 mListIdx++; 100 updateDependents(); 101 return true; 102 } 103 reset(); 104 updateDependents(); 105 return false; 106 } 107 108 T get() const 109 { 110 return mList.at(mListIdx); 111 } 112 113 virtual bool isSupported(hwc2_composition_t composition) 114 { 115 return mCompositionSupport.at(composition); 116 } 117 118protected: 119 /* If a derived class has dependents, override this function */ 120 virtual void updateDependents() { } 121 122 const std::vector<T>& mList; 123 size_t mListIdx = 0; 124 125 const std::array<bool, 6>& mCompositionSupport; 126}; 127 128class Hwc2TestBuffer; 129class Hwc2TestSourceCrop; 130class Hwc2TestSurfaceDamage; 131 132class Hwc2TestBufferArea : public Hwc2TestProperty<Area> { 133public: 134 Hwc2TestBufferArea(Hwc2TestCoverage coverage, const Area& displayArea); 135 136 std::string dump() const override; 137 138 void setDependent(Hwc2TestBuffer* buffer); 139 void setDependent(Hwc2TestSourceCrop* sourceCrop); 140 void setDependent(Hwc2TestSurfaceDamage* surfaceDamage); 141 142protected: 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 153 Hwc2TestBuffer* mBuffer = nullptr; 154 Hwc2TestSourceCrop* mSourceCrop = nullptr; 155 Hwc2TestSurfaceDamage* mSurfaceDamage = nullptr; 156 157 std::vector<Area> mBufferAreas; 158 159 static const std::array<bool, 6> mCompositionSupport; 160}; 161 162 163class Hwc2TestColor; 164 165class Hwc2TestBlendMode : public Hwc2TestProperty<hwc2_blend_mode_t> { 166public: 167 Hwc2TestBlendMode(Hwc2TestCoverage coverage); 168 169 std::string dump() const override; 170 171 void setDependent(Hwc2TestColor* color); 172 173protected: 174 void updateDependents() override; 175 176 Hwc2TestColor* mColor = nullptr; 177 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; 181 182 static const std::array<bool, 6> mCompositionSupport; 183}; 184 185 186class Hwc2TestColor : public Hwc2TestProperty<hwc_color_t> { 187public: 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 195protected: 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; 206 207 static const std::array<bool, 6> mCompositionSupport; 208}; 209 210 211class Hwc2TestComposition : public Hwc2TestProperty<hwc2_composition_t> { 212public: 213 Hwc2TestComposition(Hwc2TestCoverage coverage); 214 215 std::string dump() const override; 216 217protected: 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; 221 222 static const std::array<bool, 6> mCompositionSupport; 223}; 224 225 226class Hwc2TestDataspace : public Hwc2TestProperty<android_dataspace_t> { 227public: 228 Hwc2TestDataspace(Hwc2TestCoverage coverage); 229 230 std::string dump() const override; 231 232protected: 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; 236 237 static const std::array<bool, 6> mCompositionSupport; 238}; 239 240 241class Hwc2TestDisplayFrame : public Hwc2TestProperty<hwc_rect_t> { 242public: 243 Hwc2TestDisplayFrame(Hwc2TestCoverage coverage, const Area& displayArea); 244 245 std::string dump() const override; 246 247protected: 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; 258 259 static const std::array<bool, 6> mCompositionSupport; 260}; 261 262 263class Hwc2TestPlaneAlpha : public Hwc2TestProperty<float> { 264public: 265 Hwc2TestPlaneAlpha(Hwc2TestCoverage coverage); 266 267 std::string dump() const override; 268 269protected: 270 static const std::vector<float> mDefaultPlaneAlphas; 271 static const std::vector<float> mBasicPlaneAlphas; 272 static const std::vector<float> mCompletePlaneAlphas; 273 274 static const std::array<bool, 6> mCompositionSupport; 275}; 276 277 278class Hwc2TestSourceCrop : public Hwc2TestProperty<hwc_frect_t> { 279public: 280 Hwc2TestSourceCrop(Hwc2TestCoverage coverage, const Area& bufferArea = {0, 0}); 281 282 std::string dump() const override; 283 284 void updateBufferArea(const Area& bufferArea); 285 286protected: 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; 297 298 static const std::array<bool, 6> mCompositionSupport; 299}; 300 301 302class Hwc2TestSurfaceDamage : public Hwc2TestProperty<hwc_region_t> { 303public: 304 Hwc2TestSurfaceDamage(Hwc2TestCoverage coverage); 305 ~Hwc2TestSurfaceDamage(); 306 307 std::string dump() const override; 308 309 void updateBufferArea(const Area& bufferArea); 310 311protected: 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; 323 324 static const std::array<bool, 6> mCompositionSupport; 325}; 326 327 328class Hwc2TestTransform : public Hwc2TestProperty<hwc_transform_t> { 329public: 330 Hwc2TestTransform(Hwc2TestCoverage coverage); 331 332 std::string dump() const override; 333 334protected: 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; 338 339 static const std::array<bool, 6> mCompositionSupport; 340}; 341 342 343class Hwc2TestVisibleRegion { 344public: 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 353protected: 354 hwc_region_t mVisibleRegion = {0, nullptr}; 355}; 356 357#endif /* ifndef _HWC2_TEST_PROPERTIES_H */ 358