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/layer_iterator.h" | 5 #include "cc/layers/layer_iterator.h" |
6 #include "cc/output/copy_output_request.h" | 6 #include "cc/output/copy_output_request.h" |
7 #include "cc/output/copy_output_result.h" | 7 #include "cc/output/copy_output_result.h" |
8 #include "cc/test/fake_content_layer_client.h" | 8 #include "cc/test/fake_content_layer_client.h" |
9 #include "cc/test/fake_output_surface.h" | 9 #include "cc/test/fake_output_surface.h" |
10 #include "cc/test/fake_picture_layer.h" | 10 #include "cc/test/fake_picture_layer.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 // The |root| was copied to a bitmap and passed back also in Case 2. | 96 // The |root| was copied to a bitmap and passed back also in Case 2. |
97 EXPECT_EQ(gfx::Size(20, 20).ToString(), callbacks_[2].ToString()); | 97 EXPECT_EQ(gfx::Size(20, 20).ToString(), callbacks_[2].ToString()); |
98 // The |grand_child| was copied to a bitmap and passed back in Case 2. | 98 // The |grand_child| was copied to a bitmap and passed back in Case 2. |
99 EXPECT_EQ(gfx::Size(5, 5).ToString(), callbacks_[3].ToString()); | 99 EXPECT_EQ(gfx::Size(5, 5).ToString(), callbacks_[3].ToString()); |
100 EndTest(); | 100 EndTest(); |
101 break; | 101 break; |
102 } | 102 } |
103 } | 103 } |
104 | 104 |
105 void CopyOutputCallback(size_t id, scoped_ptr<CopyOutputResult> result) { | 105 void CopyOutputCallback(size_t id, scoped_ptr<CopyOutputResult> result) { |
106 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); | 106 EXPECT_TRUE(layer_tree_host()->task_runner_provider()->IsMainThread()); |
107 EXPECT_TRUE(result->HasBitmap()); | 107 EXPECT_TRUE(result->HasBitmap()); |
108 scoped_ptr<SkBitmap> bitmap = result->TakeBitmap().Pass(); | 108 scoped_ptr<SkBitmap> bitmap = result->TakeBitmap().Pass(); |
109 EXPECT_EQ(result->size().ToString(), | 109 EXPECT_EQ(result->size().ToString(), |
110 gfx::Size(bitmap->width(), bitmap->height()).ToString()); | 110 gfx::Size(bitmap->width(), bitmap->height()).ToString()); |
111 callbacks_[id] = result->size(); | 111 callbacks_[id] = result->size(); |
112 } | 112 } |
113 | 113 |
114 void AfterTest() override { EXPECT_EQ(4u, callbacks_.size()); } | 114 void AfterTest() override { EXPECT_EQ(4u, callbacks_.size()); } |
115 | 115 |
116 scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface() override { | 116 scoped_ptr<FakeOutputSurface> CreateFakeOutputSurface() override { |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 break; | 243 break; |
244 case 5: | 244 case 5: |
245 // We should get another callback with a NULL bitmap. | 245 // We should get another callback with a NULL bitmap. |
246 EXPECT_EQ(2, callback_count_); | 246 EXPECT_EQ(2, callback_count_); |
247 EndTest(); | 247 EndTest(); |
248 break; | 248 break; |
249 } | 249 } |
250 } | 250 } |
251 | 251 |
252 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { | 252 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { |
253 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); | 253 EXPECT_TRUE(layer_tree_host()->task_runner_provider()->IsMainThread()); |
254 EXPECT_TRUE(result->IsEmpty()); | 254 EXPECT_TRUE(result->IsEmpty()); |
255 ++callback_count_; | 255 ++callback_count_; |
256 } | 256 } |
257 | 257 |
258 void AfterTest() override {} | 258 void AfterTest() override {} |
259 | 259 |
260 int callback_count_; | 260 int callback_count_; |
261 FakeContentLayerClient client_; | 261 FakeContentLayerClient client_; |
262 scoped_refptr<FakePictureLayer> root_; | 262 scoped_refptr<FakePictureLayer> root_; |
263 scoped_refptr<FakePictureLayer> main_destroyed_; | 263 scoped_refptr<FakePictureLayer> main_destroyed_; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 | 300 |
301 void BeginTest() override { | 301 void BeginTest() override { |
302 callback_count_ = 0; | 302 callback_count_ = 0; |
303 PostSetNeedsCommitToMainThread(); | 303 PostSetNeedsCommitToMainThread(); |
304 | 304 |
305 AddCopyRequest(copy_layer_.get()); | 305 AddCopyRequest(copy_layer_.get()); |
306 } | 306 } |
307 | 307 |
308 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { | 308 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { |
309 ++callback_count_; | 309 ++callback_count_; |
310 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); | 310 EXPECT_TRUE(layer_tree_host()->task_runner_provider()->IsMainThread()); |
311 EXPECT_EQ(copy_layer_->bounds().ToString(), result->size().ToString()) | 311 EXPECT_EQ(copy_layer_->bounds().ToString(), result->size().ToString()) |
312 << callback_count_; | 312 << callback_count_; |
313 switch (callback_count_) { | 313 switch (callback_count_) { |
314 case 1: | 314 case 1: |
315 // Hide the copy request layer. | 315 // Hide the copy request layer. |
316 grand_parent_layer_->SetHideLayerAndSubtree(false); | 316 grand_parent_layer_->SetHideLayerAndSubtree(false); |
317 parent_layer_->SetHideLayerAndSubtree(false); | 317 parent_layer_->SetHideLayerAndSubtree(false); |
318 copy_layer_->SetHideLayerAndSubtree(true); | 318 copy_layer_->SetHideLayerAndSubtree(true); |
319 AddCopyRequest(copy_layer_.get()); | 319 AddCopyRequest(copy_layer_.get()); |
320 break; | 320 break; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 PostSetNeedsCommitToMainThread(); | 396 PostSetNeedsCommitToMainThread(); |
397 | 397 |
398 copy_layer_->RequestCopyOfOutput( | 398 copy_layer_->RequestCopyOfOutput( |
399 CopyOutputRequest::CreateBitmapRequest(base::Bind( | 399 CopyOutputRequest::CreateBitmapRequest(base::Bind( |
400 &LayerTreeHostTestHiddenSurfaceNotAllocatedForSubtreeCopyRequest:: | 400 &LayerTreeHostTestHiddenSurfaceNotAllocatedForSubtreeCopyRequest:: |
401 CopyOutputCallback, | 401 CopyOutputCallback, |
402 base::Unretained(this)))); | 402 base::Unretained(this)))); |
403 } | 403 } |
404 | 404 |
405 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { | 405 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { |
406 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); | 406 EXPECT_TRUE(layer_tree_host()->task_runner_provider()->IsMainThread()); |
407 EXPECT_EQ(copy_layer_->bounds().ToString(), result->size().ToString()); | 407 EXPECT_EQ(copy_layer_->bounds().ToString(), result->size().ToString()); |
408 EndTest(); | 408 EndTest(); |
409 } | 409 } |
410 | 410 |
411 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { | 411 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { |
412 Renderer* renderer = host_impl->renderer(); | 412 Renderer* renderer = host_impl->renderer(); |
413 | 413 |
414 LayerImpl* root = host_impl->active_tree()->root_layer(); | 414 LayerImpl* root = host_impl->active_tree()->root_layer(); |
415 LayerImpl* grand_parent = root->children()[0]; | 415 LayerImpl* grand_parent = root->children()[0]; |
416 LayerImpl* parent = grand_parent->children()[0]; | 416 LayerImpl* parent = grand_parent->children()[0]; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 PostSetNeedsCommitToMainThread(); | 468 PostSetNeedsCommitToMainThread(); |
469 | 469 |
470 copy_layer_->RequestCopyOfOutput(CopyOutputRequest::CreateBitmapRequest( | 470 copy_layer_->RequestCopyOfOutput(CopyOutputRequest::CreateBitmapRequest( |
471 base::Bind(&LayerTreeHostCopyRequestTestClippedOut::CopyOutputCallback, | 471 base::Bind(&LayerTreeHostCopyRequestTestClippedOut::CopyOutputCallback, |
472 base::Unretained(this)))); | 472 base::Unretained(this)))); |
473 } | 473 } |
474 | 474 |
475 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { | 475 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { |
476 // We should still get the content even if the copy requested layer was | 476 // We should still get the content even if the copy requested layer was |
477 // completely clipped away. | 477 // completely clipped away. |
478 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); | 478 EXPECT_TRUE(layer_tree_host()->task_runner_provider()->IsMainThread()); |
479 EXPECT_EQ(gfx::Size(10, 10).ToString(), result->size().ToString()); | 479 EXPECT_EQ(gfx::Size(10, 10).ToString(), result->size().ToString()); |
480 EndTest(); | 480 EndTest(); |
481 } | 481 } |
482 | 482 |
483 void AfterTest() override {} | 483 void AfterTest() override {} |
484 | 484 |
485 FakeContentLayerClient client_; | 485 FakeContentLayerClient client_; |
486 scoped_refptr<FakePictureLayer> root_; | 486 scoped_refptr<FakePictureLayer> root_; |
487 scoped_refptr<FakePictureLayer> parent_layer_; | 487 scoped_refptr<FakePictureLayer> parent_layer_; |
488 scoped_refptr<FakePictureLayer> copy_layer_; | 488 scoped_refptr<FakePictureLayer> copy_layer_; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 void DidCommit() override { | 535 void DidCommit() override { |
536 if (layer_tree_host()->source_frame_number() == 1) { | 536 if (layer_tree_host()->source_frame_number() == 1) { |
537 // Allow drawing. | 537 // Allow drawing. |
538 layer_tree_host()->SetViewportSize(gfx::Size(root_->bounds())); | 538 layer_tree_host()->SetViewportSize(gfx::Size(root_->bounds())); |
539 | 539 |
540 AddCopyRequest(copy_layer_.get()); | 540 AddCopyRequest(copy_layer_.get()); |
541 } | 541 } |
542 } | 542 } |
543 | 543 |
544 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { | 544 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { |
545 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); | 545 EXPECT_TRUE(layer_tree_host()->task_runner_provider()->IsMainThread()); |
546 | 546 |
547 // The first frame can't be drawn. | 547 // The first frame can't be drawn. |
548 switch (callback_count_) { | 548 switch (callback_count_) { |
549 case 0: | 549 case 0: |
550 EXPECT_TRUE(result->IsEmpty()); | 550 EXPECT_TRUE(result->IsEmpty()); |
551 EXPECT_EQ(gfx::Size(), result->size()); | 551 EXPECT_EQ(gfx::Size(), result->size()); |
552 break; | 552 break; |
553 case 1: | 553 case 1: |
554 EXPECT_FALSE(result->IsEmpty()); | 554 EXPECT_FALSE(result->IsEmpty()); |
555 EXPECT_EQ(copy_layer_->bounds().ToString(), result->size().ToString()); | 555 EXPECT_EQ(copy_layer_->bounds().ToString(), result->size().ToString()); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 copy_layer_->SetBounds(gfx::Size(10, 10)); | 597 copy_layer_->SetBounds(gfx::Size(10, 10)); |
598 root_->AddChild(copy_layer_); | 598 root_->AddChild(copy_layer_); |
599 | 599 |
600 layer_tree_host()->SetRootLayer(root_); | 600 layer_tree_host()->SetRootLayer(root_); |
601 LayerTreeHostCopyRequestTest::SetupTree(); | 601 LayerTreeHostCopyRequestTest::SetupTree(); |
602 } | 602 } |
603 | 603 |
604 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 604 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
605 | 605 |
606 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { | 606 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { |
607 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); | 607 EXPECT_TRUE(layer_tree_host()->task_runner_provider()->IsMainThread()); |
608 EXPECT_EQ(gfx::Size(10, 10).ToString(), result->size().ToString()); | 608 EXPECT_EQ(gfx::Size(10, 10).ToString(), result->size().ToString()); |
609 EXPECT_TRUE(result->HasTexture()); | 609 EXPECT_TRUE(result->HasTexture()); |
610 | 610 |
611 // Save the result for later. | 611 // Save the result for later. |
612 EXPECT_FALSE(result_); | 612 EXPECT_FALSE(result_); |
613 result_ = result.Pass(); | 613 result_ = result.Pass(); |
614 | 614 |
615 // Post a commit to lose the output surface. | 615 // Post a commit to lose the output surface. |
616 layer_tree_host()->SetNeedsCommit(); | 616 layer_tree_host()->SetNeedsCommit(); |
617 } | 617 } |
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1123 int num_draws_; | 1123 int num_draws_; |
1124 bool copy_happened_; | 1124 bool copy_happened_; |
1125 bool draw_happened_; | 1125 bool draw_happened_; |
1126 }; | 1126 }; |
1127 | 1127 |
1128 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 1128 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
1129 LayerTreeHostCopyRequestTestMultipleDrawsHiddenCopyRequest); | 1129 LayerTreeHostCopyRequestTestMultipleDrawsHiddenCopyRequest); |
1130 | 1130 |
1131 } // namespace | 1131 } // namespace |
1132 } // namespace cc | 1132 } // namespace cc |
OLD | NEW |