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_CLIENT_BUFFER_TRACKER_H_ 6 #define GPU_COMMAND_BUFFER_CLIENT_BUFFER_TRACKER_H_ 7 8 #include <GLES2/gl2.h> 9 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" 14 15 namespace gpu { 16 17 class CommandBufferHelper; 18 class MappedMemoryManager; 19 20 namespace gles2 { 21 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 transfer_ready_token_(0) { 39 } 40 41 GLenum id() const { 42 return id_; 43 } 44 45 unsigned int size() const { 46 return size_; 47 } 48 49 int32 shm_id() const { 50 return shm_id_; 51 } 52 53 uint32 shm_offset() const { 54 return shm_offset_; 55 } 56 57 void* address() const { 58 return address_; 59 } 60 61 void set_mapped(bool mapped) { 62 mapped_ = mapped; 63 } 64 65 bool mapped() const { 66 return mapped_; 67 } 68 69 void set_transfer_ready_token(int token) { 70 transfer_ready_token_ = token; 71 } 72 73 uint32 transfer_ready_token() const { 74 return transfer_ready_token_; 75 } 76 77 private: 78 friend class BufferTracker; 79 friend class BufferTrackerTest; 80 81 GLuint id_; 82 unsigned int size_; 83 int32 shm_id_; 84 uint32 shm_offset_; 85 void* address_; 86 bool mapped_; 87 int32 transfer_ready_token_; 88 }; 89 90 BufferTracker(MappedMemoryManager* manager); 91 ~BufferTracker(); 92 93 Buffer* CreateBuffer(GLuint id, GLsizeiptr size); 94 Buffer* GetBuffer(GLuint id); 95 void RemoveBuffer(GLuint id); 96 97 // Frees the block of memory associated with buffer, pending the passage 98 // of a token. 99 void FreePendingToken(Buffer*, int32 token); 100 101 private: 102 typedef base::hash_map<GLuint, Buffer*> BufferMap; 103 104 MappedMemoryManager* mapped_memory_; 105 BufferMap buffers_; 106 107 DISALLOW_COPY_AND_ASSIGN(BufferTracker); 108 }; 109 110 } // namespace gles2 111 } // namespace gpu 112 113 #endif // GPU_COMMAND_BUFFER_CLIENT_BUFFER_TRACKER_H_ 114