1// Copyright (c) 2012 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_ID_MANAGER_H_
6#define GPU_COMMAND_BUFFER_SERVICE_ID_MANAGER_H_
7
8#include "base/basictypes.h"
9#include "base/containers/hash_tables.h"
10#include "gpu/command_buffer/service/gl_utils.h"
11#include "gpu/gpu_export.h"
12
13namespace gpu {
14namespace gles2 {
15
16// This class maps one set of ids to another.
17//
18// NOTE: To support shared resources an instance of this class will
19// need to be shared by multiple GLES2Decoders.
20class GPU_EXPORT IdManager {
21 public:
22  IdManager();
23  ~IdManager();
24
25  // Maps a client_id to a service_id. Return false if the client_id or
26  // service_id are already mapped to something else.
27  bool AddMapping(GLuint client_id, GLuint service_id);
28
29  // Unmaps a pair of ids. Returns false if the pair were not previously mapped.
30  bool RemoveMapping(GLuint client_id, GLuint service_id);
31
32  // Gets the corresponding service_id for the given client_id.
33  // Returns false if there is no corresponding service_id.
34  bool GetServiceId(GLuint client_id, GLuint* service_id);
35
36  // Gets the corresponding client_id for the given service_id.
37  // Returns false if there is no corresponding client_id.
38  bool GetClientId(GLuint service_id, GLuint* client_id);
39
40 private:
41  typedef base::hash_map<GLuint, GLuint> MapType;
42  MapType id_map_;
43
44  DISALLOW_COPY_AND_ASSIGN(IdManager);
45};
46
47}  // namespace gles2
48}  // namespace gpu
49
50#endif  // GPU_COMMAND_BUFFER_SERVICE_ID_MANAGER_H_
51
52