1 // Copyright (c) 2010 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 #include "gpu/command_buffer/service/id_manager.h"
6 #include "base/logging.h"
7
8 namespace gpu {
9 namespace gles2 {
10
IdManager()11 IdManager::IdManager() {}
12
~IdManager()13 IdManager::~IdManager() {}
14
AddMapping(GLuint client_id,GLuint service_id)15 bool IdManager::AddMapping(GLuint client_id, GLuint service_id) {
16 std::pair<MapType::iterator, bool> result = id_map_.insert(
17 std::make_pair(client_id, service_id));
18 return result.second;
19 }
20
RemoveMapping(GLuint client_id,GLuint service_id)21 bool IdManager::RemoveMapping(GLuint client_id, GLuint service_id) {
22 MapType::iterator iter = id_map_.find(client_id);
23 if (iter != id_map_.end() && iter->second == service_id) {
24 id_map_.erase(iter);
25 return true;
26 }
27 return false;
28 }
29
GetServiceId(GLuint client_id,GLuint * service_id)30 bool IdManager::GetServiceId(GLuint client_id, GLuint* service_id) {
31 DCHECK(service_id);
32 MapType::iterator iter = id_map_.find(client_id);
33 if (iter != id_map_.end()) {
34 *service_id = iter->second;
35 return true;
36 }
37 return false;
38 }
39
GetClientId(GLuint service_id,GLuint * client_id)40 bool IdManager::GetClientId(GLuint service_id, GLuint* client_id) {
41 DCHECK(client_id);
42 MapType::iterator end(id_map_.end());
43 for (MapType::iterator iter(id_map_.begin());
44 iter != end;
45 ++iter) {
46 if (iter->second == service_id) {
47 *client_id = iter->first;
48 return true;
49 }
50 }
51 return false;
52 }
53
54 } // namespace gles2
55 } // namespace gpu
56
57
58