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

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
« no previous file with comments | « cc/surfaces/surface.cc ('k') | content/browser/BUILD.gn » ('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 "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 585 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 { 633 {
630 std::unique_ptr<RenderPass> render_pass(RenderPass::Create()); 634 std::unique_ptr<RenderPass> render_pass(RenderPass::Create());
631 CompositorFrame frame; 635 CompositorFrame frame;
632 frame.render_pass_list.push_back(std::move(render_pass)); 636 frame.render_pass_list.push_back(std::move(render_pass));
633 frame.metadata.referenced_surfaces.push_back( 637 frame.metadata.referenced_surfaces.push_back(
634 SurfaceId(factory_->frame_sink_id(), local_surface_id_)); 638 SurfaceId(factory_->frame_sink_id(), local_surface_id_));
635 factory_->SubmitCompositorFrame(local_surface_id_, std::move(frame), 639 factory_->SubmitCompositorFrame(local_surface_id_, std::move(frame),
636 SurfaceFactory::DrawCallback()); 640 SurfaceFactory::DrawCallback());
637 EXPECT_EQ(last_created_surface_id().local_surface_id(), local_surface_id_); 641 EXPECT_EQ(last_created_surface_id().local_surface_id(), local_surface_id_);
638 } 642 }
639 void* source1 = &source1;
640 void* source2 = &source2;
641 643
642 bool called1 = false; 644 bool called1 = false;
643 std::unique_ptr<CopyOutputRequest> request; 645 std::unique_ptr<CopyOutputRequest> request;
644 request = CopyOutputRequest::CreateRequest( 646 request = CopyOutputRequest::CreateRequest(
645 base::Bind(&CopyRequestTestCallback, &called1)); 647 base::Bind(&CopyRequestTestCallback, &called1));
646 request->set_source(source1); 648 request->set_source(kArbitrarySourceId1);
647 649
648 factory_->RequestCopyOfSurface(std::move(request)); 650 factory_->RequestCopyOfSurface(std::move(request));
649 EXPECT_FALSE(called1); 651 EXPECT_FALSE(called1);
650 652
651 bool called2 = false; 653 bool called2 = false;
652 request = CopyOutputRequest::CreateRequest( 654 request = CopyOutputRequest::CreateRequest(
653 base::Bind(&CopyRequestTestCallback, &called2)); 655 base::Bind(&CopyRequestTestCallback, &called2));
654 request->set_source(source2); 656 request->set_source(kArbitrarySourceId2);
655 657
656 factory_->RequestCopyOfSurface(std::move(request)); 658 factory_->RequestCopyOfSurface(std::move(request));
657 // Callbacks have different sources so neither should be called. 659 // Callbacks have different sources so neither should be called.
658 EXPECT_FALSE(called1); 660 EXPECT_FALSE(called1);
659 EXPECT_FALSE(called2); 661 EXPECT_FALSE(called2);
660 662
661 bool called3 = false; 663 bool called3 = false;
662 request = CopyOutputRequest::CreateRequest( 664 request = CopyOutputRequest::CreateRequest(
663 base::Bind(&CopyRequestTestCallback, &called3)); 665 base::Bind(&CopyRequestTestCallback, &called3));
664 request->set_source(source1); 666 request->set_source(kArbitrarySourceId1);
665 667
666 factory_->RequestCopyOfSurface(std::move(request)); 668 factory_->RequestCopyOfSurface(std::move(request));
667 // Two callbacks are from source1, so the first should be called. 669 // Two callbacks are from source1, so the first should be called.
668 EXPECT_TRUE(called1); 670 EXPECT_TRUE(called1);
669 EXPECT_FALSE(called2); 671 EXPECT_FALSE(called2);
670 EXPECT_FALSE(called3); 672 EXPECT_FALSE(called3);
671 673
672 factory_->EvictSurface(); 674 factory_->EvictSurface();
673 local_surface_id_ = LocalSurfaceId(); 675 local_surface_id_ = LocalSurfaceId();
674 EXPECT_TRUE(called1); 676 EXPECT_TRUE(called1);
(...skipping 19 matching lines...) Expand all
694 factory_->SubmitCompositorFrame(local_surface_id_, std::move(frame), 696 factory_->SubmitCompositorFrame(local_surface_id_, std::move(frame),
695 SurfaceFactory::DrawCallback()); 697 SurfaceFactory::DrawCallback());
696 SurfaceId expected_surface_id(factory_->frame_sink_id(), local_surface_id_); 698 SurfaceId expected_surface_id(factory_->frame_sink_id(), local_surface_id_);
697 EXPECT_EQ(expected_surface_id, last_surface_info_.id()); 699 EXPECT_EQ(expected_surface_id, last_surface_info_.id());
698 EXPECT_EQ(2.5f, last_surface_info_.device_scale_factor()); 700 EXPECT_EQ(2.5f, last_surface_info_.device_scale_factor());
699 EXPECT_EQ(gfx::Size(7, 8), last_surface_info_.size_in_pixels()); 701 EXPECT_EQ(gfx::Size(7, 8), last_surface_info_.size_in_pixels());
700 } 702 }
701 703
702 } // namespace 704 } // namespace
703 } // namespace cc 705 } // namespace cc
OLDNEW
« no previous file with comments | « cc/surfaces/surface.cc ('k') | content/browser/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698