blob: 25c6ad871725c3886f75788bb3922ae3ba0d0a8f [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++;
77 return true;
78 }
79 reset();
80 return false;
81 }
82
Marissa Wallffc67da2016-12-15 12:26:09 -080083 T get() const
Marissa Wall6bd8bfd2016-12-15 12:25:31 -080084 {
85 return mList.at(mListIdx);
86 }
87
Marissa Wall6bd8bfd2016-12-15 12:25:31 -080088protected:
89 const std::vector<T>& mList;
90 size_t mListIdx = 0;
91};
92
93
Marissa Wallffc67da2016-12-15 12:26:09 -080094class Hwc2TestBlendMode : public Hwc2TestProperty<hwc2_blend_mode_t> {
95public:
96 Hwc2TestBlendMode(Hwc2TestCoverage coverage);
97
98 std::string dump() const override;
99
100protected:
101 static const std::vector<hwc2_blend_mode_t> mDefaultBlendModes;
102 static const std::vector<hwc2_blend_mode_t> mBasicBlendModes;
103 static const std::vector<hwc2_blend_mode_t> mCompleteBlendModes;
104};
105
106
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800107class Hwc2TestComposition : public Hwc2TestProperty<hwc2_composition_t> {
108public:
109 Hwc2TestComposition(Hwc2TestCoverage coverage);
110
111 std::string dump() const override;
112
113protected:
114 static const std::vector<hwc2_composition_t> mDefaultCompositions;
115 static const std::vector<hwc2_composition_t> mBasicCompositions;
116 static const std::vector<hwc2_composition_t> mCompleteCompositions;
117};
118
Marissa Wallb72b5c92016-12-15 12:26:39 -0800119
120class Hwc2TestDataspace : public Hwc2TestProperty<android_dataspace_t> {
121public:
122 Hwc2TestDataspace(Hwc2TestCoverage coverage);
123
124 std::string dump() const override;
125
126protected:
127 static const std::vector<android_dataspace_t> defaultDataspaces;
128 static const std::vector<android_dataspace_t> basicDataspaces;
129 static const std::vector<android_dataspace_t> completeDataspaces;
130};
131
Marissa Wall2b1f5302016-12-15 12:27:20 -0800132
Marissa Wall600a73b2016-12-15 12:30:39 -0800133class Hwc2TestDisplayFrame : public Hwc2TestProperty<hwc_rect_t> {
134public:
135 Hwc2TestDisplayFrame(Hwc2TestCoverage coverage, const Area& displayArea);
136
137 std::string dump() const override;
138
139protected:
140 void update();
141
142 const std::vector<hwc_frect_t>& mFrectScalars;
143 const static std::vector<hwc_frect_t> mDefaultFrectScalars;
144 const static std::vector<hwc_frect_t> mBasicFrectScalars;
145 const static std::vector<hwc_frect_t> mCompleteFrectScalars;
146
147 Area mDisplayArea;
148
149 std::vector<hwc_rect_t> mDisplayFrames;
150};
151
152
Marissa Wall2b1f5302016-12-15 12:27:20 -0800153class Hwc2TestPlaneAlpha : public Hwc2TestProperty<float> {
154public:
155 Hwc2TestPlaneAlpha(Hwc2TestCoverage coverage);
156
157 std::string dump() const override;
158
159protected:
160 static const std::vector<float> mDefaultPlaneAlphas;
161 static const std::vector<float> mBasicPlaneAlphas;
162 static const std::vector<float> mCompletePlaneAlphas;
163};
164
Marissa Wallac108192016-12-15 12:27:48 -0800165
166class Hwc2TestTransform : public Hwc2TestProperty<hwc_transform_t> {
167public:
168 Hwc2TestTransform(Hwc2TestCoverage coverage);
169
170 std::string dump() const override;
171
172protected:
173 static const std::vector<hwc_transform_t> mDefaultTransforms;
174 static const std::vector<hwc_transform_t> mBasicTransforms;
175 static const std::vector<hwc_transform_t> mCompleteTransforms;
176};
177
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800178#endif /* ifndef _HWC2_TEST_PROPERTIES_H */