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 implementation. |
| 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 template <typename T> |
| 81 struct IteratorSelector { |
| 82 typedef typename T::iterator iterator; |
| 83 }; |
| 84 template <typename T> |
| 85 struct IteratorSelector<const T> { |
| 86 typedef typename T::const_iterator iterator; |
| 87 }; |
| 88 |
| 89 // Returns the range position that contains |client_id| or |
| 90 // |PathRangeMap::iterator::end()| if |client_id| is not found. |
| 91 template <typename MapType> |
| 92 static typename IteratorSelector<MapType>::iterator GetContainingRange( |
| 93 MapType& path_map, |
| 94 GLuint client_id); |
| 95 |
| 96 // Returns the range position that contains |client_id|. If that is |
| 97 // not available, returns the range that has smallest |
| 98 // |first_client_id| that is bigger than |client_id|. Returns |
| 99 // |PathRangeMap::iterator::end()| if there is no such range. |
| 100 template <typename MapType> |
| 101 static typename IteratorSelector<MapType>::iterator GetContainingOrNextRange( |
| 102 MapType& path_map, |
| 103 GLuint client_id); |
| 104 |
| 105 // Checks for consistency inside the book-keeping structures. Used as |
| 106 // DCHECK pre/post condition in mutating functions. |
| 107 bool CheckConsistency(); |
| 108 |
| 109 PathRangeMap path_map_; |
| 110 |
| 111 DISALLOW_COPY_AND_ASSIGN(PathManager); |
| 112 }; |
| 113 |
| 114 } // namespace gles2 |
| 115 } // namespace gpu |
| 116 |
| 117 #endif // GPU_COMMAND_BUFFER_SERVICE_PATH_MANAGER_H_ |
OLD | NEW |