blob: b4789f1edec9751dd0d9e208d2bc461f6c95b658 [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
Lloyd Pique17ca7422019-11-14 14:24:10 -080017#include <android-base/stringprintf.h>
Alec Mourif97df4d2023-09-06 02:10:05 +000018#include <com_android_graphics_surfaceflinger_flags.h>
Lloyd Pique9755fb72019-03-26 14:44:40 -070019#include <compositionengine/LayerFECompositionState.h>
Lloyd Pique32cbe282018-10-19 13:09:22 -070020#include <compositionengine/impl/Output.h>
Lloyd Pique66d68602019-02-13 14:23:31 -080021#include <compositionengine/impl/OutputCompositionState.h>
Lloyd Pique56eba802019-08-28 15:45:25 -070022#include <compositionengine/impl/OutputLayerCompositionState.h>
Lloyd Pique32cbe282018-10-19 13:09:22 -070023#include <compositionengine/mock/CompositionEngine.h>
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070024#include <compositionengine/mock/DisplayColorProfile.h>
Lloyd Piquecc01a452018-12-04 17:24:00 -080025#include <compositionengine/mock/LayerFE.h>
26#include <compositionengine/mock/OutputLayer.h>
Lloyd Pique31cb2942018-10-19 17:23:03 -070027#include <compositionengine/mock/RenderSurface.h>
Sally Qi59a9f502021-10-12 18:53:23 +000028#include <ftl/future.h>
Lloyd Pique32cbe282018-10-19 13:09:22 -070029#include <gtest/gtest.h>
Vishnu Nairdbbe3852022-01-12 20:22:11 -080030#include <renderengine/ExternalTexture.h>
31#include <renderengine/impl/ExternalTexture.h>
Vishnu Naira3140382022-02-24 14:07:11 -080032#include <renderengine/mock/FakeExternalTexture.h>
Lloyd Pique56eba802019-08-28 15:45:25 -070033#include <renderengine/mock/RenderEngine.h>
Lloyd Pique32cbe282018-10-19 13:09:22 -070034#include <ui/Rect.h>
35#include <ui/Region.h>
36
Alec Mouria90a5702021-04-16 16:36:21 +000037#include <cmath>
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -040038#include <cstdint>
Leon Scroggins III2f60d732022-09-12 14:42:38 -040039#include <variant>
Alec Mouria90a5702021-04-16 16:36:21 +000040
Alec Mourif97df4d2023-09-06 02:10:05 +000041#include <common/FlagManager.h>
42#include <common/test/FlagUtils.h>
Lloyd Pique17ca7422019-11-14 14:24:10 -080043#include "CallOrderStateMachineHelper.h"
Lloyd Pique07178e32019-11-19 19:15:26 -080044#include "MockHWC2.h"
Lloyd Pique32cbe282018-10-19 13:09:22 -070045#include "RegionMatcher.h"
Lloyd Pique32cbe282018-10-19 13:09:22 -070046
47namespace android::compositionengine {
48namespace {
49
Alec Mourif97df4d2023-09-06 02:10:05 +000050using namespace com::android::graphics::surfaceflinger;
51
Lloyd Pique56eba802019-08-28 15:45:25 -070052using testing::_;
Lloyd Pique03561a62019-11-19 18:34:52 -080053using testing::ByMove;
Lloyd Piquea4863342019-12-04 18:45:02 -080054using testing::ByRef;
Lloyd Pique17ca7422019-11-14 14:24:10 -080055using testing::DoAll;
Vishnu Nair9b079a22020-01-21 14:36:08 -080056using testing::ElementsAre;
Lloyd Pique6818fa52019-12-03 12:32:13 -080057using testing::ElementsAreArray;
Lloyd Pique07178e32019-11-19 19:15:26 -080058using testing::Eq;
Lloyd Piquefaa3f192019-11-14 14:05:09 -080059using testing::InSequence;
Lloyd Pique6818fa52019-12-03 12:32:13 -080060using testing::Invoke;
61using testing::IsEmpty;
Lloyd Pique17ca7422019-11-14 14:24:10 -080062using testing::Mock;
Leon Scroggins III2f60d732022-09-12 14:42:38 -040063using testing::NiceMock;
Vishnu Nair9b079a22020-01-21 14:36:08 -080064using testing::Pointee;
Lloyd Pique07178e32019-11-19 19:15:26 -080065using testing::Property;
Lloyd Piquefaa3f192019-11-14 14:05:09 -080066using testing::Ref;
Lloyd Pique31cb2942018-10-19 17:23:03 -070067using testing::Return;
Lloyd Pique32cbe282018-10-19 13:09:22 -070068using testing::ReturnRef;
Lloyd Pique17ca7422019-11-14 14:24:10 -080069using testing::SetArgPointee;
Lloyd Pique32cbe282018-10-19 13:09:22 -070070using testing::StrictMock;
71
Lloyd Pique56eba802019-08-28 15:45:25 -070072constexpr auto TR_IDENT = 0u;
73constexpr auto TR_ROT_90 = HAL_TRANSFORM_ROT_90;
Vishnu Nair9b079a22020-01-21 14:36:08 -080074constexpr auto MAX_CLIENT_COMPOSITION_CACHE_SIZE = 3;
Lloyd Pique56eba802019-08-28 15:45:25 -070075
Lloyd Pique3eb1b212019-03-07 21:15:40 -080076const mat4 kIdentity;
Lloyd Pique0a456232020-01-16 17:51:13 -080077const mat4 kNonIdentityHalf = mat4() * 0.5f;
78const mat4 kNonIdentityQuarter = mat4() * 0.25f;
Lloyd Pique3eb1b212019-03-07 21:15:40 -080079
Lloyd Pique17ca7422019-11-14 14:24:10 -080080constexpr OutputColorSetting kVendorSpecifiedOutputColorSetting =
81 static_cast<OutputColorSetting>(0x100);
82
Vishnu Nair9cf89262022-02-26 09:17:49 -080083using CompositionStrategyPredictionState = android::compositionengine::impl::
84 OutputCompositionState::CompositionStrategyPredictionState;
85
Lloyd Piquefaa3f192019-11-14 14:05:09 -080086struct OutputPartialMockBase : public impl::Output {
87 // compositionengine::Output overrides
88 const OutputCompositionState& getState() const override { return mState; }
89 OutputCompositionState& editState() override { return mState; }
90
91 // Use mocks for all the remaining virtual functions
92 // not implemented by the base implementation class.
93 MOCK_CONST_METHOD0(getOutputLayerCount, size_t());
94 MOCK_CONST_METHOD1(getOutputLayerOrderedByZByIndex, compositionengine::OutputLayer*(size_t));
Lloyd Piquede196652020-01-22 17:29:58 -080095 MOCK_METHOD2(ensureOutputLayer,
96 compositionengine::OutputLayer*(std::optional<size_t>, const sp<LayerFE>&));
Lloyd Piquefaa3f192019-11-14 14:05:09 -080097 MOCK_METHOD0(finalizePendingOutputLayers, void());
98 MOCK_METHOD0(clearOutputLayers, void());
99 MOCK_CONST_METHOD1(dumpState, void(std::string&));
100 MOCK_CONST_METHOD0(getCompositionEngine, const CompositionEngine&());
Lloyd Piquede196652020-01-22 17:29:58 -0800101 MOCK_METHOD1(injectOutputLayerForTest, compositionengine::OutputLayer*(const sp<LayerFE>&));
Lloyd Piquefaa3f192019-11-14 14:05:09 -0800102 MOCK_METHOD1(injectOutputLayerForTest, void(std::unique_ptr<OutputLayer>));
103
104 impl::OutputCompositionState mState;
105};
106
Lloyd Piquede196652020-01-22 17:29:58 -0800107struct InjectedLayer {
108 InjectedLayer() {
109 EXPECT_CALL(*outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*layerFE.get()));
110 EXPECT_CALL(*outputLayer, getState()).WillRepeatedly(ReturnRef(outputLayerState));
111 EXPECT_CALL(*outputLayer, editState()).WillRepeatedly(ReturnRef(outputLayerState));
112
113 EXPECT_CALL(*layerFE, getCompositionState()).WillRepeatedly(Return(&layerFEState));
Dan Stoza269dc4d2021-01-15 15:07:43 -0800114 EXPECT_CALL(*layerFE, getSequence()).WillRepeatedly(Return(0));
115 EXPECT_CALL(*layerFE, getDebugName()).WillRepeatedly(Return("InjectedLayer"));
Lloyd Piquede196652020-01-22 17:29:58 -0800116 }
117
118 mock::OutputLayer* outputLayer = {new StrictMock<mock::OutputLayer>};
Ady Abrahame0eafa82022-02-02 19:30:47 -0800119 sp<StrictMock<mock::LayerFE>> layerFE = sp<StrictMock<mock::LayerFE>>::make();
Lloyd Piquede196652020-01-22 17:29:58 -0800120 LayerFECompositionState layerFEState;
121 impl::OutputLayerCompositionState outputLayerState;
122};
123
124struct NonInjectedLayer {
125 NonInjectedLayer() {
126 EXPECT_CALL(outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*layerFE.get()));
127 EXPECT_CALL(outputLayer, getState()).WillRepeatedly(ReturnRef(outputLayerState));
128 EXPECT_CALL(outputLayer, editState()).WillRepeatedly(ReturnRef(outputLayerState));
129
130 EXPECT_CALL(*layerFE, getCompositionState()).WillRepeatedly(Return(&layerFEState));
Dan Stoza269dc4d2021-01-15 15:07:43 -0800131 EXPECT_CALL(*layerFE, getSequence()).WillRepeatedly(Return(0));
132 EXPECT_CALL(*layerFE, getDebugName()).WillRepeatedly(Return("NonInjectedLayer"));
Lloyd Piquede196652020-01-22 17:29:58 -0800133 }
134
135 mock::OutputLayer outputLayer;
Ady Abrahame0eafa82022-02-02 19:30:47 -0800136 sp<StrictMock<mock::LayerFE>> layerFE = sp<StrictMock<mock::LayerFE>>::make();
Lloyd Piquede196652020-01-22 17:29:58 -0800137 LayerFECompositionState layerFEState;
138 impl::OutputLayerCompositionState outputLayerState;
139};
140
Lloyd Pique66d68602019-02-13 14:23:31 -0800141struct OutputTest : public testing::Test {
Lloyd Pique01c77c12019-04-17 12:48:32 -0700142 class Output : public impl::Output {
143 public:
144 using impl::Output::injectOutputLayerForTest;
145 virtual void injectOutputLayerForTest(std::unique_ptr<compositionengine::OutputLayer>) = 0;
146 };
147
148 static std::shared_ptr<Output> createOutput(
149 const compositionengine::CompositionEngine& compositionEngine) {
150 return impl::createOutputTemplated<Output>(compositionEngine);
151 }
152
Lloyd Pique31cb2942018-10-19 17:23:03 -0700153 OutputTest() {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700154 mOutput->setDisplayColorProfileForTest(
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700155 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700156 mOutput->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
Lloyd Piqueef958122019-02-05 18:00:12 -0800157
Angel Aguayob084e0c2021-08-04 23:27:28 +0000158 mOutput->editState().displaySpace.setBounds(
159 ui::Size(kDefaultDisplaySize.getWidth(), kDefaultDisplaySize.getHeight()));
Alec Mouridf6201b2021-06-01 16:20:42 -0700160 EXPECT_CALL(mCompositionEngine, getRenderEngine()).WillRepeatedly(ReturnRef(mRenderEngine));
Lloyd Pique31cb2942018-10-19 17:23:03 -0700161 }
Lloyd Pique32cbe282018-10-19 13:09:22 -0700162
Lloyd Piquede196652020-01-22 17:29:58 -0800163 void injectOutputLayer(InjectedLayer& layer) {
164 mOutput->injectOutputLayerForTest(std::unique_ptr<OutputLayer>(layer.outputLayer));
165 }
166
167 void injectNullOutputLayer() {
168 mOutput->injectOutputLayerForTest(std::unique_ptr<OutputLayer>(nullptr));
169 }
170
Lloyd Piqueef958122019-02-05 18:00:12 -0800171 static const Rect kDefaultDisplaySize;
172
Lloyd Pique32cbe282018-10-19 13:09:22 -0700173 StrictMock<mock::CompositionEngine> mCompositionEngine;
Alec Mouridf6201b2021-06-01 16:20:42 -0700174 StrictMock<renderengine::mock::RenderEngine> mRenderEngine;
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700175 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
Lloyd Pique31cb2942018-10-19 17:23:03 -0700176 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
Lloyd Pique01c77c12019-04-17 12:48:32 -0700177 std::shared_ptr<Output> mOutput = createOutput(mCompositionEngine);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700178};
179
Lloyd Piqueef958122019-02-05 18:00:12 -0800180const Rect OutputTest::kDefaultDisplaySize{100, 200};
181
Lloyd Pique17ca7422019-11-14 14:24:10 -0800182using ColorProfile = compositionengine::Output::ColorProfile;
183
184void dumpColorProfile(ColorProfile profile, std::string& result, const char* name) {
Alec Mouri88790f32023-07-21 01:25:14 +0000185 android::base::StringAppendF(&result, "%s (%s[%d] %s[%d] %s[%d]) ", name,
Lloyd Pique17ca7422019-11-14 14:24:10 -0800186 toString(profile.mode).c_str(), profile.mode,
187 toString(profile.dataspace).c_str(), profile.dataspace,
Alec Mouri88790f32023-07-21 01:25:14 +0000188 toString(profile.renderIntent).c_str(), profile.renderIntent);
Lloyd Pique17ca7422019-11-14 14:24:10 -0800189}
190
191// Checks for a ColorProfile match
192MATCHER_P(ColorProfileEq, expected, "") {
193 std::string buf;
194 buf.append("ColorProfiles are not equal\n");
195 dumpColorProfile(expected, buf, "expected value");
196 dumpColorProfile(arg, buf, "actual value");
197 *result_listener << buf;
198
199 return (expected.mode == arg.mode) && (expected.dataspace == arg.dataspace) &&
Alec Mouri88790f32023-07-21 01:25:14 +0000200 (expected.renderIntent == arg.renderIntent);
Lloyd Pique17ca7422019-11-14 14:24:10 -0800201}
202
Lloyd Pique66d68602019-02-13 14:23:31 -0800203/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700204 * Basic construction
205 */
206
Lloyd Pique31cb2942018-10-19 17:23:03 -0700207TEST_F(OutputTest, canInstantiateOutput) {
208 // The validation check checks each required component.
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700209 EXPECT_CALL(*mDisplayColorProfile, isValid()).WillOnce(Return(true));
Lloyd Pique31cb2942018-10-19 17:23:03 -0700210 EXPECT_CALL(*mRenderSurface, isValid()).WillOnce(Return(true));
211
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700212 EXPECT_TRUE(mOutput->isValid());
Lloyd Pique31cb2942018-10-19 17:23:03 -0700213
214 // If we take away the required components, it is no longer valid.
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700215 mOutput->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>());
Lloyd Pique31cb2942018-10-19 17:23:03 -0700216
Lloyd Pique3d0c02e2018-10-19 18:38:12 -0700217 EXPECT_CALL(*mDisplayColorProfile, isValid()).WillOnce(Return(true));
218
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700219 EXPECT_FALSE(mOutput->isValid());
Lloyd Pique31cb2942018-10-19 17:23:03 -0700220}
Lloyd Pique32cbe282018-10-19 13:09:22 -0700221
Lloyd Pique66d68602019-02-13 14:23:31 -0800222/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700223 * Output::setCompositionEnabled()
224 */
225
226TEST_F(OutputTest, setCompositionEnabledDoesNothingIfAlreadyEnabled) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700227 mOutput->editState().isEnabled = true;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700228
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700229 mOutput->setCompositionEnabled(true);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700230
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700231 EXPECT_TRUE(mOutput->getState().isEnabled);
232 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region()));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700233}
234
235TEST_F(OutputTest, setCompositionEnabledSetsEnabledAndDirtiesEntireOutput) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700236 mOutput->editState().isEnabled = false;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700237
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700238 mOutput->setCompositionEnabled(true);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700239
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700240 EXPECT_TRUE(mOutput->getState().isEnabled);
241 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700242}
243
244TEST_F(OutputTest, setCompositionEnabledSetsDisabledAndDirtiesEntireOutput) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700245 mOutput->editState().isEnabled = true;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700246
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700247 mOutput->setCompositionEnabled(false);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700248
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700249 EXPECT_FALSE(mOutput->getState().isEnabled);
250 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700251}
252
Lloyd Pique66d68602019-02-13 14:23:31 -0800253/*
Alec Mouridda07d92022-04-25 22:39:25 +0000254 * Output::setTreat170mAsSrgb()
255 */
256
257TEST_F(OutputTest, setTreat170mAsSrgb) {
258 EXPECT_FALSE(mOutput->getState().treat170mAsSrgb);
259
260 mOutput->setTreat170mAsSrgb(true);
261 EXPECT_TRUE(mOutput->getState().treat170mAsSrgb);
262
263 mOutput->setTreat170mAsSrgb(false);
264 EXPECT_FALSE(mOutput->getState().treat170mAsSrgb);
265}
266
267/*
Alec Mouri023c1882021-05-08 16:36:33 -0700268 * Output::setLayerCachingEnabled()
269 */
270
271TEST_F(OutputTest, setLayerCachingEnabled_enablesCaching) {
272 const auto kSize = ui::Size(1, 1);
273 EXPECT_CALL(*mRenderSurface, getSize()).WillRepeatedly(ReturnRef(kSize));
274 mOutput->setLayerCachingEnabled(false);
275 mOutput->setLayerCachingEnabled(true);
276
277 EXPECT_TRUE(mOutput->plannerEnabled());
278}
279
280TEST_F(OutputTest, setLayerCachingEnabled_disablesCaching) {
281 const auto kSize = ui::Size(1, 1);
282 EXPECT_CALL(*mRenderSurface, getSize()).WillRepeatedly(ReturnRef(kSize));
283 mOutput->setLayerCachingEnabled(true);
284 mOutput->setLayerCachingEnabled(false);
285
286 EXPECT_FALSE(mOutput->plannerEnabled());
287}
288
Alec Mouric773472b2021-05-19 14:29:05 -0700289TEST_F(OutputTest, setLayerCachingEnabled_disablesCachingAndResetsOverrideInfo) {
290 renderengine::mock::RenderEngine renderEngine;
291 const auto kSize = ui::Size(1, 1);
292 EXPECT_CALL(*mRenderSurface, getSize()).WillRepeatedly(ReturnRef(kSize));
293 mOutput->setLayerCachingEnabled(true);
294
295 // Inject some layers
296 InjectedLayer layer;
297 layer.outputLayerState.overrideInfo.buffer = std::make_shared<
Vishnu Nairdbbe3852022-01-12 20:22:11 -0800298 renderengine::impl::
Ady Abrahamd11bade2022-08-01 16:18:03 -0700299 ExternalTexture>(sp<GraphicBuffer>::make(), renderEngine,
Vishnu Nairdbbe3852022-01-12 20:22:11 -0800300 renderengine::impl::ExternalTexture::Usage::READABLE |
301 renderengine::impl::ExternalTexture::Usage::WRITEABLE);
Alec Mouric773472b2021-05-19 14:29:05 -0700302 injectOutputLayer(layer);
303 // inject a null layer to check for null exceptions
304 injectNullOutputLayer();
305
306 EXPECT_NE(nullptr, layer.outputLayerState.overrideInfo.buffer);
307 mOutput->setLayerCachingEnabled(false);
308 EXPECT_EQ(nullptr, layer.outputLayerState.overrideInfo.buffer);
309}
310
Alec Mouri023c1882021-05-08 16:36:33 -0700311/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700312 * Output::setProjection()
313 */
314
Marin Shalamanov209ae612020-10-01 00:17:39 +0200315TEST_F(OutputTest, setProjectionWorks) {
316 const Rect displayRect{0, 0, 1000, 2000};
Angel Aguayob084e0c2021-08-04 23:27:28 +0000317 mOutput->editState().displaySpace.setBounds(
318 ui::Size(displayRect.getWidth(), displayRect.getHeight()));
319 mOutput->editState().framebufferSpace.setBounds(
320 ui::Size(displayRect.getWidth(), displayRect.getHeight()));
Marin Shalamanov209ae612020-10-01 00:17:39 +0200321
Marin Shalamanov68933fb2020-09-10 17:58:12 +0200322 const ui::Rotation orientation = ui::ROTATION_90;
Marin Shalamanov209ae612020-10-01 00:17:39 +0200323 const Rect frame{50, 60, 100, 100};
324 const Rect viewport{10, 20, 30, 40};
Lloyd Pique32cbe282018-10-19 13:09:22 -0700325
Marin Shalamanov68933fb2020-09-10 17:58:12 +0200326 mOutput->setProjection(orientation, viewport, frame);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700327
Angel Aguayob084e0c2021-08-04 23:27:28 +0000328 EXPECT_EQ(orientation, mOutput->getState().displaySpace.getOrientation());
329 EXPECT_EQ(frame, mOutput->getState().orientedDisplaySpace.getContent());
330 EXPECT_EQ(viewport, mOutput->getState().layerStackSpace.getContent());
Marin Shalamanov209ae612020-10-01 00:17:39 +0200331
332 const auto state = mOutput->getState();
Angel Aguayob084e0c2021-08-04 23:27:28 +0000333 EXPECT_EQ(ui::ROTATION_0, state.layerStackSpace.getOrientation());
334 EXPECT_EQ(viewport, state.layerStackSpace.getContent());
335 EXPECT_EQ(Rect(0, 0, 20, 20), state.layerStackSpace.getBoundsAsRect());
Marin Shalamanov209ae612020-10-01 00:17:39 +0200336
Angel Aguayob084e0c2021-08-04 23:27:28 +0000337 EXPECT_EQ(ui::ROTATION_0, state.orientedDisplaySpace.getOrientation());
338 EXPECT_EQ(frame, state.orientedDisplaySpace.getContent());
339 EXPECT_EQ(Rect(0, 0, 2000, 1000), state.orientedDisplaySpace.getBoundsAsRect());
Marin Shalamanov209ae612020-10-01 00:17:39 +0200340
Angel Aguayob084e0c2021-08-04 23:27:28 +0000341 EXPECT_EQ(displayRect, state.displaySpace.getBoundsAsRect());
342 EXPECT_EQ(Rect(900, 50, 940, 100), state.displaySpace.getContent());
343 EXPECT_EQ(orientation, state.displaySpace.getOrientation());
Marin Shalamanov209ae612020-10-01 00:17:39 +0200344
Angel Aguayob084e0c2021-08-04 23:27:28 +0000345 EXPECT_EQ(displayRect, state.framebufferSpace.getBoundsAsRect());
346 EXPECT_EQ(Rect(900, 50, 940, 100), state.framebufferSpace.getContent());
347 EXPECT_EQ(orientation, state.framebufferSpace.getOrientation());
Marin Shalamanov209ae612020-10-01 00:17:39 +0200348
Angel Aguayob084e0c2021-08-04 23:27:28 +0000349 EXPECT_EQ(state.displaySpace.getContent(),
350 state.transform.transform(state.layerStackSpace.getContent()));
Garfield Tan54edd912020-10-21 16:31:41 -0700351
352 EXPECT_EQ(ui::Transform::ROT_90, mOutput->getTransformHint());
Marin Shalamanov209ae612020-10-01 00:17:39 +0200353}
354
355TEST_F(OutputTest, setProjectionWithSmallFramebufferWorks) {
356 const Rect displayRect{0, 0, 1000, 2000};
357 const Rect framebufferRect{0, 0, 500, 1000};
Angel Aguayob084e0c2021-08-04 23:27:28 +0000358 mOutput->editState().displaySpace.setBounds(
359 ui::Size(displayRect.getWidth(), displayRect.getHeight()));
360 mOutput->editState().framebufferSpace.setBounds(
361 ui::Size(framebufferRect.getWidth(), framebufferRect.getHeight()));
Marin Shalamanov209ae612020-10-01 00:17:39 +0200362
363 const ui::Rotation orientation = ui::ROTATION_90;
364 const Rect frame{50, 60, 100, 100};
365 const Rect viewport{10, 20, 30, 40};
366
367 mOutput->setProjection(orientation, viewport, frame);
368
Angel Aguayob084e0c2021-08-04 23:27:28 +0000369 EXPECT_EQ(orientation, mOutput->getState().displaySpace.getOrientation());
370 EXPECT_EQ(frame, mOutput->getState().orientedDisplaySpace.getContent());
371 EXPECT_EQ(viewport, mOutput->getState().layerStackSpace.getContent());
Marin Shalamanov209ae612020-10-01 00:17:39 +0200372
373 const auto state = mOutput->getState();
Angel Aguayob084e0c2021-08-04 23:27:28 +0000374 EXPECT_EQ(ui::ROTATION_0, state.layerStackSpace.getOrientation());
375 EXPECT_EQ(viewport, state.layerStackSpace.getContent());
376 EXPECT_EQ(Rect(0, 0, 20, 20), state.layerStackSpace.getBoundsAsRect());
Marin Shalamanov209ae612020-10-01 00:17:39 +0200377
Angel Aguayob084e0c2021-08-04 23:27:28 +0000378 EXPECT_EQ(ui::ROTATION_0, state.orientedDisplaySpace.getOrientation());
379 EXPECT_EQ(frame, state.orientedDisplaySpace.getContent());
380 EXPECT_EQ(Rect(0, 0, 2000, 1000), state.orientedDisplaySpace.getBoundsAsRect());
Marin Shalamanov209ae612020-10-01 00:17:39 +0200381
Angel Aguayob084e0c2021-08-04 23:27:28 +0000382 EXPECT_EQ(displayRect, state.displaySpace.getBoundsAsRect());
383 EXPECT_EQ(Rect(900, 50, 940, 100), state.displaySpace.getContent());
384 EXPECT_EQ(orientation, state.displaySpace.getOrientation());
Marin Shalamanov209ae612020-10-01 00:17:39 +0200385
Angel Aguayob084e0c2021-08-04 23:27:28 +0000386 EXPECT_EQ(framebufferRect, state.framebufferSpace.getBoundsAsRect());
387 EXPECT_EQ(Rect(450, 25, 470, 50), state.framebufferSpace.getContent());
388 EXPECT_EQ(orientation, state.framebufferSpace.getOrientation());
Marin Shalamanov209ae612020-10-01 00:17:39 +0200389
Angel Aguayob084e0c2021-08-04 23:27:28 +0000390 EXPECT_EQ(state.displaySpace.getContent(),
391 state.transform.transform(state.layerStackSpace.getContent()));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700392}
393
Lloyd Pique66d68602019-02-13 14:23:31 -0800394/*
Marin Shalamanovb15d2272020-09-17 21:41:52 +0200395 * Output::setDisplaySize()
Lloyd Pique32cbe282018-10-19 13:09:22 -0700396 */
397
Marin Shalamanovb15d2272020-09-17 21:41:52 +0200398TEST_F(OutputTest, setDisplaySpaceSizeUpdatesOutputStateAndDirtiesEntireOutput) {
Angel Aguayob084e0c2021-08-04 23:27:28 +0000399 mOutput->editState().layerStackSpace.setContent(Rect(0, 0, 2000, 1000));
400 mOutput->editState().layerStackSpace.setBounds(ui::Size(2000, 1000));
401 mOutput->editState().orientedDisplaySpace.setContent(Rect(0, 0, 1800, 900));
402 mOutput->editState().orientedDisplaySpace.setBounds(ui::Size(2000, 1000));
403 mOutput->editState().framebufferSpace.setContent(Rect(0, 0, 900, 1800));
404 mOutput->editState().framebufferSpace.setBounds(ui::Size(1000, 2000));
405 mOutput->editState().framebufferSpace.setOrientation(ui::ROTATION_90);
406 mOutput->editState().displaySpace.setContent(Rect(0, 0, 900, 1800));
407 mOutput->editState().displaySpace.setBounds(ui::Size(1000, 2000));
408 mOutput->editState().displaySpace.setOrientation(ui::ROTATION_90);
Lloyd Pique31cb2942018-10-19 17:23:03 -0700409
Marin Shalamanovb15d2272020-09-17 21:41:52 +0200410 const ui::Size newDisplaySize{500, 1000};
Lloyd Pique31cb2942018-10-19 17:23:03 -0700411
Marin Shalamanovb15d2272020-09-17 21:41:52 +0200412 EXPECT_CALL(*mRenderSurface, setDisplaySize(newDisplaySize)).Times(1);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700413
Marin Shalamanovb15d2272020-09-17 21:41:52 +0200414 mOutput->setDisplaySize(newDisplaySize);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700415
Marin Shalamanovb15d2272020-09-17 21:41:52 +0200416 const auto state = mOutput->getState();
417
418 const Rect displayRect(newDisplaySize);
Angel Aguayob084e0c2021-08-04 23:27:28 +0000419 EXPECT_EQ(ui::ROTATION_0, state.layerStackSpace.getOrientation());
420 EXPECT_EQ(Rect(0, 0, 2000, 1000), state.layerStackSpace.getContent());
421 EXPECT_EQ(Rect(0, 0, 2000, 1000), state.layerStackSpace.getBoundsAsRect());
Marin Shalamanov209ae612020-10-01 00:17:39 +0200422
Angel Aguayob084e0c2021-08-04 23:27:28 +0000423 EXPECT_EQ(ui::ROTATION_0, state.orientedDisplaySpace.getOrientation());
424 EXPECT_EQ(Rect(0, 0, 1000, 500), state.orientedDisplaySpace.getBoundsAsRect());
Marin Shalamanov209ae612020-10-01 00:17:39 +0200425
Angel Aguayob084e0c2021-08-04 23:27:28 +0000426 EXPECT_EQ(displayRect, state.displaySpace.getBoundsAsRect());
427 EXPECT_EQ(ui::ROTATION_90, state.displaySpace.getOrientation());
Marin Shalamanov209ae612020-10-01 00:17:39 +0200428
Angel Aguayob084e0c2021-08-04 23:27:28 +0000429 EXPECT_EQ(displayRect, state.framebufferSpace.getBoundsAsRect());
430 EXPECT_EQ(ui::ROTATION_90, state.framebufferSpace.getOrientation());
Marin Shalamanovb15d2272020-09-17 21:41:52 +0200431
Angel Aguayob084e0c2021-08-04 23:27:28 +0000432 EXPECT_EQ(state.displaySpace.getContent(),
433 state.transform.transform(state.layerStackSpace.getContent()));
Marin Shalamanovb15d2272020-09-17 21:41:52 +0200434
435 EXPECT_THAT(state.dirtyRegion, RegionEq(Region(displayRect)));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700436}
437
Lloyd Pique66d68602019-02-13 14:23:31 -0800438/*
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700439 * Output::setLayerFilter()
Lloyd Pique32cbe282018-10-19 13:09:22 -0700440 */
441
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700442TEST_F(OutputTest, setLayerFilterSetsFilterAndDirtiesEntireOutput) {
443 constexpr ui::LayerFilter kFilter{ui::LayerStack{123u}, true};
444 mOutput->setLayerFilter(kFilter);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700445
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700446 const auto& state = mOutput->getState();
447 EXPECT_EQ(kFilter.layerStack, state.layerFilter.layerStack);
448 EXPECT_TRUE(state.layerFilter.toInternalDisplay);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700449
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700450 EXPECT_THAT(state.dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700451}
452
Lloyd Pique66d68602019-02-13 14:23:31 -0800453/*
Lloyd Pique32cbe282018-10-19 13:09:22 -0700454 * Output::setColorTransform
455 */
456
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800457TEST_F(OutputTest, setColorTransformWithNoChangeFlaggedSkipsUpdates) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700458 mOutput->editState().colorTransformMatrix = kIdentity;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700459
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800460 // If no colorTransformMatrix is set the update should be skipped.
461 CompositionRefreshArgs refreshArgs;
462 refreshArgs.colorTransformMatrix = std::nullopt;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700463
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700464 mOutput->setColorTransform(refreshArgs);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700465
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800466 // The internal state should be unchanged
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700467 EXPECT_EQ(kIdentity, mOutput->getState().colorTransformMatrix);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800468
469 // No dirty region should be set
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700470 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region()));
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800471}
Lloyd Piqueef958122019-02-05 18:00:12 -0800472
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800473TEST_F(OutputTest, setColorTransformWithNoActualChangeSkipsUpdates) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700474 mOutput->editState().colorTransformMatrix = kIdentity;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700475
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800476 // Attempting to set the same colorTransformMatrix that is already set should
477 // also skip the update.
478 CompositionRefreshArgs refreshArgs;
479 refreshArgs.colorTransformMatrix = kIdentity;
Lloyd Pique32cbe282018-10-19 13:09:22 -0700480
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700481 mOutput->setColorTransform(refreshArgs);
Lloyd Pique77f79a22019-04-29 15:55:40 -0700482
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800483 // The internal state should be unchanged
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700484 EXPECT_EQ(kIdentity, mOutput->getState().colorTransformMatrix);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800485
486 // No dirty region should be set
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700487 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region()));
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800488}
489
490TEST_F(OutputTest, setColorTransformPerformsUpdateToIdentity) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700491 mOutput->editState().colorTransformMatrix = kNonIdentityHalf;
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800492
493 // Setting a different colorTransformMatrix should perform the update.
494 CompositionRefreshArgs refreshArgs;
495 refreshArgs.colorTransformMatrix = kIdentity;
496
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700497 mOutput->setColorTransform(refreshArgs);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800498
499 // The internal state should have been updated
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700500 EXPECT_EQ(kIdentity, mOutput->getState().colorTransformMatrix);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800501
502 // The dirtyRegion should be set to the full display size
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700503 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800504}
Lloyd Pique77f79a22019-04-29 15:55:40 -0700505
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800506TEST_F(OutputTest, setColorTransformPerformsUpdateForIdentityToHalf) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700507 mOutput->editState().colorTransformMatrix = kIdentity;
Lloyd Pique77f79a22019-04-29 15:55:40 -0700508
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800509 // Setting a different colorTransformMatrix should perform the update.
510 CompositionRefreshArgs refreshArgs;
511 refreshArgs.colorTransformMatrix = kNonIdentityHalf;
Lloyd Pique77f79a22019-04-29 15:55:40 -0700512
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700513 mOutput->setColorTransform(refreshArgs);
Lloyd Piqueef958122019-02-05 18:00:12 -0800514
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800515 // The internal state should have been updated
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700516 EXPECT_EQ(kNonIdentityHalf, mOutput->getState().colorTransformMatrix);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800517
518 // The dirtyRegion should be set to the full display size
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700519 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800520}
521
522TEST_F(OutputTest, setColorTransformPerformsUpdateForHalfToQuarter) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700523 mOutput->editState().colorTransformMatrix = kNonIdentityHalf;
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800524
525 // Setting a different colorTransformMatrix should perform the update.
526 CompositionRefreshArgs refreshArgs;
527 refreshArgs.colorTransformMatrix = kNonIdentityQuarter;
528
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700529 mOutput->setColorTransform(refreshArgs);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800530
531 // The internal state should have been updated
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700532 EXPECT_EQ(kNonIdentityQuarter, mOutput->getState().colorTransformMatrix);
Lloyd Pique3eb1b212019-03-07 21:15:40 -0800533
534 // The dirtyRegion should be set to the full display size
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700535 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700536}
537
Lloyd Pique66d68602019-02-13 14:23:31 -0800538/*
Lloyd Pique17ca7422019-11-14 14:24:10 -0800539 * Output::setColorProfile
Lloyd Pique32cbe282018-10-19 13:09:22 -0700540 */
541
Lloyd Pique17ca7422019-11-14 14:24:10 -0800542using OutputSetColorProfileTest = OutputTest;
543
544TEST_F(OutputSetColorProfileTest, setsStateAndDirtiesOutputIfChanged) {
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800545 using ColorProfile = Output::ColorProfile;
546
Lloyd Piqueef958122019-02-05 18:00:12 -0800547 EXPECT_CALL(*mRenderSurface, setBufferDataspace(ui::Dataspace::DISPLAY_P3)).Times(1);
Lloyd Pique31cb2942018-10-19 17:23:03 -0700548
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700549 mOutput->setColorProfile(ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
Alec Mouri88790f32023-07-21 01:25:14 +0000550 ui::RenderIntent::TONE_MAP_COLORIMETRIC});
Lloyd Pique32cbe282018-10-19 13:09:22 -0700551
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700552 EXPECT_EQ(ui::ColorMode::DISPLAY_P3, mOutput->getState().colorMode);
553 EXPECT_EQ(ui::Dataspace::DISPLAY_P3, mOutput->getState().dataspace);
554 EXPECT_EQ(ui::RenderIntent::TONE_MAP_COLORIMETRIC, mOutput->getState().renderIntent);
Lloyd Piquef5275482019-01-29 18:42:42 -0800555
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700556 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region(kDefaultDisplaySize)));
Lloyd Piqueef958122019-02-05 18:00:12 -0800557}
558
Lloyd Pique17ca7422019-11-14 14:24:10 -0800559TEST_F(OutputSetColorProfileTest, doesNothingIfNoChange) {
Lloyd Pique6a3b4462019-03-07 20:58:12 -0800560 using ColorProfile = Output::ColorProfile;
561
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700562 mOutput->editState().colorMode = ui::ColorMode::DISPLAY_P3;
563 mOutput->editState().dataspace = ui::Dataspace::DISPLAY_P3;
564 mOutput->editState().renderIntent = ui::RenderIntent::TONE_MAP_COLORIMETRIC;
Lloyd Piqueef958122019-02-05 18:00:12 -0800565
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700566 mOutput->setColorProfile(ColorProfile{ui::ColorMode::DISPLAY_P3, ui::Dataspace::DISPLAY_P3,
Alec Mouri88790f32023-07-21 01:25:14 +0000567 ui::RenderIntent::TONE_MAP_COLORIMETRIC});
Lloyd Piqueef958122019-02-05 18:00:12 -0800568
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700569 EXPECT_THAT(mOutput->getState().dirtyRegion, RegionEq(Region()));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700570}
571
Lloyd Pique66d68602019-02-13 14:23:31 -0800572/*
Lloyd Pique31cb2942018-10-19 17:23:03 -0700573 * Output::setRenderSurface()
574 */
575
576TEST_F(OutputTest, setRenderSurfaceResetsBounds) {
577 const ui::Size newDisplaySize{640, 480};
578
579 mock::RenderSurface* renderSurface = new StrictMock<mock::RenderSurface>();
580 EXPECT_CALL(*renderSurface, getSize()).WillOnce(ReturnRef(newDisplaySize));
581
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700582 mOutput->setRenderSurface(std::unique_ptr<RenderSurface>(renderSurface));
Lloyd Pique31cb2942018-10-19 17:23:03 -0700583
Angel Aguayob084e0c2021-08-04 23:27:28 +0000584 EXPECT_EQ(Rect(newDisplaySize), mOutput->getState().framebufferSpace.getBoundsAsRect());
Lloyd Pique31cb2942018-10-19 17:23:03 -0700585}
586
Alec Mouricdf16792021-12-10 13:16:06 -0800587/**
588 * Output::setDisplayBrightness()
589 */
590
591TEST_F(OutputTest, setNextBrightness) {
592 constexpr float kDisplayBrightness = 0.5f;
593 mOutput->setNextBrightness(kDisplayBrightness);
594 ASSERT_TRUE(mOutput->getState().displayBrightness.has_value());
595 EXPECT_EQ(kDisplayBrightness, mOutput->getState().displayBrightness);
596}
597
Lloyd Pique66d68602019-02-13 14:23:31 -0800598/*
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000599 * Output::getDirtyRegion()
Lloyd Pique32cbe282018-10-19 13:09:22 -0700600 */
601
Dominik Laskowski8da6b0e2021-05-12 15:34:13 -0700602TEST_F(OutputTest, getDirtyRegion) {
Alec Mourie7d1d4a2019-02-05 01:13:46 +0000603 const Rect viewport{100, 200};
Angel Aguayob084e0c2021-08-04 23:27:28 +0000604 mOutput->editState().layerStackSpace.setContent(viewport);
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700605 mOutput->editState().dirtyRegion.set(50, 300);
Lloyd Pique32cbe282018-10-19 13:09:22 -0700606
Dominik Laskowski8da6b0e2021-05-12 15:34:13 -0700607 // The dirty region should be clipped to the display bounds.
608 EXPECT_THAT(mOutput->getDirtyRegion(), RegionEq(Region(Rect(50, 200))));
Lloyd Pique32cbe282018-10-19 13:09:22 -0700609}
610
Lloyd Pique66d68602019-02-13 14:23:31 -0800611/*
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700612 * Output::includesLayer()
Lloyd Piqueef36b002019-01-23 17:52:04 -0800613 */
614
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700615TEST_F(OutputTest, layerFiltering) {
616 const ui::LayerStack layerStack1{123u};
617 const ui::LayerStack layerStack2{456u};
Lloyd Piqueef36b002019-01-23 17:52:04 -0800618
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700619 // If the output is associated to layerStack1 and to an internal display...
620 mOutput->setLayerFilter({layerStack1, true});
Lloyd Piqueef36b002019-01-23 17:52:04 -0800621
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700622 // It excludes layers with no layer stack, internal-only or not.
623 EXPECT_FALSE(mOutput->includesLayer({ui::INVALID_LAYER_STACK, false}));
624 EXPECT_FALSE(mOutput->includesLayer({ui::INVALID_LAYER_STACK, true}));
Lloyd Piquec6687342019-03-07 21:34:57 -0800625
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700626 // It includes layers on layerStack1, internal-only or not.
627 EXPECT_TRUE(mOutput->includesLayer({layerStack1, false}));
628 EXPECT_TRUE(mOutput->includesLayer({layerStack1, true}));
629 EXPECT_FALSE(mOutput->includesLayer({layerStack2, true}));
630 EXPECT_FALSE(mOutput->includesLayer({layerStack2, false}));
Lloyd Piqueef36b002019-01-23 17:52:04 -0800631
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700632 // If the output is associated to layerStack1 but not to an internal display...
633 mOutput->setLayerFilter({layerStack1, false});
Lloyd Piqueef36b002019-01-23 17:52:04 -0800634
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700635 // It includes layers on layerStack1, unless they are internal-only.
636 EXPECT_TRUE(mOutput->includesLayer({layerStack1, false}));
637 EXPECT_FALSE(mOutput->includesLayer({layerStack1, true}));
638 EXPECT_FALSE(mOutput->includesLayer({layerStack2, true}));
639 EXPECT_FALSE(mOutput->includesLayer({layerStack2, false}));
Lloyd Piqueef36b002019-01-23 17:52:04 -0800640}
641
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700642TEST_F(OutputTest, layerFilteringWithoutCompositionState) {
Lloyd Piquede196652020-01-22 17:29:58 -0800643 NonInjectedLayer layer;
644 sp<LayerFE> layerFE(layer.layerFE);
Lloyd Pique66c20c42019-03-07 21:44:02 -0800645
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700646 // Layers without composition state are excluded.
Lloyd Piquede196652020-01-22 17:29:58 -0800647 EXPECT_CALL(*layer.layerFE, getCompositionState).WillOnce(Return(nullptr));
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700648 EXPECT_FALSE(mOutput->includesLayer(layerFE));
Lloyd Piquede196652020-01-22 17:29:58 -0800649}
650
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700651TEST_F(OutputTest, layerFilteringWithCompositionState) {
Lloyd Piquede196652020-01-22 17:29:58 -0800652 NonInjectedLayer layer;
653 sp<LayerFE> layerFE(layer.layerFE);
Lloyd Pique66c20c42019-03-07 21:44:02 -0800654
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700655 const ui::LayerStack layerStack1{123u};
656 const ui::LayerStack layerStack2{456u};
Lloyd Pique66c20c42019-03-07 21:44:02 -0800657
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700658 // If the output is associated to layerStack1 and to an internal display...
659 mOutput->setLayerFilter({layerStack1, true});
Lloyd Pique66c20c42019-03-07 21:44:02 -0800660
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700661 // It excludes layers with no layer stack, internal-only or not.
662 layer.layerFEState.outputFilter = {ui::INVALID_LAYER_STACK, false};
663 EXPECT_FALSE(mOutput->includesLayer(layerFE));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800664
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700665 layer.layerFEState.outputFilter = {ui::INVALID_LAYER_STACK, true};
666 EXPECT_FALSE(mOutput->includesLayer(layerFE));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800667
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700668 // It includes layers on layerStack1, internal-only or not.
669 layer.layerFEState.outputFilter = {layerStack1, false};
670 EXPECT_TRUE(mOutput->includesLayer(layerFE));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800671
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700672 layer.layerFEState.outputFilter = {layerStack1, true};
673 EXPECT_TRUE(mOutput->includesLayer(layerFE));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800674
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700675 layer.layerFEState.outputFilter = {layerStack2, true};
676 EXPECT_FALSE(mOutput->includesLayer(layerFE));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800677
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700678 layer.layerFEState.outputFilter = {layerStack2, false};
679 EXPECT_FALSE(mOutput->includesLayer(layerFE));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800680
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700681 // If the output is associated to layerStack1 but not to an internal display...
682 mOutput->setLayerFilter({layerStack1, false});
Lloyd Pique66c20c42019-03-07 21:44:02 -0800683
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700684 // It includes layers on layerStack1, unless they are internal-only.
685 layer.layerFEState.outputFilter = {layerStack1, false};
686 EXPECT_TRUE(mOutput->includesLayer(layerFE));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800687
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700688 layer.layerFEState.outputFilter = {layerStack1, true};
689 EXPECT_FALSE(mOutput->includesLayer(layerFE));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800690
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700691 layer.layerFEState.outputFilter = {layerStack2, true};
692 EXPECT_FALSE(mOutput->includesLayer(layerFE));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800693
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700694 layer.layerFEState.outputFilter = {layerStack2, false};
695 EXPECT_FALSE(mOutput->includesLayer(layerFE));
Lloyd Pique66c20c42019-03-07 21:44:02 -0800696}
697
Lloyd Pique66d68602019-02-13 14:23:31 -0800698/*
Lloyd Piquecc01a452018-12-04 17:24:00 -0800699 * Output::getOutputLayerForLayer()
700 */
701
702TEST_F(OutputTest, getOutputLayerForLayerWorks) {
Lloyd Piquede196652020-01-22 17:29:58 -0800703 InjectedLayer layer1;
704 InjectedLayer layer2;
705 NonInjectedLayer layer3;
Lloyd Piquecc01a452018-12-04 17:24:00 -0800706
Lloyd Piquede196652020-01-22 17:29:58 -0800707 injectOutputLayer(layer1);
708 injectNullOutputLayer();
709 injectOutputLayer(layer2);
Lloyd Piquecc01a452018-12-04 17:24:00 -0800710
711 // If the input layer matches the first OutputLayer, it will be returned.
Lloyd Piquede196652020-01-22 17:29:58 -0800712 EXPECT_CALL(*layer1.outputLayer, getLayerFE()).WillOnce(ReturnRef(*layer1.layerFE.get()));
713 EXPECT_EQ(layer1.outputLayer, mOutput->getOutputLayerForLayer(layer1.layerFE));
Lloyd Piquecc01a452018-12-04 17:24:00 -0800714
715 // If the input layer matches the second OutputLayer, it will be returned.
Lloyd Piquede196652020-01-22 17:29:58 -0800716 EXPECT_CALL(*layer1.outputLayer, getLayerFE()).WillOnce(ReturnRef(*layer1.layerFE.get()));
717 EXPECT_CALL(*layer2.outputLayer, getLayerFE()).WillOnce(ReturnRef(*layer2.layerFE.get()));
718 EXPECT_EQ(layer2.outputLayer, mOutput->getOutputLayerForLayer(layer2.layerFE));
Lloyd Piquecc01a452018-12-04 17:24:00 -0800719
720 // If the input layer does not match an output layer, null will be returned.
Lloyd Piquede196652020-01-22 17:29:58 -0800721 EXPECT_CALL(*layer1.outputLayer, getLayerFE()).WillOnce(ReturnRef(*layer1.layerFE.get()));
722 EXPECT_CALL(*layer2.outputLayer, getLayerFE()).WillOnce(ReturnRef(*layer2.layerFE.get()));
723 EXPECT_EQ(nullptr, mOutput->getOutputLayerForLayer(layer3.layerFE));
Lloyd Piquecc01a452018-12-04 17:24:00 -0800724}
725
Lloyd Pique66d68602019-02-13 14:23:31 -0800726/*
Lloyd Piquec9e60032019-11-14 11:47:26 -0800727 * Output::setReleasedLayers()
728 */
729
730using OutputSetReleasedLayersTest = OutputTest;
731
732TEST_F(OutputSetReleasedLayersTest, setReleasedLayersTakesGivenLayers) {
Ady Abrahame0eafa82022-02-02 19:30:47 -0800733 sp<StrictMock<mock::LayerFE>> layer1FE = sp<StrictMock<mock::LayerFE>>::make();
734 sp<StrictMock<mock::LayerFE>> layer2FE = sp<StrictMock<mock::LayerFE>>::make();
735 sp<StrictMock<mock::LayerFE>> layer3FE = sp<StrictMock<mock::LayerFE>>::make();
Lloyd Piquec9e60032019-11-14 11:47:26 -0800736
737 Output::ReleasedLayers layers;
738 layers.push_back(layer1FE);
739 layers.push_back(layer2FE);
740 layers.push_back(layer3FE);
741
742 mOutput->setReleasedLayers(std::move(layers));
743
744 const auto& setLayers = mOutput->getReleasedLayersForTest();
745 ASSERT_EQ(3u, setLayers.size());
746 ASSERT_EQ(layer1FE.get(), setLayers[0].promote().get());
747 ASSERT_EQ(layer2FE.get(), setLayers[1].promote().get());
748 ASSERT_EQ(layer3FE.get(), setLayers[2].promote().get());
749}
750
751/*
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800752 * Output::updateAndWriteCompositionState()
753 */
754
Lloyd Piquede196652020-01-22 17:29:58 -0800755using OutputUpdateAndWriteCompositionStateTest = OutputTest;
Lloyd Piqueef63b612019-11-14 13:19:56 -0800756
757TEST_F(OutputUpdateAndWriteCompositionStateTest, doesNothingIfLayers) {
758 mOutput->editState().isEnabled = true;
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800759
760 CompositionRefreshArgs args;
Dan Stoza269dc4d2021-01-15 15:07:43 -0800761 mOutput->updateCompositionState(args);
762 mOutput->planComposition();
763 mOutput->writeCompositionState(args);
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800764}
765
Lloyd Piqueef63b612019-11-14 13:19:56 -0800766TEST_F(OutputUpdateAndWriteCompositionStateTest, doesNothingIfOutputNotEnabled) {
Lloyd Piquede196652020-01-22 17:29:58 -0800767 InjectedLayer layer1;
768 InjectedLayer layer2;
769 InjectedLayer layer3;
770
Lloyd Piqueef63b612019-11-14 13:19:56 -0800771 mOutput->editState().isEnabled = false;
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800772
Lloyd Piquede196652020-01-22 17:29:58 -0800773 injectOutputLayer(layer1);
774 injectOutputLayer(layer2);
775 injectOutputLayer(layer3);
Lloyd Piqueef63b612019-11-14 13:19:56 -0800776
777 CompositionRefreshArgs args;
Dan Stoza269dc4d2021-01-15 15:07:43 -0800778 mOutput->updateCompositionState(args);
779 mOutput->planComposition();
780 mOutput->writeCompositionState(args);
Lloyd Piqueef63b612019-11-14 13:19:56 -0800781}
782
783TEST_F(OutputUpdateAndWriteCompositionStateTest, updatesLayerContentForAllLayers) {
Lloyd Piquede196652020-01-22 17:29:58 -0800784 InjectedLayer layer1;
785 InjectedLayer layer2;
786 InjectedLayer layer3;
Lloyd Piqueef63b612019-11-14 13:19:56 -0800787
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400788 uint32_t z = 0;
Snild Dolkow9e217d62020-04-22 15:53:42 +0200789 EXPECT_CALL(*layer1.outputLayer, updateCompositionState(false, false, ui::Transform::ROT_180));
Dan Stoza6166c312021-01-15 16:34:05 -0800790 EXPECT_CALL(*layer1.outputLayer,
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400791 writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++,
792 /*zIsOverridden*/ false, /*isPeekingThrough*/ false));
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +0000793 EXPECT_CALL(*layer1.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false));
Snild Dolkow9e217d62020-04-22 15:53:42 +0200794 EXPECT_CALL(*layer2.outputLayer, updateCompositionState(false, false, ui::Transform::ROT_180));
Dan Stoza6166c312021-01-15 16:34:05 -0800795 EXPECT_CALL(*layer2.outputLayer,
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400796 writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++,
797 /*zIsOverridden*/ false, /*isPeekingThrough*/ false));
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +0000798 EXPECT_CALL(*layer2.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false));
Snild Dolkow9e217d62020-04-22 15:53:42 +0200799 EXPECT_CALL(*layer3.outputLayer, updateCompositionState(false, false, ui::Transform::ROT_180));
Dan Stoza6166c312021-01-15 16:34:05 -0800800 EXPECT_CALL(*layer3.outputLayer,
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400801 writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++,
802 /*zIsOverridden*/ false, /*isPeekingThrough*/ false));
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +0000803 EXPECT_CALL(*layer3.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false));
Lloyd Piquede196652020-01-22 17:29:58 -0800804
805 injectOutputLayer(layer1);
806 injectOutputLayer(layer2);
807 injectOutputLayer(layer3);
Lloyd Piqueef63b612019-11-14 13:19:56 -0800808
809 mOutput->editState().isEnabled = true;
810
811 CompositionRefreshArgs args;
812 args.updatingGeometryThisFrame = false;
813 args.devOptForceClientComposition = false;
Snild Dolkow9e217d62020-04-22 15:53:42 +0200814 args.internalDisplayRotationFlags = ui::Transform::ROT_180;
Dan Stoza269dc4d2021-01-15 15:07:43 -0800815 mOutput->updateCompositionState(args);
816 mOutput->planComposition();
817 mOutput->writeCompositionState(args);
Lloyd Piqueef63b612019-11-14 13:19:56 -0800818}
819
820TEST_F(OutputUpdateAndWriteCompositionStateTest, updatesLayerGeometryAndContentForAllLayers) {
Lloyd Piquede196652020-01-22 17:29:58 -0800821 InjectedLayer layer1;
822 InjectedLayer layer2;
823 InjectedLayer layer3;
Lloyd Piqueef63b612019-11-14 13:19:56 -0800824
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400825 uint32_t z = 0;
Snild Dolkow9e217d62020-04-22 15:53:42 +0200826 EXPECT_CALL(*layer1.outputLayer, updateCompositionState(true, false, ui::Transform::ROT_0));
Dan Stoza6166c312021-01-15 16:34:05 -0800827 EXPECT_CALL(*layer1.outputLayer,
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400828 writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, z++,
829 /*zIsOverridden*/ false, /*isPeekingThrough*/ false));
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +0000830 EXPECT_CALL(*layer1.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false));
Snild Dolkow9e217d62020-04-22 15:53:42 +0200831 EXPECT_CALL(*layer2.outputLayer, updateCompositionState(true, false, ui::Transform::ROT_0));
Dan Stoza6166c312021-01-15 16:34:05 -0800832 EXPECT_CALL(*layer2.outputLayer,
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400833 writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, z++,
834 /*zIsOverridden*/ false, /*isPeekingThrough*/ false));
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +0000835 EXPECT_CALL(*layer2.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false));
Snild Dolkow9e217d62020-04-22 15:53:42 +0200836 EXPECT_CALL(*layer3.outputLayer, updateCompositionState(true, false, ui::Transform::ROT_0));
Dan Stoza6166c312021-01-15 16:34:05 -0800837 EXPECT_CALL(*layer3.outputLayer,
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400838 writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, z++,
839 /*zIsOverridden*/ false, /*isPeekingThrough*/ false));
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +0000840 EXPECT_CALL(*layer3.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false));
Lloyd Piquede196652020-01-22 17:29:58 -0800841
842 injectOutputLayer(layer1);
843 injectOutputLayer(layer2);
844 injectOutputLayer(layer3);
Lloyd Piqueef63b612019-11-14 13:19:56 -0800845
846 mOutput->editState().isEnabled = true;
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800847
848 CompositionRefreshArgs args;
849 args.updatingGeometryThisFrame = true;
Lloyd Piqueef63b612019-11-14 13:19:56 -0800850 args.devOptForceClientComposition = false;
Dan Stoza269dc4d2021-01-15 15:07:43 -0800851 mOutput->updateCompositionState(args);
852 mOutput->planComposition();
853 mOutput->writeCompositionState(args);
Lloyd Piqueef63b612019-11-14 13:19:56 -0800854}
855
856TEST_F(OutputUpdateAndWriteCompositionStateTest, forcesClientCompositionForAllLayers) {
Lloyd Piquede196652020-01-22 17:29:58 -0800857 InjectedLayer layer1;
858 InjectedLayer layer2;
859 InjectedLayer layer3;
Lloyd Piqueef63b612019-11-14 13:19:56 -0800860
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400861 uint32_t z = 0;
Snild Dolkow9e217d62020-04-22 15:53:42 +0200862 EXPECT_CALL(*layer1.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0));
Dan Stoza6166c312021-01-15 16:34:05 -0800863 EXPECT_CALL(*layer1.outputLayer,
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400864 writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++,
865 /*zIsOverridden*/ false, /*isPeekingThrough*/ false));
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +0000866 EXPECT_CALL(*layer1.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false));
Snild Dolkow9e217d62020-04-22 15:53:42 +0200867 EXPECT_CALL(*layer2.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0));
Dan Stoza6166c312021-01-15 16:34:05 -0800868 EXPECT_CALL(*layer2.outputLayer,
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400869 writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++,
870 /*zIsOverridden*/ false, /*isPeekingThrough*/ false));
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +0000871 EXPECT_CALL(*layer2.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false));
Snild Dolkow9e217d62020-04-22 15:53:42 +0200872 EXPECT_CALL(*layer3.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0));
Dan Stoza6166c312021-01-15 16:34:05 -0800873 EXPECT_CALL(*layer3.outputLayer,
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400874 writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++,
875 /*zIsOverridden*/ false, /*isPeekingThrough*/ false));
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +0000876 EXPECT_CALL(*layer3.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false));
Lloyd Piquede196652020-01-22 17:29:58 -0800877
878 injectOutputLayer(layer1);
879 injectOutputLayer(layer2);
880 injectOutputLayer(layer3);
Lloyd Piqueef63b612019-11-14 13:19:56 -0800881
882 mOutput->editState().isEnabled = true;
883
884 CompositionRefreshArgs args;
885 args.updatingGeometryThisFrame = false;
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800886 args.devOptForceClientComposition = true;
Dan Stoza269dc4d2021-01-15 15:07:43 -0800887 mOutput->updateCompositionState(args);
888 mOutput->planComposition();
889 mOutput->writeCompositionState(args);
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800890}
891
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -0400892TEST_F(OutputUpdateAndWriteCompositionStateTest, peekThroughLayerChangesOrder) {
893 renderengine::mock::RenderEngine renderEngine;
894 InjectedLayer layer0;
895 InjectedLayer layer1;
896 InjectedLayer layer2;
897 InjectedLayer layer3;
898
899 InSequence seq;
900 EXPECT_CALL(*layer0.outputLayer, updateCompositionState(true, false, ui::Transform::ROT_0));
901 EXPECT_CALL(*layer1.outputLayer, updateCompositionState(true, false, ui::Transform::ROT_0));
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +0000902 EXPECT_CALL(*layer1.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false));
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -0400903 EXPECT_CALL(*layer2.outputLayer, updateCompositionState(true, false, ui::Transform::ROT_0));
904 EXPECT_CALL(*layer3.outputLayer, updateCompositionState(true, false, ui::Transform::ROT_0));
905
906 uint32_t z = 0;
907 EXPECT_CALL(*layer0.outputLayer,
908 writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, z++,
909 /*zIsOverridden*/ false, /*isPeekingThrough*/ false));
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +0000910 EXPECT_CALL(*layer0.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false));
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -0400911
912 // After calling planComposition (which clears overrideInfo), this test sets
913 // layer3 to be the peekThroughLayer for layer1 and layer2. As a result, it
914 // comes first, setting isPeekingThrough to true and zIsOverridden to true
915 // for it and the following layers.
916 EXPECT_CALL(*layer3.outputLayer,
917 writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, z++,
918 /*zIsOverridden*/ true, /*isPeekingThrough*/
919 true));
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +0000920 EXPECT_CALL(*layer3.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false));
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -0400921 EXPECT_CALL(*layer1.outputLayer,
922 writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ false, z++,
923 /*zIsOverridden*/ true, /*isPeekingThrough*/ false));
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +0000924 EXPECT_CALL(*layer1.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false));
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -0400925 EXPECT_CALL(*layer2.outputLayer,
926 writeStateToHWC(/*includeGeometry*/ true, /*skipLayer*/ true, z++,
927 /*zIsOverridden*/ true, /*isPeekingThrough*/ false));
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +0000928 EXPECT_CALL(*layer2.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false));
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -0400929
930 injectOutputLayer(layer0);
931 injectOutputLayer(layer1);
932 injectOutputLayer(layer2);
933 injectOutputLayer(layer3);
934
935 mOutput->editState().isEnabled = true;
936
937 CompositionRefreshArgs args;
938 args.updatingGeometryThisFrame = true;
939 args.devOptForceClientComposition = false;
940 mOutput->updateCompositionState(args);
941 mOutput->planComposition();
942
943 std::shared_ptr<renderengine::ExternalTexture> buffer = std::make_shared<
Vishnu Nairdbbe3852022-01-12 20:22:11 -0800944 renderengine::impl::
Ady Abrahamd11bade2022-08-01 16:18:03 -0700945 ExternalTexture>(sp<GraphicBuffer>::make(), renderEngine,
Vishnu Nairdbbe3852022-01-12 20:22:11 -0800946 renderengine::impl::ExternalTexture::Usage::READABLE |
947 renderengine::impl::ExternalTexture::Usage::WRITEABLE);
Leon Scroggins III2e74a4c2021-04-09 13:41:14 -0400948 layer1.outputLayerState.overrideInfo.buffer = buffer;
949 layer2.outputLayerState.overrideInfo.buffer = buffer;
950 layer1.outputLayerState.overrideInfo.peekThroughLayer = layer3.outputLayer;
951 layer2.outputLayerState.overrideInfo.peekThroughLayer = layer3.outputLayer;
952
953 mOutput->writeCompositionState(args);
954}
955
Alec Mourif9a2a2c2019-11-12 12:46:02 -0800956/*
Lloyd Pique66d68602019-02-13 14:23:31 -0800957 * Output::prepareFrame()
958 */
959
960struct OutputPrepareFrameTest : public testing::Test {
Lloyd Piquefaa3f192019-11-14 14:05:09 -0800961 struct OutputPartialMock : public OutputPartialMockBase {
Lloyd Pique739afaf2019-11-21 16:40:05 -0800962 // Sets up the helper functions called by the function under test to use
963 // mock implementations.
Vishnu Naira3140382022-02-24 14:07:11 -0800964 MOCK_METHOD1(chooseCompositionStrategy,
965 bool(std::optional<android::HWComposer::DeviceRequestedChanges>*));
966 MOCK_METHOD0(resetCompositionStrategy, void());
Lloyd Pique66d68602019-02-13 14:23:31 -0800967 };
968
969 OutputPrepareFrameTest() {
970 mOutput.setDisplayColorProfileForTest(
971 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
972 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
973 }
974
975 StrictMock<mock::CompositionEngine> mCompositionEngine;
976 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
977 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700978 StrictMock<OutputPartialMock> mOutput;
Lloyd Pique66d68602019-02-13 14:23:31 -0800979};
980
981TEST_F(OutputPrepareFrameTest, takesEarlyOutIfNotEnabled) {
982 mOutput.editState().isEnabled = false;
983
984 mOutput.prepareFrame();
985}
986
987TEST_F(OutputPrepareFrameTest, delegatesToChooseCompositionStrategyAndRenderSurface) {
988 mOutput.editState().isEnabled = true;
989 mOutput.editState().usesClientComposition = false;
990 mOutput.editState().usesDeviceComposition = true;
991
Vishnu Naira3140382022-02-24 14:07:11 -0800992 EXPECT_CALL(mOutput, chooseCompositionStrategy(_)).WillRepeatedly(Return(true));
993 EXPECT_CALL(mOutput, resetCompositionStrategy()).Times(1);
Alec Mouri023c1882021-05-08 16:36:33 -0700994 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0u));
Lloyd Pique66d68602019-02-13 14:23:31 -0800995 EXPECT_CALL(*mRenderSurface, prepareFrame(false, true));
996
997 mOutput.prepareFrame();
Vishnu Nair9cf89262022-02-26 09:17:49 -0800998 EXPECT_EQ(mOutput.getState().strategyPrediction, CompositionStrategyPredictionState::DISABLED);
Lloyd Pique66d68602019-02-13 14:23:31 -0800999}
1000
1001// Note: Use OutputTest and not OutputPrepareFrameTest, so the real
1002// base chooseCompositionStrategy() is invoked.
1003TEST_F(OutputTest, prepareFrameSetsClientCompositionOnlyByDefault) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -07001004 mOutput->editState().isEnabled = true;
1005 mOutput->editState().usesClientComposition = false;
1006 mOutput->editState().usesDeviceComposition = true;
Lloyd Pique66d68602019-02-13 14:23:31 -08001007
1008 EXPECT_CALL(*mRenderSurface, prepareFrame(true, false));
1009
Lloyd Piquea38ea7e2019-04-16 18:10:26 -07001010 mOutput->prepareFrame();
Lloyd Pique66d68602019-02-13 14:23:31 -08001011
Lloyd Piquea38ea7e2019-04-16 18:10:26 -07001012 EXPECT_TRUE(mOutput->getState().usesClientComposition);
1013 EXPECT_FALSE(mOutput->getState().usesDeviceComposition);
Vishnu Nair9cf89262022-02-26 09:17:49 -08001014 EXPECT_EQ(mOutput->getState().strategyPrediction, CompositionStrategyPredictionState::DISABLED);
Lloyd Pique66d68602019-02-13 14:23:31 -08001015}
1016
Vishnu Naira3140382022-02-24 14:07:11 -08001017struct OutputPrepareFrameAsyncTest : public testing::Test {
1018 struct OutputPartialMock : public OutputPartialMockBase {
1019 // Sets up the helper functions called by the function under test to use
1020 // mock implementations.
1021 MOCK_METHOD1(chooseCompositionStrategy,
1022 bool(std::optional<android::HWComposer::DeviceRequestedChanges>*));
1023 MOCK_METHOD0(updateProtectedContentState, void());
1024 MOCK_METHOD2(dequeueRenderBuffer,
1025 bool(base::unique_fd*, std::shared_ptr<renderengine::ExternalTexture>*));
1026 MOCK_METHOD1(
1027 chooseCompositionStrategyAsync,
1028 std::future<bool>(std::optional<android::HWComposer::DeviceRequestedChanges>*));
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00001029 MOCK_METHOD3(composeSurfaces,
1030 std::optional<base::unique_fd>(const Region&,
1031 std::shared_ptr<renderengine::ExternalTexture>,
1032 base::unique_fd&));
Vishnu Naira3140382022-02-24 14:07:11 -08001033 MOCK_METHOD0(resetCompositionStrategy, void());
1034 };
1035
1036 OutputPrepareFrameAsyncTest() {
1037 mOutput.setDisplayColorProfileForTest(
1038 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
1039 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
1040 }
1041
1042 StrictMock<mock::CompositionEngine> mCompositionEngine;
1043 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
1044 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
1045 StrictMock<OutputPartialMock> mOutput;
1046 CompositionRefreshArgs mRefreshArgs;
1047};
1048
1049TEST_F(OutputPrepareFrameAsyncTest, delegatesToChooseCompositionStrategyAndRenderSurface) {
1050 mOutput.editState().isEnabled = true;
1051 mOutput.editState().usesClientComposition = false;
1052 mOutput.editState().usesDeviceComposition = true;
1053 mOutput.editState().previousDeviceRequestedChanges =
1054 std::make_optional<android::HWComposer::DeviceRequestedChanges>({});
1055 std::promise<bool> p;
1056 p.set_value(true);
1057
1058 EXPECT_CALL(mOutput, resetCompositionStrategy()).Times(1);
1059 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0u));
1060 EXPECT_CALL(mOutput, updateProtectedContentState());
1061 EXPECT_CALL(mOutput, dequeueRenderBuffer(_, _)).WillOnce(Return(true));
1062 EXPECT_CALL(*mRenderSurface, prepareFrame(false, true)).Times(1);
1063 EXPECT_CALL(mOutput, chooseCompositionStrategyAsync(_))
1064 .WillOnce(DoAll(SetArgPointee<0>(mOutput.editState().previousDeviceRequestedChanges),
1065 Return(ByMove(p.get_future()))));
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00001066 EXPECT_CALL(mOutput, composeSurfaces(_, _, _));
Vishnu Naira3140382022-02-24 14:07:11 -08001067
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00001068 impl::GpuCompositionResult result = mOutput.prepareFrameAsync();
Vishnu Nair9cf89262022-02-26 09:17:49 -08001069 EXPECT_EQ(mOutput.getState().strategyPrediction, CompositionStrategyPredictionState::SUCCESS);
Vishnu Naira3140382022-02-24 14:07:11 -08001070 EXPECT_FALSE(result.bufferAvailable());
1071}
1072
1073TEST_F(OutputPrepareFrameAsyncTest, skipCompositionOnDequeueFailure) {
1074 mOutput.editState().isEnabled = true;
1075 mOutput.editState().usesClientComposition = false;
1076 mOutput.editState().usesDeviceComposition = true;
1077 mOutput.editState().previousDeviceRequestedChanges =
1078 std::make_optional<android::HWComposer::DeviceRequestedChanges>({});
1079 std::promise<bool> p;
1080 p.set_value(true);
1081
1082 EXPECT_CALL(mOutput, resetCompositionStrategy()).Times(2);
1083 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0u));
1084 EXPECT_CALL(mOutput, updateProtectedContentState());
1085 EXPECT_CALL(mOutput, dequeueRenderBuffer(_, _)).WillOnce(Return(false));
1086 EXPECT_CALL(*mRenderSurface, prepareFrame(false, true)).Times(2);
1087 EXPECT_CALL(mOutput, chooseCompositionStrategyAsync(_))
1088 .WillOnce(DoAll(SetArgPointee<0>(mOutput.editState().previousDeviceRequestedChanges),
1089 Return(ByMove(p.get_future()))));
1090
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00001091 impl::GpuCompositionResult result = mOutput.prepareFrameAsync();
Vishnu Nair9cf89262022-02-26 09:17:49 -08001092 EXPECT_EQ(mOutput.getState().strategyPrediction, CompositionStrategyPredictionState::FAIL);
Vishnu Naira3140382022-02-24 14:07:11 -08001093 EXPECT_FALSE(result.bufferAvailable());
1094}
1095
1096// Tests that in the event of hwc error when choosing composition strategy, we would fall back
1097// client composition
1098TEST_F(OutputPrepareFrameAsyncTest, chooseCompositionStrategyFailureCallsPrepareFrame) {
1099 mOutput.editState().isEnabled = true;
1100 mOutput.editState().usesClientComposition = false;
1101 mOutput.editState().usesDeviceComposition = true;
1102 mOutput.editState().previousDeviceRequestedChanges =
1103 std::make_optional<android::HWComposer::DeviceRequestedChanges>({});
1104 std::promise<bool> p;
1105 p.set_value(false);
1106 std::shared_ptr<renderengine::ExternalTexture> tex =
1107 std::make_shared<renderengine::mock::FakeExternalTexture>(1, 1,
1108 HAL_PIXEL_FORMAT_RGBA_8888, 1,
1109 2);
1110 EXPECT_CALL(mOutput, resetCompositionStrategy()).Times(2);
1111 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0u));
1112 EXPECT_CALL(mOutput, updateProtectedContentState());
1113 EXPECT_CALL(mOutput, dequeueRenderBuffer(_, _))
1114 .WillOnce(DoAll(SetArgPointee<1>(tex), Return(true)));
1115 EXPECT_CALL(*mRenderSurface, prepareFrame(false, true)).Times(2);
1116 EXPECT_CALL(mOutput, chooseCompositionStrategyAsync(_)).WillOnce([&] {
1117 return p.get_future();
1118 });
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00001119 EXPECT_CALL(mOutput, composeSurfaces(_, _, _));
Vishnu Naira3140382022-02-24 14:07:11 -08001120
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00001121 impl::GpuCompositionResult result = mOutput.prepareFrameAsync();
Vishnu Nair9cf89262022-02-26 09:17:49 -08001122 EXPECT_EQ(mOutput.getState().strategyPrediction, CompositionStrategyPredictionState::FAIL);
Vishnu Naira3140382022-02-24 14:07:11 -08001123 EXPECT_TRUE(result.bufferAvailable());
1124}
1125
1126TEST_F(OutputPrepareFrameAsyncTest, predictionMiss) {
1127 mOutput.editState().isEnabled = true;
1128 mOutput.editState().usesClientComposition = false;
1129 mOutput.editState().usesDeviceComposition = true;
1130 mOutput.editState().previousDeviceRequestedChanges =
1131 std::make_optional<android::HWComposer::DeviceRequestedChanges>({});
1132 auto newDeviceRequestedChanges =
1133 std::make_optional<android::HWComposer::DeviceRequestedChanges>({});
1134 newDeviceRequestedChanges->displayRequests = static_cast<hal::DisplayRequest>(0);
1135 std::promise<bool> p;
1136 p.set_value(false);
1137 std::shared_ptr<renderengine::ExternalTexture> tex =
1138 std::make_shared<renderengine::mock::FakeExternalTexture>(1, 1,
1139 HAL_PIXEL_FORMAT_RGBA_8888, 1,
1140 2);
1141
1142 EXPECT_CALL(mOutput, resetCompositionStrategy()).Times(2);
1143 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0u));
1144 EXPECT_CALL(mOutput, updateProtectedContentState());
1145 EXPECT_CALL(mOutput, dequeueRenderBuffer(_, _))
1146 .WillOnce(DoAll(SetArgPointee<1>(tex), Return(true)));
1147 EXPECT_CALL(*mRenderSurface, prepareFrame(false, true)).Times(2);
1148 EXPECT_CALL(mOutput, chooseCompositionStrategyAsync(_)).WillOnce([&] {
1149 return p.get_future();
1150 });
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00001151 EXPECT_CALL(mOutput, composeSurfaces(_, _, _));
Vishnu Naira3140382022-02-24 14:07:11 -08001152
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00001153 impl::GpuCompositionResult result = mOutput.prepareFrameAsync();
Vishnu Nair9cf89262022-02-26 09:17:49 -08001154 EXPECT_EQ(mOutput.getState().strategyPrediction, CompositionStrategyPredictionState::FAIL);
Vishnu Naira3140382022-02-24 14:07:11 -08001155 EXPECT_TRUE(result.bufferAvailable());
1156}
1157
Lloyd Pique56eba802019-08-28 15:45:25 -07001158/*
Lloyd Piqueb62cebc2019-11-20 18:31:52 -08001159 * Output::prepare()
1160 */
1161
1162struct OutputPrepareTest : public testing::Test {
1163 struct OutputPartialMock : public OutputPartialMockBase {
1164 // Sets up the helper functions called by the function under test to use
1165 // mock implementations.
1166 MOCK_METHOD2(rebuildLayerStacks,
1167 void(const compositionengine::CompositionRefreshArgs&,
1168 compositionengine::LayerFESet&));
1169 };
1170
Brian Lindahl439afad2022-11-14 11:16:55 -07001171 OutputPrepareTest() {
1172 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2u));
1173 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0))
1174 .WillRepeatedly(Return(&mLayer1.outputLayer));
1175 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1))
1176 .WillRepeatedly(Return(&mLayer2.outputLayer));
1177
1178 mRefreshArgs.layers.push_back(mLayer1.layerFE);
1179 mRefreshArgs.layers.push_back(mLayer2.layerFE);
1180 }
1181
1182 struct Layer {
1183 StrictMock<mock::OutputLayer> outputLayer;
1184 sp<StrictMock<mock::LayerFE>> layerFE = sp<StrictMock<mock::LayerFE>>::make();
1185 };
1186
Lloyd Piqueb62cebc2019-11-20 18:31:52 -08001187 StrictMock<OutputPartialMock> mOutput;
1188 CompositionRefreshArgs mRefreshArgs;
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001189 LayerFESet mGeomSnapshots;
Brian Lindahl439afad2022-11-14 11:16:55 -07001190 Layer mLayer1;
1191 Layer mLayer2;
Lloyd Piqueb62cebc2019-11-20 18:31:52 -08001192};
1193
Brian Lindahl439afad2022-11-14 11:16:55 -07001194TEST_F(OutputPrepareTest, callsUncacheBuffersOnEachOutputLayerAndThenRebuildsLayerStacks) {
Lloyd Piqueb62cebc2019-11-20 18:31:52 -08001195 InSequence seq;
Brian Lindahl439afad2022-11-14 11:16:55 -07001196
1197 mRefreshArgs.bufferIdsToUncache = {1, 3, 5};
1198
Lloyd Piqueb62cebc2019-11-20 18:31:52 -08001199 EXPECT_CALL(mOutput, rebuildLayerStacks(Ref(mRefreshArgs), Ref(mGeomSnapshots)));
Brian Lindahl439afad2022-11-14 11:16:55 -07001200 EXPECT_CALL(mLayer1.outputLayer, uncacheBuffers(Ref(mRefreshArgs.bufferIdsToUncache)));
1201 EXPECT_CALL(mLayer2.outputLayer, uncacheBuffers(Ref(mRefreshArgs.bufferIdsToUncache)));
1202
1203 mOutput.prepare(mRefreshArgs, mGeomSnapshots);
1204}
1205
1206TEST_F(OutputPrepareTest, skipsUncacheBuffersIfEmptyAndThenRebuildsLayerStacks) {
1207 InSequence seq;
1208
1209 mRefreshArgs.bufferIdsToUncache = {};
1210
1211 EXPECT_CALL(mOutput, rebuildLayerStacks(Ref(mRefreshArgs), Ref(mGeomSnapshots)));
1212 EXPECT_CALL(mLayer1.outputLayer, uncacheBuffers(_)).Times(0);
1213 EXPECT_CALL(mLayer2.outputLayer, uncacheBuffers(_)).Times(0);
Lloyd Piqueb62cebc2019-11-20 18:31:52 -08001214
1215 mOutput.prepare(mRefreshArgs, mGeomSnapshots);
1216}
1217
1218/*
1219 * Output::rebuildLayerStacks()
1220 */
1221
1222struct OutputRebuildLayerStacksTest : public testing::Test {
1223 struct OutputPartialMock : public OutputPartialMockBase {
1224 // Sets up the helper functions called by the function under test to use
1225 // mock implementations.
1226 MOCK_METHOD2(collectVisibleLayers,
1227 void(const compositionengine::CompositionRefreshArgs&,
1228 compositionengine::Output::CoverageState&));
1229 };
1230
1231 OutputRebuildLayerStacksTest() {
1232 mOutput.mState.isEnabled = true;
1233 mOutput.mState.transform = kIdentityTransform;
Angel Aguayob084e0c2021-08-04 23:27:28 +00001234 mOutput.mState.displaySpace.setBounds(
1235 ui::Size(kOutputBounds.getWidth(), kOutputBounds.getHeight()));
Lloyd Piqueb62cebc2019-11-20 18:31:52 -08001236
1237 mRefreshArgs.updatingOutputGeometryThisFrame = true;
1238
1239 mCoverageAboveCoveredLayersToSet = Region(Rect(0, 0, 10, 10));
1240
1241 EXPECT_CALL(mOutput, collectVisibleLayers(Ref(mRefreshArgs), _))
1242 .WillRepeatedly(Invoke(this, &OutputRebuildLayerStacksTest::setTestCoverageValues));
1243 }
1244
1245 void setTestCoverageValues(const CompositionRefreshArgs&,
1246 compositionengine::Output::CoverageState& state) {
1247 state.aboveCoveredLayers = mCoverageAboveCoveredLayersToSet;
1248 state.aboveOpaqueLayers = mCoverageAboveOpaqueLayersToSet;
1249 state.dirtyRegion = mCoverageDirtyRegionToSet;
1250 }
1251
1252 static const ui::Transform kIdentityTransform;
1253 static const ui::Transform kRotate90Transform;
1254 static const Rect kOutputBounds;
1255
1256 StrictMock<OutputPartialMock> mOutput;
1257 CompositionRefreshArgs mRefreshArgs;
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001258 LayerFESet mGeomSnapshots;
Lloyd Piqueb62cebc2019-11-20 18:31:52 -08001259 Region mCoverageAboveCoveredLayersToSet;
1260 Region mCoverageAboveOpaqueLayersToSet;
1261 Region mCoverageDirtyRegionToSet;
1262};
1263
1264const ui::Transform OutputRebuildLayerStacksTest::kIdentityTransform{TR_IDENT, 1920, 1080};
1265const ui::Transform OutputRebuildLayerStacksTest::kRotate90Transform{TR_ROT_90, 1920, 1080};
1266const Rect OutputRebuildLayerStacksTest::kOutputBounds{0, 0, 1920, 1080};
1267
1268TEST_F(OutputRebuildLayerStacksTest, doesNothingIfNotEnabled) {
1269 mOutput.mState.isEnabled = false;
1270
1271 mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
1272}
1273
1274TEST_F(OutputRebuildLayerStacksTest, doesNothingIfNotUpdatingGeometryThisFrame) {
1275 mRefreshArgs.updatingOutputGeometryThisFrame = false;
1276
1277 mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
1278}
1279
1280TEST_F(OutputRebuildLayerStacksTest, computesUndefinedRegionWithNoRotationAndFullCoverage) {
1281 mOutput.mState.transform = kIdentityTransform;
1282
1283 mCoverageAboveOpaqueLayersToSet = Region(Rect(0, 0, 1920, 1080));
1284
1285 mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
1286
1287 EXPECT_THAT(mOutput.mState.undefinedRegion, RegionEq(Region(Rect(0, 0, 0, 0))));
1288}
1289
1290TEST_F(OutputRebuildLayerStacksTest, computesUndefinedRegionWithNoRotationAndPartialCoverage) {
1291 mOutput.mState.transform = kIdentityTransform;
1292
1293 mCoverageAboveOpaqueLayersToSet = Region(Rect(0, 0, 960, 1080));
1294
1295 mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
1296
1297 EXPECT_THAT(mOutput.mState.undefinedRegion, RegionEq(Region(Rect(960, 0, 1920, 1080))));
1298}
1299
1300TEST_F(OutputRebuildLayerStacksTest, computesUndefinedRegionWith90RotationAndFullCoverage) {
1301 mOutput.mState.transform = kRotate90Transform;
1302
1303 mCoverageAboveOpaqueLayersToSet = Region(Rect(0, 0, 1080, 1920));
1304
1305 mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
1306
1307 EXPECT_THAT(mOutput.mState.undefinedRegion, RegionEq(Region(Rect(0, 0, 0, 0))));
1308}
1309
1310TEST_F(OutputRebuildLayerStacksTest, computesUndefinedRegionWith90RotationAndPartialCoverage) {
1311 mOutput.mState.transform = kRotate90Transform;
1312
1313 mCoverageAboveOpaqueLayersToSet = Region(Rect(0, 0, 1080, 960));
1314
1315 mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
1316
1317 EXPECT_THAT(mOutput.mState.undefinedRegion, RegionEq(Region(Rect(0, 0, 960, 1080))));
1318}
1319
1320TEST_F(OutputRebuildLayerStacksTest, addsToDirtyRegionWithNoRotation) {
1321 mOutput.mState.transform = kIdentityTransform;
1322 mOutput.mState.dirtyRegion = Region(Rect(960, 0, 1920, 1080));
1323
1324 mCoverageDirtyRegionToSet = Region(Rect(0, 0, 960, 1080));
1325
1326 mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
1327
1328 EXPECT_THAT(mOutput.mState.dirtyRegion, RegionEq(Region(Rect(0, 0, 1920, 1080))));
1329}
1330
1331TEST_F(OutputRebuildLayerStacksTest, addsToDirtyRegionWith90Rotation) {
1332 mOutput.mState.transform = kRotate90Transform;
1333 mOutput.mState.dirtyRegion = Region(Rect(0, 960, 1080, 1920));
1334
1335 mCoverageDirtyRegionToSet = Region(Rect(0, 0, 1080, 960));
1336
1337 mOutput.rebuildLayerStacks(mRefreshArgs, mGeomSnapshots);
1338
1339 EXPECT_THAT(mOutput.mState.dirtyRegion, RegionEq(Region(Rect(0, 0, 1080, 1920))));
1340}
1341
1342/*
1343 * Output::collectVisibleLayers()
1344 */
1345
Lloyd Pique1ef93222019-11-21 16:41:53 -08001346struct OutputCollectVisibleLayersTest : public testing::Test {
1347 struct OutputPartialMock : public OutputPartialMockBase {
1348 // Sets up the helper functions called by the function under test to use
1349 // mock implementations.
1350 MOCK_METHOD2(ensureOutputLayerIfVisible,
Lloyd Piquede196652020-01-22 17:29:58 -08001351 void(sp<compositionengine::LayerFE>&,
Lloyd Pique1ef93222019-11-21 16:41:53 -08001352 compositionengine::Output::CoverageState&));
1353 MOCK_METHOD1(setReleasedLayers, void(const compositionengine::CompositionRefreshArgs&));
1354 MOCK_METHOD0(finalizePendingOutputLayers, void());
1355 };
1356
1357 struct Layer {
1358 Layer() {
1359 EXPECT_CALL(outputLayer, getState()).WillRepeatedly(ReturnRef(outputLayerState));
1360 EXPECT_CALL(outputLayer, editState()).WillRepeatedly(ReturnRef(outputLayerState));
1361 }
1362
1363 StrictMock<mock::OutputLayer> outputLayer;
Lloyd Pique1ef93222019-11-21 16:41:53 -08001364 impl::OutputLayerCompositionState outputLayerState;
Ady Abrahame0eafa82022-02-02 19:30:47 -08001365 sp<StrictMock<mock::LayerFE>> layerFE = sp<StrictMock<mock::LayerFE>>::make();
Lloyd Pique1ef93222019-11-21 16:41:53 -08001366 };
1367
1368 OutputCollectVisibleLayersTest() {
Lloyd Pique0a456232020-01-16 17:51:13 -08001369 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(3u));
Lloyd Pique1ef93222019-11-21 16:41:53 -08001370 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0))
1371 .WillRepeatedly(Return(&mLayer1.outputLayer));
1372 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1))
1373 .WillRepeatedly(Return(&mLayer2.outputLayer));
1374 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(2))
1375 .WillRepeatedly(Return(&mLayer3.outputLayer));
1376
Lloyd Piquede196652020-01-22 17:29:58 -08001377 mRefreshArgs.layers.push_back(mLayer1.layerFE);
1378 mRefreshArgs.layers.push_back(mLayer2.layerFE);
1379 mRefreshArgs.layers.push_back(mLayer3.layerFE);
Lloyd Pique1ef93222019-11-21 16:41:53 -08001380 }
1381
1382 StrictMock<OutputPartialMock> mOutput;
1383 CompositionRefreshArgs mRefreshArgs;
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001384 LayerFESet mGeomSnapshots;
1385 Output::CoverageState mCoverageState{mGeomSnapshots};
Lloyd Pique1ef93222019-11-21 16:41:53 -08001386 Layer mLayer1;
1387 Layer mLayer2;
1388 Layer mLayer3;
1389};
1390
1391TEST_F(OutputCollectVisibleLayersTest, doesMinimalWorkIfNoLayers) {
1392 mRefreshArgs.layers.clear();
Lloyd Pique0a456232020-01-16 17:51:13 -08001393 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0u));
Lloyd Pique1ef93222019-11-21 16:41:53 -08001394
1395 EXPECT_CALL(mOutput, setReleasedLayers(Ref(mRefreshArgs)));
1396 EXPECT_CALL(mOutput, finalizePendingOutputLayers());
1397
1398 mOutput.collectVisibleLayers(mRefreshArgs, mCoverageState);
1399}
1400
1401TEST_F(OutputCollectVisibleLayersTest, processesCandidateLayersReversedAndSetsOutputLayerZ) {
1402 // Enforce a call order sequence for this test.
1403 InSequence seq;
1404
1405 // Layer coverage is evaluated from front to back!
Lloyd Piquede196652020-01-22 17:29:58 -08001406 EXPECT_CALL(mOutput, ensureOutputLayerIfVisible(Eq(mLayer3.layerFE), Ref(mCoverageState)));
1407 EXPECT_CALL(mOutput, ensureOutputLayerIfVisible(Eq(mLayer2.layerFE), Ref(mCoverageState)));
1408 EXPECT_CALL(mOutput, ensureOutputLayerIfVisible(Eq(mLayer1.layerFE), Ref(mCoverageState)));
Lloyd Pique1ef93222019-11-21 16:41:53 -08001409
1410 EXPECT_CALL(mOutput, setReleasedLayers(Ref(mRefreshArgs)));
1411 EXPECT_CALL(mOutput, finalizePendingOutputLayers());
1412
1413 mOutput.collectVisibleLayers(mRefreshArgs, mCoverageState);
Lloyd Pique1ef93222019-11-21 16:41:53 -08001414}
Lloyd Piqueb62cebc2019-11-20 18:31:52 -08001415
1416/*
1417 * Output::ensureOutputLayerIfVisible()
1418 */
1419
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001420struct OutputEnsureOutputLayerIfVisibleTest : public testing::Test {
1421 struct OutputPartialMock : public OutputPartialMockBase {
1422 // Sets up the helper functions called by the function under test to use
1423 // mock implementations.
Dominik Laskowski29fa1462021-04-27 15:51:50 -07001424 MOCK_METHOD(bool, includesLayer, (const sp<compositionengine::LayerFE>&),
1425 (const, override));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001426 MOCK_CONST_METHOD1(getOutputLayerOrderedByZByIndex, OutputLayer*(size_t));
Lloyd Piquede196652020-01-22 17:29:58 -08001427 MOCK_METHOD2(ensureOutputLayer,
1428 compositionengine::OutputLayer*(std::optional<size_t>, const sp<LayerFE>&));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001429 };
1430
1431 OutputEnsureOutputLayerIfVisibleTest() {
Dominik Laskowski29fa1462021-04-27 15:51:50 -07001432 EXPECT_CALL(mOutput, includesLayer(sp<LayerFE>(mLayer.layerFE)))
Lloyd Piquede196652020-01-22 17:29:58 -08001433 .WillRepeatedly(Return(true));
Lloyd Pique0a456232020-01-16 17:51:13 -08001434 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(1u));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001435 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u))
Lloyd Piquede196652020-01-22 17:29:58 -08001436 .WillRepeatedly(Return(&mLayer.outputLayer));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001437
Angel Aguayob084e0c2021-08-04 23:27:28 +00001438 mOutput.mState.displaySpace.setBounds(ui::Size(200, 300));
1439 mOutput.mState.layerStackSpace.setContent(Rect(0, 0, 200, 300));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001440 mOutput.mState.transform = ui::Transform(TR_IDENT, 200, 300);
1441
Lloyd Piquede196652020-01-22 17:29:58 -08001442 mLayer.layerFEState.isVisible = true;
1443 mLayer.layerFEState.isOpaque = true;
1444 mLayer.layerFEState.contentDirty = true;
1445 mLayer.layerFEState.geomLayerBounds = FloatRect{0, 0, 100, 200};
1446 mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
Leon Scroggins III9a0afda2022-01-11 16:53:09 -05001447 mLayer.layerFEState.transparentRegionHint = kTransparentRegionHint;
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001448
Lloyd Piquede196652020-01-22 17:29:58 -08001449 mLayer.outputLayerState.visibleRegion = Region(Rect(0, 0, 50, 200));
1450 mLayer.outputLayerState.coveredRegion = Region(Rect(50, 0, 100, 200));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001451
Lloyd Piquede196652020-01-22 17:29:58 -08001452 mGeomSnapshots.insert(mLayer.layerFE);
1453 }
1454
1455 void ensureOutputLayerIfVisible() {
1456 sp<LayerFE> layerFE(mLayer.layerFE);
1457 mOutput.ensureOutputLayerIfVisible(layerFE, mCoverageState);
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001458 }
1459
1460 static const Region kEmptyRegion;
1461 static const Region kFullBoundsNoRotation;
1462 static const Region kRightHalfBoundsNoRotation;
1463 static const Region kLowerHalfBoundsNoRotation;
1464 static const Region kFullBounds90Rotation;
Leon Scroggins III9a0afda2022-01-11 16:53:09 -05001465 static const Region kTransparentRegionHint;
Leon Scroggins III81aff792022-03-21 13:51:34 -04001466 static const Region kTransparentRegionHintTwo;
1467 static const Region kTransparentRegionHintTwo90Rotation;
Alec Mourie60f0b92022-06-10 19:15:20 +00001468 static const Region kTransparentRegionHintNegative;
1469 static const Region kTransparentRegionHintNegativeIntersectsBounds;
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001470
1471 StrictMock<OutputPartialMock> mOutput;
1472 LayerFESet mGeomSnapshots;
1473 Output::CoverageState mCoverageState{mGeomSnapshots};
1474
Lloyd Piquede196652020-01-22 17:29:58 -08001475 NonInjectedLayer mLayer;
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001476};
1477
1478const Region OutputEnsureOutputLayerIfVisibleTest::kEmptyRegion = Region(Rect(0, 0, 0, 0));
1479const Region OutputEnsureOutputLayerIfVisibleTest::kFullBoundsNoRotation =
1480 Region(Rect(0, 0, 100, 200));
1481const Region OutputEnsureOutputLayerIfVisibleTest::kRightHalfBoundsNoRotation =
1482 Region(Rect(0, 100, 100, 200));
1483const Region OutputEnsureOutputLayerIfVisibleTest::kLowerHalfBoundsNoRotation =
1484 Region(Rect(50, 0, 100, 200));
1485const Region OutputEnsureOutputLayerIfVisibleTest::kFullBounds90Rotation =
1486 Region(Rect(0, 0, 200, 100));
Leon Scroggins III9a0afda2022-01-11 16:53:09 -05001487const Region OutputEnsureOutputLayerIfVisibleTest::kTransparentRegionHint =
Leon Scroggins III81aff792022-03-21 13:51:34 -04001488 Region(Rect(0, 0, 100, 100));
1489const Region OutputEnsureOutputLayerIfVisibleTest::kTransparentRegionHintTwo =
Leon Scroggins III7f7ad2c2022-03-17 17:06:20 -04001490 Region(Rect(25, 20, 50, 75));
Leon Scroggins III81aff792022-03-21 13:51:34 -04001491const Region OutputEnsureOutputLayerIfVisibleTest::kTransparentRegionHintTwo90Rotation =
Leon Scroggins III7f7ad2c2022-03-17 17:06:20 -04001492 Region(Rect(125, 25, 180, 50));
Alec Mourie60f0b92022-06-10 19:15:20 +00001493const Region OutputEnsureOutputLayerIfVisibleTest::kTransparentRegionHintNegative =
1494 Region(Rect(INT32_MIN, INT32_MIN, INT32_MIN + 100, INT32_MIN + 200));
1495const Region OutputEnsureOutputLayerIfVisibleTest::kTransparentRegionHintNegativeIntersectsBounds =
1496 Region(Rect(INT32_MIN, INT32_MIN, 100, 100));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001497
Dominik Laskowski29fa1462021-04-27 15:51:50 -07001498TEST_F(OutputEnsureOutputLayerIfVisibleTest, performsGeomLatchBeforeCheckingIfLayerIncluded) {
1499 EXPECT_CALL(mOutput, includesLayer(sp<LayerFE>(mLayer.layerFE))).WillOnce(Return(false));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001500 mGeomSnapshots.clear();
1501
Lloyd Piquede196652020-01-22 17:29:58 -08001502 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001503}
1504
1505TEST_F(OutputEnsureOutputLayerIfVisibleTest,
Dominik Laskowski29fa1462021-04-27 15:51:50 -07001506 skipsLatchIfAlreadyLatchedBeforeCheckingIfLayerIncluded) {
1507 EXPECT_CALL(mOutput, includesLayer(sp<LayerFE>(mLayer.layerFE))).WillOnce(Return(false));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001508
Lloyd Piquede196652020-01-22 17:29:58 -08001509 ensureOutputLayerIfVisible();
1510}
1511
1512TEST_F(OutputEnsureOutputLayerIfVisibleTest, takesEarlyOutIfLayerHasNoCompositionState) {
1513 EXPECT_CALL(*mLayer.layerFE, getCompositionState()).WillOnce(Return(nullptr));
1514
1515 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001516}
1517
1518TEST_F(OutputEnsureOutputLayerIfVisibleTest, takesEarlyOutIfLayerNotVisible) {
Lloyd Piquede196652020-01-22 17:29:58 -08001519 mLayer.layerFEState.isVisible = false;
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001520
Lloyd Piquede196652020-01-22 17:29:58 -08001521 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001522}
1523
1524TEST_F(OutputEnsureOutputLayerIfVisibleTest, takesEarlyOutIfLayerHasEmptyVisibleRegion) {
Lloyd Piquede196652020-01-22 17:29:58 -08001525 mLayer.layerFEState.geomLayerBounds = FloatRect{0, 0, 0, 0};
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001526
Lloyd Piquede196652020-01-22 17:29:58 -08001527 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001528}
1529
Marin Shalamanove67fcd02020-07-01 13:25:38 +00001530TEST_F(OutputEnsureOutputLayerIfVisibleTest, takesNotSoEarlyOutifDrawRegionEmpty) {
Angel Aguayob084e0c2021-08-04 23:27:28 +00001531 mOutput.mState.displaySpace.setBounds(ui::Size(0, 0));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001532
Lloyd Piquede196652020-01-22 17:29:58 -08001533 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001534}
1535
1536TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1537 handlesCreatingOutputLayerForOpaqueDirtyNotRotatedLayer) {
Lloyd Piquede196652020-01-22 17:29:58 -08001538 mLayer.layerFEState.isOpaque = true;
1539 mLayer.layerFEState.contentDirty = true;
1540 mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001541
1542 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
Lloyd Piquede196652020-01-22 17:29:58 -08001543 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE)))
1544 .WillOnce(Return(&mLayer.outputLayer));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001545
Lloyd Piquede196652020-01-22 17:29:58 -08001546 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001547
1548 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1549 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1550 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
1551
Lloyd Piquede196652020-01-22 17:29:58 -08001552 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1553 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
1554 RegionEq(kFullBoundsNoRotation));
1555 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1556 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001557}
1558
1559TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1560 handlesUpdatingOutputLayerForOpaqueDirtyNotRotatedLayer) {
Lloyd Piquede196652020-01-22 17:29:58 -08001561 mLayer.layerFEState.isOpaque = true;
1562 mLayer.layerFEState.contentDirty = true;
1563 mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001564
Lloyd Piquede196652020-01-22 17:29:58 -08001565 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE)))
1566 .WillOnce(Return(&mLayer.outputLayer));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001567
Lloyd Piquede196652020-01-22 17:29:58 -08001568 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001569
1570 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1571 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1572 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
1573
Lloyd Piquede196652020-01-22 17:29:58 -08001574 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1575 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
1576 RegionEq(kFullBoundsNoRotation));
1577 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1578 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001579}
1580
1581TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1582 handlesCreatingOutputLayerForTransparentDirtyNotRotatedLayer) {
Lloyd Piquede196652020-01-22 17:29:58 -08001583 mLayer.layerFEState.isOpaque = false;
1584 mLayer.layerFEState.contentDirty = true;
1585 mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001586
1587 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
Lloyd Piquede196652020-01-22 17:29:58 -08001588 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE)))
1589 .WillOnce(Return(&mLayer.outputLayer));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001590
Lloyd Piquede196652020-01-22 17:29:58 -08001591 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001592
1593 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1594 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1595 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kEmptyRegion));
1596
Lloyd Piquede196652020-01-22 17:29:58 -08001597 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1598 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001599 RegionEq(kRightHalfBoundsNoRotation));
Lloyd Piquede196652020-01-22 17:29:58 -08001600 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1601 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001602}
1603
1604TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1605 handlesUpdatingOutputLayerForTransparentDirtyNotRotatedLayer) {
Lloyd Piquede196652020-01-22 17:29:58 -08001606 mLayer.layerFEState.isOpaque = false;
1607 mLayer.layerFEState.contentDirty = true;
1608 mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001609
Lloyd Piquede196652020-01-22 17:29:58 -08001610 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE)))
1611 .WillOnce(Return(&mLayer.outputLayer));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001612
Lloyd Piquede196652020-01-22 17:29:58 -08001613 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001614
1615 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1616 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1617 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kEmptyRegion));
1618
Lloyd Piquede196652020-01-22 17:29:58 -08001619 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1620 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001621 RegionEq(kRightHalfBoundsNoRotation));
Lloyd Piquede196652020-01-22 17:29:58 -08001622 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1623 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001624}
1625
1626TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1627 handlesCreatingOutputLayerForOpaqueNonDirtyNotRotatedLayer) {
Lloyd Piquede196652020-01-22 17:29:58 -08001628 mLayer.layerFEState.isOpaque = true;
1629 mLayer.layerFEState.contentDirty = false;
1630 mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001631
1632 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
Lloyd Piquede196652020-01-22 17:29:58 -08001633 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE)))
1634 .WillOnce(Return(&mLayer.outputLayer));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001635
Lloyd Piquede196652020-01-22 17:29:58 -08001636 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001637
1638 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1639 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1640 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
1641
Lloyd Piquede196652020-01-22 17:29:58 -08001642 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1643 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
1644 RegionEq(kFullBoundsNoRotation));
1645 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1646 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001647}
1648
1649TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1650 handlesUpdatingOutputLayerForOpaqueNonDirtyNotRotatedLayer) {
Lloyd Piquede196652020-01-22 17:29:58 -08001651 mLayer.layerFEState.isOpaque = true;
1652 mLayer.layerFEState.contentDirty = false;
1653 mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001654
Lloyd Piquede196652020-01-22 17:29:58 -08001655 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE)))
1656 .WillOnce(Return(&mLayer.outputLayer));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001657
Lloyd Piquede196652020-01-22 17:29:58 -08001658 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001659
1660 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kLowerHalfBoundsNoRotation));
1661 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1662 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
1663
Lloyd Piquede196652020-01-22 17:29:58 -08001664 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1665 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
1666 RegionEq(kFullBoundsNoRotation));
1667 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1668 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001669}
1670
1671TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1672 handlesCreatingOutputLayerForOpaqueDirtyRotated90Layer) {
Lloyd Piquede196652020-01-22 17:29:58 -08001673 mLayer.layerFEState.isOpaque = true;
1674 mLayer.layerFEState.contentDirty = true;
1675 mLayer.layerFEState.geomLayerBounds = FloatRect{0, 0, 200, 100};
1676 mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_ROT_90, 100, 200);
1677 mLayer.outputLayerState.visibleRegion = Region(Rect(0, 0, 100, 100));
1678 mLayer.outputLayerState.coveredRegion = Region(Rect(100, 0, 200, 100));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001679
1680 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
Lloyd Piquede196652020-01-22 17:29:58 -08001681 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE)))
1682 .WillOnce(Return(&mLayer.outputLayer));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001683
Lloyd Piquede196652020-01-22 17:29:58 -08001684 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001685
1686 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1687 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1688 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
1689
Lloyd Piquede196652020-01-22 17:29:58 -08001690 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1691 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
1692 RegionEq(kFullBoundsNoRotation));
1693 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1694 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001695}
1696
1697TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1698 handlesUpdatingOutputLayerForOpaqueDirtyRotated90Layer) {
Lloyd Piquede196652020-01-22 17:29:58 -08001699 mLayer.layerFEState.isOpaque = true;
1700 mLayer.layerFEState.contentDirty = true;
1701 mLayer.layerFEState.geomLayerBounds = FloatRect{0, 0, 200, 100};
1702 mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_ROT_90, 100, 200);
1703 mLayer.outputLayerState.visibleRegion = Region(Rect(0, 0, 100, 100));
1704 mLayer.outputLayerState.coveredRegion = Region(Rect(100, 0, 200, 100));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001705
Lloyd Piquede196652020-01-22 17:29:58 -08001706 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE)))
1707 .WillOnce(Return(&mLayer.outputLayer));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001708
Lloyd Piquede196652020-01-22 17:29:58 -08001709 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001710
1711 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1712 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1713 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
1714
Lloyd Piquede196652020-01-22 17:29:58 -08001715 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1716 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
1717 RegionEq(kFullBoundsNoRotation));
1718 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1719 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBoundsNoRotation));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001720}
1721
1722TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1723 handlesCreatingOutputLayerForOpaqueDirtyNotRotatedLayerRotatedOutput) {
Lloyd Piquede196652020-01-22 17:29:58 -08001724 mLayer.layerFEState.isOpaque = true;
1725 mLayer.layerFEState.contentDirty = true;
1726 mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001727
Angel Aguayob084e0c2021-08-04 23:27:28 +00001728 mOutput.mState.layerStackSpace.setContent(Rect(0, 0, 300, 200));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001729 mOutput.mState.transform = ui::Transform(TR_ROT_90, 200, 300);
1730
1731 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
Lloyd Piquede196652020-01-22 17:29:58 -08001732 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE)))
1733 .WillOnce(Return(&mLayer.outputLayer));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001734
Lloyd Piquede196652020-01-22 17:29:58 -08001735 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001736
1737 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1738 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1739 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
1740
Lloyd Piquede196652020-01-22 17:29:58 -08001741 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1742 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
1743 RegionEq(kFullBoundsNoRotation));
1744 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1745 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBounds90Rotation));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001746}
1747
1748TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1749 handlesUpdatingOutputLayerForOpaqueDirtyNotRotatedLayerRotatedOutput) {
Lloyd Piquede196652020-01-22 17:29:58 -08001750 mLayer.layerFEState.isOpaque = true;
1751 mLayer.layerFEState.contentDirty = true;
1752 mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001753
Angel Aguayob084e0c2021-08-04 23:27:28 +00001754 mOutput.mState.layerStackSpace.setContent(Rect(0, 0, 300, 200));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001755 mOutput.mState.transform = ui::Transform(TR_ROT_90, 200, 300);
1756
Lloyd Piquede196652020-01-22 17:29:58 -08001757 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE)))
1758 .WillOnce(Return(&mLayer.outputLayer));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001759
Lloyd Piquede196652020-01-22 17:29:58 -08001760 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001761
1762 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kFullBoundsNoRotation));
1763 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kFullBoundsNoRotation));
1764 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kFullBoundsNoRotation));
1765
Lloyd Piquede196652020-01-22 17:29:58 -08001766 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kFullBoundsNoRotation));
1767 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
1768 RegionEq(kFullBoundsNoRotation));
1769 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1770 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kFullBounds90Rotation));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001771}
1772
1773TEST_F(OutputEnsureOutputLayerIfVisibleTest,
1774 handlesCreatingOutputLayerForOpaqueDirtyArbitraryTransformLayer) {
1775 ui::Transform arbitraryTransform;
1776 arbitraryTransform.set(1, 1, -1, 1);
1777 arbitraryTransform.set(0, 100);
1778
Lloyd Piquede196652020-01-22 17:29:58 -08001779 mLayer.layerFEState.isOpaque = true;
1780 mLayer.layerFEState.contentDirty = true;
1781 mLayer.layerFEState.geomLayerBounds = FloatRect{0, 0, 100, 200};
1782 mLayer.layerFEState.geomLayerTransform = arbitraryTransform;
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001783
1784 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
Lloyd Piquede196652020-01-22 17:29:58 -08001785 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE)))
1786 .WillOnce(Return(&mLayer.outputLayer));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001787
Lloyd Piquede196652020-01-22 17:29:58 -08001788 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001789
1790 const Region kRegion = Region(Rect(0, 0, 300, 300));
1791 const Region kRegionClipped = Region(Rect(0, 0, 200, 300));
1792
1793 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kRegion));
1794 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kRegion));
1795 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kEmptyRegion));
1796
Lloyd Piquede196652020-01-22 17:29:58 -08001797 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kRegion));
1798 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion, RegionEq(kRegion));
1799 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kEmptyRegion));
1800 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion, RegionEq(kRegionClipped));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001801}
1802
1803TEST_F(OutputEnsureOutputLayerIfVisibleTest, coverageAccumulatesTest) {
Lloyd Piquede196652020-01-22 17:29:58 -08001804 mLayer.layerFEState.isOpaque = false;
1805 mLayer.layerFEState.contentDirty = true;
1806 mLayer.layerFEState.geomLayerTransform = ui::Transform(TR_IDENT, 100, 200);
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001807
1808 mCoverageState.dirtyRegion = Region(Rect(0, 0, 500, 500));
1809 mCoverageState.aboveCoveredLayers = Region(Rect(50, 0, 150, 200));
1810 mCoverageState.aboveOpaqueLayers = Region(Rect(50, 0, 150, 200));
1811
Lloyd Piquede196652020-01-22 17:29:58 -08001812 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE)))
1813 .WillOnce(Return(&mLayer.outputLayer));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001814
Lloyd Piquede196652020-01-22 17:29:58 -08001815 ensureOutputLayerIfVisible();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001816
1817 const Region kExpectedDirtyRegion = Region(Rect(0, 0, 500, 500));
1818 const Region kExpectedAboveCoveredRegion = Region(Rect(0, 0, 150, 200));
1819 const Region kExpectedAboveOpaqueRegion = Region(Rect(50, 0, 150, 200));
1820 const Region kExpectedLayerVisibleRegion = Region(Rect(0, 0, 50, 200));
1821 const Region kExpectedLayerCoveredRegion = Region(Rect(50, 0, 100, 200));
1822 const Region kExpectedLayerVisibleNonTransparentRegion = Region(Rect(0, 100, 50, 200));
1823
1824 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kExpectedDirtyRegion));
1825 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kExpectedAboveCoveredRegion));
1826 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kExpectedAboveOpaqueRegion));
1827
Lloyd Piquede196652020-01-22 17:29:58 -08001828 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kExpectedLayerVisibleRegion));
1829 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001830 RegionEq(kExpectedLayerVisibleNonTransparentRegion));
Lloyd Piquede196652020-01-22 17:29:58 -08001831 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kExpectedLayerCoveredRegion));
1832 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion,
1833 RegionEq(kExpectedLayerVisibleRegion));
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08001834}
Lloyd Piqueb62cebc2019-11-20 18:31:52 -08001835
Vishnu Naira483b4a2019-12-12 15:07:52 -08001836TEST_F(OutputEnsureOutputLayerIfVisibleTest, coverageAccumulatesWithShadowsTest) {
1837 ui::Transform translate;
1838 translate.set(50, 50);
Lloyd Piquede196652020-01-22 17:29:58 -08001839 mLayer.layerFEState.geomLayerTransform = translate;
Vishnu Naird9e4f462023-10-06 04:05:45 +00001840 mLayer.layerFEState.shadowSettings.length = 10.0f;
Vishnu Naira483b4a2019-12-12 15:07:52 -08001841
1842 mCoverageState.dirtyRegion = Region(Rect(0, 0, 500, 500));
1843 // half of the layer including the casting shadow is covered and opaque
1844 mCoverageState.aboveCoveredLayers = Region(Rect(40, 40, 100, 260));
1845 mCoverageState.aboveOpaqueLayers = Region(Rect(40, 40, 100, 260));
1846
Lloyd Piquede196652020-01-22 17:29:58 -08001847 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE)))
1848 .WillOnce(Return(&mLayer.outputLayer));
Vishnu Naira483b4a2019-12-12 15:07:52 -08001849
Lloyd Piquede196652020-01-22 17:29:58 -08001850 ensureOutputLayerIfVisible();
Vishnu Naira483b4a2019-12-12 15:07:52 -08001851
1852 const Region kExpectedDirtyRegion = Region(Rect(0, 0, 500, 500));
1853 const Region kExpectedAboveCoveredRegion = Region(Rect(40, 40, 160, 260));
1854 // add starting opaque region to the opaque half of the casting layer bounds
1855 const Region kExpectedAboveOpaqueRegion =
1856 Region(Rect(40, 40, 100, 260)).orSelf(Rect(100, 50, 150, 250));
1857 const Region kExpectedLayerVisibleRegion = Region(Rect(100, 40, 160, 260));
1858 const Region kExpectedoutputSpaceLayerVisibleRegion = Region(Rect(100, 50, 150, 250));
1859 const Region kExpectedLayerCoveredRegion = Region(Rect(40, 40, 100, 260));
1860 const Region kExpectedLayerVisibleNonTransparentRegion = Region(Rect(100, 40, 160, 260));
1861 const Region kExpectedLayerShadowRegion =
1862 Region(Rect(40, 40, 160, 260)).subtractSelf(Rect(50, 50, 150, 250));
1863
1864 EXPECT_THAT(mCoverageState.dirtyRegion, RegionEq(kExpectedDirtyRegion));
1865 EXPECT_THAT(mCoverageState.aboveCoveredLayers, RegionEq(kExpectedAboveCoveredRegion));
1866 EXPECT_THAT(mCoverageState.aboveOpaqueLayers, RegionEq(kExpectedAboveOpaqueRegion));
1867
Lloyd Piquede196652020-01-22 17:29:58 -08001868 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kExpectedLayerVisibleRegion));
1869 EXPECT_THAT(mLayer.outputLayerState.visibleNonTransparentRegion,
Vishnu Naira483b4a2019-12-12 15:07:52 -08001870 RegionEq(kExpectedLayerVisibleNonTransparentRegion));
Lloyd Piquede196652020-01-22 17:29:58 -08001871 EXPECT_THAT(mLayer.outputLayerState.coveredRegion, RegionEq(kExpectedLayerCoveredRegion));
1872 EXPECT_THAT(mLayer.outputLayerState.outputSpaceVisibleRegion,
Vishnu Naira483b4a2019-12-12 15:07:52 -08001873 RegionEq(kExpectedoutputSpaceLayerVisibleRegion));
Lloyd Piquede196652020-01-22 17:29:58 -08001874 EXPECT_THAT(mLayer.outputLayerState.shadowRegion, RegionEq(kExpectedLayerShadowRegion));
Vishnu Naira483b4a2019-12-12 15:07:52 -08001875 EXPECT_FALSE(kExpectedLayerVisibleRegion.subtract(kExpectedLayerShadowRegion).isEmpty());
1876}
1877
1878TEST_F(OutputEnsureOutputLayerIfVisibleTest, shadowRegionOnlyTest) {
1879 ui::Transform translate;
1880 translate.set(50, 50);
Lloyd Piquede196652020-01-22 17:29:58 -08001881 mLayer.layerFEState.geomLayerTransform = translate;
Vishnu Naird9e4f462023-10-06 04:05:45 +00001882 mLayer.layerFEState.shadowSettings.length = 10.0f;
Vishnu Naira483b4a2019-12-12 15:07:52 -08001883
1884 mCoverageState.dirtyRegion = Region(Rect(0, 0, 500, 500));
1885 // Casting layer is covered by an opaque region leaving only part of its shadow to be drawn
1886 mCoverageState.aboveCoveredLayers = Region(Rect(40, 40, 150, 260));
1887 mCoverageState.aboveOpaqueLayers = Region(Rect(40, 40, 150, 260));
1888
Lloyd Piquede196652020-01-22 17:29:58 -08001889 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(0u), Eq(mLayer.layerFE)))
1890 .WillOnce(Return(&mLayer.outputLayer));
Vishnu Naira483b4a2019-12-12 15:07:52 -08001891
Lloyd Piquede196652020-01-22 17:29:58 -08001892 ensureOutputLayerIfVisible();
Vishnu Naira483b4a2019-12-12 15:07:52 -08001893
1894 const Region kExpectedLayerVisibleRegion = Region(Rect(150, 40, 160, 260));
1895 const Region kExpectedLayerShadowRegion =
1896 Region(Rect(40, 40, 160, 260)).subtractSelf(Rect(50, 50, 150, 250));
1897
Lloyd Piquede196652020-01-22 17:29:58 -08001898 EXPECT_THAT(mLayer.outputLayerState.visibleRegion, RegionEq(kExpectedLayerVisibleRegion));
1899 EXPECT_THAT(mLayer.outputLayerState.shadowRegion, RegionEq(kExpectedLayerShadowRegion));
Vishnu Naira483b4a2019-12-12 15:07:52 -08001900 EXPECT_TRUE(kExpectedLayerVisibleRegion.subtract(kExpectedLayerShadowRegion).isEmpty());
1901}
1902
Marin Shalamanove67fcd02020-07-01 13:25:38 +00001903TEST_F(OutputEnsureOutputLayerIfVisibleTest, takesNotSoEarlyOutifLayerWithShadowIsCovered) {
Vishnu Naira483b4a2019-12-12 15:07:52 -08001904 ui::Transform translate;
1905 translate.set(50, 50);
Lloyd Piquede196652020-01-22 17:29:58 -08001906 mLayer.layerFEState.geomLayerTransform = translate;
Vishnu Naird9e4f462023-10-06 04:05:45 +00001907 mLayer.layerFEState.shadowSettings.length = 10.0f;
Vishnu Naira483b4a2019-12-12 15:07:52 -08001908
1909 mCoverageState.dirtyRegion = Region(Rect(0, 0, 500, 500));
1910 // Casting layer and its shadows are covered by an opaque region
1911 mCoverageState.aboveCoveredLayers = Region(Rect(40, 40, 160, 260));
1912 mCoverageState.aboveOpaqueLayers = Region(Rect(40, 40, 160, 260));
1913
Lloyd Piquede196652020-01-22 17:29:58 -08001914 ensureOutputLayerIfVisible();
Vishnu Naira483b4a2019-12-12 15:07:52 -08001915}
1916
Leon Scroggins III9a0afda2022-01-11 16:53:09 -05001917TEST_F(OutputEnsureOutputLayerIfVisibleTest, displayDecorSetsBlockingFromTransparentRegion) {
1918 mLayer.layerFEState.isOpaque = false;
1919 mLayer.layerFEState.contentDirty = true;
1920 mLayer.layerFEState.compositionType =
1921 aidl::android::hardware::graphics::composer3::Composition::DISPLAY_DECORATION;
1922
1923 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
1924 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE)))
1925 .WillOnce(Return(&mLayer.outputLayer));
1926 ensureOutputLayerIfVisible();
1927
1928 EXPECT_THAT(mLayer.outputLayerState.outputSpaceBlockingRegionHint,
1929 RegionEq(kTransparentRegionHint));
1930}
1931
1932TEST_F(OutputEnsureOutputLayerIfVisibleTest, normalLayersDoNotSetBlockingRegion) {
1933 mLayer.layerFEState.isOpaque = false;
1934 mLayer.layerFEState.contentDirty = true;
1935
1936 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
1937 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE)))
1938 .WillOnce(Return(&mLayer.outputLayer));
1939 ensureOutputLayerIfVisible();
1940
1941 EXPECT_THAT(mLayer.outputLayerState.outputSpaceBlockingRegionHint, RegionEq(Region()));
1942}
1943
Leon Scroggins III7f7ad2c2022-03-17 17:06:20 -04001944TEST_F(OutputEnsureOutputLayerIfVisibleTest, blockingRegionIsInOutputSpace) {
1945 mLayer.layerFEState.isOpaque = false;
1946 mLayer.layerFEState.contentDirty = true;
1947 mLayer.layerFEState.compositionType =
1948 aidl::android::hardware::graphics::composer3::Composition::DISPLAY_DECORATION;
Leon Scroggins III81aff792022-03-21 13:51:34 -04001949 mLayer.layerFEState.transparentRegionHint = kTransparentRegionHintTwo;
Leon Scroggins III7f7ad2c2022-03-17 17:06:20 -04001950
1951 mOutput.mState.layerStackSpace.setContent(Rect(0, 0, 300, 200));
1952 mOutput.mState.transform = ui::Transform(TR_ROT_90, 200, 300);
1953
1954 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
1955 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE)))
1956 .WillOnce(Return(&mLayer.outputLayer));
1957 ensureOutputLayerIfVisible();
1958
1959 EXPECT_THAT(mLayer.outputLayerState.outputSpaceBlockingRegionHint,
Leon Scroggins III81aff792022-03-21 13:51:34 -04001960 RegionEq(kTransparentRegionHintTwo90Rotation));
Leon Scroggins III7f7ad2c2022-03-17 17:06:20 -04001961}
1962
Alec Mourie60f0b92022-06-10 19:15:20 +00001963TEST_F(OutputEnsureOutputLayerIfVisibleTest, transparentRegionExcludesOutputLayer) {
1964 mLayer.layerFEState.isOpaque = false;
1965 mLayer.layerFEState.contentDirty = true;
1966 mLayer.layerFEState.geomLayerBounds = kFullBoundsNoRotation.bounds().toFloatRect();
1967 mLayer.layerFEState.transparentRegionHint = kFullBoundsNoRotation;
1968
1969 EXPECT_CALL(mOutput, ensureOutputLayer(_, _)).Times(0);
1970}
1971
1972TEST_F(OutputEnsureOutputLayerIfVisibleTest, transparentRegionIgnoredWhenOutsideBounds) {
1973 mLayer.layerFEState.isOpaque = false;
1974 mLayer.layerFEState.contentDirty = true;
1975 mLayer.layerFEState.geomLayerBounds = kFullBoundsNoRotation.bounds().toFloatRect();
1976 mLayer.layerFEState.transparentRegionHint = kTransparentRegionHintNegative;
1977
1978 EXPECT_CALL(mOutput, ensureOutputLayer(_, _)).Times(0);
1979}
1980
1981TEST_F(OutputEnsureOutputLayerIfVisibleTest, transparentRegionClipsWhenOutsideBounds) {
1982 mLayer.layerFEState.isOpaque = false;
1983 mLayer.layerFEState.contentDirty = true;
1984 mLayer.layerFEState.compositionType =
1985 aidl::android::hardware::graphics::composer3::Composition::DISPLAY_DECORATION;
1986 mLayer.layerFEState.transparentRegionHint = kTransparentRegionHintNegativeIntersectsBounds;
1987
1988 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
1989 EXPECT_CALL(mOutput, ensureOutputLayer(Eq(std::nullopt), Eq(mLayer.layerFE)))
1990 .WillOnce(Return(&mLayer.outputLayer));
1991 ensureOutputLayerIfVisible();
1992
1993 // Check that the blocking region clips an out-of-bounds transparent region.
1994 EXPECT_THAT(mLayer.outputLayerState.outputSpaceBlockingRegionHint,
1995 RegionEq(kTransparentRegionHint));
1996}
1997
Lloyd Piqueb62cebc2019-11-20 18:31:52 -08001998/*
Lloyd Piquefaa3f192019-11-14 14:05:09 -08001999 * Output::present()
2000 */
2001
2002struct OutputPresentTest : public testing::Test {
2003 struct OutputPartialMock : public OutputPartialMockBase {
Lloyd Pique739afaf2019-11-21 16:40:05 -08002004 // Sets up the helper functions called by the function under test to use
2005 // mock implementations.
Lloyd Piquefaa3f192019-11-14 14:05:09 -08002006 MOCK_METHOD1(updateColorProfile, void(const compositionengine::CompositionRefreshArgs&));
Dan Stoza269dc4d2021-01-15 15:07:43 -08002007 MOCK_METHOD1(updateCompositionState,
Lloyd Piquefaa3f192019-11-14 14:05:09 -08002008 void(const compositionengine::CompositionRefreshArgs&));
Dan Stoza269dc4d2021-01-15 15:07:43 -08002009 MOCK_METHOD0(planComposition, void());
2010 MOCK_METHOD1(writeCompositionState, void(const compositionengine::CompositionRefreshArgs&));
Lloyd Piquefaa3f192019-11-14 14:05:09 -08002011 MOCK_METHOD1(setColorTransform, void(const compositionengine::CompositionRefreshArgs&));
2012 MOCK_METHOD0(beginFrame, void());
2013 MOCK_METHOD0(prepareFrame, void());
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00002014 MOCK_METHOD0(prepareFrameAsync, GpuCompositionResult());
Lloyd Piquefaa3f192019-11-14 14:05:09 -08002015 MOCK_METHOD1(devOptRepaintFlash, void(const compositionengine::CompositionRefreshArgs&));
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00002016 MOCK_METHOD1(finishFrame, void(GpuCompositionResult&&));
Leon Scroggins IIIc1623d12023-11-06 15:31:05 -05002017 MOCK_METHOD0(presentFrameAndReleaseLayers, void());
Alec Mouriaa831582021-06-07 16:23:01 -07002018 MOCK_METHOD1(renderCachedSets, void(const compositionengine::CompositionRefreshArgs&));
Vishnu Naira3140382022-02-24 14:07:11 -08002019 MOCK_METHOD1(canPredictCompositionStrategy, bool(const CompositionRefreshArgs&));
Xiang Wangaab31162024-03-12 19:48:08 -07002020 MOCK_METHOD(void, setHintSessionRequiresRenderEngine, (bool requiresRenderEngine),
2021 (override));
2022 MOCK_METHOD(bool, isPowerHintSessionEnabled, (), (override));
Lloyd Piquefaa3f192019-11-14 14:05:09 -08002023 };
2024
Xiang Wangaab31162024-03-12 19:48:08 -07002025 OutputPresentTest() {
2026 EXPECT_CALL(mOutput, isPowerHintSessionEnabled()).WillRepeatedly(Return(true));
2027 }
2028
Lloyd Piquefaa3f192019-11-14 14:05:09 -08002029 StrictMock<OutputPartialMock> mOutput;
2030};
2031
2032TEST_F(OutputPresentTest, justInvokesChildFunctionsInSequence) {
2033 CompositionRefreshArgs args;
2034
2035 InSequence seq;
2036 EXPECT_CALL(mOutput, updateColorProfile(Ref(args)));
Dan Stoza269dc4d2021-01-15 15:07:43 -08002037 EXPECT_CALL(mOutput, updateCompositionState(Ref(args)));
2038 EXPECT_CALL(mOutput, planComposition());
2039 EXPECT_CALL(mOutput, writeCompositionState(Ref(args)));
Lloyd Piquefaa3f192019-11-14 14:05:09 -08002040 EXPECT_CALL(mOutput, setColorTransform(Ref(args)));
2041 EXPECT_CALL(mOutput, beginFrame());
Xiang Wangaab31162024-03-12 19:48:08 -07002042 EXPECT_CALL(mOutput, setHintSessionRequiresRenderEngine(false));
Vishnu Naira3140382022-02-24 14:07:11 -08002043 EXPECT_CALL(mOutput, canPredictCompositionStrategy(Ref(args))).WillOnce(Return(false));
Lloyd Piquefaa3f192019-11-14 14:05:09 -08002044 EXPECT_CALL(mOutput, prepareFrame());
2045 EXPECT_CALL(mOutput, devOptRepaintFlash(Ref(args)));
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00002046 EXPECT_CALL(mOutput, finishFrame(_));
Leon Scroggins IIIc1623d12023-11-06 15:31:05 -05002047 EXPECT_CALL(mOutput, presentFrameAndReleaseLayers());
Vishnu Naira3140382022-02-24 14:07:11 -08002048 EXPECT_CALL(mOutput, renderCachedSets(Ref(args)));
2049
2050 mOutput.present(args);
2051}
2052
2053TEST_F(OutputPresentTest, predictingCompositionStrategyInvokesPrepareFrameAsync) {
2054 CompositionRefreshArgs args;
2055
2056 InSequence seq;
2057 EXPECT_CALL(mOutput, updateColorProfile(Ref(args)));
2058 EXPECT_CALL(mOutput, updateCompositionState(Ref(args)));
2059 EXPECT_CALL(mOutput, planComposition());
2060 EXPECT_CALL(mOutput, writeCompositionState(Ref(args)));
2061 EXPECT_CALL(mOutput, setColorTransform(Ref(args)));
2062 EXPECT_CALL(mOutput, beginFrame());
Xiang Wangaab31162024-03-12 19:48:08 -07002063 EXPECT_CALL(mOutput, setHintSessionRequiresRenderEngine(false));
Vishnu Naira3140382022-02-24 14:07:11 -08002064 EXPECT_CALL(mOutput, canPredictCompositionStrategy(Ref(args))).WillOnce(Return(true));
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00002065 EXPECT_CALL(mOutput, prepareFrameAsync());
Vishnu Naira3140382022-02-24 14:07:11 -08002066 EXPECT_CALL(mOutput, devOptRepaintFlash(Ref(args)));
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00002067 EXPECT_CALL(mOutput, finishFrame(_));
Leon Scroggins IIIc1623d12023-11-06 15:31:05 -05002068 EXPECT_CALL(mOutput, presentFrameAndReleaseLayers());
Alec Mouriaa831582021-06-07 16:23:01 -07002069 EXPECT_CALL(mOutput, renderCachedSets(Ref(args)));
Lloyd Piquefaa3f192019-11-14 14:05:09 -08002070
2071 mOutput.present(args);
2072}
2073
2074/*
2075 * Output::updateColorProfile()
2076 */
2077
Lloyd Pique17ca7422019-11-14 14:24:10 -08002078struct OutputUpdateColorProfileTest : public testing::Test {
2079 using TestType = OutputUpdateColorProfileTest;
2080
2081 struct OutputPartialMock : public OutputPartialMockBase {
Lloyd Pique739afaf2019-11-21 16:40:05 -08002082 // Sets up the helper functions called by the function under test to use
2083 // mock implementations.
Lloyd Pique17ca7422019-11-14 14:24:10 -08002084 MOCK_METHOD1(setColorProfile, void(const ColorProfile&));
2085 };
2086
2087 struct Layer {
2088 Layer() {
Ady Abrahameca9d752021-03-03 12:20:00 -08002089 EXPECT_CALL(mOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*mLayerFE));
2090 EXPECT_CALL(*mLayerFE, getCompositionState()).WillRepeatedly(Return(&mLayerFEState));
Lloyd Pique17ca7422019-11-14 14:24:10 -08002091 }
2092
2093 StrictMock<mock::OutputLayer> mOutputLayer;
Ady Abrahameca9d752021-03-03 12:20:00 -08002094 sp<StrictMock<mock::LayerFE>> mLayerFE = sp<StrictMock<mock::LayerFE>>::make();
Lloyd Pique17ca7422019-11-14 14:24:10 -08002095 LayerFECompositionState mLayerFEState;
2096 };
2097
2098 OutputUpdateColorProfileTest() {
2099 mOutput.setDisplayColorProfileForTest(
2100 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
2101 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
Vishnu Naire14c6b32022-08-06 04:20:15 +00002102 mOutput.editState().isEnabled = true;
Lloyd Pique17ca7422019-11-14 14:24:10 -08002103
2104 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0))
2105 .WillRepeatedly(Return(&mLayer1.mOutputLayer));
2106 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1))
2107 .WillRepeatedly(Return(&mLayer2.mOutputLayer));
2108 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(2))
2109 .WillRepeatedly(Return(&mLayer3.mOutputLayer));
2110 }
2111
2112 struct ExecuteState : public CallOrderStateMachineHelper<TestType, ExecuteState> {
2113 void execute() { getInstance()->mOutput.updateColorProfile(getInstance()->mRefreshArgs); }
2114 };
2115
2116 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
2117 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
2118 StrictMock<OutputPartialMock> mOutput;
2119
2120 Layer mLayer1;
2121 Layer mLayer2;
2122 Layer mLayer3;
2123
2124 CompositionRefreshArgs mRefreshArgs;
2125};
2126
2127// TODO(b/144522012): Refactor Output::updateColorProfile and the related code
2128// to make it easier to write unit tests.
2129
2130TEST_F(OutputUpdateColorProfileTest, setsAColorProfileWhenUnmanaged) {
2131 // When the outputColorSetting is set to kUnmanaged, the implementation sets
2132 // a simple default color profile without looking at anything else.
2133
Lloyd Pique0a456232020-01-16 17:51:13 -08002134 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(3u));
Lloyd Pique17ca7422019-11-14 14:24:10 -08002135 EXPECT_CALL(mOutput,
Alec Mouri88790f32023-07-21 01:25:14 +00002136 setColorProfile(
2137 ColorProfileEq(ColorProfile{ui::ColorMode::NATIVE, ui::Dataspace::UNKNOWN,
2138 ui::RenderIntent::COLORIMETRIC})));
Lloyd Pique17ca7422019-11-14 14:24:10 -08002139
2140 mRefreshArgs.outputColorSetting = OutputColorSetting::kUnmanaged;
Lloyd Pique17ca7422019-11-14 14:24:10 -08002141
2142 mOutput.updateColorProfile(mRefreshArgs);
2143}
2144
2145struct OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile
2146 : public OutputUpdateColorProfileTest {
2147 OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile() {
Lloyd Pique0a456232020-01-16 17:51:13 -08002148 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(0u));
Lloyd Pique17ca7422019-11-14 14:24:10 -08002149 mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced;
Lloyd Pique17ca7422019-11-14 14:24:10 -08002150 }
2151
2152 struct ExpectBestColorModeCallResultUsedToSetColorProfileState
2153 : public CallOrderStateMachineHelper<
2154 TestType, ExpectBestColorModeCallResultUsedToSetColorProfileState> {
2155 [[nodiscard]] auto expectBestColorModeCallResultUsedToSetColorProfile(
2156 ui::ColorMode colorMode, ui::Dataspace dataspace, ui::RenderIntent renderIntent) {
2157 EXPECT_CALL(*getInstance()->mDisplayColorProfile,
2158 getBestColorMode(ui::Dataspace::V0_SRGB, ui::RenderIntent::ENHANCE, _, _,
2159 _))
2160 .WillOnce(DoAll(SetArgPointee<2>(dataspace), SetArgPointee<3>(colorMode),
2161 SetArgPointee<4>(renderIntent)));
2162 EXPECT_CALL(getInstance()->mOutput,
2163 setColorProfile(
Alec Mouri88790f32023-07-21 01:25:14 +00002164 ColorProfileEq(ColorProfile{colorMode, dataspace, renderIntent})));
Lloyd Pique17ca7422019-11-14 14:24:10 -08002165 return nextState<ExecuteState>();
2166 }
2167 };
2168
2169 // Call this member function to start using the mini-DSL defined above.
2170 [[nodiscard]] auto verify() {
2171 return ExpectBestColorModeCallResultUsedToSetColorProfileState::make(this);
2172 }
2173};
2174
2175TEST_F(OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile,
2176 Native_Unknown_Colorimetric_Set) {
2177 verify().expectBestColorModeCallResultUsedToSetColorProfile(ui::ColorMode::NATIVE,
2178 ui::Dataspace::UNKNOWN,
2179 ui::RenderIntent::COLORIMETRIC)
2180 .execute();
2181}
2182
2183TEST_F(OutputUpdateColorProfileTest_GetBestColorModeResultBecomesSetProfile,
2184 DisplayP3_DisplayP3_Enhance_Set) {
2185 verify().expectBestColorModeCallResultUsedToSetColorProfile(ui::ColorMode::DISPLAY_P3,
2186 ui::Dataspace::DISPLAY_P3,
2187 ui::RenderIntent::ENHANCE)
2188 .execute();
2189}
2190
Lloyd Pique17ca7422019-11-14 14:24:10 -08002191struct OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference
2192 : public OutputUpdateColorProfileTest {
2193 // Internally the implementation looks through the dataspaces of all the
2194 // visible layers. The topmost one that also has an actual dataspace
2195 // preference set is used to drive subsequent choices.
2196
2197 OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference() {
2198 mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced;
Lloyd Pique17ca7422019-11-14 14:24:10 -08002199
Lloyd Pique0a456232020-01-16 17:51:13 -08002200 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(3u));
Lloyd Pique17ca7422019-11-14 14:24:10 -08002201 EXPECT_CALL(mOutput, setColorProfile(_)).WillRepeatedly(Return());
2202 }
2203
2204 struct IfTopLayerDataspaceState
2205 : public CallOrderStateMachineHelper<TestType, IfTopLayerDataspaceState> {
2206 [[nodiscard]] auto ifTopLayerIs(ui::Dataspace dataspace) {
2207 getInstance()->mLayer3.mLayerFEState.dataspace = dataspace;
2208 return nextState<AndIfMiddleLayerDataspaceState>();
2209 }
2210 [[nodiscard]] auto ifTopLayerHasNoPreference() {
2211 return ifTopLayerIs(ui::Dataspace::UNKNOWN);
2212 }
2213 };
2214
2215 struct AndIfMiddleLayerDataspaceState
2216 : public CallOrderStateMachineHelper<TestType, AndIfMiddleLayerDataspaceState> {
2217 [[nodiscard]] auto andIfMiddleLayerIs(ui::Dataspace dataspace) {
2218 getInstance()->mLayer2.mLayerFEState.dataspace = dataspace;
2219 return nextState<AndIfBottomLayerDataspaceState>();
2220 }
2221 [[nodiscard]] auto andIfMiddleLayerHasNoPreference() {
2222 return andIfMiddleLayerIs(ui::Dataspace::UNKNOWN);
2223 }
2224 };
2225
2226 struct AndIfBottomLayerDataspaceState
2227 : public CallOrderStateMachineHelper<TestType, AndIfBottomLayerDataspaceState> {
2228 [[nodiscard]] auto andIfBottomLayerIs(ui::Dataspace dataspace) {
2229 getInstance()->mLayer1.mLayerFEState.dataspace = dataspace;
2230 return nextState<ThenExpectBestColorModeCallUsesState>();
2231 }
2232 [[nodiscard]] auto andIfBottomLayerHasNoPreference() {
2233 return andIfBottomLayerIs(ui::Dataspace::UNKNOWN);
2234 }
2235 };
2236
2237 struct ThenExpectBestColorModeCallUsesState
2238 : public CallOrderStateMachineHelper<TestType, ThenExpectBestColorModeCallUsesState> {
2239 [[nodiscard]] auto thenExpectBestColorModeCallUses(ui::Dataspace dataspace) {
2240 EXPECT_CALL(*getInstance()->mDisplayColorProfile,
2241 getBestColorMode(dataspace, _, _, _, _));
2242 return nextState<ExecuteState>();
2243 }
2244 };
2245
2246 // Call this member function to start using the mini-DSL defined above.
2247 [[nodiscard]] auto verify() { return IfTopLayerDataspaceState::make(this); }
2248};
2249
2250TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference,
2251 noStrongLayerPrefenceUses_V0_SRGB) {
2252 // If none of the layers indicate a preference, then V0_SRGB is the
2253 // preferred choice (subject to additional checks).
2254 verify().ifTopLayerHasNoPreference()
2255 .andIfMiddleLayerHasNoPreference()
2256 .andIfBottomLayerHasNoPreference()
2257 .thenExpectBestColorModeCallUses(ui::Dataspace::V0_SRGB)
2258 .execute();
2259}
2260
2261TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference,
2262 ifTopmostUses_DisplayP3_Then_DisplayP3_Chosen) {
2263 // If only the topmost layer has a preference, then that is what is chosen.
2264 verify().ifTopLayerIs(ui::Dataspace::DISPLAY_P3)
2265 .andIfMiddleLayerHasNoPreference()
2266 .andIfBottomLayerHasNoPreference()
2267 .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3)
2268 .execute();
2269}
2270
2271TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference,
2272 ifMiddleUses_DisplayP3_Then_DisplayP3_Chosen) {
2273 // If only the middle layer has a preference, that that is what is chosen.
2274 verify().ifTopLayerHasNoPreference()
2275 .andIfMiddleLayerIs(ui::Dataspace::DISPLAY_P3)
2276 .andIfBottomLayerHasNoPreference()
2277 .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3)
2278 .execute();
2279}
2280
2281TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference,
2282 ifBottomUses_DisplayP3_Then_DisplayP3_Chosen) {
2283 // If only the middle layer has a preference, that that is what is chosen.
2284 verify().ifTopLayerHasNoPreference()
2285 .andIfMiddleLayerHasNoPreference()
2286 .andIfBottomLayerIs(ui::Dataspace::DISPLAY_P3)
2287 .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3)
2288 .execute();
2289}
2290
2291TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference,
2292 ifTopUses_DisplayBT2020_AndBottomUses_DisplayP3_Then_DisplayBT2020_Chosen) {
2293 // If multiple layers have a preference, the topmost value is what is used.
2294 verify().ifTopLayerIs(ui::Dataspace::DISPLAY_BT2020)
2295 .andIfMiddleLayerHasNoPreference()
2296 .andIfBottomLayerIs(ui::Dataspace::DISPLAY_P3)
2297 .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_BT2020)
2298 .execute();
2299}
2300
2301TEST_F(OutputUpdateColorProfileTest_TopmostLayerPreferenceSetsOutputPreference,
2302 ifTopUses_DisplayP3_AndBottomUses_V0_SRGB_Then_DisplayP3_Chosen) {
2303 // If multiple layers have a preference, the topmost value is what is used.
2304 verify().ifTopLayerIs(ui::Dataspace::DISPLAY_P3)
2305 .andIfMiddleLayerHasNoPreference()
2306 .andIfBottomLayerIs(ui::Dataspace::DISPLAY_BT2020)
2307 .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3)
2308 .execute();
2309}
2310
2311struct OutputUpdateColorProfileTest_ForceOutputColorOverrides
2312 : public OutputUpdateColorProfileTest {
2313 // If CompositionRefreshArgs::forceOutputColorMode is set to some specific
2314 // values, it overrides the layer dataspace choice.
2315
2316 OutputUpdateColorProfileTest_ForceOutputColorOverrides() {
2317 mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced;
Lloyd Pique17ca7422019-11-14 14:24:10 -08002318
2319 mLayer1.mLayerFEState.dataspace = ui::Dataspace::DISPLAY_BT2020;
2320
Lloyd Pique0a456232020-01-16 17:51:13 -08002321 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(1u));
Lloyd Pique17ca7422019-11-14 14:24:10 -08002322 EXPECT_CALL(mOutput, setColorProfile(_)).WillRepeatedly(Return());
2323 }
2324
2325 struct IfForceOutputColorModeState
2326 : public CallOrderStateMachineHelper<TestType, IfForceOutputColorModeState> {
2327 [[nodiscard]] auto ifForceOutputColorMode(ui::ColorMode colorMode) {
2328 getInstance()->mRefreshArgs.forceOutputColorMode = colorMode;
2329 return nextState<ThenExpectBestColorModeCallUsesState>();
2330 }
2331 [[nodiscard]] auto ifNoOverride() { return ifForceOutputColorMode(ui::ColorMode::NATIVE); }
2332 };
2333
2334 struct ThenExpectBestColorModeCallUsesState
2335 : public CallOrderStateMachineHelper<TestType, ThenExpectBestColorModeCallUsesState> {
2336 [[nodiscard]] auto thenExpectBestColorModeCallUses(ui::Dataspace dataspace) {
2337 EXPECT_CALL(*getInstance()->mDisplayColorProfile,
2338 getBestColorMode(dataspace, _, _, _, _));
2339 return nextState<ExecuteState>();
2340 }
2341 };
2342
2343 // Call this member function to start using the mini-DSL defined above.
2344 [[nodiscard]] auto verify() { return IfForceOutputColorModeState::make(this); }
2345};
2346
2347TEST_F(OutputUpdateColorProfileTest_ForceOutputColorOverrides, NoOverride_DoesNotOverride) {
2348 // By default the layer state is used to set the preferred dataspace
2349 verify().ifNoOverride()
2350 .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_BT2020)
2351 .execute();
2352}
2353
2354TEST_F(OutputUpdateColorProfileTest_ForceOutputColorOverrides, SRGB_Override_USES_V0_SRGB) {
2355 // Setting ui::ColorMode::SRGB overrides it with ui::Dataspace::V0_SRGB
2356 verify().ifForceOutputColorMode(ui::ColorMode::SRGB)
2357 .thenExpectBestColorModeCallUses(ui::Dataspace::V0_SRGB)
2358 .execute();
2359}
2360
2361TEST_F(OutputUpdateColorProfileTest_ForceOutputColorOverrides, DisplayP3_Override_Uses_DisplayP3) {
2362 // Setting ui::ColorMode::DISPLAY_P3 overrides it with ui::Dataspace::DISPLAY_P3
2363 verify().ifForceOutputColorMode(ui::ColorMode::DISPLAY_P3)
2364 .thenExpectBestColorModeCallUses(ui::Dataspace::DISPLAY_P3)
2365 .execute();
2366}
2367
2368// HDR output requires all layers to be compatible with the chosen HDR
2369// dataspace, along with there being proper support.
2370struct OutputUpdateColorProfileTest_Hdr : public OutputUpdateColorProfileTest {
2371 OutputUpdateColorProfileTest_Hdr() {
2372 mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced;
Lloyd Pique0a456232020-01-16 17:51:13 -08002373 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2u));
Lloyd Pique17ca7422019-11-14 14:24:10 -08002374 EXPECT_CALL(mOutput, setColorProfile(_)).WillRepeatedly(Return());
2375 }
2376
2377 static constexpr ui::Dataspace kNonHdrDataspace = ui::Dataspace::DISPLAY_P3;
2378 static constexpr ui::Dataspace BT2020_PQ = ui::Dataspace::BT2020_PQ;
2379 static constexpr ui::Dataspace BT2020_HLG = ui::Dataspace::BT2020_HLG;
2380 static constexpr ui::Dataspace DISPLAY_P3 = ui::Dataspace::DISPLAY_P3;
2381
2382 struct IfTopLayerDataspaceState
2383 : public CallOrderStateMachineHelper<TestType, IfTopLayerDataspaceState> {
2384 [[nodiscard]] auto ifTopLayerIs(ui::Dataspace dataspace) {
2385 getInstance()->mLayer2.mLayerFEState.dataspace = dataspace;
2386 return nextState<AndTopLayerCompositionTypeState>();
2387 }
2388 [[nodiscard]] auto ifTopLayerIsNotHdr() { return ifTopLayerIs(kNonHdrDataspace); }
2389 };
2390
2391 struct AndTopLayerCompositionTypeState
2392 : public CallOrderStateMachineHelper<TestType, AndTopLayerCompositionTypeState> {
2393 [[nodiscard]] auto andTopLayerIsREComposed(bool renderEngineComposed) {
2394 getInstance()->mLayer2.mLayerFEState.forceClientComposition = renderEngineComposed;
2395 return nextState<AndIfBottomLayerDataspaceState>();
2396 }
2397 };
2398
2399 struct AndIfBottomLayerDataspaceState
2400 : public CallOrderStateMachineHelper<TestType, AndIfBottomLayerDataspaceState> {
2401 [[nodiscard]] auto andIfBottomLayerIs(ui::Dataspace dataspace) {
2402 getInstance()->mLayer1.mLayerFEState.dataspace = dataspace;
2403 return nextState<AndBottomLayerCompositionTypeState>();
2404 }
2405 [[nodiscard]] auto andIfBottomLayerIsNotHdr() {
2406 return andIfBottomLayerIs(kNonHdrDataspace);
2407 }
2408 };
2409
2410 struct AndBottomLayerCompositionTypeState
2411 : public CallOrderStateMachineHelper<TestType, AndBottomLayerCompositionTypeState> {
2412 [[nodiscard]] auto andBottomLayerIsREComposed(bool renderEngineComposed) {
2413 getInstance()->mLayer1.mLayerFEState.forceClientComposition = renderEngineComposed;
2414 return nextState<AndIfHasLegacySupportState>();
2415 }
2416 };
2417
2418 struct AndIfHasLegacySupportState
2419 : public CallOrderStateMachineHelper<TestType, AndIfHasLegacySupportState> {
2420 [[nodiscard]] auto andIfLegacySupportFor(ui::Dataspace dataspace, bool legacySupport) {
2421 EXPECT_CALL(*getInstance()->mDisplayColorProfile, hasLegacyHdrSupport(dataspace))
2422 .WillOnce(Return(legacySupport));
2423 return nextState<ThenExpectBestColorModeCallUsesState>();
2424 }
2425 };
2426
2427 struct ThenExpectBestColorModeCallUsesState
2428 : public CallOrderStateMachineHelper<TestType, ThenExpectBestColorModeCallUsesState> {
2429 [[nodiscard]] auto thenExpectBestColorModeCallUses(ui::Dataspace dataspace) {
2430 EXPECT_CALL(*getInstance()->mDisplayColorProfile,
2431 getBestColorMode(dataspace, _, _, _, _));
2432 return nextState<ExecuteState>();
2433 }
2434 };
2435
2436 // Call this member function to start using the mini-DSL defined above.
2437 [[nodiscard]] auto verify() { return IfTopLayerDataspaceState::make(this); }
2438};
2439
2440TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_PQ_HW_Uses_PQ) {
2441 // If all layers use BT2020_PQ, and there are no other special conditions,
2442 // BT2020_PQ is used.
2443 verify().ifTopLayerIs(BT2020_PQ)
2444 .andTopLayerIsREComposed(false)
2445 .andIfBottomLayerIs(BT2020_PQ)
2446 .andBottomLayerIsREComposed(false)
2447 .andIfLegacySupportFor(BT2020_PQ, false)
2448 .thenExpectBestColorModeCallUses(BT2020_PQ)
2449 .execute();
2450}
2451
2452TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_PQ_HW_IfPQHasLegacySupport_Uses_DisplayP3) {
2453 // BT2020_PQ is not used if there is only legacy support for it.
2454 verify().ifTopLayerIs(BT2020_PQ)
2455 .andTopLayerIsREComposed(false)
2456 .andIfBottomLayerIs(BT2020_PQ)
2457 .andBottomLayerIsREComposed(false)
2458 .andIfLegacySupportFor(BT2020_PQ, true)
2459 .thenExpectBestColorModeCallUses(DISPLAY_P3)
2460 .execute();
2461}
2462
2463TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_PQ_RE_Uses_PQ) {
2464 // BT2020_PQ is still used if the bottom layer is RenderEngine composed.
2465 verify().ifTopLayerIs(BT2020_PQ)
2466 .andTopLayerIsREComposed(false)
2467 .andIfBottomLayerIs(BT2020_PQ)
2468 .andBottomLayerIsREComposed(true)
2469 .andIfLegacySupportFor(BT2020_PQ, false)
2470 .thenExpectBestColorModeCallUses(BT2020_PQ)
2471 .execute();
2472}
2473
2474TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_RE_On_PQ_HW_Uses_DisplayP3) {
2475 // BT2020_PQ is not used if the top layer is RenderEngine composed.
2476 verify().ifTopLayerIs(BT2020_PQ)
2477 .andTopLayerIsREComposed(true)
2478 .andIfBottomLayerIs(BT2020_PQ)
2479 .andBottomLayerIsREComposed(false)
2480 .andIfLegacySupportFor(BT2020_PQ, false)
2481 .thenExpectBestColorModeCallUses(DISPLAY_P3)
2482 .execute();
2483}
2484
2485TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_HLG_HW_Uses_PQ) {
2486 // If there is mixed HLG/PQ use, and the topmost layer is PQ, then PQ is used if there
2487 // are no other special conditions.
2488 verify().ifTopLayerIs(BT2020_PQ)
2489 .andTopLayerIsREComposed(false)
2490 .andIfBottomLayerIs(BT2020_HLG)
2491 .andBottomLayerIsREComposed(false)
2492 .andIfLegacySupportFor(BT2020_PQ, false)
2493 .thenExpectBestColorModeCallUses(BT2020_PQ)
2494 .execute();
2495}
2496
2497TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_HLG_HW_IfPQHasLegacySupport_Uses_DisplayP3) {
2498 // BT2020_PQ is not used if there is only legacy support for it.
2499 verify().ifTopLayerIs(BT2020_PQ)
2500 .andTopLayerIsREComposed(false)
2501 .andIfBottomLayerIs(BT2020_HLG)
2502 .andBottomLayerIsREComposed(false)
2503 .andIfLegacySupportFor(BT2020_PQ, true)
2504 .thenExpectBestColorModeCallUses(DISPLAY_P3)
2505 .execute();
2506}
2507
2508TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_HLG_RE_Uses_PQ) {
2509 // BT2020_PQ is used if the bottom HLG layer is RenderEngine composed.
2510 verify().ifTopLayerIs(BT2020_PQ)
2511 .andTopLayerIsREComposed(false)
2512 .andIfBottomLayerIs(BT2020_HLG)
2513 .andBottomLayerIsREComposed(true)
2514 .andIfLegacySupportFor(BT2020_PQ, false)
2515 .thenExpectBestColorModeCallUses(BT2020_PQ)
2516 .execute();
2517}
2518
2519TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_RE_On_HLG_HW_Uses_DisplayP3) {
2520 // BT2020_PQ is not used if the top PQ layer is RenderEngine composed.
2521 verify().ifTopLayerIs(BT2020_PQ)
2522 .andTopLayerIsREComposed(true)
2523 .andIfBottomLayerIs(BT2020_HLG)
2524 .andBottomLayerIsREComposed(false)
2525 .andIfLegacySupportFor(BT2020_PQ, false)
2526 .thenExpectBestColorModeCallUses(DISPLAY_P3)
2527 .execute();
2528}
2529
2530TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_PQ_HW_Uses_PQ) {
2531 // If there is mixed HLG/PQ use, and the topmost layer is HLG, then PQ is
2532 // used if there are no other special conditions.
2533 verify().ifTopLayerIs(BT2020_HLG)
2534 .andTopLayerIsREComposed(false)
2535 .andIfBottomLayerIs(BT2020_PQ)
2536 .andBottomLayerIsREComposed(false)
2537 .andIfLegacySupportFor(BT2020_PQ, false)
2538 .thenExpectBestColorModeCallUses(BT2020_PQ)
2539 .execute();
2540}
2541
2542TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_PQ_HW_IfPQHasLegacySupport_Uses_DisplayP3) {
2543 // BT2020_PQ is not used if there is only legacy support for it.
2544 verify().ifTopLayerIs(BT2020_HLG)
2545 .andTopLayerIsREComposed(false)
2546 .andIfBottomLayerIs(BT2020_PQ)
2547 .andBottomLayerIsREComposed(false)
2548 .andIfLegacySupportFor(BT2020_PQ, true)
2549 .thenExpectBestColorModeCallUses(DISPLAY_P3)
2550 .execute();
2551}
2552
2553TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_PQ_RE_Uses_DisplayP3) {
2554 // BT2020_PQ is not used if the bottom PQ layer is RenderEngine composed.
2555 verify().ifTopLayerIs(BT2020_HLG)
2556 .andTopLayerIsREComposed(false)
2557 .andIfBottomLayerIs(BT2020_PQ)
2558 .andBottomLayerIsREComposed(true)
2559 .andIfLegacySupportFor(BT2020_PQ, false)
2560 .thenExpectBestColorModeCallUses(DISPLAY_P3)
2561 .execute();
2562}
2563
2564TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_RE_On_PQ_HW_Uses_PQ) {
2565 // BT2020_PQ is still used if the top HLG layer is RenderEngine composed.
2566 verify().ifTopLayerIs(BT2020_HLG)
2567 .andTopLayerIsREComposed(true)
2568 .andIfBottomLayerIs(BT2020_PQ)
2569 .andBottomLayerIsREComposed(false)
2570 .andIfLegacySupportFor(BT2020_PQ, false)
2571 .thenExpectBestColorModeCallUses(BT2020_PQ)
2572 .execute();
2573}
2574
2575TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_HLG_HW_Uses_HLG) {
2576 // If all layers use HLG then HLG is used if there are no other special
2577 // conditions.
2578 verify().ifTopLayerIs(BT2020_HLG)
2579 .andTopLayerIsREComposed(false)
2580 .andIfBottomLayerIs(BT2020_HLG)
2581 .andBottomLayerIsREComposed(false)
2582 .andIfLegacySupportFor(BT2020_HLG, false)
2583 .thenExpectBestColorModeCallUses(BT2020_HLG)
2584 .execute();
2585}
2586
2587TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_HLG_HW_IfPQHasLegacySupport_Uses_DisplayP3) {
2588 // BT2020_HLG is not used if there is legacy support for it.
2589 verify().ifTopLayerIs(BT2020_HLG)
2590 .andTopLayerIsREComposed(false)
2591 .andIfBottomLayerIs(BT2020_HLG)
2592 .andBottomLayerIsREComposed(false)
2593 .andIfLegacySupportFor(BT2020_HLG, true)
2594 .thenExpectBestColorModeCallUses(DISPLAY_P3)
2595 .execute();
2596}
2597
2598TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_HLG_RE_Uses_HLG) {
2599 // BT2020_HLG is used even if the bottom layer is client composed.
2600 verify().ifTopLayerIs(BT2020_HLG)
2601 .andTopLayerIsREComposed(false)
2602 .andIfBottomLayerIs(BT2020_HLG)
2603 .andBottomLayerIsREComposed(true)
2604 .andIfLegacySupportFor(BT2020_HLG, false)
2605 .thenExpectBestColorModeCallUses(BT2020_HLG)
2606 .execute();
2607}
2608
2609TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_RE_On_HLG_HW_Uses_HLG) {
2610 // BT2020_HLG is used even if the top layer is client composed.
2611 verify().ifTopLayerIs(BT2020_HLG)
2612 .andTopLayerIsREComposed(true)
2613 .andIfBottomLayerIs(BT2020_HLG)
2614 .andBottomLayerIsREComposed(false)
2615 .andIfLegacySupportFor(BT2020_HLG, false)
2616 .thenExpectBestColorModeCallUses(BT2020_HLG)
2617 .execute();
2618}
2619
2620TEST_F(OutputUpdateColorProfileTest_Hdr, PQ_HW_On_NonHdr_HW_Uses_PQ) {
2621 // Even if there are non-HDR layers present, BT2020_PQ can still be used.
2622 verify().ifTopLayerIs(BT2020_PQ)
2623 .andTopLayerIsREComposed(false)
2624 .andIfBottomLayerIsNotHdr()
2625 .andBottomLayerIsREComposed(false)
2626 .andIfLegacySupportFor(BT2020_PQ, false)
2627 .thenExpectBestColorModeCallUses(BT2020_PQ)
2628 .execute();
2629}
2630
2631TEST_F(OutputUpdateColorProfileTest_Hdr, HLG_HW_On_NonHdr_RE_Uses_HLG) {
2632 // If all layers use HLG then HLG is used if there are no other special
2633 // conditions.
2634 verify().ifTopLayerIs(BT2020_HLG)
2635 .andTopLayerIsREComposed(false)
2636 .andIfBottomLayerIsNotHdr()
2637 .andBottomLayerIsREComposed(true)
2638 .andIfLegacySupportFor(BT2020_HLG, false)
2639 .thenExpectBestColorModeCallUses(BT2020_HLG)
2640 .execute();
2641}
2642
2643struct OutputUpdateColorProfile_AffectsChosenRenderIntentTest
2644 : public OutputUpdateColorProfileTest {
2645 // The various values for CompositionRefreshArgs::outputColorSetting affect
2646 // the chosen renderIntent, along with whether the preferred dataspace is an
2647 // HDR dataspace or not.
2648
2649 OutputUpdateColorProfile_AffectsChosenRenderIntentTest() {
2650 mRefreshArgs.outputColorSetting = OutputColorSetting::kEnhanced;
Lloyd Pique17ca7422019-11-14 14:24:10 -08002651 mLayer1.mLayerFEState.dataspace = ui::Dataspace::BT2020_PQ;
Lloyd Pique0a456232020-01-16 17:51:13 -08002652 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(1u));
Lloyd Pique17ca7422019-11-14 14:24:10 -08002653 EXPECT_CALL(mOutput, setColorProfile(_)).WillRepeatedly(Return());
2654 EXPECT_CALL(*mDisplayColorProfile, hasLegacyHdrSupport(ui::Dataspace::BT2020_PQ))
2655 .WillRepeatedly(Return(false));
2656 }
2657
2658 // The tests here involve enough state and GMock setup that using a mini-DSL
2659 // makes the tests much more readable, and allows the test to focus more on
2660 // the intent than on some of the details.
2661
2662 static constexpr ui::Dataspace kNonHdrDataspace = ui::Dataspace::DISPLAY_P3;
2663 static constexpr ui::Dataspace kHdrDataspace = ui::Dataspace::BT2020_PQ;
2664
2665 struct IfDataspaceChosenState
2666 : public CallOrderStateMachineHelper<TestType, IfDataspaceChosenState> {
2667 [[nodiscard]] auto ifDataspaceChosenIs(ui::Dataspace dataspace) {
2668 getInstance()->mLayer1.mLayerFEState.dataspace = dataspace;
2669 return nextState<AndOutputColorSettingState>();
2670 }
2671 [[nodiscard]] auto ifDataspaceChosenIsNonHdr() {
2672 return ifDataspaceChosenIs(kNonHdrDataspace);
2673 }
2674 [[nodiscard]] auto ifDataspaceChosenIsHdr() { return ifDataspaceChosenIs(kHdrDataspace); }
2675 };
2676
2677 struct AndOutputColorSettingState
2678 : public CallOrderStateMachineHelper<TestType, AndOutputColorSettingState> {
2679 [[nodiscard]] auto andOutputColorSettingIs(OutputColorSetting setting) {
2680 getInstance()->mRefreshArgs.outputColorSetting = setting;
2681 return nextState<ThenExpectBestColorModeCallUsesState>();
2682 }
2683 };
2684
2685 struct ThenExpectBestColorModeCallUsesState
2686 : public CallOrderStateMachineHelper<TestType, ThenExpectBestColorModeCallUsesState> {
2687 [[nodiscard]] auto thenExpectBestColorModeCallUses(ui::RenderIntent intent) {
2688 EXPECT_CALL(*getInstance()->mDisplayColorProfile,
2689 getBestColorMode(getInstance()->mLayer1.mLayerFEState.dataspace, intent, _,
2690 _, _));
2691 return nextState<ExecuteState>();
2692 }
2693 };
2694
2695 // Tests call one of these two helper member functions to start using the
2696 // mini-DSL defined above.
2697 [[nodiscard]] auto verify() { return IfDataspaceChosenState::make(this); }
2698};
2699
2700TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest,
2701 Managed_NonHdr_Prefers_Colorimetric) {
2702 verify().ifDataspaceChosenIsNonHdr()
2703 .andOutputColorSettingIs(OutputColorSetting::kManaged)
2704 .thenExpectBestColorModeCallUses(ui::RenderIntent::COLORIMETRIC)
2705 .execute();
2706}
2707
2708TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest,
2709 Managed_Hdr_Prefers_ToneMapColorimetric) {
2710 verify().ifDataspaceChosenIsHdr()
2711 .andOutputColorSettingIs(OutputColorSetting::kManaged)
2712 .thenExpectBestColorModeCallUses(ui::RenderIntent::TONE_MAP_COLORIMETRIC)
2713 .execute();
2714}
2715
2716TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest, Enhanced_NonHdr_Prefers_Enhance) {
2717 verify().ifDataspaceChosenIsNonHdr()
2718 .andOutputColorSettingIs(OutputColorSetting::kEnhanced)
2719 .thenExpectBestColorModeCallUses(ui::RenderIntent::ENHANCE)
2720 .execute();
2721}
2722
2723TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest,
2724 Enhanced_Hdr_Prefers_ToneMapEnhance) {
2725 verify().ifDataspaceChosenIsHdr()
2726 .andOutputColorSettingIs(OutputColorSetting::kEnhanced)
2727 .thenExpectBestColorModeCallUses(ui::RenderIntent::TONE_MAP_ENHANCE)
2728 .execute();
2729}
2730
2731TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest, Vendor_NonHdr_Prefers_Vendor) {
2732 verify().ifDataspaceChosenIsNonHdr()
2733 .andOutputColorSettingIs(kVendorSpecifiedOutputColorSetting)
2734 .thenExpectBestColorModeCallUses(
2735 static_cast<ui::RenderIntent>(kVendorSpecifiedOutputColorSetting))
2736 .execute();
2737}
2738
2739TEST_F(OutputUpdateColorProfile_AffectsChosenRenderIntentTest, Vendor_Hdr_Prefers_Vendor) {
2740 verify().ifDataspaceChosenIsHdr()
2741 .andOutputColorSettingIs(kVendorSpecifiedOutputColorSetting)
2742 .thenExpectBestColorModeCallUses(
2743 static_cast<ui::RenderIntent>(kVendorSpecifiedOutputColorSetting))
2744 .execute();
2745}
Lloyd Piquefaa3f192019-11-14 14:05:09 -08002746
2747/*
2748 * Output::beginFrame()
2749 */
2750
Lloyd Piquee5965952019-11-18 16:16:32 -08002751struct OutputBeginFrameTest : public ::testing::Test {
2752 using TestType = OutputBeginFrameTest;
2753
2754 struct OutputPartialMock : public OutputPartialMockBase {
Lloyd Pique739afaf2019-11-21 16:40:05 -08002755 // Sets up the helper functions called by the function under test to use
2756 // mock implementations.
Dominik Laskowski8da6b0e2021-05-12 15:34:13 -07002757 MOCK_METHOD(Region, getDirtyRegion, (), (const));
Lloyd Piquee5965952019-11-18 16:16:32 -08002758 };
2759
2760 OutputBeginFrameTest() {
2761 mOutput.setDisplayColorProfileForTest(
2762 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
2763 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
2764 }
2765
2766 struct IfGetDirtyRegionExpectationState
2767 : public CallOrderStateMachineHelper<TestType, IfGetDirtyRegionExpectationState> {
2768 [[nodiscard]] auto ifGetDirtyRegionReturns(Region dirtyRegion) {
Dominik Laskowski8da6b0e2021-05-12 15:34:13 -07002769 EXPECT_CALL(getInstance()->mOutput, getDirtyRegion()).WillOnce(Return(dirtyRegion));
Lloyd Piquee5965952019-11-18 16:16:32 -08002770 return nextState<AndIfGetOutputLayerCountExpectationState>();
2771 }
2772 };
2773
2774 struct AndIfGetOutputLayerCountExpectationState
2775 : public CallOrderStateMachineHelper<TestType, AndIfGetOutputLayerCountExpectationState> {
2776 [[nodiscard]] auto andIfGetOutputLayerCountReturns(size_t layerCount) {
2777 EXPECT_CALL(getInstance()->mOutput, getOutputLayerCount()).WillOnce(Return(layerCount));
2778 return nextState<AndIfLastCompositionHadVisibleLayersState>();
2779 }
2780 };
2781
2782 struct AndIfLastCompositionHadVisibleLayersState
2783 : public CallOrderStateMachineHelper<TestType,
2784 AndIfLastCompositionHadVisibleLayersState> {
2785 [[nodiscard]] auto andIfLastCompositionHadVisibleLayersIs(bool hadOutputLayers) {
2786 getInstance()->mOutput.mState.lastCompositionHadVisibleLayers = hadOutputLayers;
2787 return nextState<ThenExpectRenderSurfaceBeginFrameCallState>();
2788 }
2789 };
2790
2791 struct ThenExpectRenderSurfaceBeginFrameCallState
2792 : public CallOrderStateMachineHelper<TestType,
2793 ThenExpectRenderSurfaceBeginFrameCallState> {
2794 [[nodiscard]] auto thenExpectRenderSurfaceBeginFrameCall(bool mustRecompose) {
2795 EXPECT_CALL(*getInstance()->mRenderSurface, beginFrame(mustRecompose));
2796 return nextState<ExecuteState>();
2797 }
2798 };
2799
2800 struct ExecuteState : public CallOrderStateMachineHelper<TestType, ExecuteState> {
2801 [[nodiscard]] auto execute() {
2802 getInstance()->mOutput.beginFrame();
2803 return nextState<CheckPostconditionHadVisibleLayersState>();
2804 }
2805 };
2806
2807 struct CheckPostconditionHadVisibleLayersState
2808 : public CallOrderStateMachineHelper<TestType, CheckPostconditionHadVisibleLayersState> {
2809 void checkPostconditionHadVisibleLayers(bool expected) {
2810 EXPECT_EQ(expected, getInstance()->mOutput.mState.lastCompositionHadVisibleLayers);
2811 }
2812 };
2813
2814 // Tests call one of these two helper member functions to start using the
2815 // mini-DSL defined above.
2816 [[nodiscard]] auto verify() { return IfGetDirtyRegionExpectationState::make(this); }
2817
2818 static const Region kEmptyRegion;
2819 static const Region kNotEmptyRegion;
2820
2821 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
2822 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
2823 StrictMock<OutputPartialMock> mOutput;
2824};
2825
2826const Region OutputBeginFrameTest::kEmptyRegion{Rect{0, 0, 0, 0}};
2827const Region OutputBeginFrameTest::kNotEmptyRegion{Rect{0, 0, 1, 1}};
2828
2829TEST_F(OutputBeginFrameTest, hasDirtyHasLayersHadLayersLastFrame) {
2830 verify().ifGetDirtyRegionReturns(kNotEmptyRegion)
2831 .andIfGetOutputLayerCountReturns(1u)
2832 .andIfLastCompositionHadVisibleLayersIs(true)
2833 .thenExpectRenderSurfaceBeginFrameCall(true)
2834 .execute()
2835 .checkPostconditionHadVisibleLayers(true);
2836}
2837
2838TEST_F(OutputBeginFrameTest, hasDirtyNotHasLayersHadLayersLastFrame) {
2839 verify().ifGetDirtyRegionReturns(kNotEmptyRegion)
2840 .andIfGetOutputLayerCountReturns(0u)
2841 .andIfLastCompositionHadVisibleLayersIs(true)
2842 .thenExpectRenderSurfaceBeginFrameCall(true)
2843 .execute()
2844 .checkPostconditionHadVisibleLayers(false);
2845}
2846
2847TEST_F(OutputBeginFrameTest, hasDirtyHasLayersNotHadLayersLastFrame) {
2848 verify().ifGetDirtyRegionReturns(kNotEmptyRegion)
2849 .andIfGetOutputLayerCountReturns(1u)
2850 .andIfLastCompositionHadVisibleLayersIs(false)
2851 .thenExpectRenderSurfaceBeginFrameCall(true)
2852 .execute()
2853 .checkPostconditionHadVisibleLayers(true);
2854}
2855
2856TEST_F(OutputBeginFrameTest, hasDirtyNotHasLayersNotHadLayersLastFrame) {
2857 verify().ifGetDirtyRegionReturns(kNotEmptyRegion)
2858 .andIfGetOutputLayerCountReturns(0u)
2859 .andIfLastCompositionHadVisibleLayersIs(false)
2860 .thenExpectRenderSurfaceBeginFrameCall(false)
2861 .execute()
2862 .checkPostconditionHadVisibleLayers(false);
2863}
2864
2865TEST_F(OutputBeginFrameTest, notHasDirtyHasLayersHadLayersLastFrame) {
2866 verify().ifGetDirtyRegionReturns(kEmptyRegion)
2867 .andIfGetOutputLayerCountReturns(1u)
2868 .andIfLastCompositionHadVisibleLayersIs(true)
2869 .thenExpectRenderSurfaceBeginFrameCall(false)
2870 .execute()
2871 .checkPostconditionHadVisibleLayers(true);
2872}
2873
2874TEST_F(OutputBeginFrameTest, notHasDirtyNotHasLayersHadLayersLastFrame) {
2875 verify().ifGetDirtyRegionReturns(kEmptyRegion)
2876 .andIfGetOutputLayerCountReturns(0u)
2877 .andIfLastCompositionHadVisibleLayersIs(true)
2878 .thenExpectRenderSurfaceBeginFrameCall(false)
2879 .execute()
2880 .checkPostconditionHadVisibleLayers(true);
2881}
2882
2883TEST_F(OutputBeginFrameTest, notHasDirtyHasLayersNotHadLayersLastFrame) {
2884 verify().ifGetDirtyRegionReturns(kEmptyRegion)
2885 .andIfGetOutputLayerCountReturns(1u)
2886 .andIfLastCompositionHadVisibleLayersIs(false)
2887 .thenExpectRenderSurfaceBeginFrameCall(false)
2888 .execute()
2889 .checkPostconditionHadVisibleLayers(false);
2890}
2891
2892TEST_F(OutputBeginFrameTest, notHasDirtyNotHasLayersNotHadLayersLastFrame) {
2893 verify().ifGetDirtyRegionReturns(kEmptyRegion)
2894 .andIfGetOutputLayerCountReturns(0u)
2895 .andIfLastCompositionHadVisibleLayersIs(false)
2896 .thenExpectRenderSurfaceBeginFrameCall(false)
2897 .execute()
2898 .checkPostconditionHadVisibleLayers(false);
2899}
2900
Lloyd Piquefaa3f192019-11-14 14:05:09 -08002901/*
2902 * Output::devOptRepaintFlash()
2903 */
2904
Lloyd Piquedb462d82019-11-19 17:58:46 -08002905struct OutputDevOptRepaintFlashTest : public testing::Test {
2906 struct OutputPartialMock : public OutputPartialMockBase {
Lloyd Pique739afaf2019-11-21 16:40:05 -08002907 // Sets up the helper functions called by the function under test to use
2908 // mock implementations.
Dominik Laskowski8da6b0e2021-05-12 15:34:13 -07002909 MOCK_METHOD(Region, getDirtyRegion, (), (const));
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00002910 MOCK_METHOD3(composeSurfaces,
2911 std::optional<base::unique_fd>(const Region&,
2912 std::shared_ptr<renderengine::ExternalTexture>,
2913 base::unique_fd&));
Leon Scroggins IIIc1623d12023-11-06 15:31:05 -05002914 MOCK_METHOD0(presentFrameAndReleaseLayers, void());
Lloyd Piquedb462d82019-11-19 17:58:46 -08002915 MOCK_METHOD0(prepareFrame, void());
Vishnu Naira3140382022-02-24 14:07:11 -08002916 MOCK_METHOD0(updateProtectedContentState, void());
2917 MOCK_METHOD2(dequeueRenderBuffer,
2918 bool(base::unique_fd*, std::shared_ptr<renderengine::ExternalTexture>*));
Lloyd Piquedb462d82019-11-19 17:58:46 -08002919 };
2920
2921 OutputDevOptRepaintFlashTest() {
2922 mOutput.setDisplayColorProfileForTest(
2923 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
2924 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
2925 }
2926
2927 static const Region kEmptyRegion;
2928 static const Region kNotEmptyRegion;
2929
2930 StrictMock<OutputPartialMock> mOutput;
2931 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
2932 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
2933 CompositionRefreshArgs mRefreshArgs;
2934};
2935
2936const Region OutputDevOptRepaintFlashTest::kEmptyRegion{Rect{0, 0, 0, 0}};
2937const Region OutputDevOptRepaintFlashTest::kNotEmptyRegion{Rect{0, 0, 1, 1}};
2938
2939TEST_F(OutputDevOptRepaintFlashTest, doesNothingIfFlashDelayNotSet) {
2940 mRefreshArgs.devOptFlashDirtyRegionsDelay = {};
Lloyd Piquedb462d82019-11-19 17:58:46 -08002941 mOutput.mState.isEnabled = true;
2942
2943 mOutput.devOptRepaintFlash(mRefreshArgs);
2944}
2945
2946TEST_F(OutputDevOptRepaintFlashTest, postsAndPreparesANewFrameIfNotEnabled) {
2947 mRefreshArgs.devOptFlashDirtyRegionsDelay = std::chrono::microseconds(1);
Lloyd Piquedb462d82019-11-19 17:58:46 -08002948 mOutput.mState.isEnabled = false;
2949
2950 InSequence seq;
Leon Scroggins IIIc1623d12023-11-06 15:31:05 -05002951 EXPECT_CALL(mOutput, presentFrameAndReleaseLayers());
Lloyd Piquedb462d82019-11-19 17:58:46 -08002952 EXPECT_CALL(mOutput, prepareFrame());
2953
2954 mOutput.devOptRepaintFlash(mRefreshArgs);
2955}
2956
Dominik Laskowski8da6b0e2021-05-12 15:34:13 -07002957TEST_F(OutputDevOptRepaintFlashTest, postsAndPreparesANewFrameIfEnabled) {
Lloyd Piquedb462d82019-11-19 17:58:46 -08002958 mRefreshArgs.devOptFlashDirtyRegionsDelay = std::chrono::microseconds(1);
Lloyd Piquedb462d82019-11-19 17:58:46 -08002959 mOutput.mState.isEnabled = true;
2960
2961 InSequence seq;
Dominik Laskowski8da6b0e2021-05-12 15:34:13 -07002962 EXPECT_CALL(mOutput, getDirtyRegion()).WillOnce(Return(kEmptyRegion));
Leon Scroggins IIIc1623d12023-11-06 15:31:05 -05002963 EXPECT_CALL(mOutput, presentFrameAndReleaseLayers());
Lloyd Piquedb462d82019-11-19 17:58:46 -08002964 EXPECT_CALL(mOutput, prepareFrame());
2965
2966 mOutput.devOptRepaintFlash(mRefreshArgs);
2967}
2968
2969TEST_F(OutputDevOptRepaintFlashTest, alsoComposesSurfacesAndQueuesABufferIfDirty) {
2970 mRefreshArgs.devOptFlashDirtyRegionsDelay = std::chrono::microseconds(1);
Lloyd Piquedb462d82019-11-19 17:58:46 -08002971 mOutput.mState.isEnabled = true;
2972
2973 InSequence seq;
Dominik Laskowski8da6b0e2021-05-12 15:34:13 -07002974 EXPECT_CALL(mOutput, getDirtyRegion()).WillOnce(Return(kNotEmptyRegion));
Vishnu Naira3140382022-02-24 14:07:11 -08002975 EXPECT_CALL(mOutput, updateProtectedContentState());
2976 EXPECT_CALL(mOutput, dequeueRenderBuffer(_, _));
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00002977 EXPECT_CALL(mOutput, composeSurfaces(RegionEq(kNotEmptyRegion), _, _));
Alec Mourif97df4d2023-09-06 02:10:05 +00002978 EXPECT_CALL(*mRenderSurface, queueBuffer(_, 1.f));
Leon Scroggins IIIc1623d12023-11-06 15:31:05 -05002979 EXPECT_CALL(mOutput, presentFrameAndReleaseLayers());
Lloyd Piquedb462d82019-11-19 17:58:46 -08002980 EXPECT_CALL(mOutput, prepareFrame());
2981
2982 mOutput.devOptRepaintFlash(mRefreshArgs);
2983}
2984
Lloyd Piquefaa3f192019-11-14 14:05:09 -08002985/*
2986 * Output::finishFrame()
2987 */
2988
Lloyd Pique03561a62019-11-19 18:34:52 -08002989struct OutputFinishFrameTest : public testing::Test {
2990 struct OutputPartialMock : public OutputPartialMockBase {
Lloyd Pique739afaf2019-11-21 16:40:05 -08002991 // Sets up the helper functions called by the function under test to use
2992 // mock implementations.
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00002993 MOCK_METHOD3(composeSurfaces,
2994 std::optional<base::unique_fd>(const Region&,
2995 std::shared_ptr<renderengine::ExternalTexture>,
2996 base::unique_fd&));
Leon Scroggins IIIc1623d12023-11-06 15:31:05 -05002997 MOCK_METHOD0(presentFrameAndReleaseLayers, void());
Vishnu Naira3140382022-02-24 14:07:11 -08002998 MOCK_METHOD0(updateProtectedContentState, void());
2999 MOCK_METHOD2(dequeueRenderBuffer,
3000 bool(base::unique_fd*, std::shared_ptr<renderengine::ExternalTexture>*));
Xiang Wangaab31162024-03-12 19:48:08 -07003001 MOCK_METHOD(void, setHintSessionGpuFence, (std::unique_ptr<FenceTime> && gpuFence),
3002 (override));
3003 MOCK_METHOD(bool, isPowerHintSessionEnabled, (), (override));
Lloyd Pique03561a62019-11-19 18:34:52 -08003004 };
3005
3006 OutputFinishFrameTest() {
3007 mOutput.setDisplayColorProfileForTest(
3008 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
3009 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
Alec Mourif97df4d2023-09-06 02:10:05 +00003010 EXPECT_CALL(mOutput, getCompositionEngine()).WillRepeatedly(ReturnRef(mCompositionEngine));
3011 EXPECT_CALL(mCompositionEngine, getRenderEngine()).WillRepeatedly(ReturnRef(mRenderEngine));
Xiang Wangaab31162024-03-12 19:48:08 -07003012 EXPECT_CALL(mOutput, isPowerHintSessionEnabled()).WillRepeatedly(Return(true));
3013 SET_FLAG_FOR_TEST(flags::adpf_gpu_sf, false);
Lloyd Pique03561a62019-11-19 18:34:52 -08003014 }
3015
3016 StrictMock<OutputPartialMock> mOutput;
3017 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
3018 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
Alec Mourif97df4d2023-09-06 02:10:05 +00003019 StrictMock<mock::CompositionEngine> mCompositionEngine;
3020 StrictMock<renderengine::mock::RenderEngine> mRenderEngine;
Lloyd Pique03561a62019-11-19 18:34:52 -08003021};
3022
3023TEST_F(OutputFinishFrameTest, ifNotEnabledDoesNothing) {
3024 mOutput.mState.isEnabled = false;
3025
Vishnu Naira3140382022-02-24 14:07:11 -08003026 impl::GpuCompositionResult result;
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00003027 mOutput.finishFrame(std::move(result));
Lloyd Pique03561a62019-11-19 18:34:52 -08003028}
3029
3030TEST_F(OutputFinishFrameTest, takesEarlyOutifComposeSurfacesReturnsNoFence) {
3031 mOutput.mState.isEnabled = true;
Vishnu Naira3140382022-02-24 14:07:11 -08003032 EXPECT_CALL(mOutput, updateProtectedContentState());
3033 EXPECT_CALL(mOutput, dequeueRenderBuffer(_, _)).WillOnce(Return(true));
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00003034 EXPECT_CALL(mOutput, composeSurfaces(RegionEq(Region::INVALID_REGION), _, _));
Lloyd Pique03561a62019-11-19 18:34:52 -08003035
Vishnu Naira3140382022-02-24 14:07:11 -08003036 impl::GpuCompositionResult result;
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00003037 mOutput.finishFrame(std::move(result));
Lloyd Pique03561a62019-11-19 18:34:52 -08003038}
3039
3040TEST_F(OutputFinishFrameTest, queuesBufferIfComposeSurfacesReturnsAFence) {
3041 mOutput.mState.isEnabled = true;
3042
3043 InSequence seq;
Vishnu Naira3140382022-02-24 14:07:11 -08003044 EXPECT_CALL(mOutput, updateProtectedContentState());
3045 EXPECT_CALL(mOutput, dequeueRenderBuffer(_, _)).WillOnce(Return(true));
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00003046 EXPECT_CALL(mOutput, composeSurfaces(RegionEq(Region::INVALID_REGION), _, _))
Lloyd Pique03561a62019-11-19 18:34:52 -08003047 .WillOnce(Return(ByMove(base::unique_fd())));
Xiang Wangaab31162024-03-12 19:48:08 -07003048 EXPECT_CALL(mOutput, setHintSessionGpuFence(_));
3049 EXPECT_CALL(*mRenderSurface, queueBuffer(_, 1.f));
3050
3051 impl::GpuCompositionResult result;
3052 mOutput.finishFrame(std::move(result));
3053}
3054
3055TEST_F(OutputFinishFrameTest, queuesBufferIfComposeSurfacesReturnsAFenceWithAdpfGpuOn) {
3056 SET_FLAG_FOR_TEST(flags::adpf_gpu_sf, true);
3057 mOutput.mState.isEnabled = true;
3058
3059 InSequence seq;
3060 EXPECT_CALL(mOutput, updateProtectedContentState());
3061 EXPECT_CALL(mOutput, dequeueRenderBuffer(_, _)).WillOnce(Return(true));
3062 EXPECT_CALL(mOutput, composeSurfaces(RegionEq(Region::INVALID_REGION), _, _))
3063 .WillOnce(Return(ByMove(base::unique_fd())));
3064 EXPECT_CALL(mOutput, setHintSessionGpuFence(_)).Times(0);
Alec Mourif97df4d2023-09-06 02:10:05 +00003065 EXPECT_CALL(*mRenderSurface, queueBuffer(_, 1.f));
3066
3067 impl::GpuCompositionResult result;
3068 mOutput.finishFrame(std::move(result));
3069}
3070
3071TEST_F(OutputFinishFrameTest, queuesBufferWithHdrSdrRatio) {
3072 SET_FLAG_FOR_TEST(flags::fp16_client_target, true);
3073 mOutput.mState.isEnabled = true;
3074
3075 InSequence seq;
3076 auto texture = std::make_shared<
3077 renderengine::impl::
3078 ExternalTexture>(sp<GraphicBuffer>::make(1u, 1u, PIXEL_FORMAT_RGBA_FP16,
3079 GRALLOC_USAGE_SW_WRITE_OFTEN |
3080 GRALLOC_USAGE_SW_READ_OFTEN),
3081 mRenderEngine,
3082 renderengine::impl::ExternalTexture::Usage::READABLE |
3083 renderengine::impl::ExternalTexture::Usage::WRITEABLE);
3084 mOutput.mState.displayBrightnessNits = 400.f;
3085 mOutput.mState.sdrWhitePointNits = 200.f;
3086 mOutput.mState.dataspace = ui::Dataspace::V0_SCRGB;
3087 EXPECT_CALL(mOutput, updateProtectedContentState());
3088 EXPECT_CALL(mOutput, dequeueRenderBuffer(_, _))
3089 .WillOnce(DoAll(SetArgPointee<1>(texture), Return(true)));
3090 EXPECT_CALL(mOutput, composeSurfaces(RegionEq(Region::INVALID_REGION), _, _))
3091 .WillOnce(Return(ByMove(base::unique_fd())));
Xiang Wangaab31162024-03-12 19:48:08 -07003092 EXPECT_CALL(mOutput, setHintSessionGpuFence(_));
Alec Mourif97df4d2023-09-06 02:10:05 +00003093 EXPECT_CALL(*mRenderSurface, queueBuffer(_, 2.f));
Lloyd Pique03561a62019-11-19 18:34:52 -08003094
Vishnu Naira3140382022-02-24 14:07:11 -08003095 impl::GpuCompositionResult result;
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00003096 mOutput.finishFrame(std::move(result));
Vishnu Naira3140382022-02-24 14:07:11 -08003097}
3098
3099TEST_F(OutputFinishFrameTest, predictionSucceeded) {
3100 mOutput.mState.isEnabled = true;
Vishnu Nair9cf89262022-02-26 09:17:49 -08003101 mOutput.mState.strategyPrediction = CompositionStrategyPredictionState::SUCCESS;
Vishnu Naira3140382022-02-24 14:07:11 -08003102 InSequence seq;
Xiang Wangaab31162024-03-12 19:48:08 -07003103 EXPECT_CALL(mOutput, setHintSessionGpuFence(_));
Alec Mourif97df4d2023-09-06 02:10:05 +00003104 EXPECT_CALL(*mRenderSurface, queueBuffer(_, 1.f));
Vishnu Naira3140382022-02-24 14:07:11 -08003105
3106 impl::GpuCompositionResult result;
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00003107 mOutput.finishFrame(std::move(result));
Vishnu Naira3140382022-02-24 14:07:11 -08003108}
3109
3110TEST_F(OutputFinishFrameTest, predictionFailedAndBufferIsReused) {
3111 mOutput.mState.isEnabled = true;
Vishnu Nair9cf89262022-02-26 09:17:49 -08003112 mOutput.mState.strategyPrediction = CompositionStrategyPredictionState::FAIL;
Vishnu Naira3140382022-02-24 14:07:11 -08003113
3114 InSequence seq;
3115
3116 impl::GpuCompositionResult result;
Vishnu Naira3140382022-02-24 14:07:11 -08003117 result.buffer =
3118 std::make_shared<renderengine::mock::FakeExternalTexture>(1, 1,
3119 HAL_PIXEL_FORMAT_RGBA_8888, 1,
3120 2);
3121
3122 EXPECT_CALL(mOutput,
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00003123 composeSurfaces(RegionEq(Region::INVALID_REGION), result.buffer,
Vishnu Naira3140382022-02-24 14:07:11 -08003124 Eq(ByRef(result.fence))))
3125 .WillOnce(Return(ByMove(base::unique_fd())));
Xiang Wangaab31162024-03-12 19:48:08 -07003126 EXPECT_CALL(mOutput, setHintSessionGpuFence(_));
Alec Mourif97df4d2023-09-06 02:10:05 +00003127 EXPECT_CALL(*mRenderSurface, queueBuffer(_, 1.f));
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00003128 mOutput.finishFrame(std::move(result));
Lloyd Pique03561a62019-11-19 18:34:52 -08003129}
Lloyd Piquefaa3f192019-11-14 14:05:09 -08003130
3131/*
Leon Scroggins IIIc1623d12023-11-06 15:31:05 -05003132 * Output::presentFrameAndReleaseLayers()
Lloyd Piquefaa3f192019-11-14 14:05:09 -08003133 */
3134
Lloyd Pique07178e32019-11-19 19:15:26 -08003135struct OutputPostFramebufferTest : public testing::Test {
3136 struct OutputPartialMock : public OutputPartialMockBase {
Lloyd Pique739afaf2019-11-21 16:40:05 -08003137 // Sets up the helper functions called by the function under test to use
3138 // mock implementations.
Leon Scroggins IIIc1623d12023-11-06 15:31:05 -05003139 MOCK_METHOD0(presentFrame, compositionengine::Output::FrameFences());
Lloyd Pique07178e32019-11-19 19:15:26 -08003140 };
3141
3142 struct Layer {
3143 Layer() {
Ady Abrahameca9d752021-03-03 12:20:00 -08003144 EXPECT_CALL(outputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*layerFE));
Lloyd Pique07178e32019-11-19 19:15:26 -08003145 EXPECT_CALL(outputLayer, getHwcLayer()).WillRepeatedly(Return(&hwc2Layer));
3146 }
3147
3148 StrictMock<mock::OutputLayer> outputLayer;
Ady Abrahameca9d752021-03-03 12:20:00 -08003149 sp<StrictMock<mock::LayerFE>> layerFE = sp<StrictMock<mock::LayerFE>>::make();
Lloyd Pique07178e32019-11-19 19:15:26 -08003150 StrictMock<HWC2::mock::Layer> hwc2Layer;
3151 };
3152
3153 OutputPostFramebufferTest() {
3154 mOutput.setDisplayColorProfileForTest(
3155 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
3156 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
3157
3158 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(3u));
3159 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u))
3160 .WillRepeatedly(Return(&mLayer1.outputLayer));
3161 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1u))
3162 .WillRepeatedly(Return(&mLayer2.outputLayer));
3163 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(2u))
3164 .WillRepeatedly(Return(&mLayer3.outputLayer));
3165 }
3166
3167 StrictMock<OutputPartialMock> mOutput;
3168 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
3169 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
3170
3171 Layer mLayer1;
3172 Layer mLayer2;
3173 Layer mLayer3;
3174};
3175
3176TEST_F(OutputPostFramebufferTest, ifNotEnabledDoesNothing) {
3177 mOutput.mState.isEnabled = false;
3178
Leon Scroggins IIIc1623d12023-11-06 15:31:05 -05003179 mOutput.presentFrameAndReleaseLayers();
Lloyd Pique07178e32019-11-19 19:15:26 -08003180}
3181
3182TEST_F(OutputPostFramebufferTest, ifEnabledMustFlipThenPresentThenSendPresentCompleted) {
3183 mOutput.mState.isEnabled = true;
3184
3185 compositionengine::Output::FrameFences frameFences;
3186
3187 // This should happen even if there are no output layers.
3188 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
3189
3190 // For this test in particular we want to make sure the call expectations
3191 // setup below are satisfied in the specific order.
3192 InSequence seq;
3193
Leon Scroggins IIIc1623d12023-11-06 15:31:05 -05003194 EXPECT_CALL(mOutput, presentFrame()).WillOnce(Return(frameFences));
Lloyd Pique07178e32019-11-19 19:15:26 -08003195 EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted());
3196
Leon Scroggins IIIc1623d12023-11-06 15:31:05 -05003197 mOutput.presentFrameAndReleaseLayers();
Lloyd Pique07178e32019-11-19 19:15:26 -08003198}
3199
3200TEST_F(OutputPostFramebufferTest, releaseFencesAreSentToLayerFE) {
Melody Hsu793f8362024-01-08 20:00:35 +00003201 SET_FLAG_FOR_TEST(com::android::graphics::surfaceflinger::flags::ce_fence_promise, false);
3202 ASSERT_FALSE(FlagManager::getInstance().ce_fence_promise());
Lloyd Pique07178e32019-11-19 19:15:26 -08003203 // Simulate getting release fences from each layer, and ensure they are passed to the
3204 // front-end layer interface for each layer correctly.
3205
3206 mOutput.mState.isEnabled = true;
3207
3208 // Create three unique fence instances
Dominik Laskowskibb448ce2022-05-07 15:52:55 -07003209 sp<Fence> layer1Fence = sp<Fence>::make();
3210 sp<Fence> layer2Fence = sp<Fence>::make();
3211 sp<Fence> layer3Fence = sp<Fence>::make();
Lloyd Pique07178e32019-11-19 19:15:26 -08003212
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08003213 Output::FrameFences frameFences;
Lloyd Pique07178e32019-11-19 19:15:26 -08003214 frameFences.layerFences.emplace(&mLayer1.hwc2Layer, layer1Fence);
3215 frameFences.layerFences.emplace(&mLayer2.hwc2Layer, layer2Fence);
3216 frameFences.layerFences.emplace(&mLayer3.hwc2Layer, layer3Fence);
3217
Leon Scroggins IIIc1623d12023-11-06 15:31:05 -05003218 EXPECT_CALL(mOutput, presentFrame()).WillOnce(Return(frameFences));
Lloyd Pique07178e32019-11-19 19:15:26 -08003219 EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted());
3220
3221 // Compare the pointers values of each fence to make sure the correct ones
3222 // are passed. This happens to work with the current implementation, but
3223 // would not survive certain calls like Fence::merge() which would return a
3224 // new instance.
Vishnu Nair7ee4f462023-04-19 09:54:09 -07003225 EXPECT_CALL(*mLayer1.layerFE, onLayerDisplayed(_, _))
3226 .WillOnce([&layer1Fence](ftl::SharedFuture<FenceResult> futureFenceResult,
3227 ui::LayerStack) {
Dominik Laskowskibb448ce2022-05-07 15:52:55 -07003228 EXPECT_EQ(FenceResult(layer1Fence), futureFenceResult.get());
Sally Qi59a9f502021-10-12 18:53:23 +00003229 });
Vishnu Nair7ee4f462023-04-19 09:54:09 -07003230 EXPECT_CALL(*mLayer2.layerFE, onLayerDisplayed(_, _))
3231 .WillOnce([&layer2Fence](ftl::SharedFuture<FenceResult> futureFenceResult,
3232 ui::LayerStack) {
Dominik Laskowskibb448ce2022-05-07 15:52:55 -07003233 EXPECT_EQ(FenceResult(layer2Fence), futureFenceResult.get());
Sally Qi59a9f502021-10-12 18:53:23 +00003234 });
Vishnu Nair7ee4f462023-04-19 09:54:09 -07003235 EXPECT_CALL(*mLayer3.layerFE, onLayerDisplayed(_, _))
3236 .WillOnce([&layer3Fence](ftl::SharedFuture<FenceResult> futureFenceResult,
3237 ui::LayerStack) {
Dominik Laskowskibb448ce2022-05-07 15:52:55 -07003238 EXPECT_EQ(FenceResult(layer3Fence), futureFenceResult.get());
Sally Qi59a9f502021-10-12 18:53:23 +00003239 });
Lloyd Pique07178e32019-11-19 19:15:26 -08003240
Leon Scroggins IIIc1623d12023-11-06 15:31:05 -05003241 mOutput.presentFrameAndReleaseLayers();
Lloyd Pique07178e32019-11-19 19:15:26 -08003242}
3243
Melody Hsu793f8362024-01-08 20:00:35 +00003244TEST_F(OutputPostFramebufferTest, releaseFencesAreSetInLayerFE) {
3245 SET_FLAG_FOR_TEST(com::android::graphics::surfaceflinger::flags::ce_fence_promise, true);
3246 ASSERT_TRUE(FlagManager::getInstance().ce_fence_promise());
3247 // Simulate getting release fences from each layer, and ensure they are passed to the
3248 // front-end layer interface for each layer correctly.
3249
3250 mOutput.mState.isEnabled = true;
3251
3252 // Create three unique fence instances
3253 sp<Fence> layer1Fence = sp<Fence>::make();
3254 sp<Fence> layer2Fence = sp<Fence>::make();
3255 sp<Fence> layer3Fence = sp<Fence>::make();
3256
3257 Output::FrameFences frameFences;
3258 frameFences.layerFences.emplace(&mLayer1.hwc2Layer, layer1Fence);
3259 frameFences.layerFences.emplace(&mLayer2.hwc2Layer, layer2Fence);
3260 frameFences.layerFences.emplace(&mLayer3.hwc2Layer, layer3Fence);
3261
3262 EXPECT_CALL(mOutput, presentFrame()).WillOnce(Return(frameFences));
3263 EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted());
3264
3265 // Compare the pointers values of each fence to make sure the correct ones
3266 // are passed. This happens to work with the current implementation, but
3267 // would not survive certain calls like Fence::merge() which would return a
3268 // new instance.
3269 EXPECT_CALL(*mLayer1.layerFE, setReleaseFence(_))
3270 .WillOnce([&layer1Fence](FenceResult releaseFence) {
3271 EXPECT_EQ(FenceResult(layer1Fence), releaseFence);
3272 });
3273 EXPECT_CALL(*mLayer2.layerFE, setReleaseFence(_))
3274 .WillOnce([&layer2Fence](FenceResult releaseFence) {
3275 EXPECT_EQ(FenceResult(layer2Fence), releaseFence);
3276 });
3277 EXPECT_CALL(*mLayer3.layerFE, setReleaseFence(_))
3278 .WillOnce([&layer3Fence](FenceResult releaseFence) {
3279 EXPECT_EQ(FenceResult(layer3Fence), releaseFence);
3280 });
3281
3282 mOutput.presentFrameAndReleaseLayers();
3283}
3284
Lloyd Pique07178e32019-11-19 19:15:26 -08003285TEST_F(OutputPostFramebufferTest, releaseFencesIncludeClientTargetAcquireFence) {
Melody Hsu793f8362024-01-08 20:00:35 +00003286 SET_FLAG_FOR_TEST(com::android::graphics::surfaceflinger::flags::ce_fence_promise, false);
3287 ASSERT_FALSE(FlagManager::getInstance().ce_fence_promise());
3288
Lloyd Pique07178e32019-11-19 19:15:26 -08003289 mOutput.mState.isEnabled = true;
3290 mOutput.mState.usesClientComposition = true;
3291
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08003292 Output::FrameFences frameFences;
Dominik Laskowskibb448ce2022-05-07 15:52:55 -07003293 frameFences.clientTargetAcquireFence = sp<Fence>::make();
3294 frameFences.layerFences.emplace(&mLayer1.hwc2Layer, sp<Fence>::make());
3295 frameFences.layerFences.emplace(&mLayer2.hwc2Layer, sp<Fence>::make());
3296 frameFences.layerFences.emplace(&mLayer3.hwc2Layer, sp<Fence>::make());
Lloyd Pique07178e32019-11-19 19:15:26 -08003297
Leon Scroggins IIIc1623d12023-11-06 15:31:05 -05003298 EXPECT_CALL(mOutput, presentFrame()).WillOnce(Return(frameFences));
Lloyd Pique07178e32019-11-19 19:15:26 -08003299 EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted());
3300
3301 // Fence::merge is called, and since none of the fences are actually valid,
3302 // Fence::NO_FENCE is returned and passed to each onLayerDisplayed() call.
3303 // This is the best we can do without creating a real kernel fence object.
Sally Qi59a9f502021-10-12 18:53:23 +00003304 EXPECT_CALL(*mLayer1.layerFE, onLayerDisplayed).WillOnce(Return());
3305 EXPECT_CALL(*mLayer2.layerFE, onLayerDisplayed).WillOnce(Return());
3306 EXPECT_CALL(*mLayer3.layerFE, onLayerDisplayed).WillOnce(Return());
Lloyd Pique07178e32019-11-19 19:15:26 -08003307
Leon Scroggins IIIc1623d12023-11-06 15:31:05 -05003308 mOutput.presentFrameAndReleaseLayers();
Lloyd Pique07178e32019-11-19 19:15:26 -08003309}
3310
Melody Hsu793f8362024-01-08 20:00:35 +00003311TEST_F(OutputPostFramebufferTest, setReleaseFencesIncludeClientTargetAcquireFence) {
3312 SET_FLAG_FOR_TEST(com::android::graphics::surfaceflinger::flags::ce_fence_promise, true);
3313 ASSERT_TRUE(FlagManager::getInstance().ce_fence_promise());
3314
3315 mOutput.mState.isEnabled = true;
3316 mOutput.mState.usesClientComposition = true;
3317
3318 Output::FrameFences frameFences;
3319 frameFences.clientTargetAcquireFence = sp<Fence>::make();
3320 frameFences.layerFences.emplace(&mLayer1.hwc2Layer, sp<Fence>::make());
3321 frameFences.layerFences.emplace(&mLayer2.hwc2Layer, sp<Fence>::make());
3322 frameFences.layerFences.emplace(&mLayer3.hwc2Layer, sp<Fence>::make());
3323
3324 EXPECT_CALL(mOutput, presentFrame()).WillOnce(Return(frameFences));
3325 EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted());
3326
3327 // Fence::merge is called, and since none of the fences are actually valid,
3328 // Fence::NO_FENCE is returned and passed to each setReleaseFence() call.
3329 // This is the best we can do without creating a real kernel fence object.
3330 EXPECT_CALL(*mLayer1.layerFE, setReleaseFence).WillOnce(Return());
3331 EXPECT_CALL(*mLayer2.layerFE, setReleaseFence).WillOnce(Return());
3332 EXPECT_CALL(*mLayer3.layerFE, setReleaseFence).WillOnce(Return());
3333 mOutput.presentFrameAndReleaseLayers();
3334}
3335
Lloyd Pique07178e32019-11-19 19:15:26 -08003336TEST_F(OutputPostFramebufferTest, releasedLayersSentPresentFence) {
Melody Hsu793f8362024-01-08 20:00:35 +00003337 SET_FLAG_FOR_TEST(com::android::graphics::surfaceflinger::flags::ce_fence_promise, false);
3338 ASSERT_FALSE(FlagManager::getInstance().ce_fence_promise());
3339
Lloyd Pique07178e32019-11-19 19:15:26 -08003340 mOutput.mState.isEnabled = true;
3341 mOutput.mState.usesClientComposition = true;
3342
3343 // This should happen even if there are no (current) output layers.
3344 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
3345
3346 // Load up the released layers with some mock instances
Ady Abrahame0eafa82022-02-02 19:30:47 -08003347 sp<StrictMock<mock::LayerFE>> releasedLayer1 = sp<StrictMock<mock::LayerFE>>::make();
3348 sp<StrictMock<mock::LayerFE>> releasedLayer2 = sp<StrictMock<mock::LayerFE>>::make();
3349 sp<StrictMock<mock::LayerFE>> releasedLayer3 = sp<StrictMock<mock::LayerFE>>::make();
Lloyd Pique07178e32019-11-19 19:15:26 -08003350 Output::ReleasedLayers layers;
3351 layers.push_back(releasedLayer1);
3352 layers.push_back(releasedLayer2);
3353 layers.push_back(releasedLayer3);
3354 mOutput.setReleasedLayers(std::move(layers));
3355
3356 // Set up a fake present fence
Dominik Laskowskibb448ce2022-05-07 15:52:55 -07003357 sp<Fence> presentFence = sp<Fence>::make();
Lloyd Piquefe0ee9e2019-11-22 16:30:30 -08003358 Output::FrameFences frameFences;
Lloyd Pique07178e32019-11-19 19:15:26 -08003359 frameFences.presentFence = presentFence;
3360
Leon Scroggins IIIc1623d12023-11-06 15:31:05 -05003361 EXPECT_CALL(mOutput, presentFrame()).WillOnce(Return(frameFences));
Lloyd Pique07178e32019-11-19 19:15:26 -08003362 EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted());
3363
3364 // Each released layer should be given the presentFence.
Vishnu Nair7ee4f462023-04-19 09:54:09 -07003365 EXPECT_CALL(*releasedLayer1, onLayerDisplayed(_, _))
3366 .WillOnce([&presentFence](ftl::SharedFuture<FenceResult> futureFenceResult,
3367 ui::LayerStack) {
Dominik Laskowskibb448ce2022-05-07 15:52:55 -07003368 EXPECT_EQ(FenceResult(presentFence), futureFenceResult.get());
Sally Qi59a9f502021-10-12 18:53:23 +00003369 });
Vishnu Nair7ee4f462023-04-19 09:54:09 -07003370 EXPECT_CALL(*releasedLayer2, onLayerDisplayed(_, _))
3371 .WillOnce([&presentFence](ftl::SharedFuture<FenceResult> futureFenceResult,
3372 ui::LayerStack) {
Dominik Laskowskibb448ce2022-05-07 15:52:55 -07003373 EXPECT_EQ(FenceResult(presentFence), futureFenceResult.get());
Sally Qi59a9f502021-10-12 18:53:23 +00003374 });
Vishnu Nair7ee4f462023-04-19 09:54:09 -07003375 EXPECT_CALL(*releasedLayer3, onLayerDisplayed(_, _))
3376 .WillOnce([&presentFence](ftl::SharedFuture<FenceResult> futureFenceResult,
3377 ui::LayerStack) {
Dominik Laskowskibb448ce2022-05-07 15:52:55 -07003378 EXPECT_EQ(FenceResult(presentFence), futureFenceResult.get());
Sally Qi59a9f502021-10-12 18:53:23 +00003379 });
Lloyd Pique07178e32019-11-19 19:15:26 -08003380
Leon Scroggins IIIc1623d12023-11-06 15:31:05 -05003381 mOutput.presentFrameAndReleaseLayers();
Lloyd Pique07178e32019-11-19 19:15:26 -08003382
3383 // After the call the list of released layers should have been cleared.
3384 EXPECT_TRUE(mOutput.getReleasedLayersForTest().empty());
3385}
Lloyd Piquefaa3f192019-11-14 14:05:09 -08003386
Melody Hsu793f8362024-01-08 20:00:35 +00003387TEST_F(OutputPostFramebufferTest, setReleasedLayersSentPresentFence) {
3388 SET_FLAG_FOR_TEST(com::android::graphics::surfaceflinger::flags::ce_fence_promise, true);
3389 ASSERT_TRUE(FlagManager::getInstance().ce_fence_promise());
3390
3391 mOutput.mState.isEnabled = true;
3392 mOutput.mState.usesClientComposition = true;
3393
3394 // This should happen even if there are no (current) output layers.
3395 EXPECT_CALL(mOutput, getOutputLayerCount()).WillOnce(Return(0u));
3396
3397 // Load up the released layers with some mock instances
3398 sp<StrictMock<mock::LayerFE>> releasedLayer1 = sp<StrictMock<mock::LayerFE>>::make();
3399 sp<StrictMock<mock::LayerFE>> releasedLayer2 = sp<StrictMock<mock::LayerFE>>::make();
3400 sp<StrictMock<mock::LayerFE>> releasedLayer3 = sp<StrictMock<mock::LayerFE>>::make();
3401 Output::ReleasedLayers layers;
3402 layers.push_back(releasedLayer1);
3403 layers.push_back(releasedLayer2);
3404 layers.push_back(releasedLayer3);
3405 mOutput.setReleasedLayers(std::move(layers));
3406
3407 // Set up a fake present fence
3408 sp<Fence> presentFence = sp<Fence>::make();
3409 Output::FrameFences frameFences;
3410 frameFences.presentFence = presentFence;
3411
3412 EXPECT_CALL(mOutput, presentFrame()).WillOnce(Return(frameFences));
3413 EXPECT_CALL(*mRenderSurface, onPresentDisplayCompleted());
3414
3415 // Each released layer should be given the presentFence.
3416 EXPECT_CALL(*releasedLayer1, setReleaseFence(_))
3417 .WillOnce([&presentFence](FenceResult fenceResult) {
3418 EXPECT_EQ(FenceResult(presentFence), fenceResult);
3419 });
3420 EXPECT_CALL(*releasedLayer2, setReleaseFence(_))
3421 .WillOnce([&presentFence](FenceResult fenceResult) {
3422 EXPECT_EQ(FenceResult(presentFence), fenceResult);
3423 });
3424 EXPECT_CALL(*releasedLayer3, setReleaseFence(_))
3425 .WillOnce([&presentFence](FenceResult fenceResult) {
3426 EXPECT_EQ(FenceResult(presentFence), fenceResult);
3427 });
3428
3429 mOutput.presentFrameAndReleaseLayers();
3430
3431 // After the call the list of released layers should have been cleared.
3432 EXPECT_TRUE(mOutput.getReleasedLayersForTest().empty());
3433}
3434
Lloyd Piquefaa3f192019-11-14 14:05:09 -08003435/*
Lloyd Pique56eba802019-08-28 15:45:25 -07003436 * Output::composeSurfaces()
3437 */
3438
3439struct OutputComposeSurfacesTest : public testing::Test {
Lloyd Pique6818fa52019-12-03 12:32:13 -08003440 using TestType = OutputComposeSurfacesTest;
Lloyd Pique56eba802019-08-28 15:45:25 -07003441
Lloyd Piquefaa3f192019-11-14 14:05:09 -08003442 struct OutputPartialMock : public OutputPartialMockBase {
Lloyd Pique739afaf2019-11-21 16:40:05 -08003443 // Sets up the helper functions called by the function under test to use
3444 // mock implementations.
Lloyd Pique56eba802019-08-28 15:45:25 -07003445 MOCK_CONST_METHOD0(getSkipColorTransform, bool());
Robert Carrccab4242021-09-28 16:53:03 -07003446 MOCK_METHOD3(generateClientCompositionRequests,
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00003447 std::vector<LayerFE::LayerSettings>(bool, ui::Dataspace,
3448 std::vector<LayerFE*>&));
Lloyd Pique56eba802019-08-28 15:45:25 -07003449 MOCK_METHOD2(appendRegionFlashRequests,
Vishnu Nair9b079a22020-01-21 14:36:08 -08003450 void(const Region&, std::vector<LayerFE::LayerSettings>&));
Lloyd Pique56eba802019-08-28 15:45:25 -07003451 MOCK_METHOD1(setExpensiveRenderingExpected, void(bool));
Xiang Wangaab31162024-03-12 19:48:08 -07003452 MOCK_METHOD(void, setHintSessionGpuStart, (TimePoint startTime), (override));
Matt Buckley50c44062022-01-17 20:48:10 +00003453 MOCK_METHOD(void, setHintSessionGpuFence, (std::unique_ptr<FenceTime> && gpuFence),
3454 (override));
Xiang Wangaab31162024-03-12 19:48:08 -07003455 MOCK_METHOD(void, setHintSessionRequiresRenderEngine, (bool), (override));
Matt Buckley50c44062022-01-17 20:48:10 +00003456 MOCK_METHOD(bool, isPowerHintSessionEnabled, (), (override));
Lloyd Pique56eba802019-08-28 15:45:25 -07003457 };
3458
3459 OutputComposeSurfacesTest() {
3460 mOutput.setDisplayColorProfileForTest(
3461 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
3462 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
Vishnu Nair9b079a22020-01-21 14:36:08 -08003463 mOutput.cacheClientCompositionRequests(MAX_CLIENT_COMPOSITION_CACHE_SIZE);
Lloyd Pique56eba802019-08-28 15:45:25 -07003464
Angel Aguayob084e0c2021-08-04 23:27:28 +00003465 mOutput.mState.orientedDisplaySpace.setContent(kDefaultOutputFrame);
3466 mOutput.mState.layerStackSpace.setContent(kDefaultOutputViewport);
3467 mOutput.mState.framebufferSpace.setContent(kDefaultOutputDestinationClip);
3468 mOutput.mState.displaySpace.setContent(kDefaultOutputDestinationClip);
3469 mOutput.mState.displaySpace.setOrientation(kDefaultOutputOrientation);
Marin Shalamanovb15d2272020-09-17 21:41:52 +02003470 mOutput.mState.transform = ui::Transform{kDefaultOutputOrientationFlags};
Lloyd Pique6818fa52019-12-03 12:32:13 -08003471 mOutput.mState.dataspace = kDefaultOutputDataspace;
3472 mOutput.mState.colorTransformMatrix = kDefaultColorTransformMat;
3473 mOutput.mState.isSecure = false;
3474 mOutput.mState.needsFiltering = false;
3475 mOutput.mState.usesClientComposition = true;
3476 mOutput.mState.usesDeviceComposition = false;
Vishnu Nair9b079a22020-01-21 14:36:08 -08003477 mOutput.mState.reusedClientComposition = false;
Lloyd Piquee9eff972020-05-05 12:36:44 -07003478 mOutput.mState.flipClientTarget = false;
Alec Mourif8d093d2022-02-10 15:16:59 -08003479 mOutput.mState.clientTargetBrightness = kClientTargetBrightness;
Lloyd Pique56eba802019-08-28 15:45:25 -07003480
Lloyd Piquea38ea7e2019-04-16 18:10:26 -07003481 EXPECT_CALL(mOutput, getCompositionEngine()).WillRepeatedly(ReturnRef(mCompositionEngine));
Lloyd Pique56eba802019-08-28 15:45:25 -07003482 EXPECT_CALL(mCompositionEngine, getRenderEngine()).WillRepeatedly(ReturnRef(mRenderEngine));
Patrick Williams74c0bf62022-11-02 23:59:26 +00003483 EXPECT_CALL(mCompositionEngine, getTimeStats()).WillRepeatedly(Return(mTimeStats.get()));
Lloyd Pique6818fa52019-12-03 12:32:13 -08003484 EXPECT_CALL(*mDisplayColorProfile, getHdrCapabilities())
3485 .WillRepeatedly(ReturnRef(kHdrCapabilities));
Xiang Wangaab31162024-03-12 19:48:08 -07003486 EXPECT_CALL(mOutput, isPowerHintSessionEnabled()).WillRepeatedly(Return(true));
3487 SET_FLAG_FOR_TEST(flags::adpf_gpu_sf, false);
Lloyd Pique56eba802019-08-28 15:45:25 -07003488 }
3489
Lloyd Pique6818fa52019-12-03 12:32:13 -08003490 struct ExecuteState : public CallOrderStateMachineHelper<TestType, ExecuteState> {
3491 auto execute() {
Vishnu Naira3140382022-02-24 14:07:11 -08003492 base::unique_fd fence;
3493 std::shared_ptr<renderengine::ExternalTexture> externalTexture;
3494 const bool success =
3495 getInstance()->mOutput.dequeueRenderBuffer(&fence, &externalTexture);
3496 if (success) {
3497 getInstance()->mReadyFence =
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00003498 getInstance()->mOutput.composeSurfaces(kDebugRegion, externalTexture,
3499 fence);
Vishnu Naira3140382022-02-24 14:07:11 -08003500 }
Lloyd Pique6818fa52019-12-03 12:32:13 -08003501 return nextState<FenceCheckState>();
3502 }
3503 };
3504
3505 struct FenceCheckState : public CallOrderStateMachineHelper<TestType, FenceCheckState> {
3506 void expectNoFenceWasReturned() { EXPECT_FALSE(getInstance()->mReadyFence); }
3507
3508 void expectAFenceWasReturned() { EXPECT_TRUE(getInstance()->mReadyFence); }
3509 };
3510
3511 // Call this member function to start using the mini-DSL defined above.
3512 [[nodiscard]] auto verify() { return ExecuteState::make(this); }
3513
Marin Shalamanov68933fb2020-09-10 17:58:12 +02003514 static constexpr ui::Rotation kDefaultOutputOrientation = ui::ROTATION_0;
3515 static constexpr uint32_t kDefaultOutputOrientationFlags =
3516 ui::Transform::toRotationFlags(kDefaultOutputOrientation);
Lloyd Pique6818fa52019-12-03 12:32:13 -08003517 static constexpr ui::Dataspace kDefaultOutputDataspace = ui::Dataspace::UNKNOWN;
3518 static constexpr ui::Dataspace kExpensiveOutputDataspace = ui::Dataspace::DISPLAY_P3;
3519 static constexpr float kDefaultMaxLuminance = 0.9f;
3520 static constexpr float kDefaultAvgLuminance = 0.7f;
3521 static constexpr float kDefaultMinLuminance = 0.1f;
Alec Mourif8d093d2022-02-10 15:16:59 -08003522 static constexpr float kDisplayLuminance = 400.f;
Alec Mourif97df4d2023-09-06 02:10:05 +00003523 static constexpr float kWhitePointLuminance = 300.f;
Alec Mouricdf6cbc2021-11-01 17:21:15 -07003524 static constexpr float kClientTargetLuminanceNits = 200.f;
Alec Mourif8d093d2022-02-10 15:16:59 -08003525 static constexpr float kClientTargetBrightness = 0.5f;
Lloyd Pique6818fa52019-12-03 12:32:13 -08003526
3527 static const Rect kDefaultOutputFrame;
3528 static const Rect kDefaultOutputViewport;
Lloyd Piquee8fe4742020-01-21 15:26:18 -08003529 static const Rect kDefaultOutputDestinationClip;
Lloyd Pique6818fa52019-12-03 12:32:13 -08003530 static const mat4 kDefaultColorTransformMat;
3531
3532 static const Region kDebugRegion;
3533 static const HdrCapabilities kHdrCapabilities;
3534
Lloyd Pique56eba802019-08-28 15:45:25 -07003535 StrictMock<mock::CompositionEngine> mCompositionEngine;
3536 StrictMock<renderengine::mock::RenderEngine> mRenderEngine;
Alec Mourie4034bb2019-11-19 12:45:54 -08003537 // TODO: make this is a proper mock.
3538 std::shared_ptr<TimeStats> mTimeStats = std::make_shared<android::impl::TimeStats>();
Lloyd Pique56eba802019-08-28 15:45:25 -07003539 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
3540 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -07003541 StrictMock<OutputPartialMock> mOutput;
Alec Mouria90a5702021-04-16 16:36:21 +00003542 std::shared_ptr<renderengine::ExternalTexture> mOutputBuffer = std::make_shared<
Vishnu Nairdbbe3852022-01-12 20:22:11 -08003543 renderengine::impl::
Ady Abrahamd11bade2022-08-01 16:18:03 -07003544 ExternalTexture>(sp<GraphicBuffer>::make(), mRenderEngine,
Vishnu Nairdbbe3852022-01-12 20:22:11 -08003545 renderengine::impl::ExternalTexture::Usage::READABLE |
3546 renderengine::impl::ExternalTexture::Usage::WRITEABLE);
Lloyd Pique6818fa52019-12-03 12:32:13 -08003547
3548 std::optional<base::unique_fd> mReadyFence;
Lloyd Pique56eba802019-08-28 15:45:25 -07003549};
3550
3551const Rect OutputComposeSurfacesTest::kDefaultOutputFrame{1001, 1002, 1003, 1004};
3552const Rect OutputComposeSurfacesTest::kDefaultOutputViewport{1005, 1006, 1007, 1008};
Lloyd Piquee8fe4742020-01-21 15:26:18 -08003553const Rect OutputComposeSurfacesTest::kDefaultOutputDestinationClip{1013, 1014, 1015, 1016};
Lloyd Pique0a456232020-01-16 17:51:13 -08003554const mat4 OutputComposeSurfacesTest::kDefaultColorTransformMat{mat4() * 0.5f};
Lloyd Pique6818fa52019-12-03 12:32:13 -08003555const Region OutputComposeSurfacesTest::kDebugRegion{Rect{100, 101, 102, 103}};
Alec Mourib21d94e2022-01-13 17:44:10 -08003556
Lloyd Pique6818fa52019-12-03 12:32:13 -08003557const HdrCapabilities OutputComposeSurfacesTest::
3558 kHdrCapabilities{{},
3559 OutputComposeSurfacesTest::kDefaultMaxLuminance,
3560 OutputComposeSurfacesTest::kDefaultAvgLuminance,
3561 OutputComposeSurfacesTest::kDefaultMinLuminance};
Lloyd Pique56eba802019-08-28 15:45:25 -07003562
Lloyd Piquea76ce462020-01-14 13:06:37 -08003563TEST_F(OutputComposeSurfacesTest, doesNothingButSignalNoExpensiveRenderingIfNoClientComposition) {
Lloyd Pique6818fa52019-12-03 12:32:13 -08003564 mOutput.mState.usesClientComposition = false;
Lloyd Pique56eba802019-08-28 15:45:25 -07003565
Lloyd Piquee9eff972020-05-05 12:36:44 -07003566 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
Peiyong Lin09f910f2020-09-25 10:54:13 -07003567 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
Lloyd Piquee9eff972020-05-05 12:36:44 -07003568
Lloyd Piquea76ce462020-01-14 13:06:37 -08003569 EXPECT_CALL(mOutput, setExpensiveRenderingExpected(false));
3570
Lloyd Pique6818fa52019-12-03 12:32:13 -08003571 verify().execute().expectAFenceWasReturned();
Lloyd Pique56eba802019-08-28 15:45:25 -07003572}
3573
Lloyd Piquee9eff972020-05-05 12:36:44 -07003574TEST_F(OutputComposeSurfacesTest,
3575 dequeuesABufferIfNoClientCompositionButFlipClientTargetRequested) {
3576 mOutput.mState.usesClientComposition = false;
3577 mOutput.mState.flipClientTarget = true;
3578
Lloyd Pique6818fa52019-12-03 12:32:13 -08003579 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
Peiyong Lin09f910f2020-09-25 10:54:13 -07003580 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
Lloyd Piquee9eff972020-05-05 12:36:44 -07003581
3582 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillOnce(Return(mOutputBuffer));
3583 EXPECT_CALL(mOutput, setExpensiveRenderingExpected(false));
3584
3585 verify().execute().expectAFenceWasReturned();
3586}
3587
3588TEST_F(OutputComposeSurfacesTest, doesMinimalWorkIfDequeueBufferFailsForClientComposition) {
3589 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
Peiyong Lin09f910f2020-09-25 10:54:13 -07003590 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
Lloyd Piquee9eff972020-05-05 12:36:44 -07003591
3592 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillOnce(Return(nullptr));
3593
3594 verify().execute().expectNoFenceWasReturned();
3595}
3596
3597TEST_F(OutputComposeSurfacesTest,
3598 doesMinimalWorkIfDequeueBufferFailsForNoClientCompositionButFlipClientTargetRequested) {
3599 mOutput.mState.usesClientComposition = false;
3600 mOutput.mState.flipClientTarget = true;
3601
3602 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
Peiyong Lin09f910f2020-09-25 10:54:13 -07003603 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
Lloyd Pique56eba802019-08-28 15:45:25 -07003604
Lloyd Pique6818fa52019-12-03 12:32:13 -08003605 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillOnce(Return(nullptr));
Lloyd Pique56eba802019-08-28 15:45:25 -07003606
Lloyd Pique6818fa52019-12-03 12:32:13 -08003607 verify().execute().expectNoFenceWasReturned();
3608}
Lloyd Pique56eba802019-08-28 15:45:25 -07003609
Lloyd Pique6818fa52019-12-03 12:32:13 -08003610TEST_F(OutputComposeSurfacesTest, handlesZeroCompositionRequests) {
3611 EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false));
3612 EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true));
3613 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
Peiyong Lin09f910f2020-09-25 10:54:13 -07003614 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
Robert Carrccab4242021-09-28 16:53:03 -07003615 EXPECT_CALL(mOutput, generateClientCompositionRequests(_, kDefaultOutputDataspace, _))
Vishnu Nair9b079a22020-01-21 14:36:08 -08003616 .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{}));
Lloyd Pique6818fa52019-12-03 12:32:13 -08003617 EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _))
3618 .WillRepeatedly(Return());
Lloyd Pique56eba802019-08-28 15:45:25 -07003619
Lloyd Pique6818fa52019-12-03 12:32:13 -08003620 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer));
Alec Mourif29700f2023-08-17 21:53:31 +00003621 EXPECT_CALL(mRenderEngine, drawLayers(_, IsEmpty(), _, _))
Sally Qi4cabdd02021-08-05 16:45:57 -07003622 .WillRepeatedly([&](const renderengine::DisplaySettings&,
Sally Qi59a9f502021-10-12 18:53:23 +00003623 const std::vector<renderengine::LayerSettings>&,
Alec Mourif29700f2023-08-17 21:53:31 +00003624 const std::shared_ptr<renderengine::ExternalTexture>&,
Patrick Williams2e9748f2022-08-09 22:48:18 +00003625 base::unique_fd&&) -> ftl::Future<FenceResult> {
3626 return ftl::yield<FenceResult>(Fence::NO_FENCE);
Sally Qi4cabdd02021-08-05 16:45:57 -07003627 });
Lloyd Pique6818fa52019-12-03 12:32:13 -08003628 verify().execute().expectAFenceWasReturned();
3629}
Lloyd Pique56eba802019-08-28 15:45:25 -07003630
Lloyd Pique6818fa52019-12-03 12:32:13 -08003631TEST_F(OutputComposeSurfacesTest, buildsAndRendersRequestList) {
Vishnu Nair9b079a22020-01-21 14:36:08 -08003632 LayerFE::LayerSettings r1;
3633 LayerFE::LayerSettings r2;
Lloyd Pique6818fa52019-12-03 12:32:13 -08003634
3635 r1.geometry.boundaries = FloatRect{1, 2, 3, 4};
3636 r2.geometry.boundaries = FloatRect{5, 6, 7, 8};
3637
3638 EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false));
3639 EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true));
3640 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
Peiyong Lin09f910f2020-09-25 10:54:13 -07003641 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
Robert Carrccab4242021-09-28 16:53:03 -07003642 EXPECT_CALL(mOutput, generateClientCompositionRequests(_, kDefaultOutputDataspace, _))
Vishnu Nair9b079a22020-01-21 14:36:08 -08003643 .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{r1}));
Lloyd Pique6818fa52019-12-03 12:32:13 -08003644 EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _))
3645 .WillRepeatedly(
3646 Invoke([&](const Region&,
Vishnu Nair9b079a22020-01-21 14:36:08 -08003647 std::vector<LayerFE::LayerSettings>& clientCompositionLayers) {
Lloyd Pique6818fa52019-12-03 12:32:13 -08003648 clientCompositionLayers.emplace_back(r2);
3649 }));
3650
3651 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer));
Alec Mourif29700f2023-08-17 21:53:31 +00003652 EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(r1, r2), _, _))
Sally Qi4cabdd02021-08-05 16:45:57 -07003653 .WillRepeatedly([&](const renderengine::DisplaySettings&,
Sally Qi59a9f502021-10-12 18:53:23 +00003654 const std::vector<renderengine::LayerSettings>&,
Alec Mourif29700f2023-08-17 21:53:31 +00003655 const std::shared_ptr<renderengine::ExternalTexture>&,
Patrick Williams2e9748f2022-08-09 22:48:18 +00003656 base::unique_fd&&) -> ftl::Future<FenceResult> {
3657 return ftl::yield<FenceResult>(Fence::NO_FENCE);
Sally Qi4cabdd02021-08-05 16:45:57 -07003658 });
Alec Mouri1684c702021-02-04 12:27:26 -08003659
3660 verify().execute().expectAFenceWasReturned();
3661}
3662
3663TEST_F(OutputComposeSurfacesTest,
3664 buildsAndRendersRequestListAndCachesFramebufferForInternalLayers) {
3665 LayerFE::LayerSettings r1;
3666 LayerFE::LayerSettings r2;
3667
3668 r1.geometry.boundaries = FloatRect{1, 2, 3, 4};
3669 r2.geometry.boundaries = FloatRect{5, 6, 7, 8};
Dominik Laskowski29fa1462021-04-27 15:51:50 -07003670 mOutput.setLayerFilter({ui::LayerStack{1234u}, true});
Alec Mouri1684c702021-02-04 12:27:26 -08003671
3672 EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false));
3673 EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true));
3674 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
3675 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
Robert Carrccab4242021-09-28 16:53:03 -07003676 EXPECT_CALL(mOutput, generateClientCompositionRequests(_, kDefaultOutputDataspace, _))
Alec Mouri1684c702021-02-04 12:27:26 -08003677 .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{r1}));
3678 EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _))
3679 .WillRepeatedly(
3680 Invoke([&](const Region&,
3681 std::vector<LayerFE::LayerSettings>& clientCompositionLayers) {
3682 clientCompositionLayers.emplace_back(r2);
3683 }));
3684
3685 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer));
Alec Mourif29700f2023-08-17 21:53:31 +00003686 EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(r1, r2), _, _))
Sally Qi4cabdd02021-08-05 16:45:57 -07003687 .WillRepeatedly([&](const renderengine::DisplaySettings&,
Sally Qi59a9f502021-10-12 18:53:23 +00003688 const std::vector<renderengine::LayerSettings>&,
Alec Mourif29700f2023-08-17 21:53:31 +00003689 const std::shared_ptr<renderengine::ExternalTexture>&,
Patrick Williams2e9748f2022-08-09 22:48:18 +00003690 base::unique_fd&&) -> ftl::Future<FenceResult> {
3691 return ftl::yield<FenceResult>(Fence::NO_FENCE);
Sally Qi4cabdd02021-08-05 16:45:57 -07003692 });
Lloyd Pique6818fa52019-12-03 12:32:13 -08003693
3694 verify().execute().expectAFenceWasReturned();
3695}
3696
Vishnu Nair9b079a22020-01-21 14:36:08 -08003697TEST_F(OutputComposeSurfacesTest, renderDuplicateClientCompositionRequestsWithoutCache) {
3698 mOutput.cacheClientCompositionRequests(0);
3699 LayerFE::LayerSettings r1;
3700 LayerFE::LayerSettings r2;
3701
3702 r1.geometry.boundaries = FloatRect{1, 2, 3, 4};
3703 r2.geometry.boundaries = FloatRect{5, 6, 7, 8};
3704
3705 EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false));
3706 EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true));
3707 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
Peiyong Lin09f910f2020-09-25 10:54:13 -07003708 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
Robert Carrccab4242021-09-28 16:53:03 -07003709 EXPECT_CALL(mOutput, generateClientCompositionRequests(_, kDefaultOutputDataspace, _))
Vishnu Nair9b079a22020-01-21 14:36:08 -08003710 .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{r1, r2}));
3711 EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _))
3712 .WillRepeatedly(Return());
3713
3714 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer));
Alec Mourif29700f2023-08-17 21:53:31 +00003715 EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(r1, r2), _, _))
Vishnu Nair9b079a22020-01-21 14:36:08 -08003716 .Times(2)
Patrick Williams2e9748f2022-08-09 22:48:18 +00003717 .WillOnce(Return(ByMove(ftl::yield<FenceResult>(Fence::NO_FENCE))))
3718 .WillOnce(Return(ByMove(ftl::yield<FenceResult>(Fence::NO_FENCE))));
Vishnu Nair9b079a22020-01-21 14:36:08 -08003719
3720 verify().execute().expectAFenceWasReturned();
3721 EXPECT_FALSE(mOutput.mState.reusedClientComposition);
3722
3723 verify().execute().expectAFenceWasReturned();
3724 EXPECT_FALSE(mOutput.mState.reusedClientComposition);
3725}
3726
3727TEST_F(OutputComposeSurfacesTest, skipDuplicateClientCompositionRequests) {
3728 mOutput.cacheClientCompositionRequests(3);
3729 LayerFE::LayerSettings r1;
3730 LayerFE::LayerSettings r2;
3731
3732 r1.geometry.boundaries = FloatRect{1, 2, 3, 4};
3733 r2.geometry.boundaries = FloatRect{5, 6, 7, 8};
3734
3735 EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false));
3736 EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true));
3737 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
Peiyong Lin09f910f2020-09-25 10:54:13 -07003738 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
Robert Carrccab4242021-09-28 16:53:03 -07003739 EXPECT_CALL(mOutput, generateClientCompositionRequests(_, kDefaultOutputDataspace, _))
Vishnu Nair9b079a22020-01-21 14:36:08 -08003740 .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{r1, r2}));
3741 EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _))
3742 .WillRepeatedly(Return());
3743
3744 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer));
Alec Mourif29700f2023-08-17 21:53:31 +00003745 EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(r1, r2), _, _))
Patrick Williams2e9748f2022-08-09 22:48:18 +00003746 .WillOnce(Return(ByMove(ftl::yield<FenceResult>(Fence::NO_FENCE))));
Vishnu Nair9b079a22020-01-21 14:36:08 -08003747 EXPECT_CALL(mOutput, setExpensiveRenderingExpected(false));
3748
3749 verify().execute().expectAFenceWasReturned();
3750 EXPECT_FALSE(mOutput.mState.reusedClientComposition);
3751
3752 // We do not expect another call to draw layers.
Xiang Wangaab31162024-03-12 19:48:08 -07003753 EXPECT_CALL(mOutput, setHintSessionRequiresRenderEngine(_)).Times(0);
3754 EXPECT_CALL(mOutput, setHintSessionGpuStart(_)).Times(0);
3755 EXPECT_CALL(mOutput, setHintSessionGpuFence(_)).Times(0);
Vishnu Nair9b079a22020-01-21 14:36:08 -08003756 verify().execute().expectAFenceWasReturned();
3757 EXPECT_TRUE(mOutput.mState.reusedClientComposition);
3758}
3759
3760TEST_F(OutputComposeSurfacesTest, clientCompositionIfBufferChanges) {
3761 LayerFE::LayerSettings r1;
3762 LayerFE::LayerSettings r2;
3763
3764 r1.geometry.boundaries = FloatRect{1, 2, 3, 4};
3765 r2.geometry.boundaries = FloatRect{5, 6, 7, 8};
3766
3767 EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false));
3768 EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true));
3769 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
Peiyong Lin09f910f2020-09-25 10:54:13 -07003770 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
Robert Carrccab4242021-09-28 16:53:03 -07003771 EXPECT_CALL(mOutput, generateClientCompositionRequests(_, kDefaultOutputDataspace, _))
Vishnu Nair9b079a22020-01-21 14:36:08 -08003772 .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{r1, r2}));
3773 EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _))
3774 .WillRepeatedly(Return());
3775
Alec Mouria90a5702021-04-16 16:36:21 +00003776 const auto otherOutputBuffer = std::make_shared<
Vishnu Nairdbbe3852022-01-12 20:22:11 -08003777 renderengine::impl::
Ady Abrahamd11bade2022-08-01 16:18:03 -07003778 ExternalTexture>(sp<GraphicBuffer>::make(), mRenderEngine,
Vishnu Nairdbbe3852022-01-12 20:22:11 -08003779 renderengine::impl::ExternalTexture::Usage::READABLE |
3780 renderengine::impl::ExternalTexture::Usage::WRITEABLE);
Vishnu Nair9b079a22020-01-21 14:36:08 -08003781 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_))
3782 .WillOnce(Return(mOutputBuffer))
3783 .WillOnce(Return(otherOutputBuffer));
Xiang Wangaab31162024-03-12 19:48:08 -07003784 base::unique_fd fd(open("/dev/null", O_RDONLY));
Alec Mourif29700f2023-08-17 21:53:31 +00003785 EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(r1, r2), _, _))
Sally Qi4cabdd02021-08-05 16:45:57 -07003786 .WillRepeatedly([&](const renderengine::DisplaySettings&,
Sally Qi59a9f502021-10-12 18:53:23 +00003787 const std::vector<renderengine::LayerSettings>&,
Alec Mourif29700f2023-08-17 21:53:31 +00003788 const std::shared_ptr<renderengine::ExternalTexture>&,
Patrick Williams2e9748f2022-08-09 22:48:18 +00003789 base::unique_fd&&) -> ftl::Future<FenceResult> {
Xiang Wangaab31162024-03-12 19:48:08 -07003790 return ftl::yield<FenceResult>(sp<Fence>::make(std::move(fd)));
Sally Qi4cabdd02021-08-05 16:45:57 -07003791 });
Vishnu Nair9b079a22020-01-21 14:36:08 -08003792
Xiang Wangaab31162024-03-12 19:48:08 -07003793 EXPECT_CALL(mOutput, setHintSessionRequiresRenderEngine(true));
3794 EXPECT_CALL(mOutput, setHintSessionGpuStart(_)).Times(0);
3795 EXPECT_CALL(mOutput, setHintSessionGpuFence(_)).Times(0);
3796 verify().execute().expectAFenceWasReturned();
3797 EXPECT_FALSE(mOutput.mState.reusedClientComposition);
3798
3799 verify().execute().expectAFenceWasReturned();
3800 EXPECT_FALSE(mOutput.mState.reusedClientComposition);
3801}
3802
3803TEST_F(OutputComposeSurfacesTest, clientCompositionIfBufferChangesWithAdpfGpuOn) {
3804 SET_FLAG_FOR_TEST(flags::adpf_gpu_sf, true);
3805 LayerFE::LayerSettings r1;
3806 LayerFE::LayerSettings r2;
3807
3808 r1.geometry.boundaries = FloatRect{1, 2, 3, 4};
3809 r2.geometry.boundaries = FloatRect{5, 6, 7, 8};
3810
3811 EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false));
3812 EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true));
3813 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
3814 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
3815 EXPECT_CALL(mOutput, generateClientCompositionRequests(_, kDefaultOutputDataspace, _))
3816 .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{r1, r2}));
3817 EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _))
3818 .WillRepeatedly(Return());
3819
3820 const auto otherOutputBuffer = std::make_shared<
3821 renderengine::impl::
3822 ExternalTexture>(sp<GraphicBuffer>::make(), mRenderEngine,
3823 renderengine::impl::ExternalTexture::Usage::READABLE |
3824 renderengine::impl::ExternalTexture::Usage::WRITEABLE);
3825 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_))
3826 .WillOnce(Return(mOutputBuffer))
3827 .WillOnce(Return(otherOutputBuffer));
3828 base::unique_fd fd(open("/dev/null", O_RDONLY));
3829 EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(r1, r2), _, _))
3830 .WillRepeatedly([&](const renderengine::DisplaySettings&,
3831 const std::vector<renderengine::LayerSettings>&,
3832 const std::shared_ptr<renderengine::ExternalTexture>&,
3833 base::unique_fd&&) -> ftl::Future<FenceResult> {
3834 return ftl::yield<FenceResult>(sp<Fence>::make(std::move(fd)));
3835 });
3836
3837 EXPECT_CALL(mOutput, setHintSessionRequiresRenderEngine(true));
3838 EXPECT_CALL(mOutput, setHintSessionGpuStart(_));
3839 EXPECT_CALL(mOutput, setHintSessionGpuFence(_));
Vishnu Nair9b079a22020-01-21 14:36:08 -08003840 verify().execute().expectAFenceWasReturned();
3841 EXPECT_FALSE(mOutput.mState.reusedClientComposition);
3842
3843 verify().execute().expectAFenceWasReturned();
3844 EXPECT_FALSE(mOutput.mState.reusedClientComposition);
3845}
3846
3847TEST_F(OutputComposeSurfacesTest, clientCompositionIfRequestChanges) {
3848 LayerFE::LayerSettings r1;
3849 LayerFE::LayerSettings r2;
3850 LayerFE::LayerSettings r3;
3851
3852 r1.geometry.boundaries = FloatRect{1, 2, 3, 4};
3853 r2.geometry.boundaries = FloatRect{5, 6, 7, 8};
3854 r3.geometry.boundaries = FloatRect{5, 6, 7, 9};
3855
3856 EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false));
3857 EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true));
3858 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
Peiyong Lin09f910f2020-09-25 10:54:13 -07003859 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
Robert Carrccab4242021-09-28 16:53:03 -07003860 EXPECT_CALL(mOutput, generateClientCompositionRequests(_, kDefaultOutputDataspace, _))
Vishnu Nair9b079a22020-01-21 14:36:08 -08003861 .WillOnce(Return(std::vector<LayerFE::LayerSettings>{r1, r2}))
3862 .WillOnce(Return(std::vector<LayerFE::LayerSettings>{r1, r3}));
3863 EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _))
3864 .WillRepeatedly(Return());
3865
3866 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer));
Alec Mourif29700f2023-08-17 21:53:31 +00003867 EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(r1, r2), _, _))
Patrick Williams2e9748f2022-08-09 22:48:18 +00003868 .WillOnce(Return(ByMove(ftl::yield<FenceResult>(Fence::NO_FENCE))));
Alec Mourif29700f2023-08-17 21:53:31 +00003869 EXPECT_CALL(mRenderEngine, drawLayers(_, ElementsAre(r1, r3), _, _))
Patrick Williams2e9748f2022-08-09 22:48:18 +00003870 .WillOnce(Return(ByMove(ftl::yield<FenceResult>(Fence::NO_FENCE))));
Vishnu Nair9b079a22020-01-21 14:36:08 -08003871
3872 verify().execute().expectAFenceWasReturned();
3873 EXPECT_FALSE(mOutput.mState.reusedClientComposition);
3874
3875 verify().execute().expectAFenceWasReturned();
3876 EXPECT_FALSE(mOutput.mState.reusedClientComposition);
3877}
3878
Lloyd Pique6818fa52019-12-03 12:32:13 -08003879struct OutputComposeSurfacesTest_UsesExpectedDisplaySettings : public OutputComposeSurfacesTest {
3880 OutputComposeSurfacesTest_UsesExpectedDisplaySettings() {
3881 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
Peiyong Lin09f910f2020-09-25 10:54:13 -07003882 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
Alec Mourif97df4d2023-09-06 02:10:05 +00003883 EXPECT_CALL(mOutput, generateClientCompositionRequests(_, _, _))
Vishnu Nair9b079a22020-01-21 14:36:08 -08003884 .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{}));
Lloyd Pique6818fa52019-12-03 12:32:13 -08003885 EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _))
3886 .WillRepeatedly(Return());
3887 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer));
3888 }
3889
3890 struct MixedCompositionState
3891 : public CallOrderStateMachineHelper<TestType, MixedCompositionState> {
3892 auto ifMixedCompositionIs(bool used) {
3893 getInstance()->mOutput.mState.usesDeviceComposition = used;
3894 return nextState<OutputUsesHdrState>();
3895 }
3896 };
3897
3898 struct OutputUsesHdrState : public CallOrderStateMachineHelper<TestType, OutputUsesHdrState> {
3899 auto andIfUsesHdr(bool used) {
3900 EXPECT_CALL(*getInstance()->mDisplayColorProfile, hasWideColorGamut())
3901 .WillOnce(Return(used));
Alec Mourib21d94e2022-01-13 17:44:10 -08003902 return nextState<OutputWithDisplayBrightnessNits>();
3903 }
3904 };
3905
3906 struct OutputWithDisplayBrightnessNits
3907 : public CallOrderStateMachineHelper<TestType, OutputWithDisplayBrightnessNits> {
3908 auto withDisplayBrightnessNits(float nits) {
3909 getInstance()->mOutput.mState.displayBrightnessNits = nits;
Alec Mourif97df4d2023-09-06 02:10:05 +00003910 return nextState<OutputWithSdrWhitePointNits>();
3911 }
3912 };
3913
3914 struct OutputWithSdrWhitePointNits
3915 : public CallOrderStateMachineHelper<TestType, OutputWithSdrWhitePointNits> {
3916 auto withSdrWhitePointNits(float nits) {
3917 getInstance()->mOutput.mState.sdrWhitePointNits = nits;
Alec Mouri85065692022-03-18 00:58:26 +00003918 return nextState<OutputWithDimmingStage>();
3919 }
3920 };
3921
3922 struct OutputWithDimmingStage
3923 : public CallOrderStateMachineHelper<TestType, OutputWithDimmingStage> {
3924 auto withDimmingStage(
3925 aidl::android::hardware::graphics::composer3::DimmingStage dimmingStage) {
3926 getInstance()->mOutput.mState.clientTargetDimmingStage = dimmingStage;
Alec Mourifcedb9c2022-04-11 20:02:17 +00003927 return nextState<OutputWithRenderIntent>();
3928 }
3929 };
3930
3931 struct OutputWithRenderIntent
3932 : public CallOrderStateMachineHelper<TestType, OutputWithRenderIntent> {
3933 auto withRenderIntent(
3934 aidl::android::hardware::graphics::composer3::RenderIntent renderIntent) {
3935 getInstance()->mOutput.mState.renderIntent =
3936 static_cast<ui::RenderIntent>(renderIntent);
Lloyd Pique6818fa52019-12-03 12:32:13 -08003937 return nextState<SkipColorTransformState>();
3938 }
3939 };
3940
3941 struct SkipColorTransformState
3942 : public CallOrderStateMachineHelper<TestType, SkipColorTransformState> {
3943 auto andIfSkipColorTransform(bool skip) {
3944 // May be called zero or one times.
3945 EXPECT_CALL(getInstance()->mOutput, getSkipColorTransform())
3946 .WillRepeatedly(Return(skip));
Alec Mourif97df4d2023-09-06 02:10:05 +00003947 return nextState<PixelFormatState>();
3948 }
3949 };
3950
3951 struct PixelFormatState : public CallOrderStateMachineHelper<TestType, PixelFormatState> {
3952 auto withPixelFormat(std::optional<PixelFormat> format) {
3953 // May be called zero or one times.
3954 if (format) {
3955 auto outputBuffer = std::make_shared<
3956 renderengine::impl::
3957 ExternalTexture>(sp<GraphicBuffer>::
3958 make(1u, 1u, *format,
3959 GRALLOC_USAGE_SW_WRITE_OFTEN |
3960 GRALLOC_USAGE_SW_READ_OFTEN),
3961 getInstance()->mRenderEngine,
3962 renderengine::impl::ExternalTexture::Usage::
3963 READABLE |
3964 renderengine::impl::ExternalTexture::
3965 Usage::WRITEABLE);
3966 EXPECT_CALL(*getInstance()->mRenderSurface, dequeueBuffer(_))
3967 .WillRepeatedly(Return(outputBuffer));
3968 }
3969 return nextState<DataspaceState>();
3970 }
3971 };
3972
3973 struct DataspaceState : public CallOrderStateMachineHelper<TestType, DataspaceState> {
3974 auto withDataspace(ui::Dataspace dataspace) {
3975 getInstance()->mOutput.mState.dataspace = dataspace;
Lloyd Pique6818fa52019-12-03 12:32:13 -08003976 return nextState<ExpectDisplaySettingsState>();
3977 }
3978 };
3979
3980 struct ExpectDisplaySettingsState
3981 : public CallOrderStateMachineHelper<TestType, ExpectDisplaySettingsState> {
3982 auto thenExpectDisplaySettingsUsed(renderengine::DisplaySettings settings) {
Alec Mourif29700f2023-08-17 21:53:31 +00003983 EXPECT_CALL(getInstance()->mRenderEngine, drawLayers(settings, _, _, _))
Patrick Williams2e9748f2022-08-09 22:48:18 +00003984 .WillOnce(Return(ByMove(ftl::yield<FenceResult>(Fence::NO_FENCE))));
Lloyd Pique6818fa52019-12-03 12:32:13 -08003985 return nextState<ExecuteState>();
3986 }
3987 };
3988
3989 // Call this member function to start using the mini-DSL defined above.
3990 [[nodiscard]] auto verify() { return MixedCompositionState::make(this); }
3991};
3992
3993TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings, forHdrMixedComposition) {
3994 verify().ifMixedCompositionIs(true)
3995 .andIfUsesHdr(true)
Leon Scroggins IIIf6280bb2022-05-04 13:20:32 -04003996 .withDisplayBrightnessNits(kDisplayLuminance)
Alec Mourif97df4d2023-09-06 02:10:05 +00003997 .withSdrWhitePointNits(kWhitePointLuminance)
Alec Mouri85065692022-03-18 00:58:26 +00003998 .withDimmingStage(aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR)
Alec Mourifcedb9c2022-04-11 20:02:17 +00003999 .withRenderIntent(
4000 aidl::android::hardware::graphics::composer3::RenderIntent::COLORIMETRIC)
Lloyd Pique6818fa52019-12-03 12:32:13 -08004001 .andIfSkipColorTransform(false)
Alec Mourif97df4d2023-09-06 02:10:05 +00004002 .withPixelFormat(std::nullopt)
4003 .withDataspace(kDefaultOutputDataspace)
Alec Mouri85065692022-03-18 00:58:26 +00004004 .thenExpectDisplaySettingsUsed(
4005 {.physicalDisplay = kDefaultOutputDestinationClip,
4006 .clip = kDefaultOutputViewport,
4007 .maxLuminance = kDefaultMaxLuminance,
Leon Scroggins IIIf6280bb2022-05-04 13:20:32 -04004008 .currentLuminanceNits = kDisplayLuminance,
Alec Mouri85065692022-03-18 00:58:26 +00004009 .outputDataspace = kDefaultOutputDataspace,
4010 .colorTransform = kDefaultColorTransformMat,
4011 .deviceHandlesColorTransform = true,
4012 .orientation = kDefaultOutputOrientationFlags,
4013 .targetLuminanceNits = kClientTargetLuminanceNits,
4014 .dimmingStage =
Alec Mourifcedb9c2022-04-11 20:02:17 +00004015 aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR,
4016 .renderIntent = aidl::android::hardware::graphics::composer3::RenderIntent::
4017 COLORIMETRIC})
Alec Mourib21d94e2022-01-13 17:44:10 -08004018 .execute()
4019 .expectAFenceWasReturned();
4020}
4021
4022TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings,
4023 forHdrMixedCompositionWithDisplayBrightness) {
4024 verify().ifMixedCompositionIs(true)
4025 .andIfUsesHdr(true)
4026 .withDisplayBrightnessNits(kDisplayLuminance)
Alec Mourif97df4d2023-09-06 02:10:05 +00004027 .withSdrWhitePointNits(kWhitePointLuminance)
Alec Mouri85065692022-03-18 00:58:26 +00004028 .withDimmingStage(aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR)
Alec Mourifcedb9c2022-04-11 20:02:17 +00004029 .withRenderIntent(
4030 aidl::android::hardware::graphics::composer3::RenderIntent::COLORIMETRIC)
Alec Mouri85065692022-03-18 00:58:26 +00004031 .andIfSkipColorTransform(false)
Alec Mourif97df4d2023-09-06 02:10:05 +00004032 .withPixelFormat(std::nullopt)
4033 .withDataspace(kDefaultOutputDataspace)
Alec Mouri85065692022-03-18 00:58:26 +00004034 .thenExpectDisplaySettingsUsed(
4035 {.physicalDisplay = kDefaultOutputDestinationClip,
4036 .clip = kDefaultOutputViewport,
4037 .maxLuminance = kDefaultMaxLuminance,
4038 .currentLuminanceNits = kDisplayLuminance,
4039 .outputDataspace = kDefaultOutputDataspace,
4040 .colorTransform = kDefaultColorTransformMat,
4041 .deviceHandlesColorTransform = true,
4042 .orientation = kDefaultOutputOrientationFlags,
4043 .targetLuminanceNits = kClientTargetLuminanceNits,
4044 .dimmingStage =
Alec Mourifcedb9c2022-04-11 20:02:17 +00004045 aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR,
4046 .renderIntent = aidl::android::hardware::graphics::composer3::RenderIntent::
4047 COLORIMETRIC})
Alec Mouri85065692022-03-18 00:58:26 +00004048 .execute()
4049 .expectAFenceWasReturned();
4050}
4051
4052TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings,
4053 forHdrMixedCompositionWithDimmingStage) {
4054 verify().ifMixedCompositionIs(true)
4055 .andIfUsesHdr(true)
Leon Scroggins IIIf6280bb2022-05-04 13:20:32 -04004056 .withDisplayBrightnessNits(kDisplayLuminance)
Alec Mourif97df4d2023-09-06 02:10:05 +00004057 .withSdrWhitePointNits(kWhitePointLuminance)
Alec Mouri85065692022-03-18 00:58:26 +00004058 .withDimmingStage(
4059 aidl::android::hardware::graphics::composer3::DimmingStage::GAMMA_OETF)
Alec Mourifcedb9c2022-04-11 20:02:17 +00004060 .withRenderIntent(
4061 aidl::android::hardware::graphics::composer3::RenderIntent::COLORIMETRIC)
Lloyd Pique6818fa52019-12-03 12:32:13 -08004062 .andIfSkipColorTransform(false)
Alec Mourif97df4d2023-09-06 02:10:05 +00004063 .withPixelFormat(std::nullopt)
4064 .withDataspace(kDefaultOutputDataspace)
Alec Mouri85065692022-03-18 00:58:26 +00004065 .thenExpectDisplaySettingsUsed(
4066 {.physicalDisplay = kDefaultOutputDestinationClip,
4067 .clip = kDefaultOutputViewport,
4068 .maxLuminance = kDefaultMaxLuminance,
Leon Scroggins IIIf6280bb2022-05-04 13:20:32 -04004069 .currentLuminanceNits = kDisplayLuminance,
Alec Mouri85065692022-03-18 00:58:26 +00004070 .outputDataspace = kDefaultOutputDataspace,
4071 .colorTransform = kDefaultColorTransformMat,
4072 .deviceHandlesColorTransform = true,
4073 .orientation = kDefaultOutputOrientationFlags,
4074 .targetLuminanceNits = kClientTargetLuminanceNits,
4075 .dimmingStage =
Alec Mourifcedb9c2022-04-11 20:02:17 +00004076 aidl::android::hardware::graphics::composer3::DimmingStage::GAMMA_OETF,
4077 .renderIntent = aidl::android::hardware::graphics::composer3::RenderIntent::
4078 COLORIMETRIC})
4079 .execute()
4080 .expectAFenceWasReturned();
4081}
4082
4083TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings,
4084 forHdrMixedCompositionWithRenderIntent) {
4085 verify().ifMixedCompositionIs(true)
4086 .andIfUsesHdr(true)
Leon Scroggins IIIf6280bb2022-05-04 13:20:32 -04004087 .withDisplayBrightnessNits(kDisplayLuminance)
Alec Mourif97df4d2023-09-06 02:10:05 +00004088 .withSdrWhitePointNits(kWhitePointLuminance)
Alec Mourifcedb9c2022-04-11 20:02:17 +00004089 .withDimmingStage(aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR)
4090 .withRenderIntent(aidl::android::hardware::graphics::composer3::RenderIntent::ENHANCE)
4091 .andIfSkipColorTransform(false)
Alec Mourif97df4d2023-09-06 02:10:05 +00004092 .withPixelFormat(std::nullopt)
4093 .withDataspace(kDefaultOutputDataspace)
Alec Mourifcedb9c2022-04-11 20:02:17 +00004094 .thenExpectDisplaySettingsUsed(
4095 {.physicalDisplay = kDefaultOutputDestinationClip,
4096 .clip = kDefaultOutputViewport,
4097 .maxLuminance = kDefaultMaxLuminance,
Leon Scroggins IIIf6280bb2022-05-04 13:20:32 -04004098 .currentLuminanceNits = kDisplayLuminance,
Alec Mourifcedb9c2022-04-11 20:02:17 +00004099 .outputDataspace = kDefaultOutputDataspace,
4100 .colorTransform = kDefaultColorTransformMat,
4101 .deviceHandlesColorTransform = true,
4102 .orientation = kDefaultOutputOrientationFlags,
4103 .targetLuminanceNits = kClientTargetLuminanceNits,
4104 .dimmingStage =
4105 aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR,
4106 .renderIntent =
4107 aidl::android::hardware::graphics::composer3::RenderIntent::ENHANCE})
4108 .execute()
4109 .expectAFenceWasReturned();
4110}
4111
4112TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings, forNonHdrMixedComposition) {
4113 verify().ifMixedCompositionIs(true)
4114 .andIfUsesHdr(false)
Leon Scroggins IIIf6280bb2022-05-04 13:20:32 -04004115 .withDisplayBrightnessNits(kDisplayLuminance)
Alec Mourif97df4d2023-09-06 02:10:05 +00004116 .withSdrWhitePointNits(kWhitePointLuminance)
Alec Mourifcedb9c2022-04-11 20:02:17 +00004117 .withDimmingStage(aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR)
4118 .withRenderIntent(
4119 aidl::android::hardware::graphics::composer3::RenderIntent::COLORIMETRIC)
4120 .andIfSkipColorTransform(false)
Alec Mourif97df4d2023-09-06 02:10:05 +00004121 .withPixelFormat(std::nullopt)
4122 .withDataspace(kDefaultOutputDataspace)
Alec Mourifcedb9c2022-04-11 20:02:17 +00004123 .thenExpectDisplaySettingsUsed(
4124 {.physicalDisplay = kDefaultOutputDestinationClip,
4125 .clip = kDefaultOutputViewport,
4126 .maxLuminance = kDefaultMaxLuminance,
Leon Scroggins IIIf6280bb2022-05-04 13:20:32 -04004127 .currentLuminanceNits = kDisplayLuminance,
Alec Mourifcedb9c2022-04-11 20:02:17 +00004128 .outputDataspace = kDefaultOutputDataspace,
4129 .colorTransform = kDefaultColorTransformMat,
4130 .deviceHandlesColorTransform = true,
4131 .orientation = kDefaultOutputOrientationFlags,
4132 .targetLuminanceNits = kClientTargetLuminanceNits,
4133 .dimmingStage =
4134 aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR,
4135 .renderIntent = aidl::android::hardware::graphics::composer3::RenderIntent::
4136 COLORIMETRIC})
Lloyd Pique6818fa52019-12-03 12:32:13 -08004137 .execute()
4138 .expectAFenceWasReturned();
4139}
4140
4141TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings, forHdrOnlyClientComposition) {
4142 verify().ifMixedCompositionIs(false)
4143 .andIfUsesHdr(true)
Leon Scroggins IIIf6280bb2022-05-04 13:20:32 -04004144 .withDisplayBrightnessNits(kDisplayLuminance)
Alec Mourif97df4d2023-09-06 02:10:05 +00004145 .withSdrWhitePointNits(kWhitePointLuminance)
Alec Mouri85065692022-03-18 00:58:26 +00004146 .withDimmingStage(aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR)
Alec Mourifcedb9c2022-04-11 20:02:17 +00004147 .withRenderIntent(
4148 aidl::android::hardware::graphics::composer3::RenderIntent::COLORIMETRIC)
Lloyd Pique6818fa52019-12-03 12:32:13 -08004149 .andIfSkipColorTransform(false)
Alec Mourif97df4d2023-09-06 02:10:05 +00004150 .withPixelFormat(std::nullopt)
4151 .withDataspace(kDefaultOutputDataspace)
Alec Mouri85065692022-03-18 00:58:26 +00004152 .thenExpectDisplaySettingsUsed(
4153 {.physicalDisplay = kDefaultOutputDestinationClip,
4154 .clip = kDefaultOutputViewport,
4155 .maxLuminance = kDefaultMaxLuminance,
Leon Scroggins IIIf6280bb2022-05-04 13:20:32 -04004156 .currentLuminanceNits = kDisplayLuminance,
Alec Mouri85065692022-03-18 00:58:26 +00004157 .outputDataspace = kDefaultOutputDataspace,
4158 .colorTransform = kDefaultColorTransformMat,
4159 .deviceHandlesColorTransform = false,
4160 .orientation = kDefaultOutputOrientationFlags,
4161 .targetLuminanceNits = kClientTargetLuminanceNits,
4162 .dimmingStage =
Alec Mourifcedb9c2022-04-11 20:02:17 +00004163 aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR,
4164 .renderIntent = aidl::android::hardware::graphics::composer3::RenderIntent::
4165 COLORIMETRIC})
Lloyd Pique6818fa52019-12-03 12:32:13 -08004166 .execute()
4167 .expectAFenceWasReturned();
4168}
4169
4170TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings, forNonHdrOnlyClientComposition) {
4171 verify().ifMixedCompositionIs(false)
4172 .andIfUsesHdr(false)
Leon Scroggins IIIf6280bb2022-05-04 13:20:32 -04004173 .withDisplayBrightnessNits(kDisplayLuminance)
Alec Mourif97df4d2023-09-06 02:10:05 +00004174 .withSdrWhitePointNits(kWhitePointLuminance)
Alec Mouri85065692022-03-18 00:58:26 +00004175 .withDimmingStage(aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR)
Alec Mourifcedb9c2022-04-11 20:02:17 +00004176 .withRenderIntent(
4177 aidl::android::hardware::graphics::composer3::RenderIntent::COLORIMETRIC)
Lloyd Pique6818fa52019-12-03 12:32:13 -08004178 .andIfSkipColorTransform(false)
Alec Mourif97df4d2023-09-06 02:10:05 +00004179 .withPixelFormat(std::nullopt)
4180 .withDataspace(kDefaultOutputDataspace)
Alec Mouri85065692022-03-18 00:58:26 +00004181 .thenExpectDisplaySettingsUsed(
4182 {.physicalDisplay = kDefaultOutputDestinationClip,
4183 .clip = kDefaultOutputViewport,
4184 .maxLuminance = kDefaultMaxLuminance,
Leon Scroggins IIIf6280bb2022-05-04 13:20:32 -04004185 .currentLuminanceNits = kDisplayLuminance,
Alec Mouri85065692022-03-18 00:58:26 +00004186 .outputDataspace = kDefaultOutputDataspace,
4187 .colorTransform = kDefaultColorTransformMat,
4188 .deviceHandlesColorTransform = false,
4189 .orientation = kDefaultOutputOrientationFlags,
4190 .targetLuminanceNits = kClientTargetLuminanceNits,
4191 .dimmingStage =
Alec Mourifcedb9c2022-04-11 20:02:17 +00004192 aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR,
4193 .renderIntent = aidl::android::hardware::graphics::composer3::RenderIntent::
4194 COLORIMETRIC})
Lloyd Pique6818fa52019-12-03 12:32:13 -08004195 .execute()
4196 .expectAFenceWasReturned();
4197}
4198
4199TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings,
4200 usesExpectedDisplaySettingsForHdrOnlyClientCompositionWithSkipClientTransform) {
4201 verify().ifMixedCompositionIs(false)
4202 .andIfUsesHdr(true)
Leon Scroggins IIIf6280bb2022-05-04 13:20:32 -04004203 .withDisplayBrightnessNits(kDisplayLuminance)
Alec Mourif97df4d2023-09-06 02:10:05 +00004204 .withSdrWhitePointNits(kWhitePointLuminance)
Alec Mouri85065692022-03-18 00:58:26 +00004205 .withDimmingStage(aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR)
Alec Mourifcedb9c2022-04-11 20:02:17 +00004206 .withRenderIntent(
4207 aidl::android::hardware::graphics::composer3::RenderIntent::COLORIMETRIC)
Lloyd Pique6818fa52019-12-03 12:32:13 -08004208 .andIfSkipColorTransform(true)
Alec Mourif97df4d2023-09-06 02:10:05 +00004209 .withPixelFormat(std::nullopt)
4210 .withDataspace(kDefaultOutputDataspace)
Alec Mouri85065692022-03-18 00:58:26 +00004211 .thenExpectDisplaySettingsUsed(
4212 {.physicalDisplay = kDefaultOutputDestinationClip,
4213 .clip = kDefaultOutputViewport,
4214 .maxLuminance = kDefaultMaxLuminance,
Leon Scroggins IIIf6280bb2022-05-04 13:20:32 -04004215 .currentLuminanceNits = kDisplayLuminance,
Alec Mouri85065692022-03-18 00:58:26 +00004216 .outputDataspace = kDefaultOutputDataspace,
4217 .colorTransform = kDefaultColorTransformMat,
4218 .deviceHandlesColorTransform = true,
4219 .orientation = kDefaultOutputOrientationFlags,
4220 .targetLuminanceNits = kClientTargetLuminanceNits,
4221 .dimmingStage =
Alec Mourifcedb9c2022-04-11 20:02:17 +00004222 aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR,
4223 .renderIntent = aidl::android::hardware::graphics::composer3::RenderIntent::
4224 COLORIMETRIC})
Lloyd Pique6818fa52019-12-03 12:32:13 -08004225 .execute()
4226 .expectAFenceWasReturned();
4227}
4228
Alec Mourif97df4d2023-09-06 02:10:05 +00004229TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings,
4230 usesExpectedDisplaySettingsWithFp16Buffer) {
4231 SET_FLAG_FOR_TEST(flags::fp16_client_target, true);
Alec Mourif97df4d2023-09-06 02:10:05 +00004232 verify().ifMixedCompositionIs(false)
4233 .andIfUsesHdr(true)
4234 .withDisplayBrightnessNits(kDisplayLuminance)
4235 .withSdrWhitePointNits(kWhitePointLuminance)
4236 .withDimmingStage(aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR)
4237 .withRenderIntent(
4238 aidl::android::hardware::graphics::composer3::RenderIntent::COLORIMETRIC)
4239 .andIfSkipColorTransform(true)
4240 .withPixelFormat(PIXEL_FORMAT_RGBA_FP16)
4241 .withDataspace(ui::Dataspace::V0_SCRGB)
4242 .thenExpectDisplaySettingsUsed(
4243 {.physicalDisplay = kDefaultOutputDestinationClip,
4244 .clip = kDefaultOutputViewport,
4245 .maxLuminance = kDefaultMaxLuminance,
4246 .currentLuminanceNits = kDisplayLuminance,
4247 .outputDataspace = ui::Dataspace::V0_SCRGB,
4248 .colorTransform = kDefaultColorTransformMat,
4249 .deviceHandlesColorTransform = true,
4250 .orientation = kDefaultOutputOrientationFlags,
4251 .targetLuminanceNits = kClientTargetLuminanceNits * 0.75f,
4252 .dimmingStage =
4253 aidl::android::hardware::graphics::composer3::DimmingStage::LINEAR,
4254 .renderIntent = aidl::android::hardware::graphics::composer3::RenderIntent::
4255 COLORIMETRIC})
4256 .execute()
4257 .expectAFenceWasReturned();
4258}
4259
Lloyd Pique6818fa52019-12-03 12:32:13 -08004260struct OutputComposeSurfacesTest_HandlesProtectedContent : public OutputComposeSurfacesTest {
4261 struct Layer {
4262 Layer() {
Ady Abrahameca9d752021-03-03 12:20:00 -08004263 EXPECT_CALL(*mLayerFE, getCompositionState()).WillRepeatedly(Return(&mLayerFEState));
4264 EXPECT_CALL(mOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*mLayerFE));
Eason Chiu45099662023-10-23 08:55:48 +08004265 EXPECT_CALL(mOutputLayer, requiresClientComposition()).WillRepeatedly(Return(true));
Lloyd Pique6818fa52019-12-03 12:32:13 -08004266 }
4267
4268 StrictMock<mock::OutputLayer> mOutputLayer;
Ady Abrahameca9d752021-03-03 12:20:00 -08004269 sp<StrictMock<mock::LayerFE>> mLayerFE = sp<StrictMock<mock::LayerFE>>::make();
Lloyd Pique6818fa52019-12-03 12:32:13 -08004270 LayerFECompositionState mLayerFEState;
4271 };
4272
4273 OutputComposeSurfacesTest_HandlesProtectedContent() {
4274 mLayer1.mLayerFEState.hasProtectedContent = false;
4275 mLayer2.mLayerFEState.hasProtectedContent = false;
4276
4277 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2u));
4278 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u))
4279 .WillRepeatedly(Return(&mLayer1.mOutputLayer));
4280 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1u))
4281 .WillRepeatedly(Return(&mLayer2.mOutputLayer));
4282
4283 EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false));
4284
4285 EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true));
4286
Robert Carrccab4242021-09-28 16:53:03 -07004287 EXPECT_CALL(mOutput, generateClientCompositionRequests(_, _, _))
Vishnu Nair9b079a22020-01-21 14:36:08 -08004288 .WillRepeatedly(Return(std::vector<LayerFE::LayerSettings>{}));
Lloyd Pique6818fa52019-12-03 12:32:13 -08004289 EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _))
4290 .WillRepeatedly(Return());
4291 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer));
Alec Mourif29700f2023-08-17 21:53:31 +00004292 EXPECT_CALL(mRenderEngine, drawLayers(_, _, _, _))
Patrick Williams2e9748f2022-08-09 22:48:18 +00004293 .WillRepeatedly([&](const renderengine::DisplaySettings&,
4294 const std::vector<renderengine::LayerSettings>&,
4295 const std::shared_ptr<renderengine::ExternalTexture>&,
Alec Mourif29700f2023-08-17 21:53:31 +00004296 base::unique_fd&&) -> ftl::Future<FenceResult> {
Patrick Williams2e9748f2022-08-09 22:48:18 +00004297 return ftl::yield<FenceResult>(Fence::NO_FENCE);
4298 });
Lloyd Pique6818fa52019-12-03 12:32:13 -08004299 }
4300
4301 Layer mLayer1;
4302 Layer mLayer2;
4303};
4304
Lloyd Pique6818fa52019-12-03 12:32:13 -08004305TEST_F(OutputComposeSurfacesTest_HandlesProtectedContent, ifNoProtectedContentLayers) {
Eason Chiu45099662023-10-23 08:55:48 +08004306 SET_FLAG_FOR_TEST(flags::protected_if_client, true);
Chavi Weingartencbec71d2023-12-14 20:53:25 +00004307 if (FlagManager::getInstance().display_protected()) {
4308 mOutput.mState.isProtected = true;
4309 } else {
4310 mOutput.mState.isSecure = true;
4311 }
Lloyd Pique6818fa52019-12-03 12:32:13 -08004312 mLayer2.mLayerFEState.hasProtectedContent = false;
4313 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(true));
Lloyd Pique6818fa52019-12-03 12:32:13 -08004314 EXPECT_CALL(*mRenderSurface, isProtected).WillOnce(Return(true));
Lloyd Pique6818fa52019-12-03 12:32:13 -08004315 EXPECT_CALL(*mRenderSurface, setProtected(false));
4316
Vishnu Naira3140382022-02-24 14:07:11 -08004317 base::unique_fd fd;
4318 std::shared_ptr<renderengine::ExternalTexture> tex;
4319 mOutput.updateProtectedContentState();
4320 mOutput.dequeueRenderBuffer(&fd, &tex);
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00004321 mOutput.composeSurfaces(kDebugRegion, tex, fd);
Lloyd Pique6818fa52019-12-03 12:32:13 -08004322}
4323
4324TEST_F(OutputComposeSurfacesTest_HandlesProtectedContent, ifNotEnabled) {
Eason Chiu45099662023-10-23 08:55:48 +08004325 SET_FLAG_FOR_TEST(flags::protected_if_client, true);
Chavi Weingartencbec71d2023-12-14 20:53:25 +00004326 if (FlagManager::getInstance().display_protected()) {
4327 mOutput.mState.isProtected = true;
4328 } else {
4329 mOutput.mState.isSecure = true;
4330 }
Lloyd Pique6818fa52019-12-03 12:32:13 -08004331 mLayer2.mLayerFEState.hasProtectedContent = true;
4332 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(true));
4333
4334 // For this test, we also check the call order of key functions.
4335 InSequence seq;
4336
Lloyd Pique6818fa52019-12-03 12:32:13 -08004337 EXPECT_CALL(*mRenderSurface, isProtected).WillOnce(Return(false));
Lloyd Pique6818fa52019-12-03 12:32:13 -08004338 EXPECT_CALL(*mRenderSurface, setProtected(true));
4339 // Must happen after setting the protected content state.
4340 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer));
Alec Mourif29700f2023-08-17 21:53:31 +00004341 EXPECT_CALL(mRenderEngine, drawLayers(_, _, _, _))
Patrick Williams2e9748f2022-08-09 22:48:18 +00004342 .WillOnce(Return(ByMove(ftl::yield<FenceResult>(Fence::NO_FENCE))));
Lloyd Pique6818fa52019-12-03 12:32:13 -08004343
Vishnu Naira3140382022-02-24 14:07:11 -08004344 base::unique_fd fd;
4345 std::shared_ptr<renderengine::ExternalTexture> tex;
4346 mOutput.updateProtectedContentState();
4347 mOutput.dequeueRenderBuffer(&fd, &tex);
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00004348 mOutput.composeSurfaces(kDebugRegion, tex, fd);
Lloyd Pique6818fa52019-12-03 12:32:13 -08004349}
4350
4351TEST_F(OutputComposeSurfacesTest_HandlesProtectedContent, ifAlreadyEnabledEverywhere) {
Eason Chiu45099662023-10-23 08:55:48 +08004352 SET_FLAG_FOR_TEST(flags::protected_if_client, true);
Chavi Weingartencbec71d2023-12-14 20:53:25 +00004353 if (FlagManager::getInstance().display_protected()) {
4354 mOutput.mState.isProtected = true;
4355 } else {
4356 mOutput.mState.isSecure = true;
4357 }
Lloyd Pique6818fa52019-12-03 12:32:13 -08004358 mLayer2.mLayerFEState.hasProtectedContent = true;
4359 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(true));
Lloyd Pique6818fa52019-12-03 12:32:13 -08004360 EXPECT_CALL(*mRenderSurface, isProtected).WillOnce(Return(true));
4361
Vishnu Naira3140382022-02-24 14:07:11 -08004362 base::unique_fd fd;
4363 std::shared_ptr<renderengine::ExternalTexture> tex;
4364 mOutput.updateProtectedContentState();
4365 mOutput.dequeueRenderBuffer(&fd, &tex);
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00004366 mOutput.composeSurfaces(kDebugRegion, tex, fd);
Lloyd Pique6818fa52019-12-03 12:32:13 -08004367}
4368
Lloyd Pique6818fa52019-12-03 12:32:13 -08004369TEST_F(OutputComposeSurfacesTest_HandlesProtectedContent, ifAlreadyEnabledInRenderSurface) {
Eason Chiu45099662023-10-23 08:55:48 +08004370 SET_FLAG_FOR_TEST(flags::protected_if_client, true);
Chavi Weingartencbec71d2023-12-14 20:53:25 +00004371 if (FlagManager::getInstance().display_protected()) {
4372 mOutput.mState.isProtected = true;
4373 } else {
4374 mOutput.mState.isSecure = true;
4375 }
Lloyd Pique6818fa52019-12-03 12:32:13 -08004376 mLayer2.mLayerFEState.hasProtectedContent = true;
4377 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(true));
Lloyd Pique6818fa52019-12-03 12:32:13 -08004378 EXPECT_CALL(*mRenderSurface, isProtected).WillOnce(Return(true));
Lloyd Pique6818fa52019-12-03 12:32:13 -08004379
Vishnu Naira3140382022-02-24 14:07:11 -08004380 base::unique_fd fd;
4381 std::shared_ptr<renderengine::ExternalTexture> tex;
4382 mOutput.updateProtectedContentState();
4383 mOutput.dequeueRenderBuffer(&fd, &tex);
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00004384 mOutput.composeSurfaces(kDebugRegion, tex, fd);
Lloyd Pique6818fa52019-12-03 12:32:13 -08004385}
4386
4387struct OutputComposeSurfacesTest_SetsExpensiveRendering : public OutputComposeSurfacesTest {
4388 OutputComposeSurfacesTest_SetsExpensiveRendering() {
4389 EXPECT_CALL(mOutput, getSkipColorTransform()).WillRepeatedly(Return(false));
4390 EXPECT_CALL(*mDisplayColorProfile, hasWideColorGamut()).WillRepeatedly(Return(true));
4391 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(false));
Peiyong Lin09f910f2020-09-25 10:54:13 -07004392 EXPECT_CALL(mRenderEngine, isProtected()).WillRepeatedly(Return(false));
Lloyd Pique6818fa52019-12-03 12:32:13 -08004393 EXPECT_CALL(mOutput, appendRegionFlashRequests(RegionEq(kDebugRegion), _))
4394 .WillRepeatedly(Return());
4395 EXPECT_CALL(*mRenderSurface, dequeueBuffer(_)).WillRepeatedly(Return(mOutputBuffer));
4396 }
4397};
4398
4399TEST_F(OutputComposeSurfacesTest_SetsExpensiveRendering, IfExepensiveOutputDataspaceIsUsed) {
4400 mOutput.mState.dataspace = kExpensiveOutputDataspace;
4401
Leon Scroggins III7bdcceb2022-03-09 16:53:52 -05004402 LayerFE::LayerSettings layerSettings;
Robert Carrccab4242021-09-28 16:53:03 -07004403 EXPECT_CALL(mOutput, generateClientCompositionRequests(_, kExpensiveOutputDataspace, _))
Leon Scroggins III7bdcceb2022-03-09 16:53:52 -05004404 .WillOnce(Return(std::vector<LayerFE::LayerSettings>{layerSettings}));
Lloyd Pique6818fa52019-12-03 12:32:13 -08004405
4406 // For this test, we also check the call order of key functions.
4407 InSequence seq;
4408
4409 EXPECT_CALL(mOutput, setExpensiveRenderingExpected(true));
Alec Mourif29700f2023-08-17 21:53:31 +00004410 EXPECT_CALL(mRenderEngine, drawLayers(_, _, _, _))
Patrick Williams2e9748f2022-08-09 22:48:18 +00004411 .WillOnce(Return(ByMove(ftl::yield<FenceResult>(Fence::NO_FENCE))));
Lloyd Pique6818fa52019-12-03 12:32:13 -08004412
Vishnu Naira3140382022-02-24 14:07:11 -08004413 base::unique_fd fd;
4414 std::shared_ptr<renderengine::ExternalTexture> tex;
4415 mOutput.updateProtectedContentState();
4416 mOutput.dequeueRenderBuffer(&fd, &tex);
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00004417 mOutput.composeSurfaces(kDebugRegion, tex, fd);
Lloyd Pique56eba802019-08-28 15:45:25 -07004418}
4419
4420/*
4421 * Output::generateClientCompositionRequests()
4422 */
4423
4424struct GenerateClientCompositionRequestsTest : public testing::Test {
Lloyd Piquefaa3f192019-11-14 14:05:09 -08004425 struct OutputPartialMock : public OutputPartialMockBase {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -07004426 // compositionengine::Output overrides
Robert Carrccab4242021-09-28 16:53:03 -07004427 std::vector<LayerFE::LayerSettings> generateClientCompositionRequestsHelper(
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00004428 bool supportsProtectedContent, ui::Dataspace dataspace) {
Robert Carrccab4242021-09-28 16:53:03 -07004429 std::vector<LayerFE*> ignore;
Lloyd Pique56eba802019-08-28 15:45:25 -07004430 return impl::Output::generateClientCompositionRequests(supportsProtectedContent,
Robert Carrccab4242021-09-28 16:53:03 -07004431 dataspace, ignore);
Lloyd Pique56eba802019-08-28 15:45:25 -07004432 }
4433 };
4434
Lloyd Piquea4863342019-12-04 18:45:02 -08004435 struct Layer {
4436 Layer() {
Patrick Williams16d8b2c2022-08-08 17:29:05 +00004437 EXPECT_CALL(mOutputLayer, getOverrideCompositionSettings())
4438 .WillRepeatedly(Return(std::nullopt));
Lloyd Piquea4863342019-12-04 18:45:02 -08004439 EXPECT_CALL(mOutputLayer, getState()).WillRepeatedly(ReturnRef(mOutputLayerState));
4440 EXPECT_CALL(mOutputLayer, editState()).WillRepeatedly(ReturnRef(mOutputLayerState));
Ady Abrahameca9d752021-03-03 12:20:00 -08004441 EXPECT_CALL(mOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*mLayerFE));
4442 EXPECT_CALL(*mLayerFE, getCompositionState()).WillRepeatedly(Return(&mLayerFEState));
Lloyd Piquea4863342019-12-04 18:45:02 -08004443 }
4444
4445 StrictMock<mock::OutputLayer> mOutputLayer;
Ady Abrahameca9d752021-03-03 12:20:00 -08004446 sp<StrictMock<mock::LayerFE>> mLayerFE = sp<StrictMock<mock::LayerFE>>::make();
Lloyd Piquea4863342019-12-04 18:45:02 -08004447 LayerFECompositionState mLayerFEState;
4448 impl::OutputLayerCompositionState mOutputLayerState;
Vishnu Nair9b079a22020-01-21 14:36:08 -08004449 LayerFE::LayerSettings mLayerSettings;
Lloyd Piquea4863342019-12-04 18:45:02 -08004450 };
4451
Lloyd Pique56eba802019-08-28 15:45:25 -07004452 GenerateClientCompositionRequestsTest() {
Lloyd Piquea4863342019-12-04 18:45:02 -08004453 mOutput.mState.needsFiltering = false;
Chavi Weingartencbec71d2023-12-14 20:53:25 +00004454 mOutput.mState.isProtected = true;
Lloyd Piquea4863342019-12-04 18:45:02 -08004455
Lloyd Pique56eba802019-08-28 15:45:25 -07004456 mOutput.setDisplayColorProfileForTest(
4457 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
4458 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
4459 }
4460
Alec Mouricdf6cbc2021-11-01 17:21:15 -07004461 static constexpr float kLayerWhitePointNits = 200.f;
4462
Lloyd Pique56eba802019-08-28 15:45:25 -07004463 mock::DisplayColorProfile* mDisplayColorProfile = new StrictMock<mock::DisplayColorProfile>();
4464 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -07004465 StrictMock<OutputPartialMock> mOutput;
Lloyd Pique56eba802019-08-28 15:45:25 -07004466};
4467
Lloyd Piquea4863342019-12-04 18:45:02 -08004468struct GenerateClientCompositionRequestsTest_ThreeLayers
4469 : public GenerateClientCompositionRequestsTest {
4470 GenerateClientCompositionRequestsTest_ThreeLayers() {
Angel Aguayob084e0c2021-08-04 23:27:28 +00004471 mOutput.mState.orientedDisplaySpace.setContent(kDisplayFrame);
4472 mOutput.mState.layerStackSpace.setContent(kDisplayViewport);
4473 mOutput.mState.displaySpace.setContent(kDisplayDestinationClip);
Marin Shalamanov68933fb2020-09-10 17:58:12 +02004474 mOutput.mState.transform =
4475 ui::Transform{ui::Transform::toRotationFlags(kDisplayOrientation)};
Angel Aguayob084e0c2021-08-04 23:27:28 +00004476 mOutput.mState.displaySpace.setOrientation(kDisplayOrientation);
Lloyd Piquea4863342019-12-04 18:45:02 -08004477 mOutput.mState.needsFiltering = false;
4478 mOutput.mState.isSecure = false;
Chavi Weingartencbec71d2023-12-14 20:53:25 +00004479 mOutput.mState.isProtected = true;
Lloyd Pique56eba802019-08-28 15:45:25 -07004480
Lloyd Piquea4863342019-12-04 18:45:02 -08004481 for (size_t i = 0; i < mLayers.size(); i++) {
4482 mLayers[i].mOutputLayerState.clearClientTarget = false;
4483 mLayers[i].mOutputLayerState.visibleRegion = Region(kDisplayFrame);
4484 mLayers[i].mLayerFEState.isOpaque = true;
Vishnu Nair9b079a22020-01-21 14:36:08 -08004485 mLayers[i].mLayerSettings.geometry.boundaries =
Lloyd Piquea4863342019-12-04 18:45:02 -08004486 FloatRect{static_cast<float>(i + 1), 0.f, 0.f, 0.f};
Vishnu Nair9b079a22020-01-21 14:36:08 -08004487 mLayers[i].mLayerSettings.source.solidColor = {1.0f, 1.0f, 1.0f};
4488 mLayers[i].mLayerSettings.alpha = 1.0f;
4489 mLayers[i].mLayerSettings.disableBlending = false;
Lloyd Pique56eba802019-08-28 15:45:25 -07004490
Lloyd Piquea4863342019-12-04 18:45:02 -08004491 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(i))
4492 .WillRepeatedly(Return(&mLayers[i].mOutputLayer));
4493 EXPECT_CALL(mLayers[i].mOutputLayer, requiresClientComposition())
4494 .WillRepeatedly(Return(true));
4495 EXPECT_CALL(mLayers[i].mOutputLayer, needsFiltering()).WillRepeatedly(Return(false));
4496 }
Lloyd Pique56eba802019-08-28 15:45:25 -07004497
Lloyd Piquea4863342019-12-04 18:45:02 -08004498 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(mLayers.size()));
4499 }
Lloyd Pique56eba802019-08-28 15:45:25 -07004500
Marin Shalamanov68933fb2020-09-10 17:58:12 +02004501 static constexpr ui::Rotation kDisplayOrientation = ui::ROTATION_0;
Lloyd Piquea4863342019-12-04 18:45:02 -08004502 static constexpr ui::Dataspace kDisplayDataspace = ui::Dataspace::UNKNOWN;
Alec Mouricdf6cbc2021-11-01 17:21:15 -07004503 static constexpr float kLayerWhitePointNits = 200.f;
Lloyd Pique56eba802019-08-28 15:45:25 -07004504
Lloyd Piquea4863342019-12-04 18:45:02 -08004505 static const Rect kDisplayFrame;
4506 static const Rect kDisplayViewport;
Lloyd Piquee8fe4742020-01-21 15:26:18 -08004507 static const Rect kDisplayDestinationClip;
Lloyd Pique56eba802019-08-28 15:45:25 -07004508
Lloyd Piquea4863342019-12-04 18:45:02 -08004509 std::array<Layer, 3> mLayers;
4510};
Lloyd Pique56eba802019-08-28 15:45:25 -07004511
Lloyd Piquea4863342019-12-04 18:45:02 -08004512const Rect GenerateClientCompositionRequestsTest_ThreeLayers::kDisplayFrame(0, 0, 100, 200);
4513const Rect GenerateClientCompositionRequestsTest_ThreeLayers::kDisplayViewport(0, 0, 101, 201);
Lloyd Piquee8fe4742020-01-21 15:26:18 -08004514const Rect GenerateClientCompositionRequestsTest_ThreeLayers::kDisplayDestinationClip(0, 0, 103,
4515 203);
Lloyd Pique56eba802019-08-28 15:45:25 -07004516
Lloyd Piquea4863342019-12-04 18:45:02 -08004517TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, handlesNoClientCompostionLayers) {
4518 EXPECT_CALL(mLayers[0].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
4519 EXPECT_CALL(mLayers[1].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
4520 EXPECT_CALL(mLayers[2].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
Lloyd Pique56eba802019-08-28 15:45:25 -07004521
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00004522 auto requests =
4523 mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */,
4524 kDisplayDataspace);
Lloyd Pique56eba802019-08-28 15:45:25 -07004525 EXPECT_EQ(0u, requests.size());
4526}
4527
Lloyd Piquea4863342019-12-04 18:45:02 -08004528TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, requiresVisibleRegionAfterViewportClip) {
4529 mLayers[0].mOutputLayerState.visibleRegion = Region(Rect(10, 10, 10, 10));
4530 mLayers[1].mOutputLayerState.visibleRegion = Region(Rect(4000, 0, 4010, 10));
4531 mLayers[2].mOutputLayerState.visibleRegion = Region(Rect(-10, -10, 0, 0));
4532
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00004533 auto requests =
4534 mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */,
4535 kDisplayDataspace);
Lloyd Piquea4863342019-12-04 18:45:02 -08004536 EXPECT_EQ(0u, requests.size());
Lloyd Piquea4863342019-12-04 18:45:02 -08004537}
4538
4539TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, gathersClientCompositionRequests) {
Patrick Williams16d8b2c2022-08-08 17:29:05 +00004540 EXPECT_CALL(*mLayers[0].mLayerFE, prepareClientComposition(_))
4541 .WillOnce(Return(std::optional<LayerFE::LayerSettings>()));
4542 EXPECT_CALL(*mLayers[1].mLayerFE, prepareClientComposition(_))
4543 .WillOnce(Return(std::optional<LayerFE::LayerSettings>(mLayers[1].mLayerSettings)));
4544 EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientComposition(_))
4545 .WillOnce(Return(std::optional<LayerFE::LayerSettings>(mLayers[2].mLayerSettings)));
Lloyd Piquea4863342019-12-04 18:45:02 -08004546
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00004547 auto requests =
4548 mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */,
4549 kDisplayDataspace);
Patrick Williams16d8b2c2022-08-08 17:29:05 +00004550 ASSERT_EQ(2u, requests.size());
Vishnu Nair9b079a22020-01-21 14:36:08 -08004551 EXPECT_EQ(mLayers[1].mLayerSettings, requests[0]);
Patrick Williams16d8b2c2022-08-08 17:29:05 +00004552 EXPECT_EQ(mLayers[2].mLayerSettings, requests[1]);
Lloyd Piquea4863342019-12-04 18:45:02 -08004553
Lloyd Piquea4863342019-12-04 18:45:02 -08004554 // Check that a timestamp was set for the layers that generated requests
4555 EXPECT_TRUE(0 == mLayers[0].mOutputLayerState.clientCompositionTimestamp);
4556 EXPECT_TRUE(0 != mLayers[1].mOutputLayerState.clientCompositionTimestamp);
4557 EXPECT_TRUE(0 != mLayers[2].mOutputLayerState.clientCompositionTimestamp);
4558}
4559
Alec Mourif54453c2021-05-13 16:28:28 -07004560MATCHER_P(ClientCompositionTargetSettingsBlurSettingsEq, expectedBlurSetting, "") {
4561 *result_listener << "ClientCompositionTargetSettings' BlurSettings aren't equal \n";
4562 *result_listener << "expected " << expectedBlurSetting << "\n";
4563 *result_listener << "actual " << arg.blurSetting << "\n";
4564
4565 return expectedBlurSetting == arg.blurSetting;
4566}
4567
4568TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, overridesBlur) {
Alec Mourif54453c2021-05-13 16:28:28 -07004569 mLayers[2].mOutputLayerState.overrideInfo.disableBackgroundBlur = true;
4570
Patrick Williams16d8b2c2022-08-08 17:29:05 +00004571 EXPECT_CALL(*mLayers[0].mLayerFE, prepareClientComposition(_))
4572 .WillOnce(Return(std::optional<LayerFE::LayerSettings>()));
4573 EXPECT_CALL(*mLayers[1].mLayerFE, prepareClientComposition(_))
4574 .WillOnce(Return(std::optional<LayerFE::LayerSettings>(mLayers[1].mLayerSettings)));
Alec Mourif54453c2021-05-13 16:28:28 -07004575 EXPECT_CALL(*mLayers[2].mLayerFE,
Patrick Williams16d8b2c2022-08-08 17:29:05 +00004576 prepareClientComposition(ClientCompositionTargetSettingsBlurSettingsEq(
Alec Mourif54453c2021-05-13 16:28:28 -07004577 LayerFE::ClientCompositionTargetSettings::BlurSetting::BlurRegionsOnly)))
Patrick Williams16d8b2c2022-08-08 17:29:05 +00004578 .WillOnce(Return(std::optional<LayerFE::LayerSettings>(mLayers[2].mLayerSettings)));
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00004579 auto requests =
4580 mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */,
4581 kDisplayDataspace);
Patrick Williams16d8b2c2022-08-08 17:29:05 +00004582 ASSERT_EQ(2u, requests.size());
Alec Mourif54453c2021-05-13 16:28:28 -07004583 EXPECT_EQ(mLayers[1].mLayerSettings, requests[0]);
Patrick Williams16d8b2c2022-08-08 17:29:05 +00004584 EXPECT_EQ(mLayers[2].mLayerSettings, requests[1]);
Alec Mourif54453c2021-05-13 16:28:28 -07004585
Alec Mourif54453c2021-05-13 16:28:28 -07004586 // Check that a timestamp was set for the layers that generated requests
4587 EXPECT_TRUE(0 == mLayers[0].mOutputLayerState.clientCompositionTimestamp);
4588 EXPECT_TRUE(0 != mLayers[1].mOutputLayerState.clientCompositionTimestamp);
4589 EXPECT_TRUE(0 != mLayers[2].mOutputLayerState.clientCompositionTimestamp);
4590}
4591
Lloyd Piquea4863342019-12-04 18:45:02 -08004592TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,
4593 onlyClientComposesClientComposedLayersIfNoClearingNeeded) {
4594 EXPECT_CALL(mLayers[0].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
4595 EXPECT_CALL(mLayers[1].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
4596 EXPECT_CALL(mLayers[2].mOutputLayer, requiresClientComposition()).WillOnce(Return(true));
4597
4598 mLayers[0].mOutputLayerState.clearClientTarget = false;
4599 mLayers[1].mOutputLayerState.clearClientTarget = false;
4600 mLayers[2].mOutputLayerState.clearClientTarget = false;
4601
4602 mLayers[0].mLayerFEState.isOpaque = true;
4603 mLayers[1].mLayerFEState.isOpaque = true;
4604 mLayers[2].mLayerFEState.isOpaque = true;
4605
Patrick Williams16d8b2c2022-08-08 17:29:05 +00004606 EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientComposition(_))
4607 .WillOnce(Return(std::optional<LayerFE::LayerSettings>(mLayers[2].mLayerSettings)));
Lloyd Piquea4863342019-12-04 18:45:02 -08004608
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00004609 auto requests =
4610 mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */,
4611 kDisplayDataspace);
Lloyd Piquea4863342019-12-04 18:45:02 -08004612 ASSERT_EQ(1u, requests.size());
Vishnu Nair9b079a22020-01-21 14:36:08 -08004613 EXPECT_EQ(mLayers[2].mLayerSettings, requests[0]);
Lloyd Piquea4863342019-12-04 18:45:02 -08004614}
4615
4616TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,
4617 onlyClientComposesClientComposedLayersIfOthersAreNotOpaque) {
4618 EXPECT_CALL(mLayers[0].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
4619 EXPECT_CALL(mLayers[1].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
4620 EXPECT_CALL(mLayers[2].mOutputLayer, requiresClientComposition()).WillOnce(Return(true));
4621
4622 mLayers[0].mOutputLayerState.clearClientTarget = true;
4623 mLayers[1].mOutputLayerState.clearClientTarget = true;
4624 mLayers[2].mOutputLayerState.clearClientTarget = true;
4625
4626 mLayers[0].mLayerFEState.isOpaque = false;
4627 mLayers[1].mLayerFEState.isOpaque = false;
4628 mLayers[2].mLayerFEState.isOpaque = false;
4629
Patrick Williams16d8b2c2022-08-08 17:29:05 +00004630 EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientComposition(_))
4631 .WillOnce(Return(std::optional<LayerFE::LayerSettings>(mLayers[2].mLayerSettings)));
Lloyd Piquea4863342019-12-04 18:45:02 -08004632
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00004633 auto requests =
4634 mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */,
4635 kDisplayDataspace);
Lloyd Piquea4863342019-12-04 18:45:02 -08004636 ASSERT_EQ(1u, requests.size());
Vishnu Nair9b079a22020-01-21 14:36:08 -08004637 EXPECT_EQ(mLayers[2].mLayerSettings, requests[0]);
Lloyd Piquea4863342019-12-04 18:45:02 -08004638}
4639
4640TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers, clearsHWCLayersIfOpaqueAndNotFirst) {
Lloyd Piquec2d54d42019-08-28 18:04:21 -07004641 // If client composition is performed with some layers set to use device
4642 // composition, device layers after the first layer (device or client) will
4643 // clear the frame buffer if they are opaque and if that layer has a flag
4644 // set to do so. The first layer is skipped as the frame buffer is already
4645 // expected to be clear.
4646
Lloyd Piquea4863342019-12-04 18:45:02 -08004647 EXPECT_CALL(mLayers[0].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
4648 EXPECT_CALL(mLayers[1].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
4649 EXPECT_CALL(mLayers[2].mOutputLayer, requiresClientComposition()).WillOnce(Return(true));
Lloyd Piquec2d54d42019-08-28 18:04:21 -07004650
Lloyd Piquea4863342019-12-04 18:45:02 -08004651 mLayers[0].mOutputLayerState.clearClientTarget = true;
4652 mLayers[1].mOutputLayerState.clearClientTarget = true;
4653 mLayers[2].mOutputLayerState.clearClientTarget = true;
Lloyd Piquec2d54d42019-08-28 18:04:21 -07004654
Lloyd Piquea4863342019-12-04 18:45:02 -08004655 mLayers[0].mLayerFEState.isOpaque = true;
4656 mLayers[1].mLayerFEState.isOpaque = true;
4657 mLayers[2].mLayerFEState.isOpaque = true;
Vishnu Nairb87d94f2020-02-13 09:17:36 -08004658
4659 compositionengine::LayerFE::ClientCompositionTargetSettings layer1TargetSettings{
4660 Region(kDisplayFrame),
Alec Mouricdf6cbc2021-11-01 17:21:15 -07004661 false, /* needs filtering */
4662 false, /* secure */
4663 false, /* supports protected content */
Vishnu Nairb87d94f2020-02-13 09:17:36 -08004664 kDisplayViewport,
4665 kDisplayDataspace,
4666 false /* realContentIsVisible */,
4667 true /* clearContent */,
Alec Mourif54453c2021-05-13 16:28:28 -07004668 compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled,
Alec Mouricdf6cbc2021-11-01 17:21:15 -07004669 kLayerWhitePointNits,
Vishnu Naire14c6b32022-08-06 04:20:15 +00004670 false /* treat170mAsSrgb */,
Vishnu Nairb87d94f2020-02-13 09:17:36 -08004671 };
4672 compositionengine::LayerFE::ClientCompositionTargetSettings layer2TargetSettings{
4673 Region(kDisplayFrame),
Vishnu Nairb87d94f2020-02-13 09:17:36 -08004674 false, /* needs filtering */
4675 false, /* secure */
4676 false, /* supports protected content */
Vishnu Nairb87d94f2020-02-13 09:17:36 -08004677 kDisplayViewport,
4678 kDisplayDataspace,
4679 true /* realContentIsVisible */,
4680 false /* clearContent */,
Alec Mourif54453c2021-05-13 16:28:28 -07004681 compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled,
Alec Mouricdf6cbc2021-11-01 17:21:15 -07004682 kLayerWhitePointNits,
Vishnu Naire14c6b32022-08-06 04:20:15 +00004683 false /* treat170mAsSrgb */,
Vishnu Nairb87d94f2020-02-13 09:17:36 -08004684 };
4685
4686 LayerFE::LayerSettings mBlackoutSettings = mLayers[1].mLayerSettings;
4687 mBlackoutSettings.source.buffer.buffer = nullptr;
4688 mBlackoutSettings.source.solidColor = {0.1f, 0.1f, 0.1f};
4689 mBlackoutSettings.alpha = 0.f;
4690 mBlackoutSettings.disableBlending = true;
4691
Patrick Williams16d8b2c2022-08-08 17:29:05 +00004692 EXPECT_CALL(*mLayers[1].mLayerFE, prepareClientComposition(Eq(ByRef(layer1TargetSettings))))
4693 .WillOnce(Return(std::optional<LayerFE::LayerSettings>(mBlackoutSettings)));
4694 EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientComposition(Eq(ByRef(layer2TargetSettings))))
4695 .WillOnce(Return(std::optional<LayerFE::LayerSettings>(mLayers[2].mLayerSettings)));
Vishnu Nairb87d94f2020-02-13 09:17:36 -08004696
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00004697 auto requests =
4698 mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */,
4699 kDisplayDataspace);
Lloyd Piquea4863342019-12-04 18:45:02 -08004700 ASSERT_EQ(2u, requests.size());
Lloyd Piquec2d54d42019-08-28 18:04:21 -07004701
Lloyd Piquea4863342019-12-04 18:45:02 -08004702 // The second layer is expected to be rendered as alpha=0 black with no blending
Vishnu Nairb87d94f2020-02-13 09:17:36 -08004703 EXPECT_EQ(mBlackoutSettings, requests[0]);
Lloyd Piquec2d54d42019-08-28 18:04:21 -07004704
Vishnu Nair9b079a22020-01-21 14:36:08 -08004705 EXPECT_EQ(mLayers[2].mLayerSettings, requests[1]);
Lloyd Piquea4863342019-12-04 18:45:02 -08004706}
Lloyd Piquec2d54d42019-08-28 18:04:21 -07004707
Lloyd Piquea4863342019-12-04 18:45:02 -08004708TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,
4709 clippedVisibleRegionUsedToGenerateRequest) {
4710 mLayers[0].mOutputLayerState.visibleRegion = Region(Rect(10, 10, 20, 20));
4711 mLayers[1].mOutputLayerState.visibleRegion = Region(Rect(-10, -10, 30, 30));
4712 mLayers[2].mOutputLayerState.visibleRegion = Region(Rect(-10, 0, 40, 4000));
Lloyd Piquec2d54d42019-08-28 18:04:21 -07004713
Lloyd Piquea4863342019-12-04 18:45:02 -08004714 compositionengine::LayerFE::ClientCompositionTargetSettings layer0TargetSettings{
4715 Region(Rect(10, 10, 20, 20)),
Lloyd Piquea4863342019-12-04 18:45:02 -08004716 false, /* needs filtering */
4717 false, /* secure */
4718 false, /* supports protected content */
Vishnu Nairb87d94f2020-02-13 09:17:36 -08004719 kDisplayViewport,
4720 kDisplayDataspace,
4721 true /* realContentIsVisible */,
4722 false /* clearContent */,
Alec Mourif54453c2021-05-13 16:28:28 -07004723 compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled,
Alec Mouricdf6cbc2021-11-01 17:21:15 -07004724 kLayerWhitePointNits,
Vishnu Naire14c6b32022-08-06 04:20:15 +00004725 false /* treat170mAsSrgb */,
Lloyd Piquea4863342019-12-04 18:45:02 -08004726 };
4727 compositionengine::LayerFE::ClientCompositionTargetSettings layer1TargetSettings{
4728 Region(Rect(0, 0, 30, 30)),
Lloyd Piquea4863342019-12-04 18:45:02 -08004729 false, /* needs filtering */
4730 false, /* secure */
4731 false, /* supports protected content */
Vishnu Nairb87d94f2020-02-13 09:17:36 -08004732 kDisplayViewport,
4733 kDisplayDataspace,
4734 true /* realContentIsVisible */,
4735 false /* clearContent */,
Alec Mourif54453c2021-05-13 16:28:28 -07004736 compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled,
Alec Mouricdf6cbc2021-11-01 17:21:15 -07004737 kLayerWhitePointNits,
Vishnu Naire14c6b32022-08-06 04:20:15 +00004738 false /* treat170mAsSrgb */,
Lloyd Piquea4863342019-12-04 18:45:02 -08004739 };
4740 compositionengine::LayerFE::ClientCompositionTargetSettings layer2TargetSettings{
4741 Region(Rect(0, 0, 40, 201)),
Lloyd Piquea4863342019-12-04 18:45:02 -08004742 false, /* needs filtering */
4743 false, /* secure */
4744 false, /* supports protected content */
Vishnu Nairb87d94f2020-02-13 09:17:36 -08004745 kDisplayViewport,
4746 kDisplayDataspace,
4747 true /* realContentIsVisible */,
4748 false /* clearContent */,
Alec Mourif54453c2021-05-13 16:28:28 -07004749 compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled,
Alec Mouricdf6cbc2021-11-01 17:21:15 -07004750 kLayerWhitePointNits,
Vishnu Naire14c6b32022-08-06 04:20:15 +00004751 false /* treat170mAsSrgb */,
Lloyd Piquea4863342019-12-04 18:45:02 -08004752 };
4753
Patrick Williams16d8b2c2022-08-08 17:29:05 +00004754 EXPECT_CALL(*mLayers[0].mLayerFE, prepareClientComposition(Eq(ByRef(layer0TargetSettings))))
4755 .WillOnce(Return(std::optional<LayerFE::LayerSettings>()));
4756 EXPECT_CALL(*mLayers[1].mLayerFE, prepareClientComposition(Eq(ByRef(layer1TargetSettings))))
4757 .WillOnce(Return(std::optional<LayerFE::LayerSettings>()));
4758 EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientComposition(Eq(ByRef(layer2TargetSettings))))
4759 .WillOnce(Return(std::optional<LayerFE::LayerSettings>()));
Lloyd Piquea4863342019-12-04 18:45:02 -08004760
4761 static_cast<void>(
Robert Carrccab4242021-09-28 16:53:03 -07004762 mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */,
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00004763 kDisplayDataspace));
Lloyd Piquea4863342019-12-04 18:45:02 -08004764}
4765
4766TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,
4767 perLayerNeedsFilteringUsedToGenerateRequests) {
4768 mOutput.mState.needsFiltering = false;
4769 EXPECT_CALL(mLayers[0].mOutputLayer, needsFiltering()).WillRepeatedly(Return(true));
4770
Lloyd Piquea4863342019-12-04 18:45:02 -08004771 compositionengine::LayerFE::ClientCompositionTargetSettings layer0TargetSettings{
4772 Region(kDisplayFrame),
Lloyd Piquea4863342019-12-04 18:45:02 -08004773 true, /* needs filtering */
4774 false, /* secure */
4775 false, /* supports protected content */
Vishnu Nairb87d94f2020-02-13 09:17:36 -08004776 kDisplayViewport,
4777 kDisplayDataspace,
4778 true /* realContentIsVisible */,
4779 false /* clearContent */,
Alec Mourif54453c2021-05-13 16:28:28 -07004780 compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled,
Alec Mouricdf6cbc2021-11-01 17:21:15 -07004781 kLayerWhitePointNits,
Vishnu Naire14c6b32022-08-06 04:20:15 +00004782 false /* treat170mAsSrgb */,
Lloyd Piquea4863342019-12-04 18:45:02 -08004783 };
4784 compositionengine::LayerFE::ClientCompositionTargetSettings layer1TargetSettings{
4785 Region(kDisplayFrame),
Lloyd Piquea4863342019-12-04 18:45:02 -08004786 false, /* needs filtering */
4787 false, /* secure */
4788 false, /* supports protected content */
Vishnu Nairb87d94f2020-02-13 09:17:36 -08004789 kDisplayViewport,
4790 kDisplayDataspace,
4791 true /* realContentIsVisible */,
4792 false /* clearContent */,
Alec Mourif54453c2021-05-13 16:28:28 -07004793 compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled,
Alec Mouricdf6cbc2021-11-01 17:21:15 -07004794 kLayerWhitePointNits,
Vishnu Naire14c6b32022-08-06 04:20:15 +00004795 false /* treat170mAsSrgb */,
Lloyd Piquea4863342019-12-04 18:45:02 -08004796 };
4797 compositionengine::LayerFE::ClientCompositionTargetSettings layer2TargetSettings{
4798 Region(kDisplayFrame),
Lloyd Piquea4863342019-12-04 18:45:02 -08004799 false, /* needs filtering */
4800 false, /* secure */
4801 false, /* supports protected content */
Vishnu Nairb87d94f2020-02-13 09:17:36 -08004802 kDisplayViewport,
4803 kDisplayDataspace,
4804 true /* realContentIsVisible */,
4805 false /* clearContent */,
Alec Mourif54453c2021-05-13 16:28:28 -07004806 compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled,
Alec Mouricdf6cbc2021-11-01 17:21:15 -07004807 kLayerWhitePointNits,
Vishnu Naire14c6b32022-08-06 04:20:15 +00004808 false /* treat170mAsSrgb */,
Lloyd Piquea4863342019-12-04 18:45:02 -08004809 };
4810
Patrick Williams16d8b2c2022-08-08 17:29:05 +00004811 EXPECT_CALL(*mLayers[0].mLayerFE, prepareClientComposition(Eq(ByRef(layer0TargetSettings))))
4812 .WillOnce(Return(std::optional<LayerFE::LayerSettings>()));
4813 EXPECT_CALL(*mLayers[1].mLayerFE, prepareClientComposition(Eq(ByRef(layer1TargetSettings))))
4814 .WillOnce(Return(std::optional<LayerFE::LayerSettings>()));
4815 EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientComposition(Eq(ByRef(layer2TargetSettings))))
4816 .WillOnce(Return(std::optional<LayerFE::LayerSettings>()));
Lloyd Piquea4863342019-12-04 18:45:02 -08004817
4818 static_cast<void>(
Robert Carrccab4242021-09-28 16:53:03 -07004819 mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */,
4820 kDisplayDataspace));
Lloyd Piquea4863342019-12-04 18:45:02 -08004821}
4822
4823TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,
4824 wholeOutputNeedsFilteringUsedToGenerateRequests) {
4825 mOutput.mState.needsFiltering = true;
4826 EXPECT_CALL(mLayers[0].mOutputLayer, needsFiltering()).WillRepeatedly(Return(true));
4827
Lloyd Piquea4863342019-12-04 18:45:02 -08004828 compositionengine::LayerFE::ClientCompositionTargetSettings layer0TargetSettings{
4829 Region(kDisplayFrame),
Lloyd Piquea4863342019-12-04 18:45:02 -08004830 true, /* needs filtering */
4831 false, /* secure */
4832 false, /* supports protected content */
Vishnu Nairb87d94f2020-02-13 09:17:36 -08004833 kDisplayViewport,
4834 kDisplayDataspace,
4835 true /* realContentIsVisible */,
4836 false /* clearContent */,
Alec Mourif54453c2021-05-13 16:28:28 -07004837 compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled,
Alec Mouricdf6cbc2021-11-01 17:21:15 -07004838 kLayerWhitePointNits,
Vishnu Naire14c6b32022-08-06 04:20:15 +00004839 false /* treat170mAsSrgb */,
Lloyd Piquea4863342019-12-04 18:45:02 -08004840 };
4841 compositionengine::LayerFE::ClientCompositionTargetSettings layer1TargetSettings{
4842 Region(kDisplayFrame),
Lloyd Piquea4863342019-12-04 18:45:02 -08004843 true, /* needs filtering */
4844 false, /* secure */
4845 false, /* supports protected content */
Vishnu Nairb87d94f2020-02-13 09:17:36 -08004846 kDisplayViewport,
4847 kDisplayDataspace,
4848 true /* realContentIsVisible */,
4849 false /* clearContent */,
Alec Mourif54453c2021-05-13 16:28:28 -07004850 compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled,
Alec Mouricdf6cbc2021-11-01 17:21:15 -07004851 kLayerWhitePointNits,
Vishnu Naire14c6b32022-08-06 04:20:15 +00004852 false /* treat170mAsSrgb */,
Lloyd Piquea4863342019-12-04 18:45:02 -08004853 };
4854 compositionengine::LayerFE::ClientCompositionTargetSettings layer2TargetSettings{
4855 Region(kDisplayFrame),
Lloyd Piquea4863342019-12-04 18:45:02 -08004856 true, /* needs filtering */
4857 false, /* secure */
4858 false, /* supports protected content */
Vishnu Nairb87d94f2020-02-13 09:17:36 -08004859 kDisplayViewport,
4860 kDisplayDataspace,
4861 true /* realContentIsVisible */,
4862 false /* clearContent */,
Alec Mourif54453c2021-05-13 16:28:28 -07004863 compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled,
Alec Mouricdf6cbc2021-11-01 17:21:15 -07004864 kLayerWhitePointNits,
Vishnu Naire14c6b32022-08-06 04:20:15 +00004865 false /* treat170mAsSrgb */,
Lloyd Piquea4863342019-12-04 18:45:02 -08004866 };
4867
Patrick Williams16d8b2c2022-08-08 17:29:05 +00004868 EXPECT_CALL(*mLayers[0].mLayerFE, prepareClientComposition(Eq(ByRef(layer0TargetSettings))))
4869 .WillOnce(Return(std::optional<LayerFE::LayerSettings>()));
4870 EXPECT_CALL(*mLayers[1].mLayerFE, prepareClientComposition(Eq(ByRef(layer1TargetSettings))))
4871 .WillOnce(Return(std::optional<LayerFE::LayerSettings>()));
4872 EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientComposition(Eq(ByRef(layer2TargetSettings))))
4873 .WillOnce(Return(std::optional<LayerFE::LayerSettings>()));
Lloyd Piquea4863342019-12-04 18:45:02 -08004874
4875 static_cast<void>(
Robert Carrccab4242021-09-28 16:53:03 -07004876 mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */,
4877 kDisplayDataspace));
Lloyd Piquea4863342019-12-04 18:45:02 -08004878}
4879
4880TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,
4881 wholeOutputSecurityUsedToGenerateRequests) {
4882 mOutput.mState.isSecure = true;
4883
Lloyd Piquea4863342019-12-04 18:45:02 -08004884 compositionengine::LayerFE::ClientCompositionTargetSettings layer0TargetSettings{
4885 Region(kDisplayFrame),
Lloyd Piquea4863342019-12-04 18:45:02 -08004886 false, /* needs filtering */
4887 true, /* secure */
4888 false, /* supports protected content */
Vishnu Nairb87d94f2020-02-13 09:17:36 -08004889 kDisplayViewport,
4890 kDisplayDataspace,
4891 true /* realContentIsVisible */,
4892 false /* clearContent */,
Alec Mourif54453c2021-05-13 16:28:28 -07004893 compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled,
Alec Mouricdf6cbc2021-11-01 17:21:15 -07004894 kLayerWhitePointNits,
Vishnu Naire14c6b32022-08-06 04:20:15 +00004895 false /* treat170mAsSrgb */,
Lloyd Piquea4863342019-12-04 18:45:02 -08004896 };
4897 compositionengine::LayerFE::ClientCompositionTargetSettings layer1TargetSettings{
4898 Region(kDisplayFrame),
Lloyd Piquea4863342019-12-04 18:45:02 -08004899 false, /* needs filtering */
4900 true, /* secure */
4901 false, /* supports protected content */
Vishnu Nairb87d94f2020-02-13 09:17:36 -08004902 kDisplayViewport,
4903 kDisplayDataspace,
4904 true /* realContentIsVisible */,
4905 false /* clearContent */,
Alec Mourif54453c2021-05-13 16:28:28 -07004906 compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled,
Alec Mouricdf6cbc2021-11-01 17:21:15 -07004907 kLayerWhitePointNits,
Vishnu Naire14c6b32022-08-06 04:20:15 +00004908 false /* treat170mAsSrgb */,
Lloyd Piquea4863342019-12-04 18:45:02 -08004909 };
4910 compositionengine::LayerFE::ClientCompositionTargetSettings layer2TargetSettings{
4911 Region(kDisplayFrame),
Lloyd Piquea4863342019-12-04 18:45:02 -08004912 false, /* needs filtering */
4913 true, /* secure */
4914 false, /* supports protected content */
Vishnu Nairb87d94f2020-02-13 09:17:36 -08004915 kDisplayViewport,
4916 kDisplayDataspace,
4917 true /* realContentIsVisible */,
4918 false /* clearContent */,
Alec Mourif54453c2021-05-13 16:28:28 -07004919 compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled,
Alec Mouricdf6cbc2021-11-01 17:21:15 -07004920 kLayerWhitePointNits,
Vishnu Naire14c6b32022-08-06 04:20:15 +00004921 false /* treat170mAsSrgb */,
Lloyd Piquea4863342019-12-04 18:45:02 -08004922 };
4923
Patrick Williams16d8b2c2022-08-08 17:29:05 +00004924 EXPECT_CALL(*mLayers[0].mLayerFE, prepareClientComposition(Eq(ByRef(layer0TargetSettings))))
4925 .WillOnce(Return(std::optional<LayerFE::LayerSettings>()));
4926 EXPECT_CALL(*mLayers[1].mLayerFE, prepareClientComposition(Eq(ByRef(layer1TargetSettings))))
4927 .WillOnce(Return(std::optional<LayerFE::LayerSettings>()));
4928 EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientComposition(Eq(ByRef(layer2TargetSettings))))
4929 .WillOnce(Return(std::optional<LayerFE::LayerSettings>()));
Lloyd Piquea4863342019-12-04 18:45:02 -08004930
4931 static_cast<void>(
Robert Carrccab4242021-09-28 16:53:03 -07004932 mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */,
4933 kDisplayDataspace));
Lloyd Piquea4863342019-12-04 18:45:02 -08004934}
4935
4936TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,
4937 protectedContentSupportUsedToGenerateRequests) {
Lloyd Piquea4863342019-12-04 18:45:02 -08004938 compositionengine::LayerFE::ClientCompositionTargetSettings layer0TargetSettings{
4939 Region(kDisplayFrame),
Lloyd Piquea4863342019-12-04 18:45:02 -08004940 false, /* needs filtering */
4941 false, /* secure */
Chavi Weingartencbec71d2023-12-14 20:53:25 +00004942 true, /* isProtected */
Vishnu Nairb87d94f2020-02-13 09:17:36 -08004943 kDisplayViewport,
4944 kDisplayDataspace,
4945 true /* realContentIsVisible */,
4946 false /* clearContent */,
Alec Mourif54453c2021-05-13 16:28:28 -07004947 compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled,
Alec Mouricdf6cbc2021-11-01 17:21:15 -07004948 kLayerWhitePointNits,
Vishnu Naire14c6b32022-08-06 04:20:15 +00004949 false /* treat170mAsSrgb */,
Lloyd Piquea4863342019-12-04 18:45:02 -08004950 };
4951 compositionengine::LayerFE::ClientCompositionTargetSettings layer1TargetSettings{
4952 Region(kDisplayFrame),
Lloyd Piquea4863342019-12-04 18:45:02 -08004953 false, /* needs filtering */
4954 false, /* secure */
Chavi Weingartencbec71d2023-12-14 20:53:25 +00004955 true, /* isProtected */
Vishnu Nairb87d94f2020-02-13 09:17:36 -08004956 kDisplayViewport,
4957 kDisplayDataspace,
4958 true /* realContentIsVisible */,
4959 false /* clearContent */,
Alec Mourif54453c2021-05-13 16:28:28 -07004960 compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled,
Alec Mouricdf6cbc2021-11-01 17:21:15 -07004961 kLayerWhitePointNits,
Vishnu Naire14c6b32022-08-06 04:20:15 +00004962 false /* treat170mAsSrgb */,
Lloyd Piquea4863342019-12-04 18:45:02 -08004963 };
4964 compositionengine::LayerFE::ClientCompositionTargetSettings layer2TargetSettings{
4965 Region(kDisplayFrame),
Lloyd Piquea4863342019-12-04 18:45:02 -08004966 false, /* needs filtering */
4967 false, /* secure */
Chavi Weingartencbec71d2023-12-14 20:53:25 +00004968 true, /* isProtected */
Vishnu Nairb87d94f2020-02-13 09:17:36 -08004969 kDisplayViewport,
4970 kDisplayDataspace,
4971 true /* realContentIsVisible */,
4972 false /* clearContent */,
Alec Mourif54453c2021-05-13 16:28:28 -07004973 compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled,
Alec Mouricdf6cbc2021-11-01 17:21:15 -07004974 kLayerWhitePointNits,
Vishnu Naire14c6b32022-08-06 04:20:15 +00004975 false /* treat170mAsSrgb */,
Lloyd Piquea4863342019-12-04 18:45:02 -08004976 };
4977
Patrick Williams16d8b2c2022-08-08 17:29:05 +00004978 EXPECT_CALL(*mLayers[0].mLayerFE, prepareClientComposition(Eq(ByRef(layer0TargetSettings))))
4979 .WillOnce(Return(std::optional<LayerFE::LayerSettings>()));
4980 EXPECT_CALL(*mLayers[1].mLayerFE, prepareClientComposition(Eq(ByRef(layer1TargetSettings))))
4981 .WillOnce(Return(std::optional<LayerFE::LayerSettings>()));
4982 EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientComposition(Eq(ByRef(layer2TargetSettings))))
4983 .WillOnce(Return(std::optional<LayerFE::LayerSettings>()));
Lloyd Piquea4863342019-12-04 18:45:02 -08004984
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00004985 static_cast<void>(
4986 mOutput.generateClientCompositionRequestsHelper(true /* supportsProtectedContent */,
4987 kDisplayDataspace));
Lloyd Piquea4863342019-12-04 18:45:02 -08004988}
4989
Lucas Dupin084a6d42021-08-26 22:10:29 +00004990TEST_F(OutputUpdateAndWriteCompositionStateTest, noBackgroundBlurWhenOpaque) {
4991 InjectedLayer layer1;
4992 InjectedLayer layer2;
4993
4994 uint32_t z = 0;
4995 // Layer requesting blur, or below, should request client composition, unless opaque.
4996 EXPECT_CALL(*layer1.outputLayer, updateCompositionState(false, false, ui::Transform::ROT_0));
4997 EXPECT_CALL(*layer1.outputLayer,
4998 writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++,
4999 /*zIsOverridden*/ false, /*isPeekingThrough*/ false));
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00005000 EXPECT_CALL(*layer1.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false));
Lucas Dupin084a6d42021-08-26 22:10:29 +00005001 EXPECT_CALL(*layer2.outputLayer, updateCompositionState(false, false, ui::Transform::ROT_0));
5002 EXPECT_CALL(*layer2.outputLayer,
5003 writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++,
5004 /*zIsOverridden*/ false, /*isPeekingThrough*/ false));
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00005005 EXPECT_CALL(*layer2.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false));
Lucas Dupin084a6d42021-08-26 22:10:29 +00005006
5007 layer2.layerFEState.backgroundBlurRadius = 10;
5008 layer2.layerFEState.isOpaque = true;
5009
5010 injectOutputLayer(layer1);
5011 injectOutputLayer(layer2);
5012
5013 mOutput->editState().isEnabled = true;
5014
5015 CompositionRefreshArgs args;
5016 args.updatingGeometryThisFrame = false;
5017 args.devOptForceClientComposition = false;
5018 mOutput->updateCompositionState(args);
5019 mOutput->planComposition();
5020 mOutput->writeCompositionState(args);
5021}
5022
Lucas Dupin19c8f0e2019-11-25 17:55:44 -08005023TEST_F(OutputUpdateAndWriteCompositionStateTest, handlesBackgroundBlurRequests) {
Lloyd Piquede196652020-01-22 17:29:58 -08005024 InjectedLayer layer1;
5025 InjectedLayer layer2;
5026 InjectedLayer layer3;
5027
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -04005028 uint32_t z = 0;
Lucas Dupin19c8f0e2019-11-25 17:55:44 -08005029 // Layer requesting blur, or below, should request client composition.
Snild Dolkow9e217d62020-04-22 15:53:42 +02005030 EXPECT_CALL(*layer1.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0));
Dan Stoza6166c312021-01-15 16:34:05 -08005031 EXPECT_CALL(*layer1.outputLayer,
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04005032 writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++,
5033 /*zIsOverridden*/ false, /*isPeekingThrough*/ false));
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00005034 EXPECT_CALL(*layer1.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false));
Snild Dolkow9e217d62020-04-22 15:53:42 +02005035 EXPECT_CALL(*layer2.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0));
Dan Stoza6166c312021-01-15 16:34:05 -08005036 EXPECT_CALL(*layer2.outputLayer,
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04005037 writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++,
5038 /*zIsOverridden*/ false, /*isPeekingThrough*/ false));
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00005039 EXPECT_CALL(*layer2.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false));
Snild Dolkow9e217d62020-04-22 15:53:42 +02005040 EXPECT_CALL(*layer3.outputLayer, updateCompositionState(false, false, ui::Transform::ROT_0));
Dan Stoza6166c312021-01-15 16:34:05 -08005041 EXPECT_CALL(*layer3.outputLayer,
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04005042 writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++,
5043 /*zIsOverridden*/ false, /*isPeekingThrough*/ false));
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00005044 EXPECT_CALL(*layer3.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false));
Lucas Dupin19c8f0e2019-11-25 17:55:44 -08005045
Lloyd Piquede196652020-01-22 17:29:58 -08005046 layer2.layerFEState.backgroundBlurRadius = 10;
Lucas Dupin084a6d42021-08-26 22:10:29 +00005047 layer2.layerFEState.isOpaque = false;
Lucas Dupin19c8f0e2019-11-25 17:55:44 -08005048
Lloyd Piquede196652020-01-22 17:29:58 -08005049 injectOutputLayer(layer1);
5050 injectOutputLayer(layer2);
5051 injectOutputLayer(layer3);
Lucas Dupin19c8f0e2019-11-25 17:55:44 -08005052
5053 mOutput->editState().isEnabled = true;
5054
5055 CompositionRefreshArgs args;
5056 args.updatingGeometryThisFrame = false;
5057 args.devOptForceClientComposition = false;
Dan Stoza269dc4d2021-01-15 15:07:43 -08005058 mOutput->updateCompositionState(args);
5059 mOutput->planComposition();
5060 mOutput->writeCompositionState(args);
Lucas Dupin19c8f0e2019-11-25 17:55:44 -08005061}
5062
Lucas Dupinc3800b82020-10-02 16:24:48 -07005063TEST_F(OutputUpdateAndWriteCompositionStateTest, handlesBlurRegionRequests) {
5064 InjectedLayer layer1;
5065 InjectedLayer layer2;
5066 InjectedLayer layer3;
5067
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -04005068 uint32_t z = 0;
Lucas Dupinc3800b82020-10-02 16:24:48 -07005069 // Layer requesting blur, or below, should request client composition.
5070 EXPECT_CALL(*layer1.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0));
Dan Stoza6166c312021-01-15 16:34:05 -08005071 EXPECT_CALL(*layer1.outputLayer,
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04005072 writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++,
5073 /*zIsOverridden*/ false, /*isPeekingThrough*/ false));
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00005074 EXPECT_CALL(*layer1.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false));
Lucas Dupinc3800b82020-10-02 16:24:48 -07005075 EXPECT_CALL(*layer2.outputLayer, updateCompositionState(false, true, ui::Transform::ROT_0));
Dan Stoza6166c312021-01-15 16:34:05 -08005076 EXPECT_CALL(*layer2.outputLayer,
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04005077 writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++,
5078 /*zIsOverridden*/ false, /*isPeekingThrough*/ false));
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00005079 EXPECT_CALL(*layer2.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false));
Lucas Dupinc3800b82020-10-02 16:24:48 -07005080 EXPECT_CALL(*layer3.outputLayer, updateCompositionState(false, false, ui::Transform::ROT_0));
Dan Stoza6166c312021-01-15 16:34:05 -08005081 EXPECT_CALL(*layer3.outputLayer,
Leon Scroggins III9aa25c22021-04-15 15:30:19 -04005082 writeStateToHWC(/*includeGeometry*/ false, /*skipLayer*/ false, z++,
5083 /*zIsOverridden*/ false, /*isPeekingThrough*/ false));
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00005084 EXPECT_CALL(*layer3.outputLayer, requiresClientComposition()).WillRepeatedly(Return(false));
Lucas Dupinc3800b82020-10-02 16:24:48 -07005085
5086 BlurRegion region;
5087 layer2.layerFEState.blurRegions.push_back(region);
Lucas Dupin084a6d42021-08-26 22:10:29 +00005088 layer2.layerFEState.isOpaque = false;
Lucas Dupinc3800b82020-10-02 16:24:48 -07005089
5090 injectOutputLayer(layer1);
5091 injectOutputLayer(layer2);
5092 injectOutputLayer(layer3);
5093
5094 mOutput->editState().isEnabled = true;
5095
5096 CompositionRefreshArgs args;
5097 args.updatingGeometryThisFrame = false;
5098 args.devOptForceClientComposition = false;
Dan Stoza269dc4d2021-01-15 15:07:43 -08005099 mOutput->updateCompositionState(args);
5100 mOutput->planComposition();
5101 mOutput->writeCompositionState(args);
Lucas Dupinc3800b82020-10-02 16:24:48 -07005102}
5103
Lloyd Piquea4863342019-12-04 18:45:02 -08005104TEST_F(GenerateClientCompositionRequestsTest, handlesLandscapeModeSplitScreenRequests) {
5105 // In split-screen landscape mode, the screen is rotated 90 degrees, with
5106 // one layer on the left covering the left side of the output, and one layer
5107 // on the right covering that side of the output.
Lloyd Piquec2d54d42019-08-28 18:04:21 -07005108
5109 const Rect kPortraitFrame(0, 0, 1000, 2000);
5110 const Rect kPortraitViewport(0, 0, 2000, 1000);
Lloyd Piquee8fe4742020-01-21 15:26:18 -08005111 const Rect kPortraitDestinationClip(0, 0, 1000, 2000);
Marin Shalamanov68933fb2020-09-10 17:58:12 +02005112 const ui::Rotation kPortraitOrientation = ui::ROTATION_90;
Lloyd Piquea4863342019-12-04 18:45:02 -08005113 constexpr ui::Dataspace kOutputDataspace = ui::Dataspace::DISPLAY_P3;
Lloyd Piquec2d54d42019-08-28 18:04:21 -07005114
Angel Aguayob084e0c2021-08-04 23:27:28 +00005115 mOutput.mState.orientedDisplaySpace.setContent(kPortraitFrame);
5116 mOutput.mState.layerStackSpace.setContent(kPortraitViewport);
5117 mOutput.mState.displaySpace.setContent(kPortraitDestinationClip);
Marin Shalamanov68933fb2020-09-10 17:58:12 +02005118 mOutput.mState.transform = ui::Transform{ui::Transform::toRotationFlags(kPortraitOrientation)};
Angel Aguayob084e0c2021-08-04 23:27:28 +00005119 mOutput.mState.displaySpace.setOrientation(kPortraitOrientation);
Lloyd Piquea4863342019-12-04 18:45:02 -08005120 mOutput.mState.needsFiltering = false;
5121 mOutput.mState.isSecure = true;
Lloyd Piquec2d54d42019-08-28 18:04:21 -07005122
Lloyd Piquea4863342019-12-04 18:45:02 -08005123 Layer leftLayer;
5124 Layer rightLayer;
Lloyd Piquec2d54d42019-08-28 18:04:21 -07005125
Lloyd Piquea4863342019-12-04 18:45:02 -08005126 leftLayer.mOutputLayerState.clearClientTarget = false;
5127 leftLayer.mOutputLayerState.visibleRegion = Region(Rect(0, 0, 1000, 1000));
5128 leftLayer.mLayerFEState.isOpaque = true;
Vishnu Nair9b079a22020-01-21 14:36:08 -08005129 leftLayer.mLayerSettings.source.solidColor = {1.f, 0.f, 0.f};
Lloyd Piquec2d54d42019-08-28 18:04:21 -07005130
Lloyd Piquea4863342019-12-04 18:45:02 -08005131 rightLayer.mOutputLayerState.clearClientTarget = false;
5132 rightLayer.mOutputLayerState.visibleRegion = Region(Rect(1000, 0, 2000, 1000));
5133 rightLayer.mLayerFEState.isOpaque = true;
Vishnu Nair9b079a22020-01-21 14:36:08 -08005134 rightLayer.mLayerSettings.source.solidColor = {0.f, 1.f, 0.f};
Lloyd Piquea4863342019-12-04 18:45:02 -08005135
5136 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2u));
5137 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0u))
5138 .WillRepeatedly(Return(&leftLayer.mOutputLayer));
5139 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1u))
5140 .WillRepeatedly(Return(&rightLayer.mOutputLayer));
5141
Lloyd Piquea4863342019-12-04 18:45:02 -08005142 compositionengine::LayerFE::ClientCompositionTargetSettings leftLayerSettings{
5143 Region(Rect(0, 0, 1000, 1000)),
Lloyd Piquea4863342019-12-04 18:45:02 -08005144 false, /* needs filtering */
5145 true, /* secure */
Chavi Weingartencbec71d2023-12-14 20:53:25 +00005146 true, /* isProtected */
Vishnu Nairb87d94f2020-02-13 09:17:36 -08005147 kPortraitViewport,
5148 kOutputDataspace,
5149 true /* realContentIsVisible */,
5150 false /* clearContent */,
Alec Mourif54453c2021-05-13 16:28:28 -07005151 compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled,
Alec Mouricdf6cbc2021-11-01 17:21:15 -07005152 kLayerWhitePointNits,
Vishnu Naire14c6b32022-08-06 04:20:15 +00005153 false /* treat170mAsSrgb */,
Lloyd Piquea4863342019-12-04 18:45:02 -08005154 };
5155
5156 EXPECT_CALL(leftLayer.mOutputLayer, requiresClientComposition()).WillRepeatedly(Return(true));
5157 EXPECT_CALL(leftLayer.mOutputLayer, needsFiltering()).WillRepeatedly(Return(false));
Patrick Williams16d8b2c2022-08-08 17:29:05 +00005158 EXPECT_CALL(*leftLayer.mLayerFE, prepareClientComposition(Eq(ByRef(leftLayerSettings))))
5159 .WillOnce(Return(std::optional<LayerFE::LayerSettings>(leftLayer.mLayerSettings)));
Lloyd Piquea4863342019-12-04 18:45:02 -08005160
5161 compositionengine::LayerFE::ClientCompositionTargetSettings rightLayerSettings{
5162 Region(Rect(1000, 0, 2000, 1000)),
Lloyd Piquea4863342019-12-04 18:45:02 -08005163 false, /* needs filtering */
5164 true, /* secure */
Chavi Weingartencbec71d2023-12-14 20:53:25 +00005165 true, /* isProtected */
Vishnu Nairb87d94f2020-02-13 09:17:36 -08005166 kPortraitViewport,
5167 kOutputDataspace,
5168 true /* realContentIsVisible */,
5169 false /* clearContent */,
Alec Mourif54453c2021-05-13 16:28:28 -07005170 compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled,
Alec Mouricdf6cbc2021-11-01 17:21:15 -07005171 kLayerWhitePointNits,
Vishnu Naire14c6b32022-08-06 04:20:15 +00005172 false /* treat170mAsSrgb */,
Lloyd Piquea4863342019-12-04 18:45:02 -08005173 };
5174
5175 EXPECT_CALL(rightLayer.mOutputLayer, requiresClientComposition()).WillRepeatedly(Return(true));
5176 EXPECT_CALL(rightLayer.mOutputLayer, needsFiltering()).WillRepeatedly(Return(false));
Patrick Williams16d8b2c2022-08-08 17:29:05 +00005177 EXPECT_CALL(*rightLayer.mLayerFE, prepareClientComposition(Eq(ByRef(rightLayerSettings))))
5178 .WillOnce(Return(std::optional<LayerFE::LayerSettings>(rightLayer.mLayerSettings)));
Lloyd Piquea4863342019-12-04 18:45:02 -08005179
5180 constexpr bool supportsProtectedContent = true;
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00005181 auto requests = mOutput.generateClientCompositionRequestsHelper(supportsProtectedContent,
5182 kOutputDataspace);
Lloyd Piquea4863342019-12-04 18:45:02 -08005183 ASSERT_EQ(2u, requests.size());
Vishnu Nair9b079a22020-01-21 14:36:08 -08005184 EXPECT_EQ(leftLayer.mLayerSettings, requests[0]);
5185 EXPECT_EQ(rightLayer.mLayerSettings, requests[1]);
Lloyd Piquec2d54d42019-08-28 18:04:21 -07005186}
5187
Vishnu Naira483b4a2019-12-12 15:07:52 -08005188TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,
5189 shadowRegionOnlyVisibleSkipsContentComposition) {
5190 const Rect kContentWithShadow(40, 40, 70, 90);
5191 const Rect kContent(50, 50, 60, 80);
5192 const Region kShadowRegion = Region(kContentWithShadow).subtract(kContent);
5193 const Region kPartialShadowRegion = Region(kContentWithShadow).subtract(Rect(40, 40, 60, 80));
5194
Vishnu Nairb87d94f2020-02-13 09:17:36 -08005195 compositionengine::LayerFE::ClientCompositionTargetSettings layer2Settings{
5196 Region(Rect(60, 40, 70, 80)).merge(Rect(40, 80, 70, 90)), /* visible region */
Vishnu Nairb87d94f2020-02-13 09:17:36 -08005197 false, /* needs filtering */
5198 false, /* secure */
5199 false, /* supports protected content */
Vishnu Nairb87d94f2020-02-13 09:17:36 -08005200 kDisplayViewport,
5201 kDisplayDataspace,
5202 false /* realContentIsVisible */,
5203 false /* clearContent */,
Alec Mourif54453c2021-05-13 16:28:28 -07005204 compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled,
Alec Mouricdf6cbc2021-11-01 17:21:15 -07005205 kLayerWhitePointNits,
Vishnu Naire14c6b32022-08-06 04:20:15 +00005206 false /* treat170mAsSrgb */,
Vishnu Nairb87d94f2020-02-13 09:17:36 -08005207 };
5208
Vishnu Nair9b079a22020-01-21 14:36:08 -08005209 LayerFE::LayerSettings mShadowSettings;
5210 mShadowSettings.source.solidColor = {0.1f, 0.1f, 0.1f};
Vishnu Naira483b4a2019-12-12 15:07:52 -08005211
5212 mLayers[2].mOutputLayerState.visibleRegion = kPartialShadowRegion;
5213 mLayers[2].mOutputLayerState.shadowRegion = kShadowRegion;
5214
5215 EXPECT_CALL(mLayers[0].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
5216 EXPECT_CALL(mLayers[1].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
Patrick Williams16d8b2c2022-08-08 17:29:05 +00005217 EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientComposition(Eq(ByRef(layer2Settings))))
5218 .WillOnce(Return(std::optional<LayerFE::LayerSettings>(mShadowSettings)));
Vishnu Naira483b4a2019-12-12 15:07:52 -08005219
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00005220 auto requests =
5221 mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */,
5222 kDisplayDataspace);
Vishnu Naira483b4a2019-12-12 15:07:52 -08005223 ASSERT_EQ(1u, requests.size());
5224
Vishnu Nair9b079a22020-01-21 14:36:08 -08005225 EXPECT_EQ(mShadowSettings, requests[0]);
Vishnu Naira483b4a2019-12-12 15:07:52 -08005226}
5227
5228TEST_F(GenerateClientCompositionRequestsTest_ThreeLayers,
5229 shadowRegionWithContentVisibleRequestsContentAndShadowComposition) {
5230 const Rect kContentWithShadow(40, 40, 70, 90);
5231 const Rect kContent(50, 50, 60, 80);
5232 const Region kShadowRegion = Region(kContentWithShadow).subtract(kContent);
5233 const Region kPartialContentWithPartialShadowRegion =
5234 Region(kContentWithShadow).subtract(Rect(40, 40, 50, 80));
5235
Vishnu Naira483b4a2019-12-12 15:07:52 -08005236 mLayers[2].mOutputLayerState.visibleRegion = kPartialContentWithPartialShadowRegion;
5237 mLayers[2].mOutputLayerState.shadowRegion = kShadowRegion;
5238
Vishnu Nairb87d94f2020-02-13 09:17:36 -08005239 compositionengine::LayerFE::ClientCompositionTargetSettings layer2Settings{
5240 Region(Rect(50, 40, 70, 80)).merge(Rect(40, 80, 70, 90)), /* visible region */
Vishnu Nairb87d94f2020-02-13 09:17:36 -08005241 false, /* needs filtering */
5242 false, /* secure */
5243 false, /* supports protected content */
Vishnu Nairb87d94f2020-02-13 09:17:36 -08005244 kDisplayViewport,
5245 kDisplayDataspace,
5246 true /* realContentIsVisible */,
5247 false /* clearContent */,
Alec Mourif54453c2021-05-13 16:28:28 -07005248 compositionengine::LayerFE::ClientCompositionTargetSettings::BlurSetting::Enabled,
Alec Mouricdf6cbc2021-11-01 17:21:15 -07005249 kLayerWhitePointNits,
Vishnu Naire14c6b32022-08-06 04:20:15 +00005250 false /* treat170mAsSrgb */,
Vishnu Nairb87d94f2020-02-13 09:17:36 -08005251 };
5252
Vishnu Naira483b4a2019-12-12 15:07:52 -08005253 EXPECT_CALL(mLayers[0].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
5254 EXPECT_CALL(mLayers[1].mOutputLayer, requiresClientComposition()).WillOnce(Return(false));
Patrick Williams16d8b2c2022-08-08 17:29:05 +00005255 EXPECT_CALL(*mLayers[2].mLayerFE, prepareClientComposition(Eq(ByRef(layer2Settings))))
5256 .WillOnce(Return(std::optional<LayerFE::LayerSettings>(mLayers[2].mLayerSettings)));
Vishnu Naira483b4a2019-12-12 15:07:52 -08005257
Carlos Martinez Romeroe5d57ea2022-11-15 19:14:36 +00005258 auto requests =
5259 mOutput.generateClientCompositionRequestsHelper(false /* supportsProtectedContent */,
5260 kDisplayDataspace);
Patrick Williams16d8b2c2022-08-08 17:29:05 +00005261 ASSERT_EQ(1u, requests.size());
Vishnu Naira483b4a2019-12-12 15:07:52 -08005262
Patrick Williams16d8b2c2022-08-08 17:29:05 +00005263 EXPECT_EQ(mLayers[2].mLayerSettings, requests[0]);
Vishnu Naira483b4a2019-12-12 15:07:52 -08005264}
5265
Leon Scroggins III2f60d732022-09-12 14:42:38 -04005266struct OutputPresentFrameAndReleaseLayersAsyncTest : public ::testing::Test {
5267 // Piggy-back on OutputPrepareFrameAsyncTest's version to avoid some boilerplate.
5268 struct OutputPartialMock : public OutputPrepareFrameAsyncTest::OutputPartialMock {
5269 // Set up the helper functions called by the function under test to use
5270 // mock implementations.
5271 MOCK_METHOD0(presentFrameAndReleaseLayers, void());
5272 MOCK_METHOD0(presentFrameAndReleaseLayersAsync, ftl::Future<std::monostate>());
5273 };
5274 OutputPresentFrameAndReleaseLayersAsyncTest() {
5275 mOutput->setDisplayColorProfileForTest(
5276 std::unique_ptr<DisplayColorProfile>(mDisplayColorProfile));
5277 mOutput->setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
5278 mOutput->setCompositionEnabled(true);
5279 mRefreshArgs.outputs = {mOutput};
5280 }
5281
5282 mock::DisplayColorProfile* mDisplayColorProfile = new NiceMock<mock::DisplayColorProfile>();
5283 mock::RenderSurface* mRenderSurface = new NiceMock<mock::RenderSurface>();
5284 std::shared_ptr<OutputPartialMock> mOutput{std::make_shared<NiceMock<OutputPartialMock>>()};
5285 CompositionRefreshArgs mRefreshArgs;
5286};
5287
5288TEST_F(OutputPresentFrameAndReleaseLayersAsyncTest, notCalledWhenNotRequested) {
5289 EXPECT_CALL(*mOutput, presentFrameAndReleaseLayersAsync()).Times(0);
5290 EXPECT_CALL(*mOutput, presentFrameAndReleaseLayers()).Times(1);
5291
5292 mOutput->present(mRefreshArgs);
5293}
5294
5295TEST_F(OutputPresentFrameAndReleaseLayersAsyncTest, calledWhenRequested) {
5296 EXPECT_CALL(*mOutput, presentFrameAndReleaseLayersAsync())
5297 .WillOnce(Return(ftl::yield<std::monostate>({})));
5298 EXPECT_CALL(*mOutput, presentFrameAndReleaseLayers()).Times(0);
5299
5300 mOutput->offloadPresentNextFrame();
5301 mOutput->present(mRefreshArgs);
5302}
5303
5304TEST_F(OutputPresentFrameAndReleaseLayersAsyncTest, calledForOneFrame) {
5305 ::testing::InSequence inseq;
5306 EXPECT_CALL(*mOutput, presentFrameAndReleaseLayersAsync())
5307 .WillOnce(Return(ftl::yield<std::monostate>({})));
5308 EXPECT_CALL(*mOutput, presentFrameAndReleaseLayers()).Times(1);
5309
5310 mOutput->offloadPresentNextFrame();
5311 mOutput->present(mRefreshArgs);
5312 mOutput->present(mRefreshArgs);
5313}
5314
Eason Chiu45099662023-10-23 08:55:48 +08005315/*
5316 * Output::updateProtectedContentState()
5317 */
5318
5319struct OutputUpdateProtectedContentStateTest : public testing::Test {
5320 struct OutputPartialMock : public OutputPartialMockBase {
5321 // Sets up the helper functions called by the function under test to use
5322 // mock implementations.
5323 MOCK_CONST_METHOD0(getCompositionEngine, const CompositionEngine&());
5324 };
5325
5326 OutputUpdateProtectedContentStateTest() {
5327 mOutput.setRenderSurfaceForTest(std::unique_ptr<RenderSurface>(mRenderSurface));
5328 EXPECT_CALL(mOutput, getCompositionEngine()).WillRepeatedly(ReturnRef(mCompositionEngine));
5329 EXPECT_CALL(mCompositionEngine, getRenderEngine()).WillRepeatedly(ReturnRef(mRenderEngine));
5330 EXPECT_CALL(mOutput, getOutputLayerCount()).WillRepeatedly(Return(2u));
5331 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(0))
5332 .WillRepeatedly(Return(&mLayer1.mOutputLayer));
5333 EXPECT_CALL(mOutput, getOutputLayerOrderedByZByIndex(1))
5334 .WillRepeatedly(Return(&mLayer2.mOutputLayer));
5335 }
5336
5337 struct Layer {
5338 Layer() {
5339 EXPECT_CALL(*mLayerFE, getCompositionState()).WillRepeatedly(Return(&mLayerFEState));
5340 EXPECT_CALL(mOutputLayer, getLayerFE()).WillRepeatedly(ReturnRef(*mLayerFE));
5341 }
5342
5343 StrictMock<mock::OutputLayer> mOutputLayer;
5344 sp<StrictMock<mock::LayerFE>> mLayerFE = sp<StrictMock<mock::LayerFE>>::make();
5345 LayerFECompositionState mLayerFEState;
5346 };
5347
5348 mock::RenderSurface* mRenderSurface = new StrictMock<mock::RenderSurface>();
5349 StrictMock<OutputPartialMock> mOutput;
5350 StrictMock<mock::CompositionEngine> mCompositionEngine;
5351 StrictMock<renderengine::mock::RenderEngine> mRenderEngine;
5352 Layer mLayer1;
5353 Layer mLayer2;
5354};
5355
5356TEST_F(OutputUpdateProtectedContentStateTest, ifProtectedContentLayerComposeByHWC) {
5357 SET_FLAG_FOR_TEST(flags::protected_if_client, true);
5358 if (FlagManager::getInstance().display_protected()) {
5359 mOutput.mState.isProtected = true;
5360 } else {
5361 mOutput.mState.isSecure = true;
5362 }
5363 mLayer1.mLayerFEState.hasProtectedContent = false;
5364 mLayer2.mLayerFEState.hasProtectedContent = true;
5365 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(true));
5366 EXPECT_CALL(*mRenderSurface, isProtected).WillOnce(Return(false));
5367 EXPECT_CALL(mLayer1.mOutputLayer, requiresClientComposition()).WillRepeatedly(Return(true));
5368 EXPECT_CALL(mLayer2.mOutputLayer, requiresClientComposition()).WillRepeatedly(Return(false));
5369 mOutput.updateProtectedContentState();
5370}
5371
5372TEST_F(OutputUpdateProtectedContentStateTest, ifProtectedContentLayerComposeByClient) {
5373 SET_FLAG_FOR_TEST(flags::protected_if_client, true);
5374 if (FlagManager::getInstance().display_protected()) {
5375 mOutput.mState.isProtected = true;
5376 } else {
5377 mOutput.mState.isSecure = true;
5378 }
5379 mLayer1.mLayerFEState.hasProtectedContent = false;
5380 mLayer2.mLayerFEState.hasProtectedContent = true;
5381 EXPECT_CALL(mRenderEngine, supportsProtectedContent()).WillRepeatedly(Return(true));
5382 EXPECT_CALL(*mRenderSurface, isProtected).WillOnce(Return(false));
5383 EXPECT_CALL(*mRenderSurface, setProtected(true));
5384 EXPECT_CALL(mLayer1.mOutputLayer, requiresClientComposition()).WillRepeatedly(Return(true));
5385 EXPECT_CALL(mLayer2.mOutputLayer, requiresClientComposition()).WillRepeatedly(Return(true));
5386 mOutput.updateProtectedContentState();
5387}
5388
Lloyd Pique32cbe282018-10-19 13:09:22 -07005389} // namespace
5390} // namespace android::compositionengine