Index: gpu/command_buffer/service/path_manager.cc |
diff --git a/gpu/command_buffer/service/path_manager.cc b/gpu/command_buffer/service/path_manager.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..4f25c92333cd57b0f73ec5d13ea53ccb4c7898cf |
--- /dev/null |
+++ b/gpu/command_buffer/service/path_manager.cc |
@@ -0,0 +1,168 @@ |
+// Copyright (c) 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "gpu/command_buffer/service/path_manager.h" |
+#include "base/logging.h" |
+#include "gpu/command_buffer/common/gles2_cmd_utils.h" |
+#include "ui/gl/gl_bindings.h" |
+ |
+namespace { |
+void callDeletePaths(GLuint first_id, GLuint range) { |
piman
2015/06/24 03:27:44
nit: CallDeletePaths
Kimmo Kinnunen
2015/06/24 12:49:02
Done.
|
+ while (range > 0) { |
+ GLsizei irange; |
+ if (range > static_cast<GLuint>(std::numeric_limits<GLsizei>::max())) |
+ irange = std::numeric_limits<GLsizei>::max(); |
+ else |
+ irange = static_cast<GLsizei>(range); |
+ |
+ glDeletePathsNV(first_id, irange); |
+ range -= irange; |
+ first_id += irange + 1; |
piman
2015/06/24 03:27:44
Why +1? It doesn't seem right, and on top of it yo
Kimmo Kinnunen
2015/06/24 12:49:02
Definitely not right, oops.
Done, added a test to
|
+ } |
+} |
+} // anonymous namespace |
+ |
+namespace gpu { |
+namespace gles2 { |
+ |
+PathManager::PathManager() { |
+} |
+ |
+PathManager::~PathManager() { |
+ DCHECK(path_map_.empty()); |
+} |
+ |
+void PathManager::Destroy(bool have_context) { |
+ if (have_context) { |
+ for (PathRangeMap::const_iterator it = path_map_.begin(); |
+ it != path_map_.end(); ++it) |
+ callDeletePaths(FirstServiceId(it), RangeSize(it)); |
+ } |
+ path_map_.clear(); |
+} |
+ |
+void PathManager::CreatePathRange(GLuint first_client_id, |
+ GLuint last_client_id, |
+ GLuint first_service_id) { |
+ DCHECK(!HasPathsInRange(first_client_id, last_client_id)); |
+ DCHECK(first_service_id > 0); |
piman
2015/06/24 03:27:44
nit: also DCHECK(first_client_id > 0) - this was c
Kimmo Kinnunen
2015/06/24 12:49:02
Done.
|
+ bool check_before = false; |
+ |
+ PathRangeMap::iterator it = path_map_.lower_bound(first_client_id); |
+ PathRangeMap::iterator next_range = it; |
+ if (it != path_map_.begin()) { |
+ --it; |
+ check_before = true; |
+ } |
+ if (next_range != path_map_.end()) { |
+ GLuint last_service_id = |
+ first_service_id + last_client_id - first_client_id; |
+ // FirstClientId(next_range) - 1 does not underflow because lower_bound |
+ // returns > first_client_id. |
piman
2015/06/24 03:27:45
FirstClientId returns something that was guarantee
Kimmo Kinnunen
2015/06/24 12:49:02
Done.
|
+ // It does not return == first_client_id (== 0) because this would |
+ // contradict |
+ // !HasPathsInRange(first_client_id, last_client_id). |
+ // FirstServiceId(next_range) - 1 does not underflow because |
+ // first_service_id > 0. |
piman
2015/06/24 03:27:45
Can you add DCHECKs for these?
Kimmo Kinnunen
2015/06/24 12:49:02
Done. I removed the middle comment, as I don't eve
|
+ if (FirstClientId(next_range) - 1 == last_client_id && |
+ FirstServiceId(next_range) - 1 == last_service_id) { |
+ last_client_id = LastClientId(next_range); |
+ path_map_.erase(next_range); |
+ } |
+ } |
+ |
+ if (it != path_map_.end() && check_before) { |
+ // The last first client id -1 does not underflow because then lower_bound |
+ // would have found something, which contradicts |
+ // !HasPathsInRange(first_client_id, last_client_id). |
+ // first_service_id -1 does not underflow because first_service_id > 0. |
+ if (LastClientId(it) == first_client_id - 1 && |
+ LastServiceId(it) == first_service_id - 1) { |
+ LastClientId(it) = last_client_id; |
+ return; |
+ } |
+ } |
piman
2015/06/24 03:27:45
I find this all a bit hard to follow. I would like
Kimmo Kinnunen
2015/06/24 12:49:02
Right..
Current code has the good property that th
piman
2015/06/24 22:50:18
TBH I spent about an hour yesterday reviewing this
Kimmo Kinnunen
2015/06/25 12:13:35
Sorry about spending your time.
I tried to simpli
|
+ |
+ path_map_.insert(std::make_pair( |
+ first_client_id, PathRangeDescription(last_client_id, first_service_id))); |
+} |
+ |
+bool PathManager::HasPathsInRange(GLuint first_client_id, |
+ GLuint last_client_id) const { |
+ PathRangeMap::const_iterator it = path_map_.lower_bound(first_client_id); |
+ if (it != path_map_.end() && (FirstClientId(it) == first_client_id || |
+ FirstClientId(it) <= last_client_id)) |
+ return true; |
+ |
+ if (it == path_map_.begin()) |
+ return false; |
+ |
+ --it; |
+ return LastClientId(it) >= first_client_id; |
+} |
+ |
+bool PathManager::GetPath(GLuint client_id, GLuint* service_id) const { |
+ PathRangeMap::const_iterator it = path_map_.lower_bound(client_id); |
+ if (it != path_map_.end() && FirstClientId(it) == client_id) { |
+ *service_id = FirstServiceId(it); |
+ return true; |
+ } |
+ if (it == path_map_.begin()) |
+ return false; |
+ |
+ --it; |
+ if (LastClientId(it) < client_id) |
+ return false; |
+ |
+ *service_id = FirstServiceId(it) + client_id - FirstClientId(it); |
+ |
+ return true; |
+} |
+ |
+void PathManager::RemovePaths(GLuint first_client_id, GLuint last_client_id) { |
+ PathRangeMap::iterator it = path_map_.lower_bound(first_client_id); |
+ if (it == path_map_.end() || FirstClientId(it) != first_client_id) { |
+ if (it != path_map_.begin()) { |
+ --it; |
+ if (LastClientId(it) < first_client_id) |
+ ++it; |
+ } |
+ } |
+ |
+ while (it != path_map_.end() && FirstClientId(it) <= last_client_id) { |
+ GLuint delete_first_client_id = |
+ std::max(first_client_id, FirstClientId(it)); |
+ GLuint delete_last_client_id = std::min(last_client_id, LastClientId(it)); |
+ GLuint delete_first_service_id = |
+ FirstServiceId(it) + delete_first_client_id - FirstClientId(it); |
+ GLuint delete_range = delete_last_client_id - delete_first_client_id + 1; |
+ |
+ callDeletePaths(delete_first_service_id, delete_range); |
+ |
+ PathRangeMap::iterator current = it; |
+ ++it; |
+ |
+ GLuint current_last_client_id = LastClientId(current); |
+ |
+ if (FirstClientId(current) < delete_first_client_id) |
+ LastClientId(current) = delete_first_client_id - 1; |
+ else |
+ path_map_.erase(current); |
+ |
+ if (current_last_client_id > delete_last_client_id) { |
+ path_map_.insert(std::make_pair( |
+ delete_last_client_id + 1, |
+ PathRangeDescription(current_last_client_id, |
+ delete_first_service_id + delete_range))); |
+ DCHECK(delete_last_client_id == last_client_id); |
+ // This is necessarily the last range to check. Return early due to |
+ // consistency. Iterator increment would skip the inserted range. The |
+ // algorithm would work ok, but it looks weird. |
+ return; |
+ } |
+ } |
+} |
+ |
+} // namespace gles2 |
+} // namespace gpu |