Hwc2TestProperties.h revision c57468f1f6dfc870bea10e814a686793e64f6cf3
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;
100
101class Hwc2TestBufferArea : public Hwc2TestProperty<Area> {
102public:
103    Hwc2TestBufferArea(Hwc2TestCoverage coverage, const Area& displayArea);
104
105    std::string dump() const override;
106
107    void setDependent(Hwc2TestSourceCrop* sourceCrop);
108
109protected:
110    void update();
111    void updateDependents() override;
112
113    const std::vector<float>& mScalars;
114    static const std::vector<float> mDefaultScalars;
115    static const std::vector<float> mBasicScalars;
116    static const std::vector<float> mCompleteScalars;
117
118    Area mDisplayArea;
119
120    Hwc2TestSourceCrop* mSourceCrop = nullptr;
121
122    std::vector<Area> mBufferAreas;
123};
124
125
126class Hwc2TestBlendMode : public Hwc2TestProperty<hwc2_blend_mode_t> {
127public:
128    Hwc2TestBlendMode(Hwc2TestCoverage coverage);
129
130    std::string dump() const override;
131
132protected:
133    static const std::vector<hwc2_blend_mode_t> mDefaultBlendModes;
134    static const std::vector<hwc2_blend_mode_t> mBasicBlendModes;
135    static const std::vector<hwc2_blend_mode_t> mCompleteBlendModes;
136};
137
138
139class Hwc2TestComposition : public Hwc2TestProperty<hwc2_composition_t> {
140public:
141    Hwc2TestComposition(Hwc2TestCoverage coverage);
142
143    std::string dump() const override;
144
145protected:
146    static const std::vector<hwc2_composition_t> mDefaultCompositions;
147    static const std::vector<hwc2_composition_t> mBasicCompositions;
148    static const std::vector<hwc2_composition_t> mCompleteCompositions;
149};
150
151
152class Hwc2TestDataspace : public Hwc2TestProperty<android_dataspace_t> {
153public:
154    Hwc2TestDataspace(Hwc2TestCoverage coverage);
155
156    std::string dump() const override;
157
158protected:
159    static const std::vector<android_dataspace_t> defaultDataspaces;
160    static const std::vector<android_dataspace_t> basicDataspaces;
161    static const std::vector<android_dataspace_t> completeDataspaces;
162};
163
164
165class Hwc2TestDisplayFrame : public Hwc2TestProperty<hwc_rect_t> {
166public:
167    Hwc2TestDisplayFrame(Hwc2TestCoverage coverage, const Area& displayArea);
168
169    std::string dump() const override;
170
171protected:
172    void update();
173
174    const std::vector<hwc_frect_t>& mFrectScalars;
175    const static std::vector<hwc_frect_t> mDefaultFrectScalars;
176    const static std::vector<hwc_frect_t> mBasicFrectScalars;
177    const static std::vector<hwc_frect_t> mCompleteFrectScalars;
178
179    Area mDisplayArea;
180
181    std::vector<hwc_rect_t> mDisplayFrames;
182};
183
184
185class Hwc2TestPlaneAlpha : public Hwc2TestProperty<float> {
186public:
187    Hwc2TestPlaneAlpha(Hwc2TestCoverage coverage);
188
189    std::string dump() const override;
190
191protected:
192    static const std::vector<float> mDefaultPlaneAlphas;
193    static const std::vector<float> mBasicPlaneAlphas;
194    static const std::vector<float> mCompletePlaneAlphas;
195};
196
197
198class Hwc2TestSourceCrop : public Hwc2TestProperty<hwc_frect_t> {
199public:
200    Hwc2TestSourceCrop(Hwc2TestCoverage coverage, const Area& bufferArea = {0, 0});
201
202    std::string dump() const override;
203
204    void updateBufferArea(const Area& bufferArea);
205
206protected:
207    void update();
208
209    const std::vector<hwc_frect_t>& mFrectScalars;
210    const static std::vector<hwc_frect_t> mDefaultFrectScalars;
211    const static std::vector<hwc_frect_t> mBasicFrectScalars;
212    const static std::vector<hwc_frect_t> mCompleteFrectScalars;
213
214    Area mBufferArea;
215
216    std::vector<hwc_frect_t> mSourceCrops;
217};
218
219
220class Hwc2TestTransform : public Hwc2TestProperty<hwc_transform_t> {
221public:
222    Hwc2TestTransform(Hwc2TestCoverage coverage);
223
224    std::string dump() const override;
225
226protected:
227    static const std::vector<hwc_transform_t> mDefaultTransforms;
228    static const std::vector<hwc_transform_t> mBasicTransforms;
229    static const std::vector<hwc_transform_t> mCompleteTransforms;
230};
231
232#endif /* ifndef _HWC2_TEST_PROPERTIES_H */
233