| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/layers/picture_layer.h" | 5 #include "cc/layers/picture_layer.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
| 11 #include "cc/animation/animation_host.h" | 11 #include "cc/animation/animation_host.h" |
| 12 #include "cc/layers/append_quads_data.h" | 12 #include "cc/layers/append_quads_data.h" |
| 13 #include "cc/layers/content_layer_client.h" | 13 #include "cc/layers/content_layer_client.h" |
| 14 #include "cc/layers/empty_content_layer_client.h" | 14 #include "cc/layers/empty_content_layer_client.h" |
| 15 #include "cc/layers/picture_layer_impl.h" | 15 #include "cc/layers/picture_layer_impl.h" |
| 16 #include "cc/playback/display_item_list_settings.h" | 16 #include "cc/playback/display_item_list_settings.h" |
| 17 #include "cc/proto/layer.pb.h" | 17 #include "cc/proto/layer.pb.h" |
| 18 #include "cc/test/fake_client_picture_cache.h" | 18 #include "cc/test/fake_client_picture_cache.h" |
| 19 #include "cc/test/fake_compositor_frame_sink.h" | 19 #include "cc/test/fake_compositor_frame_sink.h" |
| 20 #include "cc/test/fake_engine_picture_cache.h" | 20 #include "cc/test/fake_engine_picture_cache.h" |
| 21 #include "cc/test/fake_image_serialization_processor.h" | 21 #include "cc/test/fake_image_serialization_processor.h" |
| 22 #include "cc/test/fake_layer_tree_host.h" | 22 #include "cc/test/fake_layer_tree_host.h" |
| 23 #include "cc/test/fake_picture_layer.h" | 23 #include "cc/test/fake_picture_layer.h" |
| 24 #include "cc/test/fake_picture_layer_impl.h" | 24 #include "cc/test/fake_picture_layer_impl.h" |
| 25 #include "cc/test/fake_proxy.h" | 25 #include "cc/test/fake_proxy.h" |
| 26 #include "cc/test/fake_recording_source.h" | 26 #include "cc/test/fake_recording_source.h" |
| 27 #include "cc/test/layer_tree_settings_for_testing.h" | 27 #include "cc/test/layer_tree_settings_for_testing.h" |
| 28 #include "cc/test/skia_common.h" | 28 #include "cc/test/skia_common.h" |
| 29 #include "cc/test/stub_layer_tree_host_single_thread_client.h" | 29 #include "cc/test/stub_layer_tree_host_single_thread_client.h" |
| 30 #include "cc/test/test_shared_bitmap_manager.h" | |
| 31 #include "cc/test/test_task_graph_runner.h" | 30 #include "cc/test/test_task_graph_runner.h" |
| 32 #include "cc/trees/single_thread_proxy.h" | 31 #include "cc/trees/single_thread_proxy.h" |
| 33 #include "testing/gmock/include/gmock/gmock.h" | 32 #include "testing/gmock/include/gmock/gmock.h" |
| 34 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
| 35 #include "third_party/skia/include/core/SkRefCnt.h" | 34 #include "third_party/skia/include/core/SkRefCnt.h" |
| 36 | 35 |
| 37 namespace cc { | 36 namespace cc { |
| 38 | 37 |
| 39 class TestSerializationPictureLayer : public PictureLayer { | 38 class TestSerializationPictureLayer : public PictureLayer { |
| 40 public: | 39 public: |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 host->CommitComplete(); | 244 host->CommitComplete(); |
| 246 EXPECT_EQ(1, host->SourceFrameNumber()); | 245 EXPECT_EQ(1, host->SourceFrameNumber()); |
| 247 | 246 |
| 248 layer->SetBounds(gfx::Size(0, 0)); | 247 layer->SetBounds(gfx::Size(0, 0)); |
| 249 layer->SavePaintProperties(); | 248 layer->SavePaintProperties(); |
| 250 // Intentionally skipping Update since it would normally be skipped on | 249 // Intentionally skipping Update since it would normally be skipped on |
| 251 // a layer with empty bounds. | 250 // a layer with empty bounds. |
| 252 | 251 |
| 253 FakeImplTaskRunnerProvider impl_task_runner_provider; | 252 FakeImplTaskRunnerProvider impl_task_runner_provider; |
| 254 | 253 |
| 255 TestSharedBitmapManager shared_bitmap_manager; | |
| 256 std::unique_ptr<FakeCompositorFrameSink> compositor_frame_sink = | 254 std::unique_ptr<FakeCompositorFrameSink> compositor_frame_sink = |
| 257 FakeCompositorFrameSink::CreateSoftware(); | 255 FakeCompositorFrameSink::CreateSoftware(); |
| 258 FakeLayerTreeHostImpl host_impl(LayerTreeSettings(), | 256 FakeLayerTreeHostImpl host_impl( |
| 259 &impl_task_runner_provider, | 257 LayerTreeSettings(), &impl_task_runner_provider, &task_graph_runner); |
| 260 &shared_bitmap_manager, &task_graph_runner); | |
| 261 host_impl.InitializeRenderer(compositor_frame_sink.get()); | 258 host_impl.InitializeRenderer(compositor_frame_sink.get()); |
| 262 host_impl.CreatePendingTree(); | 259 host_impl.CreatePendingTree(); |
| 263 std::unique_ptr<FakePictureLayerImpl> layer_impl = | 260 std::unique_ptr<FakePictureLayerImpl> layer_impl = |
| 264 FakePictureLayerImpl::Create(host_impl.pending_tree(), 1); | 261 FakePictureLayerImpl::Create(host_impl.pending_tree(), 1); |
| 265 | 262 |
| 266 layer->PushPropertiesTo(layer_impl.get()); | 263 layer->PushPropertiesTo(layer_impl.get()); |
| 267 EXPECT_FALSE(layer_impl->CanHaveTilings()); | 264 EXPECT_FALSE(layer_impl->CanHaveTilings()); |
| 268 EXPECT_TRUE(layer_impl->bounds() == gfx::Size(0, 0)); | 265 EXPECT_TRUE(layer_impl->bounds() == gfx::Size(0, 0)); |
| 269 EXPECT_EQ(gfx::Size(), layer_impl->raster_source()->GetSize()); | 266 EXPECT_EQ(gfx::Size(), layer_impl->raster_source()->GetSize()); |
| 270 EXPECT_FALSE(layer_impl->raster_source()->HasRecordings()); | 267 EXPECT_FALSE(layer_impl->raster_source()->HasRecordings()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 286 layer->SavePaintProperties(); | 283 layer->SavePaintProperties(); |
| 287 | 284 |
| 288 gfx::Rect invalidation_bounds(layer_size); | 285 gfx::Rect invalidation_bounds(layer_size); |
| 289 | 286 |
| 290 // The important two lines are the following: | 287 // The important two lines are the following: |
| 291 layer->SetNeedsDisplayRect(invalidation_bounds); | 288 layer->SetNeedsDisplayRect(invalidation_bounds); |
| 292 layer->Update(); | 289 layer->Update(); |
| 293 | 290 |
| 294 host->CommitComplete(); | 291 host->CommitComplete(); |
| 295 FakeImplTaskRunnerProvider impl_task_runner_provider; | 292 FakeImplTaskRunnerProvider impl_task_runner_provider; |
| 296 TestSharedBitmapManager shared_bitmap_manager; | |
| 297 std::unique_ptr<CompositorFrameSink> compositor_frame_sink( | 293 std::unique_ptr<CompositorFrameSink> compositor_frame_sink( |
| 298 FakeCompositorFrameSink::Create3d()); | 294 FakeCompositorFrameSink::Create3d()); |
| 299 LayerTreeSettings layer_tree_settings = LayerTreeSettingsForTesting(); | 295 LayerTreeSettings layer_tree_settings = LayerTreeSettingsForTesting(); |
| 300 layer_tree_settings.image_decode_tasks_enabled = true; | 296 layer_tree_settings.image_decode_tasks_enabled = true; |
| 301 FakeLayerTreeHostImpl host_impl(layer_tree_settings, | 297 FakeLayerTreeHostImpl host_impl( |
| 302 &impl_task_runner_provider, | 298 layer_tree_settings, &impl_task_runner_provider, &task_graph_runner); |
| 303 &shared_bitmap_manager, &task_graph_runner); | |
| 304 host_impl.SetVisible(true); | 299 host_impl.SetVisible(true); |
| 305 host_impl.InitializeRenderer(compositor_frame_sink.get()); | 300 host_impl.InitializeRenderer(compositor_frame_sink.get()); |
| 306 host_impl.CreatePendingTree(); | 301 host_impl.CreatePendingTree(); |
| 307 host_impl.pending_tree()->SetRootLayerForTesting( | 302 host_impl.pending_tree()->SetRootLayerForTesting( |
| 308 FakePictureLayerImpl::Create(host_impl.pending_tree(), 1)); | 303 FakePictureLayerImpl::Create(host_impl.pending_tree(), 1)); |
| 309 host_impl.pending_tree()->BuildLayerListForTesting(); | 304 host_impl.pending_tree()->BuildLayerListForTesting(); |
| 310 FakePictureLayerImpl* layer_impl = static_cast<FakePictureLayerImpl*>( | 305 FakePictureLayerImpl* layer_impl = static_cast<FakePictureLayerImpl*>( |
| 311 host_impl.pending_tree()->root_layer_for_testing()); | 306 host_impl.pending_tree()->root_layer_for_testing()); |
| 312 layer->PushPropertiesTo(layer_impl); | 307 layer->PushPropertiesTo(layer_impl); |
| 313 | 308 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 330 layer->SetIsDrawable(true); | 325 layer->SetIsDrawable(true); |
| 331 layer->SavePaintProperties(); | 326 layer->SavePaintProperties(); |
| 332 | 327 |
| 333 gfx::Rect invalidation_bounds(layer_size); | 328 gfx::Rect invalidation_bounds(layer_size); |
| 334 | 329 |
| 335 // The important line is the following (note that we do not call Update): | 330 // The important line is the following (note that we do not call Update): |
| 336 layer->SetNeedsDisplayRect(invalidation_bounds); | 331 layer->SetNeedsDisplayRect(invalidation_bounds); |
| 337 | 332 |
| 338 host->CommitComplete(); | 333 host->CommitComplete(); |
| 339 FakeImplTaskRunnerProvider impl_task_runner_provider; | 334 FakeImplTaskRunnerProvider impl_task_runner_provider; |
| 340 TestSharedBitmapManager shared_bitmap_manager; | |
| 341 std::unique_ptr<CompositorFrameSink> compositor_frame_sink( | 335 std::unique_ptr<CompositorFrameSink> compositor_frame_sink( |
| 342 FakeCompositorFrameSink::Create3d()); | 336 FakeCompositorFrameSink::Create3d()); |
| 343 LayerTreeSettings layer_tree_settings = LayerTreeSettingsForTesting(); | 337 LayerTreeSettings layer_tree_settings = LayerTreeSettingsForTesting(); |
| 344 layer_tree_settings.image_decode_tasks_enabled = true; | 338 layer_tree_settings.image_decode_tasks_enabled = true; |
| 345 FakeLayerTreeHostImpl host_impl(layer_tree_settings, | 339 FakeLayerTreeHostImpl host_impl( |
| 346 &impl_task_runner_provider, | 340 layer_tree_settings, &impl_task_runner_provider, &task_graph_runner); |
| 347 &shared_bitmap_manager, &task_graph_runner); | |
| 348 host_impl.SetVisible(true); | 341 host_impl.SetVisible(true); |
| 349 host_impl.InitializeRenderer(compositor_frame_sink.get()); | 342 host_impl.InitializeRenderer(compositor_frame_sink.get()); |
| 350 host_impl.CreatePendingTree(); | 343 host_impl.CreatePendingTree(); |
| 351 host_impl.pending_tree()->SetRootLayerForTesting( | 344 host_impl.pending_tree()->SetRootLayerForTesting( |
| 352 FakePictureLayerImpl::Create(host_impl.pending_tree(), 1)); | 345 FakePictureLayerImpl::Create(host_impl.pending_tree(), 1)); |
| 353 host_impl.pending_tree()->BuildLayerListForTesting(); | 346 host_impl.pending_tree()->BuildLayerListForTesting(); |
| 354 FakePictureLayerImpl* layer_impl = static_cast<FakePictureLayerImpl*>( | 347 FakePictureLayerImpl* layer_impl = static_cast<FakePictureLayerImpl*>( |
| 355 host_impl.pending_tree()->root_layer_for_testing()); | 348 host_impl.pending_tree()->root_layer_for_testing()); |
| 356 layer->PushPropertiesTo(layer_impl); | 349 layer->PushPropertiesTo(layer_impl); |
| 357 | 350 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 378 | 371 |
| 379 EXPECT_EQ(0, host->SourceFrameNumber()); | 372 EXPECT_EQ(0, host->SourceFrameNumber()); |
| 380 host->CommitComplete(); | 373 host->CommitComplete(); |
| 381 EXPECT_EQ(1, host->SourceFrameNumber()); | 374 EXPECT_EQ(1, host->SourceFrameNumber()); |
| 382 | 375 |
| 383 layer->SavePaintProperties(); | 376 layer->SavePaintProperties(); |
| 384 layer->Update(); | 377 layer->Update(); |
| 385 | 378 |
| 386 FakeImplTaskRunnerProvider impl_task_runner_provider; | 379 FakeImplTaskRunnerProvider impl_task_runner_provider; |
| 387 | 380 |
| 388 TestSharedBitmapManager shared_bitmap_manager; | |
| 389 std::unique_ptr<CompositorFrameSink> compositor_frame_sink( | 381 std::unique_ptr<CompositorFrameSink> compositor_frame_sink( |
| 390 FakeCompositorFrameSink::Create3d()); | 382 FakeCompositorFrameSink::Create3d()); |
| 391 LayerTreeSettings layer_tree_settings = LayerTreeSettingsForTesting(); | 383 LayerTreeSettings layer_tree_settings = LayerTreeSettingsForTesting(); |
| 392 layer_tree_settings.image_decode_tasks_enabled = true; | 384 layer_tree_settings.image_decode_tasks_enabled = true; |
| 393 FakeLayerTreeHostImpl host_impl(layer_tree_settings, | 385 FakeLayerTreeHostImpl host_impl( |
| 394 &impl_task_runner_provider, | 386 layer_tree_settings, &impl_task_runner_provider, &task_graph_runner); |
| 395 &shared_bitmap_manager, &task_graph_runner); | |
| 396 host_impl.SetVisible(true); | 387 host_impl.SetVisible(true); |
| 397 EXPECT_TRUE(host_impl.InitializeRenderer(compositor_frame_sink.get())); | 388 EXPECT_TRUE(host_impl.InitializeRenderer(compositor_frame_sink.get())); |
| 398 | 389 |
| 399 host_impl.CreatePendingTree(); | 390 host_impl.CreatePendingTree(); |
| 400 host_impl.pending_tree()->SetRootLayerForTesting( | 391 host_impl.pending_tree()->SetRootLayerForTesting( |
| 401 FakePictureLayerImpl::Create(host_impl.pending_tree(), 1)); | 392 FakePictureLayerImpl::Create(host_impl.pending_tree(), 1)); |
| 402 host_impl.pending_tree()->BuildLayerListForTesting(); | 393 host_impl.pending_tree()->BuildLayerListForTesting(); |
| 403 | 394 |
| 404 FakePictureLayerImpl* layer_impl = static_cast<FakePictureLayerImpl*>( | 395 FakePictureLayerImpl* layer_impl = static_cast<FakePictureLayerImpl*>( |
| 405 host_impl.pending_tree()->root_layer_for_testing()); | 396 host_impl.pending_tree()->root_layer_for_testing()); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 // non-monotonically. This executes that code path under this scenario allowing | 475 // non-monotonically. This executes that code path under this scenario allowing |
| 485 // for the code to verify correctness with DCHECKs. | 476 // for the code to verify correctness with DCHECKs. |
| 486 TEST(PictureLayerTest, NonMonotonicSourceFrameNumber) { | 477 TEST(PictureLayerTest, NonMonotonicSourceFrameNumber) { |
| 487 LayerTreeSettings settings = LayerTreeSettingsForTesting(); | 478 LayerTreeSettings settings = LayerTreeSettingsForTesting(); |
| 488 settings.single_thread_proxy_scheduler = false; | 479 settings.single_thread_proxy_scheduler = false; |
| 489 settings.use_zero_copy = true; | 480 settings.use_zero_copy = true; |
| 490 | 481 |
| 491 StubLayerTreeHostSingleThreadClient single_thread_client; | 482 StubLayerTreeHostSingleThreadClient single_thread_client; |
| 492 FakeLayerTreeHostClient host_client1; | 483 FakeLayerTreeHostClient host_client1; |
| 493 FakeLayerTreeHostClient host_client2; | 484 FakeLayerTreeHostClient host_client2; |
| 494 TestSharedBitmapManager shared_bitmap_manager; | |
| 495 TestTaskGraphRunner task_graph_runner; | 485 TestTaskGraphRunner task_graph_runner; |
| 496 | 486 |
| 497 ContentLayerClient* client = EmptyContentLayerClient::GetInstance(); | 487 ContentLayerClient* client = EmptyContentLayerClient::GetInstance(); |
| 498 scoped_refptr<FakePictureLayer> layer = FakePictureLayer::Create(client); | 488 scoped_refptr<FakePictureLayer> layer = FakePictureLayer::Create(client); |
| 499 | 489 |
| 500 LayerTreeHostInProcess::InitParams params; | 490 LayerTreeHostInProcess::InitParams params; |
| 501 params.client = &host_client1; | 491 params.client = &host_client1; |
| 502 params.shared_bitmap_manager = &shared_bitmap_manager; | |
| 503 params.settings = &settings; | 492 params.settings = &settings; |
| 504 params.task_graph_runner = &task_graph_runner; | 493 params.task_graph_runner = &task_graph_runner; |
| 505 params.main_task_runner = base::ThreadTaskRunnerHandle::Get(); | 494 params.main_task_runner = base::ThreadTaskRunnerHandle::Get(); |
| 506 params.animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN); | 495 params.animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN); |
| 507 std::unique_ptr<LayerTreeHost> host1 = | 496 std::unique_ptr<LayerTreeHost> host1 = |
| 508 LayerTreeHostInProcess::CreateSingleThreaded(&single_thread_client, | 497 LayerTreeHostInProcess::CreateSingleThreaded(&single_thread_client, |
| 509 ¶ms); | 498 ¶ms); |
| 510 host1->SetVisible(true); | 499 host1->SetVisible(true); |
| 511 host_client1.SetLayerTreeHost(host1.get()); | 500 host_client1.SetLayerTreeHost(host1.get()); |
| 512 | 501 |
| 513 // TODO(sad): InitParams will be movable. | 502 // TODO(sad): InitParams will be movable. |
| 514 LayerTreeHostInProcess::InitParams params2; | 503 LayerTreeHostInProcess::InitParams params2; |
| 515 params2.client = &host_client1; | 504 params2.client = &host_client1; |
| 516 params2.shared_bitmap_manager = &shared_bitmap_manager; | |
| 517 params2.settings = &settings; | 505 params2.settings = &settings; |
| 518 params2.task_graph_runner = &task_graph_runner; | 506 params2.task_graph_runner = &task_graph_runner; |
| 519 params2.main_task_runner = base::ThreadTaskRunnerHandle::Get(); | 507 params2.main_task_runner = base::ThreadTaskRunnerHandle::Get(); |
| 520 params2.client = &host_client2; | 508 params2.client = &host_client2; |
| 521 params2.animation_host = | 509 params2.animation_host = |
| 522 AnimationHost::CreateForTesting(ThreadInstance::MAIN); | 510 AnimationHost::CreateForTesting(ThreadInstance::MAIN); |
| 523 std::unique_ptr<LayerTreeHost> host2 = | 511 std::unique_ptr<LayerTreeHost> host2 = |
| 524 LayerTreeHostInProcess::CreateSingleThreaded(&single_thread_client, | 512 LayerTreeHostInProcess::CreateSingleThreaded(&single_thread_client, |
| 525 ¶ms2); | 513 ¶ms2); |
| 526 host2->SetVisible(true); | 514 host2->SetVisible(true); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 548 // Do a main frame, record the picture layers. The frame number has changed | 536 // Do a main frame, record the picture layers. The frame number has changed |
| 549 // non-monotonically. | 537 // non-monotonically. |
| 550 layer->SetNeedsDisplay(); | 538 layer->SetNeedsDisplay(); |
| 551 host2->Composite(base::TimeTicks::Now()); | 539 host2->Composite(base::TimeTicks::Now()); |
| 552 EXPECT_EQ(3, layer->update_count()); | 540 EXPECT_EQ(3, layer->update_count()); |
| 553 EXPECT_EQ(1, host2->SourceFrameNumber()); | 541 EXPECT_EQ(1, host2->SourceFrameNumber()); |
| 554 } | 542 } |
| 555 | 543 |
| 556 } // namespace | 544 } // namespace |
| 557 } // namespace cc | 545 } // namespace cc |
| OLD | NEW |