Chromium Code Reviews| 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..07a4630ce1cbf81b08e4915a77c685bb487e77bd |
| --- /dev/null |
| +++ b/gpu/command_buffer/service/path_manager.cc |
| @@ -0,0 +1,172 @@ |
| +// 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.
|
| +// 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) { |
| + 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; |
| + } |
| +} |
| +} // 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); |
| + 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. |
| + // 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. |
| + 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; |
| + } |
| + } |
| + |
| + 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 |