blob: 6f3bd0f43876a77f3d39582d1ae452c113179526 [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
23#define HWC2_INCLUDE_STRINGIFICATION
24#define HWC2_USE_CPP11
25#include <hardware/hwcomposer2.h>
26#undef HWC2_INCLUDE_STRINGIFICATION
27#undef HWC2_USE_CPP11
28
29enum class Hwc2TestCoverage {
30 Default = 0,
31 Basic,
32 Complete,
33};
34
Marissa Wall600a73b2016-12-15 12:30:39 -080035typedef struct {
36 int32_t width;
37 int32_t height;
38} Area;
39
Marissa Wall6bd8bfd2016-12-15 12:25:31 -080040
Marissa Wallffc67da2016-12-15 12:26:09 -080041class Hwc2TestContainer {
Marissa Wall6bd8bfd2016-12-15 12:25:31 -080042public:
Marissa Wallffc67da2016-12-15 12:26:09 -080043 virtual ~Hwc2TestContainer() = default;
44
45 /* Resets the container */
46 virtual void reset() = 0;
47
48 /* Attempts to advance to the next valid value. Returns true if one can be
49 * found */
50 virtual bool advance() = 0;
51
52 virtual std::string dump() const = 0;
53};
54
55
56template <class T>
57class Hwc2TestProperty : public Hwc2TestContainer {
58public:
59 Hwc2TestProperty(Hwc2TestCoverage coverage,
60 const std::vector<T>& completeList, const std::vector<T>& basicList,
61 const std::vector<T>& defaultList)
62 : Hwc2TestProperty((coverage == Hwc2TestCoverage::Complete)? completeList:
63 (coverage == Hwc2TestCoverage::Basic)? basicList : defaultList) { }
64
Marissa Wall6bd8bfd2016-12-15 12:25:31 -080065 Hwc2TestProperty(const std::vector<T>& list)
66 : mList(list) { }
67
Marissa Wallffc67da2016-12-15 12:26:09 -080068 void reset() override
Marissa Wall6bd8bfd2016-12-15 12:25:31 -080069 {
70 mListIdx = 0;
71 }
72
Marissa Wallffc67da2016-12-15 12:26:09 -080073 bool advance() override
Marissa Wall6bd8bfd2016-12-15 12:25:31 -080074 {
75 if (mListIdx + 1 < mList.size()) {
76 mListIdx++;
Marissa Wallc57468f2016-12-15 12:31:12 -080077 updateDependents();
Marissa Wall6bd8bfd2016-12-15 12:25:31 -080078 return true;
79 }
80 reset();
Marissa Wallc57468f2016-12-15 12:31:12 -080081 updateDependents();
Marissa Wall6bd8bfd2016-12-15 12:25:31 -080082 return false;
83 }
84
Marissa Wallffc67da2016-12-15 12:26:09 -080085 T get() const
Marissa Wall6bd8bfd2016-12-15 12:25:31 -080086 {
87 return mList.at(mListIdx);
88 }
89
Marissa Wall6bd8bfd2016-12-15 12:25:31 -080090protected:
Marissa Wallc57468f2016-12-15 12:31:12 -080091 /* If a derived class has dependents, override this function */
92 virtual void updateDependents() { }
93
Marissa Wall6bd8bfd2016-12-15 12:25:31 -080094 const std::vector<T>& mList;
95 size_t mListIdx = 0;
96};
97
98
Marissa Wallc57468f2016-12-15 12:31:12 -080099class Hwc2TestSourceCrop;
Marissa Wallad761812016-12-15 12:32:24 -0800100class Hwc2TestSurfaceDamage;
Marissa Wallc57468f2016-12-15 12:31:12 -0800101
102class Hwc2TestBufferArea : public Hwc2TestProperty<Area> {
103public:
104 Hwc2TestBufferArea(Hwc2TestCoverage coverage, const Area& displayArea);
105
106 std::string dump() const override;
107
108 void setDependent(Hwc2TestSourceCrop* sourceCrop);
Marissa Wallad761812016-12-15 12:32:24 -0800109 void setDependent(Hwc2TestSurfaceDamage* surfaceDamage);
Marissa Wallc57468f2016-12-15 12:31:12 -0800110
111protected:
112 void update();
113 void updateDependents() override;
114
115 const std::vector<float>& mScalars;
116 static const std::vector<float> mDefaultScalars;
117 static const std::vector<float> mBasicScalars;
118 static const std::vector<float> mCompleteScalars;
119
120 Area mDisplayArea;
121
122 Hwc2TestSourceCrop* mSourceCrop = nullptr;
Marissa Wallad761812016-12-15 12:32:24 -0800123 Hwc2TestSurfaceDamage* mSurfaceDamage = nullptr;
Marissa Wallc57468f2016-12-15 12:31:12 -0800124
125 std::vector<Area> mBufferAreas;
126};
127
128
Marissa Wallee242782016-12-15 12:30:12 -0800129class Hwc2TestColor;
130
Marissa Wallffc67da2016-12-15 12:26:09 -0800131class Hwc2TestBlendMode : public Hwc2TestProperty<hwc2_blend_mode_t> {
132public:
133 Hwc2TestBlendMode(Hwc2TestCoverage coverage);
134
135 std::string dump() const override;
136
Marissa Wallee242782016-12-15 12:30:12 -0800137 void setDependent(Hwc2TestColor* color);
138
Marissa Wallffc67da2016-12-15 12:26:09 -0800139protected:
Marissa Wallee242782016-12-15 12:30:12 -0800140 void updateDependents() override;
141
142 Hwc2TestColor* mColor = nullptr;
143
Marissa Wallffc67da2016-12-15 12:26:09 -0800144 static const std::vector<hwc2_blend_mode_t> mDefaultBlendModes;
145 static const std::vector<hwc2_blend_mode_t> mBasicBlendModes;
146 static const std::vector<hwc2_blend_mode_t> mCompleteBlendModes;
147};
148
149
Marissa Wallee242782016-12-15 12:30:12 -0800150class Hwc2TestColor : public Hwc2TestProperty<hwc_color_t> {
151public:
152 Hwc2TestColor(Hwc2TestCoverage coverage,
153 hwc2_blend_mode_t blendMode = HWC2_BLEND_MODE_NONE);
154
155 std::string dump() const override;
156
157 void updateBlendMode(hwc2_blend_mode_t blendMode);
158
159protected:
160 void update();
161
162 std::vector<hwc_color_t> mBaseColors;
163 static const std::vector<hwc_color_t> mDefaultBaseColors;
164 static const std::vector<hwc_color_t> mBasicBaseColors;
165 static const std::vector<hwc_color_t> mCompleteBaseColors;
166
167 hwc2_blend_mode_t mBlendMode;
168
169 std::vector<hwc_color_t> mColors;
170};
171
172
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800173class Hwc2TestComposition : public Hwc2TestProperty<hwc2_composition_t> {
174public:
175 Hwc2TestComposition(Hwc2TestCoverage coverage);
176
177 std::string dump() const override;
178
179protected:
180 static const std::vector<hwc2_composition_t> mDefaultCompositions;
181 static const std::vector<hwc2_composition_t> mBasicCompositions;
182 static const std::vector<hwc2_composition_t> mCompleteCompositions;
183};
184
Marissa Wallb72b5c92016-12-15 12:26:39 -0800185
186class Hwc2TestDataspace : public Hwc2TestProperty<android_dataspace_t> {
187public:
188 Hwc2TestDataspace(Hwc2TestCoverage coverage);
189
190 std::string dump() const override;
191
192protected:
193 static const std::vector<android_dataspace_t> defaultDataspaces;
194 static const std::vector<android_dataspace_t> basicDataspaces;
195 static const std::vector<android_dataspace_t> completeDataspaces;
196};
197
Marissa Wall2b1f5302016-12-15 12:27:20 -0800198
Marissa Wall600a73b2016-12-15 12:30:39 -0800199class Hwc2TestDisplayFrame : public Hwc2TestProperty<hwc_rect_t> {
200public:
201 Hwc2TestDisplayFrame(Hwc2TestCoverage coverage, const Area& displayArea);
202
203 std::string dump() const override;
204
205protected:
206 void update();
207
208 const std::vector<hwc_frect_t>& mFrectScalars;
209 const static std::vector<hwc_frect_t> mDefaultFrectScalars;
210 const static std::vector<hwc_frect_t> mBasicFrectScalars;
211 const static std::vector<hwc_frect_t> mCompleteFrectScalars;
212
213 Area mDisplayArea;
214
215 std::vector<hwc_rect_t> mDisplayFrames;
216};
217
218
Marissa Wall2b1f5302016-12-15 12:27:20 -0800219class Hwc2TestPlaneAlpha : public Hwc2TestProperty<float> {
220public:
221 Hwc2TestPlaneAlpha(Hwc2TestCoverage coverage);
222
223 std::string dump() const override;
224
225protected:
226 static const std::vector<float> mDefaultPlaneAlphas;
227 static const std::vector<float> mBasicPlaneAlphas;
228 static const std::vector<float> mCompletePlaneAlphas;
229};
230
Marissa Wallac108192016-12-15 12:27:48 -0800231
Marissa Wallc57468f2016-12-15 12:31:12 -0800232class Hwc2TestSourceCrop : public Hwc2TestProperty<hwc_frect_t> {
233public:
234 Hwc2TestSourceCrop(Hwc2TestCoverage coverage, const Area& bufferArea = {0, 0});
235
236 std::string dump() const override;
237
238 void updateBufferArea(const Area& bufferArea);
239
240protected:
241 void update();
242
243 const std::vector<hwc_frect_t>& mFrectScalars;
244 const static std::vector<hwc_frect_t> mDefaultFrectScalars;
245 const static std::vector<hwc_frect_t> mBasicFrectScalars;
246 const static std::vector<hwc_frect_t> mCompleteFrectScalars;
247
248 Area mBufferArea;
249
250 std::vector<hwc_frect_t> mSourceCrops;
251};
252
253
Marissa Wallad761812016-12-15 12:32:24 -0800254class Hwc2TestSurfaceDamage : public Hwc2TestProperty<hwc_region_t> {
255public:
256 Hwc2TestSurfaceDamage(Hwc2TestCoverage coverage);
257 ~Hwc2TestSurfaceDamage();
258
259 std::string dump() const override;
260
261 void updateBufferArea(const Area& bufferArea);
262
263protected:
264 void update();
265 void freeSurfaceDamages();
266
267 const std::vector<std::vector<hwc_frect_t>> &mRegionScalars;
268 const static std::vector<std::vector<hwc_frect_t>> mDefaultRegionScalars;
269 const static std::vector<std::vector<hwc_frect_t>> mBasicRegionScalars;
270 const static std::vector<std::vector<hwc_frect_t>> mCompleteRegionScalars;
271
272 Area mBufferArea = {0, 0};
273
274 std::vector<hwc_region_t> mSurfaceDamages;
275};
276
277
Marissa Wallac108192016-12-15 12:27:48 -0800278class Hwc2TestTransform : public Hwc2TestProperty<hwc_transform_t> {
279public:
280 Hwc2TestTransform(Hwc2TestCoverage coverage);
281
282 std::string dump() const override;
283
284protected:
285 static const std::vector<hwc_transform_t> mDefaultTransforms;
286 static const std::vector<hwc_transform_t> mBasicTransforms;
287 static const std::vector<hwc_transform_t> mCompleteTransforms;
288};
289
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800290#endif /* ifndef _HWC2_TEST_PROPERTIES_H */