Hwc2TestProperties.h revision 34beb7a0ff0494b0c5ad81104171f8a49e599163
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#include <ui/GraphicTypes.h>
24#include <ui/Region.h>
25
26#define HWC2_INCLUDE_STRINGIFICATION
27#define HWC2_USE_CPP11
28#include <hardware/hwcomposer2.h>
29#undef HWC2_INCLUDE_STRINGIFICATION
30#undef HWC2_USE_CPP11
31
32enum class Hwc2TestCoverage {
33    Default = 0,
34    Basic,
35    Complete,
36};
37
38enum class Hwc2TestPropertyName {
39    BlendMode = 1,
40    BufferArea,
41    Color,
42    Composition,
43    CursorPosition,
44    Dataspace,
45    DisplayFrame,
46    PlaneAlpha,
47    SourceCrop,
48    SurfaceDamage,
49    Transform,
50};
51
52typedef struct {
53    int32_t width;
54    int32_t height;
55} Area;
56
57
58typedef struct {
59    uint32_t width;
60    uint32_t height;
61} UnsignedArea;
62
63
64class Hwc2TestContainer {
65public:
66    virtual ~Hwc2TestContainer() = default;
67
68    /* Resets the container */
69    virtual void reset() = 0;
70
71    /* Attempts to advance to the next valid value. Returns true if one can be
72     * found */
73    virtual bool advance() = 0;
74
75    virtual std::string dump() const = 0;
76
77    /* Returns true if the container supports the given composition type */
78    virtual bool isSupported(hwc2_composition_t composition) = 0;
79};
80
81
82template <class T>
83class Hwc2TestProperty : public Hwc2TestContainer {
84public:
85    Hwc2TestProperty(Hwc2TestCoverage coverage,
86            const std::vector<T>& completeList, const std::vector<T>& basicList,
87            const std::vector<T>& defaultList,
88            const std::array<bool, 6>& compositionSupport)
89        : Hwc2TestProperty((coverage == Hwc2TestCoverage::Complete)? completeList:
90                (coverage == Hwc2TestCoverage::Basic)? basicList : defaultList,
91                compositionSupport) { }
92
93    Hwc2TestProperty(const std::vector<T>& list,
94            const std::array<bool, 6>& compositionSupport)
95        : mList(list),
96          mCompositionSupport(compositionSupport) { }
97
98    void reset() override
99    {
100        mListIdx = 0;
101    }
102
103    bool advance() override
104    {
105        if (mListIdx + 1 < mList.size()) {
106            mListIdx++;
107            updateDependents();
108            return true;
109        }
110        reset();
111        updateDependents();
112        return false;
113    }
114
115    T get() const
116    {
117        return mList.at(mListIdx);
118    }
119
120    virtual bool isSupported(hwc2_composition_t composition)
121    {
122        return mCompositionSupport.at(composition);
123    }
124
125protected:
126    /* If a derived class has dependents, override this function */
127    virtual void updateDependents() { }
128
129    const std::vector<T>& mList;
130    size_t mListIdx = 0;
131
132    const std::array<bool, 6>& mCompositionSupport;
133};
134
135class Hwc2TestBuffer;
136class Hwc2TestSourceCrop;
137class Hwc2TestSurfaceDamage;
138
139class Hwc2TestBufferArea : public Hwc2TestProperty<Area> {
140public:
141    Hwc2TestBufferArea(Hwc2TestCoverage coverage, const Area& displayArea);
142
143    std::string dump() const override;
144
145    void setDependent(Hwc2TestBuffer* buffer);
146    void setDependent(Hwc2TestSourceCrop* sourceCrop);
147    void setDependent(Hwc2TestSurfaceDamage* surfaceDamage);
148
149protected:
150    void update();
151    void updateDependents() override;
152
153    const std::vector<float>& mScalars;
154    static const std::vector<float> mDefaultScalars;
155    static const std::vector<float> mBasicScalars;
156    static const std::vector<float> mCompleteScalars;
157
158    Area mDisplayArea;
159
160    Hwc2TestBuffer* mBuffer = nullptr;
161    Hwc2TestSourceCrop* mSourceCrop = nullptr;
162    Hwc2TestSurfaceDamage* mSurfaceDamage = nullptr;
163
164    std::vector<Area> mBufferAreas;
165
166    static const std::array<bool, 6> mCompositionSupport;
167};
168
169
170class Hwc2TestColor;
171
172class Hwc2TestBlendMode : public Hwc2TestProperty<hwc2_blend_mode_t> {
173public:
174    Hwc2TestBlendMode(Hwc2TestCoverage coverage);
175
176    std::string dump() const override;
177
178    void setDependent(Hwc2TestColor* color);
179
180protected:
181    void updateDependents() override;
182
183    Hwc2TestColor* mColor = nullptr;
184
185    static const std::vector<hwc2_blend_mode_t> mDefaultBlendModes;
186    static const std::vector<hwc2_blend_mode_t> mBasicBlendModes;
187    static const std::vector<hwc2_blend_mode_t> mCompleteBlendModes;
188
189    static const std::array<bool, 6> mCompositionSupport;
190};
191
192
193class Hwc2TestColor : public Hwc2TestProperty<hwc_color_t> {
194public:
195    Hwc2TestColor(Hwc2TestCoverage coverage,
196            hwc2_blend_mode_t blendMode = HWC2_BLEND_MODE_NONE);
197
198    std::string dump() const override;
199
200    void updateBlendMode(hwc2_blend_mode_t blendMode);
201
202protected:
203    void update();
204
205    std::vector<hwc_color_t> mBaseColors;
206    static const std::vector<hwc_color_t> mDefaultBaseColors;
207    static const std::vector<hwc_color_t> mBasicBaseColors;
208    static const std::vector<hwc_color_t> mCompleteBaseColors;
209
210    hwc2_blend_mode_t mBlendMode;
211
212    std::vector<hwc_color_t> mColors;
213
214    static const std::array<bool, 6> mCompositionSupport;
215};
216
217
218class Hwc2TestComposition : public Hwc2TestProperty<hwc2_composition_t> {
219public:
220    Hwc2TestComposition(Hwc2TestCoverage coverage);
221
222    std::string dump() const override;
223
224protected:
225    static const std::vector<hwc2_composition_t> mDefaultCompositions;
226    static const std::vector<hwc2_composition_t> mBasicCompositions;
227    static const std::vector<hwc2_composition_t> mCompleteCompositions;
228
229    static const std::array<bool, 6> mCompositionSupport;
230};
231
232
233class Hwc2TestDataspace : public Hwc2TestProperty<android::ui::Dataspace> {
234public:
235    Hwc2TestDataspace(Hwc2TestCoverage coverage);
236
237    std::string dump() const override;
238
239protected:
240    static const std::vector<android::ui::Dataspace> defaultDataspaces;
241    static const std::vector<android::ui::Dataspace> basicDataspaces;
242    static const std::vector<android::ui::Dataspace> completeDataspaces;
243
244    static const std::array<bool, 6> mCompositionSupport;
245};
246
247class Hwc2TestVirtualBuffer;
248
249class Hwc2TestDisplayDimension : public Hwc2TestProperty<UnsignedArea> {
250public:
251    Hwc2TestDisplayDimension(Hwc2TestCoverage coverage);
252
253    std::string dump() const;
254
255    void setDependent(Hwc2TestVirtualBuffer* buffer);
256
257private:
258    void updateDependents();
259
260    std::set<Hwc2TestVirtualBuffer*> mBuffers;
261
262    static const std::vector<UnsignedArea> mDefaultDisplayDimensions;
263    static const std::vector<UnsignedArea> mBasicDisplayDimensions;
264    static const std::vector<UnsignedArea> mCompleteDisplayDimensions;
265
266    static const std::array<bool, 6> mCompositionSupport;
267};
268
269
270class Hwc2TestDisplayFrame : public Hwc2TestProperty<hwc_rect_t> {
271public:
272    Hwc2TestDisplayFrame(Hwc2TestCoverage coverage, const Area& displayArea);
273
274    std::string dump() const override;
275
276protected:
277    void update();
278
279    const std::vector<hwc_frect_t>& mFrectScalars;
280    const static std::vector<hwc_frect_t> mDefaultFrectScalars;
281    const static std::vector<hwc_frect_t> mBasicFrectScalars;
282    const static std::vector<hwc_frect_t> mCompleteFrectScalars;
283
284    Area mDisplayArea;
285
286    std::vector<hwc_rect_t> mDisplayFrames;
287
288    static const std::array<bool, 6> mCompositionSupport;
289};
290
291
292class Hwc2TestPlaneAlpha : public Hwc2TestProperty<float> {
293public:
294    Hwc2TestPlaneAlpha(Hwc2TestCoverage coverage);
295
296    std::string dump() const override;
297
298protected:
299    static const std::vector<float> mDefaultPlaneAlphas;
300    static const std::vector<float> mBasicPlaneAlphas;
301    static const std::vector<float> mCompletePlaneAlphas;
302
303    static const std::array<bool, 6> mCompositionSupport;
304};
305
306
307class Hwc2TestSourceCrop : public Hwc2TestProperty<hwc_frect_t> {
308public:
309    Hwc2TestSourceCrop(Hwc2TestCoverage coverage, const Area& bufferArea = {0, 0});
310
311    std::string dump() const override;
312
313    void updateBufferArea(const Area& bufferArea);
314
315protected:
316    void update();
317
318    const std::vector<hwc_frect_t>& mFrectScalars;
319    const static std::vector<hwc_frect_t> mDefaultFrectScalars;
320    const static std::vector<hwc_frect_t> mBasicFrectScalars;
321    const static std::vector<hwc_frect_t> mCompleteFrectScalars;
322
323    Area mBufferArea;
324
325    std::vector<hwc_frect_t> mSourceCrops;
326
327    static const std::array<bool, 6> mCompositionSupport;
328};
329
330
331class Hwc2TestSurfaceDamage : public Hwc2TestProperty<hwc_region_t> {
332public:
333    Hwc2TestSurfaceDamage(Hwc2TestCoverage coverage);
334    ~Hwc2TestSurfaceDamage();
335
336    std::string dump() const override;
337
338    void updateBufferArea(const Area& bufferArea);
339
340protected:
341    void update();
342    void freeSurfaceDamages();
343
344    const std::vector<std::vector<hwc_frect_t>> &mRegionScalars;
345    const static std::vector<std::vector<hwc_frect_t>> mDefaultRegionScalars;
346    const static std::vector<std::vector<hwc_frect_t>> mBasicRegionScalars;
347    const static std::vector<std::vector<hwc_frect_t>> mCompleteRegionScalars;
348
349    Area mBufferArea = {0, 0};
350
351    std::vector<hwc_region_t> mSurfaceDamages;
352
353    static const std::array<bool, 6> mCompositionSupport;
354};
355
356
357class Hwc2TestTransform : public Hwc2TestProperty<hwc_transform_t> {
358public:
359    Hwc2TestTransform(Hwc2TestCoverage coverage);
360
361    std::string dump() const override;
362
363protected:
364    static const std::vector<hwc_transform_t> mDefaultTransforms;
365    static const std::vector<hwc_transform_t> mBasicTransforms;
366    static const std::vector<hwc_transform_t> mCompleteTransforms;
367
368    static const std::array<bool, 6> mCompositionSupport;
369};
370
371
372class Hwc2TestVisibleRegion {
373public:
374    ~Hwc2TestVisibleRegion();
375
376    std::string dump() const;
377
378    void set(const android::Region& visibleRegion);
379    hwc_region_t get() const;
380    void release();
381
382protected:
383    hwc_region_t mVisibleRegion = {0, nullptr};
384};
385
386#endif /* ifndef _HWC2_TEST_PROPERTIES_H */
387