blob: 06ae314899df0c26415917c4dd741d82446aac07 [file] [log] [blame]
Marissa Wall6bd8bfd2016-12-15 12:25:31 -08001/*
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 Wallffc67da2016-12-15 12:26:09 -080020#include <array>
Marissa Wall6bd8bfd2016-12-15 12:25:31 -080021#include <vector>
22
Peiyong Lin34beb7a2018-03-28 11:57:12 -070023#include <ui/GraphicTypes.h>
Marissa Wallf7618ed2016-12-15 12:34:39 -080024#include <ui/Region.h>
25
Marissa Wall6bd8bfd2016-12-15 12:25:31 -080026#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
32enum class Hwc2TestCoverage {
33 Default = 0,
34 Basic,
35 Complete,
36};
37
Marissa Wall563030b2017-02-21 14:01:05 -080038enum 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
Marissa Wall600a73b2016-12-15 12:30:39 -080052typedef struct {
53 int32_t width;
54 int32_t height;
55} Area;
56
Marissa Wall6bd8bfd2016-12-15 12:25:31 -080057
Marissa Wallbad1bc72017-02-21 14:33:46 -080058typedef struct {
59 uint32_t width;
60 uint32_t height;
61} UnsignedArea;
62
63
Marissa Wallffc67da2016-12-15 12:26:09 -080064class Hwc2TestContainer {
Marissa Wall6bd8bfd2016-12-15 12:25:31 -080065public:
Marissa Wallffc67da2016-12-15 12:26:09 -080066 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;
Marissa Wall1cd789c2017-01-27 12:55:36 -080076
77 /* Returns true if the container supports the given composition type */
78 virtual bool isSupported(hwc2_composition_t composition) = 0;
Marissa Wallffc67da2016-12-15 12:26:09 -080079};
80
81
82template <class T>
83class Hwc2TestProperty : public Hwc2TestContainer {
84public:
85 Hwc2TestProperty(Hwc2TestCoverage coverage,
86 const std::vector<T>& completeList, const std::vector<T>& basicList,
Marissa Wall1cd789c2017-01-27 12:55:36 -080087 const std::vector<T>& defaultList,
88 const std::array<bool, 6>& compositionSupport)
Marissa Wallffc67da2016-12-15 12:26:09 -080089 : Hwc2TestProperty((coverage == Hwc2TestCoverage::Complete)? completeList:
Marissa Wall1cd789c2017-01-27 12:55:36 -080090 (coverage == Hwc2TestCoverage::Basic)? basicList : defaultList,
91 compositionSupport) { }
Marissa Wallffc67da2016-12-15 12:26:09 -080092
Marissa Wall1cd789c2017-01-27 12:55:36 -080093 Hwc2TestProperty(const std::vector<T>& list,
94 const std::array<bool, 6>& compositionSupport)
95 : mList(list),
96 mCompositionSupport(compositionSupport) { }
Marissa Wall6bd8bfd2016-12-15 12:25:31 -080097
Marissa Wallffc67da2016-12-15 12:26:09 -080098 void reset() override
Marissa Wall6bd8bfd2016-12-15 12:25:31 -080099 {
100 mListIdx = 0;
101 }
102
Marissa Wallffc67da2016-12-15 12:26:09 -0800103 bool advance() override
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800104 {
105 if (mListIdx + 1 < mList.size()) {
106 mListIdx++;
Marissa Wallc57468f2016-12-15 12:31:12 -0800107 updateDependents();
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800108 return true;
109 }
110 reset();
Marissa Wallc57468f2016-12-15 12:31:12 -0800111 updateDependents();
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800112 return false;
113 }
114
Marissa Wallffc67da2016-12-15 12:26:09 -0800115 T get() const
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800116 {
117 return mList.at(mListIdx);
118 }
119
Marissa Wall1cd789c2017-01-27 12:55:36 -0800120 virtual bool isSupported(hwc2_composition_t composition)
121 {
122 return mCompositionSupport.at(composition);
123 }
124
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800125protected:
Marissa Wallc57468f2016-12-15 12:31:12 -0800126 /* If a derived class has dependents, override this function */
127 virtual void updateDependents() { }
128
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800129 const std::vector<T>& mList;
130 size_t mListIdx = 0;
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800131
Marissa Wall1cd789c2017-01-27 12:55:36 -0800132 const std::array<bool, 6>& mCompositionSupport;
133};
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800134
Marissa Wall5a240aa2016-12-15 12:34:06 -0800135class Hwc2TestBuffer;
Marissa Wallc57468f2016-12-15 12:31:12 -0800136class Hwc2TestSourceCrop;
Marissa Wallad761812016-12-15 12:32:24 -0800137class Hwc2TestSurfaceDamage;
Marissa Wallc57468f2016-12-15 12:31:12 -0800138
139class Hwc2TestBufferArea : public Hwc2TestProperty<Area> {
140public:
141 Hwc2TestBufferArea(Hwc2TestCoverage coverage, const Area& displayArea);
142
143 std::string dump() const override;
144
Marissa Wall5a240aa2016-12-15 12:34:06 -0800145 void setDependent(Hwc2TestBuffer* buffer);
Marissa Wallc57468f2016-12-15 12:31:12 -0800146 void setDependent(Hwc2TestSourceCrop* sourceCrop);
Marissa Wallad761812016-12-15 12:32:24 -0800147 void setDependent(Hwc2TestSurfaceDamage* surfaceDamage);
Marissa Wallc57468f2016-12-15 12:31:12 -0800148
149protected:
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
Marissa Wall5a240aa2016-12-15 12:34:06 -0800160 Hwc2TestBuffer* mBuffer = nullptr;
Marissa Wallc57468f2016-12-15 12:31:12 -0800161 Hwc2TestSourceCrop* mSourceCrop = nullptr;
Marissa Wallad761812016-12-15 12:32:24 -0800162 Hwc2TestSurfaceDamage* mSurfaceDamage = nullptr;
Marissa Wallc57468f2016-12-15 12:31:12 -0800163
164 std::vector<Area> mBufferAreas;
Marissa Wall1cd789c2017-01-27 12:55:36 -0800165
166 static const std::array<bool, 6> mCompositionSupport;
Marissa Wallc57468f2016-12-15 12:31:12 -0800167};
168
169
Marissa Wallee242782016-12-15 12:30:12 -0800170class Hwc2TestColor;
171
Marissa Wallffc67da2016-12-15 12:26:09 -0800172class Hwc2TestBlendMode : public Hwc2TestProperty<hwc2_blend_mode_t> {
173public:
Chih-Hung Hsieh22749042018-12-20 15:50:39 -0800174 explicit Hwc2TestBlendMode(Hwc2TestCoverage coverage);
Marissa Wallffc67da2016-12-15 12:26:09 -0800175
176 std::string dump() const override;
177
Marissa Wallee242782016-12-15 12:30:12 -0800178 void setDependent(Hwc2TestColor* color);
179
Marissa Wallffc67da2016-12-15 12:26:09 -0800180protected:
Marissa Wallee242782016-12-15 12:30:12 -0800181 void updateDependents() override;
182
183 Hwc2TestColor* mColor = nullptr;
184
Marissa Wallffc67da2016-12-15 12:26:09 -0800185 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;
Marissa Wall1cd789c2017-01-27 12:55:36 -0800188
189 static const std::array<bool, 6> mCompositionSupport;
Marissa Wallffc67da2016-12-15 12:26:09 -0800190};
191
192
Marissa Wallee242782016-12-15 12:30:12 -0800193class Hwc2TestColor : public Hwc2TestProperty<hwc_color_t> {
194public:
Chih-Hung Hsieh22749042018-12-20 15:50:39 -0800195 explicit Hwc2TestColor(Hwc2TestCoverage coverage,
196 hwc2_blend_mode_t blendMode = HWC2_BLEND_MODE_NONE);
Marissa Wallee242782016-12-15 12:30:12 -0800197
198 std::string dump() const override;
199
200 void updateBlendMode(hwc2_blend_mode_t blendMode);
201
202protected:
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;
Marissa Wall1cd789c2017-01-27 12:55:36 -0800213
214 static const std::array<bool, 6> mCompositionSupport;
Marissa Wallee242782016-12-15 12:30:12 -0800215};
216
217
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800218class Hwc2TestComposition : public Hwc2TestProperty<hwc2_composition_t> {
219public:
Chih-Hung Hsieh22749042018-12-20 15:50:39 -0800220 explicit Hwc2TestComposition(Hwc2TestCoverage coverage);
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800221
222 std::string dump() const override;
223
224protected:
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;
Marissa Wall1cd789c2017-01-27 12:55:36 -0800228
229 static const std::array<bool, 6> mCompositionSupport;
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800230};
231
Marissa Wallb72b5c92016-12-15 12:26:39 -0800232
Peiyong Lin34beb7a2018-03-28 11:57:12 -0700233class Hwc2TestDataspace : public Hwc2TestProperty<android::ui::Dataspace> {
Marissa Wallb72b5c92016-12-15 12:26:39 -0800234public:
Chih-Hung Hsieh22749042018-12-20 15:50:39 -0800235 explicit Hwc2TestDataspace(Hwc2TestCoverage coverage);
Marissa Wallb72b5c92016-12-15 12:26:39 -0800236
237 std::string dump() const override;
238
239protected:
Peiyong Lin34beb7a2018-03-28 11:57:12 -0700240 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;
Marissa Wall1cd789c2017-01-27 12:55:36 -0800243
244 static const std::array<bool, 6> mCompositionSupport;
Marissa Wallb72b5c92016-12-15 12:26:39 -0800245};
246
David Hanna Jr3f056022017-07-27 19:19:15 -0700247class Hwc2TestVirtualBuffer;
Marissa Wall2b1f5302016-12-15 12:27:20 -0800248
Marissa Wallbad1bc72017-02-21 14:33:46 -0800249class Hwc2TestDisplayDimension : public Hwc2TestProperty<UnsignedArea> {
250public:
Chih-Hung Hsieh22749042018-12-20 15:50:39 -0800251 explicit Hwc2TestDisplayDimension(Hwc2TestCoverage coverage);
Marissa Wallbad1bc72017-02-21 14:33:46 -0800252
253 std::string dump() const;
254
David Hanna Jr3f056022017-07-27 19:19:15 -0700255 void setDependent(Hwc2TestVirtualBuffer* buffer);
Marissa Wallbad1bc72017-02-21 14:33:46 -0800256
257private:
258 void updateDependents();
259
David Hanna Jr3f056022017-07-27 19:19:15 -0700260 std::set<Hwc2TestVirtualBuffer*> mBuffers;
Marissa Wallbad1bc72017-02-21 14:33:46 -0800261
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
Marissa Wall600a73b2016-12-15 12:30:39 -0800270class Hwc2TestDisplayFrame : public Hwc2TestProperty<hwc_rect_t> {
271public:
272 Hwc2TestDisplayFrame(Hwc2TestCoverage coverage, const Area& displayArea);
273
274 std::string dump() const override;
275
276protected:
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;
Marissa Wall1cd789c2017-01-27 12:55:36 -0800287
288 static const std::array<bool, 6> mCompositionSupport;
Marissa Wall600a73b2016-12-15 12:30:39 -0800289};
290
291
Marissa Wall2b1f5302016-12-15 12:27:20 -0800292class Hwc2TestPlaneAlpha : public Hwc2TestProperty<float> {
293public:
Chih-Hung Hsieh22749042018-12-20 15:50:39 -0800294 explicit Hwc2TestPlaneAlpha(Hwc2TestCoverage coverage);
Marissa Wall2b1f5302016-12-15 12:27:20 -0800295
296 std::string dump() const override;
297
298protected:
299 static const std::vector<float> mDefaultPlaneAlphas;
300 static const std::vector<float> mBasicPlaneAlphas;
301 static const std::vector<float> mCompletePlaneAlphas;
Marissa Wall1cd789c2017-01-27 12:55:36 -0800302
303 static const std::array<bool, 6> mCompositionSupport;
Marissa Wall2b1f5302016-12-15 12:27:20 -0800304};
305
Marissa Wallac108192016-12-15 12:27:48 -0800306
Marissa Wallc57468f2016-12-15 12:31:12 -0800307class Hwc2TestSourceCrop : public Hwc2TestProperty<hwc_frect_t> {
308public:
Chih-Hung Hsieh22749042018-12-20 15:50:39 -0800309 explicit Hwc2TestSourceCrop(Hwc2TestCoverage coverage, const Area& bufferArea = {0, 0});
Marissa Wallc57468f2016-12-15 12:31:12 -0800310
311 std::string dump() const override;
312
313 void updateBufferArea(const Area& bufferArea);
314
315protected:
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;
Marissa Wall1cd789c2017-01-27 12:55:36 -0800326
327 static const std::array<bool, 6> mCompositionSupport;
Marissa Wallc57468f2016-12-15 12:31:12 -0800328};
329
330
Marissa Wallad761812016-12-15 12:32:24 -0800331class Hwc2TestSurfaceDamage : public Hwc2TestProperty<hwc_region_t> {
332public:
Chih-Hung Hsieh22749042018-12-20 15:50:39 -0800333 explicit Hwc2TestSurfaceDamage(Hwc2TestCoverage coverage);
Marissa Wallad761812016-12-15 12:32:24 -0800334 ~Hwc2TestSurfaceDamage();
335
336 std::string dump() const override;
337
338 void updateBufferArea(const Area& bufferArea);
339
340protected:
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;
Marissa Wall1cd789c2017-01-27 12:55:36 -0800352
353 static const std::array<bool, 6> mCompositionSupport;
Marissa Wallad761812016-12-15 12:32:24 -0800354};
355
356
Marissa Wallac108192016-12-15 12:27:48 -0800357class Hwc2TestTransform : public Hwc2TestProperty<hwc_transform_t> {
358public:
Chih-Hung Hsieh22749042018-12-20 15:50:39 -0800359 explicit Hwc2TestTransform(Hwc2TestCoverage coverage);
Marissa Wallac108192016-12-15 12:27:48 -0800360
361 std::string dump() const override;
362
363protected:
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;
Marissa Wall1cd789c2017-01-27 12:55:36 -0800367
368 static const std::array<bool, 6> mCompositionSupport;
Marissa Wallac108192016-12-15 12:27:48 -0800369};
370
Marissa Wallf7618ed2016-12-15 12:34:39 -0800371
372class Hwc2TestVisibleRegion {
373public:
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
382protected:
383 hwc_region_t mVisibleRegion = {0, nullptr};
384};
385
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800386#endif /* ifndef _HWC2_TEST_PROPERTIES_H */