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 #include "base/logging.h" | |
7 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | |
8 #include "ui/gl/gl_bindings.h" | |
9 | |
10 namespace { | |
11 void callDeletePaths(GLuint first_id, GLuint range) { | |
12 while (range > 0) { | |
13 GLsizei irange; | |
14 if (range > static_cast<GLuint>(std::numeric_limits<GLsizei>::max())) { | |
15 irange = std::numeric_limits<GLsizei>::max(); | |
16 } else { | |
17 irange = static_cast<GLsizei>(range); | |
18 } | |
19 glDeletePathsNV(first_id, irange); | |
20 range -= irange; | |
21 first_id += irange + 1; | |
22 } | |
23 } | |
24 } // anonymous namespace | |
25 | |
26 namespace gpu { | |
27 namespace gles2 { | |
28 | |
29 PathManager::PathManager() { | |
30 } | |
31 | |
32 PathManager::~PathManager() { | |
33 DCHECK(path_map_.empty()); | |
34 } | |
35 | |
36 void PathManager::Destroy(bool have_context) { | |
37 if (have_context) { | |
38 for (PathRangeMap::const_iterator it = path_map_.begin(); | |
39 it != path_map_.end(); ++it) { | |
40 callDeletePaths(FirstServiceId(it), RangeSize(it)); | |
41 } | |
42 } | |
43 path_map_.clear(); | |
44 } | |
45 | |
46 void PathManager::CreatePathRange(GLuint first_client_id, | |
47 GLuint last_client_id, | |
48 GLuint first_service_id) { | |
49 DCHECK(!HasPathsInRange(first_client_id, last_client_id)); | |
50 DCHECK(first_service_id > 0); | |
51 bool check_before = false; | |
52 | |
53 PathRangeMap::iterator it = path_map_.lower_bound(first_client_id); | |
54 PathRangeMap::iterator next_range = it; | |
55 if (it != path_map_.begin()) { | |
56 --it; | |
57 check_before = true; | |
58 } | |
59 if (next_range != path_map_.end()) { | |
60 GLuint last_service_id = | |
61 first_service_id + last_client_id - first_client_id; | |
62 // FirstClientId(next_range) - 1 does not underflow because lower_bound | |
63 // returns > first_client_id. | |
64 // It does not return == first_client_id (== 0) because this would | |
65 // contradict | |
66 // !HasPathsInRange(first_client_id, last_client_id). | |
67 // FirstServiceId(next_range) - 1 does not underflow because | |
68 // first_service_id > 0. | |
69 if (FirstClientId(next_range) - 1 == last_client_id && | |
70 FirstServiceId(next_range) - 1 == last_service_id) { | |
71 last_client_id = LastClientId(next_range); | |
72 path_map_.erase(next_range); | |
73 } | |
74 } | |
75 | |
76 if (it != path_map_.end() && check_before) { | |
77 // The last first client id -1 does not underflow because then lower_bound | |
78 // would have found something, which contradicts | |
79 // !HasPathsInRange(first_client_id, last_client_id). | |
80 // first_service_id -1 does not underflow because first_service_id > 0. | |
81 if (LastClientId(it) == first_client_id - 1 && | |
82 LastServiceId(it) == first_service_id - 1) { | |
83 LastClientId(it) = last_client_id; | |
84 return; | |
85 } | |
86 } | |
87 | |
88 path_map_.insert(std::make_pair( | |
89 first_client_id, PathRangeDescription(last_client_id, first_service_id))); | |
90 } | |
91 | |
92 bool PathManager::HasPathsInRange(GLuint first_client_id, | |
93 GLuint last_client_id) const { | |
94 PathRangeMap::const_iterator it = path_map_.lower_bound(first_client_id); | |
95 if (it != path_map_.end() && (FirstClientId(it) == first_client_id || | |
96 FirstClientId(it) <= last_client_id)) { | |
97 return true; | |
98 } | |
99 if (it == path_map_.begin()) { | |
100 return false; | |
101 } | |
102 --it; | |
103 return LastClientId(it) >= first_client_id; | |
104 } | |
105 | |
106 bool PathManager::GetPath(GLuint client_id, GLuint* service_id) const { | |
107 PathRangeMap::const_iterator it = path_map_.lower_bound(client_id); | |
108 if (it != path_map_.end() && FirstClientId(it) == client_id) { | |
109 *service_id = FirstServiceId(it); | |
110 return true; | |
111 } | |
112 if (it == path_map_.begin()) { | |
113 return false; | |
114 } | |
115 --it; | |
116 if (LastClientId(it) < client_id) { | |
117 return false; | |
118 } | |
119 | |
120 *service_id = FirstServiceId(it) + client_id - FirstClientId(it); | |
121 | |
122 return true; | |
123 } | |
124 | |
125 void PathManager::RemovePaths(GLuint first_client_id, GLuint last_client_id) { | |
126 PathRangeMap::iterator it = path_map_.lower_bound(first_client_id); | |
127 if (it == path_map_.end() || FirstClientId(it) != first_client_id) { | |
128 if (it != path_map_.begin()) { | |
129 --it; | |
130 if (LastClientId(it) < first_client_id) { | |
131 ++it; | |
132 } | |
133 } | |
134 } | |
135 | |
136 while (it != path_map_.end() && FirstClientId(it) <= last_client_id) { | |
137 GLuint delete_first_client_id = | |
138 std::max(first_client_id, FirstClientId(it)); | |
139 GLuint delete_last_client_id = std::min(last_client_id, LastClientId(it)); | |
140 GLuint delete_first_service_id = | |
141 FirstServiceId(it) + delete_first_client_id - FirstClientId(it); | |
142 GLuint delete_range = delete_last_client_id - delete_first_client_id + 1; | |
143 | |
144 callDeletePaths(delete_first_service_id, delete_range); | |
145 | |
146 PathRangeMap::iterator current = it; | |
147 ++it; | |
148 | |
149 GLuint current_last_client_id = LastClientId(current); | |
150 | |
151 if (FirstClientId(current) < delete_first_client_id) { | |
152 LastClientId(current) = delete_first_client_id - 1; | |
153 } else { | |
154 path_map_.erase(current); | |
155 } | |
156 | |
157 if (current_last_client_id > delete_last_client_id) { | |
158 path_map_.insert(std::make_pair( | |
159 delete_last_client_id + 1, | |
160 PathRangeDescription(current_last_client_id, | |
161 delete_first_service_id + delete_range))); | |
162 DCHECK(delete_last_client_id == last_client_id); | |
163 // This is necessarily the last range to check. Return early due to | |
164 // consistency. Iterator increment would skip the inserted range. The | |
165 // algorithm would work ok, but it looks weird. | |
166 return; | |
167 } | |
168 } | |
169 } | |
170 | |
171 } // namespace gles2 | |
172 } // namespace gpu | |
OLD | NEW |