blob: e36ccef0cf4e6c70fced50fb16a381b14eeb7caa [file] [log] [blame]
Lloyd Pique32cbe282018-10-19 13:09:22 -07001/*
2 * Copyright 2019 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 <cmath>
18
Lloyd Pique17ca7422019-11-14 14:24:10 -080019#include <android-base/stringprintf.h>
Lloyd Pique9755fb72019-03-26 14:44:40 -070020#include <compositionengine/LayerFECompositionState.h>
Lloyd Pique32cbe282018-10-19 13:09:22 -070021#include <compositionengine/impl/Output.h>
Lloyd Pique66d68602019-02-13 14:23:31 -080022#include <compositionengine/impl/OutputCompositionState.h>
Lloyd Pique56eba802019-08-28 15:45:25 -070023#include <compositionengine/impl/OutputLayerCompositionState.h>
Lloyd Pique32cbe282018-10-19 13:09:22 -070024#include <compositionengine/mock/CompositionEngine.h>
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070025#include <compositionengine/mock/DisplayColorProfile.h>
Lloyd Piquecc01a452018-12-04 17:24:00 -080026#include <compositionengine/mock/LayerFE.h>
27#include <compositionengine/mock/OutputLayer.h>
Lloyd Pique31cb2942018-10-19 17:23:03 -070028#include <compositionengine/mock/RenderSurface.h>
Lloyd Pique32cbe282018-10-19 13:09:22 -070029#include <gtest/gtest.h>
Lloyd Pique56eba802019-08-28 15:45:25 -070030#include <renderengine/mock/RenderEngine.h>
Lloyd Pique32cbe282018-10-19 13:09:22 -070031#include <ui/Rect.h>
32#include <ui/Region.h>
33
Lloyd Pique17ca7422019-11-14 14:24:10 -080034#include "CallOrderStateMachineHelper.h"
Lloyd Pique07178e32019-11-19 19:15:26 -080035#include "MockHWC2.h"
Lloyd Pique32cbe282018-10-19 13:09:22 -070036#include "RegionMatcher.h"
Lloyd Pique32cbe282018-10-19 13:09:22 -070037
38namespace android::compositionengine {
39namespace {
40
Lloyd Pique56eba802019-08-28 15:45:25 -070041using testing::_;
Lloyd Pique03561a62019-11-19 18:34:52 -080042using testing::ByMove;
Lloyd Piquea4863342019-12-04 18:45:02 -080043using testing::ByRef;
Lloyd Pique17ca7422019-11-14 14:24:10 -080044using testing::DoAll;
Vishnu Nair9b079a22020-01-21 14:36:08 -080045using testing::ElementsAre;
Lloyd Pique6818fa52019-12-03 12:32:13 -080046using testing::ElementsAreArray;
Lloyd Pique07178e32019-11-19 19:15:26 -080047using testing::Eq;
Lloyd Piquefaa3f192019-11-14 14:05:09 -080048using testing::InSequence;
Lloyd Pique6818fa52019-12-03 12:32:13 -080049using testing::Invoke;
50using testing::IsEmpty;
Lloyd Pique17ca7422019-11-14 14:24:10 -080051using testing::Mock;
Vishnu Nair9b079a22020-01-21 14:36:08 -080052using testing::Pointee;
Lloyd Pique07178e32019-11-19 19:15:26 -080053using testing::Property;
Lloyd Piquefaa3f192019-11-14 14:05:09 -080054using testing::Ref;
Lloyd Pique31cb2942018-10-19 17:23:03 -070055using testing::Return;
Lloyd Pique32cbe282018-10-19 13:09:22 -070056using testing::ReturnRef;
Lloyd Pique17ca7422019-11-14 14:24:10 -080057using testing::SetArgPointee;
Lloyd Pique32cbe282018-10-19 13:09:22 -070058using testing::StrictMock;
59
Lloyd Pique56eba802019-08-28 15:45:25 -070060constexpr auto TR_IDENT = 0u;
61constexpr auto TR_ROT_90 = HAL_TRANSFORM_ROT_90;
Vishnu Nair9b079a22020-01-21 14:36:08 -080062constexpr auto MAX_CLIENT_COMPOSITION_CACHE_SIZE = 3;
Lloyd Pique56eba802019-08-28 15:45:25 -070063
Lloyd Pique3eb1b212019-03-07 21:15:40 -080064const mat4 kIdentity;
Lloyd Pique0a456232020-01-16 17:51:13 -080065const mat4 kNonIdentityHalf = mat4() * 0.5f;
66const mat4 kNonIdentityQuarter = mat4() * 0.25f;
Lloyd Pique3eb1b212019-03-07 21:15:40 -080067
Lloyd Pique17ca7422019-11-14 14:24:10 -080068constexpr OutputColorSetting kVendorSpecifiedOutputColorSetting =
69 static_cast<OutputColorSetting>(0x100);
70
Lloyd Piquefaa3f192019-11-14 14:05:09 -080071struct OutputPartialMockBase : public impl::Output {
72 // compositionengine::Output overrides
73 const OutputCompositionState& getState() const override { return mState; }
74 OutputCompositionState& editState() override { return mState; }
75
76 // Use mocks for all the remaining virtual functions
77 // not implemented by the base implementation class.
78 MOCK_CONST_METHOD0(getOutputLayerCount, size_t());
79 MOCK_CONST_METHOD1(getOutputLayerOrderedByZByIndex, compositionengine::OutputLayer*(size_t));
Lloyd Piquede196652020-01-22 17:29:58 -080080 MOCK_METHOD2(ensureOutputLayer,
81 compositionengine::OutputLayer*(std::optional<size_t>, const sp<LayerFE>&));
Lloyd Piquefaa3f192019-11-14 14:05:09 -080082 MOCK_METHOD0(finalizePendingOutputLayers, void());
83 MOCK_METHOD0(clearOutputLayers, void());
84 MOCK_CONST_METHOD1(dumpState, void(std::string&));
85 MOCK_CONST_METHOD0(getCompositionEngine, const CompositionEngine&());
Lloyd Piquede196652020-01-22 17:29:58 -080086 MOCK_METHOD1(injectOutputLayerForTest, compositionengine::OutputLayer*(const sp<LayerFE>&));
Lloyd Piquefaa3f192019-11-14 14:05:09 -080087 MOCK_METHOD1(injectOutputLayerForTest, void(std::unique_ptr<OutputLayer>));
88
89 impl::OutputCompositionState mState;
90};
91
Lloyd Piquede196652020-01-22 17:29:58 -080092struct InjectedLayer {
93 InjectedLayer() {
94 EXPECT_CALL(*outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*layerFE.get()));
95 EXPECT_CALL(*outputLayer, getState()).WillRepeatedly(ReturnRef(outputLayerState));
96 EXPECT_CALL(*outputLayer, editState()).WillRepeatedly(ReturnRef(outputLayerState));
97
98 EXPECT_CALL(*layerFE, getCompositionState()).WillRepeatedly(Return(&layerFEState));
99 }
100
101 mock::OutputLayer* outputLayer = {new StrictMock<mock::OutputLayer>};
102 sp<StrictMock<mock::LayerFE>> layerFE = new StrictMock<mock::LayerFE>();
103 LayerFECompositionState layerFEState;
104 impl::OutputLayerCompositionState outputLayerState;
105};
106
107struct NonInjectedLayer {
108 NonInjectedLayer() {
109 EXPECT_CALL(outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*layerFE.get()));
110 EXPECT_CALL(outputLayer, getState()).WillRepeatedly(ReturnRef(outputLayerState));
111 EXPECT_CALL(outputLayer, editState()).WillRepeatedly(ReturnRef(outputLayerState));
112
113 EXPECT_CALL(*layerFE, getCompositionState()).WillRepeatedly(Return(&layerFEState));
114 }
115
116 mock::OutputLayer outputLayer;
117 sp<StrictMock<mock::LayerFE>> layerFE = new StrictMock<mock::LayerFE>();
118 LayerFECompositionState layerFEState;
119 impl::OutputLayerCompositionState outputLayerState;
120};
121
Lloyd Pique66d68602019-02-13 14:23:31 -0800122struct OutputTest : public testing::Test {
Lloyd Pique01c77c12019-04-17 12:48:32 -0700123 class Output : public impl::Output {
124 public:
125 using impl::Output::injectOutputLayerForTest;
126 virtual void injectOutputLayerForTest(std::unique_ptr<compositionengine::OutputLayer>) = 0;
127 };
128
129 static std::shared_ptr<Output> createOutput(
130 const compositionengine::CompositionEngine& compositionEngine) {
131 return impl::createOutputTemplated<Output>(compositionEngine);
132 }
133
Lloyd Pique31cb2942018-10-19 17:23:03 -0700134 OutputTest() {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700135 mOutput->setDisplayColorProfileForTest(
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700136 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700137 mOutput->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
Lloyd Piqueef958122019-02-05 18:00:12 -0800138
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700139 mOutput->editState().bounds = kDefaultDisplaySize;
Lloyd Pique31cb2942018-10-19 17:23:03 -0700140 }
Lloyd Pique32cbe282018-10-19 13:09:22 -0700141
Lloyd Piquede196652020-01-22 17:29:58 -0800142 void injectOutputLayer(InjectedLayer& layer) {
143 mOutput->injectOutputLayerForTest(std::unique_ptr<OutputLayer>(layer.outputLayer));
144 }
145
146 void injectNullOutputLayer() {
147 mOutput->injectOutputLayerForTest(std::unique_ptr<OutputLayer>(nullptr));
148 }
149
Lloyd Piqueef958122019-02-05 18:00:12 -0800150 static const Rect kDefaultDisplaySize;
151
Lloyd Pique32cbe282018-10-19 13:09:22 -0700152 StrictMock<mock::CompositionEngine> mCompositionEngine;
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700153 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
Lloyd Pique31cb2942018-10-19 17:23:03 -0700154 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
Lloyd Pique01c77c12019-04-17 12:48:32 -0700155 std::shared_ptr<Output> mOutput = createOutput(mCompositionEngine);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700156};
157
Lloyd Piqueef958122019-02-05 18:00:12 -0800158const Rect OutputTest::kDefaultDisplaySize{100, 200};
159
Lloyd Pique17ca7422019-11-14 14:24:10 -0800160using ColorProfile = compositionengine::Output::ColorProfile;
161
162void dumpColorProfile(ColorProfile profile, std::string& result, const char* name) {
163 android::base::StringAppendF(&result, "%s (%s[%d] %s[%d] %s[%d] %s[%d]) ", name,
164 toString(profile.mode).c_str(), profile.mode,
165 toString(profile.dataspace).c_str(), profile.dataspace,
166 toString(profile.renderIntent).c_str(), profile.renderIntent,
167 toString(profile.colorSpaceAgnosticDataspace).c_str(),
168 profile.colorSpaceAgnosticDataspace);
169}
170
171// Checks for a ColorProfile match
172MATCHER_P(ColorProfileEq, expected, "") {
173 std::string buf;
174 buf.append("ColorProfiles are not equal\n");
175 dumpColorProfile(expected, buf, "expected value");
176 dumpColorProfile(arg, buf, "actual value");
177 *result_listener << buf;
178
179 return (expected.mode == arg.mode) && (expected.dataspace == arg.dataspace) &&
180 (expected.renderIntent == arg.renderIntent) &&
181 (expected.colorSpaceAgnosticDataspace == arg.colorSpaceAgnosticDataspace);
182}
183
Lloyd Pique66d68602019-02-13 14:23:31 -0800184/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700185 * Basic construction
186 */
187
Lloyd Pique31cb2942018-10-19 17:23:03 -0700188TEST_F(OutputTest, canInstantiateOutput) {
189 // The validation check checks each required component.
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700190 EXPECT_CALL(*mDisplayColorProfile, isValid()).WillOnce(Return(true));
Lloyd Pique31cb2942018-10-19 17:23:03 -0700191 EXPECT_CALL(*mRenderSurface, isValid()).WillOnce(Return(true));
192
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700193 EXPECT_TRUE(mOutput->isValid());
Lloyd Pique31cb2942018-10-19 17:23:03 -0700194
195 // If we take away the required components, it is no longer valid.
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700196 mOutput->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>());
Lloyd Pique31cb2942018-10-19 17:23:03 -0700197
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700198 EXPECT_CALL(*mDisplayColorProfile, isValid()).WillOnce(Return(true));
199
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700200 EXPECT_FALSE(mOutput->isValid());
Lloyd Pique31cb2942018-10-19 17:23:03 -0700201}
Lloyd Pique32cbe282018-10-19 13:09:22 -0700202
Lloyd Pique66d68602019-02-13 14:23:31 -0800203/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700204 * Output::setCompositionEnabled()
205 */
206
207TEST_F(OutputTest, setCompositionEnabledDoesNothingIfAlreadyEnabled) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700208 mOutput->editState().isEnabled = true;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700209
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700210 mOutput->setCompositionEnabled(true);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700211
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700212 EXPECT_TRUE(mOutput->getState().isEnabled);
213 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region()));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700214}
215
216TEST_F(OutputTest, setCompositionEnabledSetsEnabledAndDirtiesEntireOutput) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700217 mOutput->editState().isEnabled = false;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700218
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700219 mOutput->setCompositionEnabled(true);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700220
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700221 EXPECT_TRUE(mOutput->getState().isEnabled);
222 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700223}
224
225TEST_F(OutputTest, setCompositionEnabledSetsDisabledAndDirtiesEntireOutput) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700226 mOutput->editState().isEnabled = true;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700227
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700228 mOutput->setCompositionEnabled(false);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700229
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700230 EXPECT_FALSE(mOutput->getState().isEnabled);
231 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700232}
233
Lloyd Pique66d68602019-02-13 14:23:31 -0800234/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700235 * Output::setProjection()
236 */
237
238TEST_F(OutputTest, setProjectionTriviallyWorks) {
239 const ui::Transform transform{ui::Transform::ROT_180};
240 const int32_t orientation = 123;
241 const Rect frame{1, 2, 3, 4};
242 const Rect viewport{5, 6, 7, 8};
Lloyd Piquee8fe4742020-01-21 15:26:18 -0800243 const Rect sourceClip{9, 10, 11, 12};
244 const Rect destinationClip{13, 14, 15, 16};
Lloyd Pique32cbe282018-10-19 13:09:22 -0700245 const bool needsFiltering = true;
246
Lloyd Piquee8fe4742020-01-21 15:26:18 -0800247 mOutput->setProjection(transform, orientation, frame, viewport, sourceClip, destinationClip,
248 needsFiltering);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700249
Lloyd Piqueea629282019-12-03 15:57:10 -0800250 EXPECT_THAT(mOutput->getState().transform, transform);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700251 EXPECT_EQ(orientation, mOutput->getState().orientation);
252 EXPECT_EQ(frame, mOutput->getState().frame);
253 EXPECT_EQ(viewport, mOutput->getState().viewport);
Lloyd Piquee8fe4742020-01-21 15:26:18 -0800254 EXPECT_EQ(sourceClip, mOutput->getState().sourceClip);
255 EXPECT_EQ(destinationClip, mOutput->getState().destinationClip);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700256 EXPECT_EQ(needsFiltering, mOutput->getState().needsFiltering);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700257}
258
Lloyd Pique66d68602019-02-13 14:23:31 -0800259/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700260 * Output::setBounds()
261 */
262
263TEST_F(OutputTest, setBoundsSetsSizeAndDirtiesEntireOutput) {
Lloyd Piqueef958122019-02-05 18:00:12 -0800264 const ui::Size displaySize{200, 400};
Lloyd Pique31cb2942018-10-19 17:23:03 -0700265
266 EXPECT_CALL(*mRenderSurface, setDisplaySize(displaySize)).Times(1);
267 EXPECT_CALL(*mRenderSurface, getSize()).WillOnce(ReturnRef(displaySize));
268
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700269 mOutput->setBounds(displaySize);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700270
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700271 EXPECT_EQ(Rect(displaySize), mOutput->getState().bounds);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700272
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700273 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(Rect(displaySize))));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700274}
275
Lloyd Pique66d68602019-02-13 14:23:31 -0800276/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700277 * Output::setLayerStackFilter()
278 */
279
280TEST_F(OutputTest, setLayerStackFilterSetsFilterAndDirtiesEntireOutput) {
Lloyd Pique32cbe282018-10-19 13:09:22 -0700281 const uint32_t layerStack = 123u;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700282 mOutput->setLayerStackFilter(layerStack, true);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700283
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700284 EXPECT_TRUE(mOutput->getState().layerStackInternal);
285 EXPECT_EQ(layerStack, mOutput->getState().layerStackId);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700286
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700287 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700288}
289
Lloyd Pique66d68602019-02-13 14:23:31 -0800290/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700291 * Output::setColorTransform
292 */
293
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800294TEST_F(OutputTest, setColorTransformWithNoChangeFlaggedSkipsUpdates) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700295 mOutput->editState().colorTransformMatrix = kIdentity;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700296
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800297 // If no colorTransformMatrix is set the update should be skipped.
298 CompositionRefreshArgs refreshArgs;
299 refreshArgs.colorTransformMatrix = std::nullopt;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700300
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700301 mOutput->setColorTransform(refreshArgs);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700302
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800303 // The internal state should be unchanged
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700304 EXPECT_EQ(kIdentity, mOutput->getState().colorTransformMatrix);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800305
306 // No dirty region should be set
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700307 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region()));
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800308}
Lloyd Piqueef958122019-02-05 18:00:12 -0800309
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800310TEST_F(OutputTest, setColorTransformWithNoActualChangeSkipsUpdates) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700311 mOutput->editState().colorTransformMatrix = kIdentity;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700312
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800313 // Attempting to set the same colorTransformMatrix that is already set should
314 // also skip the update.
315 CompositionRefreshArgs refreshArgs;
316 refreshArgs.colorTransformMatrix = kIdentity;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700317
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700318 mOutput->setColorTransform(refreshArgs);
Lloyd Pique77f79a22019-04-29 15:55:40 -0700319
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800320 // The internal state should be unchanged
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700321 EXPECT_EQ(kIdentity, mOutput->getState().colorTransformMatrix);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800322
323 // No dirty region should be set
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700324 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region()));
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800325}
326
327TEST_F(OutputTest, setColorTransformPerformsUpdateToIdentity) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700328 mOutput->editState().colorTransformMatrix = kNonIdentityHalf;
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800329
330 // Setting a different colorTransformMatrix should perform the update.
331 CompositionRefreshArgs refreshArgs;
332 refreshArgs.colorTransformMatrix = kIdentity;
333
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700334 mOutput->setColorTransform(refreshArgs);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800335
336 // The internal state should have been updated
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700337 EXPECT_EQ(kIdentity, mOutput->getState().colorTransformMatrix);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800338
339 // The dirtyRegion should be set to the full display size
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700340 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800341}
Lloyd Pique77f79a22019-04-29 15:55:40 -0700342
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800343TEST_F(OutputTest, setColorTransformPerformsUpdateForIdentityToHalf) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700344 mOutput->editState().colorTransformMatrix = kIdentity;
Lloyd Pique77f79a22019-04-29 15:55:40 -0700345
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800346 // Setting a different colorTransformMatrix should perform the update.
347 CompositionRefreshArgs refreshArgs;
348 refreshArgs.colorTransformMatrix = kNonIdentityHalf;
Lloyd Pique77f79a22019-04-29 15:55:40 -0700349
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700350 mOutput->setColorTransform(refreshArgs);
Lloyd Piqueef958122019-02-05 18:00:12 -0800351
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800352 // The internal state should have been updated
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700353 EXPECT_EQ(kNonIdentityHalf, mOutput->getState().colorTransformMatrix);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800354
355 // The dirtyRegion should be set to the full display size
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700356 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800357}
358
359TEST_F(OutputTest, setColorTransformPerformsUpdateForHalfToQuarter) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700360 mOutput->editState().colorTransformMatrix = kNonIdentityHalf;
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800361
362 // Setting a different colorTransformMatrix should perform the update.
363 CompositionRefreshArgs refreshArgs;
364 refreshArgs.colorTransformMatrix = kNonIdentityQuarter;
365
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700366 mOutput->setColorTransform(refreshArgs);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800367
368 // The internal state should have been updated
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700369 EXPECT_EQ(kNonIdentityQuarter, mOutput->getState().colorTransformMatrix);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800370
371 // The dirtyRegion should be set to the full display size
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700372 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700373}
374
Lloyd Pique66d68602019-02-13 14:23:31 -0800375/*
Lloyd Pique17ca7422019-11-14 14:24:10 -0800376 * Output::setColorProfile
Lloyd Pique32cbe282018-10-19 13:09:22 -0700377 */
378
Lloyd Pique17ca7422019-11-14 14:24:10 -0800379using OutputSetColorProfileTest = OutputTest;
380
381TEST_F(OutputSetColorProfileTest, setsStateAndDirtiesOutputIfChanged) {
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800382 using ColorProfile = Output::ColorProfile;
383
Lloyd Piquef5275482019-01-29 18:42:42 -0800384 EXPECT_CALL(*mDisplayColorProfile,
385 getTargetDataspace(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
386 ui::Dataspace::UNKNOWN))
387 .WillOnce(Return(ui::Dataspace::UNKNOWN));
Lloyd Piqueef958122019-02-05 18:00:12 -0800388 EXPECT_CALL(*mRenderSurface, setBufferDataspace(ui::Dataspace::DISPLAY_P3)).Times(1);
Lloyd Pique31cb2942018-10-19 17:23:03 -0700389
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700390 mOutput->setColorProfile(ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
391 ui::RenderIntent::TONE_MAP_COLORIMETRIC,
392 ui::Dataspace::UNKNOWN});
Lloyd Pique32cbe282018-10-19 13:09:22 -0700393
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700394 EXPECT_EQ(ui::ColorMode::DISPLAY_P3, mOutput->getState().colorMode);
395 EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mOutput->getState().dataspace);
396 EXPECT_EQ(ui::RenderIntent::TONE_MAP_COLORIMETRIC, mOutput->getState().renderIntent);
397 EXPECT_EQ(ui::Dataspace::UNKNOWN, mOutput->getState().targetDataspace);
Lloyd Piquef5275482019-01-29 18:42:42 -0800398
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700399 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
Lloyd Piqueef958122019-02-05 18:00:12 -0800400}
401
Lloyd Pique17ca7422019-11-14 14:24:10 -0800402TEST_F(OutputSetColorProfileTest, doesNothingIfNoChange) {
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800403 using ColorProfile = Output::ColorProfile;
404
Lloyd Piquef5275482019-01-29 18:42:42 -0800405 EXPECT_CALL(*mDisplayColorProfile,
406 getTargetDataspace(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
407 ui::Dataspace::UNKNOWN))
408 .WillOnce(Return(ui::Dataspace::UNKNOWN));
409
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700410 mOutput->editState().colorMode = ui::ColorMode::DISPLAY_P3;
411 mOutput->editState().dataspace = ui::Dataspace::DISPLAY_P3;
412 mOutput->editState().renderIntent = ui::RenderIntent::TONE_MAP_COLORIMETRIC;
413 mOutput->editState().targetDataspace = ui::Dataspace::UNKNOWN;
Lloyd Piqueef958122019-02-05 18:00:12 -0800414
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700415 mOutput->setColorProfile(ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
416 ui::RenderIntent::TONE_MAP_COLORIMETRIC,
417 ui::Dataspace::UNKNOWN});
Lloyd Piqueef958122019-02-05 18:00:12 -0800418
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700419 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region()));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700420}
421
Lloyd Pique66d68602019-02-13 14:23:31 -0800422/*
Lloyd Pique31cb2942018-10-19 17:23:03 -0700423 * Output::setRenderSurface()
424 */
425
426TEST_F(OutputTest, setRenderSurfaceResetsBounds) {
427 const ui::Size newDisplaySize{640, 480};
428
429 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
430 EXPECT_CALL(*renderSurface, getSize()).WillOnce(ReturnRef(newDisplaySize));
431
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700432 mOutput->setRenderSurface(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Pique31cb2942018-10-19 17:23:03 -0700433
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700434 EXPECT_EQ(Rect(newDisplaySize), mOutput->getState().bounds);
Lloyd Pique31cb2942018-10-19 17:23:03 -0700435}
436
Lloyd Pique66d68602019-02-13 14:23:31 -0800437/*
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000438 * Output::getDirtyRegion()
Lloyd Pique32cbe282018-10-19 13:09:22 -0700439 */
440
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000441TEST_F(OutputTest, getDirtyRegionWithRepaintEverythingTrue) {
442 const Rect viewport{100, 200};
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700443 mOutput->editState().viewport = viewport;
444 mOutput->editState().dirtyRegion.set(50, 300);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700445
446 {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700447 Region result = mOutput->getDirtyRegion(true);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700448
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000449 EXPECT_THAT(result, RegionEq(Region(viewport)));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700450 }
451}
452
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000453TEST_F(OutputTest, getDirtyRegionWithRepaintEverythingFalse) {
454 const Rect viewport{100, 200};
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700455 mOutput->editState().viewport = viewport;
456 mOutput->editState().dirtyRegion.set(50, 300);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700457
458 {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700459 Region result = mOutput->getDirtyRegion(false);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700460
461 // The dirtyRegion should be clipped to the display bounds.
462 EXPECT_THAT(result, RegionEq(Region(Rect(50, 200))));
463 }
Lloyd Pique32cbe282018-10-19 13:09:22 -0700464}
465
Lloyd Pique66d68602019-02-13 14:23:31 -0800466/*
Lloyd Piqueef36b002019-01-23 17:52:04 -0800467 * Output::belongsInOutput()
468 */
469
470TEST_F(OutputTest, belongsInOutputFiltersAsExpected) {
471 const uint32_t layerStack1 = 123u;
472 const uint32_t layerStack2 = 456u;
473
474 // If the output accepts layerStack1 and internal-only layers....
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700475 mOutput->setLayerStackFilter(layerStack1, true);
Lloyd Piqueef36b002019-01-23 17:52:04 -0800476
Lloyd Piquec6687342019-03-07 21:34:57 -0800477 // A layer with no layerStack does not belong to it, internal-only or not.
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700478 EXPECT_FALSE(mOutput->belongsInOutput(std::nullopt, false));
479 EXPECT_FALSE(mOutput->belongsInOutput(std::nullopt, true));
Lloyd Piquec6687342019-03-07 21:34:57 -0800480
Lloyd Piqueef36b002019-01-23 17:52:04 -0800481 // Any layer with layerStack1 belongs to it, internal-only or not.
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700482 EXPECT_TRUE(mOutput->belongsInOutput(layerStack1, false));
483 EXPECT_TRUE(mOutput->belongsInOutput(layerStack1, true));
484 EXPECT_FALSE(mOutput->belongsInOutput(layerStack2, true));
485 EXPECT_FALSE(mOutput->belongsInOutput(layerStack2, false));
Lloyd Piqueef36b002019-01-23 17:52:04 -0800486
487 // If the output accepts layerStack21 but not internal-only layers...
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700488 mOutput->setLayerStackFilter(layerStack1, false);
Lloyd Piqueef36b002019-01-23 17:52:04 -0800489
490 // Only non-internal layers with layerStack1 belong to it.
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700491 EXPECT_TRUE(mOutput->belongsInOutput(layerStack1, false));
492 EXPECT_FALSE(mOutput->belongsInOutput(layerStack1, true));
493 EXPECT_FALSE(mOutput->belongsInOutput(layerStack2, true));
494 EXPECT_FALSE(mOutput->belongsInOutput(layerStack2, false));
Lloyd Piqueef36b002019-01-23 17:52:04 -0800495}
496
Lloyd Piquede196652020-01-22 17:29:58 -0800497TEST_F(OutputTest, belongsInOutputHandlesLayerWithNoCompositionState) {
498 NonInjectedLayer layer;
499 sp<LayerFE> layerFE(layer.layerFE);
Lloyd Pique66c20c42019-03-07 21:44:02 -0800500
Lloyd Piquede196652020-01-22 17:29:58 -0800501 // If the layer has no composition state, it does not belong to any output.
502 EXPECT_CALL(*layer.layerFE, getCompositionState).WillOnce(Return(nullptr));
503 EXPECT_FALSE(mOutput->belongsInOutput(layerFE));
504}
505
506TEST_F(OutputTest, belongsInOutputFiltersLayersAsExpected) {
507 NonInjectedLayer layer;
508 sp<LayerFE> layerFE(layer.layerFE);
Lloyd Pique66c20c42019-03-07 21:44:02 -0800509
510 const uint32_t layerStack1 = 123u;
511 const uint32_t layerStack2 = 456u;
512
513 // If the output accepts layerStack1 and internal-only layers....
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700514 mOutput->setLayerStackFilter(layerStack1, true);
Lloyd Pique66c20c42019-03-07 21:44:02 -0800515
Lloyd Pique66c20c42019-03-07 21:44:02 -0800516 // A layer with no layerStack does not belong to it, internal-only or not.
Lloyd Piquede196652020-01-22 17:29:58 -0800517 layer.layerFEState.layerStackId = std::nullopt;
518 layer.layerFEState.internalOnly = false;
519 EXPECT_FALSE(mOutput->belongsInOutput(layerFE));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800520
Lloyd Piquede196652020-01-22 17:29:58 -0800521 layer.layerFEState.layerStackId = std::nullopt;
522 layer.layerFEState.internalOnly = true;
523 EXPECT_FALSE(mOutput->belongsInOutput(layerFE));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800524
525 // Any layer with layerStack1 belongs to it, internal-only or not.
Lloyd Piquede196652020-01-22 17:29:58 -0800526 layer.layerFEState.layerStackId = layerStack1;
527 layer.layerFEState.internalOnly = false;
528 EXPECT_TRUE(mOutput->belongsInOutput(layerFE));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800529
Lloyd Piquede196652020-01-22 17:29:58 -0800530 layer.layerFEState.layerStackId = layerStack1;
531 layer.layerFEState.internalOnly = true;
532 EXPECT_TRUE(mOutput->belongsInOutput(layerFE));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800533
Lloyd Piquede196652020-01-22 17:29:58 -0800534 layer.layerFEState.layerStackId = layerStack2;
535 layer.layerFEState.internalOnly = true;
536 EXPECT_FALSE(mOutput->belongsInOutput(layerFE));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800537
Lloyd Piquede196652020-01-22 17:29:58 -0800538 layer.layerFEState.layerStackId = layerStack2;
539 layer.layerFEState.internalOnly = false;
540 EXPECT_FALSE(mOutput->belongsInOutput(layerFE));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800541
542 // If the output accepts layerStack1 but not internal-only layers...
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700543 mOutput->setLayerStackFilter(layerStack1, false);
Lloyd Pique66c20c42019-03-07 21:44:02 -0800544
Lloyd Pique66c20c42019-03-07 21:44:02 -0800545 // Only non-internal layers with layerStack1 belong to it.
Lloyd Piquede196652020-01-22 17:29:58 -0800546 layer.layerFEState.layerStackId = layerStack1;
547 layer.layerFEState.internalOnly = false;
548 EXPECT_TRUE(mOutput->belongsInOutput(layerFE));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800549
Lloyd Piquede196652020-01-22 17:29:58 -0800550 layer.layerFEState.layerStackId = layerStack1;
551 layer.layerFEState.internalOnly = true;
552 EXPECT_FALSE(mOutput->belongsInOutput(layerFE));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800553
Lloyd Piquede196652020-01-22 17:29:58 -0800554 layer.layerFEState.layerStackId = layerStack2;
555 layer.layerFEState.internalOnly = true;
556 EXPECT_FALSE(mOutput->belongsInOutput(layerFE));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800557
Lloyd Piquede196652020-01-22 17:29:58 -0800558 layer.layerFEState.layerStackId = layerStack2;
559 layer.layerFEState.internalOnly = false;
560 EXPECT_FALSE(mOutput->belongsInOutput(layerFE));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800561}
562
Lloyd Pique66d68602019-02-13 14:23:31 -0800563/*
Lloyd Piquecc01a452018-12-04 17:24:00 -0800564 * Output::getOutputLayerForLayer()
565 */
566
567TEST_F(OutputTest, getOutputLayerForLayerWorks) {
Lloyd Piquede196652020-01-22 17:29:58 -0800568 InjectedLayer layer1;
569 InjectedLayer layer2;
570 NonInjectedLayer layer3;
Lloyd Piquecc01a452018-12-04 17:24:00 -0800571
Lloyd Piquede196652020-01-22 17:29:58 -0800572 injectOutputLayer(layer1);
573 injectNullOutputLayer();
574 injectOutputLayer(layer2);
Lloyd Piquecc01a452018-12-04 17:24:00 -0800575
576 // If the input layer matches the first OutputLayer, it will be returned.
Lloyd Piquede196652020-01-22 17:29:58 -0800577 EXPECT_CALL(*layer1.outputLayer, getLayerFE()).WillOnce(ReturnRef(*layer1.layerFE.get()));
578 EXPECT_EQ(layer1.outputLayer, mOutput->getOutputLayerForLayer(layer1.layerFE));
Lloyd Piquecc01a452018-12-04 17:24:00 -0800579
580 // If the input layer matches the second OutputLayer, it will be returned.
Lloyd Piquede196652020-01-22 17:29:58 -0800581 EXPECT_CALL(*layer1.outputLayer, getLayerFE()).WillOnce(ReturnRef(*layer1.layerFE.get()));
582 EXPECT_CALL(*layer2.outputLayer, getLayerFE()).WillOnce(ReturnRef(*layer2.layerFE.get()));
583 EXPECT_EQ(layer2.outputLayer, mOutput->getOutputLayerForLayer(layer2.layerFE));
Lloyd Piquecc01a452018-12-04 17:24:00 -0800584
585 // If the input layer does not match an output layer, null will be returned.
Lloyd Piquede196652020-01-22 17:29:58 -0800586 EXPECT_CALL(*layer1.outputLayer, getLayerFE()).WillOnce(ReturnRef(*layer1.layerFE.get()));
587 EXPECT_CALL(*layer2.outputLayer, getLayerFE()).WillOnce(ReturnRef(*layer2.layerFE.get()));
588 EXPECT_EQ(nullptr, mOutput->getOutputLayerForLayer(layer3.layerFE));
Lloyd Piquecc01a452018-12-04 17:24:00 -0800589}
590
Lloyd Pique66d68602019-02-13 14:23:31 -0800591/*
Lloyd Piquec9e60032019-11-14 11:47:26 -0800592 * Output::setReleasedLayers()
593 */
594
595using OutputSetReleasedLayersTest = OutputTest;
596
597TEST_F(OutputSetReleasedLayersTest, setReleasedLayersTakesGivenLayers) {
598 sp<StrictMock<mock::LayerFE>> layer1FE{new StrictMock<mock::LayerFE>()};
599 sp<StrictMock<mock::LayerFE>> layer2FE{new StrictMock<mock::LayerFE>()};
600 sp<StrictMock<mock::LayerFE>> layer3FE{new StrictMock<mock::LayerFE>()};
601
602 Output::ReleasedLayers layers;
603 layers.push_back(layer1FE);
604 layers.push_back(layer2FE);
605 layers.push_back(layer3FE);
606
607 mOutput->setReleasedLayers(std::move(layers));
608
609 const auto& setLayers = mOutput->getReleasedLayersForTest();
610 ASSERT_EQ(3u, setLayers.size());
611 ASSERT_EQ(layer1FE.get(), setLayers[0].promote().get());
612 ASSERT_EQ(layer2FE.get(), setLayers[1].promote().get());
613 ASSERT_EQ(layer3FE.get(), setLayers[2].promote().get());
614}
615
616/*
Lloyd Piquec0ee6ba2019-11-14 12:55:53 -0800617 * Output::updateLayerStateFromFE()
618 */
619
Lloyd Piquede196652020-01-22 17:29:58 -0800620using OutputUpdateLayerStateFromFETest = OutputTest;
Lloyd Piquec0ee6ba2019-11-14 12:55:53 -0800621
622TEST_F(OutputUpdateLayerStateFromFETest, handlesNoOutputLayerCase) {
623 CompositionRefreshArgs refreshArgs;
624
625 mOutput->updateLayerStateFromFE(refreshArgs);
626}
627
Lloyd Piquede196652020-01-22 17:29:58 -0800628TEST_F(OutputUpdateLayerStateFromFETest, preparesContentStateForAllContainedLayers) {
629 InjectedLayer layer1;
630 InjectedLayer layer2;
631 InjectedLayer layer3;
Lloyd Piquec0ee6ba2019-11-14 12:55:53 -0800632
Lloyd Piquede196652020-01-22 17:29:58 -0800633 EXPECT_CALL(*layer1.layerFE.get(), prepareCompositionState(LayerFE::StateSubset::Content));
634 EXPECT_CALL(*layer2.layerFE.get(), prepareCompositionState(LayerFE::StateSubset::Content));
635 EXPECT_CALL(*layer3.layerFE.get(), prepareCompositionState(LayerFE::StateSubset::Content));
636
637 injectOutputLayer(layer1);
638 injectOutputLayer(layer2);
639 injectOutputLayer(layer3);
Lloyd Piquec0ee6ba2019-11-14 12:55:53 -0800640
641 CompositionRefreshArgs refreshArgs;
642 refreshArgs.updatingGeometryThisFrame = false;
643
644 mOutput->updateLayerStateFromFE(refreshArgs);
645}
646
Lloyd Piquede196652020-01-22 17:29:58 -0800647TEST_F(OutputUpdateLayerStateFromFETest, preparesGeometryAndContentStateForAllContainedLayers) {
648 InjectedLayer layer1;
649 InjectedLayer layer2;
650 InjectedLayer layer3;
Lloyd Piquec0ee6ba2019-11-14 12:55:53 -0800651
Lloyd Piquede196652020-01-22 17:29:58 -0800652 EXPECT_CALL(*layer1.layerFE, prepareCompositionState(LayerFE::StateSubset::GeometryAndContent));
653 EXPECT_CALL(*layer2.layerFE, prepareCompositionState(LayerFE::StateSubset::GeometryAndContent));
654 EXPECT_CALL(*layer3.layerFE, prepareCompositionState(LayerFE::StateSubset::GeometryAndContent));
655
656 injectOutputLayer(layer1);
657 injectOutputLayer(layer2);
658 injectOutputLayer(layer3);
Lloyd Piquec0ee6ba2019-11-14 12:55:53 -0800659
660 CompositionRefreshArgs refreshArgs;
661 refreshArgs.updatingGeometryThisFrame = true;
662
663 mOutput->updateLayerStateFromFE(refreshArgs);
664}
665
666/*
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800667 * Output::updateAndWriteCompositionState()
668 */
669
Lloyd Piquede196652020-01-22 17:29:58 -0800670using OutputUpdateAndWriteCompositionStateTest = OutputTest;
Lloyd Piqueef63b612019-11-14 13:19:56 -0800671
672TEST_F(OutputUpdateAndWriteCompositionStateTest, doesNothingIfLayers) {
673 mOutput->editState().isEnabled = true;
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800674
675 CompositionRefreshArgs args;
676 mOutput->updateAndWriteCompositionState(args);
677}
678
Lloyd Piqueef63b612019-11-14 13:19:56 -0800679TEST_F(OutputUpdateAndWriteCompositionStateTest, doesNothingIfOutputNotEnabled) {
Lloyd Piquede196652020-01-22 17:29:58 -0800680 InjectedLayer layer1;
681 InjectedLayer layer2;
682 InjectedLayer layer3;
683
Lloyd Piqueef63b612019-11-14 13:19:56 -0800684 mOutput->editState().isEnabled = false;
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800685
Lloyd Piquede196652020-01-22 17:29:58 -0800686 injectOutputLayer(layer1);
687 injectOutputLayer(layer2);
688 injectOutputLayer(layer3);
Lloyd Piqueef63b612019-11-14 13:19:56 -0800689
690 CompositionRefreshArgs args;
691 mOutput->updateAndWriteCompositionState(args);
692}
693
694TEST_F(OutputUpdateAndWriteCompositionStateTest, updatesLayerContentForAllLayers) {
Lloyd Piquede196652020-01-22 17:29:58 -0800695 InjectedLayer layer1;
696 InjectedLayer layer2;
697 InjectedLayer layer3;
Lloyd Piqueef63b612019-11-14 13:19:56 -0800698
Snild Dolkow9e217d62020-04-22 15:53:42 +0200699 EXPECT_CALL(*layer1.outputLayer, updateCompositionState(false, false, ui::Transform::ROT_180));
Lloyd Piquede196652020-01-22 17:29:58 -0800700 EXPECT_CALL(*layer1.outputLayer, writeStateToHWC(false));
Snild Dolkow9e217d62020-04-22 15:53:42 +0200701 EXPECT_CALL(*layer2.outputLayer, updateCompositionState(false, false, ui::Transform::ROT_180));
Lloyd Piquede196652020-01-22 17:29:58 -0800702 EXPECT_CALL(*layer2.outputLayer, writeStateToHWC(false));
Snild Dolkow9e217d62020-04-22 15:53:42 +0200703 EXPECT_CALL(*layer3.outputLayer, updateCompositionState(false, false, ui::Transform::ROT_180));
Lloyd Piquede196652020-01-22 17:29:58 -0800704 EXPECT_CALL(*layer3.outputLayer, writeStateToHWC(false));
705
706 injectOutputLayer(layer1);
707 injectOutputLayer(layer2);
708 injectOutputLayer(layer3);
Lloyd Piqueef63b612019-11-14 13:19:56 -0800709
710 mOutput->editState().isEnabled = true;
711
712 CompositionRefreshArgs args;
713 args.updatingGeometryThisFrame = false;
714 args.devOptForceClientComposition = false;
Snild Dolkow9e217d62020-04-22 15:53:42 +0200715 args.internalDisplayRotationFlags = ui::Transform::ROT_180;
Lloyd Piqueef63b612019-11-14 13:19:56 -0800716 mOutput->updateAndWriteCompositionState(args);
717}
718
719TEST_F(OutputUpdateAndWriteCompositionStateTest, updatesLayerGeometryAndContentForAllLayers) {
Lloyd Piquede196652020-01-22 17:29:58 -0800720 InjectedLayer layer1;
721 InjectedLayer layer2;
722 InjectedLayer layer3;
Lloyd Piqueef63b612019-11-14 13:19:56 -0800723
Snild Dolkow9e217d62020-04-22 15:53:42 +0200724 EXPECT_CALL(*layer1.outputLayer, updateCompositionState(true, false, ui::Transform::ROT_0));
Lloyd Piquede196652020-01-22 17:29:58 -0800725 EXPECT_CALL(*layer1.outputLayer, writeStateToHWC(true));
Snild Dolkow9e217d62020-04-22 15:53:42 +0200726 EXPECT_CALL(*layer2.outputLayer, updateCompositionState(true, false, ui::Transform::ROT_0));
Lloyd Piquede196652020-01-22 17:29:58 -0800727 EXPECT_CALL(*layer2.outputLayer, writeStateToHWC(true));
Snild Dolkow9e217d62020-04-22 15:53:42 +0200728 EXPECT_CALL(*layer3.outputLayer, updateCompositionState(true, false, ui::Transform::ROT_0));
Lloyd Piquede196652020-01-22 17:29:58 -0800729 EXPECT_CALL(*layer3.outputLayer, writeStateToHWC(true));
730
731 injectOutputLayer(layer1);
732 injectOutputLayer(layer2);
733 injectOutputLayer(layer3);
Lloyd Piqueef63b612019-11-14 13:19:56 -0800734
735 mOutput->editState().isEnabled = true;
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800736
737 CompositionRefreshArgs args;
738 args.updatingGeometryThisFrame = true;
Lloyd Piqueef63b612019-11-14 13:19:56 -0800739 args.devOptForceClientComposition = false;
740 mOutput->updateAndWriteCompositionState(args);
741}
742
743TEST_F(OutputUpdateAndWriteCompositionStateTest, forcesClientCompositionForAllLayers) {
Lloyd Piquede196652020-01-22 17:29:58 -0800744 InjectedLayer layer1;
745 InjectedLayer layer2;
746 InjectedLayer layer3;
Lloyd Piqueef63b612019-11-14 13:19:56 -0800747
Snild Dolkow9e217d62020-04-22 15:53:42 +0200748 EXPECT_CALL(*layer1.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0));
Lloyd Piquede196652020-01-22 17:29:58 -0800749 EXPECT_CALL(*layer1.outputLayer, writeStateToHWC(false));
Snild Dolkow9e217d62020-04-22 15:53:42 +0200750 EXPECT_CALL(*layer2.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0));
Lloyd Piquede196652020-01-22 17:29:58 -0800751 EXPECT_CALL(*layer2.outputLayer, writeStateToHWC(false));
Snild Dolkow9e217d62020-04-22 15:53:42 +0200752 EXPECT_CALL(*layer3.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0));
Lloyd Piquede196652020-01-22 17:29:58 -0800753 EXPECT_CALL(*layer3.outputLayer, writeStateToHWC(false));
754
755 injectOutputLayer(layer1);
756 injectOutputLayer(layer2);
757 injectOutputLayer(layer3);
Lloyd Piqueef63b612019-11-14 13:19:56 -0800758
759 mOutput->editState().isEnabled = true;
760
761 CompositionRefreshArgs args;
762 args.updatingGeometryThisFrame = false;
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800763 args.devOptForceClientComposition = true;
764 mOutput->updateAndWriteCompositionState(args);
765}
766
767/*
Lloyd Pique66d68602019-02-13 14:23:31 -0800768 * Output::prepareFrame()
769 */
770
771struct OutputPrepareFrameTest : public testing::Test {
Lloyd Piquefaa3f192019-11-14 14:05:09 -0800772 struct OutputPartialMock : public OutputPartialMockBase {
Lloyd Pique739afaf2019-11-21 16:40:05 -0800773 // Sets up the helper functions called by the function under test to use
774 // mock implementations.
Lloyd Pique66d68602019-02-13 14:23:31 -0800775 MOCK_METHOD0(chooseCompositionStrategy, void());
776 };
777
778 OutputPrepareFrameTest() {
779 mOutput.setDisplayColorProfileForTest(
780 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
781 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
782 }
783
784 StrictMock<mock::CompositionEngine> mCompositionEngine;
785 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
786 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700787 StrictMock<OutputPartialMock> mOutput;
Lloyd Pique66d68602019-02-13 14:23:31 -0800788};
789
790TEST_F(OutputPrepareFrameTest, takesEarlyOutIfNotEnabled) {
791 mOutput.editState().isEnabled = false;
792
793 mOutput.prepareFrame();
794}
795
796TEST_F(OutputPrepareFrameTest, delegatesToChooseCompositionStrategyAndRenderSurface) {
797 mOutput.editState().isEnabled = true;
798 mOutput.editState().usesClientComposition = false;
799 mOutput.editState().usesDeviceComposition = true;
800
801 EXPECT_CALL(mOutput, chooseCompositionStrategy()).Times(1);
802 EXPECT_CALL(*mRenderSurface, prepareFrame(false, true));
803
804 mOutput.prepareFrame();
805}
806
807// Note: Use OutputTest and not OutputPrepareFrameTest, so the real
808// base chooseCompositionStrategy() is invoked.
809TEST_F(OutputTest, prepareFrameSetsClientCompositionOnlyByDefault) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700810 mOutput->editState().isEnabled = true;
811 mOutput->editState().usesClientComposition = false;
812 mOutput->editState().usesDeviceComposition = true;
Lloyd Pique66d68602019-02-13 14:23:31 -0800813
814 EXPECT_CALL(*mRenderSurface, prepareFrame(true, false));
815
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700816 mOutput->prepareFrame();
Lloyd Pique66d68602019-02-13 14:23:31 -0800817
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700818 EXPECT_TRUE(mOutput->getState().usesClientComposition);
819 EXPECT_FALSE(mOutput->getState().usesDeviceComposition);
Lloyd Pique66d68602019-02-13 14:23:31 -0800820}
821
Lloyd Pique56eba802019-08-28 15:45:25 -0700822/*
Lloyd Piqueb62cebc2019-11-20 18:31:52 -0800823 * Output::prepare()
824 */
825
826struct OutputPrepareTest : public testing::Test {
827 struct OutputPartialMock : public OutputPartialMockBase {
828 // Sets up the helper functions called by the function under test to use
829 // mock implementations.
830 MOCK_METHOD2(rebuildLayerStacks,
831 void(const compositionengine::CompositionRefreshArgs&,
832 compositionengine::LayerFESet&));
833 };
834
835 StrictMock<OutputPartialMock> mOutput;
836 CompositionRefreshArgs mRefreshArgs;
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -0800837 LayerFESet mGeomSnapshots;
Lloyd Piqueb62cebc2019-11-20 18:31:52 -0800838};
839
840TEST_F(OutputPrepareTest, justInvokesRebuildLayerStacks) {
841 InSequence seq;
842 EXPECT_CALL(mOutput, rebuildLayerStacks(Ref(mRefreshArgs), Ref(mGeomSnapshots)));
843
844 mOutput.prepare(mRefreshArgs, mGeomSnapshots);
845}
846
847/*
848 * Output::rebuildLayerStacks()
849 */
850
851struct OutputRebuildLayerStacksTest : public testing::Test {
852 struct OutputPartialMock : public OutputPartialMockBase {
853 // Sets up the helper functions called by the function under test to use
854 // mock implementations.
855 MOCK_METHOD2(collectVisibleLayers,
856 void(const compositionengine::CompositionRefreshArgs&,
857 compositionengine::Output::CoverageState&));
858 };
859
860 OutputRebuildLayerStacksTest() {
861 mOutput.mState.isEnabled = true;
862 mOutput.mState.transform = kIdentityTransform;
863 mOutput.mState.bounds = kOutputBounds;
864
865 mRefreshArgs.updatingOutputGeometryThisFrame = true;
866
867 mCoverageAboveCoveredLayersToSet = Region(Rect(0, 0, 10, 10));
868
869 EXPECT_CALL(mOutput, collectVisibleLayers(Ref(mRefreshArgs), _))
870 .WillRepeatedly(Invoke(this, &OutputRebuildLayerStacksTest::setTestCoverageValues));
871 }
872
873 void setTestCoverageValues(const CompositionRefreshArgs&,
874 compositionengine::Output::CoverageState& state) {
875 state.aboveCoveredLayers = mCoverageAboveCoveredLayersToSet;
876 state.aboveOpaqueLayers = mCoverageAboveOpaqueLayersToSet;
877 state.dirtyRegion = mCoverageDirtyRegionToSet;
878 }
879
880 static const ui::Transform kIdentityTransform;
881 static const ui::Transform kRotate90Transform;
882 static const Rect kOutputBounds;
883
884 StrictMock<OutputPartialMock> mOutput;
885 CompositionRefreshArgs mRefreshArgs;
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -0800886 LayerFESet mGeomSnapshots;
Lloyd Piqueb62cebc2019-11-20 18:31:52 -0800887 Region mCoverageAboveCoveredLayersToSet;
888 Region mCoverageAboveOpaqueLayersToSet;
889 Region mCoverageDirtyRegionToSet;
890};
891
892const ui::Transform OutputRebuildLayerStacksTest::kIdentityTransform{TR_IDENT, 1920, 1080};
893const ui::Transform OutputRebuildLayerStacksTest::kRotate90Transform{TR_ROT_90, 1920, 1080};
894const Rect OutputRebuildLayerStacksTest::kOutputBounds{0, 0, 1920, 1080};
895
896TEST_F(OutputRebuildLayerStacksTest, doesNothingIfNotEnabled) {
897 mOutput.mState.isEnabled = false;
898
899 mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
900}
901
902TEST_F(OutputRebuildLayerStacksTest, doesNothingIfNotUpdatingGeometryThisFrame) {
903 mRefreshArgs.updatingOutputGeometryThisFrame = false;
904
905 mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
906}
907
908TEST_F(OutputRebuildLayerStacksTest, computesUndefinedRegionWithNoRotationAndFullCoverage) {
909 mOutput.mState.transform = kIdentityTransform;
910
911 mCoverageAboveOpaqueLayersToSet = Region(Rect(0, 0, 1920, 1080));
912
913 mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
914
915 EXPECT_THAT(mOutput.mState.undefinedRegion, RegionEq(Region(Rect(0, 0, 0, 0))));
916}
917
918TEST_F(OutputRebuildLayerStacksTest, computesUndefinedRegionWithNoRotationAndPartialCoverage) {
919 mOutput.mState.transform = kIdentityTransform;
920
921 mCoverageAboveOpaqueLayersToSet = Region(Rect(0, 0, 960, 1080));
922
923 mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
924
925 EXPECT_THAT(mOutput.mState.undefinedRegion, RegionEq(Region(Rect(960, 0, 1920, 1080))));
926}
927
928TEST_F(OutputRebuildLayerStacksTest, computesUndefinedRegionWith90RotationAndFullCoverage) {
929 mOutput.mState.transform = kRotate90Transform;
930
931 mCoverageAboveOpaqueLayersToSet = Region(Rect(0, 0, 1080, 1920));
932
933 mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
934
935 EXPECT_THAT(mOutput.mState.undefinedRegion, RegionEq(Region(Rect(0, 0, 0, 0))));
936}
937
938TEST_F(OutputRebuildLayerStacksTest, computesUndefinedRegionWith90RotationAndPartialCoverage) {
939 mOutput.mState.transform = kRotate90Transform;
940
941 mCoverageAboveOpaqueLayersToSet = Region(Rect(0, 0, 1080, 960));
942
943 mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
944
945 EXPECT_THAT(mOutput.mState.undefinedRegion, RegionEq(Region(Rect(0, 0, 960, 1080))));
946}
947
948TEST_F(OutputRebuildLayerStacksTest, addsToDirtyRegionWithNoRotation) {
949 mOutput.mState.transform = kIdentityTransform;
950 mOutput.mState.dirtyRegion = Region(Rect(960, 0, 1920, 1080));
951
952 mCoverageDirtyRegionToSet = Region(Rect(0, 0, 960, 1080));
953
954 mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
955
956 EXPECT_THAT(mOutput.mState.dirtyRegion, RegionEq(Region(Rect(0, 0, 1920, 1080))));
957}
958
959TEST_F(OutputRebuildLayerStacksTest, addsToDirtyRegionWith90Rotation) {
960 mOutput.mState.transform = kRotate90Transform;
961 mOutput.mState.dirtyRegion = Region(Rect(0, 960, 1080, 1920));
962
963 mCoverageDirtyRegionToSet = Region(Rect(0, 0, 1080, 960));
964
965 mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
966
967 EXPECT_THAT(mOutput.mState.dirtyRegion, RegionEq(Region(Rect(0, 0, 1080, 1920))));
968}
969
970/*
971 * Output::collectVisibleLayers()
972 */
973
Lloyd Pique1ef93222019-11-21 16:41:53 -0800974struct OutputCollectVisibleLayersTest : public testing::Test {
975 struct OutputPartialMock : public OutputPartialMockBase {
976 // Sets up the helper functions called by the function under test to use
977 // mock implementations.
978 MOCK_METHOD2(ensureOutputLayerIfVisible,
Lloyd Piquede196652020-01-22 17:29:58 -0800979 void(sp<compositionengine::LayerFE>&,
Lloyd Pique1ef93222019-11-21 16:41:53 -0800980 compositionengine::Output::CoverageState&));
981 MOCK_METHOD1(setReleasedLayers, void(const compositionengine::CompositionRefreshArgs&));
982 MOCK_METHOD0(finalizePendingOutputLayers, void());
983 };
984
985 struct Layer {
986 Layer() {
987 EXPECT_CALL(outputLayer, getState()).WillRepeatedly(ReturnRef(outputLayerState));
988 EXPECT_CALL(outputLayer, editState()).WillRepeatedly(ReturnRef(outputLayerState));
989 }
990
991 StrictMock<mock::OutputLayer> outputLayer;
Lloyd Pique1ef93222019-11-21 16:41:53 -0800992 impl::OutputLayerCompositionState outputLayerState;
Lloyd Piquede196652020-01-22 17:29:58 -0800993 sp<StrictMock<mock::LayerFE>> layerFE{new StrictMock<mock::LayerFE>()};
Lloyd Pique1ef93222019-11-21 16:41:53 -0800994 };
995
996 OutputCollectVisibleLayersTest() {
Lloyd Pique0a456232020-01-16 17:51:13 -0800997 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(3u));
Lloyd Pique1ef93222019-11-21 16:41:53 -0800998 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0))
999 .WillRepeatedly(Return(&mLayer1.outputLayer));
1000 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1))
1001 .WillRepeatedly(Return(&mLayer2.outputLayer));
1002 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(2))
1003 .WillRepeatedly(Return(&mLayer3.outputLayer));
1004
Lloyd Piquede196652020-01-22 17:29:58 -08001005 mRefreshArgs.layers.push_back(mLayer1.layerFE);
1006 mRefreshArgs.layers.push_back(mLayer2.layerFE);
1007 mRefreshArgs.layers.push_back(mLayer3.layerFE);
Lloyd Pique1ef93222019-11-21 16:41:53 -08001008 }
1009
1010 StrictMock<OutputPartialMock> mOutput;
1011 CompositionRefreshArgs mRefreshArgs;
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001012 LayerFESet mGeomSnapshots;
1013 Output::CoverageState mCoverageState{mGeomSnapshots};
Lloyd Pique1ef93222019-11-21 16:41:53 -08001014 Layer mLayer1;
1015 Layer mLayer2;
1016 Layer mLayer3;
1017};
1018
1019TEST_F(OutputCollectVisibleLayersTest, doesMinimalWorkIfNoLayers) {
1020 mRefreshArgs.layers.clear();
Lloyd Pique0a456232020-01-16 17:51:13 -08001021 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0u));
Lloyd Pique1ef93222019-11-21 16:41:53 -08001022
1023 EXPECT_CALL(mOutput, setReleasedLayers(Ref(mRefreshArgs)));
1024 EXPECT_CALL(mOutput, finalizePendingOutputLayers());
1025
1026 mOutput.collectVisibleLayers(mRefreshArgs, mCoverageState);
1027}
1028
1029TEST_F(OutputCollectVisibleLayersTest, processesCandidateLayersReversedAndSetsOutputLayerZ) {
1030 // Enforce a call order sequence for this test.
1031 InSequence seq;
1032
1033 // Layer coverage is evaluated from front to back!
Lloyd Piquede196652020-01-22 17:29:58 -08001034 EXPECT_CALL(mOutput, ensureOutputLayerIfVisible(Eq(mLayer3.layerFE), Ref(mCoverageState)));
1035 EXPECT_CALL(mOutput, ensureOutputLayerIfVisible(Eq(mLayer2.layerFE), Ref(mCoverageState)));
1036 EXPECT_CALL(mOutput, ensureOutputLayerIfVisible(Eq(mLayer1.layerFE), Ref(mCoverageState)));
Lloyd Pique1ef93222019-11-21 16:41:53 -08001037
1038 EXPECT_CALL(mOutput, setReleasedLayers(Ref(mRefreshArgs)));
1039 EXPECT_CALL(mOutput, finalizePendingOutputLayers());
1040
1041 mOutput.collectVisibleLayers(mRefreshArgs, mCoverageState);
1042
1043 // Ensure all output layers have been assigned a simple/flattened z-order.
1044 EXPECT_EQ(0u, mLayer1.outputLayerState.z);
1045 EXPECT_EQ(1u, mLayer2.outputLayerState.z);
1046 EXPECT_EQ(2u, mLayer3.outputLayerState.z);
1047}
Lloyd Piqueb62cebc2019-11-20 18:31:52 -08001048
1049/*
1050 * Output::ensureOutputLayerIfVisible()
1051 */
1052
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001053struct OutputEnsureOutputLayerIfVisibleTest : public testing::Test {
1054 struct OutputPartialMock : public OutputPartialMockBase {
1055 // Sets up the helper functions called by the function under test to use
1056 // mock implementations.
Lloyd Piquede196652020-01-22 17:29:58 -08001057 MOCK_CONST_METHOD1(belongsInOutput, bool(const sp<compositionengine::LayerFE>&));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001058 MOCK_CONST_METHOD1(getOutputLayerOrderedByZByIndex, OutputLayer*(size_t));
Lloyd Piquede196652020-01-22 17:29:58 -08001059 MOCK_METHOD2(ensureOutputLayer,
1060 compositionengine::OutputLayer*(std::optional<size_t>, const sp<LayerFE>&));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001061 };
1062
1063 OutputEnsureOutputLayerIfVisibleTest() {
Lloyd Piquede196652020-01-22 17:29:58 -08001064 EXPECT_CALL(mOutput, belongsInOutput(sp<LayerFE>(mLayer.layerFE)))
1065 .WillRepeatedly(Return(true));
Lloyd Pique0a456232020-01-16 17:51:13 -08001066 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(1u));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001067 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u))
Lloyd Piquede196652020-01-22 17:29:58 -08001068 .WillRepeatedly(Return(&mLayer.outputLayer));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001069
1070 mOutput.mState.bounds = Rect(0, 0, 200, 300);
1071 mOutput.mState.viewport = Rect(0, 0, 200, 300);
1072 mOutput.mState.transform = ui::Transform(TR_IDENT, 200, 300);
1073
Lloyd Piquede196652020-01-22 17:29:58 -08001074 mLayer.layerFEState.isVisible = true;
1075 mLayer.layerFEState.isOpaque = true;
1076 mLayer.layerFEState.contentDirty = true;
1077 mLayer.layerFEState.geomLayerBounds = FloatRect{0, 0, 100, 200};
1078 mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
1079 mLayer.layerFEState.transparentRegionHint = Region(Rect(0, 0, 100, 100));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001080
Lloyd Piquede196652020-01-22 17:29:58 -08001081 mLayer.outputLayerState.visibleRegion = Region(Rect(0, 0, 50, 200));
1082 mLayer.outputLayerState.coveredRegion = Region(Rect(50, 0, 100, 200));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001083
Lloyd Piquede196652020-01-22 17:29:58 -08001084 mGeomSnapshots.insert(mLayer.layerFE);
1085 }
1086
1087 void ensureOutputLayerIfVisible() {
1088 sp<LayerFE> layerFE(mLayer.layerFE);
1089 mOutput.ensureOutputLayerIfVisible(layerFE, mCoverageState);
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001090 }
1091
1092 static const Region kEmptyRegion;
1093 static const Region kFullBoundsNoRotation;
1094 static const Region kRightHalfBoundsNoRotation;
1095 static const Region kLowerHalfBoundsNoRotation;
1096 static const Region kFullBounds90Rotation;
1097
1098 StrictMock<OutputPartialMock> mOutput;
1099 LayerFESet mGeomSnapshots;
1100 Output::CoverageState mCoverageState{mGeomSnapshots};
1101
Lloyd Piquede196652020-01-22 17:29:58 -08001102 NonInjectedLayer mLayer;
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001103};
1104
1105const Region OutputEnsureOutputLayerIfVisibleTest::kEmptyRegion = Region(Rect(0, 0, 0, 0));
1106const Region OutputEnsureOutputLayerIfVisibleTest::kFullBoundsNoRotation =
1107 Region(Rect(0, 0, 100, 200));
1108const Region OutputEnsureOutputLayerIfVisibleTest::kRightHalfBoundsNoRotation =
1109 Region(Rect(0, 100, 100, 200));
1110const Region OutputEnsureOutputLayerIfVisibleTest::kLowerHalfBoundsNoRotation =
1111 Region(Rect(50, 0, 100, 200));
1112const Region OutputEnsureOutputLayerIfVisibleTest::kFullBounds90Rotation =
1113 Region(Rect(0, 0, 200, 100));
1114
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001115TEST_F(OutputEnsureOutputLayerIfVisibleTest, performsGeomLatchBeforeCheckingIfLayerBelongs) {
Lloyd Piquede196652020-01-22 17:29:58 -08001116 EXPECT_CALL(mOutput, belongsInOutput(sp<LayerFE>(mLayer.layerFE))).WillOnce(Return(false));
1117 EXPECT_CALL(*mLayer.layerFE,
1118 prepareCompositionState(compositionengine::LayerFE::StateSubset::BasicGeometry));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001119
1120 mGeomSnapshots.clear();
1121
Lloyd Piquede196652020-01-22 17:29:58 -08001122 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001123}
1124
1125TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1126 skipsLatchIfAlreadyLatchedBeforeCheckingIfLayerBelongs) {
Lloyd Piquede196652020-01-22 17:29:58 -08001127 EXPECT_CALL(mOutput, belongsInOutput(sp<LayerFE>(mLayer.layerFE))).WillOnce(Return(false));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001128
Lloyd Piquede196652020-01-22 17:29:58 -08001129 ensureOutputLayerIfVisible();
1130}
1131
1132TEST_F(OutputEnsureOutputLayerIfVisibleTest, takesEarlyOutIfLayerHasNoCompositionState) {
1133 EXPECT_CALL(*mLayer.layerFE, getCompositionState()).WillOnce(Return(nullptr));
1134
1135 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001136}
1137
1138TEST_F(OutputEnsureOutputLayerIfVisibleTest, takesEarlyOutIfLayerNotVisible) {
Lloyd Piquede196652020-01-22 17:29:58 -08001139 mLayer.layerFEState.isVisible = false;
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001140
Lloyd Piquede196652020-01-22 17:29:58 -08001141 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001142}
1143
1144TEST_F(OutputEnsureOutputLayerIfVisibleTest, takesEarlyOutIfLayerHasEmptyVisibleRegion) {
Lloyd Piquede196652020-01-22 17:29:58 -08001145 mLayer.layerFEState.geomLayerBounds = FloatRect{0, 0, 0, 0};
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001146
Lloyd Piquede196652020-01-22 17:29:58 -08001147 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001148}
1149
1150TEST_F(OutputEnsureOutputLayerIfVisibleTest, takesNotSoEarlyOutifDrawRegionEmpty) {
1151 mOutput.mState.bounds = Rect(0, 0, 0, 0);
1152
Lloyd Piquede196652020-01-22 17:29:58 -08001153 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001154}
1155
1156TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1157 handlesCreatingOutputLayerForOpaqueDirtyNotRotatedLayer) {
Lloyd Piquede196652020-01-22 17:29:58 -08001158 mLayer.layerFEState.isOpaque = true;
1159 mLayer.layerFEState.contentDirty = true;
1160 mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001161
1162 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
Lloyd Piquede196652020-01-22 17:29:58 -08001163 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE)))
1164 .WillOnce(Return(&mLayer.outputLayer));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001165
Lloyd Piquede196652020-01-22 17:29:58 -08001166 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001167
1168 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1169 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1170 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
1171
Lloyd Piquede196652020-01-22 17:29:58 -08001172 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1173 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
1174 RegionEq(kFullBoundsNoRotation));
1175 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1176 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001177}
1178
1179TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1180 handlesUpdatingOutputLayerForOpaqueDirtyNotRotatedLayer) {
Lloyd Piquede196652020-01-22 17:29:58 -08001181 mLayer.layerFEState.isOpaque = true;
1182 mLayer.layerFEState.contentDirty = true;
1183 mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001184
Lloyd Piquede196652020-01-22 17:29:58 -08001185 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE)))
1186 .WillOnce(Return(&mLayer.outputLayer));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001187
Lloyd Piquede196652020-01-22 17:29:58 -08001188 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001189
1190 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1191 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1192 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
1193
Lloyd Piquede196652020-01-22 17:29:58 -08001194 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1195 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
1196 RegionEq(kFullBoundsNoRotation));
1197 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1198 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001199}
1200
1201TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1202 handlesCreatingOutputLayerForTransparentDirtyNotRotatedLayer) {
Lloyd Piquede196652020-01-22 17:29:58 -08001203 mLayer.layerFEState.isOpaque = false;
1204 mLayer.layerFEState.contentDirty = true;
1205 mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001206
1207 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
Lloyd Piquede196652020-01-22 17:29:58 -08001208 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE)))
1209 .WillOnce(Return(&mLayer.outputLayer));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001210
Lloyd Piquede196652020-01-22 17:29:58 -08001211 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001212
1213 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1214 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1215 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kEmptyRegion));
1216
Lloyd Piquede196652020-01-22 17:29:58 -08001217 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1218 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001219 RegionEq(kRightHalfBoundsNoRotation));
Lloyd Piquede196652020-01-22 17:29:58 -08001220 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1221 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001222}
1223
1224TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1225 handlesUpdatingOutputLayerForTransparentDirtyNotRotatedLayer) {
Lloyd Piquede196652020-01-22 17:29:58 -08001226 mLayer.layerFEState.isOpaque = false;
1227 mLayer.layerFEState.contentDirty = true;
1228 mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001229
Lloyd Piquede196652020-01-22 17:29:58 -08001230 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE)))
1231 .WillOnce(Return(&mLayer.outputLayer));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001232
Lloyd Piquede196652020-01-22 17:29:58 -08001233 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001234
1235 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1236 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1237 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kEmptyRegion));
1238
Lloyd Piquede196652020-01-22 17:29:58 -08001239 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1240 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001241 RegionEq(kRightHalfBoundsNoRotation));
Lloyd Piquede196652020-01-22 17:29:58 -08001242 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1243 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001244}
1245
1246TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1247 handlesCreatingOutputLayerForOpaqueNonDirtyNotRotatedLayer) {
Lloyd Piquede196652020-01-22 17:29:58 -08001248 mLayer.layerFEState.isOpaque = true;
1249 mLayer.layerFEState.contentDirty = false;
1250 mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001251
1252 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
Lloyd Piquede196652020-01-22 17:29:58 -08001253 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE)))
1254 .WillOnce(Return(&mLayer.outputLayer));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001255
Lloyd Piquede196652020-01-22 17:29:58 -08001256 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001257
1258 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1259 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1260 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
1261
Lloyd Piquede196652020-01-22 17:29:58 -08001262 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1263 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
1264 RegionEq(kFullBoundsNoRotation));
1265 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1266 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001267}
1268
1269TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1270 handlesUpdatingOutputLayerForOpaqueNonDirtyNotRotatedLayer) {
Lloyd Piquede196652020-01-22 17:29:58 -08001271 mLayer.layerFEState.isOpaque = true;
1272 mLayer.layerFEState.contentDirty = false;
1273 mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001274
Lloyd Piquede196652020-01-22 17:29:58 -08001275 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE)))
1276 .WillOnce(Return(&mLayer.outputLayer));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001277
Lloyd Piquede196652020-01-22 17:29:58 -08001278 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001279
1280 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kLowerHalfBoundsNoRotation));
1281 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1282 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
1283
Lloyd Piquede196652020-01-22 17:29:58 -08001284 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1285 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
1286 RegionEq(kFullBoundsNoRotation));
1287 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1288 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001289}
1290
1291TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1292 handlesCreatingOutputLayerForOpaqueDirtyRotated90Layer) {
Lloyd Piquede196652020-01-22 17:29:58 -08001293 mLayer.layerFEState.isOpaque = true;
1294 mLayer.layerFEState.contentDirty = true;
1295 mLayer.layerFEState.geomLayerBounds = FloatRect{0, 0, 200, 100};
1296 mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_ROT_90, 100, 200);
1297 mLayer.outputLayerState.visibleRegion = Region(Rect(0, 0, 100, 100));
1298 mLayer.outputLayerState.coveredRegion = Region(Rect(100, 0, 200, 100));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001299
1300 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
Lloyd Piquede196652020-01-22 17:29:58 -08001301 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE)))
1302 .WillOnce(Return(&mLayer.outputLayer));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001303
Lloyd Piquede196652020-01-22 17:29:58 -08001304 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001305
1306 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1307 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1308 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
1309
Lloyd Piquede196652020-01-22 17:29:58 -08001310 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1311 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
1312 RegionEq(kFullBoundsNoRotation));
1313 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1314 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001315}
1316
1317TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1318 handlesUpdatingOutputLayerForOpaqueDirtyRotated90Layer) {
Lloyd Piquede196652020-01-22 17:29:58 -08001319 mLayer.layerFEState.isOpaque = true;
1320 mLayer.layerFEState.contentDirty = true;
1321 mLayer.layerFEState.geomLayerBounds = FloatRect{0, 0, 200, 100};
1322 mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_ROT_90, 100, 200);
1323 mLayer.outputLayerState.visibleRegion = Region(Rect(0, 0, 100, 100));
1324 mLayer.outputLayerState.coveredRegion = Region(Rect(100, 0, 200, 100));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001325
Lloyd Piquede196652020-01-22 17:29:58 -08001326 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE)))
1327 .WillOnce(Return(&mLayer.outputLayer));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001328
Lloyd Piquede196652020-01-22 17:29:58 -08001329 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001330
1331 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1332 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1333 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
1334
Lloyd Piquede196652020-01-22 17:29:58 -08001335 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1336 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
1337 RegionEq(kFullBoundsNoRotation));
1338 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1339 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001340}
1341
1342TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1343 handlesCreatingOutputLayerForOpaqueDirtyNotRotatedLayerRotatedOutput) {
Lloyd Piquede196652020-01-22 17:29:58 -08001344 mLayer.layerFEState.isOpaque = true;
1345 mLayer.layerFEState.contentDirty = true;
1346 mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001347
1348 mOutput.mState.viewport = Rect(0, 0, 300, 200);
1349 mOutput.mState.transform = ui::Transform(TR_ROT_90, 200, 300);
1350
1351 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
Lloyd Piquede196652020-01-22 17:29:58 -08001352 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE)))
1353 .WillOnce(Return(&mLayer.outputLayer));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001354
Lloyd Piquede196652020-01-22 17:29:58 -08001355 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001356
1357 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1358 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1359 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
1360
Lloyd Piquede196652020-01-22 17:29:58 -08001361 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1362 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
1363 RegionEq(kFullBoundsNoRotation));
1364 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1365 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBounds90Rotation));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001366}
1367
1368TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1369 handlesUpdatingOutputLayerForOpaqueDirtyNotRotatedLayerRotatedOutput) {
Lloyd Piquede196652020-01-22 17:29:58 -08001370 mLayer.layerFEState.isOpaque = true;
1371 mLayer.layerFEState.contentDirty = true;
1372 mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001373
1374 mOutput.mState.viewport = Rect(0, 0, 300, 200);
1375 mOutput.mState.transform = ui::Transform(TR_ROT_90, 200, 300);
1376
Lloyd Piquede196652020-01-22 17:29:58 -08001377 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE)))
1378 .WillOnce(Return(&mLayer.outputLayer));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001379
Lloyd Piquede196652020-01-22 17:29:58 -08001380 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001381
1382 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1383 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1384 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
1385
Lloyd Piquede196652020-01-22 17:29:58 -08001386 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1387 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
1388 RegionEq(kFullBoundsNoRotation));
1389 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1390 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBounds90Rotation));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001391}
1392
1393TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1394 handlesCreatingOutputLayerForOpaqueDirtyArbitraryTransformLayer) {
1395 ui::Transform arbitraryTransform;
1396 arbitraryTransform.set(1, 1, -1, 1);
1397 arbitraryTransform.set(0, 100);
1398
Lloyd Piquede196652020-01-22 17:29:58 -08001399 mLayer.layerFEState.isOpaque = true;
1400 mLayer.layerFEState.contentDirty = true;
1401 mLayer.layerFEState.geomLayerBounds = FloatRect{0, 0, 100, 200};
1402 mLayer.layerFEState.geomLayerTransform = arbitraryTransform;
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001403
1404 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
Lloyd Piquede196652020-01-22 17:29:58 -08001405 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE)))
1406 .WillOnce(Return(&mLayer.outputLayer));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001407
Lloyd Piquede196652020-01-22 17:29:58 -08001408 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001409
1410 const Region kRegion = Region(Rect(0, 0, 300, 300));
1411 const Region kRegionClipped = Region(Rect(0, 0, 200, 300));
1412
1413 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kRegion));
1414 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kRegion));
1415 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kEmptyRegion));
1416
Lloyd Piquede196652020-01-22 17:29:58 -08001417 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kRegion));
1418 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion, RegionEq(kRegion));
1419 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1420 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kRegionClipped));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001421}
1422
1423TEST_F(OutputEnsureOutputLayerIfVisibleTest, coverageAccumulatesTest) {
Lloyd Piquede196652020-01-22 17:29:58 -08001424 mLayer.layerFEState.isOpaque = false;
1425 mLayer.layerFEState.contentDirty = true;
1426 mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001427
1428 mCoverageState.dirtyRegion = Region(Rect(0, 0, 500, 500));
1429 mCoverageState.aboveCoveredLayers = Region(Rect(50, 0, 150, 200));
1430 mCoverageState.aboveOpaqueLayers = Region(Rect(50, 0, 150, 200));
1431
Lloyd Piquede196652020-01-22 17:29:58 -08001432 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE)))
1433 .WillOnce(Return(&mLayer.outputLayer));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001434
Lloyd Piquede196652020-01-22 17:29:58 -08001435 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001436
1437 const Region kExpectedDirtyRegion = Region(Rect(0, 0, 500, 500));
1438 const Region kExpectedAboveCoveredRegion = Region(Rect(0, 0, 150, 200));
1439 const Region kExpectedAboveOpaqueRegion = Region(Rect(50, 0, 150, 200));
1440 const Region kExpectedLayerVisibleRegion = Region(Rect(0, 0, 50, 200));
1441 const Region kExpectedLayerCoveredRegion = Region(Rect(50, 0, 100, 200));
1442 const Region kExpectedLayerVisibleNonTransparentRegion = Region(Rect(0, 100, 50, 200));
1443
1444 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kExpectedDirtyRegion));
1445 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kExpectedAboveCoveredRegion));
1446 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kExpectedAboveOpaqueRegion));
1447
Lloyd Piquede196652020-01-22 17:29:58 -08001448 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kExpectedLayerVisibleRegion));
1449 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001450 RegionEq(kExpectedLayerVisibleNonTransparentRegion));
Lloyd Piquede196652020-01-22 17:29:58 -08001451 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kExpectedLayerCoveredRegion));
1452 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion,
1453 RegionEq(kExpectedLayerVisibleRegion));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001454}
Lloyd Piqueb62cebc2019-11-20 18:31:52 -08001455
Vishnu Naira483b4a2019-12-12 15:07:52 -08001456TEST_F(OutputEnsureOutputLayerIfVisibleTest, coverageAccumulatesWithShadowsTest) {
1457 ui::Transform translate;
1458 translate.set(50, 50);
Lloyd Piquede196652020-01-22 17:29:58 -08001459 mLayer.layerFEState.geomLayerTransform = translate;
1460 mLayer.layerFEState.shadowRadius = 10.0f;
Vishnu Naira483b4a2019-12-12 15:07:52 -08001461
1462 mCoverageState.dirtyRegion = Region(Rect(0, 0, 500, 500));
1463 // half of the layer including the casting shadow is covered and opaque
1464 mCoverageState.aboveCoveredLayers = Region(Rect(40, 40, 100, 260));
1465 mCoverageState.aboveOpaqueLayers = Region(Rect(40, 40, 100, 260));
1466
Lloyd Piquede196652020-01-22 17:29:58 -08001467 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE)))
1468 .WillOnce(Return(&mLayer.outputLayer));
Vishnu Naira483b4a2019-12-12 15:07:52 -08001469
Lloyd Piquede196652020-01-22 17:29:58 -08001470 ensureOutputLayerIfVisible();
Vishnu Naira483b4a2019-12-12 15:07:52 -08001471
1472 const Region kExpectedDirtyRegion = Region(Rect(0, 0, 500, 500));
1473 const Region kExpectedAboveCoveredRegion = Region(Rect(40, 40, 160, 260));
1474 // add starting opaque region to the opaque half of the casting layer bounds
1475 const Region kExpectedAboveOpaqueRegion =
1476 Region(Rect(40, 40, 100, 260)).orSelf(Rect(100, 50, 150, 250));
1477 const Region kExpectedLayerVisibleRegion = Region(Rect(100, 40, 160, 260));
1478 const Region kExpectedoutputSpaceLayerVisibleRegion = Region(Rect(100, 50, 150, 250));
1479 const Region kExpectedLayerCoveredRegion = Region(Rect(40, 40, 100, 260));
1480 const Region kExpectedLayerVisibleNonTransparentRegion = Region(Rect(100, 40, 160, 260));
1481 const Region kExpectedLayerShadowRegion =
1482 Region(Rect(40, 40, 160, 260)).subtractSelf(Rect(50, 50, 150, 250));
1483
1484 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kExpectedDirtyRegion));
1485 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kExpectedAboveCoveredRegion));
1486 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kExpectedAboveOpaqueRegion));
1487
Lloyd Piquede196652020-01-22 17:29:58 -08001488 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kExpectedLayerVisibleRegion));
1489 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
Vishnu Naira483b4a2019-12-12 15:07:52 -08001490 RegionEq(kExpectedLayerVisibleNonTransparentRegion));
Lloyd Piquede196652020-01-22 17:29:58 -08001491 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kExpectedLayerCoveredRegion));
1492 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion,
Vishnu Naira483b4a2019-12-12 15:07:52 -08001493 RegionEq(kExpectedoutputSpaceLayerVisibleRegion));
Lloyd Piquede196652020-01-22 17:29:58 -08001494 EXPECT_THAT(mLayer.outputLayerState.shadowRegion, RegionEq(kExpectedLayerShadowRegion));
Vishnu Naira483b4a2019-12-12 15:07:52 -08001495 EXPECT_FALSE(kExpectedLayerVisibleRegion.subtract(kExpectedLayerShadowRegion).isEmpty());
1496}
1497
1498TEST_F(OutputEnsureOutputLayerIfVisibleTest, shadowRegionOnlyTest) {
1499 ui::Transform translate;
1500 translate.set(50, 50);
Lloyd Piquede196652020-01-22 17:29:58 -08001501 mLayer.layerFEState.geomLayerTransform = translate;
1502 mLayer.layerFEState.shadowRadius = 10.0f;
Vishnu Naira483b4a2019-12-12 15:07:52 -08001503
1504 mCoverageState.dirtyRegion = Region(Rect(0, 0, 500, 500));
1505 // Casting layer is covered by an opaque region leaving only part of its shadow to be drawn
1506 mCoverageState.aboveCoveredLayers = Region(Rect(40, 40, 150, 260));
1507 mCoverageState.aboveOpaqueLayers = Region(Rect(40, 40, 150, 260));
1508
Lloyd Piquede196652020-01-22 17:29:58 -08001509 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE)))
1510 .WillOnce(Return(&mLayer.outputLayer));
Vishnu Naira483b4a2019-12-12 15:07:52 -08001511
Lloyd Piquede196652020-01-22 17:29:58 -08001512 ensureOutputLayerIfVisible();
Vishnu Naira483b4a2019-12-12 15:07:52 -08001513
1514 const Region kExpectedLayerVisibleRegion = Region(Rect(150, 40, 160, 260));
1515 const Region kExpectedLayerShadowRegion =
1516 Region(Rect(40, 40, 160, 260)).subtractSelf(Rect(50, 50, 150, 250));
1517
Lloyd Piquede196652020-01-22 17:29:58 -08001518 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kExpectedLayerVisibleRegion));
1519 EXPECT_THAT(mLayer.outputLayerState.shadowRegion, RegionEq(kExpectedLayerShadowRegion));
Vishnu Naira483b4a2019-12-12 15:07:52 -08001520 EXPECT_TRUE(kExpectedLayerVisibleRegion.subtract(kExpectedLayerShadowRegion).isEmpty());
1521}
1522
1523TEST_F(OutputEnsureOutputLayerIfVisibleTest, takesNotSoEarlyOutifLayerWithShadowIsCovered) {
1524 ui::Transform translate;
1525 translate.set(50, 50);
Lloyd Piquede196652020-01-22 17:29:58 -08001526 mLayer.layerFEState.geomLayerTransform = translate;
1527 mLayer.layerFEState.shadowRadius = 10.0f;
Vishnu Naira483b4a2019-12-12 15:07:52 -08001528
1529 mCoverageState.dirtyRegion = Region(Rect(0, 0, 500, 500));
1530 // Casting layer and its shadows are covered by an opaque region
1531 mCoverageState.aboveCoveredLayers = Region(Rect(40, 40, 160, 260));
1532 mCoverageState.aboveOpaqueLayers = Region(Rect(40, 40, 160, 260));
1533
Lloyd Piquede196652020-01-22 17:29:58 -08001534 ensureOutputLayerIfVisible();
Vishnu Naira483b4a2019-12-12 15:07:52 -08001535}
1536
Lloyd Piqueb62cebc2019-11-20 18:31:52 -08001537/*
Lloyd Piquefaa3f192019-11-14 14:05:09 -08001538 * Output::present()
1539 */
1540
1541struct OutputPresentTest : public testing::Test {
1542 struct OutputPartialMock : public OutputPartialMockBase {
Lloyd Pique739afaf2019-11-21 16:40:05 -08001543 // Sets up the helper functions called by the function under test to use
1544 // mock implementations.
Lloyd Piquefaa3f192019-11-14 14:05:09 -08001545 MOCK_METHOD1(updateColorProfile, void(const compositionengine::CompositionRefreshArgs&));
1546 MOCK_METHOD1(updateAndWriteCompositionState,
1547 void(const compositionengine::CompositionRefreshArgs&));
1548 MOCK_METHOD1(setColorTransform, void(const compositionengine::CompositionRefreshArgs&));
1549 MOCK_METHOD0(beginFrame, void());
1550 MOCK_METHOD0(prepareFrame, void());
1551 MOCK_METHOD1(devOptRepaintFlash, void(const compositionengine::CompositionRefreshArgs&));
1552 MOCK_METHOD1(finishFrame, void(const compositionengine::CompositionRefreshArgs&));
1553 MOCK_METHOD0(postFramebuffer, void());
1554 };
1555
1556 StrictMock<OutputPartialMock> mOutput;
1557};
1558
1559TEST_F(OutputPresentTest, justInvokesChildFunctionsInSequence) {
1560 CompositionRefreshArgs args;
1561
1562 InSequence seq;
1563 EXPECT_CALL(mOutput, updateColorProfile(Ref(args)));
1564 EXPECT_CALL(mOutput, updateAndWriteCompositionState(Ref(args)));
1565 EXPECT_CALL(mOutput, setColorTransform(Ref(args)));
1566 EXPECT_CALL(mOutput, beginFrame());
1567 EXPECT_CALL(mOutput, prepareFrame());
1568 EXPECT_CALL(mOutput, devOptRepaintFlash(Ref(args)));
1569 EXPECT_CALL(mOutput, finishFrame(Ref(args)));
1570 EXPECT_CALL(mOutput, postFramebuffer());
1571
1572 mOutput.present(args);
1573}
1574
1575/*
1576 * Output::updateColorProfile()
1577 */
1578
Lloyd Pique17ca7422019-11-14 14:24:10 -08001579struct OutputUpdateColorProfileTest : public testing::Test {
1580 using TestType = OutputUpdateColorProfileTest;
1581
1582 struct OutputPartialMock : public OutputPartialMockBase {
Lloyd Pique739afaf2019-11-21 16:40:05 -08001583 // Sets up the helper functions called by the function under test to use
1584 // mock implementations.
Lloyd Pique17ca7422019-11-14 14:24:10 -08001585 MOCK_METHOD1(setColorProfile, void(const ColorProfile&));
1586 };
1587
1588 struct Layer {
1589 Layer() {
Lloyd Pique17ca7422019-11-14 14:24:10 -08001590 EXPECT_CALL(mOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(mLayerFE));
Lloyd Piquede196652020-01-22 17:29:58 -08001591 EXPECT_CALL(mLayerFE, getCompositionState()).WillRepeatedly(Return(&mLayerFEState));
Lloyd Pique17ca7422019-11-14 14:24:10 -08001592 }
1593
1594 StrictMock<mock::OutputLayer> mOutputLayer;
Lloyd Pique17ca7422019-11-14 14:24:10 -08001595 StrictMock<mock::LayerFE> mLayerFE;
1596 LayerFECompositionState mLayerFEState;
1597 };
1598
1599 OutputUpdateColorProfileTest() {
1600 mOutput.setDisplayColorProfileForTest(
1601 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
1602 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
1603
1604 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0))
1605 .WillRepeatedly(Return(&mLayer1.mOutputLayer));
1606 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1))
1607 .WillRepeatedly(Return(&mLayer2.mOutputLayer));
1608 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(2))
1609 .WillRepeatedly(Return(&mLayer3.mOutputLayer));
1610 }
1611
1612 struct ExecuteState : public CallOrderStateMachineHelper<TestType, ExecuteState> {
1613 void execute() { getInstance()->mOutput.updateColorProfile(getInstance()->mRefreshArgs); }
1614 };
1615
1616 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
1617 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
1618 StrictMock<OutputPartialMock> mOutput;
1619
1620 Layer mLayer1;
1621 Layer mLayer2;
1622 Layer mLayer3;
1623
1624 CompositionRefreshArgs mRefreshArgs;
1625};
1626
1627// TODO(b/144522012): Refactor Output::updateColorProfile and the related code
1628// to make it easier to write unit tests.
1629
1630TEST_F(OutputUpdateColorProfileTest, setsAColorProfileWhenUnmanaged) {
1631 // When the outputColorSetting is set to kUnmanaged, the implementation sets
1632 // a simple default color profile without looking at anything else.
1633
Lloyd Pique0a456232020-01-16 17:51:13 -08001634 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(3u));
Lloyd Pique17ca7422019-11-14 14:24:10 -08001635 EXPECT_CALL(mOutput,
1636 setColorProfile(ColorProfileEq(
1637 ColorProfile{ui::ColorMode::NATIVE, ui::Dataspace::UNKNOWN,
1638 ui::RenderIntent::COLORIMETRIC, ui::Dataspace::UNKNOWN})));
1639
1640 mRefreshArgs.outputColorSetting = OutputColorSetting::kUnmanaged;
1641 mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN;
1642
1643 mOutput.updateColorProfile(mRefreshArgs);
1644}
1645
1646struct OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile
1647 : public OutputUpdateColorProfileTest {
1648 OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile() {
Lloyd Pique0a456232020-01-16 17:51:13 -08001649 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0u));
Lloyd Pique17ca7422019-11-14 14:24:10 -08001650 mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced;
1651 mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN;
1652 }
1653
1654 struct ExpectBestColorModeCallResultUsedToSetColorProfileState
1655 : public CallOrderStateMachineHelper<
1656 TestType, ExpectBestColorModeCallResultUsedToSetColorProfileState> {
1657 [[nodiscard]] auto expectBestColorModeCallResultUsedToSetColorProfile(
1658 ui::ColorMode colorMode, ui::Dataspace dataspace, ui::RenderIntent renderIntent) {
1659 EXPECT_CALL(*getInstance()->mDisplayColorProfile,
1660 getBestColorMode(ui::Dataspace::V0_SRGB, ui::RenderIntent::ENHANCE, _, _,
1661 _))
1662 .WillOnce(DoAll(SetArgPointee<2>(dataspace), SetArgPointee<3>(colorMode),
1663 SetArgPointee<4>(renderIntent)));
1664 EXPECT_CALL(getInstance()->mOutput,
1665 setColorProfile(
1666 ColorProfileEq(ColorProfile{colorMode, dataspace, renderIntent,
1667 ui::Dataspace::UNKNOWN})));
1668 return nextState<ExecuteState>();
1669 }
1670 };
1671
1672 // Call this member function to start using the mini-DSL defined above.
1673 [[nodiscard]] auto verify() {
1674 return ExpectBestColorModeCallResultUsedToSetColorProfileState::make(this);
1675 }
1676};
1677
1678TEST_F(OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile,
1679 Native_Unknown_Colorimetric_Set) {
1680 verify().expectBestColorModeCallResultUsedToSetColorProfile(ui::ColorMode::NATIVE,
1681 ui::Dataspace::UNKNOWN,
1682 ui::RenderIntent::COLORIMETRIC)
1683 .execute();
1684}
1685
1686TEST_F(OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile,
1687 DisplayP3_DisplayP3_Enhance_Set) {
1688 verify().expectBestColorModeCallResultUsedToSetColorProfile(ui::ColorMode::DISPLAY_P3,
1689 ui::Dataspace::DISPLAY_P3,
1690 ui::RenderIntent::ENHANCE)
1691 .execute();
1692}
1693
1694struct OutputUpdateColorProfileTest_ColorSpaceAgnosticeDataspaceAffectsSetColorProfile
1695 : public OutputUpdateColorProfileTest {
1696 OutputUpdateColorProfileTest_ColorSpaceAgnosticeDataspaceAffectsSetColorProfile() {
Lloyd Pique0a456232020-01-16 17:51:13 -08001697 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0u));
Lloyd Pique17ca7422019-11-14 14:24:10 -08001698 EXPECT_CALL(*mDisplayColorProfile,
1699 getBestColorMode(ui::Dataspace::V0_SRGB, ui::RenderIntent::ENHANCE, _, _, _))
1700 .WillRepeatedly(DoAll(SetArgPointee<2>(ui::Dataspace::UNKNOWN),
1701 SetArgPointee<3>(ui::ColorMode::NATIVE),
1702 SetArgPointee<4>(ui::RenderIntent::COLORIMETRIC)));
1703 mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced;
1704 }
1705
1706 struct IfColorSpaceAgnosticDataspaceSetToState
1707 : public CallOrderStateMachineHelper<TestType, IfColorSpaceAgnosticDataspaceSetToState> {
1708 [[nodiscard]] auto ifColorSpaceAgnosticDataspaceSetTo(ui::Dataspace dataspace) {
1709 getInstance()->mRefreshArgs.colorSpaceAgnosticDataspace = dataspace;
1710 return nextState<ThenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspaceState>();
1711 }
1712 };
1713
1714 struct ThenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspaceState
1715 : public CallOrderStateMachineHelper<
1716 TestType, ThenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspaceState> {
1717 [[nodiscard]] auto thenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspace(
1718 ui::Dataspace dataspace) {
1719 EXPECT_CALL(getInstance()->mOutput,
1720 setColorProfile(ColorProfileEq(
1721 ColorProfile{ui::ColorMode::NATIVE, ui::Dataspace::UNKNOWN,
1722 ui::RenderIntent::COLORIMETRIC, dataspace})));
1723 return nextState<ExecuteState>();
1724 }
1725 };
1726
1727 // Call this member function to start using the mini-DSL defined above.
1728 [[nodiscard]] auto verify() { return IfColorSpaceAgnosticDataspaceSetToState::make(this); }
1729};
1730
1731TEST_F(OutputUpdateColorProfileTest_ColorSpaceAgnosticeDataspaceAffectsSetColorProfile, DisplayP3) {
1732 verify().ifColorSpaceAgnosticDataspaceSetTo(ui::Dataspace::DISPLAY_P3)
1733 .thenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspace(ui::Dataspace::DISPLAY_P3)
1734 .execute();
1735}
1736
1737TEST_F(OutputUpdateColorProfileTest_ColorSpaceAgnosticeDataspaceAffectsSetColorProfile, V0_SRGB) {
1738 verify().ifColorSpaceAgnosticDataspaceSetTo(ui::Dataspace::V0_SRGB)
1739 .thenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspace(ui::Dataspace::V0_SRGB)
1740 .execute();
1741}
1742
1743struct OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference
1744 : public OutputUpdateColorProfileTest {
1745 // Internally the implementation looks through the dataspaces of all the
1746 // visible layers. The topmost one that also has an actual dataspace
1747 // preference set is used to drive subsequent choices.
1748
1749 OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference() {
1750 mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced;
1751 mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN;
1752
Lloyd Pique0a456232020-01-16 17:51:13 -08001753 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(3u));
Lloyd Pique17ca7422019-11-14 14:24:10 -08001754 EXPECT_CALL(mOutput, setColorProfile(_)).WillRepeatedly(Return());
1755 }
1756
1757 struct IfTopLayerDataspaceState
1758 : public CallOrderStateMachineHelper<TestType, IfTopLayerDataspaceState> {
1759 [[nodiscard]] auto ifTopLayerIs(ui::Dataspace dataspace) {
1760 getInstance()->mLayer3.mLayerFEState.dataspace = dataspace;
1761 return nextState<AndIfMiddleLayerDataspaceState>();
1762 }
1763 [[nodiscard]] auto ifTopLayerHasNoPreference() {
1764 return ifTopLayerIs(ui::Dataspace::UNKNOWN);
1765 }
1766 };
1767
1768 struct AndIfMiddleLayerDataspaceState
1769 : public CallOrderStateMachineHelper<TestType, AndIfMiddleLayerDataspaceState> {
1770 [[nodiscard]] auto andIfMiddleLayerIs(ui::Dataspace dataspace) {
1771 getInstance()->mLayer2.mLayerFEState.dataspace = dataspace;
1772 return nextState<AndIfBottomLayerDataspaceState>();
1773 }
1774 [[nodiscard]] auto andIfMiddleLayerHasNoPreference() {
1775 return andIfMiddleLayerIs(ui::Dataspace::UNKNOWN);
1776 }
1777 };
1778
1779 struct AndIfBottomLayerDataspaceState
1780 : public CallOrderStateMachineHelper<TestType, AndIfBottomLayerDataspaceState> {
1781 [[nodiscard]] auto andIfBottomLayerIs(ui::Dataspace dataspace) {
1782 getInstance()->mLayer1.mLayerFEState.dataspace = dataspace;
1783 return nextState<ThenExpectBestColorModeCallUsesState>();
1784 }
1785 [[nodiscard]] auto andIfBottomLayerHasNoPreference() {
1786 return andIfBottomLayerIs(ui::Dataspace::UNKNOWN);
1787 }
1788 };
1789
1790 struct ThenExpectBestColorModeCallUsesState
1791 : public CallOrderStateMachineHelper<TestType, ThenExpectBestColorModeCallUsesState> {
1792 [[nodiscard]] auto thenExpectBestColorModeCallUses(ui::Dataspace dataspace) {
1793 EXPECT_CALL(*getInstance()->mDisplayColorProfile,
1794 getBestColorMode(dataspace, _, _, _, _));
1795 return nextState<ExecuteState>();
1796 }
1797 };
1798
1799 // Call this member function to start using the mini-DSL defined above.
1800 [[nodiscard]] auto verify() { return IfTopLayerDataspaceState::make(this); }
1801};
1802
1803TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference,
1804 noStrongLayerPrefenceUses_V0_SRGB) {
1805 // If none of the layers indicate a preference, then V0_SRGB is the
1806 // preferred choice (subject to additional checks).
1807 verify().ifTopLayerHasNoPreference()
1808 .andIfMiddleLayerHasNoPreference()
1809 .andIfBottomLayerHasNoPreference()
1810 .thenExpectBestColorModeCallUses(ui::Dataspace::V0_SRGB)
1811 .execute();
1812}
1813
1814TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference,
1815 ifTopmostUses_DisplayP3_Then_DisplayP3_Chosen) {
1816 // If only the topmost layer has a preference, then that is what is chosen.
1817 verify().ifTopLayerIs(ui::Dataspace::DISPLAY_P3)
1818 .andIfMiddleLayerHasNoPreference()
1819 .andIfBottomLayerHasNoPreference()
1820 .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3)
1821 .execute();
1822}
1823
1824TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference,
1825 ifMiddleUses_DisplayP3_Then_DisplayP3_Chosen) {
1826 // If only the middle layer has a preference, that that is what is chosen.
1827 verify().ifTopLayerHasNoPreference()
1828 .andIfMiddleLayerIs(ui::Dataspace::DISPLAY_P3)
1829 .andIfBottomLayerHasNoPreference()
1830 .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3)
1831 .execute();
1832}
1833
1834TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference,
1835 ifBottomUses_DisplayP3_Then_DisplayP3_Chosen) {
1836 // If only the middle layer has a preference, that that is what is chosen.
1837 verify().ifTopLayerHasNoPreference()
1838 .andIfMiddleLayerHasNoPreference()
1839 .andIfBottomLayerIs(ui::Dataspace::DISPLAY_P3)
1840 .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3)
1841 .execute();
1842}
1843
1844TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference,
1845 ifTopUses_DisplayBT2020_AndBottomUses_DisplayP3_Then_DisplayBT2020_Chosen) {
1846 // If multiple layers have a preference, the topmost value is what is used.
1847 verify().ifTopLayerIs(ui::Dataspace::DISPLAY_BT2020)
1848 .andIfMiddleLayerHasNoPreference()
1849 .andIfBottomLayerIs(ui::Dataspace::DISPLAY_P3)
1850 .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_BT2020)
1851 .execute();
1852}
1853
1854TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference,
1855 ifTopUses_DisplayP3_AndBottomUses_V0_SRGB_Then_DisplayP3_Chosen) {
1856 // If multiple layers have a preference, the topmost value is what is used.
1857 verify().ifTopLayerIs(ui::Dataspace::DISPLAY_P3)
1858 .andIfMiddleLayerHasNoPreference()
1859 .andIfBottomLayerIs(ui::Dataspace::DISPLAY_BT2020)
1860 .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3)
1861 .execute();
1862}
1863
1864struct OutputUpdateColorProfileTest_ForceOutputColorOverrides
1865 : public OutputUpdateColorProfileTest {
1866 // If CompositionRefreshArgs::forceOutputColorMode is set to some specific
1867 // values, it overrides the layer dataspace choice.
1868
1869 OutputUpdateColorProfileTest_ForceOutputColorOverrides() {
1870 mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced;
1871 mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN;
1872
1873 mLayer1.mLayerFEState.dataspace = ui::Dataspace::DISPLAY_BT2020;
1874
Lloyd Pique0a456232020-01-16 17:51:13 -08001875 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(1u));
Lloyd Pique17ca7422019-11-14 14:24:10 -08001876 EXPECT_CALL(mOutput, setColorProfile(_)).WillRepeatedly(Return());
1877 }
1878
1879 struct IfForceOutputColorModeState
1880 : public CallOrderStateMachineHelper<TestType, IfForceOutputColorModeState> {
1881 [[nodiscard]] auto ifForceOutputColorMode(ui::ColorMode colorMode) {
1882 getInstance()->mRefreshArgs.forceOutputColorMode = colorMode;
1883 return nextState<ThenExpectBestColorModeCallUsesState>();
1884 }
1885 [[nodiscard]] auto ifNoOverride() { return ifForceOutputColorMode(ui::ColorMode::NATIVE); }
1886 };
1887
1888 struct ThenExpectBestColorModeCallUsesState
1889 : public CallOrderStateMachineHelper<TestType, ThenExpectBestColorModeCallUsesState> {
1890 [[nodiscard]] auto thenExpectBestColorModeCallUses(ui::Dataspace dataspace) {
1891 EXPECT_CALL(*getInstance()->mDisplayColorProfile,
1892 getBestColorMode(dataspace, _, _, _, _));
1893 return nextState<ExecuteState>();
1894 }
1895 };
1896
1897 // Call this member function to start using the mini-DSL defined above.
1898 [[nodiscard]] auto verify() { return IfForceOutputColorModeState::make(this); }
1899};
1900
1901TEST_F(OutputUpdateColorProfileTest_ForceOutputColorOverrides, NoOverride_DoesNotOverride) {
1902 // By default the layer state is used to set the preferred dataspace
1903 verify().ifNoOverride()
1904 .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_BT2020)
1905 .execute();
1906}
1907
1908TEST_F(OutputUpdateColorProfileTest_ForceOutputColorOverrides, SRGB_Override_USES_V0_SRGB) {
1909 // Setting ui::ColorMode::SRGB overrides it with ui::Dataspace::V0_SRGB
1910 verify().ifForceOutputColorMode(ui::ColorMode::SRGB)
1911 .thenExpectBestColorModeCallUses(ui::Dataspace::V0_SRGB)
1912 .execute();
1913}
1914
1915TEST_F(OutputUpdateColorProfileTest_ForceOutputColorOverrides, DisplayP3_Override_Uses_DisplayP3) {
1916 // Setting ui::ColorMode::DISPLAY_P3 overrides it with ui::Dataspace::DISPLAY_P3
1917 verify().ifForceOutputColorMode(ui::ColorMode::DISPLAY_P3)
1918 .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3)
1919 .execute();
1920}
1921
1922// HDR output requires all layers to be compatible with the chosen HDR
1923// dataspace, along with there being proper support.
1924struct OutputUpdateColorProfileTest_Hdr : public OutputUpdateColorProfileTest {
1925 OutputUpdateColorProfileTest_Hdr() {
1926 mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced;
1927 mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN;
Lloyd Pique0a456232020-01-16 17:51:13 -08001928 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2u));
Lloyd Pique17ca7422019-11-14 14:24:10 -08001929 EXPECT_CALL(mOutput, setColorProfile(_)).WillRepeatedly(Return());
1930 }
1931
1932 static constexpr ui::Dataspace kNonHdrDataspace = ui::Dataspace::DISPLAY_P3;
1933 static constexpr ui::Dataspace BT2020_PQ = ui::Dataspace::BT2020_PQ;
1934 static constexpr ui::Dataspace BT2020_HLG = ui::Dataspace::BT2020_HLG;
1935 static constexpr ui::Dataspace DISPLAY_P3 = ui::Dataspace::DISPLAY_P3;
1936
1937 struct IfTopLayerDataspaceState
1938 : public CallOrderStateMachineHelper<TestType, IfTopLayerDataspaceState> {
1939 [[nodiscard]] auto ifTopLayerIs(ui::Dataspace dataspace) {
1940 getInstance()->mLayer2.mLayerFEState.dataspace = dataspace;
1941 return nextState<AndTopLayerCompositionTypeState>();
1942 }
1943 [[nodiscard]] auto ifTopLayerIsNotHdr() { return ifTopLayerIs(kNonHdrDataspace); }
1944 };
1945
1946 struct AndTopLayerCompositionTypeState
1947 : public CallOrderStateMachineHelper<TestType, AndTopLayerCompositionTypeState> {
1948 [[nodiscard]] auto andTopLayerIsREComposed(bool renderEngineComposed) {
1949 getInstance()->mLayer2.mLayerFEState.forceClientComposition = renderEngineComposed;
1950 return nextState<AndIfBottomLayerDataspaceState>();
1951 }
1952 };
1953
1954 struct AndIfBottomLayerDataspaceState
1955 : public CallOrderStateMachineHelper<TestType, AndIfBottomLayerDataspaceState> {
1956 [[nodiscard]] auto andIfBottomLayerIs(ui::Dataspace dataspace) {
1957 getInstance()->mLayer1.mLayerFEState.dataspace = dataspace;
1958 return nextState<AndBottomLayerCompositionTypeState>();
1959 }
1960 [[nodiscard]] auto andIfBottomLayerIsNotHdr() {
1961 return andIfBottomLayerIs(kNonHdrDataspace);
1962 }
1963 };
1964
1965 struct AndBottomLayerCompositionTypeState
1966 : public CallOrderStateMachineHelper<TestType, AndBottomLayerCompositionTypeState> {
1967 [[nodiscard]] auto andBottomLayerIsREComposed(bool renderEngineComposed) {
1968 getInstance()->mLayer1.mLayerFEState.forceClientComposition = renderEngineComposed;
1969 return nextState<AndIfHasLegacySupportState>();
1970 }
1971 };
1972
1973 struct AndIfHasLegacySupportState
1974 : public CallOrderStateMachineHelper<TestType, AndIfHasLegacySupportState> {
1975 [[nodiscard]] auto andIfLegacySupportFor(ui::Dataspace dataspace, bool legacySupport) {
1976 EXPECT_CALL(*getInstance()->mDisplayColorProfile, hasLegacyHdrSupport(dataspace))
1977 .WillOnce(Return(legacySupport));
1978 return nextState<ThenExpectBestColorModeCallUsesState>();
1979 }
1980 };
1981
1982 struct ThenExpectBestColorModeCallUsesState
1983 : public CallOrderStateMachineHelper<TestType, ThenExpectBestColorModeCallUsesState> {
1984 [[nodiscard]] auto thenExpectBestColorModeCallUses(ui::Dataspace dataspace) {
1985 EXPECT_CALL(*getInstance()->mDisplayColorProfile,
1986 getBestColorMode(dataspace, _, _, _, _));
1987 return nextState<ExecuteState>();
1988 }
1989 };
1990
1991 // Call this member function to start using the mini-DSL defined above.
1992 [[nodiscard]] auto verify() { return IfTopLayerDataspaceState::make(this); }
1993};
1994
1995TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_PQ_HW_Uses_PQ) {
1996 // If all layers use BT2020_PQ, and there are no other special conditions,
1997 // BT2020_PQ is used.
1998 verify().ifTopLayerIs(BT2020_PQ)
1999 .andTopLayerIsREComposed(false)
2000 .andIfBottomLayerIs(BT2020_PQ)
2001 .andBottomLayerIsREComposed(false)
2002 .andIfLegacySupportFor(BT2020_PQ, false)
2003 .thenExpectBestColorModeCallUses(BT2020_PQ)
2004 .execute();
2005}
2006
2007TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_PQ_HW_IfPQHasLegacySupport_Uses_DisplayP3) {
2008 // BT2020_PQ is not used if there is only legacy support for it.
2009 verify().ifTopLayerIs(BT2020_PQ)
2010 .andTopLayerIsREComposed(false)
2011 .andIfBottomLayerIs(BT2020_PQ)
2012 .andBottomLayerIsREComposed(false)
2013 .andIfLegacySupportFor(BT2020_PQ, true)
2014 .thenExpectBestColorModeCallUses(DISPLAY_P3)
2015 .execute();
2016}
2017
2018TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_PQ_RE_Uses_PQ) {
2019 // BT2020_PQ is still used if the bottom layer is RenderEngine composed.
2020 verify().ifTopLayerIs(BT2020_PQ)
2021 .andTopLayerIsREComposed(false)
2022 .andIfBottomLayerIs(BT2020_PQ)
2023 .andBottomLayerIsREComposed(true)
2024 .andIfLegacySupportFor(BT2020_PQ, false)
2025 .thenExpectBestColorModeCallUses(BT2020_PQ)
2026 .execute();
2027}
2028
2029TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_RE_On_PQ_HW_Uses_DisplayP3) {
2030 // BT2020_PQ is not used if the top layer is RenderEngine composed.
2031 verify().ifTopLayerIs(BT2020_PQ)
2032 .andTopLayerIsREComposed(true)
2033 .andIfBottomLayerIs(BT2020_PQ)
2034 .andBottomLayerIsREComposed(false)
2035 .andIfLegacySupportFor(BT2020_PQ, false)
2036 .thenExpectBestColorModeCallUses(DISPLAY_P3)
2037 .execute();
2038}
2039
2040TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_HLG_HW_Uses_PQ) {
2041 // If there is mixed HLG/PQ use, and the topmost layer is PQ, then PQ is used if there
2042 // are no other special conditions.
2043 verify().ifTopLayerIs(BT2020_PQ)
2044 .andTopLayerIsREComposed(false)
2045 .andIfBottomLayerIs(BT2020_HLG)
2046 .andBottomLayerIsREComposed(false)
2047 .andIfLegacySupportFor(BT2020_PQ, false)
2048 .thenExpectBestColorModeCallUses(BT2020_PQ)
2049 .execute();
2050}
2051
2052TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_HLG_HW_IfPQHasLegacySupport_Uses_DisplayP3) {
2053 // BT2020_PQ is not used if there is only legacy support for it.
2054 verify().ifTopLayerIs(BT2020_PQ)
2055 .andTopLayerIsREComposed(false)
2056 .andIfBottomLayerIs(BT2020_HLG)
2057 .andBottomLayerIsREComposed(false)
2058 .andIfLegacySupportFor(BT2020_PQ, true)
2059 .thenExpectBestColorModeCallUses(DISPLAY_P3)
2060 .execute();
2061}
2062
2063TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_HLG_RE_Uses_PQ) {
2064 // BT2020_PQ is used if the bottom HLG layer is RenderEngine composed.
2065 verify().ifTopLayerIs(BT2020_PQ)
2066 .andTopLayerIsREComposed(false)
2067 .andIfBottomLayerIs(BT2020_HLG)
2068 .andBottomLayerIsREComposed(true)
2069 .andIfLegacySupportFor(BT2020_PQ, false)
2070 .thenExpectBestColorModeCallUses(BT2020_PQ)
2071 .execute();
2072}
2073
2074TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_RE_On_HLG_HW_Uses_DisplayP3) {
2075 // BT2020_PQ is not used if the top PQ layer is RenderEngine composed.
2076 verify().ifTopLayerIs(BT2020_PQ)
2077 .andTopLayerIsREComposed(true)
2078 .andIfBottomLayerIs(BT2020_HLG)
2079 .andBottomLayerIsREComposed(false)
2080 .andIfLegacySupportFor(BT2020_PQ, false)
2081 .thenExpectBestColorModeCallUses(DISPLAY_P3)
2082 .execute();
2083}
2084
2085TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_PQ_HW_Uses_PQ) {
2086 // If there is mixed HLG/PQ use, and the topmost layer is HLG, then PQ is
2087 // used if there are no other special conditions.
2088 verify().ifTopLayerIs(BT2020_HLG)
2089 .andTopLayerIsREComposed(false)
2090 .andIfBottomLayerIs(BT2020_PQ)
2091 .andBottomLayerIsREComposed(false)
2092 .andIfLegacySupportFor(BT2020_PQ, false)
2093 .thenExpectBestColorModeCallUses(BT2020_PQ)
2094 .execute();
2095}
2096
2097TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_PQ_HW_IfPQHasLegacySupport_Uses_DisplayP3) {
2098 // BT2020_PQ is not used if there is only legacy support for it.
2099 verify().ifTopLayerIs(BT2020_HLG)
2100 .andTopLayerIsREComposed(false)
2101 .andIfBottomLayerIs(BT2020_PQ)
2102 .andBottomLayerIsREComposed(false)
2103 .andIfLegacySupportFor(BT2020_PQ, true)
2104 .thenExpectBestColorModeCallUses(DISPLAY_P3)
2105 .execute();
2106}
2107
2108TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_PQ_RE_Uses_DisplayP3) {
2109 // BT2020_PQ is not used if the bottom PQ layer is RenderEngine composed.
2110 verify().ifTopLayerIs(BT2020_HLG)
2111 .andTopLayerIsREComposed(false)
2112 .andIfBottomLayerIs(BT2020_PQ)
2113 .andBottomLayerIsREComposed(true)
2114 .andIfLegacySupportFor(BT2020_PQ, false)
2115 .thenExpectBestColorModeCallUses(DISPLAY_P3)
2116 .execute();
2117}
2118
2119TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_RE_On_PQ_HW_Uses_PQ) {
2120 // BT2020_PQ is still used if the top HLG layer is RenderEngine composed.
2121 verify().ifTopLayerIs(BT2020_HLG)
2122 .andTopLayerIsREComposed(true)
2123 .andIfBottomLayerIs(BT2020_PQ)
2124 .andBottomLayerIsREComposed(false)
2125 .andIfLegacySupportFor(BT2020_PQ, false)
2126 .thenExpectBestColorModeCallUses(BT2020_PQ)
2127 .execute();
2128}
2129
2130TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_HLG_HW_Uses_HLG) {
2131 // If all layers use HLG then HLG is used if there are no other special
2132 // conditions.
2133 verify().ifTopLayerIs(BT2020_HLG)
2134 .andTopLayerIsREComposed(false)
2135 .andIfBottomLayerIs(BT2020_HLG)
2136 .andBottomLayerIsREComposed(false)
2137 .andIfLegacySupportFor(BT2020_HLG, false)
2138 .thenExpectBestColorModeCallUses(BT2020_HLG)
2139 .execute();
2140}
2141
2142TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_HLG_HW_IfPQHasLegacySupport_Uses_DisplayP3) {
2143 // BT2020_HLG is not used if there is legacy support for it.
2144 verify().ifTopLayerIs(BT2020_HLG)
2145 .andTopLayerIsREComposed(false)
2146 .andIfBottomLayerIs(BT2020_HLG)
2147 .andBottomLayerIsREComposed(false)
2148 .andIfLegacySupportFor(BT2020_HLG, true)
2149 .thenExpectBestColorModeCallUses(DISPLAY_P3)
2150 .execute();
2151}
2152
2153TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_HLG_RE_Uses_HLG) {
2154 // BT2020_HLG is used even if the bottom layer is client composed.
2155 verify().ifTopLayerIs(BT2020_HLG)
2156 .andTopLayerIsREComposed(false)
2157 .andIfBottomLayerIs(BT2020_HLG)
2158 .andBottomLayerIsREComposed(true)
2159 .andIfLegacySupportFor(BT2020_HLG, false)
2160 .thenExpectBestColorModeCallUses(BT2020_HLG)
2161 .execute();
2162}
2163
2164TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_RE_On_HLG_HW_Uses_HLG) {
2165 // BT2020_HLG is used even if the top layer is client composed.
2166 verify().ifTopLayerIs(BT2020_HLG)
2167 .andTopLayerIsREComposed(true)
2168 .andIfBottomLayerIs(BT2020_HLG)
2169 .andBottomLayerIsREComposed(false)
2170 .andIfLegacySupportFor(BT2020_HLG, false)
2171 .thenExpectBestColorModeCallUses(BT2020_HLG)
2172 .execute();
2173}
2174
2175TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_NonHdr_HW_Uses_PQ) {
2176 // Even if there are non-HDR layers present, BT2020_PQ can still be used.
2177 verify().ifTopLayerIs(BT2020_PQ)
2178 .andTopLayerIsREComposed(false)
2179 .andIfBottomLayerIsNotHdr()
2180 .andBottomLayerIsREComposed(false)
2181 .andIfLegacySupportFor(BT2020_PQ, false)
2182 .thenExpectBestColorModeCallUses(BT2020_PQ)
2183 .execute();
2184}
2185
2186TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_NonHdr_RE_Uses_HLG) {
2187 // If all layers use HLG then HLG is used if there are no other special
2188 // conditions.
2189 verify().ifTopLayerIs(BT2020_HLG)
2190 .andTopLayerIsREComposed(false)
2191 .andIfBottomLayerIsNotHdr()
2192 .andBottomLayerIsREComposed(true)
2193 .andIfLegacySupportFor(BT2020_HLG, false)
2194 .thenExpectBestColorModeCallUses(BT2020_HLG)
2195 .execute();
2196}
2197
2198struct OutputUpdateColorProfile_AffectsChosenRenderIntentTest
2199 : public OutputUpdateColorProfileTest {
2200 // The various values for CompositionRefreshArgs::outputColorSetting affect
2201 // the chosen renderIntent, along with whether the preferred dataspace is an
2202 // HDR dataspace or not.
2203
2204 OutputUpdateColorProfile_AffectsChosenRenderIntentTest() {
2205 mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced;
2206 mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN;
2207 mLayer1.mLayerFEState.dataspace = ui::Dataspace::BT2020_PQ;
Lloyd Pique0a456232020-01-16 17:51:13 -08002208 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(1u));
Lloyd Pique17ca7422019-11-14 14:24:10 -08002209 EXPECT_CALL(mOutput, setColorProfile(_)).WillRepeatedly(Return());
2210 EXPECT_CALL(*mDisplayColorProfile, hasLegacyHdrSupport(ui::Dataspace::BT2020_PQ))
2211 .WillRepeatedly(Return(false));
2212 }
2213
2214 // The tests here involve enough state and GMock setup that using a mini-DSL
2215 // makes the tests much more readable, and allows the test to focus more on
2216 // the intent than on some of the details.
2217
2218 static constexpr ui::Dataspace kNonHdrDataspace = ui::Dataspace::DISPLAY_P3;
2219 static constexpr ui::Dataspace kHdrDataspace = ui::Dataspace::BT2020_PQ;
2220
2221 struct IfDataspaceChosenState
2222 : public CallOrderStateMachineHelper<TestType, IfDataspaceChosenState> {
2223 [[nodiscard]] auto ifDataspaceChosenIs(ui::Dataspace dataspace) {
2224 getInstance()->mLayer1.mLayerFEState.dataspace = dataspace;
2225 return nextState<AndOutputColorSettingState>();
2226 }
2227 [[nodiscard]] auto ifDataspaceChosenIsNonHdr() {
2228 return ifDataspaceChosenIs(kNonHdrDataspace);
2229 }
2230 [[nodiscard]] auto ifDataspaceChosenIsHdr() { return ifDataspaceChosenIs(kHdrDataspace); }
2231 };
2232
2233 struct AndOutputColorSettingState
2234 : public CallOrderStateMachineHelper<TestType, AndOutputColorSettingState> {
2235 [[nodiscard]] auto andOutputColorSettingIs(OutputColorSetting setting) {
2236 getInstance()->mRefreshArgs.outputColorSetting = setting;
2237 return nextState<ThenExpectBestColorModeCallUsesState>();
2238 }
2239 };
2240
2241 struct ThenExpectBestColorModeCallUsesState
2242 : public CallOrderStateMachineHelper<TestType, ThenExpectBestColorModeCallUsesState> {
2243 [[nodiscard]] auto thenExpectBestColorModeCallUses(ui::RenderIntent intent) {
2244 EXPECT_CALL(*getInstance()->mDisplayColorProfile,
2245 getBestColorMode(getInstance()->mLayer1.mLayerFEState.dataspace, intent, _,
2246 _, _));
2247 return nextState<ExecuteState>();
2248 }
2249 };
2250
2251 // Tests call one of these two helper member functions to start using the
2252 // mini-DSL defined above.
2253 [[nodiscard]] auto verify() { return IfDataspaceChosenState::make(this); }
2254};
2255
2256TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest,
2257 Managed_NonHdr_Prefers_Colorimetric) {
2258 verify().ifDataspaceChosenIsNonHdr()
2259 .andOutputColorSettingIs(OutputColorSetting::kManaged)
2260 .thenExpectBestColorModeCallUses(ui::RenderIntent::COLORIMETRIC)
2261 .execute();
2262}
2263
2264TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest,
2265 Managed_Hdr_Prefers_ToneMapColorimetric) {
2266 verify().ifDataspaceChosenIsHdr()
2267 .andOutputColorSettingIs(OutputColorSetting::kManaged)
2268 .thenExpectBestColorModeCallUses(ui::RenderIntent::TONE_MAP_COLORIMETRIC)
2269 .execute();
2270}
2271
2272TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest, Enhanced_NonHdr_Prefers_Enhance) {
2273 verify().ifDataspaceChosenIsNonHdr()
2274 .andOutputColorSettingIs(OutputColorSetting::kEnhanced)
2275 .thenExpectBestColorModeCallUses(ui::RenderIntent::ENHANCE)
2276 .execute();
2277}
2278
2279TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest,
2280 Enhanced_Hdr_Prefers_ToneMapEnhance) {
2281 verify().ifDataspaceChosenIsHdr()
2282 .andOutputColorSettingIs(OutputColorSetting::kEnhanced)
2283 .thenExpectBestColorModeCallUses(ui::RenderIntent::TONE_MAP_ENHANCE)
2284 .execute();
2285}
2286
2287TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest, Vendor_NonHdr_Prefers_Vendor) {
2288 verify().ifDataspaceChosenIsNonHdr()
2289 .andOutputColorSettingIs(kVendorSpecifiedOutputColorSetting)
2290 .thenExpectBestColorModeCallUses(
2291 static_cast<ui::RenderIntent>(kVendorSpecifiedOutputColorSetting))
2292 .execute();
2293}
2294
2295TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest, Vendor_Hdr_Prefers_Vendor) {
2296 verify().ifDataspaceChosenIsHdr()
2297 .andOutputColorSettingIs(kVendorSpecifiedOutputColorSetting)
2298 .thenExpectBestColorModeCallUses(
2299 static_cast<ui::RenderIntent>(kVendorSpecifiedOutputColorSetting))
2300 .execute();
2301}
Lloyd Piquefaa3f192019-11-14 14:05:09 -08002302
2303/*
2304 * Output::beginFrame()
2305 */
2306
Lloyd Piquee5965952019-11-18 16:16:32 -08002307struct OutputBeginFrameTest : public ::testing::Test {
2308 using TestType = OutputBeginFrameTest;
2309
2310 struct OutputPartialMock : public OutputPartialMockBase {
Lloyd Pique739afaf2019-11-21 16:40:05 -08002311 // Sets up the helper functions called by the function under test to use
2312 // mock implementations.
Lloyd Piquee5965952019-11-18 16:16:32 -08002313 MOCK_CONST_METHOD1(getDirtyRegion, Region(bool));
2314 };
2315
2316 OutputBeginFrameTest() {
2317 mOutput.setDisplayColorProfileForTest(
2318 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
2319 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
2320 }
2321
2322 struct IfGetDirtyRegionExpectationState
2323 : public CallOrderStateMachineHelper<TestType, IfGetDirtyRegionExpectationState> {
2324 [[nodiscard]] auto ifGetDirtyRegionReturns(Region dirtyRegion) {
2325 EXPECT_CALL(getInstance()->mOutput, getDirtyRegion(false))
2326 .WillOnce(Return(dirtyRegion));
2327 return nextState<AndIfGetOutputLayerCountExpectationState>();
2328 }
2329 };
2330
2331 struct AndIfGetOutputLayerCountExpectationState
2332 : public CallOrderStateMachineHelper<TestType, AndIfGetOutputLayerCountExpectationState> {
2333 [[nodiscard]] auto andIfGetOutputLayerCountReturns(size_t layerCount) {
2334 EXPECT_CALL(getInstance()->mOutput, getOutputLayerCount()).WillOnce(Return(layerCount));
2335 return nextState<AndIfLastCompositionHadVisibleLayersState>();
2336 }
2337 };
2338
2339 struct AndIfLastCompositionHadVisibleLayersState
2340 : public CallOrderStateMachineHelper<TestType,
2341 AndIfLastCompositionHadVisibleLayersState> {
2342 [[nodiscard]] auto andIfLastCompositionHadVisibleLayersIs(bool hadOutputLayers) {
2343 getInstance()->mOutput.mState.lastCompositionHadVisibleLayers = hadOutputLayers;
2344 return nextState<ThenExpectRenderSurfaceBeginFrameCallState>();
2345 }
2346 };
2347
2348 struct ThenExpectRenderSurfaceBeginFrameCallState
2349 : public CallOrderStateMachineHelper<TestType,
2350 ThenExpectRenderSurfaceBeginFrameCallState> {
2351 [[nodiscard]] auto thenExpectRenderSurfaceBeginFrameCall(bool mustRecompose) {
2352 EXPECT_CALL(*getInstance()->mRenderSurface, beginFrame(mustRecompose));
2353 return nextState<ExecuteState>();
2354 }
2355 };
2356
2357 struct ExecuteState : public CallOrderStateMachineHelper<TestType, ExecuteState> {
2358 [[nodiscard]] auto execute() {
2359 getInstance()->mOutput.beginFrame();
2360 return nextState<CheckPostconditionHadVisibleLayersState>();
2361 }
2362 };
2363
2364 struct CheckPostconditionHadVisibleLayersState
2365 : public CallOrderStateMachineHelper<TestType, CheckPostconditionHadVisibleLayersState> {
2366 void checkPostconditionHadVisibleLayers(bool expected) {
2367 EXPECT_EQ(expected, getInstance()->mOutput.mState.lastCompositionHadVisibleLayers);
2368 }
2369 };
2370
2371 // Tests call one of these two helper member functions to start using the
2372 // mini-DSL defined above.
2373 [[nodiscard]] auto verify() { return IfGetDirtyRegionExpectationState::make(this); }
2374
2375 static const Region kEmptyRegion;
2376 static const Region kNotEmptyRegion;
2377
2378 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
2379 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
2380 StrictMock<OutputPartialMock> mOutput;
2381};
2382
2383const Region OutputBeginFrameTest::kEmptyRegion{Rect{0, 0, 0, 0}};
2384const Region OutputBeginFrameTest::kNotEmptyRegion{Rect{0, 0, 1, 1}};
2385
2386TEST_F(OutputBeginFrameTest, hasDirtyHasLayersHadLayersLastFrame) {
2387 verify().ifGetDirtyRegionReturns(kNotEmptyRegion)
2388 .andIfGetOutputLayerCountReturns(1u)
2389 .andIfLastCompositionHadVisibleLayersIs(true)
2390 .thenExpectRenderSurfaceBeginFrameCall(true)
2391 .execute()
2392 .checkPostconditionHadVisibleLayers(true);
2393}
2394
2395TEST_F(OutputBeginFrameTest, hasDirtyNotHasLayersHadLayersLastFrame) {
2396 verify().ifGetDirtyRegionReturns(kNotEmptyRegion)
2397 .andIfGetOutputLayerCountReturns(0u)
2398 .andIfLastCompositionHadVisibleLayersIs(true)
2399 .thenExpectRenderSurfaceBeginFrameCall(true)
2400 .execute()
2401 .checkPostconditionHadVisibleLayers(false);
2402}
2403
2404TEST_F(OutputBeginFrameTest, hasDirtyHasLayersNotHadLayersLastFrame) {
2405 verify().ifGetDirtyRegionReturns(kNotEmptyRegion)
2406 .andIfGetOutputLayerCountReturns(1u)
2407 .andIfLastCompositionHadVisibleLayersIs(false)
2408 .thenExpectRenderSurfaceBeginFrameCall(true)
2409 .execute()
2410 .checkPostconditionHadVisibleLayers(true);
2411}
2412
2413TEST_F(OutputBeginFrameTest, hasDirtyNotHasLayersNotHadLayersLastFrame) {
2414 verify().ifGetDirtyRegionReturns(kNotEmptyRegion)
2415 .andIfGetOutputLayerCountReturns(0u)
2416 .andIfLastCompositionHadVisibleLayersIs(false)
2417 .thenExpectRenderSurfaceBeginFrameCall(false)
2418 .execute()
2419 .checkPostconditionHadVisibleLayers(false);
2420}
2421
2422TEST_F(OutputBeginFrameTest, notHasDirtyHasLayersHadLayersLastFrame) {
2423 verify().ifGetDirtyRegionReturns(kEmptyRegion)
2424 .andIfGetOutputLayerCountReturns(1u)
2425 .andIfLastCompositionHadVisibleLayersIs(true)
2426 .thenExpectRenderSurfaceBeginFrameCall(false)
2427 .execute()
2428 .checkPostconditionHadVisibleLayers(true);
2429}
2430
2431TEST_F(OutputBeginFrameTest, notHasDirtyNotHasLayersHadLayersLastFrame) {
2432 verify().ifGetDirtyRegionReturns(kEmptyRegion)
2433 .andIfGetOutputLayerCountReturns(0u)
2434 .andIfLastCompositionHadVisibleLayersIs(true)
2435 .thenExpectRenderSurfaceBeginFrameCall(false)
2436 .execute()
2437 .checkPostconditionHadVisibleLayers(true);
2438}
2439
2440TEST_F(OutputBeginFrameTest, notHasDirtyHasLayersNotHadLayersLastFrame) {
2441 verify().ifGetDirtyRegionReturns(kEmptyRegion)
2442 .andIfGetOutputLayerCountReturns(1u)
2443 .andIfLastCompositionHadVisibleLayersIs(false)
2444 .thenExpectRenderSurfaceBeginFrameCall(false)
2445 .execute()
2446 .checkPostconditionHadVisibleLayers(false);
2447}
2448
2449TEST_F(OutputBeginFrameTest, notHasDirtyNotHasLayersNotHadLayersLastFrame) {
2450 verify().ifGetDirtyRegionReturns(kEmptyRegion)
2451 .andIfGetOutputLayerCountReturns(0u)
2452 .andIfLastCompositionHadVisibleLayersIs(false)
2453 .thenExpectRenderSurfaceBeginFrameCall(false)
2454 .execute()
2455 .checkPostconditionHadVisibleLayers(false);
2456}
2457
Lloyd Piquefaa3f192019-11-14 14:05:09 -08002458/*
2459 * Output::devOptRepaintFlash()
2460 */
2461
Lloyd Piquedb462d82019-11-19 17:58:46 -08002462struct OutputDevOptRepaintFlashTest : public testing::Test {
2463 struct OutputPartialMock : public OutputPartialMockBase {
Lloyd Pique739afaf2019-11-21 16:40:05 -08002464 // Sets up the helper functions called by the function under test to use
2465 // mock implementations.
Lloyd Piquedb462d82019-11-19 17:58:46 -08002466 MOCK_CONST_METHOD1(getDirtyRegion, Region(bool));
Lucas Dupin2dd6f392020-02-18 17:43:36 -08002467 MOCK_METHOD2(composeSurfaces,
2468 std::optional<base::unique_fd>(
2469 const Region&, const compositionengine::CompositionRefreshArgs&));
Lloyd Piquedb462d82019-11-19 17:58:46 -08002470 MOCK_METHOD0(postFramebuffer, void());
2471 MOCK_METHOD0(prepareFrame, void());
2472 };
2473
2474 OutputDevOptRepaintFlashTest() {
2475 mOutput.setDisplayColorProfileForTest(
2476 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
2477 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
2478 }
2479
2480 static const Region kEmptyRegion;
2481 static const Region kNotEmptyRegion;
2482
2483 StrictMock<OutputPartialMock> mOutput;
2484 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
2485 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
2486 CompositionRefreshArgs mRefreshArgs;
2487};
2488
2489const Region OutputDevOptRepaintFlashTest::kEmptyRegion{Rect{0, 0, 0, 0}};
2490const Region OutputDevOptRepaintFlashTest::kNotEmptyRegion{Rect{0, 0, 1, 1}};
2491
2492TEST_F(OutputDevOptRepaintFlashTest, doesNothingIfFlashDelayNotSet) {
2493 mRefreshArgs.devOptFlashDirtyRegionsDelay = {};
2494 mRefreshArgs.repaintEverything = true;
2495 mOutput.mState.isEnabled = true;
2496
2497 mOutput.devOptRepaintFlash(mRefreshArgs);
2498}
2499
2500TEST_F(OutputDevOptRepaintFlashTest, postsAndPreparesANewFrameIfNotEnabled) {
2501 mRefreshArgs.devOptFlashDirtyRegionsDelay = std::chrono::microseconds(1);
2502 mRefreshArgs.repaintEverything = true;
2503 mOutput.mState.isEnabled = false;
2504
2505 InSequence seq;
2506 EXPECT_CALL(mOutput, postFramebuffer());
2507 EXPECT_CALL(mOutput, prepareFrame());
2508
2509 mOutput.devOptRepaintFlash(mRefreshArgs);
2510}
2511
2512TEST_F(OutputDevOptRepaintFlashTest, postsAndPreparesANewFrameIfNotDirty) {
2513 mRefreshArgs.devOptFlashDirtyRegionsDelay = std::chrono::microseconds(1);
2514 mRefreshArgs.repaintEverything = true;
2515 mOutput.mState.isEnabled = true;
2516
2517 InSequence seq;
2518 EXPECT_CALL(mOutput, getDirtyRegion(true)).WillOnce(Return(kEmptyRegion));
2519 EXPECT_CALL(mOutput, postFramebuffer());
2520 EXPECT_CALL(mOutput, prepareFrame());
2521
2522 mOutput.devOptRepaintFlash(mRefreshArgs);
2523}
2524
2525TEST_F(OutputDevOptRepaintFlashTest, alsoComposesSurfacesAndQueuesABufferIfDirty) {
2526 mRefreshArgs.devOptFlashDirtyRegionsDelay = std::chrono::microseconds(1);
2527 mRefreshArgs.repaintEverything = false;
2528 mOutput.mState.isEnabled = true;
2529
2530 InSequence seq;
2531 EXPECT_CALL(mOutput, getDirtyRegion(false)).WillOnce(Return(kNotEmptyRegion));
Lucas Dupin2dd6f392020-02-18 17:43:36 -08002532 EXPECT_CALL(mOutput, composeSurfaces(RegionEq(kNotEmptyRegion), Ref(mRefreshArgs)));
Lloyd Piquedb462d82019-11-19 17:58:46 -08002533 EXPECT_CALL(*mRenderSurface, queueBuffer(_));
2534 EXPECT_CALL(mOutput, postFramebuffer());
2535 EXPECT_CALL(mOutput, prepareFrame());
2536
2537 mOutput.devOptRepaintFlash(mRefreshArgs);
2538}
2539
Lloyd Piquefaa3f192019-11-14 14:05:09 -08002540/*
2541 * Output::finishFrame()
2542 */
2543
Lloyd Pique03561a62019-11-19 18:34:52 -08002544struct OutputFinishFrameTest : public testing::Test {
2545 struct OutputPartialMock : public OutputPartialMockBase {
Lloyd Pique739afaf2019-11-21 16:40:05 -08002546 // Sets up the helper functions called by the function under test to use
2547 // mock implementations.
Lucas Dupin2dd6f392020-02-18 17:43:36 -08002548 MOCK_METHOD2(composeSurfaces,
2549 std::optional<base::unique_fd>(
2550 const Region&, const compositionengine::CompositionRefreshArgs&));
Lloyd Pique03561a62019-11-19 18:34:52 -08002551 MOCK_METHOD0(postFramebuffer, void());
2552 };
2553
2554 OutputFinishFrameTest() {
2555 mOutput.setDisplayColorProfileForTest(
2556 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
2557 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
2558 }
2559
2560 StrictMock<OutputPartialMock> mOutput;
2561 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
2562 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
2563 CompositionRefreshArgs mRefreshArgs;
2564};
2565
2566TEST_F(OutputFinishFrameTest, ifNotEnabledDoesNothing) {
2567 mOutput.mState.isEnabled = false;
2568
2569 mOutput.finishFrame(mRefreshArgs);
2570}
2571
2572TEST_F(OutputFinishFrameTest, takesEarlyOutifComposeSurfacesReturnsNoFence) {
2573 mOutput.mState.isEnabled = true;
2574
2575 InSequence seq;
Lucas Dupin2dd6f392020-02-18 17:43:36 -08002576 EXPECT_CALL(mOutput, composeSurfaces(RegionEq(Region::INVALID_REGION), _));
Lloyd Pique03561a62019-11-19 18:34:52 -08002577
2578 mOutput.finishFrame(mRefreshArgs);
2579}
2580
2581TEST_F(OutputFinishFrameTest, queuesBufferIfComposeSurfacesReturnsAFence) {
2582 mOutput.mState.isEnabled = true;
2583
2584 InSequence seq;
Lucas Dupin2dd6f392020-02-18 17:43:36 -08002585 EXPECT_CALL(mOutput, composeSurfaces(RegionEq(Region::INVALID_REGION), _))
Lloyd Pique03561a62019-11-19 18:34:52 -08002586 .WillOnce(Return(ByMove(base::unique_fd())));
2587 EXPECT_CALL(*mRenderSurface, queueBuffer(_));
2588
2589 mOutput.finishFrame(mRefreshArgs);
2590}
Lloyd Piquefaa3f192019-11-14 14:05:09 -08002591
2592/*
2593 * Output::postFramebuffer()
2594 */
2595
Lloyd Pique07178e32019-11-19 19:15:26 -08002596struct OutputPostFramebufferTest : public testing::Test {
2597 struct OutputPartialMock : public OutputPartialMockBase {
Lloyd Pique739afaf2019-11-21 16:40:05 -08002598 // Sets up the helper functions called by the function under test to use
2599 // mock implementations.
Lloyd Pique07178e32019-11-19 19:15:26 -08002600 MOCK_METHOD0(presentAndGetFrameFences, compositionengine::Output::FrameFences());
2601 };
2602
2603 struct Layer {
2604 Layer() {
2605 EXPECT_CALL(outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(layerFE));
2606 EXPECT_CALL(outputLayer, getHwcLayer()).WillRepeatedly(Return(&hwc2Layer));
2607 }
2608
2609 StrictMock<mock::OutputLayer> outputLayer;
2610 StrictMock<mock::LayerFE> layerFE;
2611 StrictMock<HWC2::mock::Layer> hwc2Layer;
2612 };
2613
2614 OutputPostFramebufferTest() {
2615 mOutput.setDisplayColorProfileForTest(
2616 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
2617 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
2618
2619 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(3u));
2620 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u))
2621 .WillRepeatedly(Return(&mLayer1.outputLayer));
2622 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1u))
2623 .WillRepeatedly(Return(&mLayer2.outputLayer));
2624 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(2u))
2625 .WillRepeatedly(Return(&mLayer3.outputLayer));
2626 }
2627
2628 StrictMock<OutputPartialMock> mOutput;
2629 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
2630 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
2631
2632 Layer mLayer1;
2633 Layer mLayer2;
2634 Layer mLayer3;
2635};
2636
2637TEST_F(OutputPostFramebufferTest, ifNotEnabledDoesNothing) {
2638 mOutput.mState.isEnabled = false;
2639
2640 mOutput.postFramebuffer();
2641}
2642
2643TEST_F(OutputPostFramebufferTest, ifEnabledMustFlipThenPresentThenSendPresentCompleted) {
2644 mOutput.mState.isEnabled = true;
2645
2646 compositionengine::Output::FrameFences frameFences;
2647
2648 // This should happen even if there are no output layers.
2649 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
2650
2651 // For this test in particular we want to make sure the call expectations
2652 // setup below are satisfied in the specific order.
2653 InSequence seq;
2654
2655 EXPECT_CALL(*mRenderSurface, flip());
2656 EXPECT_CALL(mOutput, presentAndGetFrameFences()).WillOnce(Return(frameFences));
2657 EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted());
2658
2659 mOutput.postFramebuffer();
2660}
2661
2662TEST_F(OutputPostFramebufferTest, releaseFencesAreSentToLayerFE) {
2663 // Simulate getting release fences from each layer, and ensure they are passed to the
2664 // front-end layer interface for each layer correctly.
2665
2666 mOutput.mState.isEnabled = true;
2667
2668 // Create three unique fence instances
2669 sp<Fence> layer1Fence = new Fence();
2670 sp<Fence> layer2Fence = new Fence();
2671 sp<Fence> layer3Fence = new Fence();
2672
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08002673 Output::FrameFences frameFences;
Lloyd Pique07178e32019-11-19 19:15:26 -08002674 frameFences.layerFences.emplace(&mLayer1.hwc2Layer, layer1Fence);
2675 frameFences.layerFences.emplace(&mLayer2.hwc2Layer, layer2Fence);
2676 frameFences.layerFences.emplace(&mLayer3.hwc2Layer, layer3Fence);
2677
2678 EXPECT_CALL(*mRenderSurface, flip());
2679 EXPECT_CALL(mOutput, presentAndGetFrameFences()).WillOnce(Return(frameFences));
2680 EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted());
2681
2682 // Compare the pointers values of each fence to make sure the correct ones
2683 // are passed. This happens to work with the current implementation, but
2684 // would not survive certain calls like Fence::merge() which would return a
2685 // new instance.
2686 EXPECT_CALL(mLayer1.layerFE,
2687 onLayerDisplayed(Property(&sp<Fence>::get, Eq(layer1Fence.get()))));
2688 EXPECT_CALL(mLayer2.layerFE,
2689 onLayerDisplayed(Property(&sp<Fence>::get, Eq(layer2Fence.get()))));
2690 EXPECT_CALL(mLayer3.layerFE,
2691 onLayerDisplayed(Property(&sp<Fence>::get, Eq(layer3Fence.get()))));
2692
2693 mOutput.postFramebuffer();
2694}
2695
2696TEST_F(OutputPostFramebufferTest, releaseFencesIncludeClientTargetAcquireFence) {
2697 mOutput.mState.isEnabled = true;
2698 mOutput.mState.usesClientComposition = true;
2699
2700 sp<Fence> clientTargetAcquireFence = new Fence();
2701 sp<Fence> layer1Fence = new Fence();
2702 sp<Fence> layer2Fence = new Fence();
2703 sp<Fence> layer3Fence = new Fence();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08002704 Output::FrameFences frameFences;
Lloyd Pique07178e32019-11-19 19:15:26 -08002705 frameFences.clientTargetAcquireFence = clientTargetAcquireFence;
2706 frameFences.layerFences.emplace(&mLayer1.hwc2Layer, layer1Fence);
2707 frameFences.layerFences.emplace(&mLayer2.hwc2Layer, layer2Fence);
2708 frameFences.layerFences.emplace(&mLayer3.hwc2Layer, layer3Fence);
2709
2710 EXPECT_CALL(*mRenderSurface, flip());
2711 EXPECT_CALL(mOutput, presentAndGetFrameFences()).WillOnce(Return(frameFences));
2712 EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted());
2713
2714 // Fence::merge is called, and since none of the fences are actually valid,
2715 // Fence::NO_FENCE is returned and passed to each onLayerDisplayed() call.
2716 // This is the best we can do without creating a real kernel fence object.
2717 EXPECT_CALL(mLayer1.layerFE, onLayerDisplayed(Fence::NO_FENCE));
2718 EXPECT_CALL(mLayer2.layerFE, onLayerDisplayed(Fence::NO_FENCE));
2719 EXPECT_CALL(mLayer3.layerFE, onLayerDisplayed(Fence::NO_FENCE));
2720
2721 mOutput.postFramebuffer();
2722}
2723
2724TEST_F(OutputPostFramebufferTest, releasedLayersSentPresentFence) {
2725 mOutput.mState.isEnabled = true;
2726 mOutput.mState.usesClientComposition = true;
2727
2728 // This should happen even if there are no (current) output layers.
2729 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
2730
2731 // Load up the released layers with some mock instances
2732 sp<StrictMock<mock::LayerFE>> releasedLayer1{new StrictMock<mock::LayerFE>()};
2733 sp<StrictMock<mock::LayerFE>> releasedLayer2{new StrictMock<mock::LayerFE>()};
2734 sp<StrictMock<mock::LayerFE>> releasedLayer3{new StrictMock<mock::LayerFE>()};
2735 Output::ReleasedLayers layers;
2736 layers.push_back(releasedLayer1);
2737 layers.push_back(releasedLayer2);
2738 layers.push_back(releasedLayer3);
2739 mOutput.setReleasedLayers(std::move(layers));
2740
2741 // Set up a fake present fence
2742 sp<Fence> presentFence = new Fence();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08002743 Output::FrameFences frameFences;
Lloyd Pique07178e32019-11-19 19:15:26 -08002744 frameFences.presentFence = presentFence;
2745
2746 EXPECT_CALL(*mRenderSurface, flip());
2747 EXPECT_CALL(mOutput, presentAndGetFrameFences()).WillOnce(Return(frameFences));
2748 EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted());
2749
2750 // Each released layer should be given the presentFence.
2751 EXPECT_CALL(*releasedLayer1,
2752 onLayerDisplayed(Property(&sp<Fence>::get, Eq(presentFence.get()))));
2753 EXPECT_CALL(*releasedLayer2,
2754 onLayerDisplayed(Property(&sp<Fence>::get, Eq(presentFence.get()))));
2755 EXPECT_CALL(*releasedLayer3,
2756 onLayerDisplayed(Property(&sp<Fence>::get, Eq(presentFence.get()))));
2757
2758 mOutput.postFramebuffer();
2759
2760 // After the call the list of released layers should have been cleared.
2761 EXPECT_TRUE(mOutput.getReleasedLayersForTest().empty());
2762}
Lloyd Piquefaa3f192019-11-14 14:05:09 -08002763
2764/*
Lloyd Pique56eba802019-08-28 15:45:25 -07002765 * Output::composeSurfaces()
2766 */
2767
2768struct OutputComposeSurfacesTest : public testing::Test {
Lloyd Pique6818fa52019-12-03 12:32:13 -08002769 using TestType = OutputComposeSurfacesTest;
Lloyd Pique56eba802019-08-28 15:45:25 -07002770
Lloyd Piquefaa3f192019-11-14 14:05:09 -08002771 struct OutputPartialMock : public OutputPartialMockBase {
Lloyd Pique739afaf2019-11-21 16:40:05 -08002772 // Sets up the helper functions called by the function under test to use
2773 // mock implementations.
Lloyd Pique56eba802019-08-28 15:45:25 -07002774 MOCK_CONST_METHOD0(getSkipColorTransform, bool());
Vishnu Nair3a7346c2019-12-04 08:09:09 -08002775 MOCK_METHOD3(generateClientCompositionRequests,
Vishnu Nair9b079a22020-01-21 14:36:08 -08002776 std::vector<LayerFE::LayerSettings>(bool, Region&, ui::Dataspace));
Lloyd Pique56eba802019-08-28 15:45:25 -07002777 MOCK_METHOD2(appendRegionFlashRequests,
Vishnu Nair9b079a22020-01-21 14:36:08 -08002778 void(const Region&, std::vector<LayerFE::LayerSettings>&));
Lloyd Pique56eba802019-08-28 15:45:25 -07002779 MOCK_METHOD1(setExpensiveRenderingExpected, void(bool));
2780 };
2781
2782 OutputComposeSurfacesTest() {
2783 mOutput.setDisplayColorProfileForTest(
2784 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
2785 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
Vishnu Nair9b079a22020-01-21 14:36:08 -08002786 mOutput.cacheClientCompositionRequests(MAX_CLIENT_COMPOSITION_CACHE_SIZE);
Lloyd Pique56eba802019-08-28 15:45:25 -07002787
Lloyd Pique6818fa52019-12-03 12:32:13 -08002788 mOutput.mState.frame = kDefaultOutputFrame;
2789 mOutput.mState.viewport = kDefaultOutputViewport;
Lloyd Piquee8fe4742020-01-21 15:26:18 -08002790 mOutput.mState.sourceClip = kDefaultOutputSourceClip;
2791 mOutput.mState.destinationClip = kDefaultOutputDestinationClip;
Lloyd Pique6818fa52019-12-03 12:32:13 -08002792 mOutput.mState.transform = ui::Transform{kDefaultOutputOrientation};
2793 mOutput.mState.orientation = kDefaultOutputOrientation;
2794 mOutput.mState.dataspace = kDefaultOutputDataspace;
2795 mOutput.mState.colorTransformMatrix = kDefaultColorTransformMat;
2796 mOutput.mState.isSecure = false;
2797 mOutput.mState.needsFiltering = false;
2798 mOutput.mState.usesClientComposition = true;
2799 mOutput.mState.usesDeviceComposition = false;
Vishnu Nair9b079a22020-01-21 14:36:08 -08002800 mOutput.mState.reusedClientComposition = false;
Lloyd Pique56eba802019-08-28 15:45:25 -07002801
Lloyd Piquea38ea7e2019-04-16 18:10:26 -07002802 EXPECT_CALL(mOutput, getCompositionEngine()).WillRepeatedly(ReturnRef(mCompositionEngine));
Lloyd Pique56eba802019-08-28 15:45:25 -07002803 EXPECT_CALL(mCompositionEngine, getRenderEngine()).WillRepeatedly(ReturnRef(mRenderEngine));
Alec Mourie4034bb2019-11-19 12:45:54 -08002804 EXPECT_CALL(mCompositionEngine, getTimeStats())
2805 .WillRepeatedly(ReturnRef(*mTimeStats.get()));
Lloyd Pique6818fa52019-12-03 12:32:13 -08002806 EXPECT_CALL(*mDisplayColorProfile, getHdrCapabilities())
2807 .WillRepeatedly(ReturnRef(kHdrCapabilities));
Lloyd Pique56eba802019-08-28 15:45:25 -07002808 }
2809
Lloyd Pique6818fa52019-12-03 12:32:13 -08002810 struct ExecuteState : public CallOrderStateMachineHelper<TestType, ExecuteState> {
2811 auto execute() {
Lucas Dupin2dd6f392020-02-18 17:43:36 -08002812 getInstance()->mReadyFence =
2813 getInstance()->mOutput.composeSurfaces(kDebugRegion, kDefaultRefreshArgs);
Lloyd Pique6818fa52019-12-03 12:32:13 -08002814 return nextState<FenceCheckState>();
2815 }
2816 };
2817
2818 struct FenceCheckState : public CallOrderStateMachineHelper<TestType, FenceCheckState> {
2819 void expectNoFenceWasReturned() { EXPECT_FALSE(getInstance()->mReadyFence); }
2820
2821 void expectAFenceWasReturned() { EXPECT_TRUE(getInstance()->mReadyFence); }
2822 };
2823
2824 // Call this member function to start using the mini-DSL defined above.
2825 [[nodiscard]] auto verify() { return ExecuteState::make(this); }
2826
2827 static constexpr uint32_t kDefaultOutputOrientation = TR_IDENT;
2828 static constexpr ui::Dataspace kDefaultOutputDataspace = ui::Dataspace::UNKNOWN;
2829 static constexpr ui::Dataspace kExpensiveOutputDataspace = ui::Dataspace::DISPLAY_P3;
2830 static constexpr float kDefaultMaxLuminance = 0.9f;
2831 static constexpr float kDefaultAvgLuminance = 0.7f;
2832 static constexpr float kDefaultMinLuminance = 0.1f;
2833
2834 static const Rect kDefaultOutputFrame;
2835 static const Rect kDefaultOutputViewport;
Lloyd Piquee8fe4742020-01-21 15:26:18 -08002836 static const Rect kDefaultOutputSourceClip;
2837 static const Rect kDefaultOutputDestinationClip;
Lloyd Pique6818fa52019-12-03 12:32:13 -08002838 static const mat4 kDefaultColorTransformMat;
2839
2840 static const Region kDebugRegion;
Lucas Dupin2dd6f392020-02-18 17:43:36 -08002841 static const compositionengine::CompositionRefreshArgs kDefaultRefreshArgs;
Lloyd Pique6818fa52019-12-03 12:32:13 -08002842 static const HdrCapabilities kHdrCapabilities;
2843
Lloyd Pique56eba802019-08-28 15:45:25 -07002844 StrictMock<mock::CompositionEngine> mCompositionEngine;
2845 StrictMock<renderengine::mock::RenderEngine> mRenderEngine;
Alec Mourie4034bb2019-11-19 12:45:54 -08002846 // TODO: make this is a proper mock.
2847 std::shared_ptr<TimeStats> mTimeStats = std::make_shared<android::impl::TimeStats>();
Lloyd Pique56eba802019-08-28 15:45:25 -07002848 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
2849 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -07002850 StrictMock<OutputPartialMock> mOutput;
Lloyd Pique56eba802019-08-28 15:45:25 -07002851 sp<GraphicBuffer> mOutputBuffer = new GraphicBuffer();
Lloyd Pique6818fa52019-12-03 12:32:13 -08002852
2853 std::optional<base::unique_fd> mReadyFence;
Lloyd Pique56eba802019-08-28 15:45:25 -07002854};
2855
2856const Rect OutputComposeSurfacesTest::kDefaultOutputFrame{1001, 1002, 1003, 1004};
2857const Rect OutputComposeSurfacesTest::kDefaultOutputViewport{1005, 1006, 1007, 1008};
Lloyd Piquee8fe4742020-01-21 15:26:18 -08002858const Rect OutputComposeSurfacesTest::kDefaultOutputSourceClip{1009, 1010, 1011, 1012};
2859const Rect OutputComposeSurfacesTest::kDefaultOutputDestinationClip{1013, 1014, 1015, 1016};
Lloyd Pique0a456232020-01-16 17:51:13 -08002860const mat4 OutputComposeSurfacesTest::kDefaultColorTransformMat{mat4() * 0.5f};
Lucas Dupin2dd6f392020-02-18 17:43:36 -08002861const compositionengine::CompositionRefreshArgs OutputComposeSurfacesTest::kDefaultRefreshArgs;
Lloyd Pique6818fa52019-12-03 12:32:13 -08002862const Region OutputComposeSurfacesTest::kDebugRegion{Rect{100, 101, 102, 103}};
2863const HdrCapabilities OutputComposeSurfacesTest::
2864 kHdrCapabilities{{},
2865 OutputComposeSurfacesTest::kDefaultMaxLuminance,
2866 OutputComposeSurfacesTest::kDefaultAvgLuminance,
2867 OutputComposeSurfacesTest::kDefaultMinLuminance};
Lloyd Pique56eba802019-08-28 15:45:25 -07002868
Lloyd Piquea76ce462020-01-14 13:06:37 -08002869TEST_F(OutputComposeSurfacesTest, doesNothingButSignalNoExpensiveRenderingIfNoClientComposition) {
Lloyd Pique6818fa52019-12-03 12:32:13 -08002870 mOutput.mState.usesClientComposition = false;
Lloyd Pique56eba802019-08-28 15:45:25 -07002871
Lloyd Piquea76ce462020-01-14 13:06:37 -08002872 EXPECT_CALL(mOutput, setExpensiveRenderingExpected(false));
2873
Lloyd Pique6818fa52019-12-03 12:32:13 -08002874 verify().execute().expectAFenceWasReturned();
Lloyd Pique56eba802019-08-28 15:45:25 -07002875}
2876
Lloyd Pique6818fa52019-12-03 12:32:13 -08002877TEST_F(OutputComposeSurfacesTest, doesMinimalWorkIfDequeueBufferFails) {
2878 EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false));
2879 EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true));
2880 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
2881 EXPECT_CALL(mOutput, generateClientCompositionRequests(_, _, kDefaultOutputDataspace))
Vishnu Nair9b079a22020-01-21 14:36:08 -08002882 .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{}));
Lloyd Pique6818fa52019-12-03 12:32:13 -08002883 EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _))
2884 .WillRepeatedly(Return());
Lloyd Pique56eba802019-08-28 15:45:25 -07002885
Lloyd Pique6818fa52019-12-03 12:32:13 -08002886 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillOnce(Return(nullptr));
Lloyd Pique56eba802019-08-28 15:45:25 -07002887
Lloyd Pique6818fa52019-12-03 12:32:13 -08002888 verify().execute().expectNoFenceWasReturned();
2889}
Lloyd Pique56eba802019-08-28 15:45:25 -07002890
Lloyd Pique6818fa52019-12-03 12:32:13 -08002891TEST_F(OutputComposeSurfacesTest, handlesZeroCompositionRequests) {
2892 EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false));
2893 EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true));
2894 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
2895 EXPECT_CALL(mOutput, generateClientCompositionRequests(_, _, kDefaultOutputDataspace))
Vishnu Nair9b079a22020-01-21 14:36:08 -08002896 .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{}));
Lloyd Pique6818fa52019-12-03 12:32:13 -08002897 EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _))
2898 .WillRepeatedly(Return());
Lloyd Pique56eba802019-08-28 15:45:25 -07002899
Lloyd Pique6818fa52019-12-03 12:32:13 -08002900 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer));
2901 EXPECT_CALL(mRenderEngine, drawLayers(_, IsEmpty(), _, true, _, _))
2902 .WillRepeatedly(Return(NO_ERROR));
Lloyd Pique56eba802019-08-28 15:45:25 -07002903
Lloyd Pique6818fa52019-12-03 12:32:13 -08002904 verify().execute().expectAFenceWasReturned();
2905}
Lloyd Pique56eba802019-08-28 15:45:25 -07002906
Lloyd Pique6818fa52019-12-03 12:32:13 -08002907TEST_F(OutputComposeSurfacesTest, buildsAndRendersRequestList) {
Vishnu Nair9b079a22020-01-21 14:36:08 -08002908 LayerFE::LayerSettings r1;
2909 LayerFE::LayerSettings r2;
Lloyd Pique6818fa52019-12-03 12:32:13 -08002910
2911 r1.geometry.boundaries = FloatRect{1, 2, 3, 4};
2912 r2.geometry.boundaries = FloatRect{5, 6, 7, 8};
2913
2914 EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false));
2915 EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true));
2916 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
2917 EXPECT_CALL(mOutput, generateClientCompositionRequests(_, _, kDefaultOutputDataspace))
Vishnu Nair9b079a22020-01-21 14:36:08 -08002918 .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{r1}));
Lloyd Pique6818fa52019-12-03 12:32:13 -08002919 EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _))
2920 .WillRepeatedly(
2921 Invoke([&](const Region&,
Vishnu Nair9b079a22020-01-21 14:36:08 -08002922 std::vector<LayerFE::LayerSettings>& clientCompositionLayers) {
Lloyd Pique6818fa52019-12-03 12:32:13 -08002923 clientCompositionLayers.emplace_back(r2);
2924 }));
2925
2926 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer));
Vishnu Nair9b079a22020-01-21 14:36:08 -08002927 EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(Pointee(r1), Pointee(r2)), _, true, _, _))
Lloyd Pique6818fa52019-12-03 12:32:13 -08002928 .WillRepeatedly(Return(NO_ERROR));
2929
2930 verify().execute().expectAFenceWasReturned();
2931}
2932
Vishnu Nair9b079a22020-01-21 14:36:08 -08002933TEST_F(OutputComposeSurfacesTest, renderDuplicateClientCompositionRequestsWithoutCache) {
2934 mOutput.cacheClientCompositionRequests(0);
2935 LayerFE::LayerSettings r1;
2936 LayerFE::LayerSettings r2;
2937
2938 r1.geometry.boundaries = FloatRect{1, 2, 3, 4};
2939 r2.geometry.boundaries = FloatRect{5, 6, 7, 8};
2940
2941 EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false));
2942 EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true));
2943 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
2944 EXPECT_CALL(mOutput, generateClientCompositionRequests(_, _, kDefaultOutputDataspace))
2945 .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{r1, r2}));
2946 EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _))
2947 .WillRepeatedly(Return());
2948
2949 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer));
2950 EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(Pointee(r1), Pointee(r2)), _, true, _, _))
2951 .Times(2)
2952 .WillOnce(Return(NO_ERROR));
2953
2954 verify().execute().expectAFenceWasReturned();
2955 EXPECT_FALSE(mOutput.mState.reusedClientComposition);
2956
2957 verify().execute().expectAFenceWasReturned();
2958 EXPECT_FALSE(mOutput.mState.reusedClientComposition);
2959}
2960
2961TEST_F(OutputComposeSurfacesTest, skipDuplicateClientCompositionRequests) {
2962 mOutput.cacheClientCompositionRequests(3);
2963 LayerFE::LayerSettings r1;
2964 LayerFE::LayerSettings r2;
2965
2966 r1.geometry.boundaries = FloatRect{1, 2, 3, 4};
2967 r2.geometry.boundaries = FloatRect{5, 6, 7, 8};
2968
2969 EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false));
2970 EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true));
2971 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
2972 EXPECT_CALL(mOutput, generateClientCompositionRequests(_, _, kDefaultOutputDataspace))
2973 .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{r1, r2}));
2974 EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _))
2975 .WillRepeatedly(Return());
2976
2977 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer));
2978 EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(Pointee(r1), Pointee(r2)), _, true, _, _))
2979 .WillOnce(Return(NO_ERROR));
2980 EXPECT_CALL(mOutput, setExpensiveRenderingExpected(false));
2981
2982 verify().execute().expectAFenceWasReturned();
2983 EXPECT_FALSE(mOutput.mState.reusedClientComposition);
2984
2985 // We do not expect another call to draw layers.
2986 verify().execute().expectAFenceWasReturned();
2987 EXPECT_TRUE(mOutput.mState.reusedClientComposition);
2988}
2989
2990TEST_F(OutputComposeSurfacesTest, clientCompositionIfBufferChanges) {
2991 LayerFE::LayerSettings r1;
2992 LayerFE::LayerSettings r2;
2993
2994 r1.geometry.boundaries = FloatRect{1, 2, 3, 4};
2995 r2.geometry.boundaries = FloatRect{5, 6, 7, 8};
2996
2997 EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false));
2998 EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true));
2999 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
3000 EXPECT_CALL(mOutput, generateClientCompositionRequests(_, _, kDefaultOutputDataspace))
3001 .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{r1, r2}));
3002 EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _))
3003 .WillRepeatedly(Return());
3004
3005 sp<GraphicBuffer> otherOutputBuffer = new GraphicBuffer();
3006 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_))
3007 .WillOnce(Return(mOutputBuffer))
3008 .WillOnce(Return(otherOutputBuffer));
3009 EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(Pointee(r1), Pointee(r2)), _, true, _, _))
3010 .WillRepeatedly(Return(NO_ERROR));
3011
3012 verify().execute().expectAFenceWasReturned();
3013 EXPECT_FALSE(mOutput.mState.reusedClientComposition);
3014
3015 verify().execute().expectAFenceWasReturned();
3016 EXPECT_FALSE(mOutput.mState.reusedClientComposition);
3017}
3018
3019TEST_F(OutputComposeSurfacesTest, clientCompositionIfRequestChanges) {
3020 LayerFE::LayerSettings r1;
3021 LayerFE::LayerSettings r2;
3022 LayerFE::LayerSettings r3;
3023
3024 r1.geometry.boundaries = FloatRect{1, 2, 3, 4};
3025 r2.geometry.boundaries = FloatRect{5, 6, 7, 8};
3026 r3.geometry.boundaries = FloatRect{5, 6, 7, 9};
3027
3028 EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false));
3029 EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true));
3030 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
3031 EXPECT_CALL(mOutput, generateClientCompositionRequests(_, _, kDefaultOutputDataspace))
3032 .WillOnce(Return(std::vector<LayerFE::LayerSettings>{r1, r2}))
3033 .WillOnce(Return(std::vector<LayerFE::LayerSettings>{r1, r3}));
3034 EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _))
3035 .WillRepeatedly(Return());
3036
3037 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer));
3038 EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(Pointee(r1), Pointee(r2)), _, true, _, _))
3039 .WillOnce(Return(NO_ERROR));
3040 EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(Pointee(r1), Pointee(r3)), _, true, _, _))
3041 .WillOnce(Return(NO_ERROR));
3042
3043 verify().execute().expectAFenceWasReturned();
3044 EXPECT_FALSE(mOutput.mState.reusedClientComposition);
3045
3046 verify().execute().expectAFenceWasReturned();
3047 EXPECT_FALSE(mOutput.mState.reusedClientComposition);
3048}
3049
Lloyd Pique6818fa52019-12-03 12:32:13 -08003050struct OutputComposeSurfacesTest_UsesExpectedDisplaySettings : public OutputComposeSurfacesTest {
3051 OutputComposeSurfacesTest_UsesExpectedDisplaySettings() {
3052 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
3053 EXPECT_CALL(mOutput, generateClientCompositionRequests(_, _, kDefaultOutputDataspace))
Vishnu Nair9b079a22020-01-21 14:36:08 -08003054 .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{}));
Lloyd Pique6818fa52019-12-03 12:32:13 -08003055 EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _))
3056 .WillRepeatedly(Return());
3057 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer));
3058 }
3059
3060 struct MixedCompositionState
3061 : public CallOrderStateMachineHelper<TestType, MixedCompositionState> {
3062 auto ifMixedCompositionIs(bool used) {
3063 getInstance()->mOutput.mState.usesDeviceComposition = used;
3064 return nextState<OutputUsesHdrState>();
3065 }
3066 };
3067
3068 struct OutputUsesHdrState : public CallOrderStateMachineHelper<TestType, OutputUsesHdrState> {
3069 auto andIfUsesHdr(bool used) {
3070 EXPECT_CALL(*getInstance()->mDisplayColorProfile, hasWideColorGamut())
3071 .WillOnce(Return(used));
3072 return nextState<SkipColorTransformState>();
3073 }
3074 };
3075
3076 struct SkipColorTransformState
3077 : public CallOrderStateMachineHelper<TestType, SkipColorTransformState> {
3078 auto andIfSkipColorTransform(bool skip) {
3079 // May be called zero or one times.
3080 EXPECT_CALL(getInstance()->mOutput, getSkipColorTransform())
3081 .WillRepeatedly(Return(skip));
3082 return nextState<ExpectDisplaySettingsState>();
3083 }
3084 };
3085
3086 struct ExpectDisplaySettingsState
3087 : public CallOrderStateMachineHelper<TestType, ExpectDisplaySettingsState> {
3088 auto thenExpectDisplaySettingsUsed(renderengine::DisplaySettings settings) {
3089 EXPECT_CALL(getInstance()->mRenderEngine, drawLayers(settings, _, _, true, _, _))
3090 .WillOnce(Return(NO_ERROR));
3091 return nextState<ExecuteState>();
3092 }
3093 };
3094
3095 // Call this member function to start using the mini-DSL defined above.
3096 [[nodiscard]] auto verify() { return MixedCompositionState::make(this); }
3097};
3098
3099TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings, forHdrMixedComposition) {
3100 verify().ifMixedCompositionIs(true)
3101 .andIfUsesHdr(true)
3102 .andIfSkipColorTransform(false)
Lloyd Piquee8fe4742020-01-21 15:26:18 -08003103 .thenExpectDisplaySettingsUsed({kDefaultOutputDestinationClip, kDefaultOutputSourceClip,
Alec Mourid4bf7952020-04-06 20:28:16 -07003104 kDefaultMaxLuminance, kDefaultOutputDataspace, mat4(),
3105 Region::INVALID_REGION, kDefaultOutputOrientation})
Lloyd Pique6818fa52019-12-03 12:32:13 -08003106 .execute()
3107 .expectAFenceWasReturned();
3108}
3109
3110TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings, forNonHdrMixedComposition) {
3111 verify().ifMixedCompositionIs(true)
3112 .andIfUsesHdr(false)
3113 .andIfSkipColorTransform(false)
Lloyd Piquee8fe4742020-01-21 15:26:18 -08003114 .thenExpectDisplaySettingsUsed({kDefaultOutputDestinationClip, kDefaultOutputSourceClip,
Alec Mourid4bf7952020-04-06 20:28:16 -07003115 kDefaultMaxLuminance, kDefaultOutputDataspace, mat4(),
3116 Region::INVALID_REGION, kDefaultOutputOrientation})
Lloyd Pique6818fa52019-12-03 12:32:13 -08003117 .execute()
3118 .expectAFenceWasReturned();
3119}
3120
3121TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings, forHdrOnlyClientComposition) {
3122 verify().ifMixedCompositionIs(false)
3123 .andIfUsesHdr(true)
3124 .andIfSkipColorTransform(false)
Lloyd Piquee8fe4742020-01-21 15:26:18 -08003125 .thenExpectDisplaySettingsUsed({kDefaultOutputDestinationClip, kDefaultOutputSourceClip,
Alec Mourid4bf7952020-04-06 20:28:16 -07003126 kDefaultMaxLuminance, kDefaultOutputDataspace,
Lloyd Pique6818fa52019-12-03 12:32:13 -08003127 kDefaultColorTransformMat, Region::INVALID_REGION,
3128 kDefaultOutputOrientation})
3129 .execute()
3130 .expectAFenceWasReturned();
3131}
3132
3133TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings, forNonHdrOnlyClientComposition) {
3134 verify().ifMixedCompositionIs(false)
3135 .andIfUsesHdr(false)
3136 .andIfSkipColorTransform(false)
Lloyd Piquee8fe4742020-01-21 15:26:18 -08003137 .thenExpectDisplaySettingsUsed({kDefaultOutputDestinationClip, kDefaultOutputSourceClip,
Alec Mourid4bf7952020-04-06 20:28:16 -07003138 kDefaultMaxLuminance, kDefaultOutputDataspace,
Lloyd Pique6818fa52019-12-03 12:32:13 -08003139 kDefaultColorTransformMat, Region::INVALID_REGION,
3140 kDefaultOutputOrientation})
3141 .execute()
3142 .expectAFenceWasReturned();
3143}
3144
3145TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings,
3146 usesExpectedDisplaySettingsForHdrOnlyClientCompositionWithSkipClientTransform) {
3147 verify().ifMixedCompositionIs(false)
3148 .andIfUsesHdr(true)
3149 .andIfSkipColorTransform(true)
Lloyd Piquee8fe4742020-01-21 15:26:18 -08003150 .thenExpectDisplaySettingsUsed({kDefaultOutputDestinationClip, kDefaultOutputSourceClip,
Alec Mourid4bf7952020-04-06 20:28:16 -07003151 kDefaultMaxLuminance, kDefaultOutputDataspace, mat4(),
3152 Region::INVALID_REGION, kDefaultOutputOrientation})
Lloyd Pique6818fa52019-12-03 12:32:13 -08003153 .execute()
3154 .expectAFenceWasReturned();
3155}
3156
3157struct OutputComposeSurfacesTest_HandlesProtectedContent : public OutputComposeSurfacesTest {
3158 struct Layer {
3159 Layer() {
Lloyd Piquede196652020-01-22 17:29:58 -08003160 EXPECT_CALL(mLayerFE, getCompositionState()).WillRepeatedly(Return(&mLayerFEState));
3161 EXPECT_CALL(mOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(mLayerFE));
Lloyd Pique6818fa52019-12-03 12:32:13 -08003162 }
3163
3164 StrictMock<mock::OutputLayer> mOutputLayer;
Lloyd Piquede196652020-01-22 17:29:58 -08003165 StrictMock<mock::LayerFE> mLayerFE;
Lloyd Pique6818fa52019-12-03 12:32:13 -08003166 LayerFECompositionState mLayerFEState;
3167 };
3168
3169 OutputComposeSurfacesTest_HandlesProtectedContent() {
3170 mLayer1.mLayerFEState.hasProtectedContent = false;
3171 mLayer2.mLayerFEState.hasProtectedContent = false;
3172
3173 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2u));
3174 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u))
3175 .WillRepeatedly(Return(&mLayer1.mOutputLayer));
3176 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1u))
3177 .WillRepeatedly(Return(&mLayer2.mOutputLayer));
3178
3179 EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false));
3180
3181 EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true));
3182
3183 EXPECT_CALL(mOutput, generateClientCompositionRequests(_, _, _))
Vishnu Nair9b079a22020-01-21 14:36:08 -08003184 .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{}));
Lloyd Pique6818fa52019-12-03 12:32:13 -08003185 EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _))
3186 .WillRepeatedly(Return());
3187 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer));
3188 EXPECT_CALL(mRenderEngine, drawLayers(_, _, _, true, _, _))
3189 .WillRepeatedly(Return(NO_ERROR));
3190 }
3191
3192 Layer mLayer1;
3193 Layer mLayer2;
3194};
3195
3196TEST_F(OutputComposeSurfacesTest_HandlesProtectedContent, ifDisplayIsNotSecure) {
3197 mOutput.mState.isSecure = false;
3198 mLayer2.mLayerFEState.hasProtectedContent = true;
3199 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(true));
3200
Lucas Dupin2dd6f392020-02-18 17:43:36 -08003201 mOutput.composeSurfaces(kDebugRegion, kDefaultRefreshArgs);
Lloyd Pique6818fa52019-12-03 12:32:13 -08003202}
3203
3204TEST_F(OutputComposeSurfacesTest_HandlesProtectedContent, ifRenderEngineDoesNotSupportIt) {
3205 mOutput.mState.isSecure = true;
3206 mLayer2.mLayerFEState.hasProtectedContent = true;
3207 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
3208
Lucas Dupin2dd6f392020-02-18 17:43:36 -08003209 mOutput.composeSurfaces(kDebugRegion, kDefaultRefreshArgs);
Lloyd Pique6818fa52019-12-03 12:32:13 -08003210}
3211
3212TEST_F(OutputComposeSurfacesTest_HandlesProtectedContent, ifNoProtectedContentLayers) {
3213 mOutput.mState.isSecure = true;
3214 mLayer2.mLayerFEState.hasProtectedContent = false;
3215 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(true));
3216 EXPECT_CALL(mRenderEngine, isProtected).WillOnce(Return(true)).WillOnce(Return(false));
3217 EXPECT_CALL(*mRenderSurface, isProtected).WillOnce(Return(true));
3218 EXPECT_CALL(mRenderEngine, useProtectedContext(false));
3219 EXPECT_CALL(*mRenderSurface, setProtected(false));
3220
Lucas Dupin2dd6f392020-02-18 17:43:36 -08003221 mOutput.composeSurfaces(kDebugRegion, kDefaultRefreshArgs);
Lloyd Pique6818fa52019-12-03 12:32:13 -08003222}
3223
3224TEST_F(OutputComposeSurfacesTest_HandlesProtectedContent, ifNotEnabled) {
3225 mOutput.mState.isSecure = true;
3226 mLayer2.mLayerFEState.hasProtectedContent = true;
3227 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(true));
3228
3229 // For this test, we also check the call order of key functions.
3230 InSequence seq;
3231
3232 EXPECT_CALL(mRenderEngine, isProtected).WillOnce(Return(false));
3233 EXPECT_CALL(mRenderEngine, useProtectedContext(true));
3234 EXPECT_CALL(*mRenderSurface, isProtected).WillOnce(Return(false));
3235 EXPECT_CALL(mRenderEngine, isProtected).WillOnce(Return(true));
3236 EXPECT_CALL(*mRenderSurface, setProtected(true));
3237 // Must happen after setting the protected content state.
3238 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer));
3239 EXPECT_CALL(mRenderEngine, drawLayers(_, _, _, true, _, _)).WillOnce(Return(NO_ERROR));
3240
Lucas Dupin2dd6f392020-02-18 17:43:36 -08003241 mOutput.composeSurfaces(kDebugRegion, kDefaultRefreshArgs);
Lloyd Pique6818fa52019-12-03 12:32:13 -08003242}
3243
3244TEST_F(OutputComposeSurfacesTest_HandlesProtectedContent, ifAlreadyEnabledEverywhere) {
3245 mOutput.mState.isSecure = true;
3246 mLayer2.mLayerFEState.hasProtectedContent = true;
3247 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(true));
3248 EXPECT_CALL(mRenderEngine, isProtected).WillOnce(Return(true));
3249 EXPECT_CALL(*mRenderSurface, isProtected).WillOnce(Return(true));
3250
Lucas Dupin2dd6f392020-02-18 17:43:36 -08003251 mOutput.composeSurfaces(kDebugRegion, kDefaultRefreshArgs);
Lloyd Pique6818fa52019-12-03 12:32:13 -08003252}
3253
3254TEST_F(OutputComposeSurfacesTest_HandlesProtectedContent, ifFailsToEnableInRenderEngine) {
3255 mOutput.mState.isSecure = true;
3256 mLayer2.mLayerFEState.hasProtectedContent = true;
3257 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(true));
3258 EXPECT_CALL(mRenderEngine, isProtected).WillOnce(Return(false)).WillOnce(Return(false));
3259 EXPECT_CALL(*mRenderSurface, isProtected).WillOnce(Return(false));
3260 EXPECT_CALL(mRenderEngine, useProtectedContext(true));
3261
Lucas Dupin2dd6f392020-02-18 17:43:36 -08003262 mOutput.composeSurfaces(kDebugRegion, kDefaultRefreshArgs);
Lloyd Pique6818fa52019-12-03 12:32:13 -08003263}
3264
3265TEST_F(OutputComposeSurfacesTest_HandlesProtectedContent, ifAlreadyEnabledInRenderEngine) {
3266 mOutput.mState.isSecure = true;
3267 mLayer2.mLayerFEState.hasProtectedContent = true;
3268 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(true));
3269 EXPECT_CALL(mRenderEngine, isProtected).WillOnce(Return(true)).WillOnce(Return(true));
3270 EXPECT_CALL(*mRenderSurface, isProtected).WillOnce(Return(false));
3271 EXPECT_CALL(*mRenderSurface, setProtected(true));
3272
Lucas Dupin2dd6f392020-02-18 17:43:36 -08003273 mOutput.composeSurfaces(kDebugRegion, kDefaultRefreshArgs);
Lloyd Pique6818fa52019-12-03 12:32:13 -08003274}
3275
3276TEST_F(OutputComposeSurfacesTest_HandlesProtectedContent, ifAlreadyEnabledInRenderSurface) {
3277 mOutput.mState.isSecure = true;
3278 mLayer2.mLayerFEState.hasProtectedContent = true;
3279 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(true));
3280 EXPECT_CALL(mRenderEngine, isProtected).WillOnce(Return(false));
3281 EXPECT_CALL(*mRenderSurface, isProtected).WillOnce(Return(true));
3282 EXPECT_CALL(mRenderEngine, useProtectedContext(true));
3283
Lucas Dupin2dd6f392020-02-18 17:43:36 -08003284 mOutput.composeSurfaces(kDebugRegion, kDefaultRefreshArgs);
Lloyd Pique6818fa52019-12-03 12:32:13 -08003285}
3286
3287struct OutputComposeSurfacesTest_SetsExpensiveRendering : public OutputComposeSurfacesTest {
3288 OutputComposeSurfacesTest_SetsExpensiveRendering() {
3289 EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false));
3290 EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true));
3291 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
3292 EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _))
3293 .WillRepeatedly(Return());
3294 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer));
3295 }
3296};
3297
3298TEST_F(OutputComposeSurfacesTest_SetsExpensiveRendering, IfExepensiveOutputDataspaceIsUsed) {
3299 mOutput.mState.dataspace = kExpensiveOutputDataspace;
3300
3301 EXPECT_CALL(mOutput, generateClientCompositionRequests(_, _, kExpensiveOutputDataspace))
Vishnu Nair9b079a22020-01-21 14:36:08 -08003302 .WillOnce(Return(std::vector<LayerFE::LayerSettings>{}));
Lloyd Pique6818fa52019-12-03 12:32:13 -08003303
3304 // For this test, we also check the call order of key functions.
3305 InSequence seq;
3306
3307 EXPECT_CALL(mOutput, setExpensiveRenderingExpected(true));
3308 EXPECT_CALL(mRenderEngine, drawLayers(_, _, _, true, _, _)).WillOnce(Return(NO_ERROR));
Lloyd Pique6818fa52019-12-03 12:32:13 -08003309
Lucas Dupin2dd6f392020-02-18 17:43:36 -08003310 mOutput.composeSurfaces(kDebugRegion, kDefaultRefreshArgs);
3311}
3312
3313struct OutputComposeSurfacesTest_SetsExpensiveRendering_ForBlur
3314 : public OutputComposeSurfacesTest_SetsExpensiveRendering {
3315 OutputComposeSurfacesTest_SetsExpensiveRendering_ForBlur() {
3316 mLayer.layerFEState.backgroundBlurRadius = 10;
3317 mOutput.editState().isEnabled = true;
3318
Snild Dolkow9e217d62020-04-22 15:53:42 +02003319 EXPECT_CALL(mLayer.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0));
Lucas Dupin2dd6f392020-02-18 17:43:36 -08003320 EXPECT_CALL(mLayer.outputLayer, writeStateToHWC(false));
3321 EXPECT_CALL(mOutput, generateClientCompositionRequests(_, _, kDefaultOutputDataspace))
3322 .WillOnce(Return(std::vector<LayerFE::LayerSettings>{}));
3323 EXPECT_CALL(mRenderEngine, drawLayers(_, _, _, true, _, _)).WillOnce(Return(NO_ERROR));
3324 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(1u));
3325 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u))
3326 .WillRepeatedly(Return(&mLayer.outputLayer));
3327 }
3328
3329 NonInjectedLayer mLayer;
3330 compositionengine::CompositionRefreshArgs mRefreshArgs;
3331};
3332
3333TEST_F(OutputComposeSurfacesTest_SetsExpensiveRendering_ForBlur, IfBlursAreExpensive) {
3334 mRefreshArgs.blursAreExpensive = true;
3335 mOutput.updateAndWriteCompositionState(mRefreshArgs);
3336
3337 EXPECT_CALL(mOutput, setExpensiveRenderingExpected(true));
3338 mOutput.composeSurfaces(kDebugRegion, mRefreshArgs);
3339}
3340
3341TEST_F(OutputComposeSurfacesTest_SetsExpensiveRendering_ForBlur, IfBlursAreNotExpensive) {
3342 mRefreshArgs.blursAreExpensive = false;
3343 mOutput.updateAndWriteCompositionState(mRefreshArgs);
3344
3345 EXPECT_CALL(mOutput, setExpensiveRenderingExpected(true)).Times(0);
3346 mOutput.composeSurfaces(kDebugRegion, mRefreshArgs);
Lloyd Pique56eba802019-08-28 15:45:25 -07003347}
3348
3349/*
3350 * Output::generateClientCompositionRequests()
3351 */
3352
3353struct GenerateClientCompositionRequestsTest : public testing::Test {
Lloyd Piquefaa3f192019-11-14 14:05:09 -08003354 struct OutputPartialMock : public OutputPartialMockBase {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -07003355 // compositionengine::Output overrides
Vishnu Nair9b079a22020-01-21 14:36:08 -08003356 std::vector<LayerFE::LayerSettings> generateClientCompositionRequests(
Vishnu Nair3a7346c2019-12-04 08:09:09 -08003357 bool supportsProtectedContent, Region& clearRegion,
3358 ui::Dataspace dataspace) override {
Lloyd Pique56eba802019-08-28 15:45:25 -07003359 return impl::Output::generateClientCompositionRequests(supportsProtectedContent,
Vishnu Nair3a7346c2019-12-04 08:09:09 -08003360 clearRegion, dataspace);
Lloyd Pique56eba802019-08-28 15:45:25 -07003361 }
3362 };
3363
Lloyd Piquea4863342019-12-04 18:45:02 -08003364 struct Layer {
3365 Layer() {
3366 EXPECT_CALL(mOutputLayer, getState()).WillRepeatedly(ReturnRef(mOutputLayerState));
3367 EXPECT_CALL(mOutputLayer, editState()).WillRepeatedly(ReturnRef(mOutputLayerState));
Lloyd Piquea4863342019-12-04 18:45:02 -08003368 EXPECT_CALL(mOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(mLayerFE));
Lloyd Piquede196652020-01-22 17:29:58 -08003369 EXPECT_CALL(mLayerFE, getCompositionState()).WillRepeatedly(Return(&mLayerFEState));
Lloyd Piquea4863342019-12-04 18:45:02 -08003370 }
3371
3372 StrictMock<mock::OutputLayer> mOutputLayer;
Lloyd Piquea4863342019-12-04 18:45:02 -08003373 StrictMock<mock::LayerFE> mLayerFE;
3374 LayerFECompositionState mLayerFEState;
3375 impl::OutputLayerCompositionState mOutputLayerState;
Vishnu Nair9b079a22020-01-21 14:36:08 -08003376 LayerFE::LayerSettings mLayerSettings;
Lloyd Piquea4863342019-12-04 18:45:02 -08003377 };
3378
Lloyd Pique56eba802019-08-28 15:45:25 -07003379 GenerateClientCompositionRequestsTest() {
Lloyd Piquea4863342019-12-04 18:45:02 -08003380 mOutput.mState.needsFiltering = false;
3381
Lloyd Pique56eba802019-08-28 15:45:25 -07003382 mOutput.setDisplayColorProfileForTest(
3383 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
3384 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
3385 }
3386
Lloyd Pique56eba802019-08-28 15:45:25 -07003387 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
3388 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -07003389 StrictMock<OutputPartialMock> mOutput;
Lloyd Pique56eba802019-08-28 15:45:25 -07003390};
3391
Lloyd Piquea4863342019-12-04 18:45:02 -08003392struct GenerateClientCompositionRequestsTest_ThreeLayers
3393 : public GenerateClientCompositionRequestsTest {
3394 GenerateClientCompositionRequestsTest_ThreeLayers() {
3395 mOutput.mState.frame = kDisplayFrame;
3396 mOutput.mState.viewport = kDisplayViewport;
Lloyd Piquee8fe4742020-01-21 15:26:18 -08003397 mOutput.mState.sourceClip = kDisplaySourceClip;
3398 mOutput.mState.destinationClip = kDisplayDestinationClip;
Lloyd Piquea4863342019-12-04 18:45:02 -08003399 mOutput.mState.transform = ui::Transform{kDisplayOrientation};
3400 mOutput.mState.orientation = kDisplayOrientation;
3401 mOutput.mState.needsFiltering = false;
3402 mOutput.mState.isSecure = false;
Lloyd Pique56eba802019-08-28 15:45:25 -07003403
Lloyd Piquea4863342019-12-04 18:45:02 -08003404 for (size_t i = 0; i < mLayers.size(); i++) {
3405 mLayers[i].mOutputLayerState.clearClientTarget = false;
3406 mLayers[i].mOutputLayerState.visibleRegion = Region(kDisplayFrame);
3407 mLayers[i].mLayerFEState.isOpaque = true;
Vishnu Nair9b079a22020-01-21 14:36:08 -08003408 mLayers[i].mLayerSettings.geometry.boundaries =
Lloyd Piquea4863342019-12-04 18:45:02 -08003409 FloatRect{static_cast<float>(i + 1), 0.f, 0.f, 0.f};
Vishnu Nair9b079a22020-01-21 14:36:08 -08003410 mLayers[i].mLayerSettings.source.solidColor = {1.0f, 1.0f, 1.0f};
3411 mLayers[i].mLayerSettings.alpha = 1.0f;
3412 mLayers[i].mLayerSettings.disableBlending = false;
Lloyd Pique56eba802019-08-28 15:45:25 -07003413
Lloyd Piquea4863342019-12-04 18:45:02 -08003414 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(i))
3415 .WillRepeatedly(Return(&mLayers[i].mOutputLayer));
3416 EXPECT_CALL(mLayers[i].mOutputLayer, requiresClientComposition())
3417 .WillRepeatedly(Return(true));
3418 EXPECT_CALL(mLayers[i].mOutputLayer, needsFiltering()).WillRepeatedly(Return(false));
3419 }
Lloyd Pique56eba802019-08-28 15:45:25 -07003420
Lloyd Piquea4863342019-12-04 18:45:02 -08003421 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(mLayers.size()));
3422 }
Lloyd Pique56eba802019-08-28 15:45:25 -07003423
Lloyd Piquea4863342019-12-04 18:45:02 -08003424 static constexpr uint32_t kDisplayOrientation = TR_IDENT;
3425 static constexpr ui::Dataspace kDisplayDataspace = ui::Dataspace::UNKNOWN;
Lloyd Pique56eba802019-08-28 15:45:25 -07003426
Lloyd Piquea4863342019-12-04 18:45:02 -08003427 static const Rect kDisplayFrame;
3428 static const Rect kDisplayViewport;
Lloyd Piquee8fe4742020-01-21 15:26:18 -08003429 static const Rect kDisplaySourceClip;
3430 static const Rect kDisplayDestinationClip;
Lloyd Pique56eba802019-08-28 15:45:25 -07003431
Lloyd Piquea4863342019-12-04 18:45:02 -08003432 std::array<Layer, 3> mLayers;
3433};
Lloyd Pique56eba802019-08-28 15:45:25 -07003434
Lloyd Piquea4863342019-12-04 18:45:02 -08003435const Rect GenerateClientCompositionRequestsTest_ThreeLayers::kDisplayFrame(0, 0, 100, 200);
3436const Rect GenerateClientCompositionRequestsTest_ThreeLayers::kDisplayViewport(0, 0, 101, 201);
Lloyd Piquee8fe4742020-01-21 15:26:18 -08003437const Rect GenerateClientCompositionRequestsTest_ThreeLayers::kDisplaySourceClip(0, 0, 102, 202);
3438const Rect GenerateClientCompositionRequestsTest_ThreeLayers::kDisplayDestinationClip(0, 0, 103,
3439 203);
Lloyd Pique56eba802019-08-28 15:45:25 -07003440
Lloyd Piquea4863342019-12-04 18:45:02 -08003441TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, handlesNoClientCompostionLayers) {
3442 EXPECT_CALL(mLayers[0].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
3443 EXPECT_CALL(mLayers[1].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
3444 EXPECT_CALL(mLayers[2].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
Lloyd Pique56eba802019-08-28 15:45:25 -07003445
Lloyd Piquea4863342019-12-04 18:45:02 -08003446 Region accumClearRegion(Rect(10, 11, 12, 13));
3447 auto requests = mOutput.generateClientCompositionRequests(false /* supportsProtectedContent */,
3448 accumClearRegion, kDisplayDataspace);
Lloyd Pique56eba802019-08-28 15:45:25 -07003449 EXPECT_EQ(0u, requests.size());
Lloyd Piquea4863342019-12-04 18:45:02 -08003450 EXPECT_THAT(accumClearRegion, RegionEq(Region(Rect(10, 11, 12, 13))));
Lloyd Pique56eba802019-08-28 15:45:25 -07003451}
3452
Lloyd Piquea4863342019-12-04 18:45:02 -08003453TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, requiresVisibleRegionAfterViewportClip) {
3454 mLayers[0].mOutputLayerState.visibleRegion = Region(Rect(10, 10, 10, 10));
3455 mLayers[1].mOutputLayerState.visibleRegion = Region(Rect(4000, 0, 4010, 10));
3456 mLayers[2].mOutputLayerState.visibleRegion = Region(Rect(-10, -10, 0, 0));
3457
3458 Region accumClearRegion(Rect(10, 11, 12, 13));
3459 auto requests = mOutput.generateClientCompositionRequests(false /* supportsProtectedContent */,
3460 accumClearRegion, kDisplayDataspace);
3461 EXPECT_EQ(0u, requests.size());
3462 EXPECT_THAT(accumClearRegion, RegionEq(Region(Rect(10, 11, 12, 13))));
3463}
3464
3465TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, gathersClientCompositionRequests) {
Vishnu Nair9b079a22020-01-21 14:36:08 -08003466 LayerFE::LayerSettings mShadowSettings;
3467 mShadowSettings.source.solidColor = {0.1f, 0.1f, 0.1f};
Lloyd Piquea4863342019-12-04 18:45:02 -08003468
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003469 EXPECT_CALL(mLayers[0].mLayerFE, prepareClientCompositionList(_))
3470 .WillOnce(Return(std::vector<LayerFE::LayerSettings>()));
3471 EXPECT_CALL(mLayers[1].mLayerFE, prepareClientCompositionList(_))
3472 .WillOnce(Return(std::vector<LayerFE::LayerSettings>({mLayers[1].mLayerSettings})));
3473 EXPECT_CALL(mLayers[2].mLayerFE, prepareClientCompositionList(_))
3474 .WillOnce(Return(std::vector<LayerFE::LayerSettings>(
3475 {mShadowSettings, mLayers[2].mLayerSettings})));
Lloyd Piquea4863342019-12-04 18:45:02 -08003476
3477 Region accumClearRegion(Rect(10, 11, 12, 13));
3478 auto requests = mOutput.generateClientCompositionRequests(false /* supportsProtectedContent */,
3479 accumClearRegion, kDisplayDataspace);
3480 ASSERT_EQ(3u, requests.size());
Vishnu Nair9b079a22020-01-21 14:36:08 -08003481 EXPECT_EQ(mLayers[1].mLayerSettings, requests[0]);
3482 EXPECT_EQ(mShadowSettings, requests[1]);
3483 EXPECT_EQ(mLayers[2].mLayerSettings, requests[2]);
Lloyd Piquea4863342019-12-04 18:45:02 -08003484
3485 EXPECT_THAT(accumClearRegion, RegionEq(Region(Rect(10, 11, 12, 13))));
3486
3487 // Check that a timestamp was set for the layers that generated requests
3488 EXPECT_TRUE(0 == mLayers[0].mOutputLayerState.clientCompositionTimestamp);
3489 EXPECT_TRUE(0 != mLayers[1].mOutputLayerState.clientCompositionTimestamp);
3490 EXPECT_TRUE(0 != mLayers[2].mOutputLayerState.clientCompositionTimestamp);
3491}
3492
3493TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,
3494 onlyClientComposesClientComposedLayersIfNoClearingNeeded) {
3495 EXPECT_CALL(mLayers[0].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
3496 EXPECT_CALL(mLayers[1].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
3497 EXPECT_CALL(mLayers[2].mOutputLayer, requiresClientComposition()).WillOnce(Return(true));
3498
3499 mLayers[0].mOutputLayerState.clearClientTarget = false;
3500 mLayers[1].mOutputLayerState.clearClientTarget = false;
3501 mLayers[2].mOutputLayerState.clearClientTarget = false;
3502
3503 mLayers[0].mLayerFEState.isOpaque = true;
3504 mLayers[1].mLayerFEState.isOpaque = true;
3505 mLayers[2].mLayerFEState.isOpaque = true;
3506
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003507 EXPECT_CALL(mLayers[2].mLayerFE, prepareClientCompositionList(_))
3508 .WillOnce(Return(std::vector<LayerFE::LayerSettings>({mLayers[2].mLayerSettings})));
Lloyd Piquea4863342019-12-04 18:45:02 -08003509
3510 Region accumClearRegion(Rect(10, 11, 12, 13));
3511 auto requests = mOutput.generateClientCompositionRequests(false /* supportsProtectedContent */,
3512 accumClearRegion, kDisplayDataspace);
3513 ASSERT_EQ(1u, requests.size());
Vishnu Nair9b079a22020-01-21 14:36:08 -08003514 EXPECT_EQ(mLayers[2].mLayerSettings, requests[0]);
Lloyd Piquea4863342019-12-04 18:45:02 -08003515
3516 EXPECT_THAT(accumClearRegion, RegionEq(Region(Rect(10, 11, 12, 13))));
3517}
3518
3519TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,
3520 onlyClientComposesClientComposedLayersIfOthersAreNotOpaque) {
3521 EXPECT_CALL(mLayers[0].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
3522 EXPECT_CALL(mLayers[1].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
3523 EXPECT_CALL(mLayers[2].mOutputLayer, requiresClientComposition()).WillOnce(Return(true));
3524
3525 mLayers[0].mOutputLayerState.clearClientTarget = true;
3526 mLayers[1].mOutputLayerState.clearClientTarget = true;
3527 mLayers[2].mOutputLayerState.clearClientTarget = true;
3528
3529 mLayers[0].mLayerFEState.isOpaque = false;
3530 mLayers[1].mLayerFEState.isOpaque = false;
3531 mLayers[2].mLayerFEState.isOpaque = false;
3532
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003533 EXPECT_CALL(mLayers[2].mLayerFE, prepareClientCompositionList(_))
3534 .WillOnce(Return(std::vector<LayerFE::LayerSettings>({mLayers[2].mLayerSettings})));
Lloyd Piquea4863342019-12-04 18:45:02 -08003535
3536 Region accumClearRegion(Rect(10, 11, 12, 13));
3537 auto requests = mOutput.generateClientCompositionRequests(false /* supportsProtectedContent */,
3538 accumClearRegion, kDisplayDataspace);
3539 ASSERT_EQ(1u, requests.size());
Vishnu Nair9b079a22020-01-21 14:36:08 -08003540 EXPECT_EQ(mLayers[2].mLayerSettings, requests[0]);
Lloyd Piquea4863342019-12-04 18:45:02 -08003541
3542 EXPECT_THAT(accumClearRegion, RegionEq(Region(Rect(10, 11, 12, 13))));
3543}
3544
3545TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, clearsHWCLayersIfOpaqueAndNotFirst) {
Lloyd Piquec2d54d42019-08-28 18:04:21 -07003546 // If client composition is performed with some layers set to use device
3547 // composition, device layers after the first layer (device or client) will
3548 // clear the frame buffer if they are opaque and if that layer has a flag
3549 // set to do so. The first layer is skipped as the frame buffer is already
3550 // expected to be clear.
3551
Lloyd Piquea4863342019-12-04 18:45:02 -08003552 EXPECT_CALL(mLayers[0].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
3553 EXPECT_CALL(mLayers[1].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
3554 EXPECT_CALL(mLayers[2].mOutputLayer, requiresClientComposition()).WillOnce(Return(true));
Lloyd Piquec2d54d42019-08-28 18:04:21 -07003555
Lloyd Piquea4863342019-12-04 18:45:02 -08003556 mLayers[0].mOutputLayerState.clearClientTarget = true;
3557 mLayers[1].mOutputLayerState.clearClientTarget = true;
3558 mLayers[2].mOutputLayerState.clearClientTarget = true;
Lloyd Piquec2d54d42019-08-28 18:04:21 -07003559
Lloyd Piquea4863342019-12-04 18:45:02 -08003560 mLayers[0].mLayerFEState.isOpaque = true;
3561 mLayers[1].mLayerFEState.isOpaque = true;
3562 mLayers[2].mLayerFEState.isOpaque = true;
Lloyd Piquea4863342019-12-04 18:45:02 -08003563 Region accumClearRegion(Rect(10, 11, 12, 13));
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003564 Region dummyRegion;
3565
3566 compositionengine::LayerFE::ClientCompositionTargetSettings layer1TargetSettings{
3567 Region(kDisplayFrame),
3568 false, /* identity transform */
3569 false, /* needs filtering */
3570 false, /* secure */
3571 false, /* supports protected content */
3572 dummyRegion, /* clear region */
3573 kDisplayViewport,
3574 kDisplayDataspace,
3575 false /* realContentIsVisible */,
3576 true /* clearContent */,
3577 };
3578 compositionengine::LayerFE::ClientCompositionTargetSettings layer2TargetSettings{
3579 Region(kDisplayFrame),
3580 false, /* identity transform */
3581 false, /* needs filtering */
3582 false, /* secure */
3583 false, /* supports protected content */
3584 accumClearRegion,
3585 kDisplayViewport,
3586 kDisplayDataspace,
3587 true /* realContentIsVisible */,
3588 false /* clearContent */,
3589 };
3590
3591 LayerFE::LayerSettings mBlackoutSettings = mLayers[1].mLayerSettings;
3592 mBlackoutSettings.source.buffer.buffer = nullptr;
3593 mBlackoutSettings.source.solidColor = {0.1f, 0.1f, 0.1f};
3594 mBlackoutSettings.alpha = 0.f;
3595 mBlackoutSettings.disableBlending = true;
3596
3597 EXPECT_CALL(mLayers[1].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer1TargetSettings))))
3598 .WillOnce(Return(std::vector<LayerFE::LayerSettings>({mBlackoutSettings})));
3599 EXPECT_CALL(mLayers[2].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer2TargetSettings))))
3600 .WillOnce(Return(std::vector<LayerFE::LayerSettings>({mLayers[2].mLayerSettings})));
3601
Lloyd Piquea4863342019-12-04 18:45:02 -08003602 auto requests = mOutput.generateClientCompositionRequests(false /* supportsProtectedContent */,
3603 accumClearRegion, kDisplayDataspace);
3604 ASSERT_EQ(2u, requests.size());
Lloyd Piquec2d54d42019-08-28 18:04:21 -07003605
Lloyd Piquea4863342019-12-04 18:45:02 -08003606 // The second layer is expected to be rendered as alpha=0 black with no blending
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003607 EXPECT_EQ(mBlackoutSettings, requests[0]);
Lloyd Piquec2d54d42019-08-28 18:04:21 -07003608
Vishnu Nair9b079a22020-01-21 14:36:08 -08003609 EXPECT_EQ(mLayers[2].mLayerSettings, requests[1]);
Lloyd Piquec2d54d42019-08-28 18:04:21 -07003610
Lloyd Piquea4863342019-12-04 18:45:02 -08003611 EXPECT_THAT(accumClearRegion, RegionEq(Region(Rect(10, 11, 12, 13))));
3612}
Lloyd Piquec2d54d42019-08-28 18:04:21 -07003613
Lloyd Piquea4863342019-12-04 18:45:02 -08003614TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,
3615 clippedVisibleRegionUsedToGenerateRequest) {
3616 mLayers[0].mOutputLayerState.visibleRegion = Region(Rect(10, 10, 20, 20));
3617 mLayers[1].mOutputLayerState.visibleRegion = Region(Rect(-10, -10, 30, 30));
3618 mLayers[2].mOutputLayerState.visibleRegion = Region(Rect(-10, 0, 40, 4000));
Lloyd Piquec2d54d42019-08-28 18:04:21 -07003619
Lloyd Piquea4863342019-12-04 18:45:02 -08003620 Region accumClearRegion(Rect(10, 11, 12, 13));
3621
3622 compositionengine::LayerFE::ClientCompositionTargetSettings layer0TargetSettings{
3623 Region(Rect(10, 10, 20, 20)),
3624 false, /* identity transform */
3625 false, /* needs filtering */
3626 false, /* secure */
3627 false, /* supports protected content */
3628 accumClearRegion,
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003629 kDisplayViewport,
3630 kDisplayDataspace,
3631 true /* realContentIsVisible */,
3632 false /* clearContent */,
Lloyd Piquea4863342019-12-04 18:45:02 -08003633 };
3634 compositionengine::LayerFE::ClientCompositionTargetSettings layer1TargetSettings{
3635 Region(Rect(0, 0, 30, 30)),
3636 false, /* identity transform */
3637 false, /* needs filtering */
3638 false, /* secure */
3639 false, /* supports protected content */
3640 accumClearRegion,
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003641 kDisplayViewport,
3642 kDisplayDataspace,
3643 true /* realContentIsVisible */,
3644 false /* clearContent */,
Lloyd Piquea4863342019-12-04 18:45:02 -08003645 };
3646 compositionengine::LayerFE::ClientCompositionTargetSettings layer2TargetSettings{
3647 Region(Rect(0, 0, 40, 201)),
3648 false, /* identity transform */
3649 false, /* needs filtering */
3650 false, /* secure */
3651 false, /* supports protected content */
3652 accumClearRegion,
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003653 kDisplayViewport,
3654 kDisplayDataspace,
3655 true /* realContentIsVisible */,
3656 false /* clearContent */,
Lloyd Piquea4863342019-12-04 18:45:02 -08003657 };
3658
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003659 EXPECT_CALL(mLayers[0].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer0TargetSettings))))
3660 .WillOnce(Return(std::vector<LayerFE::LayerSettings>()));
3661 EXPECT_CALL(mLayers[1].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer1TargetSettings))))
3662 .WillOnce(Return(std::vector<LayerFE::LayerSettings>()));
3663 EXPECT_CALL(mLayers[2].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer2TargetSettings))))
3664 .WillOnce(Return(std::vector<LayerFE::LayerSettings>()));
Lloyd Piquea4863342019-12-04 18:45:02 -08003665
3666 static_cast<void>(
3667 mOutput.generateClientCompositionRequests(false /* supportsProtectedContent */,
3668 accumClearRegion, kDisplayDataspace));
3669}
3670
3671TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,
3672 perLayerNeedsFilteringUsedToGenerateRequests) {
3673 mOutput.mState.needsFiltering = false;
3674 EXPECT_CALL(mLayers[0].mOutputLayer, needsFiltering()).WillRepeatedly(Return(true));
3675
3676 Region accumClearRegion(Rect(10, 11, 12, 13));
3677
3678 compositionengine::LayerFE::ClientCompositionTargetSettings layer0TargetSettings{
3679 Region(kDisplayFrame),
3680 false, /* identity transform */
3681 true, /* needs filtering */
3682 false, /* secure */
3683 false, /* supports protected content */
3684 accumClearRegion,
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003685 kDisplayViewport,
3686 kDisplayDataspace,
3687 true /* realContentIsVisible */,
3688 false /* clearContent */,
Lloyd Piquea4863342019-12-04 18:45:02 -08003689 };
3690 compositionengine::LayerFE::ClientCompositionTargetSettings layer1TargetSettings{
3691 Region(kDisplayFrame),
3692 false, /* identity transform */
3693 false, /* needs filtering */
3694 false, /* secure */
3695 false, /* supports protected content */
3696 accumClearRegion,
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003697 kDisplayViewport,
3698 kDisplayDataspace,
3699 true /* realContentIsVisible */,
3700 false /* clearContent */,
Lloyd Piquea4863342019-12-04 18:45:02 -08003701 };
3702 compositionengine::LayerFE::ClientCompositionTargetSettings layer2TargetSettings{
3703 Region(kDisplayFrame),
3704 false, /* identity transform */
3705 false, /* needs filtering */
3706 false, /* secure */
3707 false, /* supports protected content */
3708 accumClearRegion,
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003709 kDisplayViewport,
3710 kDisplayDataspace,
3711 true /* realContentIsVisible */,
3712 false /* clearContent */,
Lloyd Piquea4863342019-12-04 18:45:02 -08003713 };
3714
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003715 EXPECT_CALL(mLayers[0].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer0TargetSettings))))
3716 .WillOnce(Return(std::vector<LayerFE::LayerSettings>()));
3717 EXPECT_CALL(mLayers[1].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer1TargetSettings))))
3718 .WillOnce(Return(std::vector<LayerFE::LayerSettings>()));
3719 EXPECT_CALL(mLayers[2].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer2TargetSettings))))
3720 .WillOnce(Return(std::vector<LayerFE::LayerSettings>()));
Lloyd Piquea4863342019-12-04 18:45:02 -08003721
3722 static_cast<void>(
3723 mOutput.generateClientCompositionRequests(false /* supportsProtectedContent */,
3724 accumClearRegion, kDisplayDataspace));
3725}
3726
3727TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,
3728 wholeOutputNeedsFilteringUsedToGenerateRequests) {
3729 mOutput.mState.needsFiltering = true;
3730 EXPECT_CALL(mLayers[0].mOutputLayer, needsFiltering()).WillRepeatedly(Return(true));
3731
3732 Region accumClearRegion(Rect(10, 11, 12, 13));
3733
3734 compositionengine::LayerFE::ClientCompositionTargetSettings layer0TargetSettings{
3735 Region(kDisplayFrame),
3736 false, /* identity transform */
3737 true, /* needs filtering */
3738 false, /* secure */
3739 false, /* supports protected content */
3740 accumClearRegion,
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003741 kDisplayViewport,
3742 kDisplayDataspace,
3743 true /* realContentIsVisible */,
3744 false /* clearContent */,
3745
Lloyd Piquea4863342019-12-04 18:45:02 -08003746 };
3747 compositionengine::LayerFE::ClientCompositionTargetSettings layer1TargetSettings{
3748 Region(kDisplayFrame),
3749 false, /* identity transform */
3750 true, /* needs filtering */
3751 false, /* secure */
3752 false, /* supports protected content */
3753 accumClearRegion,
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003754 kDisplayViewport,
3755 kDisplayDataspace,
3756 true /* realContentIsVisible */,
3757 false /* clearContent */,
Lloyd Piquea4863342019-12-04 18:45:02 -08003758 };
3759 compositionengine::LayerFE::ClientCompositionTargetSettings layer2TargetSettings{
3760 Region(kDisplayFrame),
3761 false, /* identity transform */
3762 true, /* needs filtering */
3763 false, /* secure */
3764 false, /* supports protected content */
3765 accumClearRegion,
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003766 kDisplayViewport,
3767 kDisplayDataspace,
3768 true /* realContentIsVisible */,
3769 false /* clearContent */,
Lloyd Piquea4863342019-12-04 18:45:02 -08003770 };
3771
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003772 EXPECT_CALL(mLayers[0].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer0TargetSettings))))
3773 .WillOnce(Return(std::vector<LayerFE::LayerSettings>()));
3774 EXPECT_CALL(mLayers[1].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer1TargetSettings))))
3775 .WillOnce(Return(std::vector<LayerFE::LayerSettings>()));
3776 EXPECT_CALL(mLayers[2].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer2TargetSettings))))
3777 .WillOnce(Return(std::vector<LayerFE::LayerSettings>()));
Lloyd Piquea4863342019-12-04 18:45:02 -08003778
3779 static_cast<void>(
3780 mOutput.generateClientCompositionRequests(false /* supportsProtectedContent */,
3781 accumClearRegion, kDisplayDataspace));
3782}
3783
3784TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,
3785 wholeOutputSecurityUsedToGenerateRequests) {
3786 mOutput.mState.isSecure = true;
3787
3788 Region accumClearRegion(Rect(10, 11, 12, 13));
3789
3790 compositionengine::LayerFE::ClientCompositionTargetSettings layer0TargetSettings{
3791 Region(kDisplayFrame),
3792 false, /* identity transform */
3793 false, /* needs filtering */
3794 true, /* secure */
3795 false, /* supports protected content */
3796 accumClearRegion,
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003797 kDisplayViewport,
3798 kDisplayDataspace,
3799 true /* realContentIsVisible */,
3800 false /* clearContent */,
Lloyd Piquea4863342019-12-04 18:45:02 -08003801 };
3802 compositionengine::LayerFE::ClientCompositionTargetSettings layer1TargetSettings{
3803 Region(kDisplayFrame),
3804 false, /* identity transform */
3805 false, /* needs filtering */
3806 true, /* secure */
3807 false, /* supports protected content */
3808 accumClearRegion,
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003809 kDisplayViewport,
3810 kDisplayDataspace,
3811 true /* realContentIsVisible */,
3812 false /* clearContent */,
Lloyd Piquea4863342019-12-04 18:45:02 -08003813 };
3814 compositionengine::LayerFE::ClientCompositionTargetSettings layer2TargetSettings{
3815 Region(kDisplayFrame),
3816 false, /* identity transform */
3817 false, /* needs filtering */
3818 true, /* secure */
3819 false, /* supports protected content */
3820 accumClearRegion,
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003821 kDisplayViewport,
3822 kDisplayDataspace,
3823 true /* realContentIsVisible */,
3824 false /* clearContent */,
Lloyd Piquea4863342019-12-04 18:45:02 -08003825 };
3826
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003827 EXPECT_CALL(mLayers[0].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer0TargetSettings))))
3828 .WillOnce(Return(std::vector<LayerFE::LayerSettings>()));
3829 EXPECT_CALL(mLayers[1].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer1TargetSettings))))
3830 .WillOnce(Return(std::vector<LayerFE::LayerSettings>()));
3831 EXPECT_CALL(mLayers[2].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer2TargetSettings))))
3832 .WillOnce(Return(std::vector<LayerFE::LayerSettings>()));
Lloyd Piquea4863342019-12-04 18:45:02 -08003833
3834 static_cast<void>(
3835 mOutput.generateClientCompositionRequests(false /* supportsProtectedContent */,
3836 accumClearRegion, kDisplayDataspace));
3837}
3838
3839TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,
3840 protectedContentSupportUsedToGenerateRequests) {
3841 Region accumClearRegion(Rect(10, 11, 12, 13));
3842
3843 compositionengine::LayerFE::ClientCompositionTargetSettings layer0TargetSettings{
3844 Region(kDisplayFrame),
3845 false, /* identity transform */
3846 false, /* needs filtering */
3847 false, /* secure */
3848 true, /* supports protected content */
3849 accumClearRegion,
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003850 kDisplayViewport,
3851 kDisplayDataspace,
3852 true /* realContentIsVisible */,
3853 false /* clearContent */,
Lloyd Piquea4863342019-12-04 18:45:02 -08003854 };
3855 compositionengine::LayerFE::ClientCompositionTargetSettings layer1TargetSettings{
3856 Region(kDisplayFrame),
3857 false, /* identity transform */
3858 false, /* needs filtering */
3859 false, /* secure */
3860 true, /* supports protected content */
3861 accumClearRegion,
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003862 kDisplayViewport,
3863 kDisplayDataspace,
3864 true /* realContentIsVisible */,
3865 false /* clearContent */,
Lloyd Piquea4863342019-12-04 18:45:02 -08003866 };
3867 compositionengine::LayerFE::ClientCompositionTargetSettings layer2TargetSettings{
3868 Region(kDisplayFrame),
3869 false, /* identity transform */
3870 false, /* needs filtering */
3871 false, /* secure */
3872 true, /* supports protected content */
3873 accumClearRegion,
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003874 kDisplayViewport,
3875 kDisplayDataspace,
3876 true /* realContentIsVisible */,
3877 false /* clearContent */,
Lloyd Piquea4863342019-12-04 18:45:02 -08003878 };
3879
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003880 EXPECT_CALL(mLayers[0].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer0TargetSettings))))
3881 .WillOnce(Return(std::vector<LayerFE::LayerSettings>()));
3882 EXPECT_CALL(mLayers[1].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer1TargetSettings))))
3883 .WillOnce(Return(std::vector<LayerFE::LayerSettings>()));
3884 EXPECT_CALL(mLayers[2].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer2TargetSettings))))
3885 .WillOnce(Return(std::vector<LayerFE::LayerSettings>()));
Lloyd Piquea4863342019-12-04 18:45:02 -08003886
3887 static_cast<void>(mOutput.generateClientCompositionRequests(true /* supportsProtectedContent */,
3888 accumClearRegion,
3889 kDisplayDataspace));
3890}
3891
Lucas Dupin19c8f0e2019-11-25 17:55:44 -08003892TEST_F(OutputUpdateAndWriteCompositionStateTest, handlesBackgroundBlurRequests) {
Lloyd Piquede196652020-01-22 17:29:58 -08003893 InjectedLayer layer1;
3894 InjectedLayer layer2;
3895 InjectedLayer layer3;
3896
Lucas Dupin19c8f0e2019-11-25 17:55:44 -08003897 // Layer requesting blur, or below, should request client composition.
Snild Dolkow9e217d62020-04-22 15:53:42 +02003898 EXPECT_CALL(*layer1.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0));
Lloyd Piquede196652020-01-22 17:29:58 -08003899 EXPECT_CALL(*layer1.outputLayer, writeStateToHWC(false));
Snild Dolkow9e217d62020-04-22 15:53:42 +02003900 EXPECT_CALL(*layer2.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0));
Lloyd Piquede196652020-01-22 17:29:58 -08003901 EXPECT_CALL(*layer2.outputLayer, writeStateToHWC(false));
Snild Dolkow9e217d62020-04-22 15:53:42 +02003902 EXPECT_CALL(*layer3.outputLayer, updateCompositionState(false, false, ui::Transform::ROT_0));
Lloyd Piquede196652020-01-22 17:29:58 -08003903 EXPECT_CALL(*layer3.outputLayer, writeStateToHWC(false));
Lucas Dupin19c8f0e2019-11-25 17:55:44 -08003904
Lloyd Piquede196652020-01-22 17:29:58 -08003905 layer2.layerFEState.backgroundBlurRadius = 10;
Lucas Dupin19c8f0e2019-11-25 17:55:44 -08003906
Lloyd Piquede196652020-01-22 17:29:58 -08003907 injectOutputLayer(layer1);
3908 injectOutputLayer(layer2);
3909 injectOutputLayer(layer3);
Lucas Dupin19c8f0e2019-11-25 17:55:44 -08003910
3911 mOutput->editState().isEnabled = true;
3912
3913 CompositionRefreshArgs args;
3914 args.updatingGeometryThisFrame = false;
3915 args.devOptForceClientComposition = false;
3916 mOutput->updateAndWriteCompositionState(args);
3917}
3918
Lloyd Piquea4863342019-12-04 18:45:02 -08003919TEST_F(GenerateClientCompositionRequestsTest, handlesLandscapeModeSplitScreenRequests) {
3920 // In split-screen landscape mode, the screen is rotated 90 degrees, with
3921 // one layer on the left covering the left side of the output, and one layer
3922 // on the right covering that side of the output.
Lloyd Piquec2d54d42019-08-28 18:04:21 -07003923
3924 const Rect kPortraitFrame(0, 0, 1000, 2000);
3925 const Rect kPortraitViewport(0, 0, 2000, 1000);
Lloyd Piquee8fe4742020-01-21 15:26:18 -08003926 const Rect kPortraitSourceClip(0, 0, 1000, 2000);
3927 const Rect kPortraitDestinationClip(0, 0, 1000, 2000);
Lloyd Piquec2d54d42019-08-28 18:04:21 -07003928 const uint32_t kPortraitOrientation = TR_ROT_90;
Lloyd Piquea4863342019-12-04 18:45:02 -08003929 constexpr ui::Dataspace kOutputDataspace = ui::Dataspace::DISPLAY_P3;
Lloyd Piquec2d54d42019-08-28 18:04:21 -07003930
Lloyd Piquea4863342019-12-04 18:45:02 -08003931 mOutput.mState.frame = kPortraitFrame;
3932 mOutput.mState.viewport = kPortraitViewport;
Lloyd Piquee8fe4742020-01-21 15:26:18 -08003933 mOutput.mState.sourceClip = kPortraitSourceClip;
3934 mOutput.mState.destinationClip = kPortraitDestinationClip;
Lloyd Piquea4863342019-12-04 18:45:02 -08003935 mOutput.mState.transform = ui::Transform{kPortraitOrientation};
3936 mOutput.mState.orientation = kPortraitOrientation;
3937 mOutput.mState.needsFiltering = false;
3938 mOutput.mState.isSecure = true;
Lloyd Piquec2d54d42019-08-28 18:04:21 -07003939
Lloyd Piquea4863342019-12-04 18:45:02 -08003940 Layer leftLayer;
3941 Layer rightLayer;
Lloyd Piquec2d54d42019-08-28 18:04:21 -07003942
Lloyd Piquea4863342019-12-04 18:45:02 -08003943 leftLayer.mOutputLayerState.clearClientTarget = false;
3944 leftLayer.mOutputLayerState.visibleRegion = Region(Rect(0, 0, 1000, 1000));
3945 leftLayer.mLayerFEState.isOpaque = true;
Vishnu Nair9b079a22020-01-21 14:36:08 -08003946 leftLayer.mLayerSettings.source.solidColor = {1.f, 0.f, 0.f};
Lloyd Piquec2d54d42019-08-28 18:04:21 -07003947
Lloyd Piquea4863342019-12-04 18:45:02 -08003948 rightLayer.mOutputLayerState.clearClientTarget = false;
3949 rightLayer.mOutputLayerState.visibleRegion = Region(Rect(1000, 0, 2000, 1000));
3950 rightLayer.mLayerFEState.isOpaque = true;
Vishnu Nair9b079a22020-01-21 14:36:08 -08003951 rightLayer.mLayerSettings.source.solidColor = {0.f, 1.f, 0.f};
Lloyd Piquea4863342019-12-04 18:45:02 -08003952
3953 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2u));
3954 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u))
3955 .WillRepeatedly(Return(&leftLayer.mOutputLayer));
3956 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1u))
3957 .WillRepeatedly(Return(&rightLayer.mOutputLayer));
3958
3959 Region accumClearRegion(Rect(10, 11, 12, 13));
3960
3961 compositionengine::LayerFE::ClientCompositionTargetSettings leftLayerSettings{
3962 Region(Rect(0, 0, 1000, 1000)),
3963 false, /* identity transform */
3964 false, /* needs filtering */
3965 true, /* secure */
3966 true, /* supports protected content */
3967 accumClearRegion,
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003968 kPortraitViewport,
3969 kOutputDataspace,
3970 true /* realContentIsVisible */,
3971 false /* clearContent */,
Lloyd Piquea4863342019-12-04 18:45:02 -08003972 };
3973
3974 EXPECT_CALL(leftLayer.mOutputLayer, requiresClientComposition()).WillRepeatedly(Return(true));
3975 EXPECT_CALL(leftLayer.mOutputLayer, needsFiltering()).WillRepeatedly(Return(false));
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003976 EXPECT_CALL(leftLayer.mLayerFE, prepareClientCompositionList(Eq(ByRef(leftLayerSettings))))
3977 .WillOnce(Return(std::vector<LayerFE::LayerSettings>({leftLayer.mLayerSettings})));
Lloyd Piquea4863342019-12-04 18:45:02 -08003978
3979 compositionengine::LayerFE::ClientCompositionTargetSettings rightLayerSettings{
3980 Region(Rect(1000, 0, 2000, 1000)),
3981 false, /* identity transform */
3982 false, /* needs filtering */
3983 true, /* secure */
3984 true, /* supports protected content */
3985 accumClearRegion,
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003986 kPortraitViewport,
3987 kOutputDataspace,
3988 true /* realContentIsVisible */,
3989 false /* clearContent */,
Lloyd Piquea4863342019-12-04 18:45:02 -08003990 };
3991
3992 EXPECT_CALL(rightLayer.mOutputLayer, requiresClientComposition()).WillRepeatedly(Return(true));
3993 EXPECT_CALL(rightLayer.mOutputLayer, needsFiltering()).WillRepeatedly(Return(false));
Vishnu Nairb87d94f2020-02-13 09:17:36 -08003994 EXPECT_CALL(rightLayer.mLayerFE, prepareClientCompositionList(Eq(ByRef(rightLayerSettings))))
3995 .WillOnce(Return(std::vector<LayerFE::LayerSettings>({rightLayer.mLayerSettings})));
Lloyd Piquea4863342019-12-04 18:45:02 -08003996
3997 constexpr bool supportsProtectedContent = true;
3998 auto requests = mOutput.generateClientCompositionRequests(supportsProtectedContent,
3999 accumClearRegion, kOutputDataspace);
4000 ASSERT_EQ(2u, requests.size());
Vishnu Nair9b079a22020-01-21 14:36:08 -08004001 EXPECT_EQ(leftLayer.mLayerSettings, requests[0]);
4002 EXPECT_EQ(rightLayer.mLayerSettings, requests[1]);
Lloyd Piquec2d54d42019-08-28 18:04:21 -07004003}
4004
Vishnu Naira483b4a2019-12-12 15:07:52 -08004005TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,
4006 shadowRegionOnlyVisibleSkipsContentComposition) {
4007 const Rect kContentWithShadow(40, 40, 70, 90);
4008 const Rect kContent(50, 50, 60, 80);
4009 const Region kShadowRegion = Region(kContentWithShadow).subtract(kContent);
4010 const Region kPartialShadowRegion = Region(kContentWithShadow).subtract(Rect(40, 40, 60, 80));
4011
Vishnu Nairb87d94f2020-02-13 09:17:36 -08004012 Region accumClearRegion(Rect(10, 11, 12, 13));
4013 compositionengine::LayerFE::ClientCompositionTargetSettings layer2Settings{
4014 Region(Rect(60, 40, 70, 80)).merge(Rect(40, 80, 70, 90)), /* visible region */
4015 false, /* identity transform */
4016 false, /* needs filtering */
4017 false, /* secure */
4018 false, /* supports protected content */
4019 accumClearRegion,
4020 kDisplayViewport,
4021 kDisplayDataspace,
4022 false /* realContentIsVisible */,
4023 false /* clearContent */,
4024 };
4025
Vishnu Nair9b079a22020-01-21 14:36:08 -08004026 LayerFE::LayerSettings mShadowSettings;
4027 mShadowSettings.source.solidColor = {0.1f, 0.1f, 0.1f};
Vishnu Naira483b4a2019-12-12 15:07:52 -08004028
4029 mLayers[2].mOutputLayerState.visibleRegion = kPartialShadowRegion;
4030 mLayers[2].mOutputLayerState.shadowRegion = kShadowRegion;
4031
4032 EXPECT_CALL(mLayers[0].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
4033 EXPECT_CALL(mLayers[1].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
Vishnu Nairb87d94f2020-02-13 09:17:36 -08004034 EXPECT_CALL(mLayers[2].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer2Settings))))
4035 .WillOnce(Return(std::vector<LayerFE::LayerSettings>({mShadowSettings})));
Vishnu Naira483b4a2019-12-12 15:07:52 -08004036
Vishnu Naira483b4a2019-12-12 15:07:52 -08004037 auto requests = mOutput.generateClientCompositionRequests(false /* supportsProtectedContent */,
4038 accumClearRegion, kDisplayDataspace);
4039 ASSERT_EQ(1u, requests.size());
4040
Vishnu Nair9b079a22020-01-21 14:36:08 -08004041 EXPECT_EQ(mShadowSettings, requests[0]);
Vishnu Naira483b4a2019-12-12 15:07:52 -08004042}
4043
4044TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,
4045 shadowRegionWithContentVisibleRequestsContentAndShadowComposition) {
4046 const Rect kContentWithShadow(40, 40, 70, 90);
4047 const Rect kContent(50, 50, 60, 80);
4048 const Region kShadowRegion = Region(kContentWithShadow).subtract(kContent);
4049 const Region kPartialContentWithPartialShadowRegion =
4050 Region(kContentWithShadow).subtract(Rect(40, 40, 50, 80));
4051
Vishnu Nair9b079a22020-01-21 14:36:08 -08004052 LayerFE::LayerSettings mShadowSettings;
4053 mShadowSettings.source.solidColor = {0.1f, 0.1f, 0.1f};
Vishnu Naira483b4a2019-12-12 15:07:52 -08004054
4055 mLayers[2].mOutputLayerState.visibleRegion = kPartialContentWithPartialShadowRegion;
4056 mLayers[2].mOutputLayerState.shadowRegion = kShadowRegion;
4057
Vishnu Nairb87d94f2020-02-13 09:17:36 -08004058 Region accumClearRegion(Rect(10, 11, 12, 13));
4059 compositionengine::LayerFE::ClientCompositionTargetSettings layer2Settings{
4060 Region(Rect(50, 40, 70, 80)).merge(Rect(40, 80, 70, 90)), /* visible region */
4061 false, /* identity transform */
4062 false, /* needs filtering */
4063 false, /* secure */
4064 false, /* supports protected content */
4065 accumClearRegion,
4066 kDisplayViewport,
4067 kDisplayDataspace,
4068 true /* realContentIsVisible */,
4069 false /* clearContent */,
4070 };
4071
Vishnu Naira483b4a2019-12-12 15:07:52 -08004072 EXPECT_CALL(mLayers[0].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
4073 EXPECT_CALL(mLayers[1].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
Vishnu Nairb87d94f2020-02-13 09:17:36 -08004074 EXPECT_CALL(mLayers[2].mLayerFE, prepareClientCompositionList(Eq(ByRef(layer2Settings))))
4075 .WillOnce(Return(std::vector<LayerFE::LayerSettings>(
4076 {mShadowSettings, mLayers[2].mLayerSettings})));
Vishnu Naira483b4a2019-12-12 15:07:52 -08004077
Vishnu Naira483b4a2019-12-12 15:07:52 -08004078 auto requests = mOutput.generateClientCompositionRequests(false /* supportsProtectedContent */,
4079 accumClearRegion, kDisplayDataspace);
4080 ASSERT_EQ(2u, requests.size());
4081
Vishnu Nair9b079a22020-01-21 14:36:08 -08004082 EXPECT_EQ(mShadowSettings, requests[0]);
4083 EXPECT_EQ(mLayers[2].mLayerSettings, requests[1]);
Vishnu Naira483b4a2019-12-12 15:07:52 -08004084}
4085
Lloyd Pique32cbe282018-10-19 13:09:22 -07004086} // namespace
4087} // namespace android::compositionengine