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