| Index: gpu/command_buffer/service/client_service_map.h
|
| diff --git a/gpu/command_buffer/service/client_service_map.h b/gpu/command_buffer/service/client_service_map.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..4495c0ce100e1d925cf48939bcf6c264857daff5
|
| --- /dev/null
|
| +++ b/gpu/command_buffer/service/client_service_map.h
|
| @@ -0,0 +1,70 @@
|
| +// Copyright (c) 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#ifndef GPU_COMMAND_BUFFER_SERVICE_CLIENT_SERVICE_MAP_H_
|
| +#define GPU_COMMAND_BUFFER_SERVICE_CLIENT_SERVICE_MAP_H_
|
| +
|
| +#include <limits>
|
| +#include <unordered_map>
|
| +
|
| +namespace gpu {
|
| +
|
| +namespace gles2 {
|
| +
|
| +template <typename ClientType, typename ServiceType>
|
| +class ClientServiceMap {
|
| + public:
|
| + ClientServiceMap()
|
| + : client_to_service_(),
|
| + next_service_reserved_index_(std::numeric_limits<ServiceType>::max()) {}
|
| +
|
| + void SetIDMapping(ClientType client_id, ServiceType service_id) {
|
| + DCHECK(client_to_service_.find(client_id) == client_to_service_.end());
|
| + client_to_service_[client_id] = service_id;
|
| + }
|
| +
|
| + void RemoveClientID(ClientType client_id) {
|
| + client_to_service_.erase(client_id);
|
| + }
|
| +
|
| + bool GetServiceID(ClientType client_id, ServiceType* service_id) const {
|
| + if (client_id == 0) {
|
| + if (service_id) {
|
| + *service_id = 0;
|
| + }
|
| + return true;
|
| + }
|
| + auto iter = client_to_service_.find(client_id);
|
| + if (iter != client_to_service_.end()) {
|
| + if (service_id) {
|
| + *service_id = iter->second;
|
| + }
|
| + return true;
|
| + }
|
| + return false;
|
| + }
|
| +
|
| + ServiceType ReserveClientID(ClientType client_id) {
|
| + ServiceType service_id = next_service_reserved_index_--;
|
| + SetIDMapping(client_id, service_id);
|
| + return service_id;
|
| + }
|
| +
|
| + ServiceType GetServiceIDOrReserve(ClientType client_id) {
|
| + ServiceType service_id;
|
| + if (GetServiceID(client_id, &service_id)) {
|
| + return service_id;
|
| + }
|
| + return ReserveClientID(client_id);
|
| + }
|
| +
|
| + private:
|
| + std::unordered_map<ClientType, ServiceType> client_to_service_;
|
| + ServiceType next_service_reserved_index_;
|
| +};
|
| +
|
| +} // namespace gles2
|
| +} // namespace gpu
|
| +
|
| +#endif // GPU_COMMAND_BUFFER_SERVICE_CLIENT_SERVICE_MAP_H_
|
|
|