blob: 048d6e95bc29c552352b3fa04cc5091ec39a4812 [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 Wall5a240aa2016-12-15 12:34:06 -080099class Hwc2TestBuffer;
Marissa Wallc57468f2016-12-15 12:31:12 -0800100class Hwc2TestSourceCrop;
Marissa Wallad761812016-12-15 12:32:24 -0800101class Hwc2TestSurfaceDamage;
Marissa Wallc57468f2016-12-15 12:31:12 -0800102
103class Hwc2TestBufferArea : public Hwc2TestProperty<Area> {
104public:
105 Hwc2TestBufferArea(Hwc2TestCoverage coverage, const Area& displayArea);
106
107 std::string dump() const override;
108
Marissa Wall5a240aa2016-12-15 12:34:06 -0800109 void setDependent(Hwc2TestBuffer* buffer);
Marissa Wallc57468f2016-12-15 12:31:12 -0800110 void setDependent(Hwc2TestSourceCrop* sourceCrop);
Marissa Wallad761812016-12-15 12:32:24 -0800111 void setDependent(Hwc2TestSurfaceDamage* surfaceDamage);
Marissa Wallc57468f2016-12-15 12:31:12 -0800112
113protected:
114 void update();
115 void updateDependents() override;
116
117 const std::vector<float>& mScalars;
118 static const std::vector<float> mDefaultScalars;
119 static const std::vector<float> mBasicScalars;
120 static const std::vector<float> mCompleteScalars;
121
122 Area mDisplayArea;
123
Marissa Wall5a240aa2016-12-15 12:34:06 -0800124 Hwc2TestBuffer* mBuffer = nullptr;
Marissa Wallc57468f2016-12-15 12:31:12 -0800125 Hwc2TestSourceCrop* mSourceCrop = nullptr;
Marissa Wallad761812016-12-15 12:32:24 -0800126 Hwc2TestSurfaceDamage* mSurfaceDamage = nullptr;
Marissa Wallc57468f2016-12-15 12:31:12 -0800127
128 std::vector<Area> mBufferAreas;
129};
130
131
Marissa Wallee242782016-12-15 12:30:12 -0800132class Hwc2TestColor;
133
Marissa Wallffc67da2016-12-15 12:26:09 -0800134class Hwc2TestBlendMode : public Hwc2TestProperty<hwc2_blend_mode_t> {
135public:
136 Hwc2TestBlendMode(Hwc2TestCoverage coverage);
137
138 std::string dump() const override;
139
Marissa Wallee242782016-12-15 12:30:12 -0800140 void setDependent(Hwc2TestColor* color);
141
Marissa Wallffc67da2016-12-15 12:26:09 -0800142protected:
Marissa Wallee242782016-12-15 12:30:12 -0800143 void updateDependents() override;
144
145 Hwc2TestColor* mColor = nullptr;
146
Marissa Wallffc67da2016-12-15 12:26:09 -0800147 static const std::vector<hwc2_blend_mode_t> mDefaultBlendModes;
148 static const std::vector<hwc2_blend_mode_t> mBasicBlendModes;
149 static const std::vector<hwc2_blend_mode_t> mCompleteBlendModes;
150};
151
152
Marissa Wallee242782016-12-15 12:30:12 -0800153class Hwc2TestColor : public Hwc2TestProperty<hwc_color_t> {
154public:
155 Hwc2TestColor(Hwc2TestCoverage coverage,
156 hwc2_blend_mode_t blendMode = HWC2_BLEND_MODE_NONE);
157
158 std::string dump() const override;
159
160 void updateBlendMode(hwc2_blend_mode_t blendMode);
161
162protected:
163 void update();
164
165 std::vector<hwc_color_t> mBaseColors;
166 static const std::vector<hwc_color_t> mDefaultBaseColors;
167 static const std::vector<hwc_color_t> mBasicBaseColors;
168 static const std::vector<hwc_color_t> mCompleteBaseColors;
169
170 hwc2_blend_mode_t mBlendMode;
171
172 std::vector<hwc_color_t> mColors;
173};
174
175
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800176class Hwc2TestComposition : public Hwc2TestProperty<hwc2_composition_t> {
177public:
178 Hwc2TestComposition(Hwc2TestCoverage coverage);
179
180 std::string dump() const override;
181
182protected:
183 static const std::vector<hwc2_composition_t> mDefaultCompositions;
184 static const std::vector<hwc2_composition_t> mBasicCompositions;
185 static const std::vector<hwc2_composition_t> mCompleteCompositions;
186};
187
Marissa Wallb72b5c92016-12-15 12:26:39 -0800188
189class Hwc2TestDataspace : public Hwc2TestProperty<android_dataspace_t> {
190public:
191 Hwc2TestDataspace(Hwc2TestCoverage coverage);
192
193 std::string dump() const override;
194
195protected:
196 static const std::vector<android_dataspace_t> defaultDataspaces;
197 static const std::vector<android_dataspace_t> basicDataspaces;
198 static const std::vector<android_dataspace_t> completeDataspaces;
199};
200
Marissa Wall2b1f5302016-12-15 12:27:20 -0800201
Marissa Wall600a73b2016-12-15 12:30:39 -0800202class Hwc2TestDisplayFrame : public Hwc2TestProperty<hwc_rect_t> {
203public:
204 Hwc2TestDisplayFrame(Hwc2TestCoverage coverage, const Area& displayArea);
205
206 std::string dump() const override;
207
208protected:
209 void update();
210
211 const std::vector<hwc_frect_t>& mFrectScalars;
212 const static std::vector<hwc_frect_t> mDefaultFrectScalars;
213 const static std::vector<hwc_frect_t> mBasicFrectScalars;
214 const static std::vector<hwc_frect_t> mCompleteFrectScalars;
215
216 Area mDisplayArea;
217
218 std::vector<hwc_rect_t> mDisplayFrames;
219};
220
221
Marissa Wall2b1f5302016-12-15 12:27:20 -0800222class Hwc2TestPlaneAlpha : public Hwc2TestProperty<float> {
223public:
224 Hwc2TestPlaneAlpha(Hwc2TestCoverage coverage);
225
226 std::string dump() const override;
227
228protected:
229 static const std::vector<float> mDefaultPlaneAlphas;
230 static const std::vector<float> mBasicPlaneAlphas;
231 static const std::vector<float> mCompletePlaneAlphas;
232};
233
Marissa Wallac108192016-12-15 12:27:48 -0800234
Marissa Wallc57468f2016-12-15 12:31:12 -0800235class Hwc2TestSourceCrop : public Hwc2TestProperty<hwc_frect_t> {
236public:
237 Hwc2TestSourceCrop(Hwc2TestCoverage coverage, const Area& bufferArea = {0, 0});
238
239 std::string dump() const override;
240
241 void updateBufferArea(const Area& bufferArea);
242
243protected:
244 void update();
245
246 const std::vector<hwc_frect_t>& mFrectScalars;
247 const static std::vector<hwc_frect_t> mDefaultFrectScalars;
248 const static std::vector<hwc_frect_t> mBasicFrectScalars;
249 const static std::vector<hwc_frect_t> mCompleteFrectScalars;
250
251 Area mBufferArea;
252
253 std::vector<hwc_frect_t> mSourceCrops;
254};
255
256
Marissa Wallad761812016-12-15 12:32:24 -0800257class Hwc2TestSurfaceDamage : public Hwc2TestProperty<hwc_region_t> {
258public:
259 Hwc2TestSurfaceDamage(Hwc2TestCoverage coverage);
260 ~Hwc2TestSurfaceDamage();
261
262 std::string dump() const override;
263
264 void updateBufferArea(const Area& bufferArea);
265
266protected:
267 void update();
268 void freeSurfaceDamages();
269
270 const std::vector<std::vector<hwc_frect_t>> &mRegionScalars;
271 const static std::vector<std::vector<hwc_frect_t>> mDefaultRegionScalars;
272 const static std::vector<std::vector<hwc_frect_t>> mBasicRegionScalars;
273 const static std::vector<std::vector<hwc_frect_t>> mCompleteRegionScalars;
274
275 Area mBufferArea = {0, 0};
276
277 std::vector<hwc_region_t> mSurfaceDamages;
278};
279
280
Marissa Wallac108192016-12-15 12:27:48 -0800281class Hwc2TestTransform : public Hwc2TestProperty<hwc_transform_t> {
282public:
283 Hwc2TestTransform(Hwc2TestCoverage coverage);
284
285 std::string dump() const override;
286
287protected:
288 static const std::vector<hwc_transform_t> mDefaultTransforms;
289 static const std::vector<hwc_transform_t> mBasicTransforms;
290 static const std::vector<hwc_transform_t> mCompleteTransforms;
291};
292
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800293#endif /* ifndef _HWC2_TEST_PROPERTIES_H */