OLD | NEW |
---|---|
(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 #ifndef GPU_COMMAND_BUFFER_SERVICE_PATH_MANAGER_H_ | |
6 #define GPU_COMMAND_BUFFER_SERVICE_PATH_MANAGER_H_ | |
7 | |
8 #include <map> | |
9 | |
10 #include "base/basictypes.h" | |
11 #include "gpu/command_buffer/service/gl_utils.h" | |
12 #include "gpu/gpu_export.h" | |
13 | |
14 namespace gpu { | |
15 namespace gles2 { | |
16 | |
17 // This class keeps track of paths and their client and service ids | |
18 // so we can correctly clear them. | |
19 class GPU_EXPORT PathManager { | |
20 public: | |
21 PathManager(); | |
22 ~PathManager(); | |
23 | |
24 // Must call before destruction. | |
25 void Destroy(bool have_context); | |
26 | |
27 // Creates a path mapping between closed intervals | |
28 // [first_client_id, last_client_id] -> [first_service_id, ...]. | |
29 void CreatePathRange(GLuint first_client_id, | |
30 GLuint last_client_id, | |
31 GLuint first_service_id); | |
32 | |
33 // Returns true if any path exists in the closed interval | |
34 // [first_client_id, last_client_id]. | |
35 bool HasPathsInRange(GLuint first_client_id, GLuint last_client_id) const; | |
36 | |
37 // Gets the path id corresponding the client path id. | |
38 // Returns false if no such service path id was not found. | |
39 bool GetPath(GLuint client_id, GLuint* service_id) const; | |
40 | |
41 // Removes a closed interval of paths [first_client_id, last_client_id]. | |
42 void RemovePaths(GLuint first_client_id, GLuint last_client_id); | |
43 | |
44 private: | |
45 // Mapping between client id and service id. | |
46 // Should be used only by the implememntation. | |
piman
2015/06/25 21:04:59
nit: implememntation->implementation
Kimmo Kinnunen
2015/06/26 08:00:16
Done.
| |
47 struct PathRangeDescription { | |
48 PathRangeDescription(GLuint last_client, GLuint first_service) | |
49 : last_client_id(last_client), first_service_id(first_service) {} | |
50 GLuint last_client_id; | |
51 GLuint first_service_id; | |
52 typedef GLuint ServiceIdType; | |
53 }; | |
54 typedef std::map<GLuint, PathRangeDescription> PathRangeMap; | |
55 | |
56 template <typename RangeIterator> | |
57 static GLuint RangeSize(const RangeIterator& it) { | |
58 return it->second.last_client_id - it->first + 1; | |
59 } | |
60 template <typename RangeIterator> | |
61 static GLuint FirstClientId(const RangeIterator& it) { | |
62 return it->first; | |
63 } | |
64 template <typename RangeIterator> | |
65 static GLuint FirstServiceId(const RangeIterator& it) { | |
66 return it->second.first_service_id; | |
67 } | |
68 template <typename RangeIterator> | |
69 static GLuint LastServiceId(const RangeIterator& it) { | |
70 return FirstServiceId(it) + RangeSize(it) - 1; | |
71 } | |
72 static GLuint LastClientId(PathManager::PathRangeMap::const_iterator& it) { | |
73 return it->second.last_client_id; | |
74 } | |
75 // Note: this one can be assigned to. | |
76 static GLuint& LastClientId(PathManager::PathRangeMap::iterator& it) { | |
77 return it->second.last_client_id; | |
78 } | |
79 | |
80 // Returns the range position that contains |client_id| or | |
81 // |PathRangeMap::iterator::end()| if |client_id| is not found. | |
82 PathRangeMap::const_iterator GetContainingRange(GLuint client_id) const; | |
83 // Returns the range position that contains |client_id|. If that is | |
84 // not available, returns the range that has smallest | |
85 // |first_client_id| that is bigger than |client_id|. Returns | |
86 // |PathRangeMap::iterator::end()| if there is no such range. | |
87 PathRangeMap::const_iterator GetContainingOrNextRange(GLuint client_id) const; | |
88 | |
89 // Checks for consistency inside the book-keeping structures. Used as | |
90 // DCHECK pre/post condition in mutating functions. | |
91 bool CheckConsistency(); | |
92 | |
93 PathRangeMap path_map_; | |
94 | |
95 DISALLOW_COPY_AND_ASSIGN(PathManager); | |
96 }; | |
97 | |
98 } // namespace gles2 | |
99 } // namespace gpu | |
100 | |
101 #endif // GPU_COMMAND_BUFFER_SERVICE_PATH_MANAGER_H_ | |
OLD | NEW |