Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef GPU_COMMAND_BUFFER_SERVICE_CLIENT_SERVICE_MAP_H_ | |
| 6 #define GPU_COMMAND_BUFFER_SERVICE_CLIENT_SERVICE_MAP_H_ | |
| 7 | |
| 8 #include <limits> | |
| 9 #include <unordered_map> | |
| 10 | |
| 11 namespace gpu { | |
| 12 | |
| 13 namespace gles2 { | |
| 14 | |
| 15 template <typename ClientType, typename ServiceType> | |
| 16 class ClientServiceMap { | |
| 17 public: | |
| 18 ClientServiceMap() | |
| 19 : client_to_service_(), | |
| 20 next_service_reserved_index_(std::numeric_limits<ServiceType>::max()) {} | |
| 21 | |
| 22 void SetIDMapping(ClientType client_id, ServiceType service_id) { | |
| 23 DCHECK(client_to_service_.find(client_id) == client_to_service_.end()); | |
| 24 client_to_service_[client_id] = service_id; | |
| 25 } | |
| 26 | |
| 27 void RemoveClientID(ClientType client_id) { | |
| 28 client_to_service_.erase(client_id); | |
| 29 } | |
| 30 | |
| 31 bool GetServiceID(ClientType client_id, ServiceType* service_id) const { | |
| 32 if (client_id == 0) { | |
| 33 if (service_id) { | |
| 34 *service_id = 0; | |
| 35 } | |
| 36 return true; | |
| 37 } | |
| 38 auto iter = client_to_service_.find(client_id); | |
| 39 if (iter != client_to_service_.end()) { | |
| 40 if (service_id) { | |
| 41 *service_id = iter->second; | |
| 42 } | |
| 43 return true; | |
| 44 } else { | |
|
Zhenyao Mo
2016/09/09 21:22:10
nit: chrome style asks no else here.
Geoff Lang
2016/09/12 14:21:29
Done.
| |
| 45 return false; | |
| 46 } | |
| 47 } | |
| 48 | |
| 49 ServiceType ReserveClientID(ClientType client_id) { | |
| 50 ServiceType service_id = next_service_reserved_index_--; | |
| 51 SetIDMapping(client_id, service_id); | |
| 52 return service_id; | |
| 53 } | |
| 54 | |
| 55 ServiceType GetServiceIDOrReserve(ClientType client_id) { | |
| 56 ServiceType service_id; | |
| 57 if (GetServiceID(client_id, &service_id)) { | |
| 58 return service_id; | |
| 59 } else { | |
|
Zhenyao Mo
2016/09/09 21:22:10
Same here, no else
Geoff Lang
2016/09/12 14:21:29
Done.
| |
| 60 return ReserveClientID(client_id); | |
| 61 } | |
| 62 } | |
| 63 | |
| 64 private: | |
| 65 std::unordered_map<ClientType, ServiceType> client_to_service_; | |
| 66 ServiceType next_service_reserved_index_; | |
| 67 }; | |
| 68 | |
| 69 } // namespace gles2 | |
| 70 } // namespace gpu | |
| 71 | |
| 72 #endif // GPU_COMMAND_BUFFER_SERVICE_CLIENT_SERVICE_MAP_H_ | |
| OLD | NEW |