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

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

Issue 1673783004: Hook up BeginFrameSource to SurfaceFactoryClient via SurfaceManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Register id namespace on Android Created 4 years, 9 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_manager_unittest.cc ('k') | cc/surfaces/surfaces_pixeltest.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 "cc/surfaces/surface.h" 5 #include "cc/surfaces/surface.h"
6 #include "cc/surfaces/surface_factory.h" 6 #include "cc/surfaces/surface_factory.h"
7 #include "cc/surfaces/surface_factory_client.h" 7 #include "cc/surfaces/surface_factory_client.h"
8 #include "cc/surfaces/surface_manager.h" 8 #include "cc/surfaces/surface_manager.h"
9 #include "cc/test/scheduler_test_common.h" 9 #include "cc/test/scheduler_test_common.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "ui/gfx/geometry/size.h" 11 #include "ui/gfx/geometry/size.h"
12 12
13 namespace cc { 13 namespace cc {
14 namespace { 14 namespace {
15 15
16 class FakeSurfaceFactoryClient : public SurfaceFactoryClient { 16 class FakeSurfaceFactoryClient : public SurfaceFactoryClient {
17 public: 17 public:
18 FakeSurfaceFactoryClient() : begin_frame_source_(nullptr) {} 18 FakeSurfaceFactoryClient() : begin_frame_source_(nullptr) {}
19 19
20 void ReturnResources(const ReturnedResourceArray& resources) override {} 20 void ReturnResources(const ReturnedResourceArray& resources) override {}
21 21
22 void SetBeginFrameSource(SurfaceId surface_id, 22 void SetBeginFrameSource(BeginFrameSource* begin_frame_source) override {
23 BeginFrameSource* begin_frame_source) override {
24 begin_frame_source_ = begin_frame_source; 23 begin_frame_source_ = begin_frame_source;
25 } 24 }
26 25
27 BeginFrameSource* begin_frame_source() { return begin_frame_source_; } 26 BeginFrameSource* begin_frame_source() { return begin_frame_source_; }
28 27
29 private: 28 private:
30 BeginFrameSource* begin_frame_source_; 29 BeginFrameSource* begin_frame_source_;
31 }; 30 };
32 31
33 TEST(SurfaceTest, SurfaceLifetime) { 32 TEST(SurfaceTest, SurfaceLifetime) {
34 SurfaceManager manager; 33 SurfaceManager manager;
35 FakeSurfaceFactoryClient surface_factory_client; 34 FakeSurfaceFactoryClient surface_factory_client;
36 SurfaceFactory factory(&manager, &surface_factory_client); 35 SurfaceFactory factory(&manager, &surface_factory_client);
37 36
38 SurfaceId surface_id(6); 37 SurfaceId surface_id(6);
39 { 38 {
40 factory.Create(surface_id); 39 factory.Create(surface_id);
41 EXPECT_TRUE(manager.GetSurfaceForId(surface_id)); 40 EXPECT_TRUE(manager.GetSurfaceForId(surface_id));
42 factory.Destroy(surface_id); 41 factory.Destroy(surface_id);
43 } 42 }
44 43
45 EXPECT_EQ(NULL, manager.GetSurfaceForId(surface_id)); 44 EXPECT_EQ(NULL, manager.GetSurfaceForId(surface_id));
46 } 45 }
47 46
48 TEST(SurfaceTest, StableBeginFrameSourceIndependentOfOrderAdded) {
49 SurfaceManager manager;
50 FakeSurfaceFactoryClient surface_factory_client;
51 SurfaceFactory factory(&manager, &surface_factory_client);
52
53 SurfaceId surface_id(6);
54 factory.Create(surface_id);
55 Surface* surface = manager.GetSurfaceForId(surface_id);
56
57 FakeBeginFrameSource bfs1;
58 FakeBeginFrameSource bfs2;
59 FakeBeginFrameSource bfs3;
60
61 // Order 1.
62 surface->AddBeginFrameSource(&bfs1);
63 surface->AddBeginFrameSource(&bfs2);
64 surface->AddBeginFrameSource(&bfs3);
65 BeginFrameSource* bfs_order1 = surface_factory_client.begin_frame_source();
66 // Make sure one of the provided sources was chosen.
67 EXPECT_TRUE(&bfs1 == bfs_order1 || &bfs2 == bfs_order1 ||
68 &bfs3 == bfs_order1);
69 surface->RemoveBeginFrameSource(&bfs1);
70 surface->RemoveBeginFrameSource(&bfs2);
71 surface->RemoveBeginFrameSource(&bfs3);
72 EXPECT_EQ(nullptr, surface_factory_client.begin_frame_source());
73
74 // Order 2.
75 surface->AddBeginFrameSource(&bfs1);
76 surface->AddBeginFrameSource(&bfs3);
77 surface->AddBeginFrameSource(&bfs2);
78 BeginFrameSource* bfs_order2 = surface_factory_client.begin_frame_source();
79 // Verify choice is same as before.
80 EXPECT_EQ(bfs_order1, bfs_order2);
81 surface->RemoveBeginFrameSource(&bfs1);
82 surface->RemoveBeginFrameSource(&bfs2);
83 surface->RemoveBeginFrameSource(&bfs3);
84 EXPECT_EQ(nullptr, surface_factory_client.begin_frame_source());
85
86 // Order 3.
87 surface->AddBeginFrameSource(&bfs2);
88 surface->AddBeginFrameSource(&bfs1);
89 surface->AddBeginFrameSource(&bfs3);
90 BeginFrameSource* bfs_order3 = surface_factory_client.begin_frame_source();
91 // Verify choice is same as before.
92 EXPECT_EQ(bfs_order2, bfs_order3);
93 surface->RemoveBeginFrameSource(&bfs1);
94 surface->RemoveBeginFrameSource(&bfs2);
95 surface->RemoveBeginFrameSource(&bfs3);
96 EXPECT_EQ(nullptr, surface_factory_client.begin_frame_source());
97
98 // Order 4.
99 surface->AddBeginFrameSource(&bfs2);
100 surface->AddBeginFrameSource(&bfs3);
101 surface->AddBeginFrameSource(&bfs1);
102 BeginFrameSource* bfs_order4 = surface_factory_client.begin_frame_source();
103 // Verify choice is same as before.
104 EXPECT_EQ(bfs_order3, bfs_order4);
105 surface->RemoveBeginFrameSource(&bfs1);
106 surface->RemoveBeginFrameSource(&bfs2);
107 surface->RemoveBeginFrameSource(&bfs3);
108 EXPECT_EQ(nullptr, surface_factory_client.begin_frame_source());
109
110 // Order 5.
111 surface->AddBeginFrameSource(&bfs3);
112 surface->AddBeginFrameSource(&bfs1);
113 surface->AddBeginFrameSource(&bfs2);
114 BeginFrameSource* bfs_order5 = surface_factory_client.begin_frame_source();
115 // Verify choice is same as before.
116 EXPECT_EQ(bfs_order4, bfs_order5);
117 surface->RemoveBeginFrameSource(&bfs1);
118 surface->RemoveBeginFrameSource(&bfs2);
119 surface->RemoveBeginFrameSource(&bfs3);
120 EXPECT_EQ(nullptr, surface_factory_client.begin_frame_source());
121
122 // Order 6.
123 surface->AddBeginFrameSource(&bfs3);
124 surface->AddBeginFrameSource(&bfs2);
125 surface->AddBeginFrameSource(&bfs1);
126 BeginFrameSource* bfs_order6 = surface_factory_client.begin_frame_source();
127 // Verify choice is same as before.
128 EXPECT_EQ(bfs_order5, bfs_order6);
129 surface->RemoveBeginFrameSource(&bfs1);
130 surface->RemoveBeginFrameSource(&bfs2);
131 surface->RemoveBeginFrameSource(&bfs3);
132 EXPECT_EQ(nullptr, surface_factory_client.begin_frame_source());
133 }
134
135 TEST(SurfaceTest, BeginFrameSourceRemovedOnSurfaceDestruction) {
136 SurfaceManager manager;
137 FakeSurfaceFactoryClient surface_factory_client;
138 SurfaceFactory factory(&manager, &surface_factory_client);
139 FakeBeginFrameSource bfs;
140
141 SurfaceId surface_id(6);
142 factory.Create(surface_id);
143 Surface* surface = manager.GetSurfaceForId(surface_id);
144 surface->AddBeginFrameSource(&bfs);
145
146 BeginFrameSource* bfs_before = surface_factory_client.begin_frame_source();
147 factory.Destroy(surface_id);
148 BeginFrameSource* bfs_after = surface_factory_client.begin_frame_source();
149
150 EXPECT_EQ(&bfs, bfs_before);
151 EXPECT_EQ(nullptr, bfs_after);
152 }
153
154 } // namespace 47 } // namespace
155 } // namespace cc 48 } // namespace cc
OLDNEW
« no previous file with comments | « cc/surfaces/surface_manager_unittest.cc ('k') | cc/surfaces/surfaces_pixeltest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698