| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef GPU_COMMAND_BUFFER_CLIENT_BUFFER_TRACKER_H_ | 5 #ifndef GPU_COMMAND_BUFFER_CLIENT_BUFFER_TRACKER_H_ |
| 6 #define GPU_COMMAND_BUFFER_CLIENT_BUFFER_TRACKER_H_ | 6 #define GPU_COMMAND_BUFFER_CLIENT_BUFFER_TRACKER_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include <stdint.h> |
| 9 |
| 9 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
| 10 #include "base/macros.h" | 11 #include "base/macros.h" |
| 11 #include "gles2_impl_export.h" | 12 #include "gles2_impl_export.h" |
| 12 #include "gpu/command_buffer/common/gles2_cmd_format.h" | 13 #include "gpu/command_buffer/common/gles2_cmd_format.h" |
| 13 | 14 |
| 14 namespace gpu { | 15 namespace gpu { |
| 15 | 16 |
| 16 class MappedMemoryManager; | 17 class MappedMemoryManager; |
| 17 | 18 |
| 18 namespace gles2 { | 19 namespace gles2 { |
| 19 | 20 |
| 20 // Tracks buffer objects for client side of command buffer. | 21 // Tracks buffer objects for client side of command buffer. |
| 21 class GLES2_IMPL_EXPORT BufferTracker { | 22 class GLES2_IMPL_EXPORT BufferTracker { |
| 22 public: | 23 public: |
| 23 class GLES2_IMPL_EXPORT Buffer { | 24 class GLES2_IMPL_EXPORT Buffer { |
| 24 public: | 25 public: |
| 25 Buffer(GLuint id, | 26 Buffer(GLuint id, |
| 26 unsigned int size, | 27 unsigned int size, |
| 27 int32 shm_id, | 28 int32_t shm_id, |
| 28 uint32 shm_offset, | 29 uint32_t shm_offset, |
| 29 void* address) | 30 void* address) |
| 30 : id_(id), | 31 : id_(id), |
| 31 size_(size), | 32 size_(size), |
| 32 shm_id_(shm_id), | 33 shm_id_(shm_id), |
| 33 shm_offset_(shm_offset), | 34 shm_offset_(shm_offset), |
| 34 address_(address), | 35 address_(address), |
| 35 mapped_(false), | 36 mapped_(false), |
| 36 last_usage_token_(0), | 37 last_usage_token_(0), |
| 37 last_async_upload_token_(0) { | 38 last_async_upload_token_(0) {} |
| 38 } | |
| 39 | 39 |
| 40 GLenum id() const { | 40 GLenum id() const { |
| 41 return id_; | 41 return id_; |
| 42 } | 42 } |
| 43 | 43 |
| 44 unsigned int size() const { | 44 unsigned int size() const { |
| 45 return size_; | 45 return size_; |
| 46 } | 46 } |
| 47 | 47 |
| 48 int32 shm_id() const { | 48 int32_t shm_id() const { return shm_id_; } |
| 49 return shm_id_; | |
| 50 } | |
| 51 | 49 |
| 52 uint32 shm_offset() const { | 50 uint32_t shm_offset() const { return shm_offset_; } |
| 53 return shm_offset_; | |
| 54 } | |
| 55 | 51 |
| 56 void* address() const { | 52 void* address() const { |
| 57 return address_; | 53 return address_; |
| 58 } | 54 } |
| 59 | 55 |
| 60 void set_mapped(bool mapped) { | 56 void set_mapped(bool mapped) { |
| 61 mapped_ = mapped; | 57 mapped_ = mapped; |
| 62 } | 58 } |
| 63 | 59 |
| 64 bool mapped() const { | 60 bool mapped() const { |
| 65 return mapped_; | 61 return mapped_; |
| 66 } | 62 } |
| 67 | 63 |
| 68 void set_last_usage_token(int token) { | 64 void set_last_usage_token(int token) { |
| 69 last_usage_token_ = token; | 65 last_usage_token_ = token; |
| 70 } | 66 } |
| 71 | 67 |
| 72 int last_usage_token() const { | 68 int last_usage_token() const { |
| 73 return last_usage_token_; | 69 return last_usage_token_; |
| 74 } | 70 } |
| 75 | 71 |
| 76 void set_last_async_upload_token(uint32 async_token) { | 72 void set_last_async_upload_token(uint32_t async_token) { |
| 77 last_async_upload_token_ = async_token; | 73 last_async_upload_token_ = async_token; |
| 78 } | 74 } |
| 79 | 75 |
| 80 GLuint last_async_upload_token() const { | 76 GLuint last_async_upload_token() const { |
| 81 return last_async_upload_token_; | 77 return last_async_upload_token_; |
| 82 } | 78 } |
| 83 | 79 |
| 84 private: | 80 private: |
| 85 friend class BufferTracker; | 81 friend class BufferTracker; |
| 86 friend class BufferTrackerTest; | 82 friend class BufferTrackerTest; |
| 87 | 83 |
| 88 GLuint id_; | 84 GLuint id_; |
| 89 unsigned int size_; | 85 unsigned int size_; |
| 90 int32 shm_id_; | 86 int32_t shm_id_; |
| 91 uint32 shm_offset_; | 87 uint32_t shm_offset_; |
| 92 void* address_; | 88 void* address_; |
| 93 bool mapped_; | 89 bool mapped_; |
| 94 int32 last_usage_token_; | 90 int32_t last_usage_token_; |
| 95 GLuint last_async_upload_token_; | 91 GLuint last_async_upload_token_; |
| 96 }; | 92 }; |
| 97 | 93 |
| 98 BufferTracker(MappedMemoryManager* manager); | 94 BufferTracker(MappedMemoryManager* manager); |
| 99 ~BufferTracker(); | 95 ~BufferTracker(); |
| 100 | 96 |
| 101 Buffer* CreateBuffer(GLuint id, GLsizeiptr size); | 97 Buffer* CreateBuffer(GLuint id, GLsizeiptr size); |
| 102 Buffer* GetBuffer(GLuint id); | 98 Buffer* GetBuffer(GLuint id); |
| 103 void RemoveBuffer(GLuint id); | 99 void RemoveBuffer(GLuint id); |
| 104 | 100 |
| 105 // Frees the block of memory associated with buffer, pending the passage | 101 // Frees the block of memory associated with buffer, pending the passage |
| 106 // of a token. | 102 // of a token. |
| 107 void FreePendingToken(Buffer* buffer, int32 token); | 103 void FreePendingToken(Buffer* buffer, int32_t token); |
| 108 void Unmanage(Buffer* buffer); | 104 void Unmanage(Buffer* buffer); |
| 109 void Free(Buffer* buffer); | 105 void Free(Buffer* buffer); |
| 110 | 106 |
| 111 private: | 107 private: |
| 112 typedef base::hash_map<GLuint, Buffer*> BufferMap; | 108 typedef base::hash_map<GLuint, Buffer*> BufferMap; |
| 113 | 109 |
| 114 MappedMemoryManager* mapped_memory_; | 110 MappedMemoryManager* mapped_memory_; |
| 115 BufferMap buffers_; | 111 BufferMap buffers_; |
| 116 | 112 |
| 117 DISALLOW_COPY_AND_ASSIGN(BufferTracker); | 113 DISALLOW_COPY_AND_ASSIGN(BufferTracker); |
| 118 }; | 114 }; |
| 119 | 115 |
| 120 } // namespace gles2 | 116 } // namespace gles2 |
| 121 } // namespace gpu | 117 } // namespace gpu |
| 122 | 118 |
| 123 #endif // GPU_COMMAND_BUFFER_CLIENT_BUFFER_TRACKER_H_ | 119 #endif // GPU_COMMAND_BUFFER_CLIENT_BUFFER_TRACKER_H_ |
| OLD | NEW |