Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(461)

Side by Side Diff: cc/trees/layer_tree_host_unittest.cc

Issue 671653005: SetNeedsRedraw directly when updating a visible tile. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: pinchblurmerge-test: . Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/trees/layer_tree_host_impl_unittest.cc ('k') | cc/trees/layer_tree_host_unittest_damage.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/trees/layer_tree_host.h" 5 #include "cc/trees/layer_tree_host.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/synchronization/lock.h" 10 #include "base/synchronization/lock.h"
11 #include "cc/animation/timing_function.h" 11 #include "cc/animation/timing_function.h"
12 #include "cc/base/swap_promise.h" 12 #include "cc/base/swap_promise.h"
13 #include "cc/debug/frame_rate_counter.h" 13 #include "cc/debug/frame_rate_counter.h"
14 #include "cc/layers/content_layer.h" 14 #include "cc/layers/content_layer.h"
15 #include "cc/layers/content_layer_client.h" 15 #include "cc/layers/content_layer_client.h"
16 #include "cc/layers/io_surface_layer.h" 16 #include "cc/layers/io_surface_layer.h"
17 #include "cc/layers/layer_impl.h" 17 #include "cc/layers/layer_impl.h"
18 #include "cc/layers/painted_scrollbar_layer.h" 18 #include "cc/layers/painted_scrollbar_layer.h"
19 #include "cc/layers/picture_layer.h" 19 #include "cc/layers/picture_layer.h"
20 #include "cc/layers/solid_color_layer.h" 20 #include "cc/layers/solid_color_layer.h"
21 #include "cc/layers/video_layer.h" 21 #include "cc/layers/video_layer.h"
22 #include "cc/output/begin_frame_args.h" 22 #include "cc/output/begin_frame_args.h"
23 #include "cc/output/compositor_frame_ack.h" 23 #include "cc/output/compositor_frame_ack.h"
24 #include "cc/output/copy_output_request.h" 24 #include "cc/output/copy_output_request.h"
25 #include "cc/output/copy_output_result.h" 25 #include "cc/output/copy_output_result.h"
26 #include "cc/output/output_surface.h" 26 #include "cc/output/output_surface.h"
27 #include "cc/quads/draw_quad.h" 27 #include "cc/quads/draw_quad.h"
28 #include "cc/quads/io_surface_draw_quad.h" 28 #include "cc/quads/io_surface_draw_quad.h"
29 #include "cc/quads/tile_draw_quad.h"
29 #include "cc/resources/prioritized_resource.h" 30 #include "cc/resources/prioritized_resource.h"
30 #include "cc/resources/prioritized_resource_manager.h" 31 #include "cc/resources/prioritized_resource_manager.h"
31 #include "cc/resources/resource_update_queue.h" 32 #include "cc/resources/resource_update_queue.h"
32 #include "cc/test/fake_content_layer.h" 33 #include "cc/test/fake_content_layer.h"
33 #include "cc/test/fake_content_layer_client.h" 34 #include "cc/test/fake_content_layer_client.h"
34 #include "cc/test/fake_content_layer_impl.h" 35 #include "cc/test/fake_content_layer_impl.h"
35 #include "cc/test/fake_layer_tree_host_client.h" 36 #include "cc/test/fake_layer_tree_host_client.h"
36 #include "cc/test/fake_output_surface.h" 37 #include "cc/test/fake_output_surface.h"
37 #include "cc/test/fake_painted_scrollbar_layer.h" 38 #include "cc/test/fake_painted_scrollbar_layer.h"
38 #include "cc/test/fake_picture_layer.h" 39 #include "cc/test/fake_picture_layer.h"
39 #include "cc/test/fake_picture_layer_impl.h" 40 #include "cc/test/fake_picture_layer_impl.h"
41 #include "cc/test/fake_picture_pile.h"
40 #include "cc/test/fake_proxy.h" 42 #include "cc/test/fake_proxy.h"
41 #include "cc/test/fake_scoped_ui_resource.h" 43 #include "cc/test/fake_scoped_ui_resource.h"
42 #include "cc/test/fake_video_frame_provider.h" 44 #include "cc/test/fake_video_frame_provider.h"
43 #include "cc/test/geometry_test_utils.h" 45 #include "cc/test/geometry_test_utils.h"
44 #include "cc/test/layer_tree_test.h" 46 #include "cc/test/layer_tree_test.h"
45 #include "cc/test/test_shared_bitmap_manager.h" 47 #include "cc/test/test_shared_bitmap_manager.h"
46 #include "cc/test/test_web_graphics_context_3d.h" 48 #include "cc/test/test_web_graphics_context_3d.h"
47 #include "cc/trees/layer_tree_host_impl.h" 49 #include "cc/trees/layer_tree_host_impl.h"
48 #include "cc/trees/layer_tree_impl.h" 50 #include "cc/trees/layer_tree_impl.h"
49 #include "cc/trees/single_thread_proxy.h" 51 #include "cc/trees/single_thread_proxy.h"
(...skipping 4967 matching lines...) Expand 10 before | Expand all | Expand 10 after
5017 void InitializeSettings(LayerTreeSettings* settings) override { 5019 void InitializeSettings(LayerTreeSettings* settings) override {
5018 settings->impl_side_painting = true; 5020 settings->impl_side_painting = true;
5019 5021
5020 EXPECT_FALSE(settings->gpu_rasterization_forced); 5022 EXPECT_FALSE(settings->gpu_rasterization_forced);
5021 settings->gpu_rasterization_forced = true; 5023 settings->gpu_rasterization_forced = true;
5022 } 5024 }
5023 5025
5024 void SetupTree() override { 5026 void SetupTree() override {
5025 LayerTreeHostTest::SetupTree(); 5027 LayerTreeHostTest::SetupTree();
5026 5028
5027 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&layer_client_); 5029 scoped_refptr<FakePictureLayer> layer =
5030 FakePictureLayer::Create(&layer_client_);
5028 layer->SetBounds(gfx::Size(10, 10)); 5031 layer->SetBounds(gfx::Size(10, 10));
5029 layer->SetIsDrawable(true); 5032 layer->SetIsDrawable(true);
5030 layer_tree_host()->root_layer()->AddChild(layer); 5033 layer_tree_host()->root_layer()->AddChild(layer);
5031 } 5034 }
5032 5035
5033 void BeginTest() override { 5036 void BeginTest() override {
5034 Layer* root = layer_tree_host()->root_layer(); 5037 Layer* root = layer_tree_host()->root_layer();
5035 PictureLayer* layer = static_cast<PictureLayer*>(root->child_at(0)); 5038 PictureLayer* layer = static_cast<PictureLayer*>(root->child_at(0));
5036 RecordingSource* recording_source = layer->GetRecordingSourceForTesting(); 5039 RecordingSource* recording_source = layer->GetRecordingSourceForTesting();
5037 5040
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
5347 5350
5348 void AfterTest() override { 5351 void AfterTest() override {
5349 EXPECT_TRUE(deltas_sent_to_client_); 5352 EXPECT_TRUE(deltas_sent_to_client_);
5350 } 5353 }
5351 5354
5352 ScrollAndScaleSet info_; 5355 ScrollAndScaleSet info_;
5353 bool deltas_sent_to_client_; 5356 bool deltas_sent_to_client_;
5354 }; 5357 };
5355 5358
5356 MULTI_THREAD_TEST_F(LayerTreeHostAcceptsDeltasFromImplWithoutRootLayer); 5359 MULTI_THREAD_TEST_F(LayerTreeHostAcceptsDeltasFromImplWithoutRootLayer);
5360
5361 class LayerTreeHostTestCrispUpAfterPinchEnds : public LayerTreeHostTest {
5362 protected:
5363 LayerTreeHostTestCrispUpAfterPinchEnds()
5364 : playback_allowed_event_(true, true) {}
5365
5366 void InitializeSettings(LayerTreeSettings* settings) override {
5367 settings->impl_side_painting = true;
5368 }
5369
5370 void SetupTree() override {
5371 frame_ = 1;
5372 posted_ = false;
5373 client_.set_fill_with_nonsolid_color(true);
5374
5375 scoped_refptr<Layer> root = Layer::Create();
5376 root->SetBounds(gfx::Size(500, 500));
5377
5378 scoped_refptr<Layer> pinch = Layer::Create();
5379 pinch->SetBounds(gfx::Size(500, 500));
5380 pinch->SetScrollClipLayerId(root->id());
5381 pinch->SetIsContainerForFixedPositionLayers(true);
5382 root->AddChild(pinch);
5383
5384 scoped_ptr<FakePicturePile> pile(new FakePicturePile);
5385 pile->SetPlaybackAllowedEvent(&playback_allowed_event_);
5386 scoped_refptr<FakePictureLayer> layer =
5387 FakePictureLayer::CreateWithRecordingSource(&client_, pile.Pass());
5388 layer->SetBounds(gfx::Size(500, 500));
5389 layer->SetContentsOpaque(true);
5390 pinch->AddChild(layer);
5391
5392 layer_tree_host()->RegisterViewportLayers(root, pinch, pinch);
5393 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 1.f, 4.f);
5394 layer_tree_host()->SetRootLayer(root);
5395 LayerTreeHostTest::SetupTree();
5396 }
5397
5398 // Returns the delta scale of all quads in the frame's root pass from their
5399 // ideal, or 0 if they are not all the same.
5400 float FrameQuadScaleDeltaFromIdeal(LayerTreeHostImpl::FrameData* frame_data) {
5401 if (frame_data->has_no_damage)
5402 return 0.f;
5403 float frame_scale = 0.f;
5404 RenderPass* root_pass = frame_data->render_passes.back();
5405 for (const auto& draw_quad : root_pass->quad_list) {
5406 // Checkerboards mean an incomplete frame.
5407 if (draw_quad->material != DrawQuad::TILED_CONTENT)
5408 return 0.f;
5409 const TileDrawQuad* quad = TileDrawQuad::MaterialCast(draw_quad);
5410 float quad_scale =
5411 quad->tex_coord_rect.width() / static_cast<float>(quad->rect.width());
5412 float transform_scale =
5413 SkMScalarToFloat(quad->quadTransform().matrix().get(0, 0));
5414 float scale = quad_scale / transform_scale;
5415 if (frame_scale != 0.f && frame_scale != scale)
5416 return 0.f;
5417 frame_scale = scale;
5418 }
5419 return frame_scale;
5420 }
5421
5422 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
5423
5424 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
5425 LayerTreeHostImpl::FrameData* frame_data,
5426 DrawResult draw_result) override {
5427 float quad_scale_delta = FrameQuadScaleDeltaFromIdeal(frame_data);
5428 switch (frame_) {
5429 case 1:
5430 // Drew at page scale 1 before any pinching.
5431 EXPECT_EQ(1.f, host_impl->active_tree()->total_page_scale_factor());
5432 EXPECT_EQ(1.f, quad_scale_delta);
5433 PostNextAfterDraw(host_impl);
5434 break;
5435 case 2:
5436 if (quad_scale_delta != 1.f)
5437 break;
5438 // Drew at page scale 2.2 after pinching in.
5439 EXPECT_EQ(2.2f, host_impl->active_tree()->total_page_scale_factor());
5440 EXPECT_EQ(1.f, quad_scale_delta);
5441 PostNextAfterDraw(host_impl);
5442 break;
5443 case 3:
5444 if (quad_scale_delta != 2.2f)
5445 break;
5446 // Drew at page scale 1 with the 2.2 tiling while pinching out.
5447 EXPECT_EQ(1.f, host_impl->active_tree()->total_page_scale_factor());
5448 EXPECT_EQ(2.2f, quad_scale_delta);
5449 PostNextAfterDraw(host_impl);
5450 break;
5451 case 4:
5452 // Drew at page scale 1 with the 2.2 tiling after pinching out completed
5453 // while waiting for texture uploads to complete.
5454 EXPECT_EQ(1.f, host_impl->active_tree()->total_page_scale_factor());
5455 // This frame will not have any damage, since it's actually the same as
5456 // the last frame, and should contain no incomplete tiles. We just want
5457 // to make sure we drew here at least once after the pinch ended to be
5458 // sure that drawing after pinch doesn't leave us at the wrong scale
5459 // forever.
5460 EXPECT_TRUE(frame_data->has_no_damage);
5461 PostNextAfterDraw(host_impl);
5462 break;
5463 case 5:
5464 if (quad_scale_delta != 1.f)
5465 break;
5466 // Drew at scale 1 after texture uploads are done.
5467 EXPECT_EQ(1.f, host_impl->active_tree()->total_page_scale_factor());
5468 EXPECT_EQ(1.f, quad_scale_delta);
5469 EndTest();
5470 break;
5471 }
5472 return draw_result;
5473 }
5474
5475 void PostNextAfterDraw(LayerTreeHostImpl* host_impl) {
5476 if (posted_)
5477 return;
5478 posted_ = true;
5479 ImplThreadTaskRunner()->PostDelayedTask(
5480 FROM_HERE, base::Bind(&LayerTreeHostTestCrispUpAfterPinchEnds::Next,
5481 base::Unretained(this), host_impl),
5482 // Use a delay to allow raster/upload to happen in between frames. This
5483 // should cause flakiness if we fail to block raster/upload when
5484 // desired.
5485 base::TimeDelta::FromMilliseconds(16 * 6));
5486 }
5487
5488 void Next(LayerTreeHostImpl* host_impl) {
5489 ++frame_;
5490 posted_ = false;
5491 switch (frame_) {
5492 case 2:
5493 // Pinch zoom in.
5494 host_impl->PinchGestureBegin();
5495 host_impl->PinchGestureUpdate(2.2f, gfx::Point(100, 100));
5496 host_impl->PinchGestureEnd();
5497 break;
5498 case 3:
5499 // Pinch zoom back to 1.f but don't end it.
5500 host_impl->PinchGestureBegin();
5501 host_impl->PinchGestureUpdate(1.f / 2.2f, gfx::Point(100, 100));
5502 break;
5503 case 4:
5504 // End the pinch, but delay tile production.
5505 playback_allowed_event_.Reset();
5506 host_impl->PinchGestureEnd();
5507 break;
5508 case 5:
5509 // Let tiles complete.
5510 playback_allowed_event_.Signal();
5511 break;
5512 }
5513 }
5514
5515 void NotifyTileStateChangedOnThread(LayerTreeHostImpl* host_impl,
5516 const Tile* tile) override {
5517 // On frame_ == 4, we are preventing texture uploads from completing,
5518 // so this verifies they are not completing before frame_ == 5.
5519 // Flaky failures here indicate we're failing to prevent uploads from
5520 // completing.
5521 EXPECT_NE(4, frame_);
5522 }
5523
5524 void AfterTest() override {}
5525
5526 FakeContentLayerClient client_;
5527 int frame_;
5528 bool posted_;
5529 base::WaitableEvent playback_allowed_event_;
5530 };
5531
5532 MULTI_THREAD_TEST_F(LayerTreeHostTestCrispUpAfterPinchEnds);
5533
5534 class LayerTreeHostTestCrispUpAfterPinchEndsWithOneCopy
5535 : public LayerTreeHostTestCrispUpAfterPinchEnds {
5536 protected:
5537 void InitializeSettings(LayerTreeSettings* settings) override {
5538 settings->impl_side_painting = true;
5539 settings->use_one_copy = true;
5540 }
5541
5542 scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface(
5543 bool fallback) override {
5544 scoped_ptr<TestWebGraphicsContext3D> context3d =
5545 TestWebGraphicsContext3D::Create();
5546 context3d->set_support_image(true);
5547 context3d->set_support_sync_query(true);
5548
5549 if (delegating_renderer())
5550 return FakeOutputSurface::CreateDelegating3d(context3d.Pass());
5551 else
5552 return FakeOutputSurface::Create3d(context3d.Pass());
5553 }
5554 };
5555
5556 MULTI_THREAD_TEST_F(LayerTreeHostTestCrispUpAfterPinchEndsWithOneCopy);
5557
5558 class LayerTreeHostTestContinuousDrawWhenCreatingVisibleTiles
5559 : public LayerTreeHostTest {
5560 protected:
5561 LayerTreeHostTestContinuousDrawWhenCreatingVisibleTiles()
5562 : playback_allowed_event_(true, true) {}
5563
5564 void InitializeSettings(LayerTreeSettings* settings) override {
5565 settings->impl_side_painting = true;
5566 }
5567
5568 void SetupTree() override {
5569 step_ = 1;
5570 continuous_draws_ = 0;
5571 client_.set_fill_with_nonsolid_color(true);
5572
5573 scoped_refptr<Layer> root = Layer::Create();
5574 root->SetBounds(gfx::Size(500, 500));
5575
5576 scoped_refptr<Layer> pinch = Layer::Create();
5577 pinch->SetBounds(gfx::Size(500, 500));
5578 pinch->SetScrollClipLayerId(root->id());
5579 pinch->SetIsContainerForFixedPositionLayers(true);
5580 root->AddChild(pinch);
5581
5582 scoped_ptr<FakePicturePile> pile(new FakePicturePile);
5583 pile->SetPlaybackAllowedEvent(&playback_allowed_event_);
5584 scoped_refptr<FakePictureLayer> layer =
5585 FakePictureLayer::CreateWithRecordingSource(&client_, pile.Pass());
5586 layer->SetBounds(gfx::Size(500, 500));
5587 layer->SetContentsOpaque(true);
5588 pinch->AddChild(layer);
5589
5590 layer_tree_host()->RegisterViewportLayers(root, pinch, pinch);
5591 layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 1.f, 4.f);
5592 layer_tree_host()->SetRootLayer(root);
5593 LayerTreeHostTest::SetupTree();
5594 }
5595
5596 // Returns the delta scale of all quads in the frame's root pass from their
5597 // ideal, or 0 if they are not all the same.
5598 float FrameQuadScaleDeltaFromIdeal(LayerTreeHostImpl::FrameData* frame_data) {
5599 if (frame_data->has_no_damage)
5600 return 0.f;
5601 float frame_scale = 0.f;
5602 RenderPass* root_pass = frame_data->render_passes.back();
5603 for (const auto& draw_quad : root_pass->quad_list) {
5604 const TileDrawQuad* quad = TileDrawQuad::MaterialCast(draw_quad);
5605 float quad_scale =
5606 quad->tex_coord_rect.width() / static_cast<float>(quad->rect.width());
5607 float transform_scale =
5608 SkMScalarToFloat(quad->quadTransform().matrix().get(0, 0));
5609 float scale = quad_scale / transform_scale;
5610 if (frame_scale != 0.f && frame_scale != scale)
5611 return 0.f;
5612 frame_scale = scale;
5613 }
5614 return frame_scale;
5615 }
5616
5617 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
5618
5619 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
5620 LayerTreeHostImpl::FrameData* frame_data,
5621 DrawResult draw_result) override {
5622 float quad_scale_delta = FrameQuadScaleDeltaFromIdeal(frame_data);
5623 switch (step_) {
5624 case 1:
5625 // Drew at scale 1 before any pinching.
5626 EXPECT_EQ(1.f, host_impl->active_tree()->total_page_scale_factor());
5627 EXPECT_EQ(1.f, quad_scale_delta);
5628 break;
5629 case 2:
5630 if (quad_scale_delta != 1.f / 1.5f)
5631 break;
5632 // Drew at scale 1 still though the ideal is 1.5.
5633 EXPECT_EQ(1.5f, host_impl->active_tree()->total_page_scale_factor());
5634 EXPECT_EQ(1.f / 1.5f, quad_scale_delta);
5635 break;
5636 case 3:
5637 // Continuous draws are attempted.
5638 EXPECT_EQ(1.5f, host_impl->active_tree()->total_page_scale_factor());
5639 if (!frame_data->has_no_damage)
5640 EXPECT_EQ(1.f / 1.5f, quad_scale_delta);
5641 break;
5642 case 4:
5643 if (quad_scale_delta != 1.f)
5644 break;
5645 // Drew at scale 1.5 when all the tiles completed.
5646 EXPECT_EQ(1.5f, host_impl->active_tree()->total_page_scale_factor());
5647 EXPECT_EQ(1.f, quad_scale_delta);
5648
5649 // We should not continue to draw any more. End the test after a timeout
5650 // to watch for any extraneous draws.
5651 // TODO(brianderson): We could remove this delay and instead wait until
5652 // the BeginFrameSource decides it doesn't need to send frames anymore,
5653 // or test that it already doesn't here.
5654 EndTestAfterDelayMs(16 * 4);
5655 ++step_;
5656 break;
5657 case 5:
5658 ADD_FAILURE()
5659 << "No draws should happen once we have a complete frame.";
5660 break;
5661 }
5662 return draw_result;
5663 }
5664
5665 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override {
5666 switch (step_) {
5667 case 1:
5668 // Delay tile production.
5669 playback_allowed_event_.Reset();
5670 // Pinch zoom in to cause new tiles to be required.
5671 host_impl->PinchGestureBegin();
5672 host_impl->PinchGestureUpdate(1.5f, gfx::Point(100, 100));
5673 host_impl->PinchGestureEnd();
5674 ++step_;
5675 break;
5676 case 2:
5677 ++step_;
5678 break;
5679 case 3:
5680 // We should continue to try draw while there are incomplete visible
5681 // tiles.
5682 if (++continuous_draws_ > 5) {
5683 // Allow the tiles to complete.
5684 playback_allowed_event_.Signal();
5685 ++step_;
5686 }
5687 break;
5688 }
5689 }
5690
5691 void NotifyTileStateChangedOnThread(LayerTreeHostImpl* host_impl,
5692 const Tile* tile) override {
5693 // On step_ == 2, we are preventing texture uploads from completing,
5694 // so this verifies they are not completing before step_ == 3.
5695 // Flaky failures here indicate we're failing to prevent uploads from
5696 // completing.
5697 EXPECT_NE(2, step_);
5698 }
5699
5700 void AfterTest() override { EXPECT_GT(continuous_draws_, 5); }
5701
5702 FakeContentLayerClient client_;
5703 int step_;
5704 int continuous_draws_;
5705 base::WaitableEvent playback_allowed_event_;
5706 };
5707
5708 MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousDrawWhenCreatingVisibleTiles);
5709
5357 } // namespace cc 5710 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_impl_unittest.cc ('k') | cc/trees/layer_tree_host_unittest_damage.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698