Handle account removal correctly on all platforms.
[chromium-blink-merge.git] / gpu / command_buffer / client / buffer_tracker.h
blob33bd94b04561b74640f81579987f741c45a9b254
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.
5 #ifndef GPU_COMMAND_BUFFER_CLIENT_BUFFER_TRACKER_H_
6 #define GPU_COMMAND_BUFFER_CLIENT_BUFFER_TRACKER_H_
8 #include <GLES2/gl2.h>
10 #include <queue>
11 #include "base/containers/hash_tables.h"
12 #include "gles2_impl_export.h"
13 #include "gpu/command_buffer/common/gles2_cmd_format.h"
15 namespace gpu {
17 class CommandBufferHelper;
18 class MappedMemoryManager;
20 namespace gles2 {
22 // Tracks buffer objects for client side of command buffer.
23 class GLES2_IMPL_EXPORT BufferTracker {
24 public:
25 class GLES2_IMPL_EXPORT Buffer {
26 public:
27 Buffer(GLuint id,
28 unsigned int size,
29 int32 shm_id,
30 uint32 shm_offset,
31 void* address)
32 : id_(id),
33 size_(size),
34 shm_id_(shm_id),
35 shm_offset_(shm_offset),
36 address_(address),
37 mapped_(false),
38 last_usage_token_(0),
39 last_async_upload_token_(0) {
42 GLenum id() const {
43 return id_;
46 unsigned int size() const {
47 return size_;
50 int32 shm_id() const {
51 return shm_id_;
54 uint32 shm_offset() const {
55 return shm_offset_;
58 void* address() const {
59 return address_;
62 void set_mapped(bool mapped) {
63 mapped_ = mapped;
66 bool mapped() const {
67 return mapped_;
70 void set_last_usage_token(int token) {
71 last_usage_token_ = token;
74 int last_usage_token() const {
75 return last_usage_token_;
78 void set_last_async_upload_token(uint32 async_token) {
79 last_async_upload_token_ = async_token;
82 GLuint last_async_upload_token() const {
83 return last_async_upload_token_;
86 private:
87 friend class BufferTracker;
88 friend class BufferTrackerTest;
90 GLuint id_;
91 unsigned int size_;
92 int32 shm_id_;
93 uint32 shm_offset_;
94 void* address_;
95 bool mapped_;
96 int32 last_usage_token_;
97 GLuint last_async_upload_token_;
100 BufferTracker(MappedMemoryManager* manager);
101 ~BufferTracker();
103 Buffer* CreateBuffer(GLuint id, GLsizeiptr size);
104 Buffer* GetBuffer(GLuint id);
105 void RemoveBuffer(GLuint id);
107 // Frees the block of memory associated with buffer, pending the passage
108 // of a token.
109 void FreePendingToken(Buffer* buffer, int32 token);
110 void Unmanage(Buffer* buffer);
111 void Free(Buffer* buffer);
113 private:
114 typedef base::hash_map<GLuint, Buffer*> BufferMap;
116 MappedMemoryManager* mapped_memory_;
117 BufferMap buffers_;
119 DISALLOW_COPY_AND_ASSIGN(BufferTracker);
122 } // namespace gles2
123 } // namespace gpu
125 #endif // GPU_COMMAND_BUFFER_CLIENT_BUFFER_TRACKER_H_