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

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

Issue 999173004: cc: Move worker threads to content. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comment and webview fix Created 5 years, 9 months 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
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_impl.h" 5 #include "cc/trees/layer_tree_host_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 #include "cc/test/fake_picture_layer_impl.h" 47 #include "cc/test/fake_picture_layer_impl.h"
48 #include "cc/test/fake_picture_pile_impl.h" 48 #include "cc/test/fake_picture_pile_impl.h"
49 #include "cc/test/fake_proxy.h" 49 #include "cc/test/fake_proxy.h"
50 #include "cc/test/fake_video_frame_provider.h" 50 #include "cc/test/fake_video_frame_provider.h"
51 #include "cc/test/geometry_test_utils.h" 51 #include "cc/test/geometry_test_utils.h"
52 #include "cc/test/layer_test_common.h" 52 #include "cc/test/layer_test_common.h"
53 #include "cc/test/layer_tree_test.h" 53 #include "cc/test/layer_tree_test.h"
54 #include "cc/test/render_pass_test_common.h" 54 #include "cc/test/render_pass_test_common.h"
55 #include "cc/test/test_gpu_memory_buffer_manager.h" 55 #include "cc/test/test_gpu_memory_buffer_manager.h"
56 #include "cc/test/test_shared_bitmap_manager.h" 56 #include "cc/test/test_shared_bitmap_manager.h"
57 #include "cc/test/test_task_graph_runner.h"
57 #include "cc/test/test_web_graphics_context_3d.h" 58 #include "cc/test/test_web_graphics_context_3d.h"
58 #include "cc/trees/layer_tree_impl.h" 59 #include "cc/trees/layer_tree_impl.h"
59 #include "cc/trees/single_thread_proxy.h" 60 #include "cc/trees/single_thread_proxy.h"
60 #include "media/base/media.h" 61 #include "media/base/media.h"
61 #include "testing/gmock/include/gmock/gmock.h" 62 #include "testing/gmock/include/gmock/gmock.h"
62 #include "testing/gtest/include/gtest/gtest.h" 63 #include "testing/gtest/include/gtest/gtest.h"
63 #include "third_party/skia/include/core/SkMallocPixelRef.h" 64 #include "third_party/skia/include/core/SkMallocPixelRef.h"
64 #include "ui/gfx/frame_time.h" 65 #include "ui/gfx/frame_time.h"
65 #include "ui/gfx/geometry/rect_conversions.h" 66 #include "ui/gfx/geometry/rect_conversions.h"
66 #include "ui/gfx/geometry/size_conversions.h" 67 #include "ui/gfx/geometry/size_conversions.h"
(...skipping 12 matching lines...) Expand all
79 class LayerTreeHostImplTest : public testing::Test, 80 class LayerTreeHostImplTest : public testing::Test,
80 public LayerTreeHostImplClient { 81 public LayerTreeHostImplClient {
81 public: 82 public:
82 LayerTreeHostImplTest() 83 LayerTreeHostImplTest()
83 : proxy_(base::MessageLoopProxy::current(), 84 : proxy_(base::MessageLoopProxy::current(),
84 base::MessageLoopProxy::current()), 85 base::MessageLoopProxy::current()),
85 always_impl_thread_(&proxy_), 86 always_impl_thread_(&proxy_),
86 always_main_thread_blocked_(&proxy_), 87 always_main_thread_blocked_(&proxy_),
87 shared_bitmap_manager_(new TestSharedBitmapManager), 88 shared_bitmap_manager_(new TestSharedBitmapManager),
88 gpu_memory_buffer_manager_(new TestGpuMemoryBufferManager), 89 gpu_memory_buffer_manager_(new TestGpuMemoryBufferManager),
90 task_graph_runner_(new TestTaskGraphRunner),
89 on_can_draw_state_changed_called_(false), 91 on_can_draw_state_changed_called_(false),
90 did_notify_ready_to_activate_(false), 92 did_notify_ready_to_activate_(false),
91 did_request_commit_(false), 93 did_request_commit_(false),
92 did_request_redraw_(false), 94 did_request_redraw_(false),
93 did_request_animate_(false), 95 did_request_animate_(false),
94 did_request_prepare_tiles_(false), 96 did_request_prepare_tiles_(false),
95 did_complete_page_scale_animation_(false), 97 did_complete_page_scale_animation_(false),
96 reduce_memory_result_(true), 98 reduce_memory_result_(true),
97 current_limit_bytes_(0), 99 current_limit_bytes_(0),
98 current_priority_cutoff_value_(0) { 100 current_priority_cutoff_value_(0) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 void DidCompletePageScaleAnimationOnImplThread() override { 162 void DidCompletePageScaleAnimationOnImplThread() override {
161 did_complete_page_scale_animation_ = true; 163 did_complete_page_scale_animation_ = true;
162 } 164 }
163 165
164 void set_reduce_memory_result(bool reduce_memory_result) { 166 void set_reduce_memory_result(bool reduce_memory_result) {
165 reduce_memory_result_ = reduce_memory_result; 167 reduce_memory_result_ = reduce_memory_result;
166 } 168 }
167 169
168 virtual bool CreateHostImpl(const LayerTreeSettings& settings, 170 virtual bool CreateHostImpl(const LayerTreeSettings& settings,
169 scoped_ptr<OutputSurface> output_surface) { 171 scoped_ptr<OutputSurface> output_surface) {
170 host_impl_ = LayerTreeHostImpl::Create(settings, 172 host_impl_ = LayerTreeHostImpl::Create(
171 this, 173 settings, this, &proxy_, &stats_instrumentation_,
172 &proxy_, 174 shared_bitmap_manager_.get(), gpu_memory_buffer_manager_.get(),
173 &stats_instrumentation_, 175 task_graph_runner_.get(), 0);
174 shared_bitmap_manager_.get(),
175 gpu_memory_buffer_manager_.get(),
176 0);
177 bool init = host_impl_->InitializeRenderer(output_surface.Pass()); 176 bool init = host_impl_->InitializeRenderer(output_surface.Pass());
178 host_impl_->SetViewportSize(gfx::Size(10, 10)); 177 host_impl_->SetViewportSize(gfx::Size(10, 10));
179 return init; 178 return init;
180 } 179 }
181 180
182 void SetupRootLayerImpl(scoped_ptr<LayerImpl> root) { 181 void SetupRootLayerImpl(scoped_ptr<LayerImpl> root) {
183 root->SetPosition(gfx::PointF()); 182 root->SetPosition(gfx::PointF());
184 root->SetBounds(gfx::Size(10, 10)); 183 root->SetBounds(gfx::Size(10, 10));
185 root->SetContentBounds(gfx::Size(10, 10)); 184 root->SetContentBounds(gfx::Size(10, 10));
186 root->SetDrawsContent(true); 185 root->SetDrawsContent(true);
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 host_impl_->PrepareToDraw(&frame_data); 387 host_impl_->PrepareToDraw(&frame_data);
389 host_impl_->DidDrawAllLayers(frame_data); 388 host_impl_->DidDrawAllLayers(frame_data);
390 } 389 }
391 390
392 FakeProxy proxy_; 391 FakeProxy proxy_;
393 DebugScopedSetImplThread always_impl_thread_; 392 DebugScopedSetImplThread always_impl_thread_;
394 DebugScopedSetMainThreadBlocked always_main_thread_blocked_; 393 DebugScopedSetMainThreadBlocked always_main_thread_blocked_;
395 394
396 scoped_ptr<TestSharedBitmapManager> shared_bitmap_manager_; 395 scoped_ptr<TestSharedBitmapManager> shared_bitmap_manager_;
397 scoped_ptr<TestGpuMemoryBufferManager> gpu_memory_buffer_manager_; 396 scoped_ptr<TestGpuMemoryBufferManager> gpu_memory_buffer_manager_;
397 scoped_ptr<TestTaskGraphRunner> task_graph_runner_;
398 scoped_ptr<LayerTreeHostImpl> host_impl_; 398 scoped_ptr<LayerTreeHostImpl> host_impl_;
399 FakeRenderingStatsInstrumentation stats_instrumentation_; 399 FakeRenderingStatsInstrumentation stats_instrumentation_;
400 bool on_can_draw_state_changed_called_; 400 bool on_can_draw_state_changed_called_;
401 bool did_notify_ready_to_activate_; 401 bool did_notify_ready_to_activate_;
402 bool did_request_commit_; 402 bool did_request_commit_;
403 bool did_request_redraw_; 403 bool did_request_redraw_;
404 bool did_request_animate_; 404 bool did_request_animate_;
405 bool did_request_prepare_tiles_; 405 bool did_request_prepare_tiles_;
406 bool did_complete_page_scale_animation_; 406 bool did_complete_page_scale_animation_;
407 bool reduce_memory_result_; 407 bool reduce_memory_result_;
(...skipping 1132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1540 LayerTreeHostImplClient* client, 1540 LayerTreeHostImplClient* client,
1541 Proxy* proxy, 1541 Proxy* proxy,
1542 SharedBitmapManager* manager, 1542 SharedBitmapManager* manager,
1543 RenderingStatsInstrumentation* rendering_stats_instrumentation) 1543 RenderingStatsInstrumentation* rendering_stats_instrumentation)
1544 : LayerTreeHostImpl(settings, 1544 : LayerTreeHostImpl(settings,
1545 client, 1545 client,
1546 proxy, 1546 proxy,
1547 rendering_stats_instrumentation, 1547 rendering_stats_instrumentation,
1548 manager, 1548 manager,
1549 NULL, 1549 NULL,
1550 NULL,
1550 0) {} 1551 0) {}
1551 1552
1552 BeginFrameArgs CurrentBeginFrameArgs() const override { 1553 BeginFrameArgs CurrentBeginFrameArgs() const override {
1553 return CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 1554 return CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE,
1554 fake_current_physical_time_); 1555 fake_current_physical_time_);
1555 } 1556 }
1556 1557
1557 void SetCurrentPhysicalTimeTicksForTest(base::TimeTicks fake_now) { 1558 void SetCurrentPhysicalTimeTicksForTest(base::TimeTicks fake_now) {
1558 fake_current_physical_time_ = fake_now; 1559 fake_current_physical_time_ = fake_now;
1559 } 1560 }
(...skipping 3479 matching lines...) Expand 10 before | Expand all | Expand 10 after
5039 context_provider->TestContext3d()->set_have_post_sub_buffer(true); 5040 context_provider->TestContext3d()->set_have_post_sub_buffer(true);
5040 5041
5041 scoped_ptr<FakeOutputSurface> output_surface( 5042 scoped_ptr<FakeOutputSurface> output_surface(
5042 FakeOutputSurface::Create3d(context_provider)); 5043 FakeOutputSurface::Create3d(context_provider));
5043 FakeOutputSurface* fake_output_surface = output_surface.get(); 5044 FakeOutputSurface* fake_output_surface = output_surface.get();
5044 5045
5045 // This test creates its own LayerTreeHostImpl, so 5046 // This test creates its own LayerTreeHostImpl, so
5046 // that we can force partial swap enabled. 5047 // that we can force partial swap enabled.
5047 LayerTreeSettings settings; 5048 LayerTreeSettings settings;
5048 settings.renderer_settings.partial_swap_enabled = true; 5049 settings.renderer_settings.partial_swap_enabled = true;
5049 scoped_ptr<SharedBitmapManager> shared_bitmap_manager(
5050 new TestSharedBitmapManager());
5051 scoped_ptr<LayerTreeHostImpl> layer_tree_host_impl = 5050 scoped_ptr<LayerTreeHostImpl> layer_tree_host_impl =
5052 LayerTreeHostImpl::Create(settings, 5051 LayerTreeHostImpl::Create(
5053 this, 5052 settings, this, &proxy_, &stats_instrumentation_,
5054 &proxy_, 5053 shared_bitmap_manager_.get(), NULL, task_graph_runner_.get(), 0);
5055 &stats_instrumentation_,
5056 shared_bitmap_manager.get(),
5057 NULL,
5058 0);
5059 layer_tree_host_impl->InitializeRenderer(output_surface.Pass()); 5054 layer_tree_host_impl->InitializeRenderer(output_surface.Pass());
5060 layer_tree_host_impl->SetViewportSize(gfx::Size(500, 500)); 5055 layer_tree_host_impl->SetViewportSize(gfx::Size(500, 500));
5061 5056
5062 scoped_ptr<LayerImpl> root = 5057 scoped_ptr<LayerImpl> root =
5063 FakeDrawableLayerImpl::Create(layer_tree_host_impl->active_tree(), 1); 5058 FakeDrawableLayerImpl::Create(layer_tree_host_impl->active_tree(), 1);
5064 root->SetHasRenderSurface(true); 5059 root->SetHasRenderSurface(true);
5065 scoped_ptr<LayerImpl> child = 5060 scoped_ptr<LayerImpl> child =
5066 FakeDrawableLayerImpl::Create(layer_tree_host_impl->active_tree(), 2); 5061 FakeDrawableLayerImpl::Create(layer_tree_host_impl->active_tree(), 2);
5067 child->SetPosition(gfx::PointF(12.f, 13.f)); 5062 child->SetPosition(gfx::PointF(12.f, 13.f));
5068 child->SetBounds(gfx::Size(14, 15)); 5063 child->SetBounds(gfx::Size(14, 15));
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
5336 RenderingStatsInstrumentation* stats_instrumentation) { 5331 RenderingStatsInstrumentation* stats_instrumentation) {
5337 scoped_refptr<TestContextProvider> provider(TestContextProvider::Create()); 5332 scoped_refptr<TestContextProvider> provider(TestContextProvider::Create());
5338 scoped_ptr<OutputSurface> output_surface( 5333 scoped_ptr<OutputSurface> output_surface(
5339 FakeOutputSurface::Create3d(provider)); 5334 FakeOutputSurface::Create3d(provider));
5340 provider->BindToCurrentThread(); 5335 provider->BindToCurrentThread();
5341 provider->TestContext3d()->set_have_post_sub_buffer(true); 5336 provider->TestContext3d()->set_have_post_sub_buffer(true);
5342 5337
5343 LayerTreeSettings settings; 5338 LayerTreeSettings settings;
5344 settings.renderer_settings.partial_swap_enabled = partial_swap; 5339 settings.renderer_settings.partial_swap_enabled = partial_swap;
5345 scoped_ptr<LayerTreeHostImpl> my_host_impl = LayerTreeHostImpl::Create( 5340 scoped_ptr<LayerTreeHostImpl> my_host_impl = LayerTreeHostImpl::Create(
5346 settings, client, proxy, stats_instrumentation, manager, NULL, 0); 5341 settings, client, proxy, stats_instrumentation, manager, NULL, NULL, 0);
5347 my_host_impl->InitializeRenderer(output_surface.Pass()); 5342 my_host_impl->InitializeRenderer(output_surface.Pass());
5348 my_host_impl->SetViewportSize(gfx::Size(100, 100)); 5343 my_host_impl->SetViewportSize(gfx::Size(100, 100));
5349 5344
5350 /* 5345 /*
5351 Layers are created as follows: 5346 Layers are created as follows:
5352 5347
5353 +--------------------+ 5348 +--------------------+
5354 | 1 | 5349 | 1 |
5355 | +-----------+ | 5350 | +-----------+ |
5356 | | 2 | | 5351 | | 2 | |
(...skipping 1305 matching lines...) Expand 10 before | Expand all | Expand 10 after
6662 EXPECT_FALSE(did_update_renderer_capabilities_); 6657 EXPECT_FALSE(did_update_renderer_capabilities_);
6663 6658
6664 // Software draw again. 6659 // Software draw again.
6665 DrawFrame(); 6660 DrawFrame();
6666 } 6661 }
6667 6662
6668 // Checks that we have a non-0 default allocation if we pass a context that 6663 // Checks that we have a non-0 default allocation if we pass a context that
6669 // doesn't support memory management extensions. 6664 // doesn't support memory management extensions.
6670 TEST_F(LayerTreeHostImplTest, DefaultMemoryAllocation) { 6665 TEST_F(LayerTreeHostImplTest, DefaultMemoryAllocation) {
6671 LayerTreeSettings settings; 6666 LayerTreeSettings settings;
6672 host_impl_ = LayerTreeHostImpl::Create(settings, 6667 host_impl_ = LayerTreeHostImpl::Create(
6673 this, 6668 settings, this, &proxy_, &stats_instrumentation_,
6674 &proxy_, 6669 shared_bitmap_manager_.get(), gpu_memory_buffer_manager_.get(),
6675 &stats_instrumentation_, 6670 task_graph_runner_.get(), 0);
6676 shared_bitmap_manager_.get(),
6677 gpu_memory_buffer_manager_.get(),
6678 0);
6679 6671
6680 scoped_ptr<OutputSurface> output_surface( 6672 scoped_ptr<OutputSurface> output_surface(
6681 FakeOutputSurface::Create3d(TestWebGraphicsContext3D::Create())); 6673 FakeOutputSurface::Create3d(TestWebGraphicsContext3D::Create()));
6682 host_impl_->InitializeRenderer(output_surface.Pass()); 6674 host_impl_->InitializeRenderer(output_surface.Pass());
6683 EXPECT_LT(0ul, host_impl_->memory_allocation_limit_bytes()); 6675 EXPECT_LT(0ul, host_impl_->memory_allocation_limit_bytes());
6684 } 6676 }
6685 6677
6686 TEST_F(LayerTreeHostImplTest, MemoryPolicy) { 6678 TEST_F(LayerTreeHostImplTest, MemoryPolicy) {
6687 ManagedMemoryPolicy policy1( 6679 ManagedMemoryPolicy policy1(
6688 456, gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING, 1000); 6680 456, gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING, 1000);
(...skipping 20 matching lines...) Expand all
6709 6701
6710 host_impl_->SetVisible(true); 6702 host_impl_->SetVisible(true);
6711 EXPECT_EQ(policy1.bytes_limit_when_visible, current_limit_bytes_); 6703 EXPECT_EQ(policy1.bytes_limit_when_visible, current_limit_bytes_);
6712 EXPECT_EQ(everything_cutoff_value, current_priority_cutoff_value_); 6704 EXPECT_EQ(everything_cutoff_value, current_priority_cutoff_value_);
6713 6705
6714 // Now enable GPU rasterization and test if we get nice to have cutoff, 6706 // Now enable GPU rasterization and test if we get nice to have cutoff,
6715 // when visible. 6707 // when visible.
6716 LayerTreeSettings settings; 6708 LayerTreeSettings settings;
6717 settings.gpu_rasterization_enabled = true; 6709 settings.gpu_rasterization_enabled = true;
6718 host_impl_ = LayerTreeHostImpl::Create( 6710 host_impl_ = LayerTreeHostImpl::Create(
6719 settings, this, &proxy_, &stats_instrumentation_, NULL, NULL, 0); 6711 settings, this, &proxy_, &stats_instrumentation_, NULL, NULL, NULL, 0);
6720 host_impl_->SetUseGpuRasterization(true); 6712 host_impl_->SetUseGpuRasterization(true);
6721 host_impl_->SetVisible(true); 6713 host_impl_->SetVisible(true);
6722 host_impl_->SetMemoryPolicy(policy1); 6714 host_impl_->SetMemoryPolicy(policy1);
6723 EXPECT_EQ(policy1.bytes_limit_when_visible, current_limit_bytes_); 6715 EXPECT_EQ(policy1.bytes_limit_when_visible, current_limit_bytes_);
6724 EXPECT_EQ(allow_nice_to_have_cutoff_value, current_priority_cutoff_value_); 6716 EXPECT_EQ(allow_nice_to_have_cutoff_value, current_priority_cutoff_value_);
6725 6717
6726 host_impl_->SetVisible(false); 6718 host_impl_->SetVisible(false);
6727 EXPECT_EQ(0u, current_limit_bytes_); 6719 EXPECT_EQ(0u, current_limit_bytes_);
6728 EXPECT_EQ(nothing_cutoff_value, current_priority_cutoff_value_); 6720 EXPECT_EQ(nothing_cutoff_value, current_priority_cutoff_value_);
6729 } 6721 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
6772 host_impl_->SetUseGpuRasterization(true); 6764 host_impl_->SetUseGpuRasterization(true);
6773 EXPECT_TRUE(host_impl_->RequiresHighResToDraw()); 6765 EXPECT_TRUE(host_impl_->RequiresHighResToDraw());
6774 } 6766 }
6775 6767
6776 class LayerTreeHostImplTestPrepareTiles : public LayerTreeHostImplTest { 6768 class LayerTreeHostImplTestPrepareTiles : public LayerTreeHostImplTest {
6777 public: 6769 public:
6778 void SetUp() override { 6770 void SetUp() override {
6779 LayerTreeSettings settings; 6771 LayerTreeSettings settings;
6780 settings.impl_side_painting = true; 6772 settings.impl_side_painting = true;
6781 6773
6782 fake_host_impl_ = new FakeLayerTreeHostImpl( 6774 fake_host_impl_ = new FakeLayerTreeHostImpl(settings, &proxy_,
6783 settings, &proxy_, shared_bitmap_manager_.get()); 6775 shared_bitmap_manager_.get(),
6776 task_graph_runner_.get());
6784 host_impl_.reset(fake_host_impl_); 6777 host_impl_.reset(fake_host_impl_);
6785 host_impl_->InitializeRenderer(CreateOutputSurface()); 6778 host_impl_->InitializeRenderer(CreateOutputSurface());
6786 host_impl_->SetViewportSize(gfx::Size(10, 10)); 6779 host_impl_->SetViewportSize(gfx::Size(10, 10));
6787 } 6780 }
6788 6781
6789 FakeLayerTreeHostImpl* fake_host_impl_; 6782 FakeLayerTreeHostImpl* fake_host_impl_;
6790 }; 6783 };
6791 6784
6792 TEST_F(LayerTreeHostImplTestPrepareTiles, PrepareTilesWhenInvisible) { 6785 TEST_F(LayerTreeHostImplTestPrepareTiles, PrepareTilesWhenInvisible) {
6793 fake_host_impl_->DidModifyTilePriorities(); 6786 fake_host_impl_->DidModifyTilePriorities();
(...skipping 1704 matching lines...) Expand 10 before | Expand all | Expand 10 after
8498 // surface. 8491 // surface.
8499 EXPECT_EQ(0, num_lost_surfaces_); 8492 EXPECT_EQ(0, num_lost_surfaces_);
8500 host_impl_->DidLoseOutputSurface(); 8493 host_impl_->DidLoseOutputSurface();
8501 EXPECT_EQ(1, num_lost_surfaces_); 8494 EXPECT_EQ(1, num_lost_surfaces_);
8502 host_impl_->DidLoseOutputSurface(); 8495 host_impl_->DidLoseOutputSurface();
8503 EXPECT_LE(1, num_lost_surfaces_); 8496 EXPECT_LE(1, num_lost_surfaces_);
8504 } 8497 }
8505 8498
8506 } // namespace 8499 } // namespace
8507 } // namespace cc 8500 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698