| 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" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 TEST(PictureLayerTest, NoTilesIfEmptyBounds) { | 36 TEST(PictureLayerTest, NoTilesIfEmptyBounds) { |
| 37 ContentLayerClient* client = EmptyContentLayerClient::GetInstance(); | 37 ContentLayerClient* client = EmptyContentLayerClient::GetInstance(); |
| 38 scoped_refptr<PictureLayer> layer = PictureLayer::Create(client); | 38 scoped_refptr<PictureLayer> layer = PictureLayer::Create(client); |
| 39 layer->SetBounds(gfx::Size(10, 10)); | 39 layer->SetBounds(gfx::Size(10, 10)); |
| 40 | 40 |
| 41 FakeLayerTreeHostClient host_client; | 41 FakeLayerTreeHostClient host_client; |
| 42 TestTaskGraphRunner task_graph_runner; | 42 TestTaskGraphRunner task_graph_runner; |
| 43 auto animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN); | 43 auto animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN); |
| 44 std::unique_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create( | 44 std::unique_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create( |
| 45 &host_client, &task_graph_runner, animation_host.get()); | 45 &host_client, &task_graph_runner, animation_host.get()); |
| 46 host->GetLayerTree()->SetRootLayer(layer); | 46 host->SetRootLayer(layer); |
| 47 layer->SetIsDrawable(true); | 47 layer->SetIsDrawable(true); |
| 48 layer->SavePaintProperties(); | 48 layer->SavePaintProperties(); |
| 49 layer->Update(); | 49 layer->Update(); |
| 50 | 50 |
| 51 EXPECT_EQ(0, host->SourceFrameNumber()); | 51 EXPECT_EQ(0, host->SourceFrameNumber()); |
| 52 host->CommitComplete(); | 52 host->CommitComplete(); |
| 53 EXPECT_EQ(1, host->SourceFrameNumber()); | 53 EXPECT_EQ(1, host->SourceFrameNumber()); |
| 54 | 54 |
| 55 layer->SetBounds(gfx::Size(0, 0)); | 55 layer->SetBounds(gfx::Size(0, 0)); |
| 56 layer->SavePaintProperties(); | 56 layer->SavePaintProperties(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 80 FakeContentLayerClient client; | 80 FakeContentLayerClient client; |
| 81 client.set_bounds(layer_size); | 81 client.set_bounds(layer_size); |
| 82 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client); | 82 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client); |
| 83 layer->SetBounds(gfx::Size(50, 50)); | 83 layer->SetBounds(gfx::Size(50, 50)); |
| 84 | 84 |
| 85 FakeLayerTreeHostClient host_client; | 85 FakeLayerTreeHostClient host_client; |
| 86 TestTaskGraphRunner task_graph_runner; | 86 TestTaskGraphRunner task_graph_runner; |
| 87 auto animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN); | 87 auto animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN); |
| 88 std::unique_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create( | 88 std::unique_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create( |
| 89 &host_client, &task_graph_runner, animation_host.get()); | 89 &host_client, &task_graph_runner, animation_host.get()); |
| 90 host->GetLayerTree()->SetRootLayer(layer); | 90 host->SetRootLayer(layer); |
| 91 layer->SetIsDrawable(true); | 91 layer->SetIsDrawable(true); |
| 92 layer->SavePaintProperties(); | 92 layer->SavePaintProperties(); |
| 93 | 93 |
| 94 gfx::Rect invalidation_bounds(layer_size); | 94 gfx::Rect invalidation_bounds(layer_size); |
| 95 | 95 |
| 96 // The important two lines are the following: | 96 // The important two lines are the following: |
| 97 layer->SetNeedsDisplayRect(invalidation_bounds); | 97 layer->SetNeedsDisplayRect(invalidation_bounds); |
| 98 layer->Update(); | 98 layer->Update(); |
| 99 | 99 |
| 100 host->CommitComplete(); | 100 host->CommitComplete(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 124 FakeContentLayerClient client; | 124 FakeContentLayerClient client; |
| 125 client.set_bounds(layer_size); | 125 client.set_bounds(layer_size); |
| 126 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client); | 126 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client); |
| 127 layer->SetBounds(gfx::Size(50, 50)); | 127 layer->SetBounds(gfx::Size(50, 50)); |
| 128 | 128 |
| 129 FakeLayerTreeHostClient host_client; | 129 FakeLayerTreeHostClient host_client; |
| 130 TestTaskGraphRunner task_graph_runner; | 130 TestTaskGraphRunner task_graph_runner; |
| 131 auto animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN); | 131 auto animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN); |
| 132 std::unique_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create( | 132 std::unique_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create( |
| 133 &host_client, &task_graph_runner, animation_host.get()); | 133 &host_client, &task_graph_runner, animation_host.get()); |
| 134 host->GetLayerTree()->SetRootLayer(layer); | 134 host->SetRootLayer(layer); |
| 135 layer->SetIsDrawable(true); | 135 layer->SetIsDrawable(true); |
| 136 layer->SavePaintProperties(); | 136 layer->SavePaintProperties(); |
| 137 | 137 |
| 138 gfx::Rect invalidation_bounds(layer_size); | 138 gfx::Rect invalidation_bounds(layer_size); |
| 139 | 139 |
| 140 // The important line is the following (note that we do not call Update): | 140 // The important line is the following (note that we do not call Update): |
| 141 layer->SetNeedsDisplayRect(invalidation_bounds); | 141 layer->SetNeedsDisplayRect(invalidation_bounds); |
| 142 | 142 |
| 143 host->CommitComplete(); | 143 host->CommitComplete(); |
| 144 FakeImplTaskRunnerProvider impl_task_runner_provider; | 144 FakeImplTaskRunnerProvider impl_task_runner_provider; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 168 client.add_draw_image(CreateDiscardableImage(layer_size), gfx::Point(), | 168 client.add_draw_image(CreateDiscardableImage(layer_size), gfx::Point(), |
| 169 SkPaint()); | 169 SkPaint()); |
| 170 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client); | 170 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client); |
| 171 layer->SetBounds(gfx::Size(10, 10)); | 171 layer->SetBounds(gfx::Size(10, 10)); |
| 172 | 172 |
| 173 FakeLayerTreeHostClient host_client; | 173 FakeLayerTreeHostClient host_client; |
| 174 TestTaskGraphRunner task_graph_runner; | 174 TestTaskGraphRunner task_graph_runner; |
| 175 auto animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN); | 175 auto animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN); |
| 176 std::unique_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create( | 176 std::unique_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create( |
| 177 &host_client, &task_graph_runner, animation_host.get()); | 177 &host_client, &task_graph_runner, animation_host.get()); |
| 178 host->GetLayerTree()->SetRootLayer(layer); | 178 host->SetRootLayer(layer); |
| 179 layer->SetIsDrawable(true); | 179 layer->SetIsDrawable(true); |
| 180 layer->SavePaintProperties(); | 180 layer->SavePaintProperties(); |
| 181 layer->Update(); | 181 layer->Update(); |
| 182 | 182 |
| 183 EXPECT_EQ(0, host->SourceFrameNumber()); | 183 EXPECT_EQ(0, host->SourceFrameNumber()); |
| 184 host->CommitComplete(); | 184 host->CommitComplete(); |
| 185 EXPECT_EQ(1, host->SourceFrameNumber()); | 185 EXPECT_EQ(1, host->SourceFrameNumber()); |
| 186 | 186 |
| 187 layer->SavePaintProperties(); | 187 layer->SavePaintProperties(); |
| 188 layer->Update(); | 188 layer->Update(); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 ContentLayerClient* client = EmptyContentLayerClient::GetInstance(); | 250 ContentLayerClient* client = EmptyContentLayerClient::GetInstance(); |
| 251 scoped_refptr<FakePictureLayer> layer = | 251 scoped_refptr<FakePictureLayer> layer = |
| 252 FakePictureLayer::CreateWithRecordingSource( | 252 FakePictureLayer::CreateWithRecordingSource( |
| 253 client, std::move(recording_source_owned)); | 253 client, std::move(recording_source_owned)); |
| 254 | 254 |
| 255 FakeLayerTreeHostClient host_client; | 255 FakeLayerTreeHostClient host_client; |
| 256 TestTaskGraphRunner task_graph_runner; | 256 TestTaskGraphRunner task_graph_runner; |
| 257 auto animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN); | 257 auto animation_host = AnimationHost::CreateForTesting(ThreadInstance::MAIN); |
| 258 std::unique_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create( | 258 std::unique_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create( |
| 259 &host_client, &task_graph_runner, animation_host.get()); | 259 &host_client, &task_graph_runner, animation_host.get()); |
| 260 host->GetLayerTree()->SetRootLayer(layer); | 260 host->SetRootLayer(layer); |
| 261 | 261 |
| 262 // Update layers to initialize the recording source. | 262 // Update layers to initialize the recording source. |
| 263 gfx::Size layer_bounds(200, 200); | 263 gfx::Size layer_bounds(200, 200); |
| 264 gfx::Rect layer_rect(layer_bounds); | 264 gfx::Rect layer_rect(layer_bounds); |
| 265 Region invalidation(layer_rect); | 265 Region invalidation(layer_rect); |
| 266 | 266 |
| 267 gfx::Rect new_recorded_viewport = client->PaintableRegion(); | 267 gfx::Rect new_recorded_viewport = client->PaintableRegion(); |
| 268 scoped_refptr<DisplayItemList> display_list = | 268 scoped_refptr<DisplayItemList> display_list = |
| 269 client->PaintContentsToDisplayList( | 269 client->PaintContentsToDisplayList( |
| 270 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); | 270 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 params2.task_graph_runner = &task_graph_runner; | 322 params2.task_graph_runner = &task_graph_runner; |
| 323 params2.main_task_runner = base::ThreadTaskRunnerHandle::Get(); | 323 params2.main_task_runner = base::ThreadTaskRunnerHandle::Get(); |
| 324 params2.client = &host_client2; | 324 params2.client = &host_client2; |
| 325 params2.mutator_host = animation_host2.get(); | 325 params2.mutator_host = animation_host2.get(); |
| 326 std::unique_ptr<LayerTreeHost> host2 = | 326 std::unique_ptr<LayerTreeHost> host2 = |
| 327 LayerTreeHost::CreateSingleThreaded(&single_thread_client, ¶ms2); | 327 LayerTreeHost::CreateSingleThreaded(&single_thread_client, ¶ms2); |
| 328 host2->SetVisible(true); | 328 host2->SetVisible(true); |
| 329 host_client2.SetLayerTreeHost(host2.get()); | 329 host_client2.SetLayerTreeHost(host2.get()); |
| 330 | 330 |
| 331 // The PictureLayer is put in one LayerTreeHost. | 331 // The PictureLayer is put in one LayerTreeHost. |
| 332 host1->GetLayerTree()->SetRootLayer(layer); | 332 host1->SetRootLayer(layer); |
| 333 // Do a main frame, record the picture layers. | 333 // Do a main frame, record the picture layers. |
| 334 EXPECT_EQ(0, layer->update_count()); | 334 EXPECT_EQ(0, layer->update_count()); |
| 335 layer->SetNeedsDisplay(); | 335 layer->SetNeedsDisplay(); |
| 336 host1->Composite(base::TimeTicks::Now()); | 336 host1->Composite(base::TimeTicks::Now()); |
| 337 EXPECT_EQ(1, layer->update_count()); | 337 EXPECT_EQ(1, layer->update_count()); |
| 338 EXPECT_EQ(1, host1->SourceFrameNumber()); | 338 EXPECT_EQ(1, host1->SourceFrameNumber()); |
| 339 | 339 |
| 340 // The source frame number in |host1| is now higher than host2. | 340 // The source frame number in |host1| is now higher than host2. |
| 341 layer->SetNeedsDisplay(); | 341 layer->SetNeedsDisplay(); |
| 342 host1->Composite(base::TimeTicks::Now()); | 342 host1->Composite(base::TimeTicks::Now()); |
| 343 EXPECT_EQ(2, layer->update_count()); | 343 EXPECT_EQ(2, layer->update_count()); |
| 344 EXPECT_EQ(2, host1->SourceFrameNumber()); | 344 EXPECT_EQ(2, host1->SourceFrameNumber()); |
| 345 | 345 |
| 346 // Then moved to another LayerTreeHost. | 346 // Then moved to another LayerTreeHost. |
| 347 host1->GetLayerTree()->SetRootLayer(nullptr); | 347 host1->SetRootLayer(nullptr); |
| 348 host2->GetLayerTree()->SetRootLayer(layer); | 348 host2->SetRootLayer(layer); |
| 349 | 349 |
| 350 // Do a main frame, record the picture layers. The frame number has changed | 350 // Do a main frame, record the picture layers. The frame number has changed |
| 351 // non-monotonically. | 351 // non-monotonically. |
| 352 layer->SetNeedsDisplay(); | 352 layer->SetNeedsDisplay(); |
| 353 host2->Composite(base::TimeTicks::Now()); | 353 host2->Composite(base::TimeTicks::Now()); |
| 354 EXPECT_EQ(3, layer->update_count()); | 354 EXPECT_EQ(3, layer->update_count()); |
| 355 EXPECT_EQ(1, host2->SourceFrameNumber()); | 355 EXPECT_EQ(1, host2->SourceFrameNumber()); |
| 356 | 356 |
| 357 animation_host->SetMutatorHostClient(nullptr); | 357 animation_host->SetMutatorHostClient(nullptr); |
| 358 animation_host2->SetMutatorHostClient(nullptr); | 358 animation_host2->SetMutatorHostClient(nullptr); |
| 359 } | 359 } |
| 360 | 360 |
| 361 } // namespace | 361 } // namespace |
| 362 } // namespace cc | 362 } // namespace cc |
| OLD | NEW |