compositor_unittest.cc 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. // Copyright 2015 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include <stdint.h>
  5. #include "base/memory/raw_ptr.h"
  6. #include "base/run_loop.h"
  7. #include "base/task/single_thread_task_runner.h"
  8. #include "base/test/bind.h"
  9. #include "base/test/power_monitor_test.h"
  10. #include "base/test/scoped_feature_list.h"
  11. #include "base/test/task_environment.h"
  12. #include "base/test/test_mock_time_task_runner.h"
  13. #include "base/threading/thread_task_runner_handle.h"
  14. #include "base/time/time.h"
  15. #include "build/build_config.h"
  16. #include "cc/metrics/frame_sequence_tracker.h"
  17. #include "components/viz/common/surfaces/parent_local_surface_id_allocator.h"
  18. #include "testing/gmock/include/gmock/gmock.h"
  19. #include "testing/gtest/include/gtest/gtest.h"
  20. #include "ui/base/ui_base_features.h"
  21. #include "ui/compositor/compositor.h"
  22. #include "ui/compositor/layer.h"
  23. #include "ui/compositor/layer_delegate.h"
  24. #include "ui/compositor/test/draw_waiter_for_test.h"
  25. #include "ui/compositor/test/in_process_context_factory.h"
  26. #include "ui/compositor/test/test_context_factories.h"
  27. using testing::Mock;
  28. using testing::_;
  29. namespace ui {
  30. namespace {
  31. class CompositorTest : public testing::Test {
  32. public:
  33. CompositorTest() = default;
  34. CompositorTest(const CompositorTest&) = delete;
  35. CompositorTest& operator=(const CompositorTest&) = delete;
  36. ~CompositorTest() override = default;
  37. void CreateCompositor() {
  38. compositor_ = std::make_unique<Compositor>(
  39. context_factories_->GetContextFactory()->AllocateFrameSinkId(),
  40. context_factories_->GetContextFactory(), CreateTaskRunner(),
  41. false /* enable_pixel_canvas */);
  42. compositor_->SetAcceleratedWidget(gfx::kNullAcceleratedWidget);
  43. }
  44. void SetUp() override {
  45. context_factories_ = std::make_unique<TestContextFactories>(false);
  46. CreateCompositor();
  47. }
  48. void TearDown() override {
  49. compositor_.reset();
  50. context_factories_.reset();
  51. }
  52. void DestroyCompositor() { compositor_.reset(); }
  53. protected:
  54. virtual scoped_refptr<base::SingleThreadTaskRunner> CreateTaskRunner() = 0;
  55. Compositor* compositor() { return compositor_.get(); }
  56. private:
  57. std::unique_ptr<TestContextFactories> context_factories_;
  58. std::unique_ptr<Compositor> compositor_;
  59. };
  60. // For tests that control time.
  61. class CompositorTestWithMockedTime : public CompositorTest {
  62. protected:
  63. scoped_refptr<base::SingleThreadTaskRunner> CreateTaskRunner() override {
  64. task_runner_ = new base::TestMockTimeTaskRunner;
  65. return task_runner_;
  66. }
  67. base::TestMockTimeTaskRunner* task_runner() { return task_runner_.get(); }
  68. protected:
  69. void AdvanceBy(base::TimeDelta delta) {
  70. task_environment_.AdvanceClock(delta);
  71. }
  72. scoped_refptr<base::TestMockTimeTaskRunner> task_runner_;
  73. base::test::ScopedPowerMonitorTestSource test_power_monitor_source_;
  74. private:
  75. base::test::TaskEnvironment task_environment_{
  76. base::test::TaskEnvironment::MainThreadType::UI,
  77. base::test::TaskEnvironment::TimeSource::MOCK_TIME};
  78. };
  79. // For tests that run on a real MessageLoop with real time.
  80. class CompositorTestWithMessageLoop : public CompositorTest {
  81. public:
  82. CompositorTestWithMessageLoop()
  83. : task_environment_(base::test::TaskEnvironment::MainThreadType::UI) {}
  84. ~CompositorTestWithMessageLoop() override = default;
  85. protected:
  86. scoped_refptr<base::SingleThreadTaskRunner> CreateTaskRunner() override {
  87. task_runner_ = base::ThreadTaskRunnerHandle::Get();
  88. return task_runner_;
  89. }
  90. base::SequencedTaskRunner* task_runner() { return task_runner_.get(); }
  91. private:
  92. base::test::TaskEnvironment task_environment_;
  93. scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
  94. };
  95. class TestCompositorAnimationObserver : public CompositorAnimationObserver {
  96. public:
  97. TestCompositorAnimationObserver() = default;
  98. TestCompositorAnimationObserver(const TestCompositorAnimationObserver&) =
  99. delete;
  100. TestCompositorAnimationObserver& operator=(
  101. const TestCompositorAnimationObserver&) = delete;
  102. ~TestCompositorAnimationObserver() override = default;
  103. // CompositorAnimationObserver:
  104. void OnAnimationStep(base::TimeTicks timestamp) override {}
  105. void OnCompositingShuttingDown(Compositor* compositor) override {}
  106. void NotifyFailure() override { failed_ = true; }
  107. bool failed() const { return failed_; }
  108. private:
  109. bool failed_ = false;
  110. };
  111. } // namespace
  112. TEST_F(CompositorTestWithMockedTime, AnimationObserverBasic) {
  113. TestCompositorAnimationObserver test;
  114. compositor()->AddAnimationObserver(&test);
  115. test.Start();
  116. test.Check();
  117. AdvanceBy(base::Seconds(59));
  118. EXPECT_FALSE(test.failed());
  119. AdvanceBy(base::Seconds(2));
  120. test.Check();
  121. EXPECT_TRUE(test.failed());
  122. compositor()->RemoveAnimationObserver(&test);
  123. }
  124. TEST_F(CompositorTestWithMockedTime, AnimationObserverResetAfterResume) {
  125. TestCompositorAnimationObserver test;
  126. compositor()->AddAnimationObserver(&test);
  127. test.Start();
  128. test.Check();
  129. AdvanceBy(base::Seconds(59));
  130. EXPECT_TRUE(test.is_active_for_test());
  131. EXPECT_FALSE(test.failed());
  132. test_power_monitor_source_.Suspend();
  133. base::RunLoop().RunUntilIdle();
  134. AdvanceBy(base::Seconds(32));
  135. test_power_monitor_source_.Resume();
  136. base::RunLoop().RunUntilIdle();
  137. test.Check();
  138. EXPECT_TRUE(test.is_active_for_test());
  139. EXPECT_FALSE(test.failed());
  140. AdvanceBy(base::Seconds(29));
  141. test.Check();
  142. EXPECT_TRUE(test.is_active_for_test());
  143. EXPECT_FALSE(test.failed());
  144. AdvanceBy(base::Seconds(32));
  145. test.Check();
  146. EXPECT_FALSE(test.is_active_for_test());
  147. EXPECT_TRUE(test.failed());
  148. // Make sure another suspend/resume will not reactivate it.
  149. test_power_monitor_source_.Suspend();
  150. base::RunLoop().RunUntilIdle();
  151. test_power_monitor_source_.Resume();
  152. EXPECT_FALSE(test.is_active_for_test());
  153. EXPECT_TRUE(test.failed());
  154. compositor()->RemoveAnimationObserver(&test);
  155. }
  156. TEST_F(CompositorTestWithMessageLoop, ShouldUpdateDisplayProperties) {
  157. auto root_layer = std::make_unique<Layer>(ui::LAYER_SOLID_COLOR);
  158. viz::ParentLocalSurfaceIdAllocator allocator;
  159. allocator.GenerateId();
  160. root_layer->SetBounds(gfx::Rect(10, 10));
  161. compositor()->SetRootLayer(root_layer.get());
  162. compositor()->SetScaleAndSize(1.0f, gfx::Size(10, 10),
  163. allocator.GetCurrentLocalSurfaceId());
  164. ASSERT_TRUE(compositor()->IsVisible());
  165. // Set a non-identity color matrix, color space, sdr white level, vsync
  166. // timebase and vsync interval, and expect it to be set on the context
  167. // factory.
  168. SkM44 color_matrix;
  169. color_matrix.setRC(1, 1, 0.7f);
  170. color_matrix.setRC(2, 2, 0.4f);
  171. gfx::DisplayColorSpaces display_color_spaces(
  172. gfx::ColorSpace::CreateDisplayP3D65());
  173. display_color_spaces.SetSDRMaxLuminanceNits(1.f);
  174. base::TimeTicks vsync_timebase(base::TimeTicks::Now());
  175. base::TimeDelta vsync_interval(base::Milliseconds(250));
  176. compositor()->SetDisplayColorMatrix(color_matrix);
  177. compositor()->SetDisplayColorSpaces(display_color_spaces);
  178. compositor()->SetDisplayVSyncParameters(vsync_timebase, vsync_interval);
  179. InProcessContextFactory* context_factory =
  180. static_cast<InProcessContextFactory*>(compositor()->context_factory());
  181. compositor()->ScheduleDraw();
  182. DrawWaiterForTest::WaitForCompositingEnded(compositor());
  183. EXPECT_EQ(color_matrix, context_factory->GetOutputColorMatrix(compositor()));
  184. EXPECT_EQ(display_color_spaces,
  185. context_factory->GetDisplayColorSpaces(compositor()));
  186. EXPECT_EQ(vsync_timebase,
  187. context_factory->GetDisplayVSyncTimeBase(compositor()));
  188. EXPECT_EQ(vsync_interval,
  189. context_factory->GetDisplayVSyncTimeInterval(compositor()));
  190. // Simulate a lost context by releasing the output surface and setting it on
  191. // the compositor again. Expect that the same color matrix, color space, sdr
  192. // white level, vsync timebase and vsync interval will be set again on the
  193. // context factory.
  194. context_factory->ResetDisplayOutputParameters(compositor());
  195. compositor()->SetVisible(false);
  196. EXPECT_EQ(gfx::kNullAcceleratedWidget,
  197. compositor()->ReleaseAcceleratedWidget());
  198. compositor()->SetAcceleratedWidget(gfx::kNullAcceleratedWidget);
  199. compositor()->SetVisible(true);
  200. compositor()->ScheduleDraw();
  201. DrawWaiterForTest::WaitForCompositingEnded(compositor());
  202. EXPECT_EQ(color_matrix, context_factory->GetOutputColorMatrix(compositor()));
  203. EXPECT_EQ(display_color_spaces,
  204. context_factory->GetDisplayColorSpaces(compositor()));
  205. EXPECT_EQ(vsync_timebase,
  206. context_factory->GetDisplayVSyncTimeBase(compositor()));
  207. EXPECT_EQ(vsync_interval,
  208. context_factory->GetDisplayVSyncTimeInterval(compositor()));
  209. compositor()->SetRootLayer(nullptr);
  210. }
  211. TEST_F(CompositorTestWithMockedTime,
  212. ReleaseWidgetWithOutputSurfaceNeverCreated) {
  213. compositor()->SetVisible(false);
  214. EXPECT_EQ(gfx::kNullAcceleratedWidget,
  215. compositor()->ReleaseAcceleratedWidget());
  216. compositor()->SetAcceleratedWidget(gfx::kNullAcceleratedWidget);
  217. compositor()->SetVisible(true);
  218. }
  219. TEST_F(CompositorTestWithMessageLoop, MoveThroughputTracker) {
  220. // Move a not started instance.
  221. {
  222. auto tracker = compositor()->RequestNewThroughputTracker();
  223. auto moved_tracker = std::move(tracker);
  224. }
  225. // Move a started instance.
  226. {
  227. auto tracker = compositor()->RequestNewThroughputTracker();
  228. tracker.Start(base::BindLambdaForTesting(
  229. [&](const cc::FrameSequenceMetrics::CustomReportData& data) {
  230. // This should not be called since the tracking is auto canceled.
  231. ADD_FAILURE();
  232. }));
  233. auto moved_tracker = std::move(tracker);
  234. }
  235. // Move a started instance and stop.
  236. {
  237. auto tracker = compositor()->RequestNewThroughputTracker();
  238. tracker.Start(base::BindLambdaForTesting(
  239. [&](const cc::FrameSequenceMetrics::CustomReportData& data) {
  240. // May be called since Stop() is called.
  241. }));
  242. auto moved_tracker = std::move(tracker);
  243. EXPECT_TRUE(moved_tracker.Stop());
  244. }
  245. // Move a started instance and cancel.
  246. {
  247. auto tracker = compositor()->RequestNewThroughputTracker();
  248. tracker.Start(base::BindLambdaForTesting(
  249. [&](const cc::FrameSequenceMetrics::CustomReportData& data) {
  250. // This should not be called since Cancel() is called.
  251. ADD_FAILURE();
  252. }));
  253. auto moved_tracker = std::move(tracker);
  254. moved_tracker.Cancel();
  255. }
  256. // Move a stopped instance.
  257. {
  258. auto tracker = compositor()->RequestNewThroughputTracker();
  259. tracker.Start(base::BindLambdaForTesting(
  260. [&](const cc::FrameSequenceMetrics::CustomReportData& data) {
  261. // May be called since Stop() is called.
  262. }));
  263. EXPECT_TRUE(tracker.Stop());
  264. auto moved_tracker = std::move(tracker);
  265. }
  266. // Move a canceled instance.
  267. {
  268. auto tracker = compositor()->RequestNewThroughputTracker();
  269. tracker.Start(base::BindLambdaForTesting(
  270. [&](const cc::FrameSequenceMetrics::CustomReportData& data) {
  271. // This should not be called since Cancel() is called.
  272. ADD_FAILURE();
  273. }));
  274. tracker.Cancel();
  275. auto moved_tracker = std::move(tracker);
  276. }
  277. }
  278. TEST_F(CompositorTestWithMessageLoop, ThroughputTracker) {
  279. auto root_layer = std::make_unique<Layer>(ui::LAYER_SOLID_COLOR);
  280. viz::ParentLocalSurfaceIdAllocator allocator;
  281. allocator.GenerateId();
  282. root_layer->SetBounds(gfx::Rect(10, 10));
  283. compositor()->SetRootLayer(root_layer.get());
  284. compositor()->SetScaleAndSize(1.0f, gfx::Size(10, 10),
  285. allocator.GetCurrentLocalSurfaceId());
  286. ASSERT_TRUE(compositor()->IsVisible());
  287. ThroughputTracker tracker = compositor()->RequestNewThroughputTracker();
  288. base::RunLoop run_loop;
  289. tracker.Start(base::BindLambdaForTesting(
  290. [&](const cc::FrameSequenceMetrics::CustomReportData& data) {
  291. EXPECT_GT(data.frames_expected, 0u);
  292. EXPECT_GT(data.frames_produced, 0u);
  293. run_loop.Quit();
  294. }));
  295. // Generates a few frames after tracker starts to have some data collected.
  296. for (int i = 0; i < 5; ++i) {
  297. compositor()->ScheduleFullRedraw();
  298. DrawWaiterForTest::WaitForCompositingEnded(compositor());
  299. }
  300. EXPECT_TRUE(tracker.Stop());
  301. // Generates a few frames after tracker stops. Note the number of frames
  302. // must be at least two: one to trigger underlying cc::FrameSequenceTracker to
  303. // be scheduled for termination and one to report data.
  304. for (int i = 0; i < 5; ++i) {
  305. compositor()->ScheduleFullRedraw();
  306. DrawWaiterForTest::WaitForCompositingEnded(compositor());
  307. }
  308. run_loop.Run();
  309. }
  310. TEST_F(CompositorTestWithMessageLoop, ThroughputTrackerOutliveCompositor) {
  311. auto tracker = compositor()->RequestNewThroughputTracker();
  312. tracker.Start(base::BindLambdaForTesting(
  313. [&](const cc::FrameSequenceMetrics::CustomReportData& data) {
  314. ADD_FAILURE() << "No report should happen";
  315. }));
  316. DestroyCompositor();
  317. // Stop() fails but no crash, no use-after-free and no report.
  318. EXPECT_FALSE(tracker.Stop());
  319. }
  320. TEST_F(CompositorTestWithMessageLoop, ThroughputTrackerCallbackStateChange) {
  321. auto root_layer = std::make_unique<Layer>(ui::LAYER_SOLID_COLOR);
  322. viz::ParentLocalSurfaceIdAllocator allocator;
  323. allocator.GenerateId();
  324. root_layer->SetBounds(gfx::Rect(10, 10));
  325. compositor()->SetRootLayer(root_layer.get());
  326. compositor()->SetScaleAndSize(1.0f, gfx::Size(10, 10),
  327. allocator.GetCurrentLocalSurfaceId());
  328. ASSERT_TRUE(compositor()->IsVisible());
  329. ThroughputTracker tracker = compositor()->RequestNewThroughputTracker();
  330. base::RunLoop run_loop;
  331. tracker.Start(base::BindLambdaForTesting(
  332. [&](const cc::FrameSequenceMetrics::CustomReportData& data) {
  333. // The following Cancel() call should not DCHECK or crash.
  334. tracker.Cancel();
  335. // Starting another tracker should not DCHECK or crash.
  336. ThroughputTracker another_tracker =
  337. compositor()->RequestNewThroughputTracker();
  338. another_tracker.Start(base::DoNothing());
  339. run_loop.Quit();
  340. }));
  341. // Generates a few frames after tracker starts to have some data collected.
  342. for (int i = 0; i < 5; ++i) {
  343. compositor()->ScheduleFullRedraw();
  344. DrawWaiterForTest::WaitForCompositingEnded(compositor());
  345. }
  346. EXPECT_TRUE(tracker.Stop());
  347. // Generates a few frames after tracker stops. Note the number of frames
  348. // must be at least two: one to trigger underlying cc::FrameSequenceTracker to
  349. // be scheduled for termination and one to report data.
  350. for (int i = 0; i < 5; ++i) {
  351. compositor()->ScheduleFullRedraw();
  352. DrawWaiterForTest::WaitForCompositingEnded(compositor());
  353. }
  354. run_loop.Run();
  355. }
  356. TEST_F(CompositorTestWithMessageLoop, ThroughputTrackerInvoluntaryReport) {
  357. auto root_layer = std::make_unique<Layer>(ui::LAYER_SOLID_COLOR);
  358. viz::ParentLocalSurfaceIdAllocator allocator;
  359. allocator.GenerateId();
  360. root_layer->SetBounds(gfx::Rect(10, 10));
  361. compositor()->SetRootLayer(root_layer.get());
  362. compositor()->SetScaleAndSize(1.0f, gfx::Size(10, 10),
  363. allocator.GetCurrentLocalSurfaceId());
  364. ASSERT_TRUE(compositor()->IsVisible());
  365. ThroughputTracker tracker = compositor()->RequestNewThroughputTracker();
  366. tracker.Start(base::BindLambdaForTesting(
  367. [&](const cc::FrameSequenceMetrics::CustomReportData& data) {
  368. ADD_FAILURE() << "No report should happen";
  369. }));
  370. // Generates a few frames after tracker starts to have some data collected.
  371. for (int i = 0; i < 5; ++i) {
  372. compositor()->ScheduleFullRedraw();
  373. DrawWaiterForTest::WaitForCompositingEnded(compositor());
  374. }
  375. // ReleaseAcceleratedWidget() destroys underlying cc::FrameSequenceTracker
  376. // and triggers reports before Stop(). Such reports are dropped.
  377. compositor()->SetVisible(false);
  378. compositor()->ReleaseAcceleratedWidget();
  379. // Stop() fails but no DCHECK or crash.
  380. EXPECT_FALSE(tracker.Stop());
  381. }
  382. #if BUILDFLAG(IS_WIN)
  383. // TODO(crbug.com/608436): Flaky on windows trybots
  384. #define MAYBE_CreateAndReleaseOutputSurface \
  385. DISABLED_CreateAndReleaseOutputSurface
  386. #else
  387. #define MAYBE_CreateAndReleaseOutputSurface CreateAndReleaseOutputSurface
  388. #endif
  389. TEST_F(CompositorTestWithMessageLoop, MAYBE_CreateAndReleaseOutputSurface) {
  390. std::unique_ptr<Layer> root_layer(new Layer(ui::LAYER_SOLID_COLOR));
  391. viz::ParentLocalSurfaceIdAllocator allocator;
  392. allocator.GenerateId();
  393. root_layer->SetBounds(gfx::Rect(10, 10));
  394. compositor()->SetRootLayer(root_layer.get());
  395. compositor()->SetScaleAndSize(1.0f, gfx::Size(10, 10),
  396. allocator.GetCurrentLocalSurfaceId());
  397. ASSERT_TRUE(compositor()->IsVisible());
  398. compositor()->ScheduleDraw();
  399. DrawWaiterForTest::WaitForCompositingEnded(compositor());
  400. compositor()->SetVisible(false);
  401. EXPECT_EQ(gfx::kNullAcceleratedWidget,
  402. compositor()->ReleaseAcceleratedWidget());
  403. compositor()->SetAcceleratedWidget(gfx::kNullAcceleratedWidget);
  404. compositor()->SetVisible(true);
  405. compositor()->ScheduleDraw();
  406. DrawWaiterForTest::WaitForCompositingEnded(compositor());
  407. compositor()->SetRootLayer(nullptr);
  408. }
  409. class LayerDelegateThatAddsDuringUpdateVisualState : public LayerDelegate {
  410. public:
  411. explicit LayerDelegateThatAddsDuringUpdateVisualState(Layer* parent)
  412. : parent_(parent) {}
  413. bool update_visual_state_called() const {
  414. return update_visual_state_called_;
  415. }
  416. // LayerDelegate:
  417. void UpdateVisualState() override {
  418. added_layers_.push_back(std::make_unique<Layer>(ui::LAYER_SOLID_COLOR));
  419. parent_->Add(added_layers_.back().get());
  420. update_visual_state_called_ = true;
  421. }
  422. void OnPaintLayer(const PaintContext& context) override {}
  423. void OnDeviceScaleFactorChanged(float old_device_scale_factor,
  424. float new_device_scale_factor) override {}
  425. private:
  426. raw_ptr<Layer> parent_;
  427. std::vector<std::unique_ptr<Layer>> added_layers_;
  428. bool update_visual_state_called_ = false;
  429. };
  430. TEST_F(CompositorTestWithMessageLoop, AddLayerDuringUpdateVisualState) {
  431. std::unique_ptr<Layer> root_layer =
  432. std::make_unique<Layer>(ui::LAYER_SOLID_COLOR);
  433. std::unique_ptr<Layer> child_layer =
  434. std::make_unique<Layer>(ui::LAYER_TEXTURED);
  435. std::unique_ptr<Layer> child_layer2 =
  436. std::make_unique<Layer>(ui::LAYER_SOLID_COLOR);
  437. LayerDelegateThatAddsDuringUpdateVisualState child_layer_delegate(
  438. root_layer.get());
  439. child_layer->set_delegate(&child_layer_delegate);
  440. root_layer->Add(child_layer.get());
  441. root_layer->Add(child_layer2.get());
  442. viz::ParentLocalSurfaceIdAllocator allocator;
  443. allocator.GenerateId();
  444. root_layer->SetBounds(gfx::Rect(10, 10));
  445. compositor()->SetRootLayer(root_layer.get());
  446. compositor()->SetScaleAndSize(1.0f, gfx::Size(10, 10),
  447. allocator.GetCurrentLocalSurfaceId());
  448. ASSERT_TRUE(compositor()->IsVisible());
  449. compositor()->ScheduleDraw();
  450. DrawWaiterForTest::WaitForCompositingEnded(compositor());
  451. EXPECT_TRUE(child_layer_delegate.update_visual_state_called());
  452. compositor()->SetRootLayer(nullptr);
  453. child_layer2.reset();
  454. child_layer.reset();
  455. root_layer.reset();
  456. }
  457. TEST_F(CompositorTestWithMessageLoop, PriorityCutoffWhenVisible) {
  458. EXPECT_EQ(gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE,
  459. compositor()
  460. ->GetLayerTreeSettings()
  461. .memory_policy.priority_cutoff_when_visible);
  462. base::test::ScopedFeatureList scoped_feature_list;
  463. scoped_feature_list.InitAndEnableFeature(
  464. features::kUiCompositorRequiredTilesOnly);
  465. DestroyCompositor();
  466. CreateCompositor();
  467. EXPECT_EQ(gpu::MemoryAllocation::CUTOFF_ALLOW_REQUIRED_ONLY,
  468. compositor()
  469. ->GetLayerTreeSettings()
  470. .memory_policy.priority_cutoff_when_visible);
  471. }
  472. TEST_F(CompositorTestWithMessageLoop, ReleaseTileResourcesForHiddenLayers) {
  473. EXPECT_FALSE(compositor()
  474. ->GetLayerTreeSettings()
  475. .release_tile_resources_for_hidden_layers);
  476. base::test::ScopedFeatureList scoped_feature_list;
  477. scoped_feature_list.InitAndEnableFeature(
  478. features::kUiCompositorReleaseTileResourcesForHiddenLayers);
  479. DestroyCompositor();
  480. CreateCompositor();
  481. EXPECT_TRUE(compositor()
  482. ->GetLayerTreeSettings()
  483. .release_tile_resources_for_hidden_layers);
  484. }
  485. } // namespace ui