OLD | NEW |
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 <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 #include "cc/test/fake_output_surface.h" | 44 #include "cc/test/fake_output_surface.h" |
45 #include "cc/test/fake_output_surface_client.h" | 45 #include "cc/test/fake_output_surface_client.h" |
46 #include "cc/test/fake_picture_layer_impl.h" | 46 #include "cc/test/fake_picture_layer_impl.h" |
47 #include "cc/test/fake_picture_pile_impl.h" | 47 #include "cc/test/fake_picture_pile_impl.h" |
48 #include "cc/test/fake_proxy.h" | 48 #include "cc/test/fake_proxy.h" |
49 #include "cc/test/fake_rendering_stats_instrumentation.h" | 49 #include "cc/test/fake_rendering_stats_instrumentation.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/render_pass_test_common.h" | 53 #include "cc/test/render_pass_test_common.h" |
| 54 #include "cc/test/test_gpu_memory_buffer_manager.h" |
54 #include "cc/test/test_shared_bitmap_manager.h" | 55 #include "cc/test/test_shared_bitmap_manager.h" |
55 #include "cc/test/test_web_graphics_context_3d.h" | 56 #include "cc/test/test_web_graphics_context_3d.h" |
56 #include "cc/trees/layer_tree_impl.h" | 57 #include "cc/trees/layer_tree_impl.h" |
57 #include "cc/trees/single_thread_proxy.h" | 58 #include "cc/trees/single_thread_proxy.h" |
58 #include "media/base/media.h" | 59 #include "media/base/media.h" |
59 #include "testing/gmock/include/gmock/gmock.h" | 60 #include "testing/gmock/include/gmock/gmock.h" |
60 #include "testing/gtest/include/gtest/gtest.h" | 61 #include "testing/gtest/include/gtest/gtest.h" |
61 #include "third_party/skia/include/core/SkMallocPixelRef.h" | 62 #include "third_party/skia/include/core/SkMallocPixelRef.h" |
62 #include "ui/gfx/frame_time.h" | 63 #include "ui/gfx/frame_time.h" |
63 #include "ui/gfx/rect_conversions.h" | 64 #include "ui/gfx/rect_conversions.h" |
(...skipping 11 matching lines...) Expand all Loading... |
75 namespace { | 76 namespace { |
76 | 77 |
77 class LayerTreeHostImplTest : public testing::Test, | 78 class LayerTreeHostImplTest : public testing::Test, |
78 public LayerTreeHostImplClient { | 79 public LayerTreeHostImplClient { |
79 public: | 80 public: |
80 LayerTreeHostImplTest() | 81 LayerTreeHostImplTest() |
81 : proxy_(base::MessageLoopProxy::current(), | 82 : proxy_(base::MessageLoopProxy::current(), |
82 base::MessageLoopProxy::current()), | 83 base::MessageLoopProxy::current()), |
83 always_impl_thread_(&proxy_), | 84 always_impl_thread_(&proxy_), |
84 always_main_thread_blocked_(&proxy_), | 85 always_main_thread_blocked_(&proxy_), |
85 shared_bitmap_manager_(new TestSharedBitmapManager()), | 86 shared_bitmap_manager_(new TestSharedBitmapManager), |
| 87 gpu_memory_buffer_manager_(new TestGpuMemoryBufferManager), |
86 on_can_draw_state_changed_called_(false), | 88 on_can_draw_state_changed_called_(false), |
87 did_notify_ready_to_activate_(false), | 89 did_notify_ready_to_activate_(false), |
88 did_request_commit_(false), | 90 did_request_commit_(false), |
89 did_request_redraw_(false), | 91 did_request_redraw_(false), |
90 did_request_animate_(false), | 92 did_request_animate_(false), |
91 did_request_manage_tiles_(false), | 93 did_request_manage_tiles_(false), |
92 did_upload_visible_tile_(false), | 94 did_upload_visible_tile_(false), |
93 reduce_memory_result_(true), | 95 reduce_memory_result_(true), |
94 current_limit_bytes_(0), | 96 current_limit_bytes_(0), |
95 current_priority_cutoff_value_(0) { | 97 current_priority_cutoff_value_(0) { |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 reduce_memory_result_ = reduce_memory_result; | 170 reduce_memory_result_ = reduce_memory_result; |
169 } | 171 } |
170 | 172 |
171 bool CreateHostImpl(const LayerTreeSettings& settings, | 173 bool CreateHostImpl(const LayerTreeSettings& settings, |
172 scoped_ptr<OutputSurface> output_surface) { | 174 scoped_ptr<OutputSurface> output_surface) { |
173 host_impl_ = LayerTreeHostImpl::Create(settings, | 175 host_impl_ = LayerTreeHostImpl::Create(settings, |
174 this, | 176 this, |
175 &proxy_, | 177 &proxy_, |
176 &stats_instrumentation_, | 178 &stats_instrumentation_, |
177 shared_bitmap_manager_.get(), | 179 shared_bitmap_manager_.get(), |
| 180 gpu_memory_buffer_manager_.get(), |
178 0); | 181 0); |
179 bool init = host_impl_->InitializeRenderer(output_surface.Pass()); | 182 bool init = host_impl_->InitializeRenderer(output_surface.Pass()); |
180 host_impl_->SetViewportSize(gfx::Size(10, 10)); | 183 host_impl_->SetViewportSize(gfx::Size(10, 10)); |
181 return init; | 184 return init; |
182 } | 185 } |
183 | 186 |
184 void SetupRootLayerImpl(scoped_ptr<LayerImpl> root) { | 187 void SetupRootLayerImpl(scoped_ptr<LayerImpl> root) { |
185 root->SetPosition(gfx::PointF()); | 188 root->SetPosition(gfx::PointF()); |
186 root->SetBounds(gfx::Size(10, 10)); | 189 root->SetBounds(gfx::Size(10, 10)); |
187 root->SetContentBounds(gfx::Size(10, 10)); | 190 root->SetContentBounds(gfx::Size(10, 10)); |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 void DrawOneFrame() { | 388 void DrawOneFrame() { |
386 LayerTreeHostImpl::FrameData frame_data; | 389 LayerTreeHostImpl::FrameData frame_data; |
387 host_impl_->PrepareToDraw(&frame_data); | 390 host_impl_->PrepareToDraw(&frame_data); |
388 host_impl_->DidDrawAllLayers(frame_data); | 391 host_impl_->DidDrawAllLayers(frame_data); |
389 } | 392 } |
390 | 393 |
391 FakeProxy proxy_; | 394 FakeProxy proxy_; |
392 DebugScopedSetImplThread always_impl_thread_; | 395 DebugScopedSetImplThread always_impl_thread_; |
393 DebugScopedSetMainThreadBlocked always_main_thread_blocked_; | 396 DebugScopedSetMainThreadBlocked always_main_thread_blocked_; |
394 | 397 |
395 scoped_ptr<SharedBitmapManager> shared_bitmap_manager_; | 398 scoped_ptr<TestSharedBitmapManager> shared_bitmap_manager_; |
| 399 scoped_ptr<TestGpuMemoryBufferManager> gpu_memory_buffer_manager_; |
396 scoped_ptr<LayerTreeHostImpl> host_impl_; | 400 scoped_ptr<LayerTreeHostImpl> host_impl_; |
397 FakeRenderingStatsInstrumentation stats_instrumentation_; | 401 FakeRenderingStatsInstrumentation stats_instrumentation_; |
398 bool on_can_draw_state_changed_called_; | 402 bool on_can_draw_state_changed_called_; |
399 bool did_notify_ready_to_activate_; | 403 bool did_notify_ready_to_activate_; |
400 bool did_request_commit_; | 404 bool did_request_commit_; |
401 bool did_request_redraw_; | 405 bool did_request_redraw_; |
402 bool did_request_animate_; | 406 bool did_request_animate_; |
403 bool did_request_manage_tiles_; | 407 bool did_request_manage_tiles_; |
404 bool did_upload_visible_tile_; | 408 bool did_upload_visible_tile_; |
405 bool reduce_memory_result_; | 409 bool reduce_memory_result_; |
(...skipping 953 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1359 const LayerTreeSettings& settings, | 1363 const LayerTreeSettings& settings, |
1360 LayerTreeHostImplClient* client, | 1364 LayerTreeHostImplClient* client, |
1361 Proxy* proxy, | 1365 Proxy* proxy, |
1362 SharedBitmapManager* manager, | 1366 SharedBitmapManager* manager, |
1363 RenderingStatsInstrumentation* rendering_stats_instrumentation) | 1367 RenderingStatsInstrumentation* rendering_stats_instrumentation) |
1364 : LayerTreeHostImpl(settings, | 1368 : LayerTreeHostImpl(settings, |
1365 client, | 1369 client, |
1366 proxy, | 1370 proxy, |
1367 rendering_stats_instrumentation, | 1371 rendering_stats_instrumentation, |
1368 manager, | 1372 manager, |
| 1373 NULL, |
1369 0) {} | 1374 0) {} |
1370 | 1375 |
1371 virtual BeginFrameArgs CurrentBeginFrameArgs() const override { | 1376 virtual BeginFrameArgs CurrentBeginFrameArgs() const override { |
1372 return CreateBeginFrameArgsForTesting(fake_current_physical_time_); | 1377 return CreateBeginFrameArgsForTesting(fake_current_physical_time_); |
1373 } | 1378 } |
1374 | 1379 |
1375 void SetCurrentPhysicalTimeTicksForTest(base::TimeTicks fake_now) { | 1380 void SetCurrentPhysicalTimeTicksForTest(base::TimeTicks fake_now) { |
1376 fake_current_physical_time_ = fake_now; | 1381 fake_current_physical_time_ = fake_now; |
1377 } | 1382 } |
1378 | 1383 |
(...skipping 3029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4408 LayerTreeSettings settings; | 4413 LayerTreeSettings settings; |
4409 settings.partial_swap_enabled = true; | 4414 settings.partial_swap_enabled = true; |
4410 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( | 4415 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( |
4411 new TestSharedBitmapManager()); | 4416 new TestSharedBitmapManager()); |
4412 scoped_ptr<LayerTreeHostImpl> layer_tree_host_impl = | 4417 scoped_ptr<LayerTreeHostImpl> layer_tree_host_impl = |
4413 LayerTreeHostImpl::Create(settings, | 4418 LayerTreeHostImpl::Create(settings, |
4414 this, | 4419 this, |
4415 &proxy_, | 4420 &proxy_, |
4416 &stats_instrumentation_, | 4421 &stats_instrumentation_, |
4417 shared_bitmap_manager.get(), | 4422 shared_bitmap_manager.get(), |
| 4423 NULL, |
4418 0); | 4424 0); |
4419 layer_tree_host_impl->InitializeRenderer(output_surface.Pass()); | 4425 layer_tree_host_impl->InitializeRenderer(output_surface.Pass()); |
4420 layer_tree_host_impl->SetViewportSize(gfx::Size(500, 500)); | 4426 layer_tree_host_impl->SetViewportSize(gfx::Size(500, 500)); |
4421 | 4427 |
4422 scoped_ptr<LayerImpl> root = | 4428 scoped_ptr<LayerImpl> root = |
4423 FakeDrawableLayerImpl::Create(layer_tree_host_impl->active_tree(), 1); | 4429 FakeDrawableLayerImpl::Create(layer_tree_host_impl->active_tree(), 1); |
4424 scoped_ptr<LayerImpl> child = | 4430 scoped_ptr<LayerImpl> child = |
4425 FakeDrawableLayerImpl::Create(layer_tree_host_impl->active_tree(), 2); | 4431 FakeDrawableLayerImpl::Create(layer_tree_host_impl->active_tree(), 2); |
4426 child->SetPosition(gfx::PointF(12.f, 13.f)); | 4432 child->SetPosition(gfx::PointF(12.f, 13.f)); |
4427 child->SetBounds(gfx::Size(14, 15)); | 4433 child->SetBounds(gfx::Size(14, 15)); |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4696 RenderingStatsInstrumentation* stats_instrumentation) { | 4702 RenderingStatsInstrumentation* stats_instrumentation) { |
4697 scoped_refptr<TestContextProvider> provider(TestContextProvider::Create()); | 4703 scoped_refptr<TestContextProvider> provider(TestContextProvider::Create()); |
4698 scoped_ptr<OutputSurface> output_surface( | 4704 scoped_ptr<OutputSurface> output_surface( |
4699 FakeOutputSurface::Create3d(provider)); | 4705 FakeOutputSurface::Create3d(provider)); |
4700 provider->BindToCurrentThread(); | 4706 provider->BindToCurrentThread(); |
4701 provider->TestContext3d()->set_have_post_sub_buffer(true); | 4707 provider->TestContext3d()->set_have_post_sub_buffer(true); |
4702 | 4708 |
4703 LayerTreeSettings settings; | 4709 LayerTreeSettings settings; |
4704 settings.partial_swap_enabled = partial_swap; | 4710 settings.partial_swap_enabled = partial_swap; |
4705 scoped_ptr<LayerTreeHostImpl> my_host_impl = LayerTreeHostImpl::Create( | 4711 scoped_ptr<LayerTreeHostImpl> my_host_impl = LayerTreeHostImpl::Create( |
4706 settings, client, proxy, stats_instrumentation, manager, 0); | 4712 settings, client, proxy, stats_instrumentation, manager, NULL, 0); |
4707 my_host_impl->InitializeRenderer(output_surface.Pass()); | 4713 my_host_impl->InitializeRenderer(output_surface.Pass()); |
4708 my_host_impl->SetViewportSize(gfx::Size(100, 100)); | 4714 my_host_impl->SetViewportSize(gfx::Size(100, 100)); |
4709 | 4715 |
4710 /* | 4716 /* |
4711 Layers are created as follows: | 4717 Layers are created as follows: |
4712 | 4718 |
4713 +--------------------+ | 4719 +--------------------+ |
4714 | 1 | | 4720 | 1 | |
4715 | +-----------+ | | 4721 | +-----------+ | |
4716 | | 2 | | | 4722 | | 2 | | |
(...skipping 1263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5980 | 5986 |
5981 // Checks that we have a non-0 default allocation if we pass a context that | 5987 // Checks that we have a non-0 default allocation if we pass a context that |
5982 // doesn't support memory management extensions. | 5988 // doesn't support memory management extensions. |
5983 TEST_F(LayerTreeHostImplTest, DefaultMemoryAllocation) { | 5989 TEST_F(LayerTreeHostImplTest, DefaultMemoryAllocation) { |
5984 LayerTreeSettings settings; | 5990 LayerTreeSettings settings; |
5985 host_impl_ = LayerTreeHostImpl::Create(settings, | 5991 host_impl_ = LayerTreeHostImpl::Create(settings, |
5986 this, | 5992 this, |
5987 &proxy_, | 5993 &proxy_, |
5988 &stats_instrumentation_, | 5994 &stats_instrumentation_, |
5989 shared_bitmap_manager_.get(), | 5995 shared_bitmap_manager_.get(), |
| 5996 gpu_memory_buffer_manager_.get(), |
5990 0); | 5997 0); |
5991 | 5998 |
5992 scoped_ptr<OutputSurface> output_surface( | 5999 scoped_ptr<OutputSurface> output_surface( |
5993 FakeOutputSurface::Create3d(TestWebGraphicsContext3D::Create())); | 6000 FakeOutputSurface::Create3d(TestWebGraphicsContext3D::Create())); |
5994 host_impl_->InitializeRenderer(output_surface.Pass()); | 6001 host_impl_->InitializeRenderer(output_surface.Pass()); |
5995 EXPECT_LT(0ul, host_impl_->memory_allocation_limit_bytes()); | 6002 EXPECT_LT(0ul, host_impl_->memory_allocation_limit_bytes()); |
5996 } | 6003 } |
5997 | 6004 |
5998 TEST_F(LayerTreeHostImplTest, MemoryPolicy) { | 6005 TEST_F(LayerTreeHostImplTest, MemoryPolicy) { |
5999 ManagedMemoryPolicy policy1( | 6006 ManagedMemoryPolicy policy1( |
(...skipping 21 matching lines...) Expand all Loading... |
6021 | 6028 |
6022 host_impl_->SetVisible(true); | 6029 host_impl_->SetVisible(true); |
6023 EXPECT_EQ(policy1.bytes_limit_when_visible, current_limit_bytes_); | 6030 EXPECT_EQ(policy1.bytes_limit_when_visible, current_limit_bytes_); |
6024 EXPECT_EQ(everything_cutoff_value, current_priority_cutoff_value_); | 6031 EXPECT_EQ(everything_cutoff_value, current_priority_cutoff_value_); |
6025 | 6032 |
6026 // Now enable GPU rasterization and test if we get nice to have cutoff, | 6033 // Now enable GPU rasterization and test if we get nice to have cutoff, |
6027 // when visible. | 6034 // when visible. |
6028 LayerTreeSettings settings; | 6035 LayerTreeSettings settings; |
6029 settings.gpu_rasterization_enabled = true; | 6036 settings.gpu_rasterization_enabled = true; |
6030 host_impl_ = LayerTreeHostImpl::Create( | 6037 host_impl_ = LayerTreeHostImpl::Create( |
6031 settings, this, &proxy_, &stats_instrumentation_, NULL, 0); | 6038 settings, this, &proxy_, &stats_instrumentation_, NULL, NULL, 0); |
6032 host_impl_->SetUseGpuRasterization(true); | 6039 host_impl_->SetUseGpuRasterization(true); |
6033 host_impl_->SetVisible(true); | 6040 host_impl_->SetVisible(true); |
6034 host_impl_->SetMemoryPolicy(policy1); | 6041 host_impl_->SetMemoryPolicy(policy1); |
6035 EXPECT_EQ(policy1.bytes_limit_when_visible, current_limit_bytes_); | 6042 EXPECT_EQ(policy1.bytes_limit_when_visible, current_limit_bytes_); |
6036 EXPECT_EQ(allow_nice_to_have_cutoff_value, current_priority_cutoff_value_); | 6043 EXPECT_EQ(allow_nice_to_have_cutoff_value, current_priority_cutoff_value_); |
6037 | 6044 |
6038 host_impl_->SetVisible(false); | 6045 host_impl_->SetVisible(false); |
6039 EXPECT_EQ(0u, current_limit_bytes_); | 6046 EXPECT_EQ(0u, current_limit_bytes_); |
6040 EXPECT_EQ(nothing_cutoff_value, current_priority_cutoff_value_); | 6047 EXPECT_EQ(nothing_cutoff_value, current_priority_cutoff_value_); |
6041 } | 6048 } |
(...skipping 1229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7271 // surface. | 7278 // surface. |
7272 EXPECT_EQ(0, num_lost_surfaces_); | 7279 EXPECT_EQ(0, num_lost_surfaces_); |
7273 host_impl_->DidLoseOutputSurface(); | 7280 host_impl_->DidLoseOutputSurface(); |
7274 EXPECT_EQ(1, num_lost_surfaces_); | 7281 EXPECT_EQ(1, num_lost_surfaces_); |
7275 host_impl_->DidLoseOutputSurface(); | 7282 host_impl_->DidLoseOutputSurface(); |
7276 EXPECT_LE(1, num_lost_surfaces_); | 7283 EXPECT_LE(1, num_lost_surfaces_); |
7277 } | 7284 } |
7278 | 7285 |
7279 } // namespace | 7286 } // namespace |
7280 } // namespace cc | 7287 } // namespace cc |
OLD | NEW |