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

Side by Side Diff: gpu/command_buffer/service/path_manager_unittest.cc

Issue 169403005: command_buffer: Implement path rendering functions for CHROMIUM_path_rendering (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@nv-pr-02-texgen
Patch Set: rebase and cleanup ids Created 6 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
OLDNEW
(Empty)
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
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 virtual ~PathManagerTest() override {}
22
23 protected:
24 virtual void SetUp() override {
25 GpuServiceTest::SetUp();
26 manager_.reset(new PathManager());
27 }
28
29 virtual void TearDown() {
30 manager_->Destroy(true);
31 manager_.reset();
32 GpuServiceTest::TearDown();
33 }
34
35 scoped_refptr<FeatureInfo> feature_info_;
36 scoped_ptr<PathManager> manager_;
37 };
38
39 TEST_F(PathManagerTest, Basic) {
40 const GLuint kClient1Id = 1;
41 const GLuint kService1Id = 11;
42 const GLuint kClient2Id = 2;
43 GLuint service_id = 0;
44 manager_->CreatePathRange(kClient1Id, kClient1Id, kService1Id);
45 ASSERT_TRUE(manager_->HasPathsInRange(kClient1Id, kClient1Id));
46 EXPECT_TRUE(manager_->GetPath(kClient1Id, &service_id));
47 EXPECT_EQ(kService1Id, service_id);
48
49 // Check we get nothing for a non-existent texture.
50 service_id = 123u;
51 ASSERT_FALSE(manager_->HasPathsInRange(kClient2Id, kClient2Id));
52 EXPECT_FALSE(manager_->GetPath(kClient2Id, &service_id));
53 EXPECT_EQ(123u, service_id);
54
55 // Check trying to a remove non-existent textures does not crash.
56 manager_->RemovePaths(kClient2Id, kClient2Id);
57
58 // Check that it gets deleted when the last reference is released.
59 EXPECT_CALL(*gl_, DeletePathsNV(kService1Id, 1))
60 .Times(1)
61 .RetiresOnSaturation();
62
63 // Check we can't get the texture after we remove it.
64 manager_->RemovePaths(kClient1Id, kClient1Id);
65 ASSERT_FALSE(manager_->HasPathsInRange(kClient1Id, kClient1Id));
66 EXPECT_FALSE(manager_->GetPath(kClient1Id, &service_id));
67 }
68
69 // Tests that path manager does not merge ranges that contain service ids that
70 // in such a way that prevent the merging. Path ranges A and B can be merged if
71 // * client ids of B start immediately after the last client id of A
72 // * service ids of B start immediately after the last service id of A
73 // and similarly for the 'before' case.
74 TEST_F(PathManagerTest, NonContiguousServiceIds) {
75 const GLuint kMergeCheckRange = 54;
76
77 const struct {
78 GLuint first_client_id;
79 GLuint last_client_id;
80 GLuint first_service_id;
81 } kIdRanges[] = {{500, 1000, 900}, {1001, 1155, 1}, {200, 499, 4888}};
82 for (auto& range : kIdRanges) {
83 manager_->CreatePathRange(
84 range.first_client_id, range.last_client_id, range.first_service_id);
85 ASSERT_TRUE(manager_->HasPathsInRange(range.first_client_id,
86 range.first_client_id));
87 ASSERT_TRUE(
88 manager_->HasPathsInRange(range.last_client_id, range.last_client_id));
89 ASSERT_TRUE(
90 manager_->HasPathsInRange(range.first_client_id, range.last_client_id));
91 GLuint service_id = 0u;
92 EXPECT_TRUE(manager_->GetPath(range.first_client_id + 5u, &service_id));
93 EXPECT_EQ(range.first_service_id + 5u, service_id);
94 }
95
96 // Insert a mergeable range last, to check that merges
97 // work. Otherwise the test could succeed because merges were not
98 // working.
99 auto& merge_candidate = kIdRanges[1];
100 GLuint merge_candidate_range =
101 merge_candidate.last_client_id - merge_candidate.first_client_id + 1;
102 manager_->CreatePathRange(
103 merge_candidate.last_client_id + 1,
104 merge_candidate.last_client_id + kMergeCheckRange,
105 merge_candidate.first_service_id + merge_candidate_range);
106
107 // We detect that ranges were not merged accidentally by detecting individual
108 // deletes.
109 for (auto& range : kIdRanges) {
110 if (&range == &merge_candidate)
111 continue;
112 GLsizei range_amount = range.last_client_id - range.first_client_id + 1;
113 EXPECT_CALL(*gl_, DeletePathsNV(range.first_service_id, range_amount))
114 .Times(1)
115 .RetiresOnSaturation();
116 }
117
118 // Just a check that merges work.
119 EXPECT_CALL(*gl_,
120 DeletePathsNV(merge_candidate.first_service_id,
121 merge_candidate_range + kMergeCheckRange))
122 .Times(1)
123 .RetiresOnSaturation();
124
125 // Remove all ids. This should cause the expected amount of DeletePathsNV
126 // calls.
127 manager_->RemovePaths(1, std::numeric_limits<GLsizei>::max());
128
129 for (auto& range : kIdRanges) {
130 ASSERT_FALSE(
131 manager_->HasPathsInRange(range.first_client_id, range.last_client_id));
132 }
133 }
134
135 } // namespace gles2
136 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698