OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | |
vmiura
2015/06/19 21:55:22
Now -> 2015.
Kimmo Kinnunen
2015/06/23 12:03:10
Done.
| |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "gpu/command_buffer/service/path_manager.h" | |
6 | |
7 #include "base/memory/scoped_ptr.h" | |
8 #include "gpu/command_buffer/service/feature_info.h" | |
9 #include "gpu/command_buffer/service/gpu_service_test.h" | |
10 #include "gpu/command_buffer/service/mocks.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | |
12 #include "ui/gl/gl_mock.h" | |
13 | |
14 namespace gpu { | |
15 namespace gles2 { | |
16 | |
17 class PathManagerTest : public GpuServiceTest { | |
18 public: | |
19 PathManagerTest() : feature_info_(new FeatureInfo()) {} | |
20 | |
21 protected: | |
22 void SetUp() override { | |
23 SetUpWithGLVersion("3.0", "GL_NV_path_rendering"); | |
24 manager_.reset(new PathManager()); | |
25 } | |
26 | |
27 void TearDown() override { | |
28 manager_->Destroy(true); | |
29 manager_.reset(); | |
30 GpuServiceTest::TearDown(); | |
31 } | |
32 | |
33 scoped_refptr<FeatureInfo> feature_info_; | |
34 scoped_ptr<PathManager> manager_; | |
35 }; | |
36 | |
37 TEST_F(PathManagerTest, Basic) { | |
38 const GLuint kClient1Id = 1; | |
39 const GLuint kService1Id = 11; | |
40 const GLuint kClient2Id = 2; | |
41 GLuint service_id = 0; | |
42 manager_->CreatePathRange(kClient1Id, kClient1Id, kService1Id); | |
43 ASSERT_TRUE(manager_->HasPathsInRange(kClient1Id, kClient1Id)); | |
44 EXPECT_TRUE(manager_->GetPath(kClient1Id, &service_id)); | |
45 EXPECT_EQ(kService1Id, service_id); | |
46 | |
47 // Check we get nothing for a non-existent path. | |
48 service_id = 123u; | |
49 ASSERT_FALSE(manager_->HasPathsInRange(kClient2Id, kClient2Id)); | |
50 EXPECT_FALSE(manager_->GetPath(kClient2Id, &service_id)); | |
51 EXPECT_EQ(123u, service_id); | |
52 | |
53 // Check trying to a remove non-existent paths does not crash. | |
54 manager_->RemovePaths(kClient2Id, kClient2Id); | |
55 | |
56 // Check that it gets deleted when the last reference is released. | |
57 EXPECT_CALL(*gl_, DeletePathsNV(kService1Id, 1)) | |
58 .Times(1) | |
59 .RetiresOnSaturation(); | |
60 | |
61 // Check we can't get the path after we remove it. | |
62 manager_->RemovePaths(kClient1Id, kClient1Id); | |
63 ASSERT_FALSE(manager_->HasPathsInRange(kClient1Id, kClient1Id)); | |
64 EXPECT_FALSE(manager_->GetPath(kClient1Id, &service_id)); | |
65 } | |
66 | |
67 // Tests that path manager does not merge ranges that contain service ids that | |
68 // in such a way that prevent the merging. Path ranges A and B can be merged if | |
69 // * client ids of B start immediately after the last client id of A | |
70 // * service ids of B start immediately after the last service id of A | |
71 // and similarly for the 'before' case. | |
72 TEST_F(PathManagerTest, NonContiguousServiceIds) { | |
73 const GLuint kMergeCheckRange = 54; | |
74 | |
75 const struct { | |
76 GLuint first_client_id; | |
77 GLuint last_client_id; | |
78 GLuint first_service_id; | |
79 } kIdRanges[] = {{500, 1000, 900}, {1001, 1155, 1}, {200, 499, 4888}}; | |
80 for (auto& range : kIdRanges) { | |
81 manager_->CreatePathRange(range.first_client_id, range.last_client_id, | |
82 range.first_service_id); | |
83 ASSERT_TRUE(manager_->HasPathsInRange(range.first_client_id, | |
84 range.first_client_id)); | |
85 ASSERT_TRUE( | |
86 manager_->HasPathsInRange(range.last_client_id, range.last_client_id)); | |
87 ASSERT_TRUE( | |
88 manager_->HasPathsInRange(range.first_client_id, range.last_client_id)); | |
89 GLuint service_id = 0u; | |
90 EXPECT_TRUE(manager_->GetPath(range.first_client_id + 5u, &service_id)); | |
91 EXPECT_EQ(range.first_service_id + 5u, service_id); | |
92 } | |
93 | |
94 // Insert a mergeable range last, to check that merges | |
95 // work. Otherwise the test could succeed because merges were not | |
96 // working. | |
97 auto& merge_candidate = kIdRanges[1]; | |
98 GLuint merge_candidate_range = | |
99 merge_candidate.last_client_id - merge_candidate.first_client_id + 1; | |
100 manager_->CreatePathRange( | |
101 merge_candidate.last_client_id + 1, | |
102 merge_candidate.last_client_id + kMergeCheckRange, | |
103 merge_candidate.first_service_id + merge_candidate_range); | |
104 | |
105 // We detect that ranges were not merged accidentally by detecting individual | |
106 // deletes. | |
107 for (auto& range : kIdRanges) { | |
108 if (&range == &merge_candidate) | |
109 continue; | |
110 GLsizei range_amount = range.last_client_id - range.first_client_id + 1; | |
111 EXPECT_CALL(*gl_, DeletePathsNV(range.first_service_id, range_amount)) | |
112 .Times(1) | |
113 .RetiresOnSaturation(); | |
114 } | |
115 | |
116 // Just a check that merges work. | |
117 EXPECT_CALL(*gl_, DeletePathsNV(merge_candidate.first_service_id, | |
118 merge_candidate_range + kMergeCheckRange)) | |
119 .Times(1) | |
120 .RetiresOnSaturation(); | |
121 | |
122 // Remove all ids. This should cause the expected amount of DeletePathsNV | |
123 // calls. | |
124 manager_->RemovePaths(1, std::numeric_limits<GLsizei>::max()); | |
125 | |
126 for (auto& range : kIdRanges) { | |
127 ASSERT_FALSE( | |
128 manager_->HasPathsInRange(range.first_client_id, range.last_client_id)); | |
129 } | |
130 } | |
131 | |
132 } // namespace gles2 | |
133 } // namespace gpu | |
OLD | NEW |