blob: c1c9cc8f5b1f5ba9a1e8782f9ccbed9c7112ed60 [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#include <sstream>
18
19#include "Hwc2TestLayer.h"
20
Marissa Wall563030b2017-02-21 14:01:05 -080021Hwc2TestCoverage 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
28Hwc2TestLayer::Hwc2TestLayer(Hwc2TestCoverage coverage,
29 const Area& displayArea)
30 : Hwc2TestLayer(coverage, displayArea,
31 std::unordered_map<Hwc2TestPropertyName, Hwc2TestCoverage>()) { }
32
33Hwc2TestLayer::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))
Marissa Wallc57468f2016-12-15 12:31:12 -080056{
Marissa Wall5a240aa2016-12-15 12:34:06 -080057 mBufferArea.setDependent(&mBuffer);
Marissa Wallc57468f2016-12-15 12:31:12 -080058 mBufferArea.setDependent(&mSourceCrop);
Marissa Wallad761812016-12-15 12:32:24 -080059 mBufferArea.setDependent(&mSurfaceDamage);
Marissa Wallee242782016-12-15 12:30:12 -080060 mBlendMode.setDependent(&mColor);
Marissa Wallc57468f2016-12-15 12:31:12 -080061}
Marissa Wall6bd8bfd2016-12-15 12:25:31 -080062
63std::string Hwc2TestLayer::dump() const
64{
65 std::stringstream dmp;
66
67 dmp << "layer: \n";
Marissa Wallffc67da2016-12-15 12:26:09 -080068
69 for (auto property : mProperties) {
70 dmp << property->dump();
71 }
Marissa Wall6bd8bfd2016-12-15 12:25:31 -080072
Marissa Wallf7618ed2016-12-15 12:34:39 -080073 dmp << mVisibleRegion.dump();
Marissa Wall273b1df2016-12-15 12:28:47 -080074 dmp << "\tz order: " << mZOrder << "\n";
75
Marissa Wall6bd8bfd2016-12-15 12:25:31 -080076 return dmp.str();
77}
78
Marissa Wall5a240aa2016-12-15 12:34:06 -080079int 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
Marissa Wall1cd789c2017-01-27 12:55:36 -080088int Hwc2TestLayer::getBuffer(buffer_handle_t* outHandle,
89 int32_t* outAcquireFence)
90{
91 return mBuffer.get(outHandle, outAcquireFence);
92}
93
Marissa Wallf7618ed2016-12-15 12:34:39 -080094void Hwc2TestLayer::setZOrder(uint32_t zOrder)
95{
96 mZOrder = zOrder;
97}
98
99void Hwc2TestLayer::setVisibleRegion(const android::Region& region)
100{
101 return mVisibleRegion.set(region);
102}
103
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800104void Hwc2TestLayer::reset()
105{
Marissa Wallf7618ed2016-12-15 12:34:39 -0800106 mVisibleRegion.release();
107
Marissa Wallffc67da2016-12-15 12:26:09 -0800108 for (auto property : mProperties) {
109 property->reset();
110 }
111}
112
Marissa Wall1cd789c2017-01-27 12:55:36 -0800113bool 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
Marissa Wallffc67da2016-12-15 12:26:09 -0800123hwc2_blend_mode_t Hwc2TestLayer::getBlendMode() const
124{
125 return mBlendMode.get();
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800126}
127
Marissa Wallf7618ed2016-12-15 12:34:39 -0800128Area Hwc2TestLayer::getBufferArea() const
129{
130 return mBufferArea.get();
131}
132
Marissa Wallee242782016-12-15 12:30:12 -0800133hwc_color_t Hwc2TestLayer::getColor() const
134{
135 return mColor.get();
136}
137
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800138hwc2_composition_t Hwc2TestLayer::getComposition() const
139{
140 return mComposition.get();
141}
142
Marissa Wall2a0aaf92016-12-15 12:31:37 -0800143/* The cursor position corresponds to {displayFrame.left, displayFrame.top} */
144hwc_rect_t Hwc2TestLayer::getCursorPosition() const
145{
146 return mDisplayFrame.get();
147}
148
Peiyong Lin34beb7a2018-03-28 11:57:12 -0700149android::ui::Dataspace Hwc2TestLayer::getDataspace() const
Marissa Wallb72b5c92016-12-15 12:26:39 -0800150{
151 return mDataspace.get();
152}
153
Marissa Wall600a73b2016-12-15 12:30:39 -0800154hwc_rect_t Hwc2TestLayer::getDisplayFrame() const
155{
156 return mDisplayFrame.get();
157}
158
Marissa Wall2b1f5302016-12-15 12:27:20 -0800159float Hwc2TestLayer::getPlaneAlpha() const
160{
161 return mPlaneAlpha.get();
162}
163
Marissa Wallc57468f2016-12-15 12:31:12 -0800164hwc_frect_t Hwc2TestLayer::getSourceCrop() const
165{
166 return mSourceCrop.get();
167}
168
Marissa Wallad761812016-12-15 12:32:24 -0800169hwc_region_t Hwc2TestLayer::getSurfaceDamage() const
170{
171 return mSurfaceDamage.get();
172}
173
Marissa Wallac108192016-12-15 12:27:48 -0800174hwc_transform_t Hwc2TestLayer::getTransform() const
175{
176 return mTransform.get();
177}
178
Marissa Wallf7618ed2016-12-15 12:34:39 -0800179hwc_region_t Hwc2TestLayer::getVisibleRegion() const
180{
181 return mVisibleRegion.get();
182}
183
Marissa Wall273b1df2016-12-15 12:28:47 -0800184uint32_t Hwc2TestLayer::getZOrder() const
185{
186 return mZOrder;
187}
188
Marissa Wallffc67da2016-12-15 12:26:09 -0800189bool Hwc2TestLayer::advanceBlendMode()
190{
191 return mBlendMode.advance();
192}
193
Marissa Wallc57468f2016-12-15 12:31:12 -0800194bool Hwc2TestLayer::advanceBufferArea()
195{
196 return mBufferArea.advance();
197}
198
Marissa Wallee242782016-12-15 12:30:12 -0800199bool Hwc2TestLayer::advanceColor()
200{
201 return mColor.advance();
202}
203
Marissa Wall6bd8bfd2016-12-15 12:25:31 -0800204bool Hwc2TestLayer::advanceComposition()
205{
206 return mComposition.advance();
207}
Marissa Wallb72b5c92016-12-15 12:26:39 -0800208
Marissa Wall2a0aaf92016-12-15 12:31:37 -0800209bool Hwc2TestLayer::advanceCursorPosition()
210{
211 return mDisplayFrame.advance();
212}
213
Marissa Wallb72b5c92016-12-15 12:26:39 -0800214bool Hwc2TestLayer::advanceDataspace()
215{
216 return mDataspace.advance();
217}
Marissa Wall2b1f5302016-12-15 12:27:20 -0800218
Marissa Wall600a73b2016-12-15 12:30:39 -0800219bool Hwc2TestLayer::advanceDisplayFrame()
220{
221 return mDisplayFrame.advance();
222}
223
Marissa Wall2b1f5302016-12-15 12:27:20 -0800224bool Hwc2TestLayer::advancePlaneAlpha()
225{
226 return mPlaneAlpha.advance();
227}
Marissa Wallac108192016-12-15 12:27:48 -0800228
Marissa Wallc57468f2016-12-15 12:31:12 -0800229bool Hwc2TestLayer::advanceSourceCrop()
230{
231 return mSourceCrop.advance();
232}
233
Marissa Wallad761812016-12-15 12:32:24 -0800234bool Hwc2TestLayer::advanceSurfaceDamage()
235{
236 return mSurfaceDamage.advance();
237}
238
Marissa Wallac108192016-12-15 12:27:48 -0800239bool Hwc2TestLayer::advanceTransform()
240{
241 return mTransform.advance();
242}
Marissa Wallf7618ed2016-12-15 12:34:39 -0800243
244bool Hwc2TestLayer::advanceVisibleRegion()
245{
246 if (mPlaneAlpha.advance())
247 return true;
248 return mDisplayFrame.advance();
249}