blob: 9cdf69c394201bef5a8475a1ed20444d1396258d [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;
55};
56
57
58template <class T>
59class Hwc2TestProperty : public Hwc2TestContainer {
60public:
61 Hwc2TestProperty(Hwc2TestCoverage coverage,
62 const std::vector<T>& completeList, const std::vector<T>& basicList,
63 const std::vector<T>& defaultList)
64 : Hwc2TestProperty((coverage == Hwc2TestCoverage::Complete)? completeList:
65 (coverage == Hwc2TestCoverage::Basic)? basicList : defaultList) { }
66
Marissa Wall6bd8bfd2016-12-15 12:25:31 -080067 Hwc2TestProperty(const std::vector<T>& list)
68 : mList(list) { }
69
Marissa Wallffc67da2016-12-15 12:26:09 -080070 void reset() override
Marissa Wall6bd8bfd2016-12-15 12:25:31 -080071 {
72 mListIdx = 0;
73 }
74
Marissa Wallffc67da2016-12-15 12:26:09 -080075 bool advance() override
Marissa Wall6bd8bfd2016-12-15 12:25:31 -080076 {
77 if (mListIdx + 1 < mList.size()) {
78 mListIdx++;
Marissa Wallc57468f2016-12-15 12:31:12 -080079 updateDependents();
Marissa Wall6bd8bfd2016-12-15 12:25:31 -080080 return true;
81 }
82 reset();
Marissa Wallc57468f2016-12-15 12:31:12 -080083 updateDependents();
Marissa Wall6bd8bfd2016-12-15 12:25:31 -080084 return false;
85 }
86
Marissa Wallffc67da2016-12-15 12:26:09 -080087 T get() const
Marissa Wall6bd8bfd2016-12-15 12:25:31 -080088 {
89 return mList.at(mListIdx);
90 }
91
Marissa Wall6bd8bfd2016-12-15 12:25:31 -080092protected:
Marissa Wallc57468f2016-12-15 12:31:12 -080093 /* If a derived class has dependents, override this function */
94 virtual void updateDependents() { }
95
Marissa Wall6bd8bfd2016-12-15 12:25:31 -080096 const std::vector<T>& mList;
97 size_t mListIdx = 0;
98};
99
100
Marissa Wall5a240aa2016-12-15 12:34:06 -0800101class Hwc2TestBuffer;
Marissa Wallc57468f2016-12-15 12:31:12 -0800102class Hwc2TestSourceCrop;
Marissa Wallad761812016-12-15 12:32:24 -0800103class Hwc2TestSurfaceDamage;
Marissa Wallc57468f2016-12-15 12:31:12 -0800104
105class Hwc2TestBufferArea : public Hwc2TestProperty<Area> {
106public:
107 Hwc2TestBufferArea(Hwc2TestCoverage coverage, const Area& displayArea);
108
109 std::string dump() const override;
110
Marissa Wall5a240aa2016-12-15 12:34:06 -0800111 void setDependent(Hwc2TestBuffer* buffer);
Marissa Wallc57468f2016-12-15 12:31:12 -0800112 void setDependent(Hwc2TestSourceCrop* sourceCrop);
Marissa Wallad761812016-12-15 12:32:24 -0800113 void setDependent(Hwc2TestSurfaceDamage* surfaceDamage);
Marissa Wallc57468f2016-12-15 12:31:12 -0800114
115protected:
116 void update();
117 void updateDependents() override;
118
119 const std::vector<float>& mScalars;
120 static const std::vector<float> mDefaultScalars;
121 static const std::vector<float> mBasicScalars;
122 static const std::vector<float> mCompleteScalars;
123
124 Area mDisplayArea;
125
Marissa Wall5a240aa2016-12-15 12:34:06 -0800126 Hwc2TestBuffer* mBuffer = nullptr;
Marissa Wallc57468f2016-12-15 12:31:12 -0800127 Hwc2TestSourceCrop* mSourceCrop = nullptr;
Marissa Wallad761812016-12-15 12:32:24 -0800128 Hwc2TestSurfaceDamage* mSurfaceDamage = nullptr;
Marissa Wallc57468f2016-12-15 12:31:12 -0800129
130 std::vector<Area> mBufferAreas;
131};
132
133
Marissa Wallee242782016-12-15 12:30:12 -0800134class Hwc2TestColor;
135
Marissa Wallffc67da2016-12-15 12:26:09 -0800136class Hwc2TestBlendMode : public Hwc2TestProperty<hwc2_blend_mode_t> {
137public:
138 Hwc2TestBlendMode(Hwc2TestCoverage coverage);
139
140 std::string dump() const override;
141
Marissa Wallee242782016-12-15 12:30:12 -0800142 void setDependent(Hwc2TestColor* color);
143
Marissa Wallffc67da2016-12-15 12:26:09 -0800144protected:
Marissa Wallee242782016-12-15 12:30:12 -0800145 void updateDependents() override;
146
147 Hwc2TestColor* mColor = nullptr;
148
Marissa Wallffc67da2016-12-15 12:26:09 -0800149 static const std::vector<hwc2_blend_mode_t> mDefaultBlendModes;
150 static const std::vector<hwc2_blend_mode_t> mBasicBlendModes;
151 static const std::vector<hwc2_blend_mode_t> mCompleteBlendModes;
152};
153
154
Marissa Wallee242782016-12-15 12:30:12 -0800155class Hwc2TestColor : public Hwc2TestProperty<hwc_color_t> {
156public:
157 Hwc2TestColor(Hwc2TestCoverage coverage,
158 hwc2_blend_mode_t blendMode = HWC2_BLEND_MODE_NONE);
159
160 std::string dump() const override;
161
162 void updateBlendMode(hwc2_blend_mode_t blendMode);
163
164protected:
165 void update();
166
167 std::vector<hwc_color_t> mBaseColors;
168 static const std::vector<hwc_color_t> mDefaultBaseColors;
169 static const std::vector<hwc_color_t> mBasicBaseColors;
170 static const std::vector<hwc_color_t> mCompleteBaseColors;
171
172 hwc2_blend_mode_t mBlendMode;
173
174 std::vector<hwc_color_t> mColors;
175};
176
177
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800178class Hwc2TestComposition : public Hwc2TestProperty<hwc2_composition_t> {
179public:
180 Hwc2TestComposition(Hwc2TestCoverage coverage);
181
182 std::string dump() const override;
183
184protected:
185 static const std::vector<hwc2_composition_t> mDefaultCompositions;
186 static const std::vector<hwc2_composition_t> mBasicCompositions;
187 static const std::vector<hwc2_composition_t> mCompleteCompositions;
188};
189
Marissa Wallb72b5c92016-12-15 12:26:39 -0800190
191class Hwc2TestDataspace : public Hwc2TestProperty<android_dataspace_t> {
192public:
193 Hwc2TestDataspace(Hwc2TestCoverage coverage);
194
195 std::string dump() const override;
196
197protected:
198 static const std::vector<android_dataspace_t> defaultDataspaces;
199 static const std::vector<android_dataspace_t> basicDataspaces;
200 static const std::vector<android_dataspace_t> completeDataspaces;
201};
202
Marissa Wall2b1f5302016-12-15 12:27:20 -0800203
Marissa Wall600a73b2016-12-15 12:30:39 -0800204class Hwc2TestDisplayFrame : public Hwc2TestProperty<hwc_rect_t> {
205public:
206 Hwc2TestDisplayFrame(Hwc2TestCoverage coverage, const Area& displayArea);
207
208 std::string dump() const override;
209
210protected:
211 void update();
212
213 const std::vector<hwc_frect_t>& mFrectScalars;
214 const static std::vector<hwc_frect_t> mDefaultFrectScalars;
215 const static std::vector<hwc_frect_t> mBasicFrectScalars;
216 const static std::vector<hwc_frect_t> mCompleteFrectScalars;
217
218 Area mDisplayArea;
219
220 std::vector<hwc_rect_t> mDisplayFrames;
221};
222
223
Marissa Wall2b1f5302016-12-15 12:27:20 -0800224class Hwc2TestPlaneAlpha : public Hwc2TestProperty<float> {
225public:
226 Hwc2TestPlaneAlpha(Hwc2TestCoverage coverage);
227
228 std::string dump() const override;
229
230protected:
231 static const std::vector<float> mDefaultPlaneAlphas;
232 static const std::vector<float> mBasicPlaneAlphas;
233 static const std::vector<float> mCompletePlaneAlphas;
234};
235
Marissa Wallac108192016-12-15 12:27:48 -0800236
Marissa Wallc57468f2016-12-15 12:31:12 -0800237class Hwc2TestSourceCrop : public Hwc2TestProperty<hwc_frect_t> {
238public:
239 Hwc2TestSourceCrop(Hwc2TestCoverage coverage, const Area& bufferArea = {0, 0});
240
241 std::string dump() const override;
242
243 void updateBufferArea(const Area& bufferArea);
244
245protected:
246 void update();
247
248 const std::vector<hwc_frect_t>& mFrectScalars;
249 const static std::vector<hwc_frect_t> mDefaultFrectScalars;
250 const static std::vector<hwc_frect_t> mBasicFrectScalars;
251 const static std::vector<hwc_frect_t> mCompleteFrectScalars;
252
253 Area mBufferArea;
254
255 std::vector<hwc_frect_t> mSourceCrops;
256};
257
258
Marissa Wallad761812016-12-15 12:32:24 -0800259class Hwc2TestSurfaceDamage : public Hwc2TestProperty<hwc_region_t> {
260public:
261 Hwc2TestSurfaceDamage(Hwc2TestCoverage coverage);
262 ~Hwc2TestSurfaceDamage();
263
264 std::string dump() const override;
265
266 void updateBufferArea(const Area& bufferArea);
267
268protected:
269 void update();
270 void freeSurfaceDamages();
271
272 const std::vector<std::vector<hwc_frect_t>> &mRegionScalars;
273 const static std::vector<std::vector<hwc_frect_t>> mDefaultRegionScalars;
274 const static std::vector<std::vector<hwc_frect_t>> mBasicRegionScalars;
275 const static std::vector<std::vector<hwc_frect_t>> mCompleteRegionScalars;
276
277 Area mBufferArea = {0, 0};
278
279 std::vector<hwc_region_t> mSurfaceDamages;
280};
281
282
Marissa Wallac108192016-12-15 12:27:48 -0800283class Hwc2TestTransform : public Hwc2TestProperty<hwc_transform_t> {
284public:
285 Hwc2TestTransform(Hwc2TestCoverage coverage);
286
287 std::string dump() const override;
288
289protected:
290 static const std::vector<hwc_transform_t> mDefaultTransforms;
291 static const std::vector<hwc_transform_t> mBasicTransforms;
292 static const std::vector<hwc_transform_t> mCompleteTransforms;
293};
294
Marissa Wallf7618ed2016-12-15 12:34:39 -0800295
296class Hwc2TestVisibleRegion {
297public:
298 ~Hwc2TestVisibleRegion();
299
300 std::string dump() const;
301
302 void set(const android::Region& visibleRegion);
303 hwc_region_t get() const;
304 void release();
305
306protected:
307 hwc_region_t mVisibleRegion = {0, nullptr};
308};
309
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800310#endif /* ifndef _HWC2_TEST_PROPERTIES_H */