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

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

Issue 2652343003: Replace source pointer in cc::CopyOutputRequest with a base::UnguessableToken (Closed)
Patch Set: c Created 3 years, 10 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
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 "cc/surfaces/surface_factory.h" 5 #include "cc/surfaces/surface_factory.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <utility> 10 #include <utility>
(...skipping 13 matching lines...) Expand all
24 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
25 #include "ui/gfx/geometry/size.h" 25 #include "ui/gfx/geometry/size.h"
26 26
27 namespace cc { 27 namespace cc {
28 namespace { 28 namespace {
29 29
30 static constexpr FrameSinkId kArbitraryFrameSinkId(1, 1); 30 static constexpr FrameSinkId kArbitraryFrameSinkId(1, 1);
31 static constexpr FrameSinkId kAnotherArbitraryFrameSinkId(2, 2); 31 static constexpr FrameSinkId kAnotherArbitraryFrameSinkId(2, 2);
32 static const base::UnguessableToken kArbitraryToken = 32 static const base::UnguessableToken kArbitraryToken =
33 base::UnguessableToken::Create(); 33 base::UnguessableToken::Create();
34 static auto kArbitrarySourceId1 =
35 base::UnguessableToken::Deserialize(0xdead, 0xbeef);
36 static auto kArbitrarySourceId2 =
37 base::UnguessableToken::Deserialize(0xdead, 0xbee0);
34 38
35 class TestSurfaceFactoryClient : public SurfaceFactoryClient { 39 class TestSurfaceFactoryClient : public SurfaceFactoryClient {
36 public: 40 public:
37 TestSurfaceFactoryClient() : begin_frame_source_(nullptr) {} 41 TestSurfaceFactoryClient() : begin_frame_source_(nullptr) {}
38 ~TestSurfaceFactoryClient() override {} 42 ~TestSurfaceFactoryClient() override {}
39 43
40 void ReturnResources(const ReturnedResourceArray& resources) override { 44 void ReturnResources(const ReturnedResourceArray& resources) override {
41 returned_resources_.insert( 45 returned_resources_.insert(
42 returned_resources_.end(), resources.begin(), resources.end()); 46 returned_resources_.end(), resources.begin(), resources.end());
43 } 47 }
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 { 626 {
623 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); 627 std::unique_ptr<RenderPass> render_pass(RenderPass::Create());
624 CompositorFrame frame; 628 CompositorFrame frame;
625 frame.render_pass_list.push_back(std::move(render_pass)); 629 frame.render_pass_list.push_back(std::move(render_pass));
626 frame.metadata.referenced_surfaces.push_back( 630 frame.metadata.referenced_surfaces.push_back(
627 SurfaceId(factory_->frame_sink_id(), local_frame_id_)); 631 SurfaceId(factory_->frame_sink_id(), local_frame_id_));
628 factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame), 632 factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame),
629 SurfaceFactory::DrawCallback()); 633 SurfaceFactory::DrawCallback());
630 EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id_); 634 EXPECT_EQ(last_created_surface_id().local_frame_id(), local_frame_id_);
631 } 635 }
632 void* source1 = &source1;
633 void* source2 = &source2;
634 636
635 bool called1 = false; 637 bool called1 = false;
636 std::unique_ptr<CopyOutputRequest> request; 638 std::unique_ptr<CopyOutputRequest> request;
637 request = CopyOutputRequest::CreateRequest( 639 request = CopyOutputRequest::CreateRequest(
638 base::Bind(&CopyRequestTestCallback, &called1)); 640 base::Bind(&CopyRequestTestCallback, &called1));
639 request->set_source(source1); 641 request->set_source(kArbitrarySourceId1);
640 642
641 factory_->RequestCopyOfSurface(std::move(request)); 643 factory_->RequestCopyOfSurface(std::move(request));
642 EXPECT_FALSE(called1); 644 EXPECT_FALSE(called1);
643 645
644 bool called2 = false; 646 bool called2 = false;
645 request = CopyOutputRequest::CreateRequest( 647 request = CopyOutputRequest::CreateRequest(
646 base::Bind(&CopyRequestTestCallback, &called2)); 648 base::Bind(&CopyRequestTestCallback, &called2));
647 request->set_source(source2); 649 request->set_source(kArbitrarySourceId2);
648 650
649 factory_->RequestCopyOfSurface(std::move(request)); 651 factory_->RequestCopyOfSurface(std::move(request));
650 // Callbacks have different sources so neither should be called. 652 // Callbacks have different sources so neither should be called.
651 EXPECT_FALSE(called1); 653 EXPECT_FALSE(called1);
652 EXPECT_FALSE(called2); 654 EXPECT_FALSE(called2);
653 655
654 bool called3 = false; 656 bool called3 = false;
655 request = CopyOutputRequest::CreateRequest( 657 request = CopyOutputRequest::CreateRequest(
656 base::Bind(&CopyRequestTestCallback, &called3)); 658 base::Bind(&CopyRequestTestCallback, &called3));
657 request->set_source(source1); 659 request->set_source(kArbitrarySourceId1);
658 660
659 factory_->RequestCopyOfSurface(std::move(request)); 661 factory_->RequestCopyOfSurface(std::move(request));
660 // Two callbacks are from source1, so the first should be called. 662 // Two callbacks are from source1, so the first should be called.
661 EXPECT_TRUE(called1); 663 EXPECT_TRUE(called1);
662 EXPECT_FALSE(called2); 664 EXPECT_FALSE(called2);
663 EXPECT_FALSE(called3); 665 EXPECT_FALSE(called3);
664 666
665 factory_->EvictSurface(); 667 factory_->EvictSurface();
666 local_frame_id_ = LocalFrameId(); 668 local_frame_id_ = LocalFrameId();
667 EXPECT_TRUE(called1); 669 EXPECT_TRUE(called1);
668 EXPECT_TRUE(called2); 670 EXPECT_TRUE(called2);
669 EXPECT_TRUE(called3); 671 EXPECT_TRUE(called3);
670 } 672 }
671 673
672 } // namespace 674 } // namespace
673 } // namespace cc 675 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698