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 #include <sstream>
18
19 #include "Hwc2TestLayer.h"
20
getCoverage(Hwc2TestPropertyName property,Hwc2TestCoverage coverage,const std::unordered_map<Hwc2TestPropertyName,Hwc2TestCoverage> & coverageExceptions)21 Hwc2TestCoverage getCoverage(Hwc2TestPropertyName property,
22 Hwc2TestCoverage coverage, const std::unordered_map<Hwc2TestPropertyName,
23 Hwc2TestCoverage>& coverageExceptions) {
24 auto exception = coverageExceptions.find(property);
25 return (exception != coverageExceptions.end())? exception->second : coverage;
26 }
27
Hwc2TestLayer(Hwc2TestCoverage coverage,const Area & displayArea)28 Hwc2TestLayer::Hwc2TestLayer(Hwc2TestCoverage coverage,
29 const Area& displayArea)
30 : Hwc2TestLayer(coverage, displayArea,
31 std::unordered_map<Hwc2TestPropertyName, Hwc2TestCoverage>()) { }
32
Hwc2TestLayer(Hwc2TestCoverage coverage,const Area & displayArea,const std::unordered_map<Hwc2TestPropertyName,Hwc2TestCoverage> & coverageExceptions)33 Hwc2TestLayer::Hwc2TestLayer(Hwc2TestCoverage coverage,
34 const Area& displayArea, const std::unordered_map<Hwc2TestPropertyName,
35 Hwc2TestCoverage>& coverageExceptions)
36 : mBlendMode(getCoverage(Hwc2TestPropertyName::BlendMode, coverage,
37 coverageExceptions)),
38 mBufferArea(getCoverage(Hwc2TestPropertyName::BufferArea, coverage,
39 coverageExceptions), displayArea),
40 mColor(getCoverage(Hwc2TestPropertyName::Color, coverage,
41 coverageExceptions)),
42 mComposition(getCoverage(Hwc2TestPropertyName::Composition, coverage,
43 coverageExceptions)),
44 mDataspace(getCoverage(Hwc2TestPropertyName::Dataspace, coverage,
45 coverageExceptions)),
46 mDisplayFrame(getCoverage(Hwc2TestPropertyName::DisplayFrame, coverage,
47 coverageExceptions), displayArea),
48 mPlaneAlpha(getCoverage(Hwc2TestPropertyName::PlaneAlpha, coverage,
49 coverageExceptions)),
50 mSourceCrop(getCoverage(Hwc2TestPropertyName::SourceCrop, coverage,
51 coverageExceptions)),
52 mSurfaceDamage(getCoverage(Hwc2TestPropertyName::SurfaceDamage, coverage,
53 coverageExceptions)),
54 mTransform(getCoverage(Hwc2TestPropertyName::Transform, coverage,
55 coverageExceptions))
56 {
57 mBufferArea.setDependent(&mBuffer);
58 mBufferArea.setDependent(&mSourceCrop);
59 mBufferArea.setDependent(&mSurfaceDamage);
60 mBlendMode.setDependent(&mColor);
61 }
62
dump() const63 std::string Hwc2TestLayer::dump() const
64 {
65 std::stringstream dmp;
66
67 dmp << "layer: \n";
68
69 for (auto property : mProperties) {
70 dmp << property->dump();
71 }
72
73 dmp << mVisibleRegion.dump();
74 dmp << "\tz order: " << mZOrder << "\n";
75
76 return dmp.str();
77 }
78
getBuffer(buffer_handle_t * outHandle,android::base::unique_fd * outAcquireFence)79 int Hwc2TestLayer::getBuffer(buffer_handle_t* outHandle,
80 android::base::unique_fd* outAcquireFence)
81 {
82 int32_t acquireFence;
83 int ret = mBuffer.get(outHandle, &acquireFence);
84 outAcquireFence->reset(acquireFence);
85 return ret;
86 }
87
getBuffer(buffer_handle_t * outHandle,int32_t * outAcquireFence)88 int Hwc2TestLayer::getBuffer(buffer_handle_t* outHandle,
89 int32_t* outAcquireFence)
90 {
91 return mBuffer.get(outHandle, outAcquireFence);
92 }
93
setZOrder(uint32_t zOrder)94 void Hwc2TestLayer::setZOrder(uint32_t zOrder)
95 {
96 mZOrder = zOrder;
97 }
98
setVisibleRegion(const android::Region & region)99 void Hwc2TestLayer::setVisibleRegion(const android::Region& region)
100 {
101 return mVisibleRegion.set(region);
102 }
103
reset()104 void Hwc2TestLayer::reset()
105 {
106 mVisibleRegion.release();
107
108 for (auto property : mProperties) {
109 property->reset();
110 }
111 }
112
advance()113 bool Hwc2TestLayer::advance()
114 {
115 for (auto property : mProperties) {
116 if (property->isSupported(mComposition.get()))
117 if (property->advance())
118 return true;
119 }
120 return false;
121 }
122
getBlendMode() const123 hwc2_blend_mode_t Hwc2TestLayer::getBlendMode() const
124 {
125 return mBlendMode.get();
126 }
127
getBufferArea() const128 Area Hwc2TestLayer::getBufferArea() const
129 {
130 return mBufferArea.get();
131 }
132
getColor() const133 hwc_color_t Hwc2TestLayer::getColor() const
134 {
135 return mColor.get();
136 }
137
getComposition() const138 hwc2_composition_t Hwc2TestLayer::getComposition() const
139 {
140 return mComposition.get();
141 }
142
143 /* The cursor position corresponds to {displayFrame.left, displayFrame.top} */
getCursorPosition() const144 hwc_rect_t Hwc2TestLayer::getCursorPosition() const
145 {
146 return mDisplayFrame.get();
147 }
148
getDataspace() const149 android::ui::Dataspace Hwc2TestLayer::getDataspace() const
150 {
151 return mDataspace.get();
152 }
153
getDisplayFrame() const154 hwc_rect_t Hwc2TestLayer::getDisplayFrame() const
155 {
156 return mDisplayFrame.get();
157 }
158
getPlaneAlpha() const159 float Hwc2TestLayer::getPlaneAlpha() const
160 {
161 return mPlaneAlpha.get();
162 }
163
getSourceCrop() const164 hwc_frect_t Hwc2TestLayer::getSourceCrop() const
165 {
166 return mSourceCrop.get();
167 }
168
getSurfaceDamage() const169 hwc_region_t Hwc2TestLayer::getSurfaceDamage() const
170 {
171 return mSurfaceDamage.get();
172 }
173
getTransform() const174 hwc_transform_t Hwc2TestLayer::getTransform() const
175 {
176 return mTransform.get();
177 }
178
getVisibleRegion() const179 hwc_region_t Hwc2TestLayer::getVisibleRegion() const
180 {
181 return mVisibleRegion.get();
182 }
183
getZOrder() const184 uint32_t Hwc2TestLayer::getZOrder() const
185 {
186 return mZOrder;
187 }
188
advanceBlendMode()189 bool Hwc2TestLayer::advanceBlendMode()
190 {
191 return mBlendMode.advance();
192 }
193
advanceBufferArea()194 bool Hwc2TestLayer::advanceBufferArea()
195 {
196 return mBufferArea.advance();
197 }
198
advanceColor()199 bool Hwc2TestLayer::advanceColor()
200 {
201 return mColor.advance();
202 }
203
advanceComposition()204 bool Hwc2TestLayer::advanceComposition()
205 {
206 return mComposition.advance();
207 }
208
advanceCursorPosition()209 bool Hwc2TestLayer::advanceCursorPosition()
210 {
211 return mDisplayFrame.advance();
212 }
213
advanceDataspace()214 bool Hwc2TestLayer::advanceDataspace()
215 {
216 return mDataspace.advance();
217 }
218
advanceDisplayFrame()219 bool Hwc2TestLayer::advanceDisplayFrame()
220 {
221 return mDisplayFrame.advance();
222 }
223
advancePlaneAlpha()224 bool Hwc2TestLayer::advancePlaneAlpha()
225 {
226 return mPlaneAlpha.advance();
227 }
228
advanceSourceCrop()229 bool Hwc2TestLayer::advanceSourceCrop()
230 {
231 return mSourceCrop.advance();
232 }
233
advanceSurfaceDamage()234 bool Hwc2TestLayer::advanceSurfaceDamage()
235 {
236 return mSurfaceDamage.advance();
237 }
238
advanceTransform()239 bool Hwc2TestLayer::advanceTransform()
240 {
241 return mTransform.advance();
242 }
243
advanceVisibleRegion()244 bool Hwc2TestLayer::advanceVisibleRegion()
245 {
246 if (mPlaneAlpha.advance())
247 return true;
248 return mDisplayFrame.advance();
249 }
250