| OLD | NEW |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef GPU_COMMAND_BUFFER_SERVICE_CLIENT_SERVICE_MAP_H_ | 5 #ifndef GPU_COMMAND_BUFFER_SERVICE_CLIENT_SERVICE_MAP_H_ |
| 6 #define GPU_COMMAND_BUFFER_SERVICE_CLIENT_SERVICE_MAP_H_ | 6 #define GPU_COMMAND_BUFFER_SERVICE_CLIENT_SERVICE_MAP_H_ |
| 7 | 7 |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <unordered_map> | 9 #include <unordered_map> |
| 10 | 10 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 } | 47 } |
| 48 | 48 |
| 49 ServiceType GetServiceIDOrInvalid(ClientType client_id) { | 49 ServiceType GetServiceIDOrInvalid(ClientType client_id) { |
| 50 ServiceType service_id; | 50 ServiceType service_id; |
| 51 if (GetServiceID(client_id, &service_id)) { | 51 if (GetServiceID(client_id, &service_id)) { |
| 52 return service_id; | 52 return service_id; |
| 53 } | 53 } |
| 54 return invalid_service_id(); | 54 return invalid_service_id(); |
| 55 } | 55 } |
| 56 | 56 |
| 57 bool GetClientID(ServiceType service_id, ClientType* client_id) const { |
| 58 if (service_id == 0) { |
| 59 if (client_id) { |
| 60 *client_id = 0; |
| 61 } |
| 62 return true; |
| 63 } |
| 64 for (auto mapping : client_to_service_) { |
| 65 if (mapping.second == service_id) { |
| 66 if (client_id) { |
| 67 *client_id = mapping.first; |
| 68 } |
| 69 return true; |
| 70 } |
| 71 } |
| 72 return false; |
| 73 } |
| 74 |
| 57 ServiceType invalid_service_id() const { | 75 ServiceType invalid_service_id() const { |
| 58 return std::numeric_limits<ServiceType>::max(); | 76 return std::numeric_limits<ServiceType>::max(); |
| 59 } | 77 } |
| 60 | 78 |
| 61 typedef typename std::unordered_map<ClientType, ServiceType>::const_iterator | 79 typedef typename std::unordered_map<ClientType, ServiceType>::const_iterator |
| 62 const_iterator; | 80 const_iterator; |
| 63 const_iterator begin() const { return client_to_service_.begin(); } | 81 const_iterator begin() const { return client_to_service_.begin(); } |
| 64 const_iterator end() const { return client_to_service_.end(); } | 82 const_iterator end() const { return client_to_service_.end(); } |
| 65 | 83 |
| 66 private: | 84 private: |
| 67 std::unordered_map<ClientType, ServiceType> client_to_service_; | 85 std::unordered_map<ClientType, ServiceType> client_to_service_; |
| 68 }; | 86 }; |
| 69 | 87 |
| 70 } // namespace gles2 | 88 } // namespace gles2 |
| 71 } // namespace gpu | 89 } // namespace gpu |
| 72 | 90 |
| 73 #endif // GPU_COMMAND_BUFFER_SERVICE_CLIENT_SERVICE_MAP_H_ | 91 #endif // GPU_COMMAND_BUFFER_SERVICE_CLIENT_SERVICE_MAP_H_ |
| OLD | NEW |