blob: d978237cdf04d96469a80db63a666e44896f6075 [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
Marissa Wallf7618ed2016-12-15 12:34:39 -080023#include <ui/Region.h>
24
Marissa Wall6bd8bfd2016-12-15 12:25:31 -080025#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
Marissa Wall563030b2017-02-21 14:01:05 -080037enum 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 Wall600a73b2016-12-15 12:30:39 -080051typedef struct {
52 int32_t width;
53 int32_t height;
54} Area;
55
Marissa Wall6bd8bfd2016-12-15 12:25:31 -080056
Marissa Wallffc67da2016-12-15 12:26:09 -080057class Hwc2TestContainer {
Marissa Wall6bd8bfd2016-12-15 12:25:31 -080058public:
Marissa Wallffc67da2016-12-15 12:26:09 -080059 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 Wall1cd789c2017-01-27 12:55:36 -080069
70 /* Returns true if the container supports the given composition type */
71 virtual bool isSupported(hwc2_composition_t composition) = 0;
Marissa Wallffc67da2016-12-15 12:26:09 -080072};
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,
Marissa Wall1cd789c2017-01-27 12:55:36 -080080 const std::vector<T>& defaultList,
81 const std::array<bool, 6>& compositionSupport)
Marissa Wallffc67da2016-12-15 12:26:09 -080082 : Hwc2TestProperty((coverage == Hwc2TestCoverage::Complete)? completeList:
Marissa Wall1cd789c2017-01-27 12:55:36 -080083 (coverage == Hwc2TestCoverage::Basic)? basicList : defaultList,
84 compositionSupport) { }
Marissa Wallffc67da2016-12-15 12:26:09 -080085
Marissa Wall1cd789c2017-01-27 12:55:36 -080086 Hwc2TestProperty(const std::vector<T>& list,
87 const std::array<bool, 6>& compositionSupport)
88 : mList(list),
89 mCompositionSupport(compositionSupport) { }
Marissa Wall6bd8bfd2016-12-15 12:25:31 -080090
Marissa Wallffc67da2016-12-15 12:26:09 -080091 void reset() override
Marissa Wall6bd8bfd2016-12-15 12:25:31 -080092 {
93 mListIdx = 0;
94 }
95
Marissa Wallffc67da2016-12-15 12:26:09 -080096 bool advance() override
Marissa Wall6bd8bfd2016-12-15 12:25:31 -080097 {
98 if (mListIdx + 1 < mList.size()) {
99 mListIdx++;
Marissa Wallc57468f2016-12-15 12:31:12 -0800100 updateDependents();
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800101 return true;
102 }
103 reset();
Marissa Wallc57468f2016-12-15 12:31:12 -0800104 updateDependents();
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800105 return false;
106 }
107
Marissa Wallffc67da2016-12-15 12:26:09 -0800108 T get() const
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800109 {
110 return mList.at(mListIdx);
111 }
112
Marissa Wall1cd789c2017-01-27 12:55:36 -0800113 virtual bool isSupported(hwc2_composition_t composition)
114 {
115 return mCompositionSupport.at(composition);
116 }
117
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800118protected:
Marissa Wallc57468f2016-12-15 12:31:12 -0800119 /* If a derived class has dependents, override this function */
120 virtual void updateDependents() { }
121
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800122 const std::vector<T>& mList;
123 size_t mListIdx = 0;
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800124
Marissa Wall1cd789c2017-01-27 12:55:36 -0800125 const std::array<bool, 6>& mCompositionSupport;
126};
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800127
Marissa Wall5a240aa2016-12-15 12:34:06 -0800128class Hwc2TestBuffer;
Marissa Wallc57468f2016-12-15 12:31:12 -0800129class Hwc2TestSourceCrop;
Marissa Wallad761812016-12-15 12:32:24 -0800130class Hwc2TestSurfaceDamage;
Marissa Wallc57468f2016-12-15 12:31:12 -0800131
132class Hwc2TestBufferArea : public Hwc2TestProperty<Area> {
133public:
134 Hwc2TestBufferArea(Hwc2TestCoverage coverage, const Area& displayArea);
135
136 std::string dump() const override;
137
Marissa Wall5a240aa2016-12-15 12:34:06 -0800138 void setDependent(Hwc2TestBuffer* buffer);
Marissa Wallc57468f2016-12-15 12:31:12 -0800139 void setDependent(Hwc2TestSourceCrop* sourceCrop);
Marissa Wallad761812016-12-15 12:32:24 -0800140 void setDependent(Hwc2TestSurfaceDamage* surfaceDamage);
Marissa Wallc57468f2016-12-15 12:31:12 -0800141
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
Marissa Wall5a240aa2016-12-15 12:34:06 -0800153 Hwc2TestBuffer* mBuffer = nullptr;
Marissa Wallc57468f2016-12-15 12:31:12 -0800154 Hwc2TestSourceCrop* mSourceCrop = nullptr;
Marissa Wallad761812016-12-15 12:32:24 -0800155 Hwc2TestSurfaceDamage* mSurfaceDamage = nullptr;
Marissa Wallc57468f2016-12-15 12:31:12 -0800156
157 std::vector<Area> mBufferAreas;
Marissa Wall1cd789c2017-01-27 12:55:36 -0800158
159 static const std::array<bool, 6> mCompositionSupport;
Marissa Wallc57468f2016-12-15 12:31:12 -0800160};
161
162
Marissa Wallee242782016-12-15 12:30:12 -0800163class Hwc2TestColor;
164
Marissa Wallffc67da2016-12-15 12:26:09 -0800165class Hwc2TestBlendMode : public Hwc2TestProperty<hwc2_blend_mode_t> {
166public:
167 Hwc2TestBlendMode(Hwc2TestCoverage coverage);
168
169 std::string dump() const override;
170
Marissa Wallee242782016-12-15 12:30:12 -0800171 void setDependent(Hwc2TestColor* color);
172
Marissa Wallffc67da2016-12-15 12:26:09 -0800173protected:
Marissa Wallee242782016-12-15 12:30:12 -0800174 void updateDependents() override;
175
176 Hwc2TestColor* mColor = nullptr;
177
Marissa Wallffc67da2016-12-15 12:26:09 -0800178 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 Wall1cd789c2017-01-27 12:55:36 -0800181
182 static const std::array<bool, 6> mCompositionSupport;
Marissa Wallffc67da2016-12-15 12:26:09 -0800183};
184
185
Marissa Wallee242782016-12-15 12:30:12 -0800186class 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;
Marissa Wall1cd789c2017-01-27 12:55:36 -0800206
207 static const std::array<bool, 6> mCompositionSupport;
Marissa Wallee242782016-12-15 12:30:12 -0800208};
209
210
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800211class 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;
Marissa Wall1cd789c2017-01-27 12:55:36 -0800221
222 static const std::array<bool, 6> mCompositionSupport;
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800223};
224
Marissa Wallb72b5c92016-12-15 12:26:39 -0800225
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;
Marissa Wall1cd789c2017-01-27 12:55:36 -0800236
237 static const std::array<bool, 6> mCompositionSupport;
Marissa Wallb72b5c92016-12-15 12:26:39 -0800238};
239
Marissa Wall2b1f5302016-12-15 12:27:20 -0800240
Marissa Wall600a73b2016-12-15 12:30:39 -0800241class 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;
Marissa Wall1cd789c2017-01-27 12:55:36 -0800258
259 static const std::array<bool, 6> mCompositionSupport;
Marissa Wall600a73b2016-12-15 12:30:39 -0800260};
261
262
Marissa Wall2b1f5302016-12-15 12:27:20 -0800263class 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;
Marissa Wall1cd789c2017-01-27 12:55:36 -0800273
274 static const std::array<bool, 6> mCompositionSupport;
Marissa Wall2b1f5302016-12-15 12:27:20 -0800275};
276
Marissa Wallac108192016-12-15 12:27:48 -0800277
Marissa Wallc57468f2016-12-15 12:31:12 -0800278class 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;
Marissa Wall1cd789c2017-01-27 12:55:36 -0800297
298 static const std::array<bool, 6> mCompositionSupport;
Marissa Wallc57468f2016-12-15 12:31:12 -0800299};
300
301
Marissa Wallad761812016-12-15 12:32:24 -0800302class 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;
Marissa Wall1cd789c2017-01-27 12:55:36 -0800323
324 static const std::array<bool, 6> mCompositionSupport;
Marissa Wallad761812016-12-15 12:32:24 -0800325};
326
327
Marissa Wallac108192016-12-15 12:27:48 -0800328class 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;
Marissa Wall1cd789c2017-01-27 12:55:36 -0800338
339 static const std::array<bool, 6> mCompositionSupport;
Marissa Wallac108192016-12-15 12:27:48 -0800340};
341
Marissa Wallf7618ed2016-12-15 12:34:39 -0800342
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
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800357#endif /* ifndef _HWC2_TEST_PROPERTIES_H */