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

Side by Side Diff: gpu/command_buffer/service/path_manager.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: make more consistent Created 5 years, 6 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) 2015 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 #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) {
piman 2015/06/24 03:27:44 nit: CallDeletePaths
Kimmo Kinnunen 2015/06/24 12:49:02 Done.
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;
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
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 path_map_.clear();
43 }
44
45 void PathManager::CreatePathRange(GLuint first_client_id,
46 GLuint last_client_id,
47 GLuint first_service_id) {
48 DCHECK(!HasPathsInRange(first_client_id, last_client_id));
49 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.
50 bool check_before = false;
51
52 PathRangeMap::iterator it = path_map_.lower_bound(first_client_id);
53 PathRangeMap::iterator next_range = it;
54 if (it != path_map_.begin()) {
55 --it;
56 check_before = true;
57 }
58 if (next_range != path_map_.end()) {
59 GLuint last_service_id =
60 first_service_id + last_client_id - first_client_id;
61 // FirstClientId(next_range) - 1 does not underflow because lower_bound
62 // 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.
63 // It does not return == first_client_id (== 0) because this would
64 // contradict
65 // !HasPathsInRange(first_client_id, last_client_id).
66 // FirstServiceId(next_range) - 1 does not underflow because
67 // 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
68 if (FirstClientId(next_range) - 1 == last_client_id &&
69 FirstServiceId(next_range) - 1 == last_service_id) {
70 last_client_id = LastClientId(next_range);
71 path_map_.erase(next_range);
72 }
73 }
74
75 if (it != path_map_.end() && check_before) {
76 // The last first client id -1 does not underflow because then lower_bound
77 // would have found something, which contradicts
78 // !HasPathsInRange(first_client_id, last_client_id).
79 // first_service_id -1 does not underflow because first_service_id > 0.
80 if (LastClientId(it) == first_client_id - 1 &&
81 LastServiceId(it) == first_service_id - 1) {
82 LastClientId(it) = last_client_id;
83 return;
84 }
85 }
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
86
87 path_map_.insert(std::make_pair(
88 first_client_id, PathRangeDescription(last_client_id, first_service_id)));
89 }
90
91 bool PathManager::HasPathsInRange(GLuint first_client_id,
92 GLuint last_client_id) const {
93 PathRangeMap::const_iterator it = path_map_.lower_bound(first_client_id);
94 if (it != path_map_.end() && (FirstClientId(it) == first_client_id ||
95 FirstClientId(it) <= last_client_id))
96 return true;
97
98 if (it == path_map_.begin())
99 return false;
100
101 --it;
102 return LastClientId(it) >= first_client_id;
103 }
104
105 bool PathManager::GetPath(GLuint client_id, GLuint* service_id) const {
106 PathRangeMap::const_iterator it = path_map_.lower_bound(client_id);
107 if (it != path_map_.end() && FirstClientId(it) == client_id) {
108 *service_id = FirstServiceId(it);
109 return true;
110 }
111 if (it == path_map_.begin())
112 return false;
113
114 --it;
115 if (LastClientId(it) < client_id)
116 return false;
117
118 *service_id = FirstServiceId(it) + client_id - FirstClientId(it);
119
120 return true;
121 }
122
123 void PathManager::RemovePaths(GLuint first_client_id, GLuint last_client_id) {
124 PathRangeMap::iterator it = path_map_.lower_bound(first_client_id);
125 if (it == path_map_.end() || FirstClientId(it) != first_client_id) {
126 if (it != path_map_.begin()) {
127 --it;
128 if (LastClientId(it) < first_client_id)
129 ++it;
130 }
131 }
132
133 while (it != path_map_.end() && FirstClientId(it) <= last_client_id) {
134 GLuint delete_first_client_id =
135 std::max(first_client_id, FirstClientId(it));
136 GLuint delete_last_client_id = std::min(last_client_id, LastClientId(it));
137 GLuint delete_first_service_id =
138 FirstServiceId(it) + delete_first_client_id - FirstClientId(it);
139 GLuint delete_range = delete_last_client_id - delete_first_client_id + 1;
140
141 callDeletePaths(delete_first_service_id, delete_range);
142
143 PathRangeMap::iterator current = it;
144 ++it;
145
146 GLuint current_last_client_id = LastClientId(current);
147
148 if (FirstClientId(current) < delete_first_client_id)
149 LastClientId(current) = delete_first_client_id - 1;
150 else
151 path_map_.erase(current);
152
153 if (current_last_client_id > delete_last_client_id) {
154 path_map_.insert(std::make_pair(
155 delete_last_client_id + 1,
156 PathRangeDescription(current_last_client_id,
157 delete_first_service_id + delete_range)));
158 DCHECK(delete_last_client_id == last_client_id);
159 // This is necessarily the last range to check. Return early due to
160 // consistency. Iterator increment would skip the inserted range. The
161 // algorithm would work ok, but it looks weird.
162 return;
163 }
164 }
165 }
166
167 } // namespace gles2
168 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698