Hwc2TestProperties.h revision ad761818a4426b4e6a0696ba90e05056aa35553c
1/*
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
20#include <array>
21#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
35typedef struct {
36    int32_t width;
37    int32_t height;
38} Area;
39
40
41class Hwc2TestContainer {
42public:
43    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
65    Hwc2TestProperty(const std::vector<T>& list)
66        : mList(list) { }
67
68    void reset() override
69    {
70        mListIdx = 0;
71    }
72
73    bool advance() override
74    {
75        if (mListIdx + 1 < mList.size()) {
76            mListIdx++;
77            updateDependents();
78            return true;
79        }
80        reset();
81        updateDependents();
82        return false;
83    }
84
85    T get() const
86    {
87        return mList.at(mListIdx);
88    }
89
90protected:
91    /* If a derived class has dependents, override this function */
92    virtual void updateDependents() { }
93
94    const std::vector<T>& mList;
95    size_t mListIdx = 0;
96};
97
98
99class Hwc2TestSourceCrop;
100class Hwc2TestSurfaceDamage;
101
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);
109    void setDependent(Hwc2TestSurfaceDamage* surfaceDamage);
110
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;
123    Hwc2TestSurfaceDamage* mSurfaceDamage = nullptr;
124
125    std::vector<Area> mBufferAreas;
126};
127
128
129class Hwc2TestColor;
130
131class Hwc2TestBlendMode : public Hwc2TestProperty<hwc2_blend_mode_t> {
132public:
133    Hwc2TestBlendMode(Hwc2TestCoverage coverage);
134
135    std::string dump() const override;
136
137    void setDependent(Hwc2TestColor* color);
138
139protected:
140    void updateDependents() override;
141
142    Hwc2TestColor* mColor = nullptr;
143
144    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
150class 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
173class 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
185
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
198
199class 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
219class 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
231
232class 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
254class 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
278class 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
290#endif /* ifndef _HWC2_TEST_PROPERTIES_H */
291