Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / gpu / command_buffer / client / buffer_tracker.h
blobb092b8a6148eb9414b0a6aa7517441e0c7de36a7
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 "base/basictypes.h"
9 #include "base/containers/hash_tables.h"
10 #include "base/macros.h"
11 #include "gles2_impl_export.h"
12 #include "gpu/command_buffer/common/gles2_cmd_format.h"
14 namespace gpu {
16 class MappedMemoryManager;
18 namespace gles2 {
20 // Tracks buffer objects for client side of command buffer.
21 class GLES2_IMPL_EXPORT BufferTracker {
22 public:
23 class GLES2_IMPL_EXPORT Buffer {
24 public:
25 Buffer(GLuint id,
26 unsigned int size,
27 int32 shm_id,
28 uint32 shm_offset,
29 void* address)
30 : id_(id),
31 size_(size),
32 shm_id_(shm_id),
33 shm_offset_(shm_offset),
34 address_(address),
35 mapped_(false),
36 last_usage_token_(0),
37 last_async_upload_token_(0) {
40 GLenum id() const {
41 return id_;
44 unsigned int size() const {
45 return size_;
48 int32 shm_id() const {
49 return shm_id_;
52 uint32 shm_offset() const {
53 return shm_offset_;
56 void* address() const {
57 return address_;
60 void set_mapped(bool mapped) {
61 mapped_ = mapped;
64 bool mapped() const {
65 return mapped_;
68 void set_last_usage_token(int token) {
69 last_usage_token_ = token;
72 int last_usage_token() const {
73 return last_usage_token_;
76 void set_last_async_upload_token(uint32 async_token) {
77 last_async_upload_token_ = async_token;
80 GLuint last_async_upload_token() const {
81 return last_async_upload_token_;
84 private:
85 friend class BufferTracker;
86 friend class BufferTrackerTest;
88 GLuint id_;
89 unsigned int size_;
90 int32 shm_id_;
91 uint32 shm_offset_;
92 void* address_;
93 bool mapped_;
94 int32 last_usage_token_;
95 GLuint last_async_upload_token_;
98 BufferTracker(MappedMemoryManager* manager);
99 ~BufferTracker();
101 Buffer* CreateBuffer(GLuint id, GLsizeiptr size);
102 Buffer* GetBuffer(GLuint id);
103 void RemoveBuffer(GLuint id);
105 // Frees the block of memory associated with buffer, pending the passage
106 // of a token.
107 void FreePendingToken(Buffer* buffer, int32 token);
108 void Unmanage(Buffer* buffer);
109 void Free(Buffer* buffer);
111 private:
112 typedef base::hash_map<GLuint, Buffer*> BufferMap;
114 MappedMemoryManager* mapped_memory_;
115 BufferMap buffers_;
117 DISALLOW_COPY_AND_ASSIGN(BufferTracker);
120 } // namespace gles2
121 } // namespace gpu
123 #endif // GPU_COMMAND_BUFFER_CLIENT_BUFFER_TRACKER_H_