blob: 08b8818e946c03053c4ba6153920f124aa9e8b67 [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/Layer.h>
27#include <compositionengine/mock/LayerFE.h>
28#include <compositionengine/mock/OutputLayer.h>
Lloyd Pique31cb2942018-10-19 17:23:03 -070029#include <compositionengine/mock/RenderSurface.h>
Lloyd Pique32cbe282018-10-19 13:09:22 -070030#include <gtest/gtest.h>
Lloyd Pique56eba802019-08-28 15:45:25 -070031#include <renderengine/mock/RenderEngine.h>
Lloyd Pique32cbe282018-10-19 13:09:22 -070032#include <ui/Rect.h>
33#include <ui/Region.h>
34
Lloyd Pique17ca7422019-11-14 14:24:10 -080035#include "CallOrderStateMachineHelper.h"
Lloyd Pique07178e32019-11-19 19:15:26 -080036#include "MockHWC2.h"
Lloyd Pique32cbe282018-10-19 13:09:22 -070037#include "RegionMatcher.h"
Lloyd Pique32cbe282018-10-19 13:09:22 -070038
39namespace android::compositionengine {
40namespace {
41
Lloyd Pique56eba802019-08-28 15:45:25 -070042using testing::_;
Lloyd Pique03561a62019-11-19 18:34:52 -080043using testing::ByMove;
Lloyd Pique17ca7422019-11-14 14:24:10 -080044using testing::DoAll;
Lloyd Pique07178e32019-11-19 19:15:26 -080045using testing::Eq;
Lloyd Piquefaa3f192019-11-14 14:05:09 -080046using testing::InSequence;
Lloyd Pique17ca7422019-11-14 14:24:10 -080047using testing::Mock;
Lloyd Pique07178e32019-11-19 19:15:26 -080048using testing::Property;
Lloyd Piquefaa3f192019-11-14 14:05:09 -080049using testing::Ref;
Lloyd Pique31cb2942018-10-19 17:23:03 -070050using testing::Return;
Lloyd Pique32cbe282018-10-19 13:09:22 -070051using testing::ReturnRef;
Lloyd Pique17ca7422019-11-14 14:24:10 -080052using testing::SetArgPointee;
Lloyd Pique32cbe282018-10-19 13:09:22 -070053using testing::StrictMock;
54
Lloyd Pique56eba802019-08-28 15:45:25 -070055constexpr auto TR_IDENT = 0u;
56constexpr auto TR_ROT_90 = HAL_TRANSFORM_ROT_90;
57
Lloyd Pique3eb1b212019-03-07 21:15:40 -080058const mat4 kIdentity;
59const mat4 kNonIdentityHalf = mat4() * 0.5;
60const mat4 kNonIdentityQuarter = mat4() * 0.25;
61
Lloyd Pique17ca7422019-11-14 14:24:10 -080062constexpr OutputColorSetting kVendorSpecifiedOutputColorSetting =
63 static_cast<OutputColorSetting>(0x100);
64
Lloyd Piquefaa3f192019-11-14 14:05:09 -080065struct OutputPartialMockBase : public impl::Output {
66 // compositionengine::Output overrides
67 const OutputCompositionState& getState() const override { return mState; }
68 OutputCompositionState& editState() override { return mState; }
69
70 // Use mocks for all the remaining virtual functions
71 // not implemented by the base implementation class.
72 MOCK_CONST_METHOD0(getOutputLayerCount, size_t());
73 MOCK_CONST_METHOD1(getOutputLayerOrderedByZByIndex, compositionengine::OutputLayer*(size_t));
74 MOCK_METHOD3(ensureOutputLayer,
75 compositionengine::OutputLayer*(std::optional<size_t>,
76 const std::shared_ptr<compositionengine::Layer>&,
77 const sp<LayerFE>&));
78 MOCK_METHOD0(finalizePendingOutputLayers, void());
79 MOCK_METHOD0(clearOutputLayers, void());
80 MOCK_CONST_METHOD1(dumpState, void(std::string&));
81 MOCK_CONST_METHOD0(getCompositionEngine, const CompositionEngine&());
82 MOCK_METHOD2(injectOutputLayerForTest,
83 compositionengine::OutputLayer*(const std::shared_ptr<compositionengine::Layer>&,
84 const sp<LayerFE>&));
85 MOCK_METHOD1(injectOutputLayerForTest, void(std::unique_ptr<OutputLayer>));
86
87 impl::OutputCompositionState mState;
88};
89
Lloyd Pique66d68602019-02-13 14:23:31 -080090struct OutputTest : public testing::Test {
Lloyd Pique01c77c12019-04-17 12:48:32 -070091 class Output : public impl::Output {
92 public:
93 using impl::Output::injectOutputLayerForTest;
94 virtual void injectOutputLayerForTest(std::unique_ptr<compositionengine::OutputLayer>) = 0;
95 };
96
97 static std::shared_ptr<Output> createOutput(
98 const compositionengine::CompositionEngine& compositionEngine) {
99 return impl::createOutputTemplated<Output>(compositionEngine);
100 }
101
Lloyd Pique31cb2942018-10-19 17:23:03 -0700102 OutputTest() {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700103 mOutput->setDisplayColorProfileForTest(
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700104 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700105 mOutput->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
Lloyd Piqueef958122019-02-05 18:00:12 -0800106
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700107 mOutput->editState().bounds = kDefaultDisplaySize;
Lloyd Pique31cb2942018-10-19 17:23:03 -0700108 }
Lloyd Pique32cbe282018-10-19 13:09:22 -0700109
Lloyd Piqueef958122019-02-05 18:00:12 -0800110 static const Rect kDefaultDisplaySize;
111
Lloyd Pique32cbe282018-10-19 13:09:22 -0700112 StrictMock<mock::CompositionEngine> mCompositionEngine;
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700113 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
Lloyd Pique31cb2942018-10-19 17:23:03 -0700114 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
Lloyd Pique01c77c12019-04-17 12:48:32 -0700115 std::shared_ptr<Output> mOutput = createOutput(mCompositionEngine);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700116};
117
Lloyd Piquec0ee6ba2019-11-14 12:55:53 -0800118// Extension of the base test useful for checking interactions with the LayerFE
119// functions to latch composition state.
120struct OutputLatchFEStateTest : public OutputTest {
121 OutputLatchFEStateTest() {
122 EXPECT_CALL(*mOutputLayer1, getLayer()).WillRepeatedly(ReturnRef(mLayer1));
123 EXPECT_CALL(*mOutputLayer2, getLayer()).WillRepeatedly(ReturnRef(mLayer2));
124 EXPECT_CALL(*mOutputLayer3, getLayer()).WillRepeatedly(ReturnRef(mLayer3));
125
126 EXPECT_CALL(*mOutputLayer1, getLayerFE()).WillRepeatedly(ReturnRef(mLayer1FE));
127 EXPECT_CALL(*mOutputLayer2, getLayerFE()).WillRepeatedly(ReturnRef(mLayer2FE));
128 EXPECT_CALL(*mOutputLayer3, getLayerFE()).WillRepeatedly(ReturnRef(mLayer3FE));
129
130 EXPECT_CALL(mLayer1, editFEState()).WillRepeatedly(ReturnRef(mLayer1FEState));
131 EXPECT_CALL(mLayer2, editFEState()).WillRepeatedly(ReturnRef(mLayer2FEState));
132 EXPECT_CALL(mLayer3, editFEState()).WillRepeatedly(ReturnRef(mLayer3FEState));
133 }
134
135 void injectLayer(std::unique_ptr<mock::OutputLayer> layer) {
136 mOutput->injectOutputLayerForTest(std::unique_ptr<OutputLayer>(layer.release()));
137 }
138
139 std::unique_ptr<mock::OutputLayer> mOutputLayer1{new StrictMock<mock::OutputLayer>};
140 std::unique_ptr<mock::OutputLayer> mOutputLayer2{new StrictMock<mock::OutputLayer>};
141 std::unique_ptr<mock::OutputLayer> mOutputLayer3{new StrictMock<mock::OutputLayer>};
142
143 StrictMock<mock::Layer> mLayer1;
144 StrictMock<mock::Layer> mLayer2;
145 StrictMock<mock::Layer> mLayer3;
146
147 StrictMock<mock::LayerFE> mLayer1FE;
148 StrictMock<mock::LayerFE> mLayer2FE;
149 StrictMock<mock::LayerFE> mLayer3FE;
150
151 LayerFECompositionState mLayer1FEState;
152 LayerFECompositionState mLayer2FEState;
153 LayerFECompositionState mLayer3FEState;
154};
155
Lloyd Piqueef958122019-02-05 18:00:12 -0800156const Rect OutputTest::kDefaultDisplaySize{100, 200};
157
Lloyd Pique17ca7422019-11-14 14:24:10 -0800158using ColorProfile = compositionengine::Output::ColorProfile;
159
160void dumpColorProfile(ColorProfile profile, std::string& result, const char* name) {
161 android::base::StringAppendF(&result, "%s (%s[%d] %s[%d] %s[%d] %s[%d]) ", name,
162 toString(profile.mode).c_str(), profile.mode,
163 toString(profile.dataspace).c_str(), profile.dataspace,
164 toString(profile.renderIntent).c_str(), profile.renderIntent,
165 toString(profile.colorSpaceAgnosticDataspace).c_str(),
166 profile.colorSpaceAgnosticDataspace);
167}
168
169// Checks for a ColorProfile match
170MATCHER_P(ColorProfileEq, expected, "") {
171 std::string buf;
172 buf.append("ColorProfiles are not equal\n");
173 dumpColorProfile(expected, buf, "expected value");
174 dumpColorProfile(arg, buf, "actual value");
175 *result_listener << buf;
176
177 return (expected.mode == arg.mode) && (expected.dataspace == arg.dataspace) &&
178 (expected.renderIntent == arg.renderIntent) &&
179 (expected.colorSpaceAgnosticDataspace == arg.colorSpaceAgnosticDataspace);
180}
181
Lloyd Pique66d68602019-02-13 14:23:31 -0800182/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700183 * Basic construction
184 */
185
Lloyd Pique31cb2942018-10-19 17:23:03 -0700186TEST_F(OutputTest, canInstantiateOutput) {
187 // The validation check checks each required component.
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700188 EXPECT_CALL(*mDisplayColorProfile, isValid()).WillOnce(Return(true));
Lloyd Pique31cb2942018-10-19 17:23:03 -0700189 EXPECT_CALL(*mRenderSurface, isValid()).WillOnce(Return(true));
190
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700191 EXPECT_TRUE(mOutput->isValid());
Lloyd Pique31cb2942018-10-19 17:23:03 -0700192
193 // If we take away the required components, it is no longer valid.
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700194 mOutput->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>());
Lloyd Pique31cb2942018-10-19 17:23:03 -0700195
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700196 EXPECT_CALL(*mDisplayColorProfile, isValid()).WillOnce(Return(true));
197
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700198 EXPECT_FALSE(mOutput->isValid());
Lloyd Pique31cb2942018-10-19 17:23:03 -0700199}
Lloyd Pique32cbe282018-10-19 13:09:22 -0700200
Lloyd Pique66d68602019-02-13 14:23:31 -0800201/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700202 * Output::setCompositionEnabled()
203 */
204
205TEST_F(OutputTest, setCompositionEnabledDoesNothingIfAlreadyEnabled) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700206 mOutput->editState().isEnabled = true;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700207
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700208 mOutput->setCompositionEnabled(true);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700209
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700210 EXPECT_TRUE(mOutput->getState().isEnabled);
211 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region()));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700212}
213
214TEST_F(OutputTest, setCompositionEnabledSetsEnabledAndDirtiesEntireOutput) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700215 mOutput->editState().isEnabled = false;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700216
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700217 mOutput->setCompositionEnabled(true);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700218
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700219 EXPECT_TRUE(mOutput->getState().isEnabled);
220 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700221}
222
223TEST_F(OutputTest, setCompositionEnabledSetsDisabledAndDirtiesEntireOutput) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700224 mOutput->editState().isEnabled = true;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700225
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700226 mOutput->setCompositionEnabled(false);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700227
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700228 EXPECT_FALSE(mOutput->getState().isEnabled);
229 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700230}
231
Lloyd Pique66d68602019-02-13 14:23:31 -0800232/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700233 * Output::setProjection()
234 */
235
236TEST_F(OutputTest, setProjectionTriviallyWorks) {
237 const ui::Transform transform{ui::Transform::ROT_180};
238 const int32_t orientation = 123;
239 const Rect frame{1, 2, 3, 4};
240 const Rect viewport{5, 6, 7, 8};
241 const Rect scissor{9, 10, 11, 12};
242 const bool needsFiltering = true;
243
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700244 mOutput->setProjection(transform, orientation, frame, viewport, scissor, needsFiltering);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700245
Lloyd Piqueea629282019-12-03 15:57:10 -0800246 EXPECT_THAT(mOutput->getState().transform, transform);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700247 EXPECT_EQ(orientation, mOutput->getState().orientation);
248 EXPECT_EQ(frame, mOutput->getState().frame);
249 EXPECT_EQ(viewport, mOutput->getState().viewport);
250 EXPECT_EQ(scissor, mOutput->getState().scissor);
251 EXPECT_EQ(needsFiltering, mOutput->getState().needsFiltering);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700252}
253
Lloyd Pique66d68602019-02-13 14:23:31 -0800254/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700255 * Output::setBounds()
256 */
257
258TEST_F(OutputTest, setBoundsSetsSizeAndDirtiesEntireOutput) {
Lloyd Piqueef958122019-02-05 18:00:12 -0800259 const ui::Size displaySize{200, 400};
Lloyd Pique31cb2942018-10-19 17:23:03 -0700260
261 EXPECT_CALL(*mRenderSurface, setDisplaySize(displaySize)).Times(1);
262 EXPECT_CALL(*mRenderSurface, getSize()).WillOnce(ReturnRef(displaySize));
263
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700264 mOutput->setBounds(displaySize);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700265
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700266 EXPECT_EQ(Rect(displaySize), mOutput->getState().bounds);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700267
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700268 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(Rect(displaySize))));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700269}
270
Lloyd Pique66d68602019-02-13 14:23:31 -0800271/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700272 * Output::setLayerStackFilter()
273 */
274
275TEST_F(OutputTest, setLayerStackFilterSetsFilterAndDirtiesEntireOutput) {
Lloyd Pique32cbe282018-10-19 13:09:22 -0700276 const uint32_t layerStack = 123u;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700277 mOutput->setLayerStackFilter(layerStack, true);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700278
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700279 EXPECT_TRUE(mOutput->getState().layerStackInternal);
280 EXPECT_EQ(layerStack, mOutput->getState().layerStackId);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700281
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700282 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700283}
284
Lloyd Pique66d68602019-02-13 14:23:31 -0800285/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700286 * Output::setColorTransform
287 */
288
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800289TEST_F(OutputTest, setColorTransformWithNoChangeFlaggedSkipsUpdates) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700290 mOutput->editState().colorTransformMatrix = kIdentity;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700291
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800292 // If no colorTransformMatrix is set the update should be skipped.
293 CompositionRefreshArgs refreshArgs;
294 refreshArgs.colorTransformMatrix = std::nullopt;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700295
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700296 mOutput->setColorTransform(refreshArgs);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700297
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800298 // The internal state should be unchanged
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700299 EXPECT_EQ(kIdentity, mOutput->getState().colorTransformMatrix);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800300
301 // No dirty region should be set
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700302 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region()));
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800303}
Lloyd Piqueef958122019-02-05 18:00:12 -0800304
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800305TEST_F(OutputTest, setColorTransformWithNoActualChangeSkipsUpdates) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700306 mOutput->editState().colorTransformMatrix = kIdentity;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700307
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800308 // Attempting to set the same colorTransformMatrix that is already set should
309 // also skip the update.
310 CompositionRefreshArgs refreshArgs;
311 refreshArgs.colorTransformMatrix = kIdentity;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700312
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700313 mOutput->setColorTransform(refreshArgs);
Lloyd Pique77f79a22019-04-29 15:55:40 -0700314
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800315 // The internal state should be unchanged
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700316 EXPECT_EQ(kIdentity, mOutput->getState().colorTransformMatrix);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800317
318 // No dirty region should be set
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700319 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region()));
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800320}
321
322TEST_F(OutputTest, setColorTransformPerformsUpdateToIdentity) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700323 mOutput->editState().colorTransformMatrix = kNonIdentityHalf;
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800324
325 // Setting a different colorTransformMatrix should perform the update.
326 CompositionRefreshArgs refreshArgs;
327 refreshArgs.colorTransformMatrix = kIdentity;
328
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700329 mOutput->setColorTransform(refreshArgs);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800330
331 // The internal state should have been updated
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700332 EXPECT_EQ(kIdentity, mOutput->getState().colorTransformMatrix);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800333
334 // The dirtyRegion should be set to the full display size
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700335 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800336}
Lloyd Pique77f79a22019-04-29 15:55:40 -0700337
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800338TEST_F(OutputTest, setColorTransformPerformsUpdateForIdentityToHalf) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700339 mOutput->editState().colorTransformMatrix = kIdentity;
Lloyd Pique77f79a22019-04-29 15:55:40 -0700340
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800341 // Setting a different colorTransformMatrix should perform the update.
342 CompositionRefreshArgs refreshArgs;
343 refreshArgs.colorTransformMatrix = kNonIdentityHalf;
Lloyd Pique77f79a22019-04-29 15:55:40 -0700344
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700345 mOutput->setColorTransform(refreshArgs);
Lloyd Piqueef958122019-02-05 18:00:12 -0800346
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800347 // The internal state should have been updated
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700348 EXPECT_EQ(kNonIdentityHalf, mOutput->getState().colorTransformMatrix);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800349
350 // The dirtyRegion should be set to the full display size
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700351 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800352}
353
354TEST_F(OutputTest, setColorTransformPerformsUpdateForHalfToQuarter) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700355 mOutput->editState().colorTransformMatrix = kNonIdentityHalf;
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800356
357 // Setting a different colorTransformMatrix should perform the update.
358 CompositionRefreshArgs refreshArgs;
359 refreshArgs.colorTransformMatrix = kNonIdentityQuarter;
360
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700361 mOutput->setColorTransform(refreshArgs);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800362
363 // The internal state should have been updated
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700364 EXPECT_EQ(kNonIdentityQuarter, mOutput->getState().colorTransformMatrix);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800365
366 // The dirtyRegion should be set to the full display size
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700367 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700368}
369
Lloyd Pique66d68602019-02-13 14:23:31 -0800370/*
Lloyd Pique17ca7422019-11-14 14:24:10 -0800371 * Output::setColorProfile
Lloyd Pique32cbe282018-10-19 13:09:22 -0700372 */
373
Lloyd Pique17ca7422019-11-14 14:24:10 -0800374using OutputSetColorProfileTest = OutputTest;
375
376TEST_F(OutputSetColorProfileTest, setsStateAndDirtiesOutputIfChanged) {
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800377 using ColorProfile = Output::ColorProfile;
378
Lloyd Piquef5275482019-01-29 18:42:42 -0800379 EXPECT_CALL(*mDisplayColorProfile,
380 getTargetDataspace(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
381 ui::Dataspace::UNKNOWN))
382 .WillOnce(Return(ui::Dataspace::UNKNOWN));
Lloyd Piqueef958122019-02-05 18:00:12 -0800383 EXPECT_CALL(*mRenderSurface, setBufferDataspace(ui::Dataspace::DISPLAY_P3)).Times(1);
Lloyd Pique31cb2942018-10-19 17:23:03 -0700384
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700385 mOutput->setColorProfile(ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
386 ui::RenderIntent::TONE_MAP_COLORIMETRIC,
387 ui::Dataspace::UNKNOWN});
Lloyd Pique32cbe282018-10-19 13:09:22 -0700388
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700389 EXPECT_EQ(ui::ColorMode::DISPLAY_P3, mOutput->getState().colorMode);
390 EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mOutput->getState().dataspace);
391 EXPECT_EQ(ui::RenderIntent::TONE_MAP_COLORIMETRIC, mOutput->getState().renderIntent);
392 EXPECT_EQ(ui::Dataspace::UNKNOWN, mOutput->getState().targetDataspace);
Lloyd Piquef5275482019-01-29 18:42:42 -0800393
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700394 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
Lloyd Piqueef958122019-02-05 18:00:12 -0800395}
396
Lloyd Pique17ca7422019-11-14 14:24:10 -0800397TEST_F(OutputSetColorProfileTest, doesNothingIfNoChange) {
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800398 using ColorProfile = Output::ColorProfile;
399
Lloyd Piquef5275482019-01-29 18:42:42 -0800400 EXPECT_CALL(*mDisplayColorProfile,
401 getTargetDataspace(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
402 ui::Dataspace::UNKNOWN))
403 .WillOnce(Return(ui::Dataspace::UNKNOWN));
404
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700405 mOutput->editState().colorMode = ui::ColorMode::DISPLAY_P3;
406 mOutput->editState().dataspace = ui::Dataspace::DISPLAY_P3;
407 mOutput->editState().renderIntent = ui::RenderIntent::TONE_MAP_COLORIMETRIC;
408 mOutput->editState().targetDataspace = ui::Dataspace::UNKNOWN;
Lloyd Piqueef958122019-02-05 18:00:12 -0800409
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700410 mOutput->setColorProfile(ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
411 ui::RenderIntent::TONE_MAP_COLORIMETRIC,
412 ui::Dataspace::UNKNOWN});
Lloyd Piqueef958122019-02-05 18:00:12 -0800413
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700414 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region()));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700415}
416
Lloyd Pique66d68602019-02-13 14:23:31 -0800417/*
Lloyd Pique31cb2942018-10-19 17:23:03 -0700418 * Output::setRenderSurface()
419 */
420
421TEST_F(OutputTest, setRenderSurfaceResetsBounds) {
422 const ui::Size newDisplaySize{640, 480};
423
424 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
425 EXPECT_CALL(*renderSurface, getSize()).WillOnce(ReturnRef(newDisplaySize));
426
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700427 mOutput->setRenderSurface(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Pique31cb2942018-10-19 17:23:03 -0700428
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700429 EXPECT_EQ(Rect(newDisplaySize), mOutput->getState().bounds);
Lloyd Pique31cb2942018-10-19 17:23:03 -0700430}
431
Lloyd Pique66d68602019-02-13 14:23:31 -0800432/*
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000433 * Output::getDirtyRegion()
Lloyd Pique32cbe282018-10-19 13:09:22 -0700434 */
435
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000436TEST_F(OutputTest, getDirtyRegionWithRepaintEverythingTrue) {
437 const Rect viewport{100, 200};
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700438 mOutput->editState().viewport = viewport;
439 mOutput->editState().dirtyRegion.set(50, 300);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700440
441 {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700442 Region result = mOutput->getDirtyRegion(true);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700443
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000444 EXPECT_THAT(result, RegionEq(Region(viewport)));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700445 }
446}
447
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000448TEST_F(OutputTest, getDirtyRegionWithRepaintEverythingFalse) {
449 const Rect viewport{100, 200};
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700450 mOutput->editState().viewport = viewport;
451 mOutput->editState().dirtyRegion.set(50, 300);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700452
453 {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700454 Region result = mOutput->getDirtyRegion(false);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700455
456 // The dirtyRegion should be clipped to the display bounds.
457 EXPECT_THAT(result, RegionEq(Region(Rect(50, 200))));
458 }
Lloyd Pique32cbe282018-10-19 13:09:22 -0700459}
460
Lloyd Pique66d68602019-02-13 14:23:31 -0800461/*
Lloyd Piqueef36b002019-01-23 17:52:04 -0800462 * Output::belongsInOutput()
463 */
464
465TEST_F(OutputTest, belongsInOutputFiltersAsExpected) {
466 const uint32_t layerStack1 = 123u;
467 const uint32_t layerStack2 = 456u;
468
469 // If the output accepts layerStack1 and internal-only layers....
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700470 mOutput->setLayerStackFilter(layerStack1, true);
Lloyd Piqueef36b002019-01-23 17:52:04 -0800471
Lloyd Piquec6687342019-03-07 21:34:57 -0800472 // A layer with no layerStack does not belong to it, internal-only or not.
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700473 EXPECT_FALSE(mOutput->belongsInOutput(std::nullopt, false));
474 EXPECT_FALSE(mOutput->belongsInOutput(std::nullopt, true));
Lloyd Piquec6687342019-03-07 21:34:57 -0800475
Lloyd Piqueef36b002019-01-23 17:52:04 -0800476 // Any layer with layerStack1 belongs to it, internal-only or not.
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700477 EXPECT_TRUE(mOutput->belongsInOutput(layerStack1, false));
478 EXPECT_TRUE(mOutput->belongsInOutput(layerStack1, true));
479 EXPECT_FALSE(mOutput->belongsInOutput(layerStack2, true));
480 EXPECT_FALSE(mOutput->belongsInOutput(layerStack2, false));
Lloyd Piqueef36b002019-01-23 17:52:04 -0800481
482 // If the output accepts layerStack21 but not internal-only layers...
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700483 mOutput->setLayerStackFilter(layerStack1, false);
Lloyd Piqueef36b002019-01-23 17:52:04 -0800484
485 // Only non-internal layers with layerStack1 belong to it.
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700486 EXPECT_TRUE(mOutput->belongsInOutput(layerStack1, false));
487 EXPECT_FALSE(mOutput->belongsInOutput(layerStack1, true));
488 EXPECT_FALSE(mOutput->belongsInOutput(layerStack2, true));
489 EXPECT_FALSE(mOutput->belongsInOutput(layerStack2, false));
Lloyd Piqueef36b002019-01-23 17:52:04 -0800490}
491
Lloyd Pique66c20c42019-03-07 21:44:02 -0800492TEST_F(OutputTest, belongsInOutputFiltersLayersAsExpected) {
493 StrictMock<mock::Layer> layer;
Lloyd Pique9755fb72019-03-26 14:44:40 -0700494 LayerFECompositionState layerFEState;
Lloyd Pique66c20c42019-03-07 21:44:02 -0800495
Lloyd Pique9755fb72019-03-26 14:44:40 -0700496 EXPECT_CALL(layer, getFEState()).WillRepeatedly(ReturnRef(layerFEState));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800497
498 const uint32_t layerStack1 = 123u;
499 const uint32_t layerStack2 = 456u;
500
501 // If the output accepts layerStack1 and internal-only layers....
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700502 mOutput->setLayerStackFilter(layerStack1, true);
Lloyd Pique66c20c42019-03-07 21:44:02 -0800503
504 // A null layer pointer does not belong to the output
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700505 EXPECT_FALSE(mOutput->belongsInOutput(nullptr));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800506
507 // A layer with no layerStack does not belong to it, internal-only or not.
Lloyd Pique9755fb72019-03-26 14:44:40 -0700508 layerFEState.layerStackId = std::nullopt;
509 layerFEState.internalOnly = false;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700510 EXPECT_FALSE(mOutput->belongsInOutput(&layer));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800511
Lloyd Pique9755fb72019-03-26 14:44:40 -0700512 layerFEState.layerStackId = std::nullopt;
513 layerFEState.internalOnly = true;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700514 EXPECT_FALSE(mOutput->belongsInOutput(&layer));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800515
516 // Any layer with layerStack1 belongs to it, internal-only or not.
Lloyd Pique9755fb72019-03-26 14:44:40 -0700517 layerFEState.layerStackId = layerStack1;
518 layerFEState.internalOnly = false;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700519 EXPECT_TRUE(mOutput->belongsInOutput(&layer));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800520
Lloyd Pique9755fb72019-03-26 14:44:40 -0700521 layerFEState.layerStackId = layerStack1;
522 layerFEState.internalOnly = true;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700523 EXPECT_TRUE(mOutput->belongsInOutput(&layer));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800524
Lloyd Pique9755fb72019-03-26 14:44:40 -0700525 layerFEState.layerStackId = layerStack2;
526 layerFEState.internalOnly = true;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700527 EXPECT_FALSE(mOutput->belongsInOutput(&layer));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800528
Lloyd Pique9755fb72019-03-26 14:44:40 -0700529 layerFEState.layerStackId = layerStack2;
530 layerFEState.internalOnly = false;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700531 EXPECT_FALSE(mOutput->belongsInOutput(&layer));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800532
533 // If the output accepts layerStack1 but not internal-only layers...
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700534 mOutput->setLayerStackFilter(layerStack1, false);
Lloyd Pique66c20c42019-03-07 21:44:02 -0800535
536 // A null layer pointer does not belong to the output
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700537 EXPECT_FALSE(mOutput->belongsInOutput(nullptr));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800538
539 // Only non-internal layers with layerStack1 belong to it.
Lloyd Pique9755fb72019-03-26 14:44:40 -0700540 layerFEState.layerStackId = layerStack1;
541 layerFEState.internalOnly = false;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700542 EXPECT_TRUE(mOutput->belongsInOutput(&layer));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800543
Lloyd Pique9755fb72019-03-26 14:44:40 -0700544 layerFEState.layerStackId = layerStack1;
545 layerFEState.internalOnly = true;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700546 EXPECT_FALSE(mOutput->belongsInOutput(&layer));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800547
Lloyd Pique9755fb72019-03-26 14:44:40 -0700548 layerFEState.layerStackId = layerStack2;
549 layerFEState.internalOnly = true;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700550 EXPECT_FALSE(mOutput->belongsInOutput(&layer));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800551
Lloyd Pique9755fb72019-03-26 14:44:40 -0700552 layerFEState.layerStackId = layerStack2;
553 layerFEState.internalOnly = false;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700554 EXPECT_FALSE(mOutput->belongsInOutput(&layer));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800555}
556
Lloyd Pique66d68602019-02-13 14:23:31 -0800557/*
Lloyd Piquecc01a452018-12-04 17:24:00 -0800558 * Output::getOutputLayerForLayer()
559 */
560
561TEST_F(OutputTest, getOutputLayerForLayerWorks) {
562 mock::OutputLayer* outputLayer1 = new StrictMock<mock::OutputLayer>();
563 mock::OutputLayer* outputLayer2 = new StrictMock<mock::OutputLayer>();
564
Lloyd Pique01c77c12019-04-17 12:48:32 -0700565 mOutput->injectOutputLayerForTest(std::unique_ptr<OutputLayer>(outputLayer1));
566 mOutput->injectOutputLayerForTest(nullptr);
567 mOutput->injectOutputLayerForTest(std::unique_ptr<OutputLayer>(outputLayer2));
Lloyd Piquecc01a452018-12-04 17:24:00 -0800568
569 StrictMock<mock::Layer> layer;
570 StrictMock<mock::Layer> otherLayer;
571
572 // If the input layer matches the first OutputLayer, it will be returned.
573 EXPECT_CALL(*outputLayer1, getLayer()).WillOnce(ReturnRef(layer));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700574 EXPECT_EQ(outputLayer1, mOutput->getOutputLayerForLayer(&layer));
Lloyd Piquecc01a452018-12-04 17:24:00 -0800575
576 // If the input layer matches the second OutputLayer, it will be returned.
577 EXPECT_CALL(*outputLayer1, getLayer()).WillOnce(ReturnRef(otherLayer));
578 EXPECT_CALL(*outputLayer2, getLayer()).WillOnce(ReturnRef(layer));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700579 EXPECT_EQ(outputLayer2, mOutput->getOutputLayerForLayer(&layer));
Lloyd Piquecc01a452018-12-04 17:24:00 -0800580
581 // If the input layer does not match an output layer, null will be returned.
582 EXPECT_CALL(*outputLayer1, getLayer()).WillOnce(ReturnRef(otherLayer));
583 EXPECT_CALL(*outputLayer2, getLayer()).WillOnce(ReturnRef(otherLayer));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700584 EXPECT_EQ(nullptr, mOutput->getOutputLayerForLayer(&layer));
Lloyd Piquecc01a452018-12-04 17:24:00 -0800585}
586
Lloyd Pique66d68602019-02-13 14:23:31 -0800587/*
Lloyd Piquec9e60032019-11-14 11:47:26 -0800588 * Output::setReleasedLayers()
589 */
590
591using OutputSetReleasedLayersTest = OutputTest;
592
593TEST_F(OutputSetReleasedLayersTest, setReleasedLayersTakesGivenLayers) {
594 sp<StrictMock<mock::LayerFE>> layer1FE{new StrictMock<mock::LayerFE>()};
595 sp<StrictMock<mock::LayerFE>> layer2FE{new StrictMock<mock::LayerFE>()};
596 sp<StrictMock<mock::LayerFE>> layer3FE{new StrictMock<mock::LayerFE>()};
597
598 Output::ReleasedLayers layers;
599 layers.push_back(layer1FE);
600 layers.push_back(layer2FE);
601 layers.push_back(layer3FE);
602
603 mOutput->setReleasedLayers(std::move(layers));
604
605 const auto& setLayers = mOutput->getReleasedLayersForTest();
606 ASSERT_EQ(3u, setLayers.size());
607 ASSERT_EQ(layer1FE.get(), setLayers[0].promote().get());
608 ASSERT_EQ(layer2FE.get(), setLayers[1].promote().get());
609 ASSERT_EQ(layer3FE.get(), setLayers[2].promote().get());
610}
611
612/*
Lloyd Piquec0ee6ba2019-11-14 12:55:53 -0800613 * Output::updateLayerStateFromFE()
614 */
615
616using OutputUpdateLayerStateFromFETest = OutputLatchFEStateTest;
617
618TEST_F(OutputUpdateLayerStateFromFETest, handlesNoOutputLayerCase) {
619 CompositionRefreshArgs refreshArgs;
620
621 mOutput->updateLayerStateFromFE(refreshArgs);
622}
623
624TEST_F(OutputUpdateLayerStateFromFETest, latchesContentStateForAllContainedLayers) {
625 EXPECT_CALL(mLayer1FE,
626 latchCompositionState(Ref(mLayer1FEState), LayerFE::StateSubset::Content));
627 EXPECT_CALL(mLayer2FE,
628 latchCompositionState(Ref(mLayer2FEState), LayerFE::StateSubset::Content));
629 EXPECT_CALL(mLayer3FE,
630 latchCompositionState(Ref(mLayer3FEState), LayerFE::StateSubset::Content));
631
632 // Note: Must be performed after any expectations on these mocks
633 injectLayer(std::move(mOutputLayer1));
634 injectLayer(std::move(mOutputLayer2));
635 injectLayer(std::move(mOutputLayer3));
636
637 CompositionRefreshArgs refreshArgs;
638 refreshArgs.updatingGeometryThisFrame = false;
639
640 mOutput->updateLayerStateFromFE(refreshArgs);
641}
642
643TEST_F(OutputUpdateLayerStateFromFETest, latchesGeometryAndContentStateForAllContainedLayers) {
644 EXPECT_CALL(mLayer1FE,
645 latchCompositionState(Ref(mLayer1FEState),
646 LayerFE::StateSubset::GeometryAndContent));
647 EXPECT_CALL(mLayer2FE,
648 latchCompositionState(Ref(mLayer2FEState),
649 LayerFE::StateSubset::GeometryAndContent));
650 EXPECT_CALL(mLayer3FE,
651 latchCompositionState(Ref(mLayer3FEState),
652 LayerFE::StateSubset::GeometryAndContent));
653
654 // Note: Must be performed after any expectations on these mocks
655 injectLayer(std::move(mOutputLayer1));
656 injectLayer(std::move(mOutputLayer2));
657 injectLayer(std::move(mOutputLayer3));
658
659 CompositionRefreshArgs refreshArgs;
660 refreshArgs.updatingGeometryThisFrame = true;
661
662 mOutput->updateLayerStateFromFE(refreshArgs);
663}
664
665/*
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800666 * Output::updateAndWriteCompositionState()
667 */
668
Lloyd Piqueef63b612019-11-14 13:19:56 -0800669using OutputUpdateAndWriteCompositionStateTest = OutputLatchFEStateTest;
670
671TEST_F(OutputUpdateAndWriteCompositionStateTest, doesNothingIfLayers) {
672 mOutput->editState().isEnabled = true;
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800673
674 CompositionRefreshArgs args;
675 mOutput->updateAndWriteCompositionState(args);
676}
677
Lloyd Piqueef63b612019-11-14 13:19:56 -0800678TEST_F(OutputUpdateAndWriteCompositionStateTest, doesNothingIfOutputNotEnabled) {
679 mOutput->editState().isEnabled = false;
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800680
Lloyd Piqueef63b612019-11-14 13:19:56 -0800681 injectLayer(std::move(mOutputLayer1));
682 injectLayer(std::move(mOutputLayer2));
683 injectLayer(std::move(mOutputLayer3));
684
685 CompositionRefreshArgs args;
686 mOutput->updateAndWriteCompositionState(args);
687}
688
689TEST_F(OutputUpdateAndWriteCompositionStateTest, updatesLayerContentForAllLayers) {
690 EXPECT_CALL(*mOutputLayer1, updateCompositionState(false, false));
691 EXPECT_CALL(*mOutputLayer1, writeStateToHWC(false));
692 EXPECT_CALL(*mOutputLayer2, updateCompositionState(false, false));
693 EXPECT_CALL(*mOutputLayer2, writeStateToHWC(false));
694 EXPECT_CALL(*mOutputLayer3, updateCompositionState(false, false));
695 EXPECT_CALL(*mOutputLayer3, writeStateToHWC(false));
696
697 injectLayer(std::move(mOutputLayer1));
698 injectLayer(std::move(mOutputLayer2));
699 injectLayer(std::move(mOutputLayer3));
700
701 mOutput->editState().isEnabled = true;
702
703 CompositionRefreshArgs args;
704 args.updatingGeometryThisFrame = false;
705 args.devOptForceClientComposition = false;
706 mOutput->updateAndWriteCompositionState(args);
707}
708
709TEST_F(OutputUpdateAndWriteCompositionStateTest, updatesLayerGeometryAndContentForAllLayers) {
710 EXPECT_CALL(*mOutputLayer1, updateCompositionState(true, false));
711 EXPECT_CALL(*mOutputLayer1, writeStateToHWC(true));
712 EXPECT_CALL(*mOutputLayer2, updateCompositionState(true, false));
713 EXPECT_CALL(*mOutputLayer2, writeStateToHWC(true));
714 EXPECT_CALL(*mOutputLayer3, updateCompositionState(true, false));
715 EXPECT_CALL(*mOutputLayer3, writeStateToHWC(true));
716
717 injectLayer(std::move(mOutputLayer1));
718 injectLayer(std::move(mOutputLayer2));
719 injectLayer(std::move(mOutputLayer3));
720
721 mOutput->editState().isEnabled = true;
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800722
723 CompositionRefreshArgs args;
724 args.updatingGeometryThisFrame = true;
Lloyd Piqueef63b612019-11-14 13:19:56 -0800725 args.devOptForceClientComposition = false;
726 mOutput->updateAndWriteCompositionState(args);
727}
728
729TEST_F(OutputUpdateAndWriteCompositionStateTest, forcesClientCompositionForAllLayers) {
730 EXPECT_CALL(*mOutputLayer1, updateCompositionState(false, true));
731 EXPECT_CALL(*mOutputLayer1, writeStateToHWC(false));
732 EXPECT_CALL(*mOutputLayer2, updateCompositionState(false, true));
733 EXPECT_CALL(*mOutputLayer2, writeStateToHWC(false));
734 EXPECT_CALL(*mOutputLayer3, updateCompositionState(false, true));
735 EXPECT_CALL(*mOutputLayer3, writeStateToHWC(false));
736
737 injectLayer(std::move(mOutputLayer1));
738 injectLayer(std::move(mOutputLayer2));
739 injectLayer(std::move(mOutputLayer3));
740
741 mOutput->editState().isEnabled = true;
742
743 CompositionRefreshArgs args;
744 args.updatingGeometryThisFrame = false;
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800745 args.devOptForceClientComposition = true;
746 mOutput->updateAndWriteCompositionState(args);
747}
748
749/*
Lloyd Pique66d68602019-02-13 14:23:31 -0800750 * Output::prepareFrame()
751 */
752
753struct OutputPrepareFrameTest : public testing::Test {
Lloyd Piquefaa3f192019-11-14 14:05:09 -0800754 struct OutputPartialMock : public OutputPartialMockBase {
Lloyd Pique739afaf2019-11-21 16:40:05 -0800755 // Sets up the helper functions called by the function under test to use
756 // mock implementations.
Lloyd Pique66d68602019-02-13 14:23:31 -0800757 MOCK_METHOD0(chooseCompositionStrategy, void());
758 };
759
760 OutputPrepareFrameTest() {
761 mOutput.setDisplayColorProfileForTest(
762 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
763 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
764 }
765
766 StrictMock<mock::CompositionEngine> mCompositionEngine;
767 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
768 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700769 StrictMock<OutputPartialMock> mOutput;
Lloyd Pique66d68602019-02-13 14:23:31 -0800770};
771
772TEST_F(OutputPrepareFrameTest, takesEarlyOutIfNotEnabled) {
773 mOutput.editState().isEnabled = false;
774
775 mOutput.prepareFrame();
776}
777
778TEST_F(OutputPrepareFrameTest, delegatesToChooseCompositionStrategyAndRenderSurface) {
779 mOutput.editState().isEnabled = true;
780 mOutput.editState().usesClientComposition = false;
781 mOutput.editState().usesDeviceComposition = true;
782
783 EXPECT_CALL(mOutput, chooseCompositionStrategy()).Times(1);
784 EXPECT_CALL(*mRenderSurface, prepareFrame(false, true));
785
786 mOutput.prepareFrame();
787}
788
789// Note: Use OutputTest and not OutputPrepareFrameTest, so the real
790// base chooseCompositionStrategy() is invoked.
791TEST_F(OutputTest, prepareFrameSetsClientCompositionOnlyByDefault) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700792 mOutput->editState().isEnabled = true;
793 mOutput->editState().usesClientComposition = false;
794 mOutput->editState().usesDeviceComposition = true;
Lloyd Pique66d68602019-02-13 14:23:31 -0800795
796 EXPECT_CALL(*mRenderSurface, prepareFrame(true, false));
797
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700798 mOutput->prepareFrame();
Lloyd Pique66d68602019-02-13 14:23:31 -0800799
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700800 EXPECT_TRUE(mOutput->getState().usesClientComposition);
801 EXPECT_FALSE(mOutput->getState().usesDeviceComposition);
Lloyd Pique66d68602019-02-13 14:23:31 -0800802}
803
Lloyd Pique56eba802019-08-28 15:45:25 -0700804/*
Lloyd Piqueb62cebc2019-11-20 18:31:52 -0800805 * Output::prepare()
806 */
807
808struct OutputPrepareTest : public testing::Test {
809 struct OutputPartialMock : public OutputPartialMockBase {
810 // Sets up the helper functions called by the function under test to use
811 // mock implementations.
812 MOCK_METHOD2(rebuildLayerStacks,
813 void(const compositionengine::CompositionRefreshArgs&,
814 compositionengine::LayerFESet&));
815 };
816
817 StrictMock<OutputPartialMock> mOutput;
818 CompositionRefreshArgs mRefreshArgs;
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -0800819 LayerFESet mGeomSnapshots;
Lloyd Piqueb62cebc2019-11-20 18:31:52 -0800820};
821
822TEST_F(OutputPrepareTest, justInvokesRebuildLayerStacks) {
823 InSequence seq;
824 EXPECT_CALL(mOutput, rebuildLayerStacks(Ref(mRefreshArgs), Ref(mGeomSnapshots)));
825
826 mOutput.prepare(mRefreshArgs, mGeomSnapshots);
827}
828
829/*
830 * Output::rebuildLayerStacks()
831 */
832
833struct OutputRebuildLayerStacksTest : public testing::Test {
834 struct OutputPartialMock : public OutputPartialMockBase {
835 // Sets up the helper functions called by the function under test to use
836 // mock implementations.
837 MOCK_METHOD2(collectVisibleLayers,
838 void(const compositionengine::CompositionRefreshArgs&,
839 compositionengine::Output::CoverageState&));
840 };
841
842 OutputRebuildLayerStacksTest() {
843 mOutput.mState.isEnabled = true;
844 mOutput.mState.transform = kIdentityTransform;
845 mOutput.mState.bounds = kOutputBounds;
846
847 mRefreshArgs.updatingOutputGeometryThisFrame = true;
848
849 mCoverageAboveCoveredLayersToSet = Region(Rect(0, 0, 10, 10));
850
851 EXPECT_CALL(mOutput, collectVisibleLayers(Ref(mRefreshArgs), _))
852 .WillRepeatedly(Invoke(this, &OutputRebuildLayerStacksTest::setTestCoverageValues));
853 }
854
855 void setTestCoverageValues(const CompositionRefreshArgs&,
856 compositionengine::Output::CoverageState& state) {
857 state.aboveCoveredLayers = mCoverageAboveCoveredLayersToSet;
858 state.aboveOpaqueLayers = mCoverageAboveOpaqueLayersToSet;
859 state.dirtyRegion = mCoverageDirtyRegionToSet;
860 }
861
862 static const ui::Transform kIdentityTransform;
863 static const ui::Transform kRotate90Transform;
864 static const Rect kOutputBounds;
865
866 StrictMock<OutputPartialMock> mOutput;
867 CompositionRefreshArgs mRefreshArgs;
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -0800868 LayerFESet mGeomSnapshots;
Lloyd Piqueb62cebc2019-11-20 18:31:52 -0800869 Region mCoverageAboveCoveredLayersToSet;
870 Region mCoverageAboveOpaqueLayersToSet;
871 Region mCoverageDirtyRegionToSet;
872};
873
874const ui::Transform OutputRebuildLayerStacksTest::kIdentityTransform{TR_IDENT, 1920, 1080};
875const ui::Transform OutputRebuildLayerStacksTest::kRotate90Transform{TR_ROT_90, 1920, 1080};
876const Rect OutputRebuildLayerStacksTest::kOutputBounds{0, 0, 1920, 1080};
877
878TEST_F(OutputRebuildLayerStacksTest, doesNothingIfNotEnabled) {
879 mOutput.mState.isEnabled = false;
880
881 mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
882}
883
884TEST_F(OutputRebuildLayerStacksTest, doesNothingIfNotUpdatingGeometryThisFrame) {
885 mRefreshArgs.updatingOutputGeometryThisFrame = false;
886
887 mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
888}
889
890TEST_F(OutputRebuildLayerStacksTest, computesUndefinedRegionWithNoRotationAndFullCoverage) {
891 mOutput.mState.transform = kIdentityTransform;
892
893 mCoverageAboveOpaqueLayersToSet = Region(Rect(0, 0, 1920, 1080));
894
895 mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
896
897 EXPECT_THAT(mOutput.mState.undefinedRegion, RegionEq(Region(Rect(0, 0, 0, 0))));
898}
899
900TEST_F(OutputRebuildLayerStacksTest, computesUndefinedRegionWithNoRotationAndPartialCoverage) {
901 mOutput.mState.transform = kIdentityTransform;
902
903 mCoverageAboveOpaqueLayersToSet = Region(Rect(0, 0, 960, 1080));
904
905 mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
906
907 EXPECT_THAT(mOutput.mState.undefinedRegion, RegionEq(Region(Rect(960, 0, 1920, 1080))));
908}
909
910TEST_F(OutputRebuildLayerStacksTest, computesUndefinedRegionWith90RotationAndFullCoverage) {
911 mOutput.mState.transform = kRotate90Transform;
912
913 mCoverageAboveOpaqueLayersToSet = Region(Rect(0, 0, 1080, 1920));
914
915 mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
916
917 EXPECT_THAT(mOutput.mState.undefinedRegion, RegionEq(Region(Rect(0, 0, 0, 0))));
918}
919
920TEST_F(OutputRebuildLayerStacksTest, computesUndefinedRegionWith90RotationAndPartialCoverage) {
921 mOutput.mState.transform = kRotate90Transform;
922
923 mCoverageAboveOpaqueLayersToSet = Region(Rect(0, 0, 1080, 960));
924
925 mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
926
927 EXPECT_THAT(mOutput.mState.undefinedRegion, RegionEq(Region(Rect(0, 0, 960, 1080))));
928}
929
930TEST_F(OutputRebuildLayerStacksTest, addsToDirtyRegionWithNoRotation) {
931 mOutput.mState.transform = kIdentityTransform;
932 mOutput.mState.dirtyRegion = Region(Rect(960, 0, 1920, 1080));
933
934 mCoverageDirtyRegionToSet = Region(Rect(0, 0, 960, 1080));
935
936 mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
937
938 EXPECT_THAT(mOutput.mState.dirtyRegion, RegionEq(Region(Rect(0, 0, 1920, 1080))));
939}
940
941TEST_F(OutputRebuildLayerStacksTest, addsToDirtyRegionWith90Rotation) {
942 mOutput.mState.transform = kRotate90Transform;
943 mOutput.mState.dirtyRegion = Region(Rect(0, 960, 1080, 1920));
944
945 mCoverageDirtyRegionToSet = Region(Rect(0, 0, 1080, 960));
946
947 mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
948
949 EXPECT_THAT(mOutput.mState.dirtyRegion, RegionEq(Region(Rect(0, 0, 1080, 1920))));
950}
951
952/*
953 * Output::collectVisibleLayers()
954 */
955
Lloyd Pique1ef93222019-11-21 16:41:53 -0800956struct OutputCollectVisibleLayersTest : public testing::Test {
957 struct OutputPartialMock : public OutputPartialMockBase {
958 // Sets up the helper functions called by the function under test to use
959 // mock implementations.
960 MOCK_METHOD2(ensureOutputLayerIfVisible,
961 void(std::shared_ptr<compositionengine::Layer>,
962 compositionengine::Output::CoverageState&));
963 MOCK_METHOD1(setReleasedLayers, void(const compositionengine::CompositionRefreshArgs&));
964 MOCK_METHOD0(finalizePendingOutputLayers, void());
965 };
966
967 struct Layer {
968 Layer() {
969 EXPECT_CALL(outputLayer, getState()).WillRepeatedly(ReturnRef(outputLayerState));
970 EXPECT_CALL(outputLayer, editState()).WillRepeatedly(ReturnRef(outputLayerState));
971 }
972
973 StrictMock<mock::OutputLayer> outputLayer;
974 std::shared_ptr<StrictMock<mock::Layer>> layer{new StrictMock<mock::Layer>()};
975 impl::OutputLayerCompositionState outputLayerState;
976 };
977
978 OutputCollectVisibleLayersTest() {
979 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(3));
980 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0))
981 .WillRepeatedly(Return(&mLayer1.outputLayer));
982 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1))
983 .WillRepeatedly(Return(&mLayer2.outputLayer));
984 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(2))
985 .WillRepeatedly(Return(&mLayer3.outputLayer));
986
987 mRefreshArgs.layers.push_back(mLayer1.layer);
988 mRefreshArgs.layers.push_back(mLayer2.layer);
989 mRefreshArgs.layers.push_back(mLayer3.layer);
990 }
991
992 StrictMock<OutputPartialMock> mOutput;
993 CompositionRefreshArgs mRefreshArgs;
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -0800994 LayerFESet mGeomSnapshots;
995 Output::CoverageState mCoverageState{mGeomSnapshots};
Lloyd Pique1ef93222019-11-21 16:41:53 -0800996 Layer mLayer1;
997 Layer mLayer2;
998 Layer mLayer3;
999};
1000
1001TEST_F(OutputCollectVisibleLayersTest, doesMinimalWorkIfNoLayers) {
1002 mRefreshArgs.layers.clear();
1003 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0));
1004
1005 EXPECT_CALL(mOutput, setReleasedLayers(Ref(mRefreshArgs)));
1006 EXPECT_CALL(mOutput, finalizePendingOutputLayers());
1007
1008 mOutput.collectVisibleLayers(mRefreshArgs, mCoverageState);
1009}
1010
1011TEST_F(OutputCollectVisibleLayersTest, processesCandidateLayersReversedAndSetsOutputLayerZ) {
1012 // Enforce a call order sequence for this test.
1013 InSequence seq;
1014
1015 // Layer coverage is evaluated from front to back!
1016 EXPECT_CALL(mOutput, ensureOutputLayerIfVisible(Eq(mLayer3.layer), Ref(mCoverageState)));
1017 EXPECT_CALL(mOutput, ensureOutputLayerIfVisible(Eq(mLayer2.layer), Ref(mCoverageState)));
1018 EXPECT_CALL(mOutput, ensureOutputLayerIfVisible(Eq(mLayer1.layer), Ref(mCoverageState)));
1019
1020 EXPECT_CALL(mOutput, setReleasedLayers(Ref(mRefreshArgs)));
1021 EXPECT_CALL(mOutput, finalizePendingOutputLayers());
1022
1023 mOutput.collectVisibleLayers(mRefreshArgs, mCoverageState);
1024
1025 // Ensure all output layers have been assigned a simple/flattened z-order.
1026 EXPECT_EQ(0u, mLayer1.outputLayerState.z);
1027 EXPECT_EQ(1u, mLayer2.outputLayerState.z);
1028 EXPECT_EQ(2u, mLayer3.outputLayerState.z);
1029}
Lloyd Piqueb62cebc2019-11-20 18:31:52 -08001030
1031/*
1032 * Output::ensureOutputLayerIfVisible()
1033 */
1034
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001035struct OutputEnsureOutputLayerIfVisibleTest : public testing::Test {
1036 struct OutputPartialMock : public OutputPartialMockBase {
1037 // Sets up the helper functions called by the function under test to use
1038 // mock implementations.
1039 MOCK_CONST_METHOD1(belongsInOutput, bool(const compositionengine::Layer*));
1040 MOCK_CONST_METHOD1(getOutputLayerOrderedByZByIndex, OutputLayer*(size_t));
1041 MOCK_METHOD3(ensureOutputLayer,
1042 compositionengine::OutputLayer*(
1043 std::optional<size_t>,
1044 const std::shared_ptr<compositionengine::Layer>&, const sp<LayerFE>&));
1045 };
1046
1047 OutputEnsureOutputLayerIfVisibleTest() {
1048 EXPECT_CALL(*mLayer, getLayerFE()).WillRepeatedly(Return(mLayerFE));
1049 EXPECT_CALL(*mLayer, getFEState()).WillRepeatedly(ReturnRef(mLayerFEState));
1050 EXPECT_CALL(*mLayer, editFEState()).WillRepeatedly(ReturnRef(mLayerFEState));
1051
1052 EXPECT_CALL(mOutput, belongsInOutput(mLayer.get())).WillRepeatedly(Return(true));
1053 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(1));
1054 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u))
1055 .WillRepeatedly(Return(&mOutputLayer));
1056
1057 EXPECT_CALL(mOutputLayer, getState()).WillRepeatedly(ReturnRef(mOutputLayerState));
1058 EXPECT_CALL(mOutputLayer, editState()).WillRepeatedly(ReturnRef(mOutputLayerState));
1059 EXPECT_CALL(mOutputLayer, getLayer()).WillRepeatedly(ReturnRef(*mLayer.get()));
1060
1061 mOutput.mState.bounds = Rect(0, 0, 200, 300);
1062 mOutput.mState.viewport = Rect(0, 0, 200, 300);
1063 mOutput.mState.transform = ui::Transform(TR_IDENT, 200, 300);
1064
1065 mLayerFEState.isVisible = true;
1066 mLayerFEState.isOpaque = true;
1067 mLayerFEState.contentDirty = true;
1068 mLayerFEState.geomLayerBounds = FloatRect{0, 0, 100, 200};
1069 mLayerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
1070 mLayerFEState.transparentRegionHint = Region(Rect(0, 0, 100, 100));
1071
1072 mOutputLayerState.visibleRegion = Region(Rect(0, 0, 50, 200));
1073 mOutputLayerState.coveredRegion = Region(Rect(50, 0, 100, 200));
1074
1075 mGeomSnapshots.insert(mLayerFE);
1076 }
1077
1078 static const Region kEmptyRegion;
1079 static const Region kFullBoundsNoRotation;
1080 static const Region kRightHalfBoundsNoRotation;
1081 static const Region kLowerHalfBoundsNoRotation;
1082 static const Region kFullBounds90Rotation;
1083
1084 StrictMock<OutputPartialMock> mOutput;
1085 LayerFESet mGeomSnapshots;
1086 Output::CoverageState mCoverageState{mGeomSnapshots};
1087
1088 std::shared_ptr<mock::Layer> mLayer{new StrictMock<mock::Layer>()};
1089 sp<StrictMock<mock::LayerFE>> mLayerFE{new StrictMock<mock::LayerFE>()};
1090 LayerFECompositionState mLayerFEState;
1091 mock::OutputLayer mOutputLayer;
1092 impl::OutputLayerCompositionState mOutputLayerState;
1093};
1094
1095const Region OutputEnsureOutputLayerIfVisibleTest::kEmptyRegion = Region(Rect(0, 0, 0, 0));
1096const Region OutputEnsureOutputLayerIfVisibleTest::kFullBoundsNoRotation =
1097 Region(Rect(0, 0, 100, 200));
1098const Region OutputEnsureOutputLayerIfVisibleTest::kRightHalfBoundsNoRotation =
1099 Region(Rect(0, 100, 100, 200));
1100const Region OutputEnsureOutputLayerIfVisibleTest::kLowerHalfBoundsNoRotation =
1101 Region(Rect(50, 0, 100, 200));
1102const Region OutputEnsureOutputLayerIfVisibleTest::kFullBounds90Rotation =
1103 Region(Rect(0, 0, 200, 100));
1104
1105TEST_F(OutputEnsureOutputLayerIfVisibleTest, doesNothingIfNoLayerFE) {
1106 EXPECT_CALL(*mLayer, getLayerFE).WillOnce(Return(sp<LayerFE>()));
1107
1108 mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState);
1109}
1110
1111TEST_F(OutputEnsureOutputLayerIfVisibleTest, performsGeomLatchBeforeCheckingIfLayerBelongs) {
1112 EXPECT_CALL(mOutput, belongsInOutput(mLayer.get())).WillOnce(Return(false));
1113 EXPECT_CALL(*mLayerFE.get(),
1114 latchCompositionState(Ref(mLayerFEState),
1115 compositionengine::LayerFE::StateSubset::BasicGeometry));
1116
1117 mGeomSnapshots.clear();
1118
1119 mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState);
1120}
1121
1122TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1123 skipsLatchIfAlreadyLatchedBeforeCheckingIfLayerBelongs) {
1124 EXPECT_CALL(mOutput, belongsInOutput(mLayer.get())).WillOnce(Return(false));
1125
1126 mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState);
1127}
1128
1129TEST_F(OutputEnsureOutputLayerIfVisibleTest, takesEarlyOutIfLayerNotVisible) {
1130 mLayerFEState.isVisible = false;
1131
1132 mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState);
1133}
1134
1135TEST_F(OutputEnsureOutputLayerIfVisibleTest, takesEarlyOutIfLayerHasEmptyVisibleRegion) {
1136 mLayerFEState.geomLayerBounds = FloatRect{0, 0, 0, 0};
1137
1138 mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState);
1139}
1140
1141TEST_F(OutputEnsureOutputLayerIfVisibleTest, takesNotSoEarlyOutifDrawRegionEmpty) {
1142 mOutput.mState.bounds = Rect(0, 0, 0, 0);
1143
1144 mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState);
1145}
1146
1147TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1148 handlesCreatingOutputLayerForOpaqueDirtyNotRotatedLayer) {
1149 mLayerFEState.isOpaque = true;
1150 mLayerFEState.contentDirty = true;
1151 mLayerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
1152
1153 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
1154 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer), Eq(mLayerFE)))
1155 .WillOnce(Return(&mOutputLayer));
1156
1157 mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState);
1158
1159 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1160 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1161 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
1162
1163 EXPECT_THAT(mOutputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1164 EXPECT_THAT(mOutputLayerState.visibleNonTransparentRegion, RegionEq(kFullBoundsNoRotation));
1165 EXPECT_THAT(mOutputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1166 EXPECT_THAT(mOutputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
1167}
1168
1169TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1170 handlesUpdatingOutputLayerForOpaqueDirtyNotRotatedLayer) {
1171 mLayerFEState.isOpaque = true;
1172 mLayerFEState.contentDirty = true;
1173 mLayerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
1174
1175 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer), Eq(mLayerFE)))
1176 .WillOnce(Return(&mOutputLayer));
1177
1178 mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState);
1179
1180 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1181 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1182 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
1183
1184 EXPECT_THAT(mOutputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1185 EXPECT_THAT(mOutputLayerState.visibleNonTransparentRegion, RegionEq(kFullBoundsNoRotation));
1186 EXPECT_THAT(mOutputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1187 EXPECT_THAT(mOutputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
1188}
1189
1190TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1191 handlesCreatingOutputLayerForTransparentDirtyNotRotatedLayer) {
1192 mLayerFEState.isOpaque = false;
1193 mLayerFEState.contentDirty = true;
1194 mLayerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
1195
1196 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
1197 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer), Eq(mLayerFE)))
1198 .WillOnce(Return(&mOutputLayer));
1199
1200 mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState);
1201
1202 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1203 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1204 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kEmptyRegion));
1205
1206 EXPECT_THAT(mOutputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1207 EXPECT_THAT(mOutputLayerState.visibleNonTransparentRegion,
1208 RegionEq(kRightHalfBoundsNoRotation));
1209 EXPECT_THAT(mOutputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1210 EXPECT_THAT(mOutputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
1211}
1212
1213TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1214 handlesUpdatingOutputLayerForTransparentDirtyNotRotatedLayer) {
1215 mLayerFEState.isOpaque = false;
1216 mLayerFEState.contentDirty = true;
1217 mLayerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
1218
1219 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer), Eq(mLayerFE)))
1220 .WillOnce(Return(&mOutputLayer));
1221
1222 mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState);
1223
1224 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1225 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1226 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kEmptyRegion));
1227
1228 EXPECT_THAT(mOutputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1229 EXPECT_THAT(mOutputLayerState.visibleNonTransparentRegion,
1230 RegionEq(kRightHalfBoundsNoRotation));
1231 EXPECT_THAT(mOutputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1232 EXPECT_THAT(mOutputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
1233}
1234
1235TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1236 handlesCreatingOutputLayerForOpaqueNonDirtyNotRotatedLayer) {
1237 mLayerFEState.isOpaque = true;
1238 mLayerFEState.contentDirty = false;
1239 mLayerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
1240
1241 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
1242 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer), Eq(mLayerFE)))
1243 .WillOnce(Return(&mOutputLayer));
1244
1245 mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState);
1246
1247 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1248 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1249 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
1250
1251 EXPECT_THAT(mOutputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1252 EXPECT_THAT(mOutputLayerState.visibleNonTransparentRegion, RegionEq(kFullBoundsNoRotation));
1253 EXPECT_THAT(mOutputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1254 EXPECT_THAT(mOutputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
1255}
1256
1257TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1258 handlesUpdatingOutputLayerForOpaqueNonDirtyNotRotatedLayer) {
1259 mLayerFEState.isOpaque = true;
1260 mLayerFEState.contentDirty = false;
1261 mLayerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
1262
1263 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer), Eq(mLayerFE)))
1264 .WillOnce(Return(&mOutputLayer));
1265
1266 mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState);
1267
1268 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kLowerHalfBoundsNoRotation));
1269 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1270 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
1271
1272 EXPECT_THAT(mOutputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1273 EXPECT_THAT(mOutputLayerState.visibleNonTransparentRegion, RegionEq(kFullBoundsNoRotation));
1274 EXPECT_THAT(mOutputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1275 EXPECT_THAT(mOutputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
1276}
1277
1278TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1279 handlesCreatingOutputLayerForOpaqueDirtyRotated90Layer) {
1280 mLayerFEState.isOpaque = true;
1281 mLayerFEState.contentDirty = true;
1282 mLayerFEState.geomLayerBounds = FloatRect{0, 0, 200, 100};
1283 mLayerFEState.geomLayerTransform = ui::Transform(TR_ROT_90, 100, 200);
1284 mOutputLayerState.visibleRegion = Region(Rect(0, 0, 100, 100));
1285 mOutputLayerState.coveredRegion = Region(Rect(100, 0, 200, 100));
1286
1287 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
1288 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer), Eq(mLayerFE)))
1289 .WillOnce(Return(&mOutputLayer));
1290
1291 mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState);
1292
1293 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1294 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1295 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
1296
1297 EXPECT_THAT(mOutputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1298 EXPECT_THAT(mOutputLayerState.visibleNonTransparentRegion, RegionEq(kFullBoundsNoRotation));
1299 EXPECT_THAT(mOutputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1300 EXPECT_THAT(mOutputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
1301}
1302
1303TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1304 handlesUpdatingOutputLayerForOpaqueDirtyRotated90Layer) {
1305 mLayerFEState.isOpaque = true;
1306 mLayerFEState.contentDirty = true;
1307 mLayerFEState.geomLayerBounds = FloatRect{0, 0, 200, 100};
1308 mLayerFEState.geomLayerTransform = ui::Transform(TR_ROT_90, 100, 200);
1309 mOutputLayerState.visibleRegion = Region(Rect(0, 0, 100, 100));
1310 mOutputLayerState.coveredRegion = Region(Rect(100, 0, 200, 100));
1311
1312 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer), Eq(mLayerFE)))
1313 .WillOnce(Return(&mOutputLayer));
1314
1315 mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState);
1316
1317 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1318 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1319 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
1320
1321 EXPECT_THAT(mOutputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1322 EXPECT_THAT(mOutputLayerState.visibleNonTransparentRegion, RegionEq(kFullBoundsNoRotation));
1323 EXPECT_THAT(mOutputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1324 EXPECT_THAT(mOutputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
1325}
1326
1327TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1328 handlesCreatingOutputLayerForOpaqueDirtyNotRotatedLayerRotatedOutput) {
1329 mLayerFEState.isOpaque = true;
1330 mLayerFEState.contentDirty = true;
1331 mLayerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
1332
1333 mOutput.mState.viewport = Rect(0, 0, 300, 200);
1334 mOutput.mState.transform = ui::Transform(TR_ROT_90, 200, 300);
1335
1336 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
1337 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer), Eq(mLayerFE)))
1338 .WillOnce(Return(&mOutputLayer));
1339
1340 mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState);
1341
1342 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1343 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1344 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
1345
1346 EXPECT_THAT(mOutputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1347 EXPECT_THAT(mOutputLayerState.visibleNonTransparentRegion, RegionEq(kFullBoundsNoRotation));
1348 EXPECT_THAT(mOutputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1349 EXPECT_THAT(mOutputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBounds90Rotation));
1350}
1351
1352TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1353 handlesUpdatingOutputLayerForOpaqueDirtyNotRotatedLayerRotatedOutput) {
1354 mLayerFEState.isOpaque = true;
1355 mLayerFEState.contentDirty = true;
1356 mLayerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
1357
1358 mOutput.mState.viewport = Rect(0, 0, 300, 200);
1359 mOutput.mState.transform = ui::Transform(TR_ROT_90, 200, 300);
1360
1361 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer), Eq(mLayerFE)))
1362 .WillOnce(Return(&mOutputLayer));
1363
1364 mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState);
1365
1366 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1367 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1368 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
1369
1370 EXPECT_THAT(mOutputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1371 EXPECT_THAT(mOutputLayerState.visibleNonTransparentRegion, RegionEq(kFullBoundsNoRotation));
1372 EXPECT_THAT(mOutputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1373 EXPECT_THAT(mOutputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBounds90Rotation));
1374}
1375
1376TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1377 handlesCreatingOutputLayerForOpaqueDirtyArbitraryTransformLayer) {
1378 ui::Transform arbitraryTransform;
1379 arbitraryTransform.set(1, 1, -1, 1);
1380 arbitraryTransform.set(0, 100);
1381
1382 mLayerFEState.isOpaque = true;
1383 mLayerFEState.contentDirty = true;
1384 mLayerFEState.geomLayerBounds = FloatRect{0, 0, 100, 200};
1385 mLayerFEState.geomLayerTransform = arbitraryTransform;
1386
1387 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
1388 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer), Eq(mLayerFE)))
1389 .WillOnce(Return(&mOutputLayer));
1390
1391 mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState);
1392
1393 const Region kRegion = Region(Rect(0, 0, 300, 300));
1394 const Region kRegionClipped = Region(Rect(0, 0, 200, 300));
1395
1396 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kRegion));
1397 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kRegion));
1398 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kEmptyRegion));
1399
1400 EXPECT_THAT(mOutputLayerState.visibleRegion, RegionEq(kRegion));
1401 EXPECT_THAT(mOutputLayerState.visibleNonTransparentRegion, RegionEq(kRegion));
1402 EXPECT_THAT(mOutputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1403 EXPECT_THAT(mOutputLayerState.outputSpaceVisibleRegion, RegionEq(kRegionClipped));
1404}
1405
1406TEST_F(OutputEnsureOutputLayerIfVisibleTest, coverageAccumulatesTest) {
1407 mLayerFEState.isOpaque = false;
1408 mLayerFEState.contentDirty = true;
1409 mLayerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
1410
1411 mCoverageState.dirtyRegion = Region(Rect(0, 0, 500, 500));
1412 mCoverageState.aboveCoveredLayers = Region(Rect(50, 0, 150, 200));
1413 mCoverageState.aboveOpaqueLayers = Region(Rect(50, 0, 150, 200));
1414
1415 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer), Eq(mLayerFE)))
1416 .WillOnce(Return(&mOutputLayer));
1417
1418 mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState);
1419
1420 const Region kExpectedDirtyRegion = Region(Rect(0, 0, 500, 500));
1421 const Region kExpectedAboveCoveredRegion = Region(Rect(0, 0, 150, 200));
1422 const Region kExpectedAboveOpaqueRegion = Region(Rect(50, 0, 150, 200));
1423 const Region kExpectedLayerVisibleRegion = Region(Rect(0, 0, 50, 200));
1424 const Region kExpectedLayerCoveredRegion = Region(Rect(50, 0, 100, 200));
1425 const Region kExpectedLayerVisibleNonTransparentRegion = Region(Rect(0, 100, 50, 200));
1426
1427 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kExpectedDirtyRegion));
1428 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kExpectedAboveCoveredRegion));
1429 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kExpectedAboveOpaqueRegion));
1430
1431 EXPECT_THAT(mOutputLayerState.visibleRegion, RegionEq(kExpectedLayerVisibleRegion));
1432 EXPECT_THAT(mOutputLayerState.visibleNonTransparentRegion,
1433 RegionEq(kExpectedLayerVisibleNonTransparentRegion));
1434 EXPECT_THAT(mOutputLayerState.coveredRegion, RegionEq(kExpectedLayerCoveredRegion));
1435 EXPECT_THAT(mOutputLayerState.outputSpaceVisibleRegion, RegionEq(kExpectedLayerVisibleRegion));
1436}
Lloyd Piqueb62cebc2019-11-20 18:31:52 -08001437
1438/*
Lloyd Piquefaa3f192019-11-14 14:05:09 -08001439 * Output::present()
1440 */
1441
1442struct OutputPresentTest : public testing::Test {
1443 struct OutputPartialMock : public OutputPartialMockBase {
Lloyd Pique739afaf2019-11-21 16:40:05 -08001444 // Sets up the helper functions called by the function under test to use
1445 // mock implementations.
Lloyd Piquefaa3f192019-11-14 14:05:09 -08001446 MOCK_METHOD1(updateColorProfile, void(const compositionengine::CompositionRefreshArgs&));
1447 MOCK_METHOD1(updateAndWriteCompositionState,
1448 void(const compositionengine::CompositionRefreshArgs&));
1449 MOCK_METHOD1(setColorTransform, void(const compositionengine::CompositionRefreshArgs&));
1450 MOCK_METHOD0(beginFrame, void());
1451 MOCK_METHOD0(prepareFrame, void());
1452 MOCK_METHOD1(devOptRepaintFlash, void(const compositionengine::CompositionRefreshArgs&));
1453 MOCK_METHOD1(finishFrame, void(const compositionengine::CompositionRefreshArgs&));
1454 MOCK_METHOD0(postFramebuffer, void());
1455 };
1456
1457 StrictMock<OutputPartialMock> mOutput;
1458};
1459
1460TEST_F(OutputPresentTest, justInvokesChildFunctionsInSequence) {
1461 CompositionRefreshArgs args;
1462
1463 InSequence seq;
1464 EXPECT_CALL(mOutput, updateColorProfile(Ref(args)));
1465 EXPECT_CALL(mOutput, updateAndWriteCompositionState(Ref(args)));
1466 EXPECT_CALL(mOutput, setColorTransform(Ref(args)));
1467 EXPECT_CALL(mOutput, beginFrame());
1468 EXPECT_CALL(mOutput, prepareFrame());
1469 EXPECT_CALL(mOutput, devOptRepaintFlash(Ref(args)));
1470 EXPECT_CALL(mOutput, finishFrame(Ref(args)));
1471 EXPECT_CALL(mOutput, postFramebuffer());
1472
1473 mOutput.present(args);
1474}
1475
1476/*
1477 * Output::updateColorProfile()
1478 */
1479
Lloyd Pique17ca7422019-11-14 14:24:10 -08001480struct OutputUpdateColorProfileTest : public testing::Test {
1481 using TestType = OutputUpdateColorProfileTest;
1482
1483 struct OutputPartialMock : public OutputPartialMockBase {
Lloyd Pique739afaf2019-11-21 16:40:05 -08001484 // Sets up the helper functions called by the function under test to use
1485 // mock implementations.
Lloyd Pique17ca7422019-11-14 14:24:10 -08001486 MOCK_METHOD1(setColorProfile, void(const ColorProfile&));
1487 };
1488
1489 struct Layer {
1490 Layer() {
1491 EXPECT_CALL(mOutputLayer, getLayer()).WillRepeatedly(ReturnRef(mLayer));
1492 EXPECT_CALL(mOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(mLayerFE));
1493 EXPECT_CALL(mLayer, getFEState()).WillRepeatedly(ReturnRef(mLayerFEState));
1494 }
1495
1496 StrictMock<mock::OutputLayer> mOutputLayer;
1497 StrictMock<mock::Layer> mLayer;
1498 StrictMock<mock::LayerFE> mLayerFE;
1499 LayerFECompositionState mLayerFEState;
1500 };
1501
1502 OutputUpdateColorProfileTest() {
1503 mOutput.setDisplayColorProfileForTest(
1504 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
1505 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
1506
1507 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0))
1508 .WillRepeatedly(Return(&mLayer1.mOutputLayer));
1509 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1))
1510 .WillRepeatedly(Return(&mLayer2.mOutputLayer));
1511 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(2))
1512 .WillRepeatedly(Return(&mLayer3.mOutputLayer));
1513 }
1514
1515 struct ExecuteState : public CallOrderStateMachineHelper<TestType, ExecuteState> {
1516 void execute() { getInstance()->mOutput.updateColorProfile(getInstance()->mRefreshArgs); }
1517 };
1518
1519 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
1520 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
1521 StrictMock<OutputPartialMock> mOutput;
1522
1523 Layer mLayer1;
1524 Layer mLayer2;
1525 Layer mLayer3;
1526
1527 CompositionRefreshArgs mRefreshArgs;
1528};
1529
1530// TODO(b/144522012): Refactor Output::updateColorProfile and the related code
1531// to make it easier to write unit tests.
1532
1533TEST_F(OutputUpdateColorProfileTest, setsAColorProfileWhenUnmanaged) {
1534 // When the outputColorSetting is set to kUnmanaged, the implementation sets
1535 // a simple default color profile without looking at anything else.
1536
1537 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(3));
1538 EXPECT_CALL(mOutput,
1539 setColorProfile(ColorProfileEq(
1540 ColorProfile{ui::ColorMode::NATIVE, ui::Dataspace::UNKNOWN,
1541 ui::RenderIntent::COLORIMETRIC, ui::Dataspace::UNKNOWN})));
1542
1543 mRefreshArgs.outputColorSetting = OutputColorSetting::kUnmanaged;
1544 mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN;
1545
1546 mOutput.updateColorProfile(mRefreshArgs);
1547}
1548
1549struct OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile
1550 : public OutputUpdateColorProfileTest {
1551 OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile() {
1552 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0));
1553 mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced;
1554 mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN;
1555 }
1556
1557 struct ExpectBestColorModeCallResultUsedToSetColorProfileState
1558 : public CallOrderStateMachineHelper<
1559 TestType, ExpectBestColorModeCallResultUsedToSetColorProfileState> {
1560 [[nodiscard]] auto expectBestColorModeCallResultUsedToSetColorProfile(
1561 ui::ColorMode colorMode, ui::Dataspace dataspace, ui::RenderIntent renderIntent) {
1562 EXPECT_CALL(*getInstance()->mDisplayColorProfile,
1563 getBestColorMode(ui::Dataspace::V0_SRGB, ui::RenderIntent::ENHANCE, _, _,
1564 _))
1565 .WillOnce(DoAll(SetArgPointee<2>(dataspace), SetArgPointee<3>(colorMode),
1566 SetArgPointee<4>(renderIntent)));
1567 EXPECT_CALL(getInstance()->mOutput,
1568 setColorProfile(
1569 ColorProfileEq(ColorProfile{colorMode, dataspace, renderIntent,
1570 ui::Dataspace::UNKNOWN})));
1571 return nextState<ExecuteState>();
1572 }
1573 };
1574
1575 // Call this member function to start using the mini-DSL defined above.
1576 [[nodiscard]] auto verify() {
1577 return ExpectBestColorModeCallResultUsedToSetColorProfileState::make(this);
1578 }
1579};
1580
1581TEST_F(OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile,
1582 Native_Unknown_Colorimetric_Set) {
1583 verify().expectBestColorModeCallResultUsedToSetColorProfile(ui::ColorMode::NATIVE,
1584 ui::Dataspace::UNKNOWN,
1585 ui::RenderIntent::COLORIMETRIC)
1586 .execute();
1587}
1588
1589TEST_F(OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile,
1590 DisplayP3_DisplayP3_Enhance_Set) {
1591 verify().expectBestColorModeCallResultUsedToSetColorProfile(ui::ColorMode::DISPLAY_P3,
1592 ui::Dataspace::DISPLAY_P3,
1593 ui::RenderIntent::ENHANCE)
1594 .execute();
1595}
1596
1597struct OutputUpdateColorProfileTest_ColorSpaceAgnosticeDataspaceAffectsSetColorProfile
1598 : public OutputUpdateColorProfileTest {
1599 OutputUpdateColorProfileTest_ColorSpaceAgnosticeDataspaceAffectsSetColorProfile() {
1600 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0));
1601 EXPECT_CALL(*mDisplayColorProfile,
1602 getBestColorMode(ui::Dataspace::V0_SRGB, ui::RenderIntent::ENHANCE, _, _, _))
1603 .WillRepeatedly(DoAll(SetArgPointee<2>(ui::Dataspace::UNKNOWN),
1604 SetArgPointee<3>(ui::ColorMode::NATIVE),
1605 SetArgPointee<4>(ui::RenderIntent::COLORIMETRIC)));
1606 mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced;
1607 }
1608
1609 struct IfColorSpaceAgnosticDataspaceSetToState
1610 : public CallOrderStateMachineHelper<TestType, IfColorSpaceAgnosticDataspaceSetToState> {
1611 [[nodiscard]] auto ifColorSpaceAgnosticDataspaceSetTo(ui::Dataspace dataspace) {
1612 getInstance()->mRefreshArgs.colorSpaceAgnosticDataspace = dataspace;
1613 return nextState<ThenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspaceState>();
1614 }
1615 };
1616
1617 struct ThenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspaceState
1618 : public CallOrderStateMachineHelper<
1619 TestType, ThenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspaceState> {
1620 [[nodiscard]] auto thenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspace(
1621 ui::Dataspace dataspace) {
1622 EXPECT_CALL(getInstance()->mOutput,
1623 setColorProfile(ColorProfileEq(
1624 ColorProfile{ui::ColorMode::NATIVE, ui::Dataspace::UNKNOWN,
1625 ui::RenderIntent::COLORIMETRIC, dataspace})));
1626 return nextState<ExecuteState>();
1627 }
1628 };
1629
1630 // Call this member function to start using the mini-DSL defined above.
1631 [[nodiscard]] auto verify() { return IfColorSpaceAgnosticDataspaceSetToState::make(this); }
1632};
1633
1634TEST_F(OutputUpdateColorProfileTest_ColorSpaceAgnosticeDataspaceAffectsSetColorProfile, DisplayP3) {
1635 verify().ifColorSpaceAgnosticDataspaceSetTo(ui::Dataspace::DISPLAY_P3)
1636 .thenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspace(ui::Dataspace::DISPLAY_P3)
1637 .execute();
1638}
1639
1640TEST_F(OutputUpdateColorProfileTest_ColorSpaceAgnosticeDataspaceAffectsSetColorProfile, V0_SRGB) {
1641 verify().ifColorSpaceAgnosticDataspaceSetTo(ui::Dataspace::V0_SRGB)
1642 .thenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspace(ui::Dataspace::V0_SRGB)
1643 .execute();
1644}
1645
1646struct OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference
1647 : public OutputUpdateColorProfileTest {
1648 // Internally the implementation looks through the dataspaces of all the
1649 // visible layers. The topmost one that also has an actual dataspace
1650 // preference set is used to drive subsequent choices.
1651
1652 OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference() {
1653 mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced;
1654 mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN;
1655
1656 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(3));
1657 EXPECT_CALL(mOutput, setColorProfile(_)).WillRepeatedly(Return());
1658 }
1659
1660 struct IfTopLayerDataspaceState
1661 : public CallOrderStateMachineHelper<TestType, IfTopLayerDataspaceState> {
1662 [[nodiscard]] auto ifTopLayerIs(ui::Dataspace dataspace) {
1663 getInstance()->mLayer3.mLayerFEState.dataspace = dataspace;
1664 return nextState<AndIfMiddleLayerDataspaceState>();
1665 }
1666 [[nodiscard]] auto ifTopLayerHasNoPreference() {
1667 return ifTopLayerIs(ui::Dataspace::UNKNOWN);
1668 }
1669 };
1670
1671 struct AndIfMiddleLayerDataspaceState
1672 : public CallOrderStateMachineHelper<TestType, AndIfMiddleLayerDataspaceState> {
1673 [[nodiscard]] auto andIfMiddleLayerIs(ui::Dataspace dataspace) {
1674 getInstance()->mLayer2.mLayerFEState.dataspace = dataspace;
1675 return nextState<AndIfBottomLayerDataspaceState>();
1676 }
1677 [[nodiscard]] auto andIfMiddleLayerHasNoPreference() {
1678 return andIfMiddleLayerIs(ui::Dataspace::UNKNOWN);
1679 }
1680 };
1681
1682 struct AndIfBottomLayerDataspaceState
1683 : public CallOrderStateMachineHelper<TestType, AndIfBottomLayerDataspaceState> {
1684 [[nodiscard]] auto andIfBottomLayerIs(ui::Dataspace dataspace) {
1685 getInstance()->mLayer1.mLayerFEState.dataspace = dataspace;
1686 return nextState<ThenExpectBestColorModeCallUsesState>();
1687 }
1688 [[nodiscard]] auto andIfBottomLayerHasNoPreference() {
1689 return andIfBottomLayerIs(ui::Dataspace::UNKNOWN);
1690 }
1691 };
1692
1693 struct ThenExpectBestColorModeCallUsesState
1694 : public CallOrderStateMachineHelper<TestType, ThenExpectBestColorModeCallUsesState> {
1695 [[nodiscard]] auto thenExpectBestColorModeCallUses(ui::Dataspace dataspace) {
1696 EXPECT_CALL(*getInstance()->mDisplayColorProfile,
1697 getBestColorMode(dataspace, _, _, _, _));
1698 return nextState<ExecuteState>();
1699 }
1700 };
1701
1702 // Call this member function to start using the mini-DSL defined above.
1703 [[nodiscard]] auto verify() { return IfTopLayerDataspaceState::make(this); }
1704};
1705
1706TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference,
1707 noStrongLayerPrefenceUses_V0_SRGB) {
1708 // If none of the layers indicate a preference, then V0_SRGB is the
1709 // preferred choice (subject to additional checks).
1710 verify().ifTopLayerHasNoPreference()
1711 .andIfMiddleLayerHasNoPreference()
1712 .andIfBottomLayerHasNoPreference()
1713 .thenExpectBestColorModeCallUses(ui::Dataspace::V0_SRGB)
1714 .execute();
1715}
1716
1717TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference,
1718 ifTopmostUses_DisplayP3_Then_DisplayP3_Chosen) {
1719 // If only the topmost layer has a preference, then that is what is chosen.
1720 verify().ifTopLayerIs(ui::Dataspace::DISPLAY_P3)
1721 .andIfMiddleLayerHasNoPreference()
1722 .andIfBottomLayerHasNoPreference()
1723 .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3)
1724 .execute();
1725}
1726
1727TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference,
1728 ifMiddleUses_DisplayP3_Then_DisplayP3_Chosen) {
1729 // If only the middle layer has a preference, that that is what is chosen.
1730 verify().ifTopLayerHasNoPreference()
1731 .andIfMiddleLayerIs(ui::Dataspace::DISPLAY_P3)
1732 .andIfBottomLayerHasNoPreference()
1733 .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3)
1734 .execute();
1735}
1736
1737TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference,
1738 ifBottomUses_DisplayP3_Then_DisplayP3_Chosen) {
1739 // If only the middle layer has a preference, that that is what is chosen.
1740 verify().ifTopLayerHasNoPreference()
1741 .andIfMiddleLayerHasNoPreference()
1742 .andIfBottomLayerIs(ui::Dataspace::DISPLAY_P3)
1743 .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3)
1744 .execute();
1745}
1746
1747TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference,
1748 ifTopUses_DisplayBT2020_AndBottomUses_DisplayP3_Then_DisplayBT2020_Chosen) {
1749 // If multiple layers have a preference, the topmost value is what is used.
1750 verify().ifTopLayerIs(ui::Dataspace::DISPLAY_BT2020)
1751 .andIfMiddleLayerHasNoPreference()
1752 .andIfBottomLayerIs(ui::Dataspace::DISPLAY_P3)
1753 .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_BT2020)
1754 .execute();
1755}
1756
1757TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference,
1758 ifTopUses_DisplayP3_AndBottomUses_V0_SRGB_Then_DisplayP3_Chosen) {
1759 // If multiple layers have a preference, the topmost value is what is used.
1760 verify().ifTopLayerIs(ui::Dataspace::DISPLAY_P3)
1761 .andIfMiddleLayerHasNoPreference()
1762 .andIfBottomLayerIs(ui::Dataspace::DISPLAY_BT2020)
1763 .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3)
1764 .execute();
1765}
1766
1767struct OutputUpdateColorProfileTest_ForceOutputColorOverrides
1768 : public OutputUpdateColorProfileTest {
1769 // If CompositionRefreshArgs::forceOutputColorMode is set to some specific
1770 // values, it overrides the layer dataspace choice.
1771
1772 OutputUpdateColorProfileTest_ForceOutputColorOverrides() {
1773 mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced;
1774 mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN;
1775
1776 mLayer1.mLayerFEState.dataspace = ui::Dataspace::DISPLAY_BT2020;
1777
1778 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(1));
1779 EXPECT_CALL(mOutput, setColorProfile(_)).WillRepeatedly(Return());
1780 }
1781
1782 struct IfForceOutputColorModeState
1783 : public CallOrderStateMachineHelper<TestType, IfForceOutputColorModeState> {
1784 [[nodiscard]] auto ifForceOutputColorMode(ui::ColorMode colorMode) {
1785 getInstance()->mRefreshArgs.forceOutputColorMode = colorMode;
1786 return nextState<ThenExpectBestColorModeCallUsesState>();
1787 }
1788 [[nodiscard]] auto ifNoOverride() { return ifForceOutputColorMode(ui::ColorMode::NATIVE); }
1789 };
1790
1791 struct ThenExpectBestColorModeCallUsesState
1792 : public CallOrderStateMachineHelper<TestType, ThenExpectBestColorModeCallUsesState> {
1793 [[nodiscard]] auto thenExpectBestColorModeCallUses(ui::Dataspace dataspace) {
1794 EXPECT_CALL(*getInstance()->mDisplayColorProfile,
1795 getBestColorMode(dataspace, _, _, _, _));
1796 return nextState<ExecuteState>();
1797 }
1798 };
1799
1800 // Call this member function to start using the mini-DSL defined above.
1801 [[nodiscard]] auto verify() { return IfForceOutputColorModeState::make(this); }
1802};
1803
1804TEST_F(OutputUpdateColorProfileTest_ForceOutputColorOverrides, NoOverride_DoesNotOverride) {
1805 // By default the layer state is used to set the preferred dataspace
1806 verify().ifNoOverride()
1807 .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_BT2020)
1808 .execute();
1809}
1810
1811TEST_F(OutputUpdateColorProfileTest_ForceOutputColorOverrides, SRGB_Override_USES_V0_SRGB) {
1812 // Setting ui::ColorMode::SRGB overrides it with ui::Dataspace::V0_SRGB
1813 verify().ifForceOutputColorMode(ui::ColorMode::SRGB)
1814 .thenExpectBestColorModeCallUses(ui::Dataspace::V0_SRGB)
1815 .execute();
1816}
1817
1818TEST_F(OutputUpdateColorProfileTest_ForceOutputColorOverrides, DisplayP3_Override_Uses_DisplayP3) {
1819 // Setting ui::ColorMode::DISPLAY_P3 overrides it with ui::Dataspace::DISPLAY_P3
1820 verify().ifForceOutputColorMode(ui::ColorMode::DISPLAY_P3)
1821 .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3)
1822 .execute();
1823}
1824
1825// HDR output requires all layers to be compatible with the chosen HDR
1826// dataspace, along with there being proper support.
1827struct OutputUpdateColorProfileTest_Hdr : public OutputUpdateColorProfileTest {
1828 OutputUpdateColorProfileTest_Hdr() {
1829 mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced;
1830 mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN;
1831 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2));
1832 EXPECT_CALL(mOutput, setColorProfile(_)).WillRepeatedly(Return());
1833 }
1834
1835 static constexpr ui::Dataspace kNonHdrDataspace = ui::Dataspace::DISPLAY_P3;
1836 static constexpr ui::Dataspace BT2020_PQ = ui::Dataspace::BT2020_PQ;
1837 static constexpr ui::Dataspace BT2020_HLG = ui::Dataspace::BT2020_HLG;
1838 static constexpr ui::Dataspace DISPLAY_P3 = ui::Dataspace::DISPLAY_P3;
1839
1840 struct IfTopLayerDataspaceState
1841 : public CallOrderStateMachineHelper<TestType, IfTopLayerDataspaceState> {
1842 [[nodiscard]] auto ifTopLayerIs(ui::Dataspace dataspace) {
1843 getInstance()->mLayer2.mLayerFEState.dataspace = dataspace;
1844 return nextState<AndTopLayerCompositionTypeState>();
1845 }
1846 [[nodiscard]] auto ifTopLayerIsNotHdr() { return ifTopLayerIs(kNonHdrDataspace); }
1847 };
1848
1849 struct AndTopLayerCompositionTypeState
1850 : public CallOrderStateMachineHelper<TestType, AndTopLayerCompositionTypeState> {
1851 [[nodiscard]] auto andTopLayerIsREComposed(bool renderEngineComposed) {
1852 getInstance()->mLayer2.mLayerFEState.forceClientComposition = renderEngineComposed;
1853 return nextState<AndIfBottomLayerDataspaceState>();
1854 }
1855 };
1856
1857 struct AndIfBottomLayerDataspaceState
1858 : public CallOrderStateMachineHelper<TestType, AndIfBottomLayerDataspaceState> {
1859 [[nodiscard]] auto andIfBottomLayerIs(ui::Dataspace dataspace) {
1860 getInstance()->mLayer1.mLayerFEState.dataspace = dataspace;
1861 return nextState<AndBottomLayerCompositionTypeState>();
1862 }
1863 [[nodiscard]] auto andIfBottomLayerIsNotHdr() {
1864 return andIfBottomLayerIs(kNonHdrDataspace);
1865 }
1866 };
1867
1868 struct AndBottomLayerCompositionTypeState
1869 : public CallOrderStateMachineHelper<TestType, AndBottomLayerCompositionTypeState> {
1870 [[nodiscard]] auto andBottomLayerIsREComposed(bool renderEngineComposed) {
1871 getInstance()->mLayer1.mLayerFEState.forceClientComposition = renderEngineComposed;
1872 return nextState<AndIfHasLegacySupportState>();
1873 }
1874 };
1875
1876 struct AndIfHasLegacySupportState
1877 : public CallOrderStateMachineHelper<TestType, AndIfHasLegacySupportState> {
1878 [[nodiscard]] auto andIfLegacySupportFor(ui::Dataspace dataspace, bool legacySupport) {
1879 EXPECT_CALL(*getInstance()->mDisplayColorProfile, hasLegacyHdrSupport(dataspace))
1880 .WillOnce(Return(legacySupport));
1881 return nextState<ThenExpectBestColorModeCallUsesState>();
1882 }
1883 };
1884
1885 struct ThenExpectBestColorModeCallUsesState
1886 : public CallOrderStateMachineHelper<TestType, ThenExpectBestColorModeCallUsesState> {
1887 [[nodiscard]] auto thenExpectBestColorModeCallUses(ui::Dataspace dataspace) {
1888 EXPECT_CALL(*getInstance()->mDisplayColorProfile,
1889 getBestColorMode(dataspace, _, _, _, _));
1890 return nextState<ExecuteState>();
1891 }
1892 };
1893
1894 // Call this member function to start using the mini-DSL defined above.
1895 [[nodiscard]] auto verify() { return IfTopLayerDataspaceState::make(this); }
1896};
1897
1898TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_PQ_HW_Uses_PQ) {
1899 // If all layers use BT2020_PQ, and there are no other special conditions,
1900 // BT2020_PQ is used.
1901 verify().ifTopLayerIs(BT2020_PQ)
1902 .andTopLayerIsREComposed(false)
1903 .andIfBottomLayerIs(BT2020_PQ)
1904 .andBottomLayerIsREComposed(false)
1905 .andIfLegacySupportFor(BT2020_PQ, false)
1906 .thenExpectBestColorModeCallUses(BT2020_PQ)
1907 .execute();
1908}
1909
1910TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_PQ_HW_IfPQHasLegacySupport_Uses_DisplayP3) {
1911 // BT2020_PQ is not used if there is only legacy support for it.
1912 verify().ifTopLayerIs(BT2020_PQ)
1913 .andTopLayerIsREComposed(false)
1914 .andIfBottomLayerIs(BT2020_PQ)
1915 .andBottomLayerIsREComposed(false)
1916 .andIfLegacySupportFor(BT2020_PQ, true)
1917 .thenExpectBestColorModeCallUses(DISPLAY_P3)
1918 .execute();
1919}
1920
1921TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_PQ_RE_Uses_PQ) {
1922 // BT2020_PQ is still used if the bottom layer is RenderEngine composed.
1923 verify().ifTopLayerIs(BT2020_PQ)
1924 .andTopLayerIsREComposed(false)
1925 .andIfBottomLayerIs(BT2020_PQ)
1926 .andBottomLayerIsREComposed(true)
1927 .andIfLegacySupportFor(BT2020_PQ, false)
1928 .thenExpectBestColorModeCallUses(BT2020_PQ)
1929 .execute();
1930}
1931
1932TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_RE_On_PQ_HW_Uses_DisplayP3) {
1933 // BT2020_PQ is not used if the top layer is RenderEngine composed.
1934 verify().ifTopLayerIs(BT2020_PQ)
1935 .andTopLayerIsREComposed(true)
1936 .andIfBottomLayerIs(BT2020_PQ)
1937 .andBottomLayerIsREComposed(false)
1938 .andIfLegacySupportFor(BT2020_PQ, false)
1939 .thenExpectBestColorModeCallUses(DISPLAY_P3)
1940 .execute();
1941}
1942
1943TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_HLG_HW_Uses_PQ) {
1944 // If there is mixed HLG/PQ use, and the topmost layer is PQ, then PQ is used if there
1945 // are no other special conditions.
1946 verify().ifTopLayerIs(BT2020_PQ)
1947 .andTopLayerIsREComposed(false)
1948 .andIfBottomLayerIs(BT2020_HLG)
1949 .andBottomLayerIsREComposed(false)
1950 .andIfLegacySupportFor(BT2020_PQ, false)
1951 .thenExpectBestColorModeCallUses(BT2020_PQ)
1952 .execute();
1953}
1954
1955TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_HLG_HW_IfPQHasLegacySupport_Uses_DisplayP3) {
1956 // BT2020_PQ is not used if there is only legacy support for it.
1957 verify().ifTopLayerIs(BT2020_PQ)
1958 .andTopLayerIsREComposed(false)
1959 .andIfBottomLayerIs(BT2020_HLG)
1960 .andBottomLayerIsREComposed(false)
1961 .andIfLegacySupportFor(BT2020_PQ, true)
1962 .thenExpectBestColorModeCallUses(DISPLAY_P3)
1963 .execute();
1964}
1965
1966TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_HLG_RE_Uses_PQ) {
1967 // BT2020_PQ is used if the bottom HLG layer is RenderEngine composed.
1968 verify().ifTopLayerIs(BT2020_PQ)
1969 .andTopLayerIsREComposed(false)
1970 .andIfBottomLayerIs(BT2020_HLG)
1971 .andBottomLayerIsREComposed(true)
1972 .andIfLegacySupportFor(BT2020_PQ, false)
1973 .thenExpectBestColorModeCallUses(BT2020_PQ)
1974 .execute();
1975}
1976
1977TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_RE_On_HLG_HW_Uses_DisplayP3) {
1978 // BT2020_PQ is not used if the top PQ layer is RenderEngine composed.
1979 verify().ifTopLayerIs(BT2020_PQ)
1980 .andTopLayerIsREComposed(true)
1981 .andIfBottomLayerIs(BT2020_HLG)
1982 .andBottomLayerIsREComposed(false)
1983 .andIfLegacySupportFor(BT2020_PQ, false)
1984 .thenExpectBestColorModeCallUses(DISPLAY_P3)
1985 .execute();
1986}
1987
1988TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_PQ_HW_Uses_PQ) {
1989 // If there is mixed HLG/PQ use, and the topmost layer is HLG, then PQ is
1990 // used if there are no other special conditions.
1991 verify().ifTopLayerIs(BT2020_HLG)
1992 .andTopLayerIsREComposed(false)
1993 .andIfBottomLayerIs(BT2020_PQ)
1994 .andBottomLayerIsREComposed(false)
1995 .andIfLegacySupportFor(BT2020_PQ, false)
1996 .thenExpectBestColorModeCallUses(BT2020_PQ)
1997 .execute();
1998}
1999
2000TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_PQ_HW_IfPQHasLegacySupport_Uses_DisplayP3) {
2001 // BT2020_PQ is not used if there is only legacy support for it.
2002 verify().ifTopLayerIs(BT2020_HLG)
2003 .andTopLayerIsREComposed(false)
2004 .andIfBottomLayerIs(BT2020_PQ)
2005 .andBottomLayerIsREComposed(false)
2006 .andIfLegacySupportFor(BT2020_PQ, true)
2007 .thenExpectBestColorModeCallUses(DISPLAY_P3)
2008 .execute();
2009}
2010
2011TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_PQ_RE_Uses_DisplayP3) {
2012 // BT2020_PQ is not used if the bottom PQ layer is RenderEngine composed.
2013 verify().ifTopLayerIs(BT2020_HLG)
2014 .andTopLayerIsREComposed(false)
2015 .andIfBottomLayerIs(BT2020_PQ)
2016 .andBottomLayerIsREComposed(true)
2017 .andIfLegacySupportFor(BT2020_PQ, false)
2018 .thenExpectBestColorModeCallUses(DISPLAY_P3)
2019 .execute();
2020}
2021
2022TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_RE_On_PQ_HW_Uses_PQ) {
2023 // BT2020_PQ is still used if the top HLG layer is RenderEngine composed.
2024 verify().ifTopLayerIs(BT2020_HLG)
2025 .andTopLayerIsREComposed(true)
2026 .andIfBottomLayerIs(BT2020_PQ)
2027 .andBottomLayerIsREComposed(false)
2028 .andIfLegacySupportFor(BT2020_PQ, false)
2029 .thenExpectBestColorModeCallUses(BT2020_PQ)
2030 .execute();
2031}
2032
2033TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_HLG_HW_Uses_HLG) {
2034 // If all layers use HLG then HLG is used if there are no other special
2035 // conditions.
2036 verify().ifTopLayerIs(BT2020_HLG)
2037 .andTopLayerIsREComposed(false)
2038 .andIfBottomLayerIs(BT2020_HLG)
2039 .andBottomLayerIsREComposed(false)
2040 .andIfLegacySupportFor(BT2020_HLG, false)
2041 .thenExpectBestColorModeCallUses(BT2020_HLG)
2042 .execute();
2043}
2044
2045TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_HLG_HW_IfPQHasLegacySupport_Uses_DisplayP3) {
2046 // BT2020_HLG is not used if there is legacy support for it.
2047 verify().ifTopLayerIs(BT2020_HLG)
2048 .andTopLayerIsREComposed(false)
2049 .andIfBottomLayerIs(BT2020_HLG)
2050 .andBottomLayerIsREComposed(false)
2051 .andIfLegacySupportFor(BT2020_HLG, true)
2052 .thenExpectBestColorModeCallUses(DISPLAY_P3)
2053 .execute();
2054}
2055
2056TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_HLG_RE_Uses_HLG) {
2057 // BT2020_HLG is used even if the bottom layer is client composed.
2058 verify().ifTopLayerIs(BT2020_HLG)
2059 .andTopLayerIsREComposed(false)
2060 .andIfBottomLayerIs(BT2020_HLG)
2061 .andBottomLayerIsREComposed(true)
2062 .andIfLegacySupportFor(BT2020_HLG, false)
2063 .thenExpectBestColorModeCallUses(BT2020_HLG)
2064 .execute();
2065}
2066
2067TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_RE_On_HLG_HW_Uses_HLG) {
2068 // BT2020_HLG is used even if the top layer is client composed.
2069 verify().ifTopLayerIs(BT2020_HLG)
2070 .andTopLayerIsREComposed(true)
2071 .andIfBottomLayerIs(BT2020_HLG)
2072 .andBottomLayerIsREComposed(false)
2073 .andIfLegacySupportFor(BT2020_HLG, false)
2074 .thenExpectBestColorModeCallUses(BT2020_HLG)
2075 .execute();
2076}
2077
2078TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_NonHdr_HW_Uses_PQ) {
2079 // Even if there are non-HDR layers present, BT2020_PQ can still be used.
2080 verify().ifTopLayerIs(BT2020_PQ)
2081 .andTopLayerIsREComposed(false)
2082 .andIfBottomLayerIsNotHdr()
2083 .andBottomLayerIsREComposed(false)
2084 .andIfLegacySupportFor(BT2020_PQ, false)
2085 .thenExpectBestColorModeCallUses(BT2020_PQ)
2086 .execute();
2087}
2088
2089TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_NonHdr_RE_Uses_HLG) {
2090 // If all layers use HLG then HLG is used if there are no other special
2091 // conditions.
2092 verify().ifTopLayerIs(BT2020_HLG)
2093 .andTopLayerIsREComposed(false)
2094 .andIfBottomLayerIsNotHdr()
2095 .andBottomLayerIsREComposed(true)
2096 .andIfLegacySupportFor(BT2020_HLG, false)
2097 .thenExpectBestColorModeCallUses(BT2020_HLG)
2098 .execute();
2099}
2100
2101struct OutputUpdateColorProfile_AffectsChosenRenderIntentTest
2102 : public OutputUpdateColorProfileTest {
2103 // The various values for CompositionRefreshArgs::outputColorSetting affect
2104 // the chosen renderIntent, along with whether the preferred dataspace is an
2105 // HDR dataspace or not.
2106
2107 OutputUpdateColorProfile_AffectsChosenRenderIntentTest() {
2108 mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced;
2109 mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN;
2110 mLayer1.mLayerFEState.dataspace = ui::Dataspace::BT2020_PQ;
2111 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(1));
2112 EXPECT_CALL(mOutput, setColorProfile(_)).WillRepeatedly(Return());
2113 EXPECT_CALL(*mDisplayColorProfile, hasLegacyHdrSupport(ui::Dataspace::BT2020_PQ))
2114 .WillRepeatedly(Return(false));
2115 }
2116
2117 // The tests here involve enough state and GMock setup that using a mini-DSL
2118 // makes the tests much more readable, and allows the test to focus more on
2119 // the intent than on some of the details.
2120
2121 static constexpr ui::Dataspace kNonHdrDataspace = ui::Dataspace::DISPLAY_P3;
2122 static constexpr ui::Dataspace kHdrDataspace = ui::Dataspace::BT2020_PQ;
2123
2124 struct IfDataspaceChosenState
2125 : public CallOrderStateMachineHelper<TestType, IfDataspaceChosenState> {
2126 [[nodiscard]] auto ifDataspaceChosenIs(ui::Dataspace dataspace) {
2127 getInstance()->mLayer1.mLayerFEState.dataspace = dataspace;
2128 return nextState<AndOutputColorSettingState>();
2129 }
2130 [[nodiscard]] auto ifDataspaceChosenIsNonHdr() {
2131 return ifDataspaceChosenIs(kNonHdrDataspace);
2132 }
2133 [[nodiscard]] auto ifDataspaceChosenIsHdr() { return ifDataspaceChosenIs(kHdrDataspace); }
2134 };
2135
2136 struct AndOutputColorSettingState
2137 : public CallOrderStateMachineHelper<TestType, AndOutputColorSettingState> {
2138 [[nodiscard]] auto andOutputColorSettingIs(OutputColorSetting setting) {
2139 getInstance()->mRefreshArgs.outputColorSetting = setting;
2140 return nextState<ThenExpectBestColorModeCallUsesState>();
2141 }
2142 };
2143
2144 struct ThenExpectBestColorModeCallUsesState
2145 : public CallOrderStateMachineHelper<TestType, ThenExpectBestColorModeCallUsesState> {
2146 [[nodiscard]] auto thenExpectBestColorModeCallUses(ui::RenderIntent intent) {
2147 EXPECT_CALL(*getInstance()->mDisplayColorProfile,
2148 getBestColorMode(getInstance()->mLayer1.mLayerFEState.dataspace, intent, _,
2149 _, _));
2150 return nextState<ExecuteState>();
2151 }
2152 };
2153
2154 // Tests call one of these two helper member functions to start using the
2155 // mini-DSL defined above.
2156 [[nodiscard]] auto verify() { return IfDataspaceChosenState::make(this); }
2157};
2158
2159TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest,
2160 Managed_NonHdr_Prefers_Colorimetric) {
2161 verify().ifDataspaceChosenIsNonHdr()
2162 .andOutputColorSettingIs(OutputColorSetting::kManaged)
2163 .thenExpectBestColorModeCallUses(ui::RenderIntent::COLORIMETRIC)
2164 .execute();
2165}
2166
2167TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest,
2168 Managed_Hdr_Prefers_ToneMapColorimetric) {
2169 verify().ifDataspaceChosenIsHdr()
2170 .andOutputColorSettingIs(OutputColorSetting::kManaged)
2171 .thenExpectBestColorModeCallUses(ui::RenderIntent::TONE_MAP_COLORIMETRIC)
2172 .execute();
2173}
2174
2175TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest, Enhanced_NonHdr_Prefers_Enhance) {
2176 verify().ifDataspaceChosenIsNonHdr()
2177 .andOutputColorSettingIs(OutputColorSetting::kEnhanced)
2178 .thenExpectBestColorModeCallUses(ui::RenderIntent::ENHANCE)
2179 .execute();
2180}
2181
2182TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest,
2183 Enhanced_Hdr_Prefers_ToneMapEnhance) {
2184 verify().ifDataspaceChosenIsHdr()
2185 .andOutputColorSettingIs(OutputColorSetting::kEnhanced)
2186 .thenExpectBestColorModeCallUses(ui::RenderIntent::TONE_MAP_ENHANCE)
2187 .execute();
2188}
2189
2190TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest, Vendor_NonHdr_Prefers_Vendor) {
2191 verify().ifDataspaceChosenIsNonHdr()
2192 .andOutputColorSettingIs(kVendorSpecifiedOutputColorSetting)
2193 .thenExpectBestColorModeCallUses(
2194 static_cast<ui::RenderIntent>(kVendorSpecifiedOutputColorSetting))
2195 .execute();
2196}
2197
2198TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest, Vendor_Hdr_Prefers_Vendor) {
2199 verify().ifDataspaceChosenIsHdr()
2200 .andOutputColorSettingIs(kVendorSpecifiedOutputColorSetting)
2201 .thenExpectBestColorModeCallUses(
2202 static_cast<ui::RenderIntent>(kVendorSpecifiedOutputColorSetting))
2203 .execute();
2204}
Lloyd Piquefaa3f192019-11-14 14:05:09 -08002205
2206/*
2207 * Output::beginFrame()
2208 */
2209
Lloyd Piquee5965952019-11-18 16:16:32 -08002210struct OutputBeginFrameTest : public ::testing::Test {
2211 using TestType = OutputBeginFrameTest;
2212
2213 struct OutputPartialMock : public OutputPartialMockBase {
Lloyd Pique739afaf2019-11-21 16:40:05 -08002214 // Sets up the helper functions called by the function under test to use
2215 // mock implementations.
Lloyd Piquee5965952019-11-18 16:16:32 -08002216 MOCK_CONST_METHOD1(getDirtyRegion, Region(bool));
2217 };
2218
2219 OutputBeginFrameTest() {
2220 mOutput.setDisplayColorProfileForTest(
2221 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
2222 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
2223 }
2224
2225 struct IfGetDirtyRegionExpectationState
2226 : public CallOrderStateMachineHelper<TestType, IfGetDirtyRegionExpectationState> {
2227 [[nodiscard]] auto ifGetDirtyRegionReturns(Region dirtyRegion) {
2228 EXPECT_CALL(getInstance()->mOutput, getDirtyRegion(false))
2229 .WillOnce(Return(dirtyRegion));
2230 return nextState<AndIfGetOutputLayerCountExpectationState>();
2231 }
2232 };
2233
2234 struct AndIfGetOutputLayerCountExpectationState
2235 : public CallOrderStateMachineHelper<TestType, AndIfGetOutputLayerCountExpectationState> {
2236 [[nodiscard]] auto andIfGetOutputLayerCountReturns(size_t layerCount) {
2237 EXPECT_CALL(getInstance()->mOutput, getOutputLayerCount()).WillOnce(Return(layerCount));
2238 return nextState<AndIfLastCompositionHadVisibleLayersState>();
2239 }
2240 };
2241
2242 struct AndIfLastCompositionHadVisibleLayersState
2243 : public CallOrderStateMachineHelper<TestType,
2244 AndIfLastCompositionHadVisibleLayersState> {
2245 [[nodiscard]] auto andIfLastCompositionHadVisibleLayersIs(bool hadOutputLayers) {
2246 getInstance()->mOutput.mState.lastCompositionHadVisibleLayers = hadOutputLayers;
2247 return nextState<ThenExpectRenderSurfaceBeginFrameCallState>();
2248 }
2249 };
2250
2251 struct ThenExpectRenderSurfaceBeginFrameCallState
2252 : public CallOrderStateMachineHelper<TestType,
2253 ThenExpectRenderSurfaceBeginFrameCallState> {
2254 [[nodiscard]] auto thenExpectRenderSurfaceBeginFrameCall(bool mustRecompose) {
2255 EXPECT_CALL(*getInstance()->mRenderSurface, beginFrame(mustRecompose));
2256 return nextState<ExecuteState>();
2257 }
2258 };
2259
2260 struct ExecuteState : public CallOrderStateMachineHelper<TestType, ExecuteState> {
2261 [[nodiscard]] auto execute() {
2262 getInstance()->mOutput.beginFrame();
2263 return nextState<CheckPostconditionHadVisibleLayersState>();
2264 }
2265 };
2266
2267 struct CheckPostconditionHadVisibleLayersState
2268 : public CallOrderStateMachineHelper<TestType, CheckPostconditionHadVisibleLayersState> {
2269 void checkPostconditionHadVisibleLayers(bool expected) {
2270 EXPECT_EQ(expected, getInstance()->mOutput.mState.lastCompositionHadVisibleLayers);
2271 }
2272 };
2273
2274 // Tests call one of these two helper member functions to start using the
2275 // mini-DSL defined above.
2276 [[nodiscard]] auto verify() { return IfGetDirtyRegionExpectationState::make(this); }
2277
2278 static const Region kEmptyRegion;
2279 static const Region kNotEmptyRegion;
2280
2281 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
2282 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
2283 StrictMock<OutputPartialMock> mOutput;
2284};
2285
2286const Region OutputBeginFrameTest::kEmptyRegion{Rect{0, 0, 0, 0}};
2287const Region OutputBeginFrameTest::kNotEmptyRegion{Rect{0, 0, 1, 1}};
2288
2289TEST_F(OutputBeginFrameTest, hasDirtyHasLayersHadLayersLastFrame) {
2290 verify().ifGetDirtyRegionReturns(kNotEmptyRegion)
2291 .andIfGetOutputLayerCountReturns(1u)
2292 .andIfLastCompositionHadVisibleLayersIs(true)
2293 .thenExpectRenderSurfaceBeginFrameCall(true)
2294 .execute()
2295 .checkPostconditionHadVisibleLayers(true);
2296}
2297
2298TEST_F(OutputBeginFrameTest, hasDirtyNotHasLayersHadLayersLastFrame) {
2299 verify().ifGetDirtyRegionReturns(kNotEmptyRegion)
2300 .andIfGetOutputLayerCountReturns(0u)
2301 .andIfLastCompositionHadVisibleLayersIs(true)
2302 .thenExpectRenderSurfaceBeginFrameCall(true)
2303 .execute()
2304 .checkPostconditionHadVisibleLayers(false);
2305}
2306
2307TEST_F(OutputBeginFrameTest, hasDirtyHasLayersNotHadLayersLastFrame) {
2308 verify().ifGetDirtyRegionReturns(kNotEmptyRegion)
2309 .andIfGetOutputLayerCountReturns(1u)
2310 .andIfLastCompositionHadVisibleLayersIs(false)
2311 .thenExpectRenderSurfaceBeginFrameCall(true)
2312 .execute()
2313 .checkPostconditionHadVisibleLayers(true);
2314}
2315
2316TEST_F(OutputBeginFrameTest, hasDirtyNotHasLayersNotHadLayersLastFrame) {
2317 verify().ifGetDirtyRegionReturns(kNotEmptyRegion)
2318 .andIfGetOutputLayerCountReturns(0u)
2319 .andIfLastCompositionHadVisibleLayersIs(false)
2320 .thenExpectRenderSurfaceBeginFrameCall(false)
2321 .execute()
2322 .checkPostconditionHadVisibleLayers(false);
2323}
2324
2325TEST_F(OutputBeginFrameTest, notHasDirtyHasLayersHadLayersLastFrame) {
2326 verify().ifGetDirtyRegionReturns(kEmptyRegion)
2327 .andIfGetOutputLayerCountReturns(1u)
2328 .andIfLastCompositionHadVisibleLayersIs(true)
2329 .thenExpectRenderSurfaceBeginFrameCall(false)
2330 .execute()
2331 .checkPostconditionHadVisibleLayers(true);
2332}
2333
2334TEST_F(OutputBeginFrameTest, notHasDirtyNotHasLayersHadLayersLastFrame) {
2335 verify().ifGetDirtyRegionReturns(kEmptyRegion)
2336 .andIfGetOutputLayerCountReturns(0u)
2337 .andIfLastCompositionHadVisibleLayersIs(true)
2338 .thenExpectRenderSurfaceBeginFrameCall(false)
2339 .execute()
2340 .checkPostconditionHadVisibleLayers(true);
2341}
2342
2343TEST_F(OutputBeginFrameTest, notHasDirtyHasLayersNotHadLayersLastFrame) {
2344 verify().ifGetDirtyRegionReturns(kEmptyRegion)
2345 .andIfGetOutputLayerCountReturns(1u)
2346 .andIfLastCompositionHadVisibleLayersIs(false)
2347 .thenExpectRenderSurfaceBeginFrameCall(false)
2348 .execute()
2349 .checkPostconditionHadVisibleLayers(false);
2350}
2351
2352TEST_F(OutputBeginFrameTest, notHasDirtyNotHasLayersNotHadLayersLastFrame) {
2353 verify().ifGetDirtyRegionReturns(kEmptyRegion)
2354 .andIfGetOutputLayerCountReturns(0u)
2355 .andIfLastCompositionHadVisibleLayersIs(false)
2356 .thenExpectRenderSurfaceBeginFrameCall(false)
2357 .execute()
2358 .checkPostconditionHadVisibleLayers(false);
2359}
2360
Lloyd Piquefaa3f192019-11-14 14:05:09 -08002361/*
2362 * Output::devOptRepaintFlash()
2363 */
2364
Lloyd Piquedb462d82019-11-19 17:58:46 -08002365struct OutputDevOptRepaintFlashTest : public testing::Test {
2366 struct OutputPartialMock : public OutputPartialMockBase {
Lloyd Pique739afaf2019-11-21 16:40:05 -08002367 // Sets up the helper functions called by the function under test to use
2368 // mock implementations.
Lloyd Piquedb462d82019-11-19 17:58:46 -08002369 MOCK_CONST_METHOD1(getDirtyRegion, Region(bool));
2370 MOCK_METHOD1(composeSurfaces, std::optional<base::unique_fd>(const Region&));
2371 MOCK_METHOD0(postFramebuffer, void());
2372 MOCK_METHOD0(prepareFrame, void());
2373 };
2374
2375 OutputDevOptRepaintFlashTest() {
2376 mOutput.setDisplayColorProfileForTest(
2377 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
2378 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
2379 }
2380
2381 static const Region kEmptyRegion;
2382 static const Region kNotEmptyRegion;
2383
2384 StrictMock<OutputPartialMock> mOutput;
2385 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
2386 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
2387 CompositionRefreshArgs mRefreshArgs;
2388};
2389
2390const Region OutputDevOptRepaintFlashTest::kEmptyRegion{Rect{0, 0, 0, 0}};
2391const Region OutputDevOptRepaintFlashTest::kNotEmptyRegion{Rect{0, 0, 1, 1}};
2392
2393TEST_F(OutputDevOptRepaintFlashTest, doesNothingIfFlashDelayNotSet) {
2394 mRefreshArgs.devOptFlashDirtyRegionsDelay = {};
2395 mRefreshArgs.repaintEverything = true;
2396 mOutput.mState.isEnabled = true;
2397
2398 mOutput.devOptRepaintFlash(mRefreshArgs);
2399}
2400
2401TEST_F(OutputDevOptRepaintFlashTest, postsAndPreparesANewFrameIfNotEnabled) {
2402 mRefreshArgs.devOptFlashDirtyRegionsDelay = std::chrono::microseconds(1);
2403 mRefreshArgs.repaintEverything = true;
2404 mOutput.mState.isEnabled = false;
2405
2406 InSequence seq;
2407 EXPECT_CALL(mOutput, postFramebuffer());
2408 EXPECT_CALL(mOutput, prepareFrame());
2409
2410 mOutput.devOptRepaintFlash(mRefreshArgs);
2411}
2412
2413TEST_F(OutputDevOptRepaintFlashTest, postsAndPreparesANewFrameIfNotDirty) {
2414 mRefreshArgs.devOptFlashDirtyRegionsDelay = std::chrono::microseconds(1);
2415 mRefreshArgs.repaintEverything = true;
2416 mOutput.mState.isEnabled = true;
2417
2418 InSequence seq;
2419 EXPECT_CALL(mOutput, getDirtyRegion(true)).WillOnce(Return(kEmptyRegion));
2420 EXPECT_CALL(mOutput, postFramebuffer());
2421 EXPECT_CALL(mOutput, prepareFrame());
2422
2423 mOutput.devOptRepaintFlash(mRefreshArgs);
2424}
2425
2426TEST_F(OutputDevOptRepaintFlashTest, alsoComposesSurfacesAndQueuesABufferIfDirty) {
2427 mRefreshArgs.devOptFlashDirtyRegionsDelay = std::chrono::microseconds(1);
2428 mRefreshArgs.repaintEverything = false;
2429 mOutput.mState.isEnabled = true;
2430
2431 InSequence seq;
2432 EXPECT_CALL(mOutput, getDirtyRegion(false)).WillOnce(Return(kNotEmptyRegion));
2433 EXPECT_CALL(mOutput, composeSurfaces(RegionEq(kNotEmptyRegion)));
2434 EXPECT_CALL(*mRenderSurface, queueBuffer(_));
2435 EXPECT_CALL(mOutput, postFramebuffer());
2436 EXPECT_CALL(mOutput, prepareFrame());
2437
2438 mOutput.devOptRepaintFlash(mRefreshArgs);
2439}
2440
Lloyd Piquefaa3f192019-11-14 14:05:09 -08002441// TODO(b/144060211) - Add coverage
2442
2443/*
2444 * Output::finishFrame()
2445 */
2446
Lloyd Pique03561a62019-11-19 18:34:52 -08002447struct OutputFinishFrameTest : public testing::Test {
2448 struct OutputPartialMock : public OutputPartialMockBase {
Lloyd Pique739afaf2019-11-21 16:40:05 -08002449 // Sets up the helper functions called by the function under test to use
2450 // mock implementations.
Lloyd Pique03561a62019-11-19 18:34:52 -08002451 MOCK_METHOD1(composeSurfaces, std::optional<base::unique_fd>(const Region&));
2452 MOCK_METHOD0(postFramebuffer, void());
2453 };
2454
2455 OutputFinishFrameTest() {
2456 mOutput.setDisplayColorProfileForTest(
2457 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
2458 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
2459 }
2460
2461 StrictMock<OutputPartialMock> mOutput;
2462 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
2463 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
2464 CompositionRefreshArgs mRefreshArgs;
2465};
2466
2467TEST_F(OutputFinishFrameTest, ifNotEnabledDoesNothing) {
2468 mOutput.mState.isEnabled = false;
2469
2470 mOutput.finishFrame(mRefreshArgs);
2471}
2472
2473TEST_F(OutputFinishFrameTest, takesEarlyOutifComposeSurfacesReturnsNoFence) {
2474 mOutput.mState.isEnabled = true;
2475
2476 InSequence seq;
2477 EXPECT_CALL(mOutput, composeSurfaces(RegionEq(Region::INVALID_REGION)));
2478
2479 mOutput.finishFrame(mRefreshArgs);
2480}
2481
2482TEST_F(OutputFinishFrameTest, queuesBufferIfComposeSurfacesReturnsAFence) {
2483 mOutput.mState.isEnabled = true;
2484
2485 InSequence seq;
2486 EXPECT_CALL(mOutput, composeSurfaces(RegionEq(Region::INVALID_REGION)))
2487 .WillOnce(Return(ByMove(base::unique_fd())));
2488 EXPECT_CALL(*mRenderSurface, queueBuffer(_));
2489
2490 mOutput.finishFrame(mRefreshArgs);
2491}
Lloyd Piquefaa3f192019-11-14 14:05:09 -08002492
2493/*
2494 * Output::postFramebuffer()
2495 */
2496
Lloyd Pique07178e32019-11-19 19:15:26 -08002497struct OutputPostFramebufferTest : public testing::Test {
2498 struct OutputPartialMock : public OutputPartialMockBase {
Lloyd Pique739afaf2019-11-21 16:40:05 -08002499 // Sets up the helper functions called by the function under test to use
2500 // mock implementations.
Lloyd Pique07178e32019-11-19 19:15:26 -08002501 MOCK_METHOD0(presentAndGetFrameFences, compositionengine::Output::FrameFences());
2502 };
2503
2504 struct Layer {
2505 Layer() {
2506 EXPECT_CALL(outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(layerFE));
2507 EXPECT_CALL(outputLayer, getHwcLayer()).WillRepeatedly(Return(&hwc2Layer));
2508 }
2509
2510 StrictMock<mock::OutputLayer> outputLayer;
2511 StrictMock<mock::LayerFE> layerFE;
2512 StrictMock<HWC2::mock::Layer> hwc2Layer;
2513 };
2514
2515 OutputPostFramebufferTest() {
2516 mOutput.setDisplayColorProfileForTest(
2517 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
2518 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
2519
2520 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(3u));
2521 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u))
2522 .WillRepeatedly(Return(&mLayer1.outputLayer));
2523 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1u))
2524 .WillRepeatedly(Return(&mLayer2.outputLayer));
2525 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(2u))
2526 .WillRepeatedly(Return(&mLayer3.outputLayer));
2527 }
2528
2529 StrictMock<OutputPartialMock> mOutput;
2530 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
2531 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
2532
2533 Layer mLayer1;
2534 Layer mLayer2;
2535 Layer mLayer3;
2536};
2537
2538TEST_F(OutputPostFramebufferTest, ifNotEnabledDoesNothing) {
2539 mOutput.mState.isEnabled = false;
2540
2541 mOutput.postFramebuffer();
2542}
2543
2544TEST_F(OutputPostFramebufferTest, ifEnabledMustFlipThenPresentThenSendPresentCompleted) {
2545 mOutput.mState.isEnabled = true;
2546
2547 compositionengine::Output::FrameFences frameFences;
2548
2549 // This should happen even if there are no output layers.
2550 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
2551
2552 // For this test in particular we want to make sure the call expectations
2553 // setup below are satisfied in the specific order.
2554 InSequence seq;
2555
2556 EXPECT_CALL(*mRenderSurface, flip());
2557 EXPECT_CALL(mOutput, presentAndGetFrameFences()).WillOnce(Return(frameFences));
2558 EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted());
2559
2560 mOutput.postFramebuffer();
2561}
2562
2563TEST_F(OutputPostFramebufferTest, releaseFencesAreSentToLayerFE) {
2564 // Simulate getting release fences from each layer, and ensure they are passed to the
2565 // front-end layer interface for each layer correctly.
2566
2567 mOutput.mState.isEnabled = true;
2568
2569 // Create three unique fence instances
2570 sp<Fence> layer1Fence = new Fence();
2571 sp<Fence> layer2Fence = new Fence();
2572 sp<Fence> layer3Fence = new Fence();
2573
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08002574 Output::FrameFences frameFences;
Lloyd Pique07178e32019-11-19 19:15:26 -08002575 frameFences.layerFences.emplace(&mLayer1.hwc2Layer, layer1Fence);
2576 frameFences.layerFences.emplace(&mLayer2.hwc2Layer, layer2Fence);
2577 frameFences.layerFences.emplace(&mLayer3.hwc2Layer, layer3Fence);
2578
2579 EXPECT_CALL(*mRenderSurface, flip());
2580 EXPECT_CALL(mOutput, presentAndGetFrameFences()).WillOnce(Return(frameFences));
2581 EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted());
2582
2583 // Compare the pointers values of each fence to make sure the correct ones
2584 // are passed. This happens to work with the current implementation, but
2585 // would not survive certain calls like Fence::merge() which would return a
2586 // new instance.
2587 EXPECT_CALL(mLayer1.layerFE,
2588 onLayerDisplayed(Property(&sp<Fence>::get, Eq(layer1Fence.get()))));
2589 EXPECT_CALL(mLayer2.layerFE,
2590 onLayerDisplayed(Property(&sp<Fence>::get, Eq(layer2Fence.get()))));
2591 EXPECT_CALL(mLayer3.layerFE,
2592 onLayerDisplayed(Property(&sp<Fence>::get, Eq(layer3Fence.get()))));
2593
2594 mOutput.postFramebuffer();
2595}
2596
2597TEST_F(OutputPostFramebufferTest, releaseFencesIncludeClientTargetAcquireFence) {
2598 mOutput.mState.isEnabled = true;
2599 mOutput.mState.usesClientComposition = true;
2600
2601 sp<Fence> clientTargetAcquireFence = new Fence();
2602 sp<Fence> layer1Fence = new Fence();
2603 sp<Fence> layer2Fence = new Fence();
2604 sp<Fence> layer3Fence = new Fence();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08002605 Output::FrameFences frameFences;
Lloyd Pique07178e32019-11-19 19:15:26 -08002606 frameFences.clientTargetAcquireFence = clientTargetAcquireFence;
2607 frameFences.layerFences.emplace(&mLayer1.hwc2Layer, layer1Fence);
2608 frameFences.layerFences.emplace(&mLayer2.hwc2Layer, layer2Fence);
2609 frameFences.layerFences.emplace(&mLayer3.hwc2Layer, layer3Fence);
2610
2611 EXPECT_CALL(*mRenderSurface, flip());
2612 EXPECT_CALL(mOutput, presentAndGetFrameFences()).WillOnce(Return(frameFences));
2613 EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted());
2614
2615 // Fence::merge is called, and since none of the fences are actually valid,
2616 // Fence::NO_FENCE is returned and passed to each onLayerDisplayed() call.
2617 // This is the best we can do without creating a real kernel fence object.
2618 EXPECT_CALL(mLayer1.layerFE, onLayerDisplayed(Fence::NO_FENCE));
2619 EXPECT_CALL(mLayer2.layerFE, onLayerDisplayed(Fence::NO_FENCE));
2620 EXPECT_CALL(mLayer3.layerFE, onLayerDisplayed(Fence::NO_FENCE));
2621
2622 mOutput.postFramebuffer();
2623}
2624
2625TEST_F(OutputPostFramebufferTest, releasedLayersSentPresentFence) {
2626 mOutput.mState.isEnabled = true;
2627 mOutput.mState.usesClientComposition = true;
2628
2629 // This should happen even if there are no (current) output layers.
2630 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
2631
2632 // Load up the released layers with some mock instances
2633 sp<StrictMock<mock::LayerFE>> releasedLayer1{new StrictMock<mock::LayerFE>()};
2634 sp<StrictMock<mock::LayerFE>> releasedLayer2{new StrictMock<mock::LayerFE>()};
2635 sp<StrictMock<mock::LayerFE>> releasedLayer3{new StrictMock<mock::LayerFE>()};
2636 Output::ReleasedLayers layers;
2637 layers.push_back(releasedLayer1);
2638 layers.push_back(releasedLayer2);
2639 layers.push_back(releasedLayer3);
2640 mOutput.setReleasedLayers(std::move(layers));
2641
2642 // Set up a fake present fence
2643 sp<Fence> presentFence = new Fence();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08002644 Output::FrameFences frameFences;
Lloyd Pique07178e32019-11-19 19:15:26 -08002645 frameFences.presentFence = presentFence;
2646
2647 EXPECT_CALL(*mRenderSurface, flip());
2648 EXPECT_CALL(mOutput, presentAndGetFrameFences()).WillOnce(Return(frameFences));
2649 EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted());
2650
2651 // Each released layer should be given the presentFence.
2652 EXPECT_CALL(*releasedLayer1,
2653 onLayerDisplayed(Property(&sp<Fence>::get, Eq(presentFence.get()))));
2654 EXPECT_CALL(*releasedLayer2,
2655 onLayerDisplayed(Property(&sp<Fence>::get, Eq(presentFence.get()))));
2656 EXPECT_CALL(*releasedLayer3,
2657 onLayerDisplayed(Property(&sp<Fence>::get, Eq(presentFence.get()))));
2658
2659 mOutput.postFramebuffer();
2660
2661 // After the call the list of released layers should have been cleared.
2662 EXPECT_TRUE(mOutput.getReleasedLayersForTest().empty());
2663}
Lloyd Piquefaa3f192019-11-14 14:05:09 -08002664
2665/*
Lloyd Pique56eba802019-08-28 15:45:25 -07002666 * Output::composeSurfaces()
2667 */
2668
2669struct OutputComposeSurfacesTest : public testing::Test {
2670 static constexpr uint32_t kDefaultOutputOrientation = TR_IDENT;
2671 static constexpr ui::Dataspace kDefaultOutputDataspace = ui::Dataspace::DISPLAY_P3;
2672
2673 static const Rect kDefaultOutputFrame;
2674 static const Rect kDefaultOutputViewport;
2675 static const Rect kDefaultOutputScissor;
2676 static const mat4 kDefaultColorTransformMat;
2677
Lloyd Piquefaa3f192019-11-14 14:05:09 -08002678 struct OutputPartialMock : public OutputPartialMockBase {
Lloyd Pique739afaf2019-11-21 16:40:05 -08002679 // Sets up the helper functions called by the function under test to use
2680 // mock implementations.
Lloyd Pique56eba802019-08-28 15:45:25 -07002681 MOCK_CONST_METHOD0(getSkipColorTransform, bool());
Vishnu Nair3a7346c2019-12-04 08:09:09 -08002682 MOCK_METHOD3(generateClientCompositionRequests,
2683 std::vector<renderengine::LayerSettings>(bool, Region&, ui::Dataspace));
Lloyd Pique56eba802019-08-28 15:45:25 -07002684 MOCK_METHOD2(appendRegionFlashRequests,
2685 void(const Region&, std::vector<renderengine::LayerSettings>&));
2686 MOCK_METHOD1(setExpensiveRenderingExpected, void(bool));
2687 };
2688
2689 OutputComposeSurfacesTest() {
2690 mOutput.setDisplayColorProfileForTest(
2691 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
2692 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
2693
Lloyd Pique56eba802019-08-28 15:45:25 -07002694 mOutput.editState().frame = kDefaultOutputFrame;
2695 mOutput.editState().viewport = kDefaultOutputViewport;
2696 mOutput.editState().scissor = kDefaultOutputScissor;
2697 mOutput.editState().transform = ui::Transform{kDefaultOutputOrientation};
2698 mOutput.editState().orientation = kDefaultOutputOrientation;
2699 mOutput.editState().dataspace = kDefaultOutputDataspace;
Lloyd Pique3eb1b212019-03-07 21:15:40 -08002700 mOutput.editState().colorTransformMatrix = kDefaultColorTransformMat;
Lloyd Pique56eba802019-08-28 15:45:25 -07002701 mOutput.editState().isSecure = true;
2702 mOutput.editState().needsFiltering = false;
2703 mOutput.editState().usesClientComposition = true;
2704 mOutput.editState().usesDeviceComposition = false;
2705
Lloyd Pique01c77c12019-04-17 12:48:32 -07002706 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2u));
2707 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u))
2708 .WillRepeatedly(Return(&mOutputLayer1));
2709 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1u))
2710 .WillRepeatedly(Return(&mOutputLayer2));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -07002711 EXPECT_CALL(mOutput, getCompositionEngine()).WillRepeatedly(ReturnRef(mCompositionEngine));
Lloyd Pique56eba802019-08-28 15:45:25 -07002712 EXPECT_CALL(mCompositionEngine, getRenderEngine()).WillRepeatedly(ReturnRef(mRenderEngine));
Alec Mourie4034bb2019-11-19 12:45:54 -08002713 EXPECT_CALL(mCompositionEngine, getTimeStats())
2714 .WillRepeatedly(ReturnRef(*mTimeStats.get()));
Lloyd Pique56eba802019-08-28 15:45:25 -07002715 }
2716
2717 StrictMock<mock::CompositionEngine> mCompositionEngine;
2718 StrictMock<renderengine::mock::RenderEngine> mRenderEngine;
Alec Mourie4034bb2019-11-19 12:45:54 -08002719 // TODO: make this is a proper mock.
2720 std::shared_ptr<TimeStats> mTimeStats = std::make_shared<android::impl::TimeStats>();
Lloyd Pique56eba802019-08-28 15:45:25 -07002721 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
2722 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
Lloyd Pique01c77c12019-04-17 12:48:32 -07002723 StrictMock<mock::OutputLayer> mOutputLayer1;
2724 StrictMock<mock::OutputLayer> mOutputLayer2;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -07002725 StrictMock<OutputPartialMock> mOutput;
Lloyd Pique56eba802019-08-28 15:45:25 -07002726 sp<GraphicBuffer> mOutputBuffer = new GraphicBuffer();
2727};
2728
2729const Rect OutputComposeSurfacesTest::kDefaultOutputFrame{1001, 1002, 1003, 1004};
2730const Rect OutputComposeSurfacesTest::kDefaultOutputViewport{1005, 1006, 1007, 1008};
2731const Rect OutputComposeSurfacesTest::kDefaultOutputScissor{1009, 1010, 1011, 1012};
2732const mat4 OutputComposeSurfacesTest::kDefaultColorTransformMat{mat4() * 0.5};
2733
2734// TODO(b/121291683): Expand unit test coverage for composeSurfaces beyond these
2735// basic tests.
2736
2737TEST_F(OutputComposeSurfacesTest, doesNothingIfNoClientComposition) {
2738 mOutput.editState().usesClientComposition = false;
2739
2740 Region debugRegion;
Lloyd Piqued3d69882019-02-28 16:03:46 -08002741 std::optional<base::unique_fd> readyFence = mOutput.composeSurfaces(debugRegion);
2742 EXPECT_TRUE(readyFence);
Lloyd Pique56eba802019-08-28 15:45:25 -07002743}
2744
2745TEST_F(OutputComposeSurfacesTest, worksIfNoClientLayersQueued) {
2746 const Region kDebugRegion{Rect{100, 101, 102, 103}};
2747
2748 constexpr float kDefaultMaxLuminance = 1.0f;
2749 constexpr float kDefaultAvgLuminance = 0.7f;
2750 constexpr float kDefaultMinLuminance = 0.1f;
2751 HdrCapabilities HdrCapabilities{{},
2752 kDefaultMaxLuminance,
2753 kDefaultAvgLuminance,
2754 kDefaultMinLuminance};
2755
2756 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillOnce(Return(false));
2757 EXPECT_CALL(mRenderEngine, drawLayers(_, _, _, true, _, _)).Times(1);
2758
2759 EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillOnce(Return(true));
2760 EXPECT_CALL(*mDisplayColorProfile, getHdrCapabilities()).WillOnce(ReturnRef(HdrCapabilities));
2761
2762 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillOnce(Return(mOutputBuffer));
2763
2764 EXPECT_CALL(mOutput, getSkipColorTransform()).WillOnce(Return(false));
Vishnu Nair3a7346c2019-12-04 08:09:09 -08002765 EXPECT_CALL(mOutput, generateClientCompositionRequests(false, _, _)).Times(1);
Lloyd Pique56eba802019-08-28 15:45:25 -07002766 EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _)).Times(1);
2767 EXPECT_CALL(mOutput, setExpensiveRenderingExpected(true)).Times(1);
2768 EXPECT_CALL(mOutput, setExpensiveRenderingExpected(false)).Times(1);
2769
Lloyd Piqued3d69882019-02-28 16:03:46 -08002770 std::optional<base::unique_fd> readyFence = mOutput.composeSurfaces(kDebugRegion);
2771 EXPECT_TRUE(readyFence);
Lloyd Pique56eba802019-08-28 15:45:25 -07002772}
2773
2774/*
2775 * Output::generateClientCompositionRequests()
2776 */
2777
2778struct GenerateClientCompositionRequestsTest : public testing::Test {
Lloyd Piquefaa3f192019-11-14 14:05:09 -08002779 struct OutputPartialMock : public OutputPartialMockBase {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -07002780 // compositionengine::Output overrides
Lloyd Pique56eba802019-08-28 15:45:25 -07002781 std::vector<renderengine::LayerSettings> generateClientCompositionRequests(
Vishnu Nair3a7346c2019-12-04 08:09:09 -08002782 bool supportsProtectedContent, Region& clearRegion,
2783 ui::Dataspace dataspace) override {
Lloyd Pique56eba802019-08-28 15:45:25 -07002784 return impl::Output::generateClientCompositionRequests(supportsProtectedContent,
Vishnu Nair3a7346c2019-12-04 08:09:09 -08002785 clearRegion, dataspace);
Lloyd Pique56eba802019-08-28 15:45:25 -07002786 }
2787 };
2788
2789 GenerateClientCompositionRequestsTest() {
2790 mOutput.setDisplayColorProfileForTest(
2791 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
2792 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
2793 }
2794
Lloyd Pique56eba802019-08-28 15:45:25 -07002795 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
2796 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -07002797 StrictMock<OutputPartialMock> mOutput;
Lloyd Pique56eba802019-08-28 15:45:25 -07002798};
2799
2800// TODO(b/121291683): Add more unit test coverage for generateClientCompositionRequests
2801
2802TEST_F(GenerateClientCompositionRequestsTest, worksForLandscapeModeSplitScreen) {
2803 // In split-screen landscape mode, the screen is rotated 90 degrees, with
2804 // one layer on the left covering the left side of the output, and one layer
2805 // on the right covering that side of the output.
2806
Lloyd Pique01c77c12019-04-17 12:48:32 -07002807 StrictMock<mock::OutputLayer> leftOutputLayer;
2808 StrictMock<mock::OutputLayer> rightOutputLayer;
Lloyd Pique56eba802019-08-28 15:45:25 -07002809
2810 StrictMock<mock::Layer> leftLayer;
2811 StrictMock<mock::LayerFE> leftLayerFE;
2812 StrictMock<mock::Layer> rightLayer;
2813 StrictMock<mock::LayerFE> rightLayerFE;
2814
2815 impl::OutputLayerCompositionState leftOutputLayerState;
2816 leftOutputLayerState.clearClientTarget = false;
Lloyd Piquea2468662019-03-07 21:31:06 -08002817 leftOutputLayerState.visibleRegion = Region{Rect{0, 0, 1000, 1000}};
Lloyd Pique56eba802019-08-28 15:45:25 -07002818
Lloyd Pique9755fb72019-03-26 14:44:40 -07002819 LayerFECompositionState leftLayerFEState;
2820 leftLayerFEState.isOpaque = true;
Lloyd Pique56eba802019-08-28 15:45:25 -07002821
2822 const half3 leftLayerColor{1.f, 0.f, 0.f};
2823 renderengine::LayerSettings leftLayerRESettings;
2824 leftLayerRESettings.source.solidColor = leftLayerColor;
2825
2826 impl::OutputLayerCompositionState rightOutputLayerState;
2827 rightOutputLayerState.clearClientTarget = false;
Lloyd Piquea2468662019-03-07 21:31:06 -08002828 rightOutputLayerState.visibleRegion = Region{Rect{1000, 0, 2000, 1000}};
Lloyd Pique56eba802019-08-28 15:45:25 -07002829
Lloyd Pique9755fb72019-03-26 14:44:40 -07002830 LayerFECompositionState rightLayerFEState;
2831 rightLayerFEState.isOpaque = true;
Lloyd Pique56eba802019-08-28 15:45:25 -07002832
2833 const half3 rightLayerColor{0.f, 1.f, 0.f};
2834 renderengine::LayerSettings rightLayerRESettings;
2835 rightLayerRESettings.source.solidColor = rightLayerColor;
2836
Lloyd Pique01c77c12019-04-17 12:48:32 -07002837 EXPECT_CALL(leftOutputLayer, getState()).WillRepeatedly(ReturnRef(leftOutputLayerState));
2838 EXPECT_CALL(leftOutputLayer, getLayer()).WillRepeatedly(ReturnRef(leftLayer));
2839 EXPECT_CALL(leftOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(leftLayerFE));
2840 EXPECT_CALL(leftOutputLayer, requiresClientComposition()).WillRepeatedly(Return(true));
2841 EXPECT_CALL(leftOutputLayer, needsFiltering()).WillRepeatedly(Return(false));
Lloyd Pique9755fb72019-03-26 14:44:40 -07002842 EXPECT_CALL(leftLayer, getFEState()).WillRepeatedly(ReturnRef(leftLayerFEState));
Lloyd Pique56eba802019-08-28 15:45:25 -07002843 EXPECT_CALL(leftLayerFE, prepareClientComposition(_)).WillOnce(Return(leftLayerRESettings));
Vishnu Nair3a7346c2019-12-04 08:09:09 -08002844 EXPECT_CALL(leftLayerFE, prepareShadowClientComposition(_, _, _))
2845 .WillOnce(Return(std::optional<renderengine::LayerSettings>()));
Adithya Srinivasanb69e0762019-11-11 18:39:53 -08002846 EXPECT_CALL(leftOutputLayer, editState()).WillRepeatedly(ReturnRef(leftOutputLayerState));
Lloyd Pique56eba802019-08-28 15:45:25 -07002847
Lloyd Pique01c77c12019-04-17 12:48:32 -07002848 EXPECT_CALL(rightOutputLayer, getState()).WillRepeatedly(ReturnRef(rightOutputLayerState));
2849 EXPECT_CALL(rightOutputLayer, getLayer()).WillRepeatedly(ReturnRef(rightLayer));
2850 EXPECT_CALL(rightOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(rightLayerFE));
2851 EXPECT_CALL(rightOutputLayer, requiresClientComposition()).WillRepeatedly(Return(true));
2852 EXPECT_CALL(rightOutputLayer, needsFiltering()).WillRepeatedly(Return(false));
Lloyd Pique9755fb72019-03-26 14:44:40 -07002853 EXPECT_CALL(rightLayer, getFEState()).WillRepeatedly(ReturnRef(rightLayerFEState));
Lloyd Pique56eba802019-08-28 15:45:25 -07002854 EXPECT_CALL(rightLayerFE, prepareClientComposition(_)).WillOnce(Return(rightLayerRESettings));
Vishnu Nair3a7346c2019-12-04 08:09:09 -08002855 EXPECT_CALL(rightLayerFE, prepareShadowClientComposition(_, _, _))
2856 .WillOnce(Return(std::optional<renderengine::LayerSettings>()));
Adithya Srinivasanb69e0762019-11-11 18:39:53 -08002857 EXPECT_CALL(rightOutputLayer, editState()).WillRepeatedly(ReturnRef(rightOutputLayerState));
Lloyd Pique56eba802019-08-28 15:45:25 -07002858
Lloyd Pique01c77c12019-04-17 12:48:32 -07002859 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2u));
2860 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u))
2861 .WillRepeatedly(Return(&leftOutputLayer));
2862 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1u))
2863 .WillRepeatedly(Return(&rightOutputLayer));
Lloyd Pique56eba802019-08-28 15:45:25 -07002864
2865 const Rect kPortraitFrame(0, 0, 1000, 2000);
2866 const Rect kPortraitViewport(0, 0, 2000, 1000);
2867 const Rect kPortraitScissor(0, 0, 1000, 2000);
2868 const uint32_t kPortraitOrientation = TR_ROT_90;
2869
2870 mOutput.editState().frame = kPortraitFrame;
2871 mOutput.editState().viewport = kPortraitViewport;
2872 mOutput.editState().scissor = kPortraitScissor;
2873 mOutput.editState().transform = ui::Transform{kPortraitOrientation};
2874 mOutput.editState().orientation = kPortraitOrientation;
2875 mOutput.editState().needsFiltering = true;
2876 mOutput.editState().isSecure = false;
2877
2878 constexpr bool supportsProtectedContent = false;
2879 Region clearRegion;
Vishnu Nair3a7346c2019-12-04 08:09:09 -08002880 auto requests = mOutput.generateClientCompositionRequests(supportsProtectedContent, clearRegion,
2881 mOutput.getState().targetDataspace);
Lloyd Pique56eba802019-08-28 15:45:25 -07002882
2883 ASSERT_EQ(2u, requests.size());
2884 EXPECT_EQ(leftLayerColor, requests[0].source.solidColor);
2885 EXPECT_EQ(rightLayerColor, requests[1].source.solidColor);
2886}
2887
2888TEST_F(GenerateClientCompositionRequestsTest, ignoresLayersThatDoNotIntersectWithViewport) {
2889 // Layers whose visible region does not intersect with the viewport will be
2890 // skipped when generating client composition request state.
2891
Lloyd Pique01c77c12019-04-17 12:48:32 -07002892 StrictMock<mock::OutputLayer> outputLayer;
Lloyd Pique56eba802019-08-28 15:45:25 -07002893 StrictMock<mock::Layer> layer;
2894 StrictMock<mock::LayerFE> layerFE;
2895
2896 impl::OutputLayerCompositionState outputLayerState;
2897 outputLayerState.clearClientTarget = false;
Lloyd Piquea2468662019-03-07 21:31:06 -08002898 outputLayerState.visibleRegion = Region{Rect{3000, 0, 4000, 1000}};
Lloyd Pique56eba802019-08-28 15:45:25 -07002899
Lloyd Pique9755fb72019-03-26 14:44:40 -07002900 LayerFECompositionState layerFEState;
2901 layerFEState.isOpaque = true;
Lloyd Pique56eba802019-08-28 15:45:25 -07002902
Lloyd Pique01c77c12019-04-17 12:48:32 -07002903 EXPECT_CALL(outputLayer, getState()).WillRepeatedly(ReturnRef(outputLayerState));
2904 EXPECT_CALL(outputLayer, getLayer()).WillRepeatedly(ReturnRef(layer));
2905 EXPECT_CALL(outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(layerFE));
2906 EXPECT_CALL(outputLayer, requiresClientComposition()).WillRepeatedly(Return(true));
2907 EXPECT_CALL(outputLayer, needsFiltering()).WillRepeatedly(Return(false));
Lloyd Pique9755fb72019-03-26 14:44:40 -07002908 EXPECT_CALL(layer, getFEState()).WillRepeatedly(ReturnRef(layerFEState));
Lloyd Pique56eba802019-08-28 15:45:25 -07002909 EXPECT_CALL(layerFE, prepareClientComposition(_)).Times(0);
Adithya Srinivasanb69e0762019-11-11 18:39:53 -08002910 EXPECT_CALL(outputLayer, editState()).WillRepeatedly(ReturnRef(outputLayerState));
Lloyd Pique56eba802019-08-28 15:45:25 -07002911
Lloyd Pique01c77c12019-04-17 12:48:32 -07002912 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(1u));
2913 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u)).WillRepeatedly(Return(&outputLayer));
Lloyd Pique56eba802019-08-28 15:45:25 -07002914
2915 const Rect kPortraitFrame(0, 0, 1000, 2000);
2916 const Rect kPortraitViewport(0, 0, 2000, 1000);
2917 const Rect kPortraitScissor(0, 0, 1000, 2000);
2918 const uint32_t kPortraitOrientation = TR_ROT_90;
2919
2920 mOutput.editState().frame = kPortraitFrame;
2921 mOutput.editState().viewport = kPortraitViewport;
2922 mOutput.editState().scissor = kPortraitScissor;
2923 mOutput.editState().transform = ui::Transform{kPortraitOrientation};
2924 mOutput.editState().orientation = kPortraitOrientation;
2925 mOutput.editState().needsFiltering = true;
2926 mOutput.editState().isSecure = false;
2927
2928 constexpr bool supportsProtectedContent = false;
2929 Region clearRegion;
Vishnu Nair3a7346c2019-12-04 08:09:09 -08002930 auto requests = mOutput.generateClientCompositionRequests(supportsProtectedContent, clearRegion,
2931 mOutput.getState().targetDataspace);
Lloyd Pique56eba802019-08-28 15:45:25 -07002932
2933 EXPECT_EQ(0u, requests.size());
2934}
2935
Lloyd Piquec2d54d42019-08-28 18:04:21 -07002936TEST_F(GenerateClientCompositionRequestsTest, clearsDeviceLayesAfterFirst) {
2937 // If client composition is performed with some layers set to use device
2938 // composition, device layers after the first layer (device or client) will
2939 // clear the frame buffer if they are opaque and if that layer has a flag
2940 // set to do so. The first layer is skipped as the frame buffer is already
2941 // expected to be clear.
2942
Lloyd Pique01c77c12019-04-17 12:48:32 -07002943 StrictMock<mock::OutputLayer> leftOutputLayer;
2944 StrictMock<mock::OutputLayer> rightOutputLayer;
Lloyd Piquec2d54d42019-08-28 18:04:21 -07002945
2946 StrictMock<mock::Layer> leftLayer;
2947 StrictMock<mock::LayerFE> leftLayerFE;
2948 StrictMock<mock::Layer> rightLayer;
2949 StrictMock<mock::LayerFE> rightLayerFE;
2950
2951 impl::OutputLayerCompositionState leftOutputLayerState;
2952 leftOutputLayerState.clearClientTarget = true;
Lloyd Piquea2468662019-03-07 21:31:06 -08002953 leftOutputLayerState.visibleRegion = Region{Rect{0, 0, 1000, 1000}};
Lloyd Piquec2d54d42019-08-28 18:04:21 -07002954
Lloyd Pique9755fb72019-03-26 14:44:40 -07002955 LayerFECompositionState leftLayerFEState;
2956 leftLayerFEState.isOpaque = true;
Lloyd Piquec2d54d42019-08-28 18:04:21 -07002957
2958 impl::OutputLayerCompositionState rightOutputLayerState;
2959 rightOutputLayerState.clearClientTarget = true;
Lloyd Piquea2468662019-03-07 21:31:06 -08002960 rightOutputLayerState.visibleRegion = Region{Rect{1000, 0, 2000, 1000}};
Lloyd Piquec2d54d42019-08-28 18:04:21 -07002961
Lloyd Pique9755fb72019-03-26 14:44:40 -07002962 LayerFECompositionState rightLayerFEState;
2963 rightLayerFEState.isOpaque = true;
Lloyd Piquec2d54d42019-08-28 18:04:21 -07002964
2965 const half3 rightLayerColor{0.f, 1.f, 0.f};
2966 renderengine::LayerSettings rightLayerRESettings;
2967 rightLayerRESettings.geometry.boundaries = FloatRect{456, 0, 0, 0};
2968 rightLayerRESettings.source.solidColor = rightLayerColor;
2969
Lloyd Pique01c77c12019-04-17 12:48:32 -07002970 EXPECT_CALL(leftOutputLayer, getState()).WillRepeatedly(ReturnRef(leftOutputLayerState));
2971 EXPECT_CALL(leftOutputLayer, getLayer()).WillRepeatedly(ReturnRef(leftLayer));
2972 EXPECT_CALL(leftOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(leftLayerFE));
2973 EXPECT_CALL(leftOutputLayer, requiresClientComposition()).WillRepeatedly(Return(false));
2974 EXPECT_CALL(leftOutputLayer, needsFiltering()).WillRepeatedly(Return(false));
Lloyd Pique9755fb72019-03-26 14:44:40 -07002975 EXPECT_CALL(leftLayer, getFEState()).WillRepeatedly(ReturnRef(leftLayerFEState));
Adithya Srinivasanb69e0762019-11-11 18:39:53 -08002976 EXPECT_CALL(leftOutputLayer, editState()).WillRepeatedly(ReturnRef(leftOutputLayerState));
Lloyd Piquec2d54d42019-08-28 18:04:21 -07002977
Lloyd Pique01c77c12019-04-17 12:48:32 -07002978 EXPECT_CALL(rightOutputLayer, getState()).WillRepeatedly(ReturnRef(rightOutputLayerState));
2979 EXPECT_CALL(rightOutputLayer, getLayer()).WillRepeatedly(ReturnRef(rightLayer));
2980 EXPECT_CALL(rightOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(rightLayerFE));
2981 EXPECT_CALL(rightOutputLayer, requiresClientComposition()).WillRepeatedly(Return(false));
2982 EXPECT_CALL(rightOutputLayer, needsFiltering()).WillRepeatedly(Return(false));
Lloyd Pique9755fb72019-03-26 14:44:40 -07002983 EXPECT_CALL(rightLayer, getFEState()).WillRepeatedly(ReturnRef(rightLayerFEState));
Lloyd Piquec2d54d42019-08-28 18:04:21 -07002984 EXPECT_CALL(rightLayerFE, prepareClientComposition(_)).WillOnce(Return(rightLayerRESettings));
Adithya Srinivasanb69e0762019-11-11 18:39:53 -08002985 EXPECT_CALL(rightOutputLayer, editState()).WillRepeatedly(ReturnRef(rightOutputLayerState));
Lloyd Piquec2d54d42019-08-28 18:04:21 -07002986
Lloyd Pique01c77c12019-04-17 12:48:32 -07002987 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2u));
2988 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u))
2989 .WillRepeatedly(Return(&leftOutputLayer));
2990 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1u))
2991 .WillRepeatedly(Return(&rightOutputLayer));
Lloyd Piquec2d54d42019-08-28 18:04:21 -07002992
2993 const Rect kPortraitFrame(0, 0, 1000, 2000);
2994 const Rect kPortraitViewport(0, 0, 2000, 1000);
2995 const Rect kPortraitScissor(0, 0, 1000, 2000);
2996 const uint32_t kPortraitOrientation = TR_ROT_90;
2997
2998 mOutput.editState().frame = kPortraitFrame;
2999 mOutput.editState().viewport = kPortraitViewport;
3000 mOutput.editState().scissor = kPortraitScissor;
3001 mOutput.editState().transform = ui::Transform{kPortraitOrientation};
3002 mOutput.editState().orientation = kPortraitOrientation;
3003 mOutput.editState().needsFiltering = true;
3004 mOutput.editState().isSecure = false;
3005
3006 constexpr bool supportsProtectedContent = false;
3007 Region clearRegion;
Vishnu Nair3a7346c2019-12-04 08:09:09 -08003008 auto requests = mOutput.generateClientCompositionRequests(supportsProtectedContent, clearRegion,
3009 mOutput.getState().targetDataspace);
Lloyd Piquec2d54d42019-08-28 18:04:21 -07003010
3011 const half3 clearColor{0.f, 0.f, 0.f};
3012
3013 ASSERT_EQ(1u, requests.size());
3014 EXPECT_EQ(456.f, requests[0].geometry.boundaries.left);
3015 EXPECT_EQ(clearColor, requests[0].source.solidColor);
3016}
3017
Lloyd Pique32cbe282018-10-19 13:09:22 -07003018} // namespace
3019} // namespace android::compositionengine