blob: cb811e06e2c3e7f956180d894b9c8c95562264a5 [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 Wallbad1bc72017-02-21 14:33:46 -080057typedef struct {
58 uint32_t width;
59 uint32_t height;
60} UnsignedArea;
61
62
Marissa Wallffc67da2016-12-15 12:26:09 -080063class Hwc2TestContainer {
Marissa Wall6bd8bfd2016-12-15 12:25:31 -080064public:
Marissa Wallffc67da2016-12-15 12:26:09 -080065 virtual ~Hwc2TestContainer() = default;
66
67 /* Resets the container */
68 virtual void reset() = 0;
69
70 /* Attempts to advance to the next valid value. Returns true if one can be
71 * found */
72 virtual bool advance() = 0;
73
74 virtual std::string dump() const = 0;
Marissa Wall1cd789c2017-01-27 12:55:36 -080075
76 /* Returns true if the container supports the given composition type */
77 virtual bool isSupported(hwc2_composition_t composition) = 0;
Marissa Wallffc67da2016-12-15 12:26:09 -080078};
79
80
81template <class T>
82class Hwc2TestProperty : public Hwc2TestContainer {
83public:
84 Hwc2TestProperty(Hwc2TestCoverage coverage,
85 const std::vector<T>& completeList, const std::vector<T>& basicList,
Marissa Wall1cd789c2017-01-27 12:55:36 -080086 const std::vector<T>& defaultList,
87 const std::array<bool, 6>& compositionSupport)
Marissa Wallffc67da2016-12-15 12:26:09 -080088 : Hwc2TestProperty((coverage == Hwc2TestCoverage::Complete)? completeList:
Marissa Wall1cd789c2017-01-27 12:55:36 -080089 (coverage == Hwc2TestCoverage::Basic)? basicList : defaultList,
90 compositionSupport) { }
Marissa Wallffc67da2016-12-15 12:26:09 -080091
Marissa Wall1cd789c2017-01-27 12:55:36 -080092 Hwc2TestProperty(const std::vector<T>& list,
93 const std::array<bool, 6>& compositionSupport)
94 : mList(list),
95 mCompositionSupport(compositionSupport) { }
Marissa Wall6bd8bfd2016-12-15 12:25:31 -080096
Marissa Wallffc67da2016-12-15 12:26:09 -080097 void reset() override
Marissa Wall6bd8bfd2016-12-15 12:25:31 -080098 {
99 mListIdx = 0;
100 }
101
Marissa Wallffc67da2016-12-15 12:26:09 -0800102 bool advance() override
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800103 {
104 if (mListIdx + 1 < mList.size()) {
105 mListIdx++;
Marissa Wallc57468f2016-12-15 12:31:12 -0800106 updateDependents();
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800107 return true;
108 }
109 reset();
Marissa Wallc57468f2016-12-15 12:31:12 -0800110 updateDependents();
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800111 return false;
112 }
113
Marissa Wallffc67da2016-12-15 12:26:09 -0800114 T get() const
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800115 {
116 return mList.at(mListIdx);
117 }
118
Marissa Wall1cd789c2017-01-27 12:55:36 -0800119 virtual bool isSupported(hwc2_composition_t composition)
120 {
121 return mCompositionSupport.at(composition);
122 }
123
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800124protected:
Marissa Wallc57468f2016-12-15 12:31:12 -0800125 /* If a derived class has dependents, override this function */
126 virtual void updateDependents() { }
127
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800128 const std::vector<T>& mList;
129 size_t mListIdx = 0;
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800130
Marissa Wall1cd789c2017-01-27 12:55:36 -0800131 const std::array<bool, 6>& mCompositionSupport;
132};
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800133
Marissa Wall5a240aa2016-12-15 12:34:06 -0800134class Hwc2TestBuffer;
Marissa Wallc57468f2016-12-15 12:31:12 -0800135class Hwc2TestSourceCrop;
Marissa Wallad761812016-12-15 12:32:24 -0800136class Hwc2TestSurfaceDamage;
Marissa Wallc57468f2016-12-15 12:31:12 -0800137
138class Hwc2TestBufferArea : public Hwc2TestProperty<Area> {
139public:
140 Hwc2TestBufferArea(Hwc2TestCoverage coverage, const Area& displayArea);
141
142 std::string dump() const override;
143
Marissa Wall5a240aa2016-12-15 12:34:06 -0800144 void setDependent(Hwc2TestBuffer* buffer);
Marissa Wallc57468f2016-12-15 12:31:12 -0800145 void setDependent(Hwc2TestSourceCrop* sourceCrop);
Marissa Wallad761812016-12-15 12:32:24 -0800146 void setDependent(Hwc2TestSurfaceDamage* surfaceDamage);
Marissa Wallc57468f2016-12-15 12:31:12 -0800147
148protected:
149 void update();
150 void updateDependents() override;
151
152 const std::vector<float>& mScalars;
153 static const std::vector<float> mDefaultScalars;
154 static const std::vector<float> mBasicScalars;
155 static const std::vector<float> mCompleteScalars;
156
157 Area mDisplayArea;
158
Marissa Wall5a240aa2016-12-15 12:34:06 -0800159 Hwc2TestBuffer* mBuffer = nullptr;
Marissa Wallc57468f2016-12-15 12:31:12 -0800160 Hwc2TestSourceCrop* mSourceCrop = nullptr;
Marissa Wallad761812016-12-15 12:32:24 -0800161 Hwc2TestSurfaceDamage* mSurfaceDamage = nullptr;
Marissa Wallc57468f2016-12-15 12:31:12 -0800162
163 std::vector<Area> mBufferAreas;
Marissa Wall1cd789c2017-01-27 12:55:36 -0800164
165 static const std::array<bool, 6> mCompositionSupport;
Marissa Wallc57468f2016-12-15 12:31:12 -0800166};
167
168
Marissa Wallee242782016-12-15 12:30:12 -0800169class Hwc2TestColor;
170
Marissa Wallffc67da2016-12-15 12:26:09 -0800171class Hwc2TestBlendMode : public Hwc2TestProperty<hwc2_blend_mode_t> {
172public:
173 Hwc2TestBlendMode(Hwc2TestCoverage coverage);
174
175 std::string dump() const override;
176
Marissa Wallee242782016-12-15 12:30:12 -0800177 void setDependent(Hwc2TestColor* color);
178
Marissa Wallffc67da2016-12-15 12:26:09 -0800179protected:
Marissa Wallee242782016-12-15 12:30:12 -0800180 void updateDependents() override;
181
182 Hwc2TestColor* mColor = nullptr;
183
Marissa Wallffc67da2016-12-15 12:26:09 -0800184 static const std::vector<hwc2_blend_mode_t> mDefaultBlendModes;
185 static const std::vector<hwc2_blend_mode_t> mBasicBlendModes;
186 static const std::vector<hwc2_blend_mode_t> mCompleteBlendModes;
Marissa Wall1cd789c2017-01-27 12:55:36 -0800187
188 static const std::array<bool, 6> mCompositionSupport;
Marissa Wallffc67da2016-12-15 12:26:09 -0800189};
190
191
Marissa Wallee242782016-12-15 12:30:12 -0800192class Hwc2TestColor : public Hwc2TestProperty<hwc_color_t> {
193public:
194 Hwc2TestColor(Hwc2TestCoverage coverage,
195 hwc2_blend_mode_t blendMode = HWC2_BLEND_MODE_NONE);
196
197 std::string dump() const override;
198
199 void updateBlendMode(hwc2_blend_mode_t blendMode);
200
201protected:
202 void update();
203
204 std::vector<hwc_color_t> mBaseColors;
205 static const std::vector<hwc_color_t> mDefaultBaseColors;
206 static const std::vector<hwc_color_t> mBasicBaseColors;
207 static const std::vector<hwc_color_t> mCompleteBaseColors;
208
209 hwc2_blend_mode_t mBlendMode;
210
211 std::vector<hwc_color_t> mColors;
Marissa Wall1cd789c2017-01-27 12:55:36 -0800212
213 static const std::array<bool, 6> mCompositionSupport;
Marissa Wallee242782016-12-15 12:30:12 -0800214};
215
216
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800217class Hwc2TestComposition : public Hwc2TestProperty<hwc2_composition_t> {
218public:
219 Hwc2TestComposition(Hwc2TestCoverage coverage);
220
221 std::string dump() const override;
222
223protected:
224 static const std::vector<hwc2_composition_t> mDefaultCompositions;
225 static const std::vector<hwc2_composition_t> mBasicCompositions;
226 static const std::vector<hwc2_composition_t> mCompleteCompositions;
Marissa Wall1cd789c2017-01-27 12:55:36 -0800227
228 static const std::array<bool, 6> mCompositionSupport;
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800229};
230
Marissa Wallb72b5c92016-12-15 12:26:39 -0800231
232class Hwc2TestDataspace : public Hwc2TestProperty<android_dataspace_t> {
233public:
234 Hwc2TestDataspace(Hwc2TestCoverage coverage);
235
236 std::string dump() const override;
237
238protected:
239 static const std::vector<android_dataspace_t> defaultDataspaces;
240 static const std::vector<android_dataspace_t> basicDataspaces;
241 static const std::vector<android_dataspace_t> completeDataspaces;
Marissa Wall1cd789c2017-01-27 12:55:36 -0800242
243 static const std::array<bool, 6> mCompositionSupport;
Marissa Wallb72b5c92016-12-15 12:26:39 -0800244};
245
David Hanna Jr3f056022017-07-27 19:19:15 -0700246class Hwc2TestVirtualBuffer;
Marissa Wall2b1f5302016-12-15 12:27:20 -0800247
Marissa Wallbad1bc72017-02-21 14:33:46 -0800248class Hwc2TestDisplayDimension : public Hwc2TestProperty<UnsignedArea> {
249public:
250 Hwc2TestDisplayDimension(Hwc2TestCoverage coverage);
251
252 std::string dump() const;
253
David Hanna Jr3f056022017-07-27 19:19:15 -0700254 void setDependent(Hwc2TestVirtualBuffer* buffer);
Marissa Wallbad1bc72017-02-21 14:33:46 -0800255
256private:
257 void updateDependents();
258
David Hanna Jr3f056022017-07-27 19:19:15 -0700259 std::set<Hwc2TestVirtualBuffer*> mBuffers;
Marissa Wallbad1bc72017-02-21 14:33:46 -0800260
261 static const std::vector<UnsignedArea> mDefaultDisplayDimensions;
262 static const std::vector<UnsignedArea> mBasicDisplayDimensions;
263 static const std::vector<UnsignedArea> mCompleteDisplayDimensions;
264
265 static const std::array<bool, 6> mCompositionSupport;
266};
267
268
Marissa Wall600a73b2016-12-15 12:30:39 -0800269class Hwc2TestDisplayFrame : public Hwc2TestProperty<hwc_rect_t> {
270public:
271 Hwc2TestDisplayFrame(Hwc2TestCoverage coverage, const Area& displayArea);
272
273 std::string dump() const override;
274
275protected:
276 void update();
277
278 const std::vector<hwc_frect_t>& mFrectScalars;
279 const static std::vector<hwc_frect_t> mDefaultFrectScalars;
280 const static std::vector<hwc_frect_t> mBasicFrectScalars;
281 const static std::vector<hwc_frect_t> mCompleteFrectScalars;
282
283 Area mDisplayArea;
284
285 std::vector<hwc_rect_t> mDisplayFrames;
Marissa Wall1cd789c2017-01-27 12:55:36 -0800286
287 static const std::array<bool, 6> mCompositionSupport;
Marissa Wall600a73b2016-12-15 12:30:39 -0800288};
289
290
Marissa Wall2b1f5302016-12-15 12:27:20 -0800291class Hwc2TestPlaneAlpha : public Hwc2TestProperty<float> {
292public:
293 Hwc2TestPlaneAlpha(Hwc2TestCoverage coverage);
294
295 std::string dump() const override;
296
297protected:
298 static const std::vector<float> mDefaultPlaneAlphas;
299 static const std::vector<float> mBasicPlaneAlphas;
300 static const std::vector<float> mCompletePlaneAlphas;
Marissa Wall1cd789c2017-01-27 12:55:36 -0800301
302 static const std::array<bool, 6> mCompositionSupport;
Marissa Wall2b1f5302016-12-15 12:27:20 -0800303};
304
Marissa Wallac108192016-12-15 12:27:48 -0800305
Marissa Wallc57468f2016-12-15 12:31:12 -0800306class Hwc2TestSourceCrop : public Hwc2TestProperty<hwc_frect_t> {
307public:
308 Hwc2TestSourceCrop(Hwc2TestCoverage coverage, const Area& bufferArea = {0, 0});
309
310 std::string dump() const override;
311
312 void updateBufferArea(const Area& bufferArea);
313
314protected:
315 void update();
316
317 const std::vector<hwc_frect_t>& mFrectScalars;
318 const static std::vector<hwc_frect_t> mDefaultFrectScalars;
319 const static std::vector<hwc_frect_t> mBasicFrectScalars;
320 const static std::vector<hwc_frect_t> mCompleteFrectScalars;
321
322 Area mBufferArea;
323
324 std::vector<hwc_frect_t> mSourceCrops;
Marissa Wall1cd789c2017-01-27 12:55:36 -0800325
326 static const std::array<bool, 6> mCompositionSupport;
Marissa Wallc57468f2016-12-15 12:31:12 -0800327};
328
329
Marissa Wallad761812016-12-15 12:32:24 -0800330class Hwc2TestSurfaceDamage : public Hwc2TestProperty<hwc_region_t> {
331public:
332 Hwc2TestSurfaceDamage(Hwc2TestCoverage coverage);
333 ~Hwc2TestSurfaceDamage();
334
335 std::string dump() const override;
336
337 void updateBufferArea(const Area& bufferArea);
338
339protected:
340 void update();
341 void freeSurfaceDamages();
342
343 const std::vector<std::vector<hwc_frect_t>> &mRegionScalars;
344 const static std::vector<std::vector<hwc_frect_t>> mDefaultRegionScalars;
345 const static std::vector<std::vector<hwc_frect_t>> mBasicRegionScalars;
346 const static std::vector<std::vector<hwc_frect_t>> mCompleteRegionScalars;
347
348 Area mBufferArea = {0, 0};
349
350 std::vector<hwc_region_t> mSurfaceDamages;
Marissa Wall1cd789c2017-01-27 12:55:36 -0800351
352 static const std::array<bool, 6> mCompositionSupport;
Marissa Wallad761812016-12-15 12:32:24 -0800353};
354
355
Marissa Wallac108192016-12-15 12:27:48 -0800356class Hwc2TestTransform : public Hwc2TestProperty<hwc_transform_t> {
357public:
358 Hwc2TestTransform(Hwc2TestCoverage coverage);
359
360 std::string dump() const override;
361
362protected:
363 static const std::vector<hwc_transform_t> mDefaultTransforms;
364 static const std::vector<hwc_transform_t> mBasicTransforms;
365 static const std::vector<hwc_transform_t> mCompleteTransforms;
Marissa Wall1cd789c2017-01-27 12:55:36 -0800366
367 static const std::array<bool, 6> mCompositionSupport;
Marissa Wallac108192016-12-15 12:27:48 -0800368};
369
Marissa Wallf7618ed2016-12-15 12:34:39 -0800370
371class Hwc2TestVisibleRegion {
372public:
373 ~Hwc2TestVisibleRegion();
374
375 std::string dump() const;
376
377 void set(const android::Region& visibleRegion);
378 hwc_region_t get() const;
379 void release();
380
381protected:
382 hwc_region_t mVisibleRegion = {0, nullptr};
383};
384
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800385#endif /* ifndef _HWC2_TEST_PROPERTIES_H */