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

Side by Side Diff: cc/surfaces/surface_factory_unittest.cc

Issue 1304063014: cc: Plumbing for BeginFrameSource based on Surfaces (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix webview Created 5 years, 2 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
« no previous file with comments | « cc/surfaces/surface_factory_client.h ('k') | cc/surfaces/surface_hittest_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "cc/output/compositor_frame.h" 6 #include "cc/output/compositor_frame.h"
7 #include "cc/output/copy_output_request.h" 7 #include "cc/output/copy_output_request.h"
8 #include "cc/output/copy_output_result.h" 8 #include "cc/output/copy_output_result.h"
9 #include "cc/output/delegated_frame_data.h" 9 #include "cc/output/delegated_frame_data.h"
10 #include "cc/resources/resource_provider.h" 10 #include "cc/resources/resource_provider.h"
11 #include "cc/surfaces/surface.h" 11 #include "cc/surfaces/surface.h"
12 #include "cc/surfaces/surface_factory.h" 12 #include "cc/surfaces/surface_factory.h"
13 #include "cc/surfaces/surface_factory_client.h" 13 #include "cc/surfaces/surface_factory_client.h"
14 #include "cc/surfaces/surface_manager.h" 14 #include "cc/surfaces/surface_manager.h"
15 #include "cc/test/scheduler_test_common.h"
15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
16 #include "ui/gfx/geometry/size.h" 17 #include "ui/gfx/geometry/size.h"
17 18
18 namespace cc { 19 namespace cc {
19 namespace { 20 namespace {
20 21
21 class TestSurfaceFactoryClient : public SurfaceFactoryClient { 22 class TestSurfaceFactoryClient : public SurfaceFactoryClient {
22 public: 23 public:
23 TestSurfaceFactoryClient() {} 24 TestSurfaceFactoryClient() : begin_frame_source_(nullptr) {}
24 ~TestSurfaceFactoryClient() override {} 25 ~TestSurfaceFactoryClient() override {}
25 26
26 void ReturnResources(const ReturnedResourceArray& resources) override { 27 void ReturnResources(const ReturnedResourceArray& resources) override {
27 returned_resources_.insert( 28 returned_resources_.insert(
28 returned_resources_.end(), resources.begin(), resources.end()); 29 returned_resources_.end(), resources.begin(), resources.end());
29 } 30 }
30 31
32 void SetBeginFrameSource(SurfaceId surface_id,
33 BeginFrameSource* begin_frame_source) override {
34 begin_frame_source_ = begin_frame_source;
35 }
36
31 const ReturnedResourceArray& returned_resources() const { 37 const ReturnedResourceArray& returned_resources() const {
32 return returned_resources_; 38 return returned_resources_;
33 } 39 }
34 40
35 void clear_returned_resources() { returned_resources_.clear(); } 41 void clear_returned_resources() { returned_resources_.clear(); }
36 42
43 BeginFrameSource* begin_frame_source() const { return begin_frame_source_; }
44
37 private: 45 private:
38 ReturnedResourceArray returned_resources_; 46 ReturnedResourceArray returned_resources_;
47 BeginFrameSource* begin_frame_source_;
39 48
40 DISALLOW_COPY_AND_ASSIGN(TestSurfaceFactoryClient); 49 DISALLOW_COPY_AND_ASSIGN(TestSurfaceFactoryClient);
41 }; 50 };
42 51
43 class SurfaceFactoryTest : public testing::Test { 52 class SurfaceFactoryTest : public testing::Test {
44 public: 53 public:
45 SurfaceFactoryTest() : factory_(&manager_, &client_), surface_id_(3) { 54 SurfaceFactoryTest()
46 factory_.Create(surface_id_); 55 : factory_(new SurfaceFactory(&manager_, &client_)), surface_id_(3) {
56 factory_->Create(surface_id_);
47 } 57 }
48 58
49 ~SurfaceFactoryTest() override { 59 ~SurfaceFactoryTest() override {
50 if (!surface_id_.is_null()) 60 if (!surface_id_.is_null())
51 factory_.Destroy(surface_id_); 61 factory_->Destroy(surface_id_);
52 } 62 }
53 63
54 void SubmitCompositorFrameWithResources(ResourceId* resource_ids, 64 void SubmitCompositorFrameWithResources(ResourceId* resource_ids,
55 size_t num_resource_ids) { 65 size_t num_resource_ids) {
56 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); 66 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
57 for (size_t i = 0u; i < num_resource_ids; ++i) { 67 for (size_t i = 0u; i < num_resource_ids; ++i) {
58 TransferableResource resource; 68 TransferableResource resource;
59 resource.id = resource_ids[i]; 69 resource.id = resource_ids[i];
60 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; 70 resource.mailbox_holder.texture_target = GL_TEXTURE_2D;
61 frame_data->resource_list.push_back(resource); 71 frame_data->resource_list.push_back(resource);
62 } 72 }
63 scoped_ptr<CompositorFrame> frame(new CompositorFrame); 73 scoped_ptr<CompositorFrame> frame(new CompositorFrame);
64 frame->delegated_frame_data = frame_data.Pass(); 74 frame->delegated_frame_data = frame_data.Pass();
65 factory_.SubmitCompositorFrame(surface_id_, frame.Pass(), 75 factory_->SubmitCompositorFrame(surface_id_, frame.Pass(),
66 SurfaceFactory::DrawCallback()); 76 SurfaceFactory::DrawCallback());
67 } 77 }
68 78
69 void UnrefResources(ResourceId* ids_to_unref, 79 void UnrefResources(ResourceId* ids_to_unref,
70 int* counts_to_unref, 80 int* counts_to_unref,
71 size_t num_ids_to_unref) { 81 size_t num_ids_to_unref) {
72 ReturnedResourceArray unref_array; 82 ReturnedResourceArray unref_array;
73 for (size_t i = 0; i < num_ids_to_unref; ++i) { 83 for (size_t i = 0; i < num_ids_to_unref; ++i) {
74 ReturnedResource resource; 84 ReturnedResource resource;
75 resource.id = ids_to_unref[i]; 85 resource.id = ids_to_unref[i];
76 resource.count = counts_to_unref[i]; 86 resource.count = counts_to_unref[i];
77 unref_array.push_back(resource); 87 unref_array.push_back(resource);
78 } 88 }
79 factory_.UnrefResources(unref_array); 89 factory_->UnrefResources(unref_array);
80 } 90 }
81 91
82 void CheckReturnedResourcesMatchExpected(ResourceId* expected_returned_ids, 92 void CheckReturnedResourcesMatchExpected(ResourceId* expected_returned_ids,
83 int* expected_returned_counts, 93 int* expected_returned_counts,
84 size_t expected_resources) { 94 size_t expected_resources) {
85 const ReturnedResourceArray& actual_resources = 95 const ReturnedResourceArray& actual_resources =
86 client_.returned_resources(); 96 client_.returned_resources();
87 ASSERT_EQ(expected_resources, actual_resources.size()); 97 ASSERT_EQ(expected_resources, actual_resources.size());
88 for (size_t i = 0; i < expected_resources; ++i) { 98 for (size_t i = 0; i < expected_resources; ++i) {
89 ReturnedResource resource = actual_resources[i]; 99 ReturnedResource resource = actual_resources[i];
90 EXPECT_EQ(expected_returned_ids[i], resource.id); 100 EXPECT_EQ(expected_returned_ids[i], resource.id);
91 EXPECT_EQ(expected_returned_counts[i], resource.count); 101 EXPECT_EQ(expected_returned_counts[i], resource.count);
92 } 102 }
93 client_.clear_returned_resources(); 103 client_.clear_returned_resources();
94 } 104 }
95 105
96 void RefCurrentFrameResources() { 106 void RefCurrentFrameResources() {
97 Surface* surface = manager_.GetSurfaceForId(surface_id_); 107 Surface* surface = manager_.GetSurfaceForId(surface_id_);
98 factory_.RefResources( 108 factory_->RefResources(
99 surface->GetEligibleFrame()->delegated_frame_data->resource_list); 109 surface->GetEligibleFrame()->delegated_frame_data->resource_list);
100 } 110 }
101 111
102 protected: 112 protected:
103 SurfaceManager manager_; 113 SurfaceManager manager_;
104 TestSurfaceFactoryClient client_; 114 TestSurfaceFactoryClient client_;
105 SurfaceFactory factory_; 115 scoped_ptr<SurfaceFactory> factory_;
106 SurfaceId surface_id_; 116 SurfaceId surface_id_;
107 }; 117 };
108 118
109 // Tests submitting a frame with resources followed by one with no resources 119 // Tests submitting a frame with resources followed by one with no resources
110 // with no resource provider action in between. 120 // with no resource provider action in between.
111 TEST_F(SurfaceFactoryTest, ResourceLifetimeSimple) { 121 TEST_F(SurfaceFactoryTest, ResourceLifetimeSimple) {
112 ResourceId first_frame_ids[] = {1, 2, 3}; 122 ResourceId first_frame_ids[] = {1, 2, 3};
113 SubmitCompositorFrameWithResources(first_frame_ids, 123 SubmitCompositorFrameWithResources(first_frame_ids,
114 arraysize(first_frame_ids)); 124 arraysize(first_frame_ids));
115 125
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 ResourceId expected_returned_ids[] = {12, 13}; 377 ResourceId expected_returned_ids[] = {12, 13};
368 int expected_returned_counts[] = {2, 2}; 378 int expected_returned_counts[] = {2, 2};
369 CheckReturnedResourcesMatchExpected(expected_returned_ids, 379 CheckReturnedResourcesMatchExpected(expected_returned_ids,
370 expected_returned_counts, 380 expected_returned_counts,
371 arraysize(expected_returned_counts)); 381 arraysize(expected_returned_counts));
372 } 382 }
373 } 383 }
374 384
375 TEST_F(SurfaceFactoryTest, BlankNoIndexIncrement) { 385 TEST_F(SurfaceFactoryTest, BlankNoIndexIncrement) {
376 SurfaceId surface_id(6); 386 SurfaceId surface_id(6);
377 factory_.Create(surface_id); 387 factory_->Create(surface_id);
378 Surface* surface = manager_.GetSurfaceForId(surface_id); 388 Surface* surface = manager_.GetSurfaceForId(surface_id);
379 ASSERT_NE(nullptr, surface); 389 ASSERT_NE(nullptr, surface);
380 EXPECT_EQ(2, surface->frame_index()); 390 EXPECT_EQ(2, surface->frame_index());
381 scoped_ptr<CompositorFrame> frame(new CompositorFrame); 391 scoped_ptr<CompositorFrame> frame(new CompositorFrame);
382 frame->delegated_frame_data.reset(new DelegatedFrameData); 392 frame->delegated_frame_data.reset(new DelegatedFrameData);
383 393
384 factory_.SubmitCompositorFrame(surface_id, frame.Pass(), 394 factory_->SubmitCompositorFrame(surface_id, frame.Pass(),
385 SurfaceFactory::DrawCallback()); 395 SurfaceFactory::DrawCallback());
386 EXPECT_EQ(2, surface->frame_index()); 396 EXPECT_EQ(2, surface->frame_index());
387 factory_.Destroy(surface_id); 397 factory_->Destroy(surface_id);
388 } 398 }
389 399
390 void DrawCallback(uint32* execute_count, 400 void DrawCallback(uint32* execute_count,
391 SurfaceDrawStatus* result, 401 SurfaceDrawStatus* result,
392 SurfaceDrawStatus drawn) { 402 SurfaceDrawStatus drawn) {
393 *execute_count += 1; 403 *execute_count += 1;
394 *result = drawn; 404 *result = drawn;
395 } 405 }
396 406
397 // Tests doing a DestroyAll before shutting down the factory; 407 // Tests doing a DestroyAll before shutting down the factory;
398 TEST_F(SurfaceFactoryTest, DestroyAll) { 408 TEST_F(SurfaceFactoryTest, DestroyAll) {
399 SurfaceId id(7); 409 SurfaceId id(7);
400 factory_.Create(id); 410 factory_->Create(id);
401 411
402 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); 412 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
403 TransferableResource resource; 413 TransferableResource resource;
404 resource.id = 1; 414 resource.id = 1;
405 resource.mailbox_holder.texture_target = GL_TEXTURE_2D; 415 resource.mailbox_holder.texture_target = GL_TEXTURE_2D;
406 frame_data->resource_list.push_back(resource); 416 frame_data->resource_list.push_back(resource);
407 scoped_ptr<CompositorFrame> frame(new CompositorFrame); 417 scoped_ptr<CompositorFrame> frame(new CompositorFrame);
408 frame->delegated_frame_data = frame_data.Pass(); 418 frame->delegated_frame_data = frame_data.Pass();
409 uint32 execute_count = 0; 419 uint32 execute_count = 0;
410 SurfaceDrawStatus drawn = SurfaceDrawStatus::DRAW_SKIPPED; 420 SurfaceDrawStatus drawn = SurfaceDrawStatus::DRAW_SKIPPED;
411 421
412 factory_.SubmitCompositorFrame( 422 factory_->SubmitCompositorFrame(
413 id, frame.Pass(), base::Bind(&DrawCallback, &execute_count, &drawn)); 423 id, frame.Pass(), base::Bind(&DrawCallback, &execute_count, &drawn));
414 424
415 surface_id_ = SurfaceId(); 425 surface_id_ = SurfaceId();
416 factory_.DestroyAll(); 426 factory_->DestroyAll();
417 EXPECT_EQ(1u, execute_count); 427 EXPECT_EQ(1u, execute_count);
418 EXPECT_EQ(SurfaceDrawStatus::DRAW_SKIPPED, drawn); 428 EXPECT_EQ(SurfaceDrawStatus::DRAW_SKIPPED, drawn);
419 } 429 }
420 430
421 TEST_F(SurfaceFactoryTest, DestroySequence) { 431 TEST_F(SurfaceFactoryTest, DestroySequence) {
422 SurfaceId id2(5); 432 SurfaceId id2(5);
423 factory_.Create(id2); 433 factory_->Create(id2);
424 434
425 manager_.RegisterSurfaceIdNamespace(0); 435 manager_.RegisterSurfaceIdNamespace(0);
426 436
427 // Check that waiting before the sequence is satisfied works. 437 // Check that waiting before the sequence is satisfied works.
428 manager_.GetSurfaceForId(id2) 438 manager_.GetSurfaceForId(id2)
429 ->AddDestructionDependency(SurfaceSequence(0, 4)); 439 ->AddDestructionDependency(SurfaceSequence(0, 4));
430 factory_.Destroy(id2); 440 factory_->Destroy(id2);
431 441
432 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); 442 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
433 scoped_ptr<CompositorFrame> frame(new CompositorFrame); 443 scoped_ptr<CompositorFrame> frame(new CompositorFrame);
434 frame->metadata.satisfies_sequences.push_back(6); 444 frame->metadata.satisfies_sequences.push_back(6);
435 frame->metadata.satisfies_sequences.push_back(4); 445 frame->metadata.satisfies_sequences.push_back(4);
436 frame->delegated_frame_data = frame_data.Pass(); 446 frame->delegated_frame_data = frame_data.Pass();
437 DCHECK(manager_.GetSurfaceForId(id2)); 447 DCHECK(manager_.GetSurfaceForId(id2));
438 factory_.SubmitCompositorFrame(surface_id_, frame.Pass(), 448 factory_->SubmitCompositorFrame(surface_id_, frame.Pass(),
439 SurfaceFactory::DrawCallback()); 449 SurfaceFactory::DrawCallback());
440 DCHECK(!manager_.GetSurfaceForId(id2)); 450 DCHECK(!manager_.GetSurfaceForId(id2));
441 451
442 // Check that waiting after the sequence is satisfied works. 452 // Check that waiting after the sequence is satisfied works.
443 factory_.Create(id2); 453 factory_->Create(id2);
444 DCHECK(manager_.GetSurfaceForId(id2)); 454 DCHECK(manager_.GetSurfaceForId(id2));
445 manager_.GetSurfaceForId(id2) 455 manager_.GetSurfaceForId(id2)
446 ->AddDestructionDependency(SurfaceSequence(0, 6)); 456 ->AddDestructionDependency(SurfaceSequence(0, 6));
447 factory_.Destroy(id2); 457 factory_->Destroy(id2);
448 DCHECK(!manager_.GetSurfaceForId(id2)); 458 DCHECK(!manager_.GetSurfaceForId(id2));
449 } 459 }
450 460
451 // Tests that Surface ID namespace invalidation correctly allows 461 // Tests that Surface ID namespace invalidation correctly allows
452 // Sequences to be ignored. 462 // Sequences to be ignored.
453 TEST_F(SurfaceFactoryTest, InvalidIdNamespace) { 463 TEST_F(SurfaceFactoryTest, InvalidIdNamespace) {
454 uint32_t id_namespace = 9u; 464 uint32_t id_namespace = 9u;
455 SurfaceId id(5); 465 SurfaceId id(5);
456 factory_.Create(id); 466 factory_->Create(id);
457 467
458 manager_.RegisterSurfaceIdNamespace(id_namespace); 468 manager_.RegisterSurfaceIdNamespace(id_namespace);
459 manager_.GetSurfaceForId(id) 469 manager_.GetSurfaceForId(id)
460 ->AddDestructionDependency(SurfaceSequence(id_namespace, 4)); 470 ->AddDestructionDependency(SurfaceSequence(id_namespace, 4));
461 factory_.Destroy(id); 471 factory_->Destroy(id);
462 472
463 // Verify the dependency has prevented the surface from getting destroyed. 473 // Verify the dependency has prevented the surface from getting destroyed.
464 EXPECT_TRUE(manager_.GetSurfaceForId(id)); 474 EXPECT_TRUE(manager_.GetSurfaceForId(id));
465 475
466 manager_.InvalidateSurfaceIdNamespace(id_namespace); 476 manager_.InvalidateSurfaceIdNamespace(id_namespace);
467 477
468 // Verify that the invalidated namespace caused the unsatisfied sequence 478 // Verify that the invalidated namespace caused the unsatisfied sequence
469 // to be ignored. 479 // to be ignored.
470 EXPECT_FALSE(manager_.GetSurfaceForId(id)); 480 EXPECT_FALSE(manager_.GetSurfaceForId(id));
471 } 481 }
472 482
473 TEST_F(SurfaceFactoryTest, DestroyCycle) { 483 TEST_F(SurfaceFactoryTest, DestroyCycle) {
474 SurfaceId id2(5); 484 SurfaceId id2(5);
475 factory_.Create(id2); 485 factory_->Create(id2);
476 486
477 manager_.RegisterSurfaceIdNamespace(0); 487 manager_.RegisterSurfaceIdNamespace(0);
478 488
479 manager_.GetSurfaceForId(id2) 489 manager_.GetSurfaceForId(id2)
480 ->AddDestructionDependency(SurfaceSequence(0, 4)); 490 ->AddDestructionDependency(SurfaceSequence(0, 4));
481 491
482 // Give id2 a frame that references surface_id_. 492 // Give id2 a frame that references surface_id_.
483 { 493 {
484 scoped_ptr<RenderPass> render_pass(RenderPass::Create()); 494 scoped_ptr<RenderPass> render_pass(RenderPass::Create());
485 render_pass->referenced_surfaces.push_back(surface_id_); 495 render_pass->referenced_surfaces.push_back(surface_id_);
486 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); 496 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
487 frame_data->render_pass_list.push_back(render_pass.Pass()); 497 frame_data->render_pass_list.push_back(render_pass.Pass());
488 scoped_ptr<CompositorFrame> frame(new CompositorFrame); 498 scoped_ptr<CompositorFrame> frame(new CompositorFrame);
489 frame->delegated_frame_data = frame_data.Pass(); 499 frame->delegated_frame_data = frame_data.Pass();
490 factory_.SubmitCompositorFrame(id2, frame.Pass(), 500 factory_->SubmitCompositorFrame(id2, frame.Pass(),
491 SurfaceFactory::DrawCallback()); 501 SurfaceFactory::DrawCallback());
492 } 502 }
493 factory_.Destroy(id2); 503 factory_->Destroy(id2);
494 504
495 // Give surface_id_ a frame that references id2. 505 // Give surface_id_ a frame that references id2.
496 { 506 {
497 scoped_ptr<RenderPass> render_pass(RenderPass::Create()); 507 scoped_ptr<RenderPass> render_pass(RenderPass::Create());
498 render_pass->referenced_surfaces.push_back(id2); 508 render_pass->referenced_surfaces.push_back(id2);
499 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); 509 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
500 frame_data->render_pass_list.push_back(render_pass.Pass()); 510 frame_data->render_pass_list.push_back(render_pass.Pass());
501 scoped_ptr<CompositorFrame> frame(new CompositorFrame); 511 scoped_ptr<CompositorFrame> frame(new CompositorFrame);
502 frame->delegated_frame_data = frame_data.Pass(); 512 frame->delegated_frame_data = frame_data.Pass();
503 factory_.SubmitCompositorFrame(surface_id_, frame.Pass(), 513 factory_->SubmitCompositorFrame(surface_id_, frame.Pass(),
504 SurfaceFactory::DrawCallback()); 514 SurfaceFactory::DrawCallback());
505 } 515 }
506 factory_.Destroy(surface_id_); 516 factory_->Destroy(surface_id_);
507 EXPECT_TRUE(manager_.GetSurfaceForId(id2)); 517 EXPECT_TRUE(manager_.GetSurfaceForId(id2));
508 // surface_id_ should be retained by reference from id2. 518 // surface_id_ should be retained by reference from id2.
509 EXPECT_TRUE(manager_.GetSurfaceForId(surface_id_)); 519 EXPECT_TRUE(manager_.GetSurfaceForId(surface_id_));
510 520
511 // Satisfy last destruction dependency for id2. 521 // Satisfy last destruction dependency for id2.
512 std::vector<uint32_t> to_satisfy; 522 std::vector<uint32_t> to_satisfy;
513 to_satisfy.push_back(4); 523 to_satisfy.push_back(4);
514 manager_.DidSatisfySequences(0, &to_satisfy); 524 manager_.DidSatisfySequences(0, &to_satisfy);
515 525
516 // id2 and surface_id_ are in a reference cycle that has no surface 526 // id2 and surface_id_ are in a reference cycle that has no surface
(...skipping 10 matching lines...) Expand all
527 } 537 }
528 538
529 TEST_F(SurfaceFactoryTest, DuplicateCopyRequest) { 539 TEST_F(SurfaceFactoryTest, DuplicateCopyRequest) {
530 { 540 {
531 scoped_ptr<RenderPass> render_pass(RenderPass::Create()); 541 scoped_ptr<RenderPass> render_pass(RenderPass::Create());
532 render_pass->referenced_surfaces.push_back(surface_id_); 542 render_pass->referenced_surfaces.push_back(surface_id_);
533 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); 543 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
534 frame_data->render_pass_list.push_back(render_pass.Pass()); 544 frame_data->render_pass_list.push_back(render_pass.Pass());
535 scoped_ptr<CompositorFrame> frame(new CompositorFrame); 545 scoped_ptr<CompositorFrame> frame(new CompositorFrame);
536 frame->delegated_frame_data = frame_data.Pass(); 546 frame->delegated_frame_data = frame_data.Pass();
537 factory_.SubmitCompositorFrame(surface_id_, frame.Pass(), 547 factory_->SubmitCompositorFrame(surface_id_, frame.Pass(),
538 SurfaceFactory::DrawCallback()); 548 SurfaceFactory::DrawCallback());
539 } 549 }
540 void* source1 = &source1; 550 void* source1 = &source1;
541 void* source2 = &source2; 551 void* source2 = &source2;
542 552
543 bool called1 = false; 553 bool called1 = false;
544 scoped_ptr<CopyOutputRequest> request; 554 scoped_ptr<CopyOutputRequest> request;
545 request = CopyOutputRequest::CreateRequest( 555 request = CopyOutputRequest::CreateRequest(
546 base::Bind(&CopyRequestTestCallback, &called1)); 556 base::Bind(&CopyRequestTestCallback, &called1));
547 request->set_source(source1); 557 request->set_source(source1);
548 558
549 factory_.RequestCopyOfSurface(surface_id_, request.Pass()); 559 factory_->RequestCopyOfSurface(surface_id_, request.Pass());
550 EXPECT_FALSE(called1); 560 EXPECT_FALSE(called1);
551 561
552 bool called2 = false; 562 bool called2 = false;
553 request = CopyOutputRequest::CreateRequest( 563 request = CopyOutputRequest::CreateRequest(
554 base::Bind(&CopyRequestTestCallback, &called2)); 564 base::Bind(&CopyRequestTestCallback, &called2));
555 request->set_source(source2); 565 request->set_source(source2);
556 566
557 factory_.RequestCopyOfSurface(surface_id_, request.Pass()); 567 factory_->RequestCopyOfSurface(surface_id_, request.Pass());
558 // Callbacks have different sources so neither should be called. 568 // Callbacks have different sources so neither should be called.
559 EXPECT_FALSE(called1); 569 EXPECT_FALSE(called1);
560 EXPECT_FALSE(called2); 570 EXPECT_FALSE(called2);
561 571
562 bool called3 = false; 572 bool called3 = false;
563 request = CopyOutputRequest::CreateRequest( 573 request = CopyOutputRequest::CreateRequest(
564 base::Bind(&CopyRequestTestCallback, &called3)); 574 base::Bind(&CopyRequestTestCallback, &called3));
565 request->set_source(source1); 575 request->set_source(source1);
566 576
567 factory_.RequestCopyOfSurface(surface_id_, request.Pass()); 577 factory_->RequestCopyOfSurface(surface_id_, request.Pass());
568 // Two callbacks are from source1, so the first should be called. 578 // Two callbacks are from source1, so the first should be called.
569 EXPECT_TRUE(called1); 579 EXPECT_TRUE(called1);
570 EXPECT_FALSE(called2); 580 EXPECT_FALSE(called2);
571 EXPECT_FALSE(called3); 581 EXPECT_FALSE(called3);
572 582
573 factory_.Destroy(surface_id_); 583 factory_->Destroy(surface_id_);
574 surface_id_ = SurfaceId(); 584 surface_id_ = SurfaceId();
575 EXPECT_TRUE(called1); 585 EXPECT_TRUE(called1);
576 EXPECT_TRUE(called2); 586 EXPECT_TRUE(called2);
577 EXPECT_TRUE(called3); 587 EXPECT_TRUE(called3);
578 } 588 }
579 589
590 // Verifies BFS is forwarded to the client.
591 TEST_F(SurfaceFactoryTest, SetBeginFrameSource) {
592 FakeBeginFrameSource bfs1;
593 FakeBeginFrameSource bfs2;
594 EXPECT_EQ(nullptr, client_.begin_frame_source());
595 factory_->SetBeginFrameSource(surface_id_, &bfs1);
596 EXPECT_EQ(&bfs1, client_.begin_frame_source());
597 factory_->SetBeginFrameSource(surface_id_, &bfs2);
598 EXPECT_EQ(&bfs2, client_.begin_frame_source());
599 factory_->SetBeginFrameSource(surface_id_, nullptr);
600 EXPECT_EQ(nullptr, client_.begin_frame_source());
601 }
602
603 TEST_F(SurfaceFactoryTest, BeginFrameSourceRemovedOnFactoryDestruction) {
604 FakeBeginFrameSource bfs;
605 factory_->SetBeginFrameSource(surface_id_, &bfs);
606 EXPECT_EQ(&bfs, client_.begin_frame_source());
607
608 // Prevent the Surface from being destroyed when we destroy the factory.
609 manager_.RegisterSurfaceIdNamespace(0);
610 manager_.GetSurfaceForId(surface_id_)
611 ->AddDestructionDependency(SurfaceSequence(0, 4));
612
613 surface_id_ = SurfaceId();
614 factory_->DestroyAll();
615
616 EXPECT_EQ(&bfs, client_.begin_frame_source());
617 factory_.reset();
618 EXPECT_EQ(nullptr, client_.begin_frame_source());
619 }
620
580 } // namespace 621 } // namespace
581 } // namespace cc 622 } // namespace cc
OLDNEW
« no previous file with comments | « cc/surfaces/surface_factory_client.h ('k') | cc/surfaces/surface_hittest_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698