blob: df7aa13d8aaf7b872f74da3b658a09aabf9c3cd3 [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"
38#include "TransformMatcher.h"
39
40namespace android::compositionengine {
41namespace {
42
Lloyd Pique56eba802019-08-28 15:45:25 -070043using testing::_;
Lloyd Pique03561a62019-11-19 18:34:52 -080044using testing::ByMove;
Lloyd Pique17ca7422019-11-14 14:24:10 -080045using testing::DoAll;
Lloyd Pique07178e32019-11-19 19:15:26 -080046using testing::Eq;
Lloyd Piquefaa3f192019-11-14 14:05:09 -080047using testing::InSequence;
Lloyd Pique17ca7422019-11-14 14:24:10 -080048using testing::Mock;
Lloyd Pique07178e32019-11-19 19:15:26 -080049using testing::Property;
Lloyd Piquefaa3f192019-11-14 14:05:09 -080050using testing::Ref;
Lloyd Pique31cb2942018-10-19 17:23:03 -070051using testing::Return;
Lloyd Pique32cbe282018-10-19 13:09:22 -070052using testing::ReturnRef;
Lloyd Pique17ca7422019-11-14 14:24:10 -080053using testing::SetArgPointee;
Lloyd Pique32cbe282018-10-19 13:09:22 -070054using testing::StrictMock;
55
Lloyd Pique56eba802019-08-28 15:45:25 -070056constexpr auto TR_IDENT = 0u;
57constexpr auto TR_ROT_90 = HAL_TRANSFORM_ROT_90;
58
Lloyd Pique3eb1b212019-03-07 21:15:40 -080059const mat4 kIdentity;
60const mat4 kNonIdentityHalf = mat4() * 0.5;
61const mat4 kNonIdentityQuarter = mat4() * 0.25;
62
Lloyd Pique17ca7422019-11-14 14:24:10 -080063constexpr OutputColorSetting kVendorSpecifiedOutputColorSetting =
64 static_cast<OutputColorSetting>(0x100);
65
Lloyd Piquefaa3f192019-11-14 14:05:09 -080066struct OutputPartialMockBase : public impl::Output {
67 // compositionengine::Output overrides
68 const OutputCompositionState& getState() const override { return mState; }
69 OutputCompositionState& editState() override { return mState; }
70
71 // Use mocks for all the remaining virtual functions
72 // not implemented by the base implementation class.
73 MOCK_CONST_METHOD0(getOutputLayerCount, size_t());
74 MOCK_CONST_METHOD1(getOutputLayerOrderedByZByIndex, compositionengine::OutputLayer*(size_t));
75 MOCK_METHOD3(ensureOutputLayer,
76 compositionengine::OutputLayer*(std::optional<size_t>,
77 const std::shared_ptr<compositionengine::Layer>&,
78 const sp<LayerFE>&));
79 MOCK_METHOD0(finalizePendingOutputLayers, void());
80 MOCK_METHOD0(clearOutputLayers, void());
81 MOCK_CONST_METHOD1(dumpState, void(std::string&));
82 MOCK_CONST_METHOD0(getCompositionEngine, const CompositionEngine&());
83 MOCK_METHOD2(injectOutputLayerForTest,
84 compositionengine::OutputLayer*(const std::shared_ptr<compositionengine::Layer>&,
85 const sp<LayerFE>&));
86 MOCK_METHOD1(injectOutputLayerForTest, void(std::unique_ptr<OutputLayer>));
87
88 impl::OutputCompositionState mState;
89};
90
Lloyd Pique66d68602019-02-13 14:23:31 -080091struct OutputTest : public testing::Test {
Lloyd Pique01c77c12019-04-17 12:48:32 -070092 class Output : public impl::Output {
93 public:
94 using impl::Output::injectOutputLayerForTest;
95 virtual void injectOutputLayerForTest(std::unique_ptr<compositionengine::OutputLayer>) = 0;
96 };
97
98 static std::shared_ptr<Output> createOutput(
99 const compositionengine::CompositionEngine& compositionEngine) {
100 return impl::createOutputTemplated<Output>(compositionEngine);
101 }
102
Lloyd Pique31cb2942018-10-19 17:23:03 -0700103 OutputTest() {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700104 mOutput->setDisplayColorProfileForTest(
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700105 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700106 mOutput->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
Lloyd Piqueef958122019-02-05 18:00:12 -0800107
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700108 mOutput->editState().bounds = kDefaultDisplaySize;
Lloyd Pique31cb2942018-10-19 17:23:03 -0700109 }
Lloyd Pique32cbe282018-10-19 13:09:22 -0700110
Lloyd Piqueef958122019-02-05 18:00:12 -0800111 static const Rect kDefaultDisplaySize;
112
Lloyd Pique32cbe282018-10-19 13:09:22 -0700113 StrictMock<mock::CompositionEngine> mCompositionEngine;
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700114 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
Lloyd Pique31cb2942018-10-19 17:23:03 -0700115 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
Lloyd Pique01c77c12019-04-17 12:48:32 -0700116 std::shared_ptr<Output> mOutput = createOutput(mCompositionEngine);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700117};
118
Lloyd Piquec0ee6ba2019-11-14 12:55:53 -0800119// Extension of the base test useful for checking interactions with the LayerFE
120// functions to latch composition state.
121struct OutputLatchFEStateTest : public OutputTest {
122 OutputLatchFEStateTest() {
123 EXPECT_CALL(*mOutputLayer1, getLayer()).WillRepeatedly(ReturnRef(mLayer1));
124 EXPECT_CALL(*mOutputLayer2, getLayer()).WillRepeatedly(ReturnRef(mLayer2));
125 EXPECT_CALL(*mOutputLayer3, getLayer()).WillRepeatedly(ReturnRef(mLayer3));
126
127 EXPECT_CALL(*mOutputLayer1, getLayerFE()).WillRepeatedly(ReturnRef(mLayer1FE));
128 EXPECT_CALL(*mOutputLayer2, getLayerFE()).WillRepeatedly(ReturnRef(mLayer2FE));
129 EXPECT_CALL(*mOutputLayer3, getLayerFE()).WillRepeatedly(ReturnRef(mLayer3FE));
130
131 EXPECT_CALL(mLayer1, editFEState()).WillRepeatedly(ReturnRef(mLayer1FEState));
132 EXPECT_CALL(mLayer2, editFEState()).WillRepeatedly(ReturnRef(mLayer2FEState));
133 EXPECT_CALL(mLayer3, editFEState()).WillRepeatedly(ReturnRef(mLayer3FEState));
134 }
135
136 void injectLayer(std::unique_ptr<mock::OutputLayer> layer) {
137 mOutput->injectOutputLayerForTest(std::unique_ptr<OutputLayer>(layer.release()));
138 }
139
140 std::unique_ptr<mock::OutputLayer> mOutputLayer1{new StrictMock<mock::OutputLayer>};
141 std::unique_ptr<mock::OutputLayer> mOutputLayer2{new StrictMock<mock::OutputLayer>};
142 std::unique_ptr<mock::OutputLayer> mOutputLayer3{new StrictMock<mock::OutputLayer>};
143
144 StrictMock<mock::Layer> mLayer1;
145 StrictMock<mock::Layer> mLayer2;
146 StrictMock<mock::Layer> mLayer3;
147
148 StrictMock<mock::LayerFE> mLayer1FE;
149 StrictMock<mock::LayerFE> mLayer2FE;
150 StrictMock<mock::LayerFE> mLayer3FE;
151
152 LayerFECompositionState mLayer1FEState;
153 LayerFECompositionState mLayer2FEState;
154 LayerFECompositionState mLayer3FEState;
155};
156
Lloyd Piqueef958122019-02-05 18:00:12 -0800157const Rect OutputTest::kDefaultDisplaySize{100, 200};
158
Lloyd Pique17ca7422019-11-14 14:24:10 -0800159using ColorProfile = compositionengine::Output::ColorProfile;
160
161void dumpColorProfile(ColorProfile profile, std::string& result, const char* name) {
162 android::base::StringAppendF(&result, "%s (%s[%d] %s[%d] %s[%d] %s[%d]) ", name,
163 toString(profile.mode).c_str(), profile.mode,
164 toString(profile.dataspace).c_str(), profile.dataspace,
165 toString(profile.renderIntent).c_str(), profile.renderIntent,
166 toString(profile.colorSpaceAgnosticDataspace).c_str(),
167 profile.colorSpaceAgnosticDataspace);
168}
169
170// Checks for a ColorProfile match
171MATCHER_P(ColorProfileEq, expected, "") {
172 std::string buf;
173 buf.append("ColorProfiles are not equal\n");
174 dumpColorProfile(expected, buf, "expected value");
175 dumpColorProfile(arg, buf, "actual value");
176 *result_listener << buf;
177
178 return (expected.mode == arg.mode) && (expected.dataspace == arg.dataspace) &&
179 (expected.renderIntent == arg.renderIntent) &&
180 (expected.colorSpaceAgnosticDataspace == arg.colorSpaceAgnosticDataspace);
181}
182
Lloyd Pique66d68602019-02-13 14:23:31 -0800183/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700184 * Basic construction
185 */
186
Lloyd Pique31cb2942018-10-19 17:23:03 -0700187TEST_F(OutputTest, canInstantiateOutput) {
188 // The validation check checks each required component.
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700189 EXPECT_CALL(*mDisplayColorProfile, isValid()).WillOnce(Return(true));
Lloyd Pique31cb2942018-10-19 17:23:03 -0700190 EXPECT_CALL(*mRenderSurface, isValid()).WillOnce(Return(true));
191
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700192 EXPECT_TRUE(mOutput->isValid());
Lloyd Pique31cb2942018-10-19 17:23:03 -0700193
194 // If we take away the required components, it is no longer valid.
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700195 mOutput->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>());
Lloyd Pique31cb2942018-10-19 17:23:03 -0700196
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700197 EXPECT_CALL(*mDisplayColorProfile, isValid()).WillOnce(Return(true));
198
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700199 EXPECT_FALSE(mOutput->isValid());
Lloyd Pique31cb2942018-10-19 17:23:03 -0700200}
Lloyd Pique32cbe282018-10-19 13:09:22 -0700201
Lloyd Pique66d68602019-02-13 14:23:31 -0800202/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700203 * Output::setCompositionEnabled()
204 */
205
206TEST_F(OutputTest, setCompositionEnabledDoesNothingIfAlreadyEnabled) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700207 mOutput->editState().isEnabled = true;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700208
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700209 mOutput->setCompositionEnabled(true);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700210
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700211 EXPECT_TRUE(mOutput->getState().isEnabled);
212 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region()));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700213}
214
215TEST_F(OutputTest, setCompositionEnabledSetsEnabledAndDirtiesEntireOutput) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700216 mOutput->editState().isEnabled = false;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700217
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700218 mOutput->setCompositionEnabled(true);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700219
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700220 EXPECT_TRUE(mOutput->getState().isEnabled);
221 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700222}
223
224TEST_F(OutputTest, setCompositionEnabledSetsDisabledAndDirtiesEntireOutput) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700225 mOutput->editState().isEnabled = true;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700226
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700227 mOutput->setCompositionEnabled(false);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700228
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700229 EXPECT_FALSE(mOutput->getState().isEnabled);
230 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700231}
232
Lloyd Pique66d68602019-02-13 14:23:31 -0800233/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700234 * Output::setProjection()
235 */
236
237TEST_F(OutputTest, setProjectionTriviallyWorks) {
238 const ui::Transform transform{ui::Transform::ROT_180};
239 const int32_t orientation = 123;
240 const Rect frame{1, 2, 3, 4};
241 const Rect viewport{5, 6, 7, 8};
242 const Rect scissor{9, 10, 11, 12};
243 const bool needsFiltering = true;
244
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700245 mOutput->setProjection(transform, orientation, frame, viewport, scissor, needsFiltering);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700246
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700247 EXPECT_THAT(mOutput->getState().transform, TransformEq(transform));
248 EXPECT_EQ(orientation, mOutput->getState().orientation);
249 EXPECT_EQ(frame, mOutput->getState().frame);
250 EXPECT_EQ(viewport, mOutput->getState().viewport);
251 EXPECT_EQ(scissor, mOutput->getState().scissor);
252 EXPECT_EQ(needsFiltering, mOutput->getState().needsFiltering);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700253}
254
Lloyd Pique66d68602019-02-13 14:23:31 -0800255/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700256 * Output::setBounds()
257 */
258
259TEST_F(OutputTest, setBoundsSetsSizeAndDirtiesEntireOutput) {
Lloyd Piqueef958122019-02-05 18:00:12 -0800260 const ui::Size displaySize{200, 400};
Lloyd Pique31cb2942018-10-19 17:23:03 -0700261
262 EXPECT_CALL(*mRenderSurface, setDisplaySize(displaySize)).Times(1);
263 EXPECT_CALL(*mRenderSurface, getSize()).WillOnce(ReturnRef(displaySize));
264
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700265 mOutput->setBounds(displaySize);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700266
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700267 EXPECT_EQ(Rect(displaySize), mOutput->getState().bounds);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700268
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700269 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(Rect(displaySize))));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700270}
271
Lloyd Pique66d68602019-02-13 14:23:31 -0800272/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700273 * Output::setLayerStackFilter()
274 */
275
276TEST_F(OutputTest, setLayerStackFilterSetsFilterAndDirtiesEntireOutput) {
Lloyd Pique32cbe282018-10-19 13:09:22 -0700277 const uint32_t layerStack = 123u;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700278 mOutput->setLayerStackFilter(layerStack, true);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700279
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700280 EXPECT_TRUE(mOutput->getState().layerStackInternal);
281 EXPECT_EQ(layerStack, mOutput->getState().layerStackId);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700282
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700283 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700284}
285
Lloyd Pique66d68602019-02-13 14:23:31 -0800286/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700287 * Output::setColorTransform
288 */
289
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800290TEST_F(OutputTest, setColorTransformWithNoChangeFlaggedSkipsUpdates) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700291 mOutput->editState().colorTransformMatrix = kIdentity;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700292
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800293 // If no colorTransformMatrix is set the update should be skipped.
294 CompositionRefreshArgs refreshArgs;
295 refreshArgs.colorTransformMatrix = std::nullopt;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700296
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700297 mOutput->setColorTransform(refreshArgs);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700298
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800299 // The internal state should be unchanged
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700300 EXPECT_EQ(kIdentity, mOutput->getState().colorTransformMatrix);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800301
302 // No dirty region should be set
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700303 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region()));
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800304}
Lloyd Piqueef958122019-02-05 18:00:12 -0800305
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800306TEST_F(OutputTest, setColorTransformWithNoActualChangeSkipsUpdates) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700307 mOutput->editState().colorTransformMatrix = kIdentity;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700308
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800309 // Attempting to set the same colorTransformMatrix that is already set should
310 // also skip the update.
311 CompositionRefreshArgs refreshArgs;
312 refreshArgs.colorTransformMatrix = kIdentity;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700313
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700314 mOutput->setColorTransform(refreshArgs);
Lloyd Pique77f79a22019-04-29 15:55:40 -0700315
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800316 // The internal state should be unchanged
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700317 EXPECT_EQ(kIdentity, mOutput->getState().colorTransformMatrix);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800318
319 // No dirty region should be set
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700320 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region()));
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800321}
322
323TEST_F(OutputTest, setColorTransformPerformsUpdateToIdentity) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700324 mOutput->editState().colorTransformMatrix = kNonIdentityHalf;
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800325
326 // Setting a different colorTransformMatrix should perform the update.
327 CompositionRefreshArgs refreshArgs;
328 refreshArgs.colorTransformMatrix = kIdentity;
329
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700330 mOutput->setColorTransform(refreshArgs);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800331
332 // The internal state should have been updated
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700333 EXPECT_EQ(kIdentity, mOutput->getState().colorTransformMatrix);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800334
335 // The dirtyRegion should be set to the full display size
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700336 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800337}
Lloyd Pique77f79a22019-04-29 15:55:40 -0700338
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800339TEST_F(OutputTest, setColorTransformPerformsUpdateForIdentityToHalf) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700340 mOutput->editState().colorTransformMatrix = kIdentity;
Lloyd Pique77f79a22019-04-29 15:55:40 -0700341
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800342 // Setting a different colorTransformMatrix should perform the update.
343 CompositionRefreshArgs refreshArgs;
344 refreshArgs.colorTransformMatrix = kNonIdentityHalf;
Lloyd Pique77f79a22019-04-29 15:55:40 -0700345
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700346 mOutput->setColorTransform(refreshArgs);
Lloyd Piqueef958122019-02-05 18:00:12 -0800347
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800348 // The internal state should have been updated
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700349 EXPECT_EQ(kNonIdentityHalf, mOutput->getState().colorTransformMatrix);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800350
351 // The dirtyRegion should be set to the full display size
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700352 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800353}
354
355TEST_F(OutputTest, setColorTransformPerformsUpdateForHalfToQuarter) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700356 mOutput->editState().colorTransformMatrix = kNonIdentityHalf;
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800357
358 // Setting a different colorTransformMatrix should perform the update.
359 CompositionRefreshArgs refreshArgs;
360 refreshArgs.colorTransformMatrix = kNonIdentityQuarter;
361
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700362 mOutput->setColorTransform(refreshArgs);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800363
364 // The internal state should have been updated
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700365 EXPECT_EQ(kNonIdentityQuarter, mOutput->getState().colorTransformMatrix);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800366
367 // The dirtyRegion should be set to the full display size
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700368 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700369}
370
Lloyd Pique66d68602019-02-13 14:23:31 -0800371/*
Lloyd Pique17ca7422019-11-14 14:24:10 -0800372 * Output::setColorProfile
Lloyd Pique32cbe282018-10-19 13:09:22 -0700373 */
374
Lloyd Pique17ca7422019-11-14 14:24:10 -0800375using OutputSetColorProfileTest = OutputTest;
376
377TEST_F(OutputSetColorProfileTest, setsStateAndDirtiesOutputIfChanged) {
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800378 using ColorProfile = Output::ColorProfile;
379
Lloyd Piquef5275482019-01-29 18:42:42 -0800380 EXPECT_CALL(*mDisplayColorProfile,
381 getTargetDataspace(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
382 ui::Dataspace::UNKNOWN))
383 .WillOnce(Return(ui::Dataspace::UNKNOWN));
Lloyd Piqueef958122019-02-05 18:00:12 -0800384 EXPECT_CALL(*mRenderSurface, setBufferDataspace(ui::Dataspace::DISPLAY_P3)).Times(1);
Lloyd Pique31cb2942018-10-19 17:23:03 -0700385
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700386 mOutput->setColorProfile(ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
387 ui::RenderIntent::TONE_MAP_COLORIMETRIC,
388 ui::Dataspace::UNKNOWN});
Lloyd Pique32cbe282018-10-19 13:09:22 -0700389
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700390 EXPECT_EQ(ui::ColorMode::DISPLAY_P3, mOutput->getState().colorMode);
391 EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mOutput->getState().dataspace);
392 EXPECT_EQ(ui::RenderIntent::TONE_MAP_COLORIMETRIC, mOutput->getState().renderIntent);
393 EXPECT_EQ(ui::Dataspace::UNKNOWN, mOutput->getState().targetDataspace);
Lloyd Piquef5275482019-01-29 18:42:42 -0800394
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700395 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
Lloyd Piqueef958122019-02-05 18:00:12 -0800396}
397
Lloyd Pique17ca7422019-11-14 14:24:10 -0800398TEST_F(OutputSetColorProfileTest, doesNothingIfNoChange) {
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800399 using ColorProfile = Output::ColorProfile;
400
Lloyd Piquef5275482019-01-29 18:42:42 -0800401 EXPECT_CALL(*mDisplayColorProfile,
402 getTargetDataspace(ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
403 ui::Dataspace::UNKNOWN))
404 .WillOnce(Return(ui::Dataspace::UNKNOWN));
405
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700406 mOutput->editState().colorMode = ui::ColorMode::DISPLAY_P3;
407 mOutput->editState().dataspace = ui::Dataspace::DISPLAY_P3;
408 mOutput->editState().renderIntent = ui::RenderIntent::TONE_MAP_COLORIMETRIC;
409 mOutput->editState().targetDataspace = ui::Dataspace::UNKNOWN;
Lloyd Piqueef958122019-02-05 18:00:12 -0800410
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700411 mOutput->setColorProfile(ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
412 ui::RenderIntent::TONE_MAP_COLORIMETRIC,
413 ui::Dataspace::UNKNOWN});
Lloyd Piqueef958122019-02-05 18:00:12 -0800414
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700415 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region()));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700416}
417
Lloyd Pique66d68602019-02-13 14:23:31 -0800418/*
Lloyd Pique31cb2942018-10-19 17:23:03 -0700419 * Output::setRenderSurface()
420 */
421
422TEST_F(OutputTest, setRenderSurfaceResetsBounds) {
423 const ui::Size newDisplaySize{640, 480};
424
425 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
426 EXPECT_CALL(*renderSurface, getSize()).WillOnce(ReturnRef(newDisplaySize));
427
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700428 mOutput->setRenderSurface(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Pique31cb2942018-10-19 17:23:03 -0700429
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700430 EXPECT_EQ(Rect(newDisplaySize), mOutput->getState().bounds);
Lloyd Pique31cb2942018-10-19 17:23:03 -0700431}
432
Lloyd Pique66d68602019-02-13 14:23:31 -0800433/*
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000434 * Output::getDirtyRegion()
Lloyd Pique32cbe282018-10-19 13:09:22 -0700435 */
436
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000437TEST_F(OutputTest, getDirtyRegionWithRepaintEverythingTrue) {
438 const Rect viewport{100, 200};
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700439 mOutput->editState().viewport = viewport;
440 mOutput->editState().dirtyRegion.set(50, 300);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700441
442 {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700443 Region result = mOutput->getDirtyRegion(true);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700444
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000445 EXPECT_THAT(result, RegionEq(Region(viewport)));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700446 }
447}
448
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000449TEST_F(OutputTest, getDirtyRegionWithRepaintEverythingFalse) {
450 const Rect viewport{100, 200};
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700451 mOutput->editState().viewport = viewport;
452 mOutput->editState().dirtyRegion.set(50, 300);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700453
454 {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700455 Region result = mOutput->getDirtyRegion(false);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700456
457 // The dirtyRegion should be clipped to the display bounds.
458 EXPECT_THAT(result, RegionEq(Region(Rect(50, 200))));
459 }
Lloyd Pique32cbe282018-10-19 13:09:22 -0700460}
461
Lloyd Pique66d68602019-02-13 14:23:31 -0800462/*
Lloyd Piqueef36b002019-01-23 17:52:04 -0800463 * Output::belongsInOutput()
464 */
465
466TEST_F(OutputTest, belongsInOutputFiltersAsExpected) {
467 const uint32_t layerStack1 = 123u;
468 const uint32_t layerStack2 = 456u;
469
470 // If the output accepts layerStack1 and internal-only layers....
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700471 mOutput->setLayerStackFilter(layerStack1, true);
Lloyd Piqueef36b002019-01-23 17:52:04 -0800472
Lloyd Piquec6687342019-03-07 21:34:57 -0800473 // A layer with no layerStack does not belong to it, internal-only or not.
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700474 EXPECT_FALSE(mOutput->belongsInOutput(std::nullopt, false));
475 EXPECT_FALSE(mOutput->belongsInOutput(std::nullopt, true));
Lloyd Piquec6687342019-03-07 21:34:57 -0800476
Lloyd Piqueef36b002019-01-23 17:52:04 -0800477 // Any layer with layerStack1 belongs to it, internal-only or not.
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700478 EXPECT_TRUE(mOutput->belongsInOutput(layerStack1, false));
479 EXPECT_TRUE(mOutput->belongsInOutput(layerStack1, true));
480 EXPECT_FALSE(mOutput->belongsInOutput(layerStack2, true));
481 EXPECT_FALSE(mOutput->belongsInOutput(layerStack2, false));
Lloyd Piqueef36b002019-01-23 17:52:04 -0800482
483 // If the output accepts layerStack21 but not internal-only layers...
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700484 mOutput->setLayerStackFilter(layerStack1, false);
Lloyd Piqueef36b002019-01-23 17:52:04 -0800485
486 // Only non-internal layers with layerStack1 belong to it.
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700487 EXPECT_TRUE(mOutput->belongsInOutput(layerStack1, false));
488 EXPECT_FALSE(mOutput->belongsInOutput(layerStack1, true));
489 EXPECT_FALSE(mOutput->belongsInOutput(layerStack2, true));
490 EXPECT_FALSE(mOutput->belongsInOutput(layerStack2, false));
Lloyd Piqueef36b002019-01-23 17:52:04 -0800491}
492
Lloyd Pique66c20c42019-03-07 21:44:02 -0800493TEST_F(OutputTest, belongsInOutputFiltersLayersAsExpected) {
494 StrictMock<mock::Layer> layer;
Lloyd Pique9755fb72019-03-26 14:44:40 -0700495 LayerFECompositionState layerFEState;
Lloyd Pique66c20c42019-03-07 21:44:02 -0800496
Lloyd Pique9755fb72019-03-26 14:44:40 -0700497 EXPECT_CALL(layer, getFEState()).WillRepeatedly(ReturnRef(layerFEState));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800498
499 const uint32_t layerStack1 = 123u;
500 const uint32_t layerStack2 = 456u;
501
502 // If the output accepts layerStack1 and internal-only layers....
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700503 mOutput->setLayerStackFilter(layerStack1, true);
Lloyd Pique66c20c42019-03-07 21:44:02 -0800504
505 // A null layer pointer does not belong to the output
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700506 EXPECT_FALSE(mOutput->belongsInOutput(nullptr));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800507
508 // A layer with no layerStack does not belong to it, internal-only or not.
Lloyd Pique9755fb72019-03-26 14:44:40 -0700509 layerFEState.layerStackId = std::nullopt;
510 layerFEState.internalOnly = false;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700511 EXPECT_FALSE(mOutput->belongsInOutput(&layer));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800512
Lloyd Pique9755fb72019-03-26 14:44:40 -0700513 layerFEState.layerStackId = std::nullopt;
514 layerFEState.internalOnly = true;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700515 EXPECT_FALSE(mOutput->belongsInOutput(&layer));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800516
517 // Any layer with layerStack1 belongs to it, internal-only or not.
Lloyd Pique9755fb72019-03-26 14:44:40 -0700518 layerFEState.layerStackId = layerStack1;
519 layerFEState.internalOnly = false;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700520 EXPECT_TRUE(mOutput->belongsInOutput(&layer));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800521
Lloyd Pique9755fb72019-03-26 14:44:40 -0700522 layerFEState.layerStackId = layerStack1;
523 layerFEState.internalOnly = true;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700524 EXPECT_TRUE(mOutput->belongsInOutput(&layer));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800525
Lloyd Pique9755fb72019-03-26 14:44:40 -0700526 layerFEState.layerStackId = layerStack2;
527 layerFEState.internalOnly = true;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700528 EXPECT_FALSE(mOutput->belongsInOutput(&layer));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800529
Lloyd Pique9755fb72019-03-26 14:44:40 -0700530 layerFEState.layerStackId = layerStack2;
531 layerFEState.internalOnly = false;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700532 EXPECT_FALSE(mOutput->belongsInOutput(&layer));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800533
534 // If the output accepts layerStack1 but not internal-only layers...
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700535 mOutput->setLayerStackFilter(layerStack1, false);
Lloyd Pique66c20c42019-03-07 21:44:02 -0800536
537 // A null layer pointer does not belong to the output
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700538 EXPECT_FALSE(mOutput->belongsInOutput(nullptr));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800539
540 // Only non-internal layers with layerStack1 belong to it.
Lloyd Pique9755fb72019-03-26 14:44:40 -0700541 layerFEState.layerStackId = layerStack1;
542 layerFEState.internalOnly = false;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700543 EXPECT_TRUE(mOutput->belongsInOutput(&layer));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800544
Lloyd Pique9755fb72019-03-26 14:44:40 -0700545 layerFEState.layerStackId = layerStack1;
546 layerFEState.internalOnly = true;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700547 EXPECT_FALSE(mOutput->belongsInOutput(&layer));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800548
Lloyd Pique9755fb72019-03-26 14:44:40 -0700549 layerFEState.layerStackId = layerStack2;
550 layerFEState.internalOnly = true;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700551 EXPECT_FALSE(mOutput->belongsInOutput(&layer));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800552
Lloyd Pique9755fb72019-03-26 14:44:40 -0700553 layerFEState.layerStackId = layerStack2;
554 layerFEState.internalOnly = false;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700555 EXPECT_FALSE(mOutput->belongsInOutput(&layer));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800556}
557
Lloyd Pique66d68602019-02-13 14:23:31 -0800558/*
Lloyd Piquecc01a452018-12-04 17:24:00 -0800559 * Output::getOutputLayerForLayer()
560 */
561
562TEST_F(OutputTest, getOutputLayerForLayerWorks) {
563 mock::OutputLayer* outputLayer1 = new StrictMock<mock::OutputLayer>();
564 mock::OutputLayer* outputLayer2 = new StrictMock<mock::OutputLayer>();
565
Lloyd Pique01c77c12019-04-17 12:48:32 -0700566 mOutput->injectOutputLayerForTest(std::unique_ptr<OutputLayer>(outputLayer1));
567 mOutput->injectOutputLayerForTest(nullptr);
568 mOutput->injectOutputLayerForTest(std::unique_ptr<OutputLayer>(outputLayer2));
Lloyd Piquecc01a452018-12-04 17:24:00 -0800569
570 StrictMock<mock::Layer> layer;
571 StrictMock<mock::Layer> otherLayer;
572
573 // If the input layer matches the first OutputLayer, it will be returned.
574 EXPECT_CALL(*outputLayer1, getLayer()).WillOnce(ReturnRef(layer));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700575 EXPECT_EQ(outputLayer1, mOutput->getOutputLayerForLayer(&layer));
Lloyd Piquecc01a452018-12-04 17:24:00 -0800576
577 // If the input layer matches the second OutputLayer, it will be returned.
578 EXPECT_CALL(*outputLayer1, getLayer()).WillOnce(ReturnRef(otherLayer));
579 EXPECT_CALL(*outputLayer2, getLayer()).WillOnce(ReturnRef(layer));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700580 EXPECT_EQ(outputLayer2, mOutput->getOutputLayerForLayer(&layer));
Lloyd Piquecc01a452018-12-04 17:24:00 -0800581
582 // If the input layer does not match an output layer, null will be returned.
583 EXPECT_CALL(*outputLayer1, getLayer()).WillOnce(ReturnRef(otherLayer));
584 EXPECT_CALL(*outputLayer2, getLayer()).WillOnce(ReturnRef(otherLayer));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700585 EXPECT_EQ(nullptr, mOutput->getOutputLayerForLayer(&layer));
Lloyd Piquecc01a452018-12-04 17:24:00 -0800586}
587
Lloyd Pique66d68602019-02-13 14:23:31 -0800588/*
Lloyd Piquec9e60032019-11-14 11:47:26 -0800589 * Output::setReleasedLayers()
590 */
591
592using OutputSetReleasedLayersTest = OutputTest;
593
594TEST_F(OutputSetReleasedLayersTest, setReleasedLayersTakesGivenLayers) {
595 sp<StrictMock<mock::LayerFE>> layer1FE{new StrictMock<mock::LayerFE>()};
596 sp<StrictMock<mock::LayerFE>> layer2FE{new StrictMock<mock::LayerFE>()};
597 sp<StrictMock<mock::LayerFE>> layer3FE{new StrictMock<mock::LayerFE>()};
598
599 Output::ReleasedLayers layers;
600 layers.push_back(layer1FE);
601 layers.push_back(layer2FE);
602 layers.push_back(layer3FE);
603
604 mOutput->setReleasedLayers(std::move(layers));
605
606 const auto& setLayers = mOutput->getReleasedLayersForTest();
607 ASSERT_EQ(3u, setLayers.size());
608 ASSERT_EQ(layer1FE.get(), setLayers[0].promote().get());
609 ASSERT_EQ(layer2FE.get(), setLayers[1].promote().get());
610 ASSERT_EQ(layer3FE.get(), setLayers[2].promote().get());
611}
612
613/*
Lloyd Piquec0ee6ba2019-11-14 12:55:53 -0800614 * Output::updateLayerStateFromFE()
615 */
616
617using OutputUpdateLayerStateFromFETest = OutputLatchFEStateTest;
618
619TEST_F(OutputUpdateLayerStateFromFETest, handlesNoOutputLayerCase) {
620 CompositionRefreshArgs refreshArgs;
621
622 mOutput->updateLayerStateFromFE(refreshArgs);
623}
624
625TEST_F(OutputUpdateLayerStateFromFETest, latchesContentStateForAllContainedLayers) {
626 EXPECT_CALL(mLayer1FE,
627 latchCompositionState(Ref(mLayer1FEState), LayerFE::StateSubset::Content));
628 EXPECT_CALL(mLayer2FE,
629 latchCompositionState(Ref(mLayer2FEState), LayerFE::StateSubset::Content));
630 EXPECT_CALL(mLayer3FE,
631 latchCompositionState(Ref(mLayer3FEState), LayerFE::StateSubset::Content));
632
633 // Note: Must be performed after any expectations on these mocks
634 injectLayer(std::move(mOutputLayer1));
635 injectLayer(std::move(mOutputLayer2));
636 injectLayer(std::move(mOutputLayer3));
637
638 CompositionRefreshArgs refreshArgs;
639 refreshArgs.updatingGeometryThisFrame = false;
640
641 mOutput->updateLayerStateFromFE(refreshArgs);
642}
643
644TEST_F(OutputUpdateLayerStateFromFETest, latchesGeometryAndContentStateForAllContainedLayers) {
645 EXPECT_CALL(mLayer1FE,
646 latchCompositionState(Ref(mLayer1FEState),
647 LayerFE::StateSubset::GeometryAndContent));
648 EXPECT_CALL(mLayer2FE,
649 latchCompositionState(Ref(mLayer2FEState),
650 LayerFE::StateSubset::GeometryAndContent));
651 EXPECT_CALL(mLayer3FE,
652 latchCompositionState(Ref(mLayer3FEState),
653 LayerFE::StateSubset::GeometryAndContent));
654
655 // Note: Must be performed after any expectations on these mocks
656 injectLayer(std::move(mOutputLayer1));
657 injectLayer(std::move(mOutputLayer2));
658 injectLayer(std::move(mOutputLayer3));
659
660 CompositionRefreshArgs refreshArgs;
661 refreshArgs.updatingGeometryThisFrame = true;
662
663 mOutput->updateLayerStateFromFE(refreshArgs);
664}
665
666/*
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800667 * Output::updateAndWriteCompositionState()
668 */
669
Lloyd Piqueef63b612019-11-14 13:19:56 -0800670using OutputUpdateAndWriteCompositionStateTest = OutputLatchFEStateTest;
671
672TEST_F(OutputUpdateAndWriteCompositionStateTest, doesNothingIfLayers) {
673 mOutput->editState().isEnabled = true;
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800674
675 CompositionRefreshArgs args;
676 mOutput->updateAndWriteCompositionState(args);
677}
678
Lloyd Piqueef63b612019-11-14 13:19:56 -0800679TEST_F(OutputUpdateAndWriteCompositionStateTest, doesNothingIfOutputNotEnabled) {
680 mOutput->editState().isEnabled = false;
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800681
Lloyd Piqueef63b612019-11-14 13:19:56 -0800682 injectLayer(std::move(mOutputLayer1));
683 injectLayer(std::move(mOutputLayer2));
684 injectLayer(std::move(mOutputLayer3));
685
686 CompositionRefreshArgs args;
687 mOutput->updateAndWriteCompositionState(args);
688}
689
690TEST_F(OutputUpdateAndWriteCompositionStateTest, updatesLayerContentForAllLayers) {
691 EXPECT_CALL(*mOutputLayer1, updateCompositionState(false, false));
692 EXPECT_CALL(*mOutputLayer1, writeStateToHWC(false));
693 EXPECT_CALL(*mOutputLayer2, updateCompositionState(false, false));
694 EXPECT_CALL(*mOutputLayer2, writeStateToHWC(false));
695 EXPECT_CALL(*mOutputLayer3, updateCompositionState(false, false));
696 EXPECT_CALL(*mOutputLayer3, writeStateToHWC(false));
697
698 injectLayer(std::move(mOutputLayer1));
699 injectLayer(std::move(mOutputLayer2));
700 injectLayer(std::move(mOutputLayer3));
701
702 mOutput->editState().isEnabled = true;
703
704 CompositionRefreshArgs args;
705 args.updatingGeometryThisFrame = false;
706 args.devOptForceClientComposition = false;
707 mOutput->updateAndWriteCompositionState(args);
708}
709
710TEST_F(OutputUpdateAndWriteCompositionStateTest, updatesLayerGeometryAndContentForAllLayers) {
711 EXPECT_CALL(*mOutputLayer1, updateCompositionState(true, false));
712 EXPECT_CALL(*mOutputLayer1, writeStateToHWC(true));
713 EXPECT_CALL(*mOutputLayer2, updateCompositionState(true, false));
714 EXPECT_CALL(*mOutputLayer2, writeStateToHWC(true));
715 EXPECT_CALL(*mOutputLayer3, updateCompositionState(true, false));
716 EXPECT_CALL(*mOutputLayer3, writeStateToHWC(true));
717
718 injectLayer(std::move(mOutputLayer1));
719 injectLayer(std::move(mOutputLayer2));
720 injectLayer(std::move(mOutputLayer3));
721
722 mOutput->editState().isEnabled = true;
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800723
724 CompositionRefreshArgs args;
725 args.updatingGeometryThisFrame = true;
Lloyd Piqueef63b612019-11-14 13:19:56 -0800726 args.devOptForceClientComposition = false;
727 mOutput->updateAndWriteCompositionState(args);
728}
729
730TEST_F(OutputUpdateAndWriteCompositionStateTest, forcesClientCompositionForAllLayers) {
731 EXPECT_CALL(*mOutputLayer1, updateCompositionState(false, true));
732 EXPECT_CALL(*mOutputLayer1, writeStateToHWC(false));
733 EXPECT_CALL(*mOutputLayer2, updateCompositionState(false, true));
734 EXPECT_CALL(*mOutputLayer2, writeStateToHWC(false));
735 EXPECT_CALL(*mOutputLayer3, updateCompositionState(false, true));
736 EXPECT_CALL(*mOutputLayer3, writeStateToHWC(false));
737
738 injectLayer(std::move(mOutputLayer1));
739 injectLayer(std::move(mOutputLayer2));
740 injectLayer(std::move(mOutputLayer3));
741
742 mOutput->editState().isEnabled = true;
743
744 CompositionRefreshArgs args;
745 args.updatingGeometryThisFrame = false;
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800746 args.devOptForceClientComposition = true;
747 mOutput->updateAndWriteCompositionState(args);
748}
749
750/*
Lloyd Pique66d68602019-02-13 14:23:31 -0800751 * Output::prepareFrame()
752 */
753
754struct OutputPrepareFrameTest : public testing::Test {
Lloyd Piquefaa3f192019-11-14 14:05:09 -0800755 struct OutputPartialMock : public OutputPartialMockBase {
Lloyd Pique739afaf2019-11-21 16:40:05 -0800756 // Sets up the helper functions called by the function under test to use
757 // mock implementations.
Lloyd Pique66d68602019-02-13 14:23:31 -0800758 MOCK_METHOD0(chooseCompositionStrategy, void());
759 };
760
761 OutputPrepareFrameTest() {
762 mOutput.setDisplayColorProfileForTest(
763 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
764 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
765 }
766
767 StrictMock<mock::CompositionEngine> mCompositionEngine;
768 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
769 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700770 StrictMock<OutputPartialMock> mOutput;
Lloyd Pique66d68602019-02-13 14:23:31 -0800771};
772
773TEST_F(OutputPrepareFrameTest, takesEarlyOutIfNotEnabled) {
774 mOutput.editState().isEnabled = false;
775
776 mOutput.prepareFrame();
777}
778
779TEST_F(OutputPrepareFrameTest, delegatesToChooseCompositionStrategyAndRenderSurface) {
780 mOutput.editState().isEnabled = true;
781 mOutput.editState().usesClientComposition = false;
782 mOutput.editState().usesDeviceComposition = true;
783
784 EXPECT_CALL(mOutput, chooseCompositionStrategy()).Times(1);
785 EXPECT_CALL(*mRenderSurface, prepareFrame(false, true));
786
787 mOutput.prepareFrame();
788}
789
790// Note: Use OutputTest and not OutputPrepareFrameTest, so the real
791// base chooseCompositionStrategy() is invoked.
792TEST_F(OutputTest, prepareFrameSetsClientCompositionOnlyByDefault) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700793 mOutput->editState().isEnabled = true;
794 mOutput->editState().usesClientComposition = false;
795 mOutput->editState().usesDeviceComposition = true;
Lloyd Pique66d68602019-02-13 14:23:31 -0800796
797 EXPECT_CALL(*mRenderSurface, prepareFrame(true, false));
798
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700799 mOutput->prepareFrame();
Lloyd Pique66d68602019-02-13 14:23:31 -0800800
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700801 EXPECT_TRUE(mOutput->getState().usesClientComposition);
802 EXPECT_FALSE(mOutput->getState().usesDeviceComposition);
Lloyd Pique66d68602019-02-13 14:23:31 -0800803}
804
Lloyd Pique56eba802019-08-28 15:45:25 -0700805/*
Lloyd Piqueb62cebc2019-11-20 18:31:52 -0800806 * Output::prepare()
807 */
808
809struct OutputPrepareTest : public testing::Test {
810 struct OutputPartialMock : public OutputPartialMockBase {
811 // Sets up the helper functions called by the function under test to use
812 // mock implementations.
813 MOCK_METHOD2(rebuildLayerStacks,
814 void(const compositionengine::CompositionRefreshArgs&,
815 compositionengine::LayerFESet&));
816 };
817
818 StrictMock<OutputPartialMock> mOutput;
819 CompositionRefreshArgs mRefreshArgs;
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -0800820 LayerFESet mGeomSnapshots;
Lloyd Piqueb62cebc2019-11-20 18:31:52 -0800821};
822
823TEST_F(OutputPrepareTest, justInvokesRebuildLayerStacks) {
824 InSequence seq;
825 EXPECT_CALL(mOutput, rebuildLayerStacks(Ref(mRefreshArgs), Ref(mGeomSnapshots)));
826
827 mOutput.prepare(mRefreshArgs, mGeomSnapshots);
828}
829
830/*
831 * Output::rebuildLayerStacks()
832 */
833
834struct OutputRebuildLayerStacksTest : public testing::Test {
835 struct OutputPartialMock : public OutputPartialMockBase {
836 // Sets up the helper functions called by the function under test to use
837 // mock implementations.
838 MOCK_METHOD2(collectVisibleLayers,
839 void(const compositionengine::CompositionRefreshArgs&,
840 compositionengine::Output::CoverageState&));
841 };
842
843 OutputRebuildLayerStacksTest() {
844 mOutput.mState.isEnabled = true;
845 mOutput.mState.transform = kIdentityTransform;
846 mOutput.mState.bounds = kOutputBounds;
847
848 mRefreshArgs.updatingOutputGeometryThisFrame = true;
849
850 mCoverageAboveCoveredLayersToSet = Region(Rect(0, 0, 10, 10));
851
852 EXPECT_CALL(mOutput, collectVisibleLayers(Ref(mRefreshArgs), _))
853 .WillRepeatedly(Invoke(this, &OutputRebuildLayerStacksTest::setTestCoverageValues));
854 }
855
856 void setTestCoverageValues(const CompositionRefreshArgs&,
857 compositionengine::Output::CoverageState& state) {
858 state.aboveCoveredLayers = mCoverageAboveCoveredLayersToSet;
859 state.aboveOpaqueLayers = mCoverageAboveOpaqueLayersToSet;
860 state.dirtyRegion = mCoverageDirtyRegionToSet;
861 }
862
863 static const ui::Transform kIdentityTransform;
864 static const ui::Transform kRotate90Transform;
865 static const Rect kOutputBounds;
866
867 StrictMock<OutputPartialMock> mOutput;
868 CompositionRefreshArgs mRefreshArgs;
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -0800869 LayerFESet mGeomSnapshots;
Lloyd Piqueb62cebc2019-11-20 18:31:52 -0800870 Region mCoverageAboveCoveredLayersToSet;
871 Region mCoverageAboveOpaqueLayersToSet;
872 Region mCoverageDirtyRegionToSet;
873};
874
875const ui::Transform OutputRebuildLayerStacksTest::kIdentityTransform{TR_IDENT, 1920, 1080};
876const ui::Transform OutputRebuildLayerStacksTest::kRotate90Transform{TR_ROT_90, 1920, 1080};
877const Rect OutputRebuildLayerStacksTest::kOutputBounds{0, 0, 1920, 1080};
878
879TEST_F(OutputRebuildLayerStacksTest, doesNothingIfNotEnabled) {
880 mOutput.mState.isEnabled = false;
881
882 mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
883}
884
885TEST_F(OutputRebuildLayerStacksTest, doesNothingIfNotUpdatingGeometryThisFrame) {
886 mRefreshArgs.updatingOutputGeometryThisFrame = false;
887
888 mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
889}
890
891TEST_F(OutputRebuildLayerStacksTest, computesUndefinedRegionWithNoRotationAndFullCoverage) {
892 mOutput.mState.transform = kIdentityTransform;
893
894 mCoverageAboveOpaqueLayersToSet = Region(Rect(0, 0, 1920, 1080));
895
896 mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
897
898 EXPECT_THAT(mOutput.mState.undefinedRegion, RegionEq(Region(Rect(0, 0, 0, 0))));
899}
900
901TEST_F(OutputRebuildLayerStacksTest, computesUndefinedRegionWithNoRotationAndPartialCoverage) {
902 mOutput.mState.transform = kIdentityTransform;
903
904 mCoverageAboveOpaqueLayersToSet = Region(Rect(0, 0, 960, 1080));
905
906 mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
907
908 EXPECT_THAT(mOutput.mState.undefinedRegion, RegionEq(Region(Rect(960, 0, 1920, 1080))));
909}
910
911TEST_F(OutputRebuildLayerStacksTest, computesUndefinedRegionWith90RotationAndFullCoverage) {
912 mOutput.mState.transform = kRotate90Transform;
913
914 mCoverageAboveOpaqueLayersToSet = Region(Rect(0, 0, 1080, 1920));
915
916 mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
917
918 EXPECT_THAT(mOutput.mState.undefinedRegion, RegionEq(Region(Rect(0, 0, 0, 0))));
919}
920
921TEST_F(OutputRebuildLayerStacksTest, computesUndefinedRegionWith90RotationAndPartialCoverage) {
922 mOutput.mState.transform = kRotate90Transform;
923
924 mCoverageAboveOpaqueLayersToSet = Region(Rect(0, 0, 1080, 960));
925
926 mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
927
928 EXPECT_THAT(mOutput.mState.undefinedRegion, RegionEq(Region(Rect(0, 0, 960, 1080))));
929}
930
931TEST_F(OutputRebuildLayerStacksTest, addsToDirtyRegionWithNoRotation) {
932 mOutput.mState.transform = kIdentityTransform;
933 mOutput.mState.dirtyRegion = Region(Rect(960, 0, 1920, 1080));
934
935 mCoverageDirtyRegionToSet = Region(Rect(0, 0, 960, 1080));
936
937 mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
938
939 EXPECT_THAT(mOutput.mState.dirtyRegion, RegionEq(Region(Rect(0, 0, 1920, 1080))));
940}
941
942TEST_F(OutputRebuildLayerStacksTest, addsToDirtyRegionWith90Rotation) {
943 mOutput.mState.transform = kRotate90Transform;
944 mOutput.mState.dirtyRegion = Region(Rect(0, 960, 1080, 1920));
945
946 mCoverageDirtyRegionToSet = Region(Rect(0, 0, 1080, 960));
947
948 mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
949
950 EXPECT_THAT(mOutput.mState.dirtyRegion, RegionEq(Region(Rect(0, 0, 1080, 1920))));
951}
952
953/*
954 * Output::collectVisibleLayers()
955 */
956
Lloyd Pique1ef93222019-11-21 16:41:53 -0800957struct OutputCollectVisibleLayersTest : public testing::Test {
958 struct OutputPartialMock : public OutputPartialMockBase {
959 // Sets up the helper functions called by the function under test to use
960 // mock implementations.
961 MOCK_METHOD2(ensureOutputLayerIfVisible,
962 void(std::shared_ptr<compositionengine::Layer>,
963 compositionengine::Output::CoverageState&));
964 MOCK_METHOD1(setReleasedLayers, void(const compositionengine::CompositionRefreshArgs&));
965 MOCK_METHOD0(finalizePendingOutputLayers, void());
966 };
967
968 struct Layer {
969 Layer() {
970 EXPECT_CALL(outputLayer, getState()).WillRepeatedly(ReturnRef(outputLayerState));
971 EXPECT_CALL(outputLayer, editState()).WillRepeatedly(ReturnRef(outputLayerState));
972 }
973
974 StrictMock<mock::OutputLayer> outputLayer;
975 std::shared_ptr<StrictMock<mock::Layer>> layer{new StrictMock<mock::Layer>()};
976 impl::OutputLayerCompositionState outputLayerState;
977 };
978
979 OutputCollectVisibleLayersTest() {
980 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(3));
981 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0))
982 .WillRepeatedly(Return(&mLayer1.outputLayer));
983 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1))
984 .WillRepeatedly(Return(&mLayer2.outputLayer));
985 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(2))
986 .WillRepeatedly(Return(&mLayer3.outputLayer));
987
988 mRefreshArgs.layers.push_back(mLayer1.layer);
989 mRefreshArgs.layers.push_back(mLayer2.layer);
990 mRefreshArgs.layers.push_back(mLayer3.layer);
991 }
992
993 StrictMock<OutputPartialMock> mOutput;
994 CompositionRefreshArgs mRefreshArgs;
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -0800995 LayerFESet mGeomSnapshots;
996 Output::CoverageState mCoverageState{mGeomSnapshots};
Lloyd Pique1ef93222019-11-21 16:41:53 -0800997 Layer mLayer1;
998 Layer mLayer2;
999 Layer mLayer3;
1000};
1001
1002TEST_F(OutputCollectVisibleLayersTest, doesMinimalWorkIfNoLayers) {
1003 mRefreshArgs.layers.clear();
1004 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0));
1005
1006 EXPECT_CALL(mOutput, setReleasedLayers(Ref(mRefreshArgs)));
1007 EXPECT_CALL(mOutput, finalizePendingOutputLayers());
1008
1009 mOutput.collectVisibleLayers(mRefreshArgs, mCoverageState);
1010}
1011
1012TEST_F(OutputCollectVisibleLayersTest, processesCandidateLayersReversedAndSetsOutputLayerZ) {
1013 // Enforce a call order sequence for this test.
1014 InSequence seq;
1015
1016 // Layer coverage is evaluated from front to back!
1017 EXPECT_CALL(mOutput, ensureOutputLayerIfVisible(Eq(mLayer3.layer), Ref(mCoverageState)));
1018 EXPECT_CALL(mOutput, ensureOutputLayerIfVisible(Eq(mLayer2.layer), Ref(mCoverageState)));
1019 EXPECT_CALL(mOutput, ensureOutputLayerIfVisible(Eq(mLayer1.layer), Ref(mCoverageState)));
1020
1021 EXPECT_CALL(mOutput, setReleasedLayers(Ref(mRefreshArgs)));
1022 EXPECT_CALL(mOutput, finalizePendingOutputLayers());
1023
1024 mOutput.collectVisibleLayers(mRefreshArgs, mCoverageState);
1025
1026 // Ensure all output layers have been assigned a simple/flattened z-order.
1027 EXPECT_EQ(0u, mLayer1.outputLayerState.z);
1028 EXPECT_EQ(1u, mLayer2.outputLayerState.z);
1029 EXPECT_EQ(2u, mLayer3.outputLayerState.z);
1030}
Lloyd Piqueb62cebc2019-11-20 18:31:52 -08001031
1032/*
1033 * Output::ensureOutputLayerIfVisible()
1034 */
1035
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001036struct OutputEnsureOutputLayerIfVisibleTest : public testing::Test {
1037 struct OutputPartialMock : public OutputPartialMockBase {
1038 // Sets up the helper functions called by the function under test to use
1039 // mock implementations.
1040 MOCK_CONST_METHOD1(belongsInOutput, bool(const compositionengine::Layer*));
1041 MOCK_CONST_METHOD1(getOutputLayerOrderedByZByIndex, OutputLayer*(size_t));
1042 MOCK_METHOD3(ensureOutputLayer,
1043 compositionengine::OutputLayer*(
1044 std::optional<size_t>,
1045 const std::shared_ptr<compositionengine::Layer>&, const sp<LayerFE>&));
1046 };
1047
1048 OutputEnsureOutputLayerIfVisibleTest() {
1049 EXPECT_CALL(*mLayer, getLayerFE()).WillRepeatedly(Return(mLayerFE));
1050 EXPECT_CALL(*mLayer, getFEState()).WillRepeatedly(ReturnRef(mLayerFEState));
1051 EXPECT_CALL(*mLayer, editFEState()).WillRepeatedly(ReturnRef(mLayerFEState));
1052
1053 EXPECT_CALL(mOutput, belongsInOutput(mLayer.get())).WillRepeatedly(Return(true));
1054 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(1));
1055 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u))
1056 .WillRepeatedly(Return(&mOutputLayer));
1057
1058 EXPECT_CALL(mOutputLayer, getState()).WillRepeatedly(ReturnRef(mOutputLayerState));
1059 EXPECT_CALL(mOutputLayer, editState()).WillRepeatedly(ReturnRef(mOutputLayerState));
1060 EXPECT_CALL(mOutputLayer, getLayer()).WillRepeatedly(ReturnRef(*mLayer.get()));
1061
1062 mOutput.mState.bounds = Rect(0, 0, 200, 300);
1063 mOutput.mState.viewport = Rect(0, 0, 200, 300);
1064 mOutput.mState.transform = ui::Transform(TR_IDENT, 200, 300);
1065
1066 mLayerFEState.isVisible = true;
1067 mLayerFEState.isOpaque = true;
1068 mLayerFEState.contentDirty = true;
1069 mLayerFEState.geomLayerBounds = FloatRect{0, 0, 100, 200};
1070 mLayerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
1071 mLayerFEState.transparentRegionHint = Region(Rect(0, 0, 100, 100));
1072
1073 mOutputLayerState.visibleRegion = Region(Rect(0, 0, 50, 200));
1074 mOutputLayerState.coveredRegion = Region(Rect(50, 0, 100, 200));
1075
1076 mGeomSnapshots.insert(mLayerFE);
1077 }
1078
1079 static const Region kEmptyRegion;
1080 static const Region kFullBoundsNoRotation;
1081 static const Region kRightHalfBoundsNoRotation;
1082 static const Region kLowerHalfBoundsNoRotation;
1083 static const Region kFullBounds90Rotation;
1084
1085 StrictMock<OutputPartialMock> mOutput;
1086 LayerFESet mGeomSnapshots;
1087 Output::CoverageState mCoverageState{mGeomSnapshots};
1088
1089 std::shared_ptr<mock::Layer> mLayer{new StrictMock<mock::Layer>()};
1090 sp<StrictMock<mock::LayerFE>> mLayerFE{new StrictMock<mock::LayerFE>()};
1091 LayerFECompositionState mLayerFEState;
1092 mock::OutputLayer mOutputLayer;
1093 impl::OutputLayerCompositionState mOutputLayerState;
1094};
1095
1096const Region OutputEnsureOutputLayerIfVisibleTest::kEmptyRegion = Region(Rect(0, 0, 0, 0));
1097const Region OutputEnsureOutputLayerIfVisibleTest::kFullBoundsNoRotation =
1098 Region(Rect(0, 0, 100, 200));
1099const Region OutputEnsureOutputLayerIfVisibleTest::kRightHalfBoundsNoRotation =
1100 Region(Rect(0, 100, 100, 200));
1101const Region OutputEnsureOutputLayerIfVisibleTest::kLowerHalfBoundsNoRotation =
1102 Region(Rect(50, 0, 100, 200));
1103const Region OutputEnsureOutputLayerIfVisibleTest::kFullBounds90Rotation =
1104 Region(Rect(0, 0, 200, 100));
1105
1106TEST_F(OutputEnsureOutputLayerIfVisibleTest, doesNothingIfNoLayerFE) {
1107 EXPECT_CALL(*mLayer, getLayerFE).WillOnce(Return(sp<LayerFE>()));
1108
1109 mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState);
1110}
1111
1112TEST_F(OutputEnsureOutputLayerIfVisibleTest, performsGeomLatchBeforeCheckingIfLayerBelongs) {
1113 EXPECT_CALL(mOutput, belongsInOutput(mLayer.get())).WillOnce(Return(false));
1114 EXPECT_CALL(*mLayerFE.get(),
1115 latchCompositionState(Ref(mLayerFEState),
1116 compositionengine::LayerFE::StateSubset::BasicGeometry));
1117
1118 mGeomSnapshots.clear();
1119
1120 mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState);
1121}
1122
1123TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1124 skipsLatchIfAlreadyLatchedBeforeCheckingIfLayerBelongs) {
1125 EXPECT_CALL(mOutput, belongsInOutput(mLayer.get())).WillOnce(Return(false));
1126
1127 mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState);
1128}
1129
1130TEST_F(OutputEnsureOutputLayerIfVisibleTest, takesEarlyOutIfLayerNotVisible) {
1131 mLayerFEState.isVisible = false;
1132
1133 mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState);
1134}
1135
1136TEST_F(OutputEnsureOutputLayerIfVisibleTest, takesEarlyOutIfLayerHasEmptyVisibleRegion) {
1137 mLayerFEState.geomLayerBounds = FloatRect{0, 0, 0, 0};
1138
1139 mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState);
1140}
1141
1142TEST_F(OutputEnsureOutputLayerIfVisibleTest, takesNotSoEarlyOutifDrawRegionEmpty) {
1143 mOutput.mState.bounds = Rect(0, 0, 0, 0);
1144
1145 mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState);
1146}
1147
1148TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1149 handlesCreatingOutputLayerForOpaqueDirtyNotRotatedLayer) {
1150 mLayerFEState.isOpaque = true;
1151 mLayerFEState.contentDirty = true;
1152 mLayerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
1153
1154 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
1155 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer), Eq(mLayerFE)))
1156 .WillOnce(Return(&mOutputLayer));
1157
1158 mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState);
1159
1160 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1161 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1162 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
1163
1164 EXPECT_THAT(mOutputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1165 EXPECT_THAT(mOutputLayerState.visibleNonTransparentRegion, RegionEq(kFullBoundsNoRotation));
1166 EXPECT_THAT(mOutputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1167 EXPECT_THAT(mOutputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
1168}
1169
1170TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1171 handlesUpdatingOutputLayerForOpaqueDirtyNotRotatedLayer) {
1172 mLayerFEState.isOpaque = true;
1173 mLayerFEState.contentDirty = true;
1174 mLayerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
1175
1176 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer), Eq(mLayerFE)))
1177 .WillOnce(Return(&mOutputLayer));
1178
1179 mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState);
1180
1181 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1182 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1183 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
1184
1185 EXPECT_THAT(mOutputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1186 EXPECT_THAT(mOutputLayerState.visibleNonTransparentRegion, RegionEq(kFullBoundsNoRotation));
1187 EXPECT_THAT(mOutputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1188 EXPECT_THAT(mOutputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
1189}
1190
1191TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1192 handlesCreatingOutputLayerForTransparentDirtyNotRotatedLayer) {
1193 mLayerFEState.isOpaque = false;
1194 mLayerFEState.contentDirty = true;
1195 mLayerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
1196
1197 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
1198 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer), Eq(mLayerFE)))
1199 .WillOnce(Return(&mOutputLayer));
1200
1201 mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState);
1202
1203 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1204 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1205 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kEmptyRegion));
1206
1207 EXPECT_THAT(mOutputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1208 EXPECT_THAT(mOutputLayerState.visibleNonTransparentRegion,
1209 RegionEq(kRightHalfBoundsNoRotation));
1210 EXPECT_THAT(mOutputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1211 EXPECT_THAT(mOutputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
1212}
1213
1214TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1215 handlesUpdatingOutputLayerForTransparentDirtyNotRotatedLayer) {
1216 mLayerFEState.isOpaque = false;
1217 mLayerFEState.contentDirty = true;
1218 mLayerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
1219
1220 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer), Eq(mLayerFE)))
1221 .WillOnce(Return(&mOutputLayer));
1222
1223 mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState);
1224
1225 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1226 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1227 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kEmptyRegion));
1228
1229 EXPECT_THAT(mOutputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1230 EXPECT_THAT(mOutputLayerState.visibleNonTransparentRegion,
1231 RegionEq(kRightHalfBoundsNoRotation));
1232 EXPECT_THAT(mOutputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1233 EXPECT_THAT(mOutputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
1234}
1235
1236TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1237 handlesCreatingOutputLayerForOpaqueNonDirtyNotRotatedLayer) {
1238 mLayerFEState.isOpaque = true;
1239 mLayerFEState.contentDirty = false;
1240 mLayerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
1241
1242 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
1243 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer), Eq(mLayerFE)))
1244 .WillOnce(Return(&mOutputLayer));
1245
1246 mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState);
1247
1248 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1249 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1250 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
1251
1252 EXPECT_THAT(mOutputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1253 EXPECT_THAT(mOutputLayerState.visibleNonTransparentRegion, RegionEq(kFullBoundsNoRotation));
1254 EXPECT_THAT(mOutputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1255 EXPECT_THAT(mOutputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
1256}
1257
1258TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1259 handlesUpdatingOutputLayerForOpaqueNonDirtyNotRotatedLayer) {
1260 mLayerFEState.isOpaque = true;
1261 mLayerFEState.contentDirty = false;
1262 mLayerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
1263
1264 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer), Eq(mLayerFE)))
1265 .WillOnce(Return(&mOutputLayer));
1266
1267 mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState);
1268
1269 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kLowerHalfBoundsNoRotation));
1270 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1271 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
1272
1273 EXPECT_THAT(mOutputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1274 EXPECT_THAT(mOutputLayerState.visibleNonTransparentRegion, RegionEq(kFullBoundsNoRotation));
1275 EXPECT_THAT(mOutputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1276 EXPECT_THAT(mOutputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
1277}
1278
1279TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1280 handlesCreatingOutputLayerForOpaqueDirtyRotated90Layer) {
1281 mLayerFEState.isOpaque = true;
1282 mLayerFEState.contentDirty = true;
1283 mLayerFEState.geomLayerBounds = FloatRect{0, 0, 200, 100};
1284 mLayerFEState.geomLayerTransform = ui::Transform(TR_ROT_90, 100, 200);
1285 mOutputLayerState.visibleRegion = Region(Rect(0, 0, 100, 100));
1286 mOutputLayerState.coveredRegion = Region(Rect(100, 0, 200, 100));
1287
1288 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
1289 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer), Eq(mLayerFE)))
1290 .WillOnce(Return(&mOutputLayer));
1291
1292 mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState);
1293
1294 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1295 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1296 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
1297
1298 EXPECT_THAT(mOutputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1299 EXPECT_THAT(mOutputLayerState.visibleNonTransparentRegion, RegionEq(kFullBoundsNoRotation));
1300 EXPECT_THAT(mOutputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1301 EXPECT_THAT(mOutputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
1302}
1303
1304TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1305 handlesUpdatingOutputLayerForOpaqueDirtyRotated90Layer) {
1306 mLayerFEState.isOpaque = true;
1307 mLayerFEState.contentDirty = true;
1308 mLayerFEState.geomLayerBounds = FloatRect{0, 0, 200, 100};
1309 mLayerFEState.geomLayerTransform = ui::Transform(TR_ROT_90, 100, 200);
1310 mOutputLayerState.visibleRegion = Region(Rect(0, 0, 100, 100));
1311 mOutputLayerState.coveredRegion = Region(Rect(100, 0, 200, 100));
1312
1313 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer), Eq(mLayerFE)))
1314 .WillOnce(Return(&mOutputLayer));
1315
1316 mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState);
1317
1318 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1319 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1320 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
1321
1322 EXPECT_THAT(mOutputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1323 EXPECT_THAT(mOutputLayerState.visibleNonTransparentRegion, RegionEq(kFullBoundsNoRotation));
1324 EXPECT_THAT(mOutputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1325 EXPECT_THAT(mOutputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
1326}
1327
1328TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1329 handlesCreatingOutputLayerForOpaqueDirtyNotRotatedLayerRotatedOutput) {
1330 mLayerFEState.isOpaque = true;
1331 mLayerFEState.contentDirty = true;
1332 mLayerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
1333
1334 mOutput.mState.viewport = Rect(0, 0, 300, 200);
1335 mOutput.mState.transform = ui::Transform(TR_ROT_90, 200, 300);
1336
1337 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
1338 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer), Eq(mLayerFE)))
1339 .WillOnce(Return(&mOutputLayer));
1340
1341 mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState);
1342
1343 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1344 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1345 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
1346
1347 EXPECT_THAT(mOutputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1348 EXPECT_THAT(mOutputLayerState.visibleNonTransparentRegion, RegionEq(kFullBoundsNoRotation));
1349 EXPECT_THAT(mOutputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1350 EXPECT_THAT(mOutputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBounds90Rotation));
1351}
1352
1353TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1354 handlesUpdatingOutputLayerForOpaqueDirtyNotRotatedLayerRotatedOutput) {
1355 mLayerFEState.isOpaque = true;
1356 mLayerFEState.contentDirty = true;
1357 mLayerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
1358
1359 mOutput.mState.viewport = Rect(0, 0, 300, 200);
1360 mOutput.mState.transform = ui::Transform(TR_ROT_90, 200, 300);
1361
1362 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer), Eq(mLayerFE)))
1363 .WillOnce(Return(&mOutputLayer));
1364
1365 mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState);
1366
1367 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1368 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1369 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
1370
1371 EXPECT_THAT(mOutputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1372 EXPECT_THAT(mOutputLayerState.visibleNonTransparentRegion, RegionEq(kFullBoundsNoRotation));
1373 EXPECT_THAT(mOutputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1374 EXPECT_THAT(mOutputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBounds90Rotation));
1375}
1376
1377TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1378 handlesCreatingOutputLayerForOpaqueDirtyArbitraryTransformLayer) {
1379 ui::Transform arbitraryTransform;
1380 arbitraryTransform.set(1, 1, -1, 1);
1381 arbitraryTransform.set(0, 100);
1382
1383 mLayerFEState.isOpaque = true;
1384 mLayerFEState.contentDirty = true;
1385 mLayerFEState.geomLayerBounds = FloatRect{0, 0, 100, 200};
1386 mLayerFEState.geomLayerTransform = arbitraryTransform;
1387
1388 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
1389 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer), Eq(mLayerFE)))
1390 .WillOnce(Return(&mOutputLayer));
1391
1392 mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState);
1393
1394 const Region kRegion = Region(Rect(0, 0, 300, 300));
1395 const Region kRegionClipped = Region(Rect(0, 0, 200, 300));
1396
1397 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kRegion));
1398 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kRegion));
1399 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kEmptyRegion));
1400
1401 EXPECT_THAT(mOutputLayerState.visibleRegion, RegionEq(kRegion));
1402 EXPECT_THAT(mOutputLayerState.visibleNonTransparentRegion, RegionEq(kRegion));
1403 EXPECT_THAT(mOutputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1404 EXPECT_THAT(mOutputLayerState.outputSpaceVisibleRegion, RegionEq(kRegionClipped));
1405}
1406
1407TEST_F(OutputEnsureOutputLayerIfVisibleTest, coverageAccumulatesTest) {
1408 mLayerFEState.isOpaque = false;
1409 mLayerFEState.contentDirty = true;
1410 mLayerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
1411
1412 mCoverageState.dirtyRegion = Region(Rect(0, 0, 500, 500));
1413 mCoverageState.aboveCoveredLayers = Region(Rect(50, 0, 150, 200));
1414 mCoverageState.aboveOpaqueLayers = Region(Rect(50, 0, 150, 200));
1415
1416 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer), Eq(mLayerFE)))
1417 .WillOnce(Return(&mOutputLayer));
1418
1419 mOutput.ensureOutputLayerIfVisible(mLayer, mCoverageState);
1420
1421 const Region kExpectedDirtyRegion = Region(Rect(0, 0, 500, 500));
1422 const Region kExpectedAboveCoveredRegion = Region(Rect(0, 0, 150, 200));
1423 const Region kExpectedAboveOpaqueRegion = Region(Rect(50, 0, 150, 200));
1424 const Region kExpectedLayerVisibleRegion = Region(Rect(0, 0, 50, 200));
1425 const Region kExpectedLayerCoveredRegion = Region(Rect(50, 0, 100, 200));
1426 const Region kExpectedLayerVisibleNonTransparentRegion = Region(Rect(0, 100, 50, 200));
1427
1428 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kExpectedDirtyRegion));
1429 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kExpectedAboveCoveredRegion));
1430 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kExpectedAboveOpaqueRegion));
1431
1432 EXPECT_THAT(mOutputLayerState.visibleRegion, RegionEq(kExpectedLayerVisibleRegion));
1433 EXPECT_THAT(mOutputLayerState.visibleNonTransparentRegion,
1434 RegionEq(kExpectedLayerVisibleNonTransparentRegion));
1435 EXPECT_THAT(mOutputLayerState.coveredRegion, RegionEq(kExpectedLayerCoveredRegion));
1436 EXPECT_THAT(mOutputLayerState.outputSpaceVisibleRegion, RegionEq(kExpectedLayerVisibleRegion));
1437}
Lloyd Piqueb62cebc2019-11-20 18:31:52 -08001438
1439/*
Lloyd Piquefaa3f192019-11-14 14:05:09 -08001440 * Output::present()
1441 */
1442
1443struct OutputPresentTest : public testing::Test {
1444 struct OutputPartialMock : public OutputPartialMockBase {
Lloyd Pique739afaf2019-11-21 16:40:05 -08001445 // Sets up the helper functions called by the function under test to use
1446 // mock implementations.
Lloyd Piquefaa3f192019-11-14 14:05:09 -08001447 MOCK_METHOD1(updateColorProfile, void(const compositionengine::CompositionRefreshArgs&));
1448 MOCK_METHOD1(updateAndWriteCompositionState,
1449 void(const compositionengine::CompositionRefreshArgs&));
1450 MOCK_METHOD1(setColorTransform, void(const compositionengine::CompositionRefreshArgs&));
1451 MOCK_METHOD0(beginFrame, void());
1452 MOCK_METHOD0(prepareFrame, void());
1453 MOCK_METHOD1(devOptRepaintFlash, void(const compositionengine::CompositionRefreshArgs&));
1454 MOCK_METHOD1(finishFrame, void(const compositionengine::CompositionRefreshArgs&));
1455 MOCK_METHOD0(postFramebuffer, void());
1456 };
1457
1458 StrictMock<OutputPartialMock> mOutput;
1459};
1460
1461TEST_F(OutputPresentTest, justInvokesChildFunctionsInSequence) {
1462 CompositionRefreshArgs args;
1463
1464 InSequence seq;
1465 EXPECT_CALL(mOutput, updateColorProfile(Ref(args)));
1466 EXPECT_CALL(mOutput, updateAndWriteCompositionState(Ref(args)));
1467 EXPECT_CALL(mOutput, setColorTransform(Ref(args)));
1468 EXPECT_CALL(mOutput, beginFrame());
1469 EXPECT_CALL(mOutput, prepareFrame());
1470 EXPECT_CALL(mOutput, devOptRepaintFlash(Ref(args)));
1471 EXPECT_CALL(mOutput, finishFrame(Ref(args)));
1472 EXPECT_CALL(mOutput, postFramebuffer());
1473
1474 mOutput.present(args);
1475}
1476
1477/*
1478 * Output::updateColorProfile()
1479 */
1480
Lloyd Pique17ca7422019-11-14 14:24:10 -08001481struct OutputUpdateColorProfileTest : public testing::Test {
1482 using TestType = OutputUpdateColorProfileTest;
1483
1484 struct OutputPartialMock : public OutputPartialMockBase {
Lloyd Pique739afaf2019-11-21 16:40:05 -08001485 // Sets up the helper functions called by the function under test to use
1486 // mock implementations.
Lloyd Pique17ca7422019-11-14 14:24:10 -08001487 MOCK_METHOD1(setColorProfile, void(const ColorProfile&));
1488 };
1489
1490 struct Layer {
1491 Layer() {
1492 EXPECT_CALL(mOutputLayer, getLayer()).WillRepeatedly(ReturnRef(mLayer));
1493 EXPECT_CALL(mOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(mLayerFE));
1494 EXPECT_CALL(mLayer, getFEState()).WillRepeatedly(ReturnRef(mLayerFEState));
1495 }
1496
1497 StrictMock<mock::OutputLayer> mOutputLayer;
1498 StrictMock<mock::Layer> mLayer;
1499 StrictMock<mock::LayerFE> mLayerFE;
1500 LayerFECompositionState mLayerFEState;
1501 };
1502
1503 OutputUpdateColorProfileTest() {
1504 mOutput.setDisplayColorProfileForTest(
1505 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
1506 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
1507
1508 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0))
1509 .WillRepeatedly(Return(&mLayer1.mOutputLayer));
1510 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1))
1511 .WillRepeatedly(Return(&mLayer2.mOutputLayer));
1512 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(2))
1513 .WillRepeatedly(Return(&mLayer3.mOutputLayer));
1514 }
1515
1516 struct ExecuteState : public CallOrderStateMachineHelper<TestType, ExecuteState> {
1517 void execute() { getInstance()->mOutput.updateColorProfile(getInstance()->mRefreshArgs); }
1518 };
1519
1520 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
1521 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
1522 StrictMock<OutputPartialMock> mOutput;
1523
1524 Layer mLayer1;
1525 Layer mLayer2;
1526 Layer mLayer3;
1527
1528 CompositionRefreshArgs mRefreshArgs;
1529};
1530
1531// TODO(b/144522012): Refactor Output::updateColorProfile and the related code
1532// to make it easier to write unit tests.
1533
1534TEST_F(OutputUpdateColorProfileTest, setsAColorProfileWhenUnmanaged) {
1535 // When the outputColorSetting is set to kUnmanaged, the implementation sets
1536 // a simple default color profile without looking at anything else.
1537
1538 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(3));
1539 EXPECT_CALL(mOutput,
1540 setColorProfile(ColorProfileEq(
1541 ColorProfile{ui::ColorMode::NATIVE, ui::Dataspace::UNKNOWN,
1542 ui::RenderIntent::COLORIMETRIC, ui::Dataspace::UNKNOWN})));
1543
1544 mRefreshArgs.outputColorSetting = OutputColorSetting::kUnmanaged;
1545 mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN;
1546
1547 mOutput.updateColorProfile(mRefreshArgs);
1548}
1549
1550struct OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile
1551 : public OutputUpdateColorProfileTest {
1552 OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile() {
1553 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0));
1554 mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced;
1555 mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN;
1556 }
1557
1558 struct ExpectBestColorModeCallResultUsedToSetColorProfileState
1559 : public CallOrderStateMachineHelper<
1560 TestType, ExpectBestColorModeCallResultUsedToSetColorProfileState> {
1561 [[nodiscard]] auto expectBestColorModeCallResultUsedToSetColorProfile(
1562 ui::ColorMode colorMode, ui::Dataspace dataspace, ui::RenderIntent renderIntent) {
1563 EXPECT_CALL(*getInstance()->mDisplayColorProfile,
1564 getBestColorMode(ui::Dataspace::V0_SRGB, ui::RenderIntent::ENHANCE, _, _,
1565 _))
1566 .WillOnce(DoAll(SetArgPointee<2>(dataspace), SetArgPointee<3>(colorMode),
1567 SetArgPointee<4>(renderIntent)));
1568 EXPECT_CALL(getInstance()->mOutput,
1569 setColorProfile(
1570 ColorProfileEq(ColorProfile{colorMode, dataspace, renderIntent,
1571 ui::Dataspace::UNKNOWN})));
1572 return nextState<ExecuteState>();
1573 }
1574 };
1575
1576 // Call this member function to start using the mini-DSL defined above.
1577 [[nodiscard]] auto verify() {
1578 return ExpectBestColorModeCallResultUsedToSetColorProfileState::make(this);
1579 }
1580};
1581
1582TEST_F(OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile,
1583 Native_Unknown_Colorimetric_Set) {
1584 verify().expectBestColorModeCallResultUsedToSetColorProfile(ui::ColorMode::NATIVE,
1585 ui::Dataspace::UNKNOWN,
1586 ui::RenderIntent::COLORIMETRIC)
1587 .execute();
1588}
1589
1590TEST_F(OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile,
1591 DisplayP3_DisplayP3_Enhance_Set) {
1592 verify().expectBestColorModeCallResultUsedToSetColorProfile(ui::ColorMode::DISPLAY_P3,
1593 ui::Dataspace::DISPLAY_P3,
1594 ui::RenderIntent::ENHANCE)
1595 .execute();
1596}
1597
1598struct OutputUpdateColorProfileTest_ColorSpaceAgnosticeDataspaceAffectsSetColorProfile
1599 : public OutputUpdateColorProfileTest {
1600 OutputUpdateColorProfileTest_ColorSpaceAgnosticeDataspaceAffectsSetColorProfile() {
1601 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0));
1602 EXPECT_CALL(*mDisplayColorProfile,
1603 getBestColorMode(ui::Dataspace::V0_SRGB, ui::RenderIntent::ENHANCE, _, _, _))
1604 .WillRepeatedly(DoAll(SetArgPointee<2>(ui::Dataspace::UNKNOWN),
1605 SetArgPointee<3>(ui::ColorMode::NATIVE),
1606 SetArgPointee<4>(ui::RenderIntent::COLORIMETRIC)));
1607 mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced;
1608 }
1609
1610 struct IfColorSpaceAgnosticDataspaceSetToState
1611 : public CallOrderStateMachineHelper<TestType, IfColorSpaceAgnosticDataspaceSetToState> {
1612 [[nodiscard]] auto ifColorSpaceAgnosticDataspaceSetTo(ui::Dataspace dataspace) {
1613 getInstance()->mRefreshArgs.colorSpaceAgnosticDataspace = dataspace;
1614 return nextState<ThenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspaceState>();
1615 }
1616 };
1617
1618 struct ThenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspaceState
1619 : public CallOrderStateMachineHelper<
1620 TestType, ThenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspaceState> {
1621 [[nodiscard]] auto thenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspace(
1622 ui::Dataspace dataspace) {
1623 EXPECT_CALL(getInstance()->mOutput,
1624 setColorProfile(ColorProfileEq(
1625 ColorProfile{ui::ColorMode::NATIVE, ui::Dataspace::UNKNOWN,
1626 ui::RenderIntent::COLORIMETRIC, dataspace})));
1627 return nextState<ExecuteState>();
1628 }
1629 };
1630
1631 // Call this member function to start using the mini-DSL defined above.
1632 [[nodiscard]] auto verify() { return IfColorSpaceAgnosticDataspaceSetToState::make(this); }
1633};
1634
1635TEST_F(OutputUpdateColorProfileTest_ColorSpaceAgnosticeDataspaceAffectsSetColorProfile, DisplayP3) {
1636 verify().ifColorSpaceAgnosticDataspaceSetTo(ui::Dataspace::DISPLAY_P3)
1637 .thenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspace(ui::Dataspace::DISPLAY_P3)
1638 .execute();
1639}
1640
1641TEST_F(OutputUpdateColorProfileTest_ColorSpaceAgnosticeDataspaceAffectsSetColorProfile, V0_SRGB) {
1642 verify().ifColorSpaceAgnosticDataspaceSetTo(ui::Dataspace::V0_SRGB)
1643 .thenExpectSetColorProfileCallUsesColorSpaceAgnosticDataspace(ui::Dataspace::V0_SRGB)
1644 .execute();
1645}
1646
1647struct OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference
1648 : public OutputUpdateColorProfileTest {
1649 // Internally the implementation looks through the dataspaces of all the
1650 // visible layers. The topmost one that also has an actual dataspace
1651 // preference set is used to drive subsequent choices.
1652
1653 OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference() {
1654 mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced;
1655 mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN;
1656
1657 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(3));
1658 EXPECT_CALL(mOutput, setColorProfile(_)).WillRepeatedly(Return());
1659 }
1660
1661 struct IfTopLayerDataspaceState
1662 : public CallOrderStateMachineHelper<TestType, IfTopLayerDataspaceState> {
1663 [[nodiscard]] auto ifTopLayerIs(ui::Dataspace dataspace) {
1664 getInstance()->mLayer3.mLayerFEState.dataspace = dataspace;
1665 return nextState<AndIfMiddleLayerDataspaceState>();
1666 }
1667 [[nodiscard]] auto ifTopLayerHasNoPreference() {
1668 return ifTopLayerIs(ui::Dataspace::UNKNOWN);
1669 }
1670 };
1671
1672 struct AndIfMiddleLayerDataspaceState
1673 : public CallOrderStateMachineHelper<TestType, AndIfMiddleLayerDataspaceState> {
1674 [[nodiscard]] auto andIfMiddleLayerIs(ui::Dataspace dataspace) {
1675 getInstance()->mLayer2.mLayerFEState.dataspace = dataspace;
1676 return nextState<AndIfBottomLayerDataspaceState>();
1677 }
1678 [[nodiscard]] auto andIfMiddleLayerHasNoPreference() {
1679 return andIfMiddleLayerIs(ui::Dataspace::UNKNOWN);
1680 }
1681 };
1682
1683 struct AndIfBottomLayerDataspaceState
1684 : public CallOrderStateMachineHelper<TestType, AndIfBottomLayerDataspaceState> {
1685 [[nodiscard]] auto andIfBottomLayerIs(ui::Dataspace dataspace) {
1686 getInstance()->mLayer1.mLayerFEState.dataspace = dataspace;
1687 return nextState<ThenExpectBestColorModeCallUsesState>();
1688 }
1689 [[nodiscard]] auto andIfBottomLayerHasNoPreference() {
1690 return andIfBottomLayerIs(ui::Dataspace::UNKNOWN);
1691 }
1692 };
1693
1694 struct ThenExpectBestColorModeCallUsesState
1695 : public CallOrderStateMachineHelper<TestType, ThenExpectBestColorModeCallUsesState> {
1696 [[nodiscard]] auto thenExpectBestColorModeCallUses(ui::Dataspace dataspace) {
1697 EXPECT_CALL(*getInstance()->mDisplayColorProfile,
1698 getBestColorMode(dataspace, _, _, _, _));
1699 return nextState<ExecuteState>();
1700 }
1701 };
1702
1703 // Call this member function to start using the mini-DSL defined above.
1704 [[nodiscard]] auto verify() { return IfTopLayerDataspaceState::make(this); }
1705};
1706
1707TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference,
1708 noStrongLayerPrefenceUses_V0_SRGB) {
1709 // If none of the layers indicate a preference, then V0_SRGB is the
1710 // preferred choice (subject to additional checks).
1711 verify().ifTopLayerHasNoPreference()
1712 .andIfMiddleLayerHasNoPreference()
1713 .andIfBottomLayerHasNoPreference()
1714 .thenExpectBestColorModeCallUses(ui::Dataspace::V0_SRGB)
1715 .execute();
1716}
1717
1718TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference,
1719 ifTopmostUses_DisplayP3_Then_DisplayP3_Chosen) {
1720 // If only the topmost layer has a preference, then that is what is chosen.
1721 verify().ifTopLayerIs(ui::Dataspace::DISPLAY_P3)
1722 .andIfMiddleLayerHasNoPreference()
1723 .andIfBottomLayerHasNoPreference()
1724 .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3)
1725 .execute();
1726}
1727
1728TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference,
1729 ifMiddleUses_DisplayP3_Then_DisplayP3_Chosen) {
1730 // If only the middle layer has a preference, that that is what is chosen.
1731 verify().ifTopLayerHasNoPreference()
1732 .andIfMiddleLayerIs(ui::Dataspace::DISPLAY_P3)
1733 .andIfBottomLayerHasNoPreference()
1734 .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3)
1735 .execute();
1736}
1737
1738TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference,
1739 ifBottomUses_DisplayP3_Then_DisplayP3_Chosen) {
1740 // If only the middle layer has a preference, that that is what is chosen.
1741 verify().ifTopLayerHasNoPreference()
1742 .andIfMiddleLayerHasNoPreference()
1743 .andIfBottomLayerIs(ui::Dataspace::DISPLAY_P3)
1744 .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3)
1745 .execute();
1746}
1747
1748TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference,
1749 ifTopUses_DisplayBT2020_AndBottomUses_DisplayP3_Then_DisplayBT2020_Chosen) {
1750 // If multiple layers have a preference, the topmost value is what is used.
1751 verify().ifTopLayerIs(ui::Dataspace::DISPLAY_BT2020)
1752 .andIfMiddleLayerHasNoPreference()
1753 .andIfBottomLayerIs(ui::Dataspace::DISPLAY_P3)
1754 .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_BT2020)
1755 .execute();
1756}
1757
1758TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference,
1759 ifTopUses_DisplayP3_AndBottomUses_V0_SRGB_Then_DisplayP3_Chosen) {
1760 // If multiple layers have a preference, the topmost value is what is used.
1761 verify().ifTopLayerIs(ui::Dataspace::DISPLAY_P3)
1762 .andIfMiddleLayerHasNoPreference()
1763 .andIfBottomLayerIs(ui::Dataspace::DISPLAY_BT2020)
1764 .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3)
1765 .execute();
1766}
1767
1768struct OutputUpdateColorProfileTest_ForceOutputColorOverrides
1769 : public OutputUpdateColorProfileTest {
1770 // If CompositionRefreshArgs::forceOutputColorMode is set to some specific
1771 // values, it overrides the layer dataspace choice.
1772
1773 OutputUpdateColorProfileTest_ForceOutputColorOverrides() {
1774 mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced;
1775 mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN;
1776
1777 mLayer1.mLayerFEState.dataspace = ui::Dataspace::DISPLAY_BT2020;
1778
1779 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(1));
1780 EXPECT_CALL(mOutput, setColorProfile(_)).WillRepeatedly(Return());
1781 }
1782
1783 struct IfForceOutputColorModeState
1784 : public CallOrderStateMachineHelper<TestType, IfForceOutputColorModeState> {
1785 [[nodiscard]] auto ifForceOutputColorMode(ui::ColorMode colorMode) {
1786 getInstance()->mRefreshArgs.forceOutputColorMode = colorMode;
1787 return nextState<ThenExpectBestColorModeCallUsesState>();
1788 }
1789 [[nodiscard]] auto ifNoOverride() { return ifForceOutputColorMode(ui::ColorMode::NATIVE); }
1790 };
1791
1792 struct ThenExpectBestColorModeCallUsesState
1793 : public CallOrderStateMachineHelper<TestType, ThenExpectBestColorModeCallUsesState> {
1794 [[nodiscard]] auto thenExpectBestColorModeCallUses(ui::Dataspace dataspace) {
1795 EXPECT_CALL(*getInstance()->mDisplayColorProfile,
1796 getBestColorMode(dataspace, _, _, _, _));
1797 return nextState<ExecuteState>();
1798 }
1799 };
1800
1801 // Call this member function to start using the mini-DSL defined above.
1802 [[nodiscard]] auto verify() { return IfForceOutputColorModeState::make(this); }
1803};
1804
1805TEST_F(OutputUpdateColorProfileTest_ForceOutputColorOverrides, NoOverride_DoesNotOverride) {
1806 // By default the layer state is used to set the preferred dataspace
1807 verify().ifNoOverride()
1808 .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_BT2020)
1809 .execute();
1810}
1811
1812TEST_F(OutputUpdateColorProfileTest_ForceOutputColorOverrides, SRGB_Override_USES_V0_SRGB) {
1813 // Setting ui::ColorMode::SRGB overrides it with ui::Dataspace::V0_SRGB
1814 verify().ifForceOutputColorMode(ui::ColorMode::SRGB)
1815 .thenExpectBestColorModeCallUses(ui::Dataspace::V0_SRGB)
1816 .execute();
1817}
1818
1819TEST_F(OutputUpdateColorProfileTest_ForceOutputColorOverrides, DisplayP3_Override_Uses_DisplayP3) {
1820 // Setting ui::ColorMode::DISPLAY_P3 overrides it with ui::Dataspace::DISPLAY_P3
1821 verify().ifForceOutputColorMode(ui::ColorMode::DISPLAY_P3)
1822 .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3)
1823 .execute();
1824}
1825
1826// HDR output requires all layers to be compatible with the chosen HDR
1827// dataspace, along with there being proper support.
1828struct OutputUpdateColorProfileTest_Hdr : public OutputUpdateColorProfileTest {
1829 OutputUpdateColorProfileTest_Hdr() {
1830 mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced;
1831 mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN;
1832 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2));
1833 EXPECT_CALL(mOutput, setColorProfile(_)).WillRepeatedly(Return());
1834 }
1835
1836 static constexpr ui::Dataspace kNonHdrDataspace = ui::Dataspace::DISPLAY_P3;
1837 static constexpr ui::Dataspace BT2020_PQ = ui::Dataspace::BT2020_PQ;
1838 static constexpr ui::Dataspace BT2020_HLG = ui::Dataspace::BT2020_HLG;
1839 static constexpr ui::Dataspace DISPLAY_P3 = ui::Dataspace::DISPLAY_P3;
1840
1841 struct IfTopLayerDataspaceState
1842 : public CallOrderStateMachineHelper<TestType, IfTopLayerDataspaceState> {
1843 [[nodiscard]] auto ifTopLayerIs(ui::Dataspace dataspace) {
1844 getInstance()->mLayer2.mLayerFEState.dataspace = dataspace;
1845 return nextState<AndTopLayerCompositionTypeState>();
1846 }
1847 [[nodiscard]] auto ifTopLayerIsNotHdr() { return ifTopLayerIs(kNonHdrDataspace); }
1848 };
1849
1850 struct AndTopLayerCompositionTypeState
1851 : public CallOrderStateMachineHelper<TestType, AndTopLayerCompositionTypeState> {
1852 [[nodiscard]] auto andTopLayerIsREComposed(bool renderEngineComposed) {
1853 getInstance()->mLayer2.mLayerFEState.forceClientComposition = renderEngineComposed;
1854 return nextState<AndIfBottomLayerDataspaceState>();
1855 }
1856 };
1857
1858 struct AndIfBottomLayerDataspaceState
1859 : public CallOrderStateMachineHelper<TestType, AndIfBottomLayerDataspaceState> {
1860 [[nodiscard]] auto andIfBottomLayerIs(ui::Dataspace dataspace) {
1861 getInstance()->mLayer1.mLayerFEState.dataspace = dataspace;
1862 return nextState<AndBottomLayerCompositionTypeState>();
1863 }
1864 [[nodiscard]] auto andIfBottomLayerIsNotHdr() {
1865 return andIfBottomLayerIs(kNonHdrDataspace);
1866 }
1867 };
1868
1869 struct AndBottomLayerCompositionTypeState
1870 : public CallOrderStateMachineHelper<TestType, AndBottomLayerCompositionTypeState> {
1871 [[nodiscard]] auto andBottomLayerIsREComposed(bool renderEngineComposed) {
1872 getInstance()->mLayer1.mLayerFEState.forceClientComposition = renderEngineComposed;
1873 return nextState<AndIfHasLegacySupportState>();
1874 }
1875 };
1876
1877 struct AndIfHasLegacySupportState
1878 : public CallOrderStateMachineHelper<TestType, AndIfHasLegacySupportState> {
1879 [[nodiscard]] auto andIfLegacySupportFor(ui::Dataspace dataspace, bool legacySupport) {
1880 EXPECT_CALL(*getInstance()->mDisplayColorProfile, hasLegacyHdrSupport(dataspace))
1881 .WillOnce(Return(legacySupport));
1882 return nextState<ThenExpectBestColorModeCallUsesState>();
1883 }
1884 };
1885
1886 struct ThenExpectBestColorModeCallUsesState
1887 : public CallOrderStateMachineHelper<TestType, ThenExpectBestColorModeCallUsesState> {
1888 [[nodiscard]] auto thenExpectBestColorModeCallUses(ui::Dataspace dataspace) {
1889 EXPECT_CALL(*getInstance()->mDisplayColorProfile,
1890 getBestColorMode(dataspace, _, _, _, _));
1891 return nextState<ExecuteState>();
1892 }
1893 };
1894
1895 // Call this member function to start using the mini-DSL defined above.
1896 [[nodiscard]] auto verify() { return IfTopLayerDataspaceState::make(this); }
1897};
1898
1899TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_PQ_HW_Uses_PQ) {
1900 // If all layers use BT2020_PQ, and there are no other special conditions,
1901 // BT2020_PQ is used.
1902 verify().ifTopLayerIs(BT2020_PQ)
1903 .andTopLayerIsREComposed(false)
1904 .andIfBottomLayerIs(BT2020_PQ)
1905 .andBottomLayerIsREComposed(false)
1906 .andIfLegacySupportFor(BT2020_PQ, false)
1907 .thenExpectBestColorModeCallUses(BT2020_PQ)
1908 .execute();
1909}
1910
1911TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_PQ_HW_IfPQHasLegacySupport_Uses_DisplayP3) {
1912 // BT2020_PQ is not used if there is only legacy support for it.
1913 verify().ifTopLayerIs(BT2020_PQ)
1914 .andTopLayerIsREComposed(false)
1915 .andIfBottomLayerIs(BT2020_PQ)
1916 .andBottomLayerIsREComposed(false)
1917 .andIfLegacySupportFor(BT2020_PQ, true)
1918 .thenExpectBestColorModeCallUses(DISPLAY_P3)
1919 .execute();
1920}
1921
1922TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_PQ_RE_Uses_PQ) {
1923 // BT2020_PQ is still used if the bottom layer is RenderEngine composed.
1924 verify().ifTopLayerIs(BT2020_PQ)
1925 .andTopLayerIsREComposed(false)
1926 .andIfBottomLayerIs(BT2020_PQ)
1927 .andBottomLayerIsREComposed(true)
1928 .andIfLegacySupportFor(BT2020_PQ, false)
1929 .thenExpectBestColorModeCallUses(BT2020_PQ)
1930 .execute();
1931}
1932
1933TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_RE_On_PQ_HW_Uses_DisplayP3) {
1934 // BT2020_PQ is not used if the top layer is RenderEngine composed.
1935 verify().ifTopLayerIs(BT2020_PQ)
1936 .andTopLayerIsREComposed(true)
1937 .andIfBottomLayerIs(BT2020_PQ)
1938 .andBottomLayerIsREComposed(false)
1939 .andIfLegacySupportFor(BT2020_PQ, false)
1940 .thenExpectBestColorModeCallUses(DISPLAY_P3)
1941 .execute();
1942}
1943
1944TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_HLG_HW_Uses_PQ) {
1945 // If there is mixed HLG/PQ use, and the topmost layer is PQ, then PQ is used if there
1946 // are no other special conditions.
1947 verify().ifTopLayerIs(BT2020_PQ)
1948 .andTopLayerIsREComposed(false)
1949 .andIfBottomLayerIs(BT2020_HLG)
1950 .andBottomLayerIsREComposed(false)
1951 .andIfLegacySupportFor(BT2020_PQ, false)
1952 .thenExpectBestColorModeCallUses(BT2020_PQ)
1953 .execute();
1954}
1955
1956TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_HLG_HW_IfPQHasLegacySupport_Uses_DisplayP3) {
1957 // BT2020_PQ is not used if there is only legacy support for it.
1958 verify().ifTopLayerIs(BT2020_PQ)
1959 .andTopLayerIsREComposed(false)
1960 .andIfBottomLayerIs(BT2020_HLG)
1961 .andBottomLayerIsREComposed(false)
1962 .andIfLegacySupportFor(BT2020_PQ, true)
1963 .thenExpectBestColorModeCallUses(DISPLAY_P3)
1964 .execute();
1965}
1966
1967TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_HLG_RE_Uses_PQ) {
1968 // BT2020_PQ is used if the bottom HLG layer is RenderEngine composed.
1969 verify().ifTopLayerIs(BT2020_PQ)
1970 .andTopLayerIsREComposed(false)
1971 .andIfBottomLayerIs(BT2020_HLG)
1972 .andBottomLayerIsREComposed(true)
1973 .andIfLegacySupportFor(BT2020_PQ, false)
1974 .thenExpectBestColorModeCallUses(BT2020_PQ)
1975 .execute();
1976}
1977
1978TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_RE_On_HLG_HW_Uses_DisplayP3) {
1979 // BT2020_PQ is not used if the top PQ layer is RenderEngine composed.
1980 verify().ifTopLayerIs(BT2020_PQ)
1981 .andTopLayerIsREComposed(true)
1982 .andIfBottomLayerIs(BT2020_HLG)
1983 .andBottomLayerIsREComposed(false)
1984 .andIfLegacySupportFor(BT2020_PQ, false)
1985 .thenExpectBestColorModeCallUses(DISPLAY_P3)
1986 .execute();
1987}
1988
1989TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_PQ_HW_Uses_PQ) {
1990 // If there is mixed HLG/PQ use, and the topmost layer is HLG, then PQ is
1991 // used if there are no other special conditions.
1992 verify().ifTopLayerIs(BT2020_HLG)
1993 .andTopLayerIsREComposed(false)
1994 .andIfBottomLayerIs(BT2020_PQ)
1995 .andBottomLayerIsREComposed(false)
1996 .andIfLegacySupportFor(BT2020_PQ, false)
1997 .thenExpectBestColorModeCallUses(BT2020_PQ)
1998 .execute();
1999}
2000
2001TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_PQ_HW_IfPQHasLegacySupport_Uses_DisplayP3) {
2002 // BT2020_PQ is not used if there is only legacy support for it.
2003 verify().ifTopLayerIs(BT2020_HLG)
2004 .andTopLayerIsREComposed(false)
2005 .andIfBottomLayerIs(BT2020_PQ)
2006 .andBottomLayerIsREComposed(false)
2007 .andIfLegacySupportFor(BT2020_PQ, true)
2008 .thenExpectBestColorModeCallUses(DISPLAY_P3)
2009 .execute();
2010}
2011
2012TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_PQ_RE_Uses_DisplayP3) {
2013 // BT2020_PQ is not used if the bottom PQ layer is RenderEngine composed.
2014 verify().ifTopLayerIs(BT2020_HLG)
2015 .andTopLayerIsREComposed(false)
2016 .andIfBottomLayerIs(BT2020_PQ)
2017 .andBottomLayerIsREComposed(true)
2018 .andIfLegacySupportFor(BT2020_PQ, false)
2019 .thenExpectBestColorModeCallUses(DISPLAY_P3)
2020 .execute();
2021}
2022
2023TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_RE_On_PQ_HW_Uses_PQ) {
2024 // BT2020_PQ is still used if the top HLG layer is RenderEngine composed.
2025 verify().ifTopLayerIs(BT2020_HLG)
2026 .andTopLayerIsREComposed(true)
2027 .andIfBottomLayerIs(BT2020_PQ)
2028 .andBottomLayerIsREComposed(false)
2029 .andIfLegacySupportFor(BT2020_PQ, false)
2030 .thenExpectBestColorModeCallUses(BT2020_PQ)
2031 .execute();
2032}
2033
2034TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_HLG_HW_Uses_HLG) {
2035 // If all layers use HLG then HLG is used if there are no other special
2036 // conditions.
2037 verify().ifTopLayerIs(BT2020_HLG)
2038 .andTopLayerIsREComposed(false)
2039 .andIfBottomLayerIs(BT2020_HLG)
2040 .andBottomLayerIsREComposed(false)
2041 .andIfLegacySupportFor(BT2020_HLG, false)
2042 .thenExpectBestColorModeCallUses(BT2020_HLG)
2043 .execute();
2044}
2045
2046TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_HLG_HW_IfPQHasLegacySupport_Uses_DisplayP3) {
2047 // BT2020_HLG is not used if there is legacy support for it.
2048 verify().ifTopLayerIs(BT2020_HLG)
2049 .andTopLayerIsREComposed(false)
2050 .andIfBottomLayerIs(BT2020_HLG)
2051 .andBottomLayerIsREComposed(false)
2052 .andIfLegacySupportFor(BT2020_HLG, true)
2053 .thenExpectBestColorModeCallUses(DISPLAY_P3)
2054 .execute();
2055}
2056
2057TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_HLG_RE_Uses_HLG) {
2058 // BT2020_HLG is used even if the bottom layer is client composed.
2059 verify().ifTopLayerIs(BT2020_HLG)
2060 .andTopLayerIsREComposed(false)
2061 .andIfBottomLayerIs(BT2020_HLG)
2062 .andBottomLayerIsREComposed(true)
2063 .andIfLegacySupportFor(BT2020_HLG, false)
2064 .thenExpectBestColorModeCallUses(BT2020_HLG)
2065 .execute();
2066}
2067
2068TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_RE_On_HLG_HW_Uses_HLG) {
2069 // BT2020_HLG is used even if the top layer is client composed.
2070 verify().ifTopLayerIs(BT2020_HLG)
2071 .andTopLayerIsREComposed(true)
2072 .andIfBottomLayerIs(BT2020_HLG)
2073 .andBottomLayerIsREComposed(false)
2074 .andIfLegacySupportFor(BT2020_HLG, false)
2075 .thenExpectBestColorModeCallUses(BT2020_HLG)
2076 .execute();
2077}
2078
2079TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_NonHdr_HW_Uses_PQ) {
2080 // Even if there are non-HDR layers present, BT2020_PQ can still be used.
2081 verify().ifTopLayerIs(BT2020_PQ)
2082 .andTopLayerIsREComposed(false)
2083 .andIfBottomLayerIsNotHdr()
2084 .andBottomLayerIsREComposed(false)
2085 .andIfLegacySupportFor(BT2020_PQ, false)
2086 .thenExpectBestColorModeCallUses(BT2020_PQ)
2087 .execute();
2088}
2089
2090TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_NonHdr_RE_Uses_HLG) {
2091 // If all layers use HLG then HLG is used if there are no other special
2092 // conditions.
2093 verify().ifTopLayerIs(BT2020_HLG)
2094 .andTopLayerIsREComposed(false)
2095 .andIfBottomLayerIsNotHdr()
2096 .andBottomLayerIsREComposed(true)
2097 .andIfLegacySupportFor(BT2020_HLG, false)
2098 .thenExpectBestColorModeCallUses(BT2020_HLG)
2099 .execute();
2100}
2101
2102struct OutputUpdateColorProfile_AffectsChosenRenderIntentTest
2103 : public OutputUpdateColorProfileTest {
2104 // The various values for CompositionRefreshArgs::outputColorSetting affect
2105 // the chosen renderIntent, along with whether the preferred dataspace is an
2106 // HDR dataspace or not.
2107
2108 OutputUpdateColorProfile_AffectsChosenRenderIntentTest() {
2109 mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced;
2110 mRefreshArgs.colorSpaceAgnosticDataspace = ui::Dataspace::UNKNOWN;
2111 mLayer1.mLayerFEState.dataspace = ui::Dataspace::BT2020_PQ;
2112 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(1));
2113 EXPECT_CALL(mOutput, setColorProfile(_)).WillRepeatedly(Return());
2114 EXPECT_CALL(*mDisplayColorProfile, hasLegacyHdrSupport(ui::Dataspace::BT2020_PQ))
2115 .WillRepeatedly(Return(false));
2116 }
2117
2118 // The tests here involve enough state and GMock setup that using a mini-DSL
2119 // makes the tests much more readable, and allows the test to focus more on
2120 // the intent than on some of the details.
2121
2122 static constexpr ui::Dataspace kNonHdrDataspace = ui::Dataspace::DISPLAY_P3;
2123 static constexpr ui::Dataspace kHdrDataspace = ui::Dataspace::BT2020_PQ;
2124
2125 struct IfDataspaceChosenState
2126 : public CallOrderStateMachineHelper<TestType, IfDataspaceChosenState> {
2127 [[nodiscard]] auto ifDataspaceChosenIs(ui::Dataspace dataspace) {
2128 getInstance()->mLayer1.mLayerFEState.dataspace = dataspace;
2129 return nextState<AndOutputColorSettingState>();
2130 }
2131 [[nodiscard]] auto ifDataspaceChosenIsNonHdr() {
2132 return ifDataspaceChosenIs(kNonHdrDataspace);
2133 }
2134 [[nodiscard]] auto ifDataspaceChosenIsHdr() { return ifDataspaceChosenIs(kHdrDataspace); }
2135 };
2136
2137 struct AndOutputColorSettingState
2138 : public CallOrderStateMachineHelper<TestType, AndOutputColorSettingState> {
2139 [[nodiscard]] auto andOutputColorSettingIs(OutputColorSetting setting) {
2140 getInstance()->mRefreshArgs.outputColorSetting = setting;
2141 return nextState<ThenExpectBestColorModeCallUsesState>();
2142 }
2143 };
2144
2145 struct ThenExpectBestColorModeCallUsesState
2146 : public CallOrderStateMachineHelper<TestType, ThenExpectBestColorModeCallUsesState> {
2147 [[nodiscard]] auto thenExpectBestColorModeCallUses(ui::RenderIntent intent) {
2148 EXPECT_CALL(*getInstance()->mDisplayColorProfile,
2149 getBestColorMode(getInstance()->mLayer1.mLayerFEState.dataspace, intent, _,
2150 _, _));
2151 return nextState<ExecuteState>();
2152 }
2153 };
2154
2155 // Tests call one of these two helper member functions to start using the
2156 // mini-DSL defined above.
2157 [[nodiscard]] auto verify() { return IfDataspaceChosenState::make(this); }
2158};
2159
2160TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest,
2161 Managed_NonHdr_Prefers_Colorimetric) {
2162 verify().ifDataspaceChosenIsNonHdr()
2163 .andOutputColorSettingIs(OutputColorSetting::kManaged)
2164 .thenExpectBestColorModeCallUses(ui::RenderIntent::COLORIMETRIC)
2165 .execute();
2166}
2167
2168TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest,
2169 Managed_Hdr_Prefers_ToneMapColorimetric) {
2170 verify().ifDataspaceChosenIsHdr()
2171 .andOutputColorSettingIs(OutputColorSetting::kManaged)
2172 .thenExpectBestColorModeCallUses(ui::RenderIntent::TONE_MAP_COLORIMETRIC)
2173 .execute();
2174}
2175
2176TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest, Enhanced_NonHdr_Prefers_Enhance) {
2177 verify().ifDataspaceChosenIsNonHdr()
2178 .andOutputColorSettingIs(OutputColorSetting::kEnhanced)
2179 .thenExpectBestColorModeCallUses(ui::RenderIntent::ENHANCE)
2180 .execute();
2181}
2182
2183TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest,
2184 Enhanced_Hdr_Prefers_ToneMapEnhance) {
2185 verify().ifDataspaceChosenIsHdr()
2186 .andOutputColorSettingIs(OutputColorSetting::kEnhanced)
2187 .thenExpectBestColorModeCallUses(ui::RenderIntent::TONE_MAP_ENHANCE)
2188 .execute();
2189}
2190
2191TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest, Vendor_NonHdr_Prefers_Vendor) {
2192 verify().ifDataspaceChosenIsNonHdr()
2193 .andOutputColorSettingIs(kVendorSpecifiedOutputColorSetting)
2194 .thenExpectBestColorModeCallUses(
2195 static_cast<ui::RenderIntent>(kVendorSpecifiedOutputColorSetting))
2196 .execute();
2197}
2198
2199TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest, Vendor_Hdr_Prefers_Vendor) {
2200 verify().ifDataspaceChosenIsHdr()
2201 .andOutputColorSettingIs(kVendorSpecifiedOutputColorSetting)
2202 .thenExpectBestColorModeCallUses(
2203 static_cast<ui::RenderIntent>(kVendorSpecifiedOutputColorSetting))
2204 .execute();
2205}
Lloyd Piquefaa3f192019-11-14 14:05:09 -08002206
2207/*
2208 * Output::beginFrame()
2209 */
2210
Lloyd Piquee5965952019-11-18 16:16:32 -08002211struct OutputBeginFrameTest : public ::testing::Test {
2212 using TestType = OutputBeginFrameTest;
2213
2214 struct OutputPartialMock : public OutputPartialMockBase {
Lloyd Pique739afaf2019-11-21 16:40:05 -08002215 // Sets up the helper functions called by the function under test to use
2216 // mock implementations.
Lloyd Piquee5965952019-11-18 16:16:32 -08002217 MOCK_CONST_METHOD1(getDirtyRegion, Region(bool));
2218 };
2219
2220 OutputBeginFrameTest() {
2221 mOutput.setDisplayColorProfileForTest(
2222 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
2223 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
2224 }
2225
2226 struct IfGetDirtyRegionExpectationState
2227 : public CallOrderStateMachineHelper<TestType, IfGetDirtyRegionExpectationState> {
2228 [[nodiscard]] auto ifGetDirtyRegionReturns(Region dirtyRegion) {
2229 EXPECT_CALL(getInstance()->mOutput, getDirtyRegion(false))
2230 .WillOnce(Return(dirtyRegion));
2231 return nextState<AndIfGetOutputLayerCountExpectationState>();
2232 }
2233 };
2234
2235 struct AndIfGetOutputLayerCountExpectationState
2236 : public CallOrderStateMachineHelper<TestType, AndIfGetOutputLayerCountExpectationState> {
2237 [[nodiscard]] auto andIfGetOutputLayerCountReturns(size_t layerCount) {
2238 EXPECT_CALL(getInstance()->mOutput, getOutputLayerCount()).WillOnce(Return(layerCount));
2239 return nextState<AndIfLastCompositionHadVisibleLayersState>();
2240 }
2241 };
2242
2243 struct AndIfLastCompositionHadVisibleLayersState
2244 : public CallOrderStateMachineHelper<TestType,
2245 AndIfLastCompositionHadVisibleLayersState> {
2246 [[nodiscard]] auto andIfLastCompositionHadVisibleLayersIs(bool hadOutputLayers) {
2247 getInstance()->mOutput.mState.lastCompositionHadVisibleLayers = hadOutputLayers;
2248 return nextState<ThenExpectRenderSurfaceBeginFrameCallState>();
2249 }
2250 };
2251
2252 struct ThenExpectRenderSurfaceBeginFrameCallState
2253 : public CallOrderStateMachineHelper<TestType,
2254 ThenExpectRenderSurfaceBeginFrameCallState> {
2255 [[nodiscard]] auto thenExpectRenderSurfaceBeginFrameCall(bool mustRecompose) {
2256 EXPECT_CALL(*getInstance()->mRenderSurface, beginFrame(mustRecompose));
2257 return nextState<ExecuteState>();
2258 }
2259 };
2260
2261 struct ExecuteState : public CallOrderStateMachineHelper<TestType, ExecuteState> {
2262 [[nodiscard]] auto execute() {
2263 getInstance()->mOutput.beginFrame();
2264 return nextState<CheckPostconditionHadVisibleLayersState>();
2265 }
2266 };
2267
2268 struct CheckPostconditionHadVisibleLayersState
2269 : public CallOrderStateMachineHelper<TestType, CheckPostconditionHadVisibleLayersState> {
2270 void checkPostconditionHadVisibleLayers(bool expected) {
2271 EXPECT_EQ(expected, getInstance()->mOutput.mState.lastCompositionHadVisibleLayers);
2272 }
2273 };
2274
2275 // Tests call one of these two helper member functions to start using the
2276 // mini-DSL defined above.
2277 [[nodiscard]] auto verify() { return IfGetDirtyRegionExpectationState::make(this); }
2278
2279 static const Region kEmptyRegion;
2280 static const Region kNotEmptyRegion;
2281
2282 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
2283 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
2284 StrictMock<OutputPartialMock> mOutput;
2285};
2286
2287const Region OutputBeginFrameTest::kEmptyRegion{Rect{0, 0, 0, 0}};
2288const Region OutputBeginFrameTest::kNotEmptyRegion{Rect{0, 0, 1, 1}};
2289
2290TEST_F(OutputBeginFrameTest, hasDirtyHasLayersHadLayersLastFrame) {
2291 verify().ifGetDirtyRegionReturns(kNotEmptyRegion)
2292 .andIfGetOutputLayerCountReturns(1u)
2293 .andIfLastCompositionHadVisibleLayersIs(true)
2294 .thenExpectRenderSurfaceBeginFrameCall(true)
2295 .execute()
2296 .checkPostconditionHadVisibleLayers(true);
2297}
2298
2299TEST_F(OutputBeginFrameTest, hasDirtyNotHasLayersHadLayersLastFrame) {
2300 verify().ifGetDirtyRegionReturns(kNotEmptyRegion)
2301 .andIfGetOutputLayerCountReturns(0u)
2302 .andIfLastCompositionHadVisibleLayersIs(true)
2303 .thenExpectRenderSurfaceBeginFrameCall(true)
2304 .execute()
2305 .checkPostconditionHadVisibleLayers(false);
2306}
2307
2308TEST_F(OutputBeginFrameTest, hasDirtyHasLayersNotHadLayersLastFrame) {
2309 verify().ifGetDirtyRegionReturns(kNotEmptyRegion)
2310 .andIfGetOutputLayerCountReturns(1u)
2311 .andIfLastCompositionHadVisibleLayersIs(false)
2312 .thenExpectRenderSurfaceBeginFrameCall(true)
2313 .execute()
2314 .checkPostconditionHadVisibleLayers(true);
2315}
2316
2317TEST_F(OutputBeginFrameTest, hasDirtyNotHasLayersNotHadLayersLastFrame) {
2318 verify().ifGetDirtyRegionReturns(kNotEmptyRegion)
2319 .andIfGetOutputLayerCountReturns(0u)
2320 .andIfLastCompositionHadVisibleLayersIs(false)
2321 .thenExpectRenderSurfaceBeginFrameCall(false)
2322 .execute()
2323 .checkPostconditionHadVisibleLayers(false);
2324}
2325
2326TEST_F(OutputBeginFrameTest, notHasDirtyHasLayersHadLayersLastFrame) {
2327 verify().ifGetDirtyRegionReturns(kEmptyRegion)
2328 .andIfGetOutputLayerCountReturns(1u)
2329 .andIfLastCompositionHadVisibleLayersIs(true)
2330 .thenExpectRenderSurfaceBeginFrameCall(false)
2331 .execute()
2332 .checkPostconditionHadVisibleLayers(true);
2333}
2334
2335TEST_F(OutputBeginFrameTest, notHasDirtyNotHasLayersHadLayersLastFrame) {
2336 verify().ifGetDirtyRegionReturns(kEmptyRegion)
2337 .andIfGetOutputLayerCountReturns(0u)
2338 .andIfLastCompositionHadVisibleLayersIs(true)
2339 .thenExpectRenderSurfaceBeginFrameCall(false)
2340 .execute()
2341 .checkPostconditionHadVisibleLayers(true);
2342}
2343
2344TEST_F(OutputBeginFrameTest, notHasDirtyHasLayersNotHadLayersLastFrame) {
2345 verify().ifGetDirtyRegionReturns(kEmptyRegion)
2346 .andIfGetOutputLayerCountReturns(1u)
2347 .andIfLastCompositionHadVisibleLayersIs(false)
2348 .thenExpectRenderSurfaceBeginFrameCall(false)
2349 .execute()
2350 .checkPostconditionHadVisibleLayers(false);
2351}
2352
2353TEST_F(OutputBeginFrameTest, notHasDirtyNotHasLayersNotHadLayersLastFrame) {
2354 verify().ifGetDirtyRegionReturns(kEmptyRegion)
2355 .andIfGetOutputLayerCountReturns(0u)
2356 .andIfLastCompositionHadVisibleLayersIs(false)
2357 .thenExpectRenderSurfaceBeginFrameCall(false)
2358 .execute()
2359 .checkPostconditionHadVisibleLayers(false);
2360}
2361
Lloyd Piquefaa3f192019-11-14 14:05:09 -08002362/*
2363 * Output::devOptRepaintFlash()
2364 */
2365
Lloyd Piquedb462d82019-11-19 17:58:46 -08002366struct OutputDevOptRepaintFlashTest : public testing::Test {
2367 struct OutputPartialMock : public OutputPartialMockBase {
Lloyd Pique739afaf2019-11-21 16:40:05 -08002368 // Sets up the helper functions called by the function under test to use
2369 // mock implementations.
Lloyd Piquedb462d82019-11-19 17:58:46 -08002370 MOCK_CONST_METHOD1(getDirtyRegion, Region(bool));
2371 MOCK_METHOD1(composeSurfaces, std::optional<base::unique_fd>(const Region&));
2372 MOCK_METHOD0(postFramebuffer, void());
2373 MOCK_METHOD0(prepareFrame, void());
2374 };
2375
2376 OutputDevOptRepaintFlashTest() {
2377 mOutput.setDisplayColorProfileForTest(
2378 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
2379 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
2380 }
2381
2382 static const Region kEmptyRegion;
2383 static const Region kNotEmptyRegion;
2384
2385 StrictMock<OutputPartialMock> mOutput;
2386 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
2387 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
2388 CompositionRefreshArgs mRefreshArgs;
2389};
2390
2391const Region OutputDevOptRepaintFlashTest::kEmptyRegion{Rect{0, 0, 0, 0}};
2392const Region OutputDevOptRepaintFlashTest::kNotEmptyRegion{Rect{0, 0, 1, 1}};
2393
2394TEST_F(OutputDevOptRepaintFlashTest, doesNothingIfFlashDelayNotSet) {
2395 mRefreshArgs.devOptFlashDirtyRegionsDelay = {};
2396 mRefreshArgs.repaintEverything = true;
2397 mOutput.mState.isEnabled = true;
2398
2399 mOutput.devOptRepaintFlash(mRefreshArgs);
2400}
2401
2402TEST_F(OutputDevOptRepaintFlashTest, postsAndPreparesANewFrameIfNotEnabled) {
2403 mRefreshArgs.devOptFlashDirtyRegionsDelay = std::chrono::microseconds(1);
2404 mRefreshArgs.repaintEverything = true;
2405 mOutput.mState.isEnabled = false;
2406
2407 InSequence seq;
2408 EXPECT_CALL(mOutput, postFramebuffer());
2409 EXPECT_CALL(mOutput, prepareFrame());
2410
2411 mOutput.devOptRepaintFlash(mRefreshArgs);
2412}
2413
2414TEST_F(OutputDevOptRepaintFlashTest, postsAndPreparesANewFrameIfNotDirty) {
2415 mRefreshArgs.devOptFlashDirtyRegionsDelay = std::chrono::microseconds(1);
2416 mRefreshArgs.repaintEverything = true;
2417 mOutput.mState.isEnabled = true;
2418
2419 InSequence seq;
2420 EXPECT_CALL(mOutput, getDirtyRegion(true)).WillOnce(Return(kEmptyRegion));
2421 EXPECT_CALL(mOutput, postFramebuffer());
2422 EXPECT_CALL(mOutput, prepareFrame());
2423
2424 mOutput.devOptRepaintFlash(mRefreshArgs);
2425}
2426
2427TEST_F(OutputDevOptRepaintFlashTest, alsoComposesSurfacesAndQueuesABufferIfDirty) {
2428 mRefreshArgs.devOptFlashDirtyRegionsDelay = std::chrono::microseconds(1);
2429 mRefreshArgs.repaintEverything = false;
2430 mOutput.mState.isEnabled = true;
2431
2432 InSequence seq;
2433 EXPECT_CALL(mOutput, getDirtyRegion(false)).WillOnce(Return(kNotEmptyRegion));
2434 EXPECT_CALL(mOutput, composeSurfaces(RegionEq(kNotEmptyRegion)));
2435 EXPECT_CALL(*mRenderSurface, queueBuffer(_));
2436 EXPECT_CALL(mOutput, postFramebuffer());
2437 EXPECT_CALL(mOutput, prepareFrame());
2438
2439 mOutput.devOptRepaintFlash(mRefreshArgs);
2440}
2441
Lloyd Piquefaa3f192019-11-14 14:05:09 -08002442// TODO(b/144060211) - Add coverage
2443
2444/*
2445 * Output::finishFrame()
2446 */
2447
Lloyd Pique03561a62019-11-19 18:34:52 -08002448struct OutputFinishFrameTest : public testing::Test {
2449 struct OutputPartialMock : public OutputPartialMockBase {
Lloyd Pique739afaf2019-11-21 16:40:05 -08002450 // Sets up the helper functions called by the function under test to use
2451 // mock implementations.
Lloyd Pique03561a62019-11-19 18:34:52 -08002452 MOCK_METHOD1(composeSurfaces, std::optional<base::unique_fd>(const Region&));
2453 MOCK_METHOD0(postFramebuffer, void());
2454 };
2455
2456 OutputFinishFrameTest() {
2457 mOutput.setDisplayColorProfileForTest(
2458 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
2459 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
2460 }
2461
2462 StrictMock<OutputPartialMock> mOutput;
2463 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
2464 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
2465 CompositionRefreshArgs mRefreshArgs;
2466};
2467
2468TEST_F(OutputFinishFrameTest, ifNotEnabledDoesNothing) {
2469 mOutput.mState.isEnabled = false;
2470
2471 mOutput.finishFrame(mRefreshArgs);
2472}
2473
2474TEST_F(OutputFinishFrameTest, takesEarlyOutifComposeSurfacesReturnsNoFence) {
2475 mOutput.mState.isEnabled = true;
2476
2477 InSequence seq;
2478 EXPECT_CALL(mOutput, composeSurfaces(RegionEq(Region::INVALID_REGION)));
2479
2480 mOutput.finishFrame(mRefreshArgs);
2481}
2482
2483TEST_F(OutputFinishFrameTest, queuesBufferIfComposeSurfacesReturnsAFence) {
2484 mOutput.mState.isEnabled = true;
2485
2486 InSequence seq;
2487 EXPECT_CALL(mOutput, composeSurfaces(RegionEq(Region::INVALID_REGION)))
2488 .WillOnce(Return(ByMove(base::unique_fd())));
2489 EXPECT_CALL(*mRenderSurface, queueBuffer(_));
2490
2491 mOutput.finishFrame(mRefreshArgs);
2492}
Lloyd Piquefaa3f192019-11-14 14:05:09 -08002493
2494/*
2495 * Output::postFramebuffer()
2496 */
2497
Lloyd Pique07178e32019-11-19 19:15:26 -08002498struct OutputPostFramebufferTest : public testing::Test {
2499 struct OutputPartialMock : public OutputPartialMockBase {
Lloyd Pique739afaf2019-11-21 16:40:05 -08002500 // Sets up the helper functions called by the function under test to use
2501 // mock implementations.
Lloyd Pique07178e32019-11-19 19:15:26 -08002502 MOCK_METHOD0(presentAndGetFrameFences, compositionengine::Output::FrameFences());
2503 };
2504
2505 struct Layer {
2506 Layer() {
2507 EXPECT_CALL(outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(layerFE));
2508 EXPECT_CALL(outputLayer, getHwcLayer()).WillRepeatedly(Return(&hwc2Layer));
2509 }
2510
2511 StrictMock<mock::OutputLayer> outputLayer;
2512 StrictMock<mock::LayerFE> layerFE;
2513 StrictMock<HWC2::mock::Layer> hwc2Layer;
2514 };
2515
2516 OutputPostFramebufferTest() {
2517 mOutput.setDisplayColorProfileForTest(
2518 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
2519 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
2520
2521 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(3u));
2522 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u))
2523 .WillRepeatedly(Return(&mLayer1.outputLayer));
2524 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1u))
2525 .WillRepeatedly(Return(&mLayer2.outputLayer));
2526 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(2u))
2527 .WillRepeatedly(Return(&mLayer3.outputLayer));
2528 }
2529
2530 StrictMock<OutputPartialMock> mOutput;
2531 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
2532 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
2533
2534 Layer mLayer1;
2535 Layer mLayer2;
2536 Layer mLayer3;
2537};
2538
2539TEST_F(OutputPostFramebufferTest, ifNotEnabledDoesNothing) {
2540 mOutput.mState.isEnabled = false;
2541
2542 mOutput.postFramebuffer();
2543}
2544
2545TEST_F(OutputPostFramebufferTest, ifEnabledMustFlipThenPresentThenSendPresentCompleted) {
2546 mOutput.mState.isEnabled = true;
2547
2548 compositionengine::Output::FrameFences frameFences;
2549
2550 // This should happen even if there are no output layers.
2551 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
2552
2553 // For this test in particular we want to make sure the call expectations
2554 // setup below are satisfied in the specific order.
2555 InSequence seq;
2556
2557 EXPECT_CALL(*mRenderSurface, flip());
2558 EXPECT_CALL(mOutput, presentAndGetFrameFences()).WillOnce(Return(frameFences));
2559 EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted());
2560
2561 mOutput.postFramebuffer();
2562}
2563
2564TEST_F(OutputPostFramebufferTest, releaseFencesAreSentToLayerFE) {
2565 // Simulate getting release fences from each layer, and ensure they are passed to the
2566 // front-end layer interface for each layer correctly.
2567
2568 mOutput.mState.isEnabled = true;
2569
2570 // Create three unique fence instances
2571 sp<Fence> layer1Fence = new Fence();
2572 sp<Fence> layer2Fence = new Fence();
2573 sp<Fence> layer3Fence = new Fence();
2574
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08002575 Output::FrameFences frameFences;
Lloyd Pique07178e32019-11-19 19:15:26 -08002576 frameFences.layerFences.emplace(&mLayer1.hwc2Layer, layer1Fence);
2577 frameFences.layerFences.emplace(&mLayer2.hwc2Layer, layer2Fence);
2578 frameFences.layerFences.emplace(&mLayer3.hwc2Layer, layer3Fence);
2579
2580 EXPECT_CALL(*mRenderSurface, flip());
2581 EXPECT_CALL(mOutput, presentAndGetFrameFences()).WillOnce(Return(frameFences));
2582 EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted());
2583
2584 // Compare the pointers values of each fence to make sure the correct ones
2585 // are passed. This happens to work with the current implementation, but
2586 // would not survive certain calls like Fence::merge() which would return a
2587 // new instance.
2588 EXPECT_CALL(mLayer1.layerFE,
2589 onLayerDisplayed(Property(&sp<Fence>::get, Eq(layer1Fence.get()))));
2590 EXPECT_CALL(mLayer2.layerFE,
2591 onLayerDisplayed(Property(&sp<Fence>::get, Eq(layer2Fence.get()))));
2592 EXPECT_CALL(mLayer3.layerFE,
2593 onLayerDisplayed(Property(&sp<Fence>::get, Eq(layer3Fence.get()))));
2594
2595 mOutput.postFramebuffer();
2596}
2597
2598TEST_F(OutputPostFramebufferTest, releaseFencesIncludeClientTargetAcquireFence) {
2599 mOutput.mState.isEnabled = true;
2600 mOutput.mState.usesClientComposition = true;
2601
2602 sp<Fence> clientTargetAcquireFence = new Fence();
2603 sp<Fence> layer1Fence = new Fence();
2604 sp<Fence> layer2Fence = new Fence();
2605 sp<Fence> layer3Fence = new Fence();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08002606 Output::FrameFences frameFences;
Lloyd Pique07178e32019-11-19 19:15:26 -08002607 frameFences.clientTargetAcquireFence = clientTargetAcquireFence;
2608 frameFences.layerFences.emplace(&mLayer1.hwc2Layer, layer1Fence);
2609 frameFences.layerFences.emplace(&mLayer2.hwc2Layer, layer2Fence);
2610 frameFences.layerFences.emplace(&mLayer3.hwc2Layer, layer3Fence);
2611
2612 EXPECT_CALL(*mRenderSurface, flip());
2613 EXPECT_CALL(mOutput, presentAndGetFrameFences()).WillOnce(Return(frameFences));
2614 EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted());
2615
2616 // Fence::merge is called, and since none of the fences are actually valid,
2617 // Fence::NO_FENCE is returned and passed to each onLayerDisplayed() call.
2618 // This is the best we can do without creating a real kernel fence object.
2619 EXPECT_CALL(mLayer1.layerFE, onLayerDisplayed(Fence::NO_FENCE));
2620 EXPECT_CALL(mLayer2.layerFE, onLayerDisplayed(Fence::NO_FENCE));
2621 EXPECT_CALL(mLayer3.layerFE, onLayerDisplayed(Fence::NO_FENCE));
2622
2623 mOutput.postFramebuffer();
2624}
2625
2626TEST_F(OutputPostFramebufferTest, releasedLayersSentPresentFence) {
2627 mOutput.mState.isEnabled = true;
2628 mOutput.mState.usesClientComposition = true;
2629
2630 // This should happen even if there are no (current) output layers.
2631 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
2632
2633 // Load up the released layers with some mock instances
2634 sp<StrictMock<mock::LayerFE>> releasedLayer1{new StrictMock<mock::LayerFE>()};
2635 sp<StrictMock<mock::LayerFE>> releasedLayer2{new StrictMock<mock::LayerFE>()};
2636 sp<StrictMock<mock::LayerFE>> releasedLayer3{new StrictMock<mock::LayerFE>()};
2637 Output::ReleasedLayers layers;
2638 layers.push_back(releasedLayer1);
2639 layers.push_back(releasedLayer2);
2640 layers.push_back(releasedLayer3);
2641 mOutput.setReleasedLayers(std::move(layers));
2642
2643 // Set up a fake present fence
2644 sp<Fence> presentFence = new Fence();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08002645 Output::FrameFences frameFences;
Lloyd Pique07178e32019-11-19 19:15:26 -08002646 frameFences.presentFence = presentFence;
2647
2648 EXPECT_CALL(*mRenderSurface, flip());
2649 EXPECT_CALL(mOutput, presentAndGetFrameFences()).WillOnce(Return(frameFences));
2650 EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted());
2651
2652 // Each released layer should be given the presentFence.
2653 EXPECT_CALL(*releasedLayer1,
2654 onLayerDisplayed(Property(&sp<Fence>::get, Eq(presentFence.get()))));
2655 EXPECT_CALL(*releasedLayer2,
2656 onLayerDisplayed(Property(&sp<Fence>::get, Eq(presentFence.get()))));
2657 EXPECT_CALL(*releasedLayer3,
2658 onLayerDisplayed(Property(&sp<Fence>::get, Eq(presentFence.get()))));
2659
2660 mOutput.postFramebuffer();
2661
2662 // After the call the list of released layers should have been cleared.
2663 EXPECT_TRUE(mOutput.getReleasedLayersForTest().empty());
2664}
Lloyd Piquefaa3f192019-11-14 14:05:09 -08002665
2666/*
Lloyd Pique56eba802019-08-28 15:45:25 -07002667 * Output::composeSurfaces()
2668 */
2669
2670struct OutputComposeSurfacesTest : public testing::Test {
2671 static constexpr uint32_t kDefaultOutputOrientation = TR_IDENT;
2672 static constexpr ui::Dataspace kDefaultOutputDataspace = ui::Dataspace::DISPLAY_P3;
2673
2674 static const Rect kDefaultOutputFrame;
2675 static const Rect kDefaultOutputViewport;
2676 static const Rect kDefaultOutputScissor;
2677 static const mat4 kDefaultColorTransformMat;
2678
Lloyd Piquefaa3f192019-11-14 14:05:09 -08002679 struct OutputPartialMock : public OutputPartialMockBase {
Lloyd Pique739afaf2019-11-21 16:40:05 -08002680 // Sets up the helper functions called by the function under test to use
2681 // mock implementations.
Lloyd Pique56eba802019-08-28 15:45:25 -07002682 MOCK_CONST_METHOD0(getSkipColorTransform, bool());
2683 MOCK_METHOD2(generateClientCompositionRequests,
2684 std::vector<renderengine::LayerSettings>(bool, Region&));
2685 MOCK_METHOD2(appendRegionFlashRequests,
2686 void(const Region&, std::vector<renderengine::LayerSettings>&));
2687 MOCK_METHOD1(setExpensiveRenderingExpected, void(bool));
2688 };
2689
2690 OutputComposeSurfacesTest() {
2691 mOutput.setDisplayColorProfileForTest(
2692 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
2693 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
2694
Lloyd Pique56eba802019-08-28 15:45:25 -07002695 mOutput.editState().frame = kDefaultOutputFrame;
2696 mOutput.editState().viewport = kDefaultOutputViewport;
2697 mOutput.editState().scissor = kDefaultOutputScissor;
2698 mOutput.editState().transform = ui::Transform{kDefaultOutputOrientation};
2699 mOutput.editState().orientation = kDefaultOutputOrientation;
2700 mOutput.editState().dataspace = kDefaultOutputDataspace;
Lloyd Pique3eb1b212019-03-07 21:15:40 -08002701 mOutput.editState().colorTransformMatrix = kDefaultColorTransformMat;
Lloyd Pique56eba802019-08-28 15:45:25 -07002702 mOutput.editState().isSecure = true;
2703 mOutput.editState().needsFiltering = false;
2704 mOutput.editState().usesClientComposition = true;
2705 mOutput.editState().usesDeviceComposition = false;
2706
Lloyd Pique01c77c12019-04-17 12:48:32 -07002707 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2u));
2708 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u))
2709 .WillRepeatedly(Return(&mOutputLayer1));
2710 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1u))
2711 .WillRepeatedly(Return(&mOutputLayer2));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -07002712 EXPECT_CALL(mOutput, getCompositionEngine()).WillRepeatedly(ReturnRef(mCompositionEngine));
Lloyd Pique56eba802019-08-28 15:45:25 -07002713 EXPECT_CALL(mCompositionEngine, getRenderEngine()).WillRepeatedly(ReturnRef(mRenderEngine));
2714 }
2715
2716 StrictMock<mock::CompositionEngine> mCompositionEngine;
2717 StrictMock<renderengine::mock::RenderEngine> mRenderEngine;
2718 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
2719 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
Lloyd Pique01c77c12019-04-17 12:48:32 -07002720 StrictMock<mock::OutputLayer> mOutputLayer1;
2721 StrictMock<mock::OutputLayer> mOutputLayer2;
Lloyd Piquea38ea7e2019-04-16 18:10:26 -07002722 StrictMock<OutputPartialMock> mOutput;
Lloyd Pique56eba802019-08-28 15:45:25 -07002723 sp<GraphicBuffer> mOutputBuffer = new GraphicBuffer();
2724};
2725
2726const Rect OutputComposeSurfacesTest::kDefaultOutputFrame{1001, 1002, 1003, 1004};
2727const Rect OutputComposeSurfacesTest::kDefaultOutputViewport{1005, 1006, 1007, 1008};
2728const Rect OutputComposeSurfacesTest::kDefaultOutputScissor{1009, 1010, 1011, 1012};
2729const mat4 OutputComposeSurfacesTest::kDefaultColorTransformMat{mat4() * 0.5};
2730
2731// TODO(b/121291683): Expand unit test coverage for composeSurfaces beyond these
2732// basic tests.
2733
2734TEST_F(OutputComposeSurfacesTest, doesNothingIfNoClientComposition) {
2735 mOutput.editState().usesClientComposition = false;
2736
2737 Region debugRegion;
Lloyd Piqued3d69882019-02-28 16:03:46 -08002738 std::optional<base::unique_fd> readyFence = mOutput.composeSurfaces(debugRegion);
2739 EXPECT_TRUE(readyFence);
Lloyd Pique56eba802019-08-28 15:45:25 -07002740}
2741
2742TEST_F(OutputComposeSurfacesTest, worksIfNoClientLayersQueued) {
2743 const Region kDebugRegion{Rect{100, 101, 102, 103}};
2744
2745 constexpr float kDefaultMaxLuminance = 1.0f;
2746 constexpr float kDefaultAvgLuminance = 0.7f;
2747 constexpr float kDefaultMinLuminance = 0.1f;
2748 HdrCapabilities HdrCapabilities{{},
2749 kDefaultMaxLuminance,
2750 kDefaultAvgLuminance,
2751 kDefaultMinLuminance};
2752
2753 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillOnce(Return(false));
2754 EXPECT_CALL(mRenderEngine, drawLayers(_, _, _, true, _, _)).Times(1);
2755
2756 EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillOnce(Return(true));
2757 EXPECT_CALL(*mDisplayColorProfile, getHdrCapabilities()).WillOnce(ReturnRef(HdrCapabilities));
2758
2759 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillOnce(Return(mOutputBuffer));
2760
2761 EXPECT_CALL(mOutput, getSkipColorTransform()).WillOnce(Return(false));
2762 EXPECT_CALL(mOutput, generateClientCompositionRequests(false, _)).Times(1);
2763 EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _)).Times(1);
2764 EXPECT_CALL(mOutput, setExpensiveRenderingExpected(true)).Times(1);
2765 EXPECT_CALL(mOutput, setExpensiveRenderingExpected(false)).Times(1);
2766
Lloyd Piqued3d69882019-02-28 16:03:46 -08002767 std::optional<base::unique_fd> readyFence = mOutput.composeSurfaces(kDebugRegion);
2768 EXPECT_TRUE(readyFence);
Lloyd Pique56eba802019-08-28 15:45:25 -07002769}
2770
2771/*
2772 * Output::generateClientCompositionRequests()
2773 */
2774
2775struct GenerateClientCompositionRequestsTest : public testing::Test {
Lloyd Piquefaa3f192019-11-14 14:05:09 -08002776 struct OutputPartialMock : public OutputPartialMockBase {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -07002777 // compositionengine::Output overrides
Lloyd Pique56eba802019-08-28 15:45:25 -07002778 std::vector<renderengine::LayerSettings> generateClientCompositionRequests(
2779 bool supportsProtectedContent, Region& clearRegion) override {
2780 return impl::Output::generateClientCompositionRequests(supportsProtectedContent,
2781 clearRegion);
2782 }
2783 };
2784
2785 GenerateClientCompositionRequestsTest() {
2786 mOutput.setDisplayColorProfileForTest(
2787 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
2788 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
2789 }
2790
Lloyd Pique56eba802019-08-28 15:45:25 -07002791 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
2792 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -07002793 StrictMock<OutputPartialMock> mOutput;
Lloyd Pique56eba802019-08-28 15:45:25 -07002794};
2795
2796// TODO(b/121291683): Add more unit test coverage for generateClientCompositionRequests
2797
2798TEST_F(GenerateClientCompositionRequestsTest, worksForLandscapeModeSplitScreen) {
2799 // In split-screen landscape mode, the screen is rotated 90 degrees, with
2800 // one layer on the left covering the left side of the output, and one layer
2801 // on the right covering that side of the output.
2802
Lloyd Pique01c77c12019-04-17 12:48:32 -07002803 StrictMock<mock::OutputLayer> leftOutputLayer;
2804 StrictMock<mock::OutputLayer> rightOutputLayer;
Lloyd Pique56eba802019-08-28 15:45:25 -07002805
2806 StrictMock<mock::Layer> leftLayer;
2807 StrictMock<mock::LayerFE> leftLayerFE;
2808 StrictMock<mock::Layer> rightLayer;
2809 StrictMock<mock::LayerFE> rightLayerFE;
2810
2811 impl::OutputLayerCompositionState leftOutputLayerState;
2812 leftOutputLayerState.clearClientTarget = false;
Lloyd Piquea2468662019-03-07 21:31:06 -08002813 leftOutputLayerState.visibleRegion = Region{Rect{0, 0, 1000, 1000}};
Lloyd Pique56eba802019-08-28 15:45:25 -07002814
Lloyd Pique9755fb72019-03-26 14:44:40 -07002815 LayerFECompositionState leftLayerFEState;
2816 leftLayerFEState.isOpaque = true;
Lloyd Pique56eba802019-08-28 15:45:25 -07002817
2818 const half3 leftLayerColor{1.f, 0.f, 0.f};
2819 renderengine::LayerSettings leftLayerRESettings;
2820 leftLayerRESettings.source.solidColor = leftLayerColor;
2821
2822 impl::OutputLayerCompositionState rightOutputLayerState;
2823 rightOutputLayerState.clearClientTarget = false;
Lloyd Piquea2468662019-03-07 21:31:06 -08002824 rightOutputLayerState.visibleRegion = Region{Rect{1000, 0, 2000, 1000}};
Lloyd Pique56eba802019-08-28 15:45:25 -07002825
Lloyd Pique9755fb72019-03-26 14:44:40 -07002826 LayerFECompositionState rightLayerFEState;
2827 rightLayerFEState.isOpaque = true;
Lloyd Pique56eba802019-08-28 15:45:25 -07002828
2829 const half3 rightLayerColor{0.f, 1.f, 0.f};
2830 renderengine::LayerSettings rightLayerRESettings;
2831 rightLayerRESettings.source.solidColor = rightLayerColor;
2832
Lloyd Pique01c77c12019-04-17 12:48:32 -07002833 EXPECT_CALL(leftOutputLayer, getState()).WillRepeatedly(ReturnRef(leftOutputLayerState));
2834 EXPECT_CALL(leftOutputLayer, getLayer()).WillRepeatedly(ReturnRef(leftLayer));
2835 EXPECT_CALL(leftOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(leftLayerFE));
2836 EXPECT_CALL(leftOutputLayer, requiresClientComposition()).WillRepeatedly(Return(true));
2837 EXPECT_CALL(leftOutputLayer, needsFiltering()).WillRepeatedly(Return(false));
Lloyd Pique9755fb72019-03-26 14:44:40 -07002838 EXPECT_CALL(leftLayer, getFEState()).WillRepeatedly(ReturnRef(leftLayerFEState));
Lloyd Pique56eba802019-08-28 15:45:25 -07002839 EXPECT_CALL(leftLayerFE, prepareClientComposition(_)).WillOnce(Return(leftLayerRESettings));
Adithya Srinivasanb69e0762019-11-11 18:39:53 -08002840 EXPECT_CALL(leftOutputLayer, editState()).WillRepeatedly(ReturnRef(leftOutputLayerState));
Lloyd Pique56eba802019-08-28 15:45:25 -07002841
Lloyd Pique01c77c12019-04-17 12:48:32 -07002842 EXPECT_CALL(rightOutputLayer, getState()).WillRepeatedly(ReturnRef(rightOutputLayerState));
2843 EXPECT_CALL(rightOutputLayer, getLayer()).WillRepeatedly(ReturnRef(rightLayer));
2844 EXPECT_CALL(rightOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(rightLayerFE));
2845 EXPECT_CALL(rightOutputLayer, requiresClientComposition()).WillRepeatedly(Return(true));
2846 EXPECT_CALL(rightOutputLayer, needsFiltering()).WillRepeatedly(Return(false));
Lloyd Pique9755fb72019-03-26 14:44:40 -07002847 EXPECT_CALL(rightLayer, getFEState()).WillRepeatedly(ReturnRef(rightLayerFEState));
Lloyd Pique56eba802019-08-28 15:45:25 -07002848 EXPECT_CALL(rightLayerFE, prepareClientComposition(_)).WillOnce(Return(rightLayerRESettings));
Adithya Srinivasanb69e0762019-11-11 18:39:53 -08002849 EXPECT_CALL(rightOutputLayer, editState()).WillRepeatedly(ReturnRef(rightOutputLayerState));
Lloyd Pique56eba802019-08-28 15:45:25 -07002850
Lloyd Pique01c77c12019-04-17 12:48:32 -07002851 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2u));
2852 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u))
2853 .WillRepeatedly(Return(&leftOutputLayer));
2854 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1u))
2855 .WillRepeatedly(Return(&rightOutputLayer));
Lloyd Pique56eba802019-08-28 15:45:25 -07002856
2857 const Rect kPortraitFrame(0, 0, 1000, 2000);
2858 const Rect kPortraitViewport(0, 0, 2000, 1000);
2859 const Rect kPortraitScissor(0, 0, 1000, 2000);
2860 const uint32_t kPortraitOrientation = TR_ROT_90;
2861
2862 mOutput.editState().frame = kPortraitFrame;
2863 mOutput.editState().viewport = kPortraitViewport;
2864 mOutput.editState().scissor = kPortraitScissor;
2865 mOutput.editState().transform = ui::Transform{kPortraitOrientation};
2866 mOutput.editState().orientation = kPortraitOrientation;
2867 mOutput.editState().needsFiltering = true;
2868 mOutput.editState().isSecure = false;
2869
2870 constexpr bool supportsProtectedContent = false;
2871 Region clearRegion;
2872 auto requests =
2873 mOutput.generateClientCompositionRequests(supportsProtectedContent, clearRegion);
2874
2875 ASSERT_EQ(2u, requests.size());
2876 EXPECT_EQ(leftLayerColor, requests[0].source.solidColor);
2877 EXPECT_EQ(rightLayerColor, requests[1].source.solidColor);
2878}
2879
2880TEST_F(GenerateClientCompositionRequestsTest, ignoresLayersThatDoNotIntersectWithViewport) {
2881 // Layers whose visible region does not intersect with the viewport will be
2882 // skipped when generating client composition request state.
2883
Lloyd Pique01c77c12019-04-17 12:48:32 -07002884 StrictMock<mock::OutputLayer> outputLayer;
Lloyd Pique56eba802019-08-28 15:45:25 -07002885 StrictMock<mock::Layer> layer;
2886 StrictMock<mock::LayerFE> layerFE;
2887
2888 impl::OutputLayerCompositionState outputLayerState;
2889 outputLayerState.clearClientTarget = false;
Lloyd Piquea2468662019-03-07 21:31:06 -08002890 outputLayerState.visibleRegion = Region{Rect{3000, 0, 4000, 1000}};
Lloyd Pique56eba802019-08-28 15:45:25 -07002891
Lloyd Pique9755fb72019-03-26 14:44:40 -07002892 LayerFECompositionState layerFEState;
2893 layerFEState.isOpaque = true;
Lloyd Pique56eba802019-08-28 15:45:25 -07002894
Lloyd Pique01c77c12019-04-17 12:48:32 -07002895 EXPECT_CALL(outputLayer, getState()).WillRepeatedly(ReturnRef(outputLayerState));
2896 EXPECT_CALL(outputLayer, getLayer()).WillRepeatedly(ReturnRef(layer));
2897 EXPECT_CALL(outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(layerFE));
2898 EXPECT_CALL(outputLayer, requiresClientComposition()).WillRepeatedly(Return(true));
2899 EXPECT_CALL(outputLayer, needsFiltering()).WillRepeatedly(Return(false));
Lloyd Pique9755fb72019-03-26 14:44:40 -07002900 EXPECT_CALL(layer, getFEState()).WillRepeatedly(ReturnRef(layerFEState));
Lloyd Pique56eba802019-08-28 15:45:25 -07002901 EXPECT_CALL(layerFE, prepareClientComposition(_)).Times(0);
Adithya Srinivasanb69e0762019-11-11 18:39:53 -08002902 EXPECT_CALL(outputLayer, editState()).WillRepeatedly(ReturnRef(outputLayerState));
Lloyd Pique56eba802019-08-28 15:45:25 -07002903
Lloyd Pique01c77c12019-04-17 12:48:32 -07002904 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(1u));
2905 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u)).WillRepeatedly(Return(&outputLayer));
Lloyd Pique56eba802019-08-28 15:45:25 -07002906
2907 const Rect kPortraitFrame(0, 0, 1000, 2000);
2908 const Rect kPortraitViewport(0, 0, 2000, 1000);
2909 const Rect kPortraitScissor(0, 0, 1000, 2000);
2910 const uint32_t kPortraitOrientation = TR_ROT_90;
2911
2912 mOutput.editState().frame = kPortraitFrame;
2913 mOutput.editState().viewport = kPortraitViewport;
2914 mOutput.editState().scissor = kPortraitScissor;
2915 mOutput.editState().transform = ui::Transform{kPortraitOrientation};
2916 mOutput.editState().orientation = kPortraitOrientation;
2917 mOutput.editState().needsFiltering = true;
2918 mOutput.editState().isSecure = false;
2919
2920 constexpr bool supportsProtectedContent = false;
2921 Region clearRegion;
2922 auto requests =
2923 mOutput.generateClientCompositionRequests(supportsProtectedContent, clearRegion);
2924
2925 EXPECT_EQ(0u, requests.size());
2926}
2927
Lloyd Piquec2d54d42019-08-28 18:04:21 -07002928TEST_F(GenerateClientCompositionRequestsTest, clearsDeviceLayesAfterFirst) {
2929 // If client composition is performed with some layers set to use device
2930 // composition, device layers after the first layer (device or client) will
2931 // clear the frame buffer if they are opaque and if that layer has a flag
2932 // set to do so. The first layer is skipped as the frame buffer is already
2933 // expected to be clear.
2934
Lloyd Pique01c77c12019-04-17 12:48:32 -07002935 StrictMock<mock::OutputLayer> leftOutputLayer;
2936 StrictMock<mock::OutputLayer> rightOutputLayer;
Lloyd Piquec2d54d42019-08-28 18:04:21 -07002937
2938 StrictMock<mock::Layer> leftLayer;
2939 StrictMock<mock::LayerFE> leftLayerFE;
2940 StrictMock<mock::Layer> rightLayer;
2941 StrictMock<mock::LayerFE> rightLayerFE;
2942
2943 impl::OutputLayerCompositionState leftOutputLayerState;
2944 leftOutputLayerState.clearClientTarget = true;
Lloyd Piquea2468662019-03-07 21:31:06 -08002945 leftOutputLayerState.visibleRegion = Region{Rect{0, 0, 1000, 1000}};
Lloyd Piquec2d54d42019-08-28 18:04:21 -07002946
Lloyd Pique9755fb72019-03-26 14:44:40 -07002947 LayerFECompositionState leftLayerFEState;
2948 leftLayerFEState.isOpaque = true;
Lloyd Piquec2d54d42019-08-28 18:04:21 -07002949
2950 impl::OutputLayerCompositionState rightOutputLayerState;
2951 rightOutputLayerState.clearClientTarget = true;
Lloyd Piquea2468662019-03-07 21:31:06 -08002952 rightOutputLayerState.visibleRegion = Region{Rect{1000, 0, 2000, 1000}};
Lloyd Piquec2d54d42019-08-28 18:04:21 -07002953
Lloyd Pique9755fb72019-03-26 14:44:40 -07002954 LayerFECompositionState rightLayerFEState;
2955 rightLayerFEState.isOpaque = true;
Lloyd Piquec2d54d42019-08-28 18:04:21 -07002956
2957 const half3 rightLayerColor{0.f, 1.f, 0.f};
2958 renderengine::LayerSettings rightLayerRESettings;
2959 rightLayerRESettings.geometry.boundaries = FloatRect{456, 0, 0, 0};
2960 rightLayerRESettings.source.solidColor = rightLayerColor;
2961
Lloyd Pique01c77c12019-04-17 12:48:32 -07002962 EXPECT_CALL(leftOutputLayer, getState()).WillRepeatedly(ReturnRef(leftOutputLayerState));
2963 EXPECT_CALL(leftOutputLayer, getLayer()).WillRepeatedly(ReturnRef(leftLayer));
2964 EXPECT_CALL(leftOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(leftLayerFE));
2965 EXPECT_CALL(leftOutputLayer, requiresClientComposition()).WillRepeatedly(Return(false));
2966 EXPECT_CALL(leftOutputLayer, needsFiltering()).WillRepeatedly(Return(false));
Lloyd Pique9755fb72019-03-26 14:44:40 -07002967 EXPECT_CALL(leftLayer, getFEState()).WillRepeatedly(ReturnRef(leftLayerFEState));
Adithya Srinivasanb69e0762019-11-11 18:39:53 -08002968 EXPECT_CALL(leftOutputLayer, editState()).WillRepeatedly(ReturnRef(leftOutputLayerState));
Lloyd Piquec2d54d42019-08-28 18:04:21 -07002969
Lloyd Pique01c77c12019-04-17 12:48:32 -07002970 EXPECT_CALL(rightOutputLayer, getState()).WillRepeatedly(ReturnRef(rightOutputLayerState));
2971 EXPECT_CALL(rightOutputLayer, getLayer()).WillRepeatedly(ReturnRef(rightLayer));
2972 EXPECT_CALL(rightOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(rightLayerFE));
2973 EXPECT_CALL(rightOutputLayer, requiresClientComposition()).WillRepeatedly(Return(false));
2974 EXPECT_CALL(rightOutputLayer, needsFiltering()).WillRepeatedly(Return(false));
Lloyd Pique9755fb72019-03-26 14:44:40 -07002975 EXPECT_CALL(rightLayer, getFEState()).WillRepeatedly(ReturnRef(rightLayerFEState));
Lloyd Piquec2d54d42019-08-28 18:04:21 -07002976 EXPECT_CALL(rightLayerFE, prepareClientComposition(_)).WillOnce(Return(rightLayerRESettings));
Adithya Srinivasanb69e0762019-11-11 18:39:53 -08002977 EXPECT_CALL(rightOutputLayer, editState()).WillRepeatedly(ReturnRef(rightOutputLayerState));
Lloyd Piquec2d54d42019-08-28 18:04:21 -07002978
Lloyd Pique01c77c12019-04-17 12:48:32 -07002979 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2u));
2980 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u))
2981 .WillRepeatedly(Return(&leftOutputLayer));
2982 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1u))
2983 .WillRepeatedly(Return(&rightOutputLayer));
Lloyd Piquec2d54d42019-08-28 18:04:21 -07002984
2985 const Rect kPortraitFrame(0, 0, 1000, 2000);
2986 const Rect kPortraitViewport(0, 0, 2000, 1000);
2987 const Rect kPortraitScissor(0, 0, 1000, 2000);
2988 const uint32_t kPortraitOrientation = TR_ROT_90;
2989
2990 mOutput.editState().frame = kPortraitFrame;
2991 mOutput.editState().viewport = kPortraitViewport;
2992 mOutput.editState().scissor = kPortraitScissor;
2993 mOutput.editState().transform = ui::Transform{kPortraitOrientation};
2994 mOutput.editState().orientation = kPortraitOrientation;
2995 mOutput.editState().needsFiltering = true;
2996 mOutput.editState().isSecure = false;
2997
2998 constexpr bool supportsProtectedContent = false;
2999 Region clearRegion;
3000 auto requests =
3001 mOutput.generateClientCompositionRequests(supportsProtectedContent, clearRegion);
3002
3003 const half3 clearColor{0.f, 0.f, 0.f};
3004
3005 ASSERT_EQ(1u, requests.size());
3006 EXPECT_EQ(456.f, requests[0].geometry.boundaries.left);
3007 EXPECT_EQ(clearColor, requests[0].source.solidColor);
3008}
3009
Lloyd Pique32cbe282018-10-19 13:09:22 -07003010} // namespace
3011} // namespace android::compositionengine