blob: f3c614cd556dae251dd61c3d77c08ef0b9adffe9 [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 Wall600a73b2016-12-15 12:30:39 -080037typedef struct {
38 int32_t width;
39 int32_t height;
40} Area;
41
Marissa Wall6bd8bfd2016-12-15 12:25:31 -080042
Marissa Wallffc67da2016-12-15 12:26:09 -080043class Hwc2TestContainer {
Marissa Wall6bd8bfd2016-12-15 12:25:31 -080044public:
Marissa Wallffc67da2016-12-15 12:26:09 -080045 virtual ~Hwc2TestContainer() = default;
46
47 /* Resets the container */
48 virtual void reset() = 0;
49
50 /* Attempts to advance to the next valid value. Returns true if one can be
51 * found */
52 virtual bool advance() = 0;
53
54 virtual std::string dump() const = 0;
Marissa Wall1cd789c2017-01-27 12:55:36 -080055
56 /* Returns true if the container supports the given composition type */
57 virtual bool isSupported(hwc2_composition_t composition) = 0;
Marissa Wallffc67da2016-12-15 12:26:09 -080058};
59
60
61template <class T>
62class Hwc2TestProperty : public Hwc2TestContainer {
63public:
64 Hwc2TestProperty(Hwc2TestCoverage coverage,
65 const std::vector<T>& completeList, const std::vector<T>& basicList,
Marissa Wall1cd789c2017-01-27 12:55:36 -080066 const std::vector<T>& defaultList,
67 const std::array<bool, 6>& compositionSupport)
Marissa Wallffc67da2016-12-15 12:26:09 -080068 : Hwc2TestProperty((coverage == Hwc2TestCoverage::Complete)? completeList:
Marissa Wall1cd789c2017-01-27 12:55:36 -080069 (coverage == Hwc2TestCoverage::Basic)? basicList : defaultList,
70 compositionSupport) { }
Marissa Wallffc67da2016-12-15 12:26:09 -080071
Marissa Wall1cd789c2017-01-27 12:55:36 -080072 Hwc2TestProperty(const std::vector<T>& list,
73 const std::array<bool, 6>& compositionSupport)
74 : mList(list),
75 mCompositionSupport(compositionSupport) { }
Marissa Wall6bd8bfd2016-12-15 12:25:31 -080076
Marissa Wallffc67da2016-12-15 12:26:09 -080077 void reset() override
Marissa Wall6bd8bfd2016-12-15 12:25:31 -080078 {
79 mListIdx = 0;
80 }
81
Marissa Wallffc67da2016-12-15 12:26:09 -080082 bool advance() override
Marissa Wall6bd8bfd2016-12-15 12:25:31 -080083 {
84 if (mListIdx + 1 < mList.size()) {
85 mListIdx++;
Marissa Wallc57468f2016-12-15 12:31:12 -080086 updateDependents();
Marissa Wall6bd8bfd2016-12-15 12:25:31 -080087 return true;
88 }
89 reset();
Marissa Wallc57468f2016-12-15 12:31:12 -080090 updateDependents();
Marissa Wall6bd8bfd2016-12-15 12:25:31 -080091 return false;
92 }
93
Marissa Wallffc67da2016-12-15 12:26:09 -080094 T get() const
Marissa Wall6bd8bfd2016-12-15 12:25:31 -080095 {
96 return mList.at(mListIdx);
97 }
98
Marissa Wall1cd789c2017-01-27 12:55:36 -080099 virtual bool isSupported(hwc2_composition_t composition)
100 {
101 return mCompositionSupport.at(composition);
102 }
103
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800104protected:
Marissa Wallc57468f2016-12-15 12:31:12 -0800105 /* If a derived class has dependents, override this function */
106 virtual void updateDependents() { }
107
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800108 const std::vector<T>& mList;
109 size_t mListIdx = 0;
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800110
Marissa Wall1cd789c2017-01-27 12:55:36 -0800111 const std::array<bool, 6>& mCompositionSupport;
112};
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800113
Marissa Wall5a240aa2016-12-15 12:34:06 -0800114class Hwc2TestBuffer;
Marissa Wallc57468f2016-12-15 12:31:12 -0800115class Hwc2TestSourceCrop;
Marissa Wallad761812016-12-15 12:32:24 -0800116class Hwc2TestSurfaceDamage;
Marissa Wallc57468f2016-12-15 12:31:12 -0800117
118class Hwc2TestBufferArea : public Hwc2TestProperty<Area> {
119public:
120 Hwc2TestBufferArea(Hwc2TestCoverage coverage, const Area& displayArea);
121
122 std::string dump() const override;
123
Marissa Wall5a240aa2016-12-15 12:34:06 -0800124 void setDependent(Hwc2TestBuffer* buffer);
Marissa Wallc57468f2016-12-15 12:31:12 -0800125 void setDependent(Hwc2TestSourceCrop* sourceCrop);
Marissa Wallad761812016-12-15 12:32:24 -0800126 void setDependent(Hwc2TestSurfaceDamage* surfaceDamage);
Marissa Wallc57468f2016-12-15 12:31:12 -0800127
128protected:
129 void update();
130 void updateDependents() override;
131
132 const std::vector<float>& mScalars;
133 static const std::vector<float> mDefaultScalars;
134 static const std::vector<float> mBasicScalars;
135 static const std::vector<float> mCompleteScalars;
136
137 Area mDisplayArea;
138
Marissa Wall5a240aa2016-12-15 12:34:06 -0800139 Hwc2TestBuffer* mBuffer = nullptr;
Marissa Wallc57468f2016-12-15 12:31:12 -0800140 Hwc2TestSourceCrop* mSourceCrop = nullptr;
Marissa Wallad761812016-12-15 12:32:24 -0800141 Hwc2TestSurfaceDamage* mSurfaceDamage = nullptr;
Marissa Wallc57468f2016-12-15 12:31:12 -0800142
143 std::vector<Area> mBufferAreas;
Marissa Wall1cd789c2017-01-27 12:55:36 -0800144
145 static const std::array<bool, 6> mCompositionSupport;
Marissa Wallc57468f2016-12-15 12:31:12 -0800146};
147
148
Marissa Wallee242782016-12-15 12:30:12 -0800149class Hwc2TestColor;
150
Marissa Wallffc67da2016-12-15 12:26:09 -0800151class Hwc2TestBlendMode : public Hwc2TestProperty<hwc2_blend_mode_t> {
152public:
153 Hwc2TestBlendMode(Hwc2TestCoverage coverage);
154
155 std::string dump() const override;
156
Marissa Wallee242782016-12-15 12:30:12 -0800157 void setDependent(Hwc2TestColor* color);
158
Marissa Wallffc67da2016-12-15 12:26:09 -0800159protected:
Marissa Wallee242782016-12-15 12:30:12 -0800160 void updateDependents() override;
161
162 Hwc2TestColor* mColor = nullptr;
163
Marissa Wallffc67da2016-12-15 12:26:09 -0800164 static const std::vector<hwc2_blend_mode_t> mDefaultBlendModes;
165 static const std::vector<hwc2_blend_mode_t> mBasicBlendModes;
166 static const std::vector<hwc2_blend_mode_t> mCompleteBlendModes;
Marissa Wall1cd789c2017-01-27 12:55:36 -0800167
168 static const std::array<bool, 6> mCompositionSupport;
Marissa Wallffc67da2016-12-15 12:26:09 -0800169};
170
171
Marissa Wallee242782016-12-15 12:30:12 -0800172class Hwc2TestColor : public Hwc2TestProperty<hwc_color_t> {
173public:
174 Hwc2TestColor(Hwc2TestCoverage coverage,
175 hwc2_blend_mode_t blendMode = HWC2_BLEND_MODE_NONE);
176
177 std::string dump() const override;
178
179 void updateBlendMode(hwc2_blend_mode_t blendMode);
180
181protected:
182 void update();
183
184 std::vector<hwc_color_t> mBaseColors;
185 static const std::vector<hwc_color_t> mDefaultBaseColors;
186 static const std::vector<hwc_color_t> mBasicBaseColors;
187 static const std::vector<hwc_color_t> mCompleteBaseColors;
188
189 hwc2_blend_mode_t mBlendMode;
190
191 std::vector<hwc_color_t> mColors;
Marissa Wall1cd789c2017-01-27 12:55:36 -0800192
193 static const std::array<bool, 6> mCompositionSupport;
Marissa Wallee242782016-12-15 12:30:12 -0800194};
195
196
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800197class Hwc2TestComposition : public Hwc2TestProperty<hwc2_composition_t> {
198public:
199 Hwc2TestComposition(Hwc2TestCoverage coverage);
200
201 std::string dump() const override;
202
203protected:
204 static const std::vector<hwc2_composition_t> mDefaultCompositions;
205 static const std::vector<hwc2_composition_t> mBasicCompositions;
206 static const std::vector<hwc2_composition_t> mCompleteCompositions;
Marissa Wall1cd789c2017-01-27 12:55:36 -0800207
208 static const std::array<bool, 6> mCompositionSupport;
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800209};
210
Marissa Wallb72b5c92016-12-15 12:26:39 -0800211
212class Hwc2TestDataspace : public Hwc2TestProperty<android_dataspace_t> {
213public:
214 Hwc2TestDataspace(Hwc2TestCoverage coverage);
215
216 std::string dump() const override;
217
218protected:
219 static const std::vector<android_dataspace_t> defaultDataspaces;
220 static const std::vector<android_dataspace_t> basicDataspaces;
221 static const std::vector<android_dataspace_t> completeDataspaces;
Marissa Wall1cd789c2017-01-27 12:55:36 -0800222
223 static const std::array<bool, 6> mCompositionSupport;
Marissa Wallb72b5c92016-12-15 12:26:39 -0800224};
225
Marissa Wall2b1f5302016-12-15 12:27:20 -0800226
Marissa Wall600a73b2016-12-15 12:30:39 -0800227class Hwc2TestDisplayFrame : public Hwc2TestProperty<hwc_rect_t> {
228public:
229 Hwc2TestDisplayFrame(Hwc2TestCoverage coverage, const Area& displayArea);
230
231 std::string dump() const override;
232
233protected:
234 void update();
235
236 const std::vector<hwc_frect_t>& mFrectScalars;
237 const static std::vector<hwc_frect_t> mDefaultFrectScalars;
238 const static std::vector<hwc_frect_t> mBasicFrectScalars;
239 const static std::vector<hwc_frect_t> mCompleteFrectScalars;
240
241 Area mDisplayArea;
242
243 std::vector<hwc_rect_t> mDisplayFrames;
Marissa Wall1cd789c2017-01-27 12:55:36 -0800244
245 static const std::array<bool, 6> mCompositionSupport;
Marissa Wall600a73b2016-12-15 12:30:39 -0800246};
247
248
Marissa Wall2b1f5302016-12-15 12:27:20 -0800249class Hwc2TestPlaneAlpha : public Hwc2TestProperty<float> {
250public:
251 Hwc2TestPlaneAlpha(Hwc2TestCoverage coverage);
252
253 std::string dump() const override;
254
255protected:
256 static const std::vector<float> mDefaultPlaneAlphas;
257 static const std::vector<float> mBasicPlaneAlphas;
258 static const std::vector<float> mCompletePlaneAlphas;
Marissa Wall1cd789c2017-01-27 12:55:36 -0800259
260 static const std::array<bool, 6> mCompositionSupport;
Marissa Wall2b1f5302016-12-15 12:27:20 -0800261};
262
Marissa Wallac108192016-12-15 12:27:48 -0800263
Marissa Wallc57468f2016-12-15 12:31:12 -0800264class Hwc2TestSourceCrop : public Hwc2TestProperty<hwc_frect_t> {
265public:
266 Hwc2TestSourceCrop(Hwc2TestCoverage coverage, const Area& bufferArea = {0, 0});
267
268 std::string dump() const override;
269
270 void updateBufferArea(const Area& bufferArea);
271
272protected:
273 void update();
274
275 const std::vector<hwc_frect_t>& mFrectScalars;
276 const static std::vector<hwc_frect_t> mDefaultFrectScalars;
277 const static std::vector<hwc_frect_t> mBasicFrectScalars;
278 const static std::vector<hwc_frect_t> mCompleteFrectScalars;
279
280 Area mBufferArea;
281
282 std::vector<hwc_frect_t> mSourceCrops;
Marissa Wall1cd789c2017-01-27 12:55:36 -0800283
284 static const std::array<bool, 6> mCompositionSupport;
Marissa Wallc57468f2016-12-15 12:31:12 -0800285};
286
287
Marissa Wallad761812016-12-15 12:32:24 -0800288class Hwc2TestSurfaceDamage : public Hwc2TestProperty<hwc_region_t> {
289public:
290 Hwc2TestSurfaceDamage(Hwc2TestCoverage coverage);
291 ~Hwc2TestSurfaceDamage();
292
293 std::string dump() const override;
294
295 void updateBufferArea(const Area& bufferArea);
296
297protected:
298 void update();
299 void freeSurfaceDamages();
300
301 const std::vector<std::vector<hwc_frect_t>> &mRegionScalars;
302 const static std::vector<std::vector<hwc_frect_t>> mDefaultRegionScalars;
303 const static std::vector<std::vector<hwc_frect_t>> mBasicRegionScalars;
304 const static std::vector<std::vector<hwc_frect_t>> mCompleteRegionScalars;
305
306 Area mBufferArea = {0, 0};
307
308 std::vector<hwc_region_t> mSurfaceDamages;
Marissa Wall1cd789c2017-01-27 12:55:36 -0800309
310 static const std::array<bool, 6> mCompositionSupport;
Marissa Wallad761812016-12-15 12:32:24 -0800311};
312
313
Marissa Wallac108192016-12-15 12:27:48 -0800314class Hwc2TestTransform : public Hwc2TestProperty<hwc_transform_t> {
315public:
316 Hwc2TestTransform(Hwc2TestCoverage coverage);
317
318 std::string dump() const override;
319
320protected:
321 static const std::vector<hwc_transform_t> mDefaultTransforms;
322 static const std::vector<hwc_transform_t> mBasicTransforms;
323 static const std::vector<hwc_transform_t> mCompleteTransforms;
Marissa Wall1cd789c2017-01-27 12:55:36 -0800324
325 static const std::array<bool, 6> mCompositionSupport;
Marissa Wallac108192016-12-15 12:27:48 -0800326};
327
Marissa Wallf7618ed2016-12-15 12:34:39 -0800328
329class Hwc2TestVisibleRegion {
330public:
331 ~Hwc2TestVisibleRegion();
332
333 std::string dump() const;
334
335 void set(const android::Region& visibleRegion);
336 hwc_region_t get() const;
337 void release();
338
339protected:
340 hwc_region_t mVisibleRegion = {0, nullptr};
341};
342
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800343#endif /* ifndef _HWC2_TEST_PROPERTIES_H */