| 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 // This file contains the definition of the FencedAllocator class. | 5 // This file contains the definition of the FencedAllocator class. | 
| 6 | 6 | 
| 7 #ifndef GPU_COMMAND_BUFFER_CLIENT_FENCED_ALLOCATOR_H_ | 7 #ifndef GPU_COMMAND_BUFFER_CLIENT_FENCED_ALLOCATOR_H_ | 
| 8 #define GPU_COMMAND_BUFFER_CLIENT_FENCED_ALLOCATOR_H_ | 8 #define GPU_COMMAND_BUFFER_CLIENT_FENCED_ALLOCATOR_H_ | 
| 9 | 9 | 
| 10 #include <vector> | 10 #include <vector> | 
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 76   // block. | 76   // block. | 
| 77   unsigned int GetLargestFreeOrPendingSize(); | 77   unsigned int GetLargestFreeOrPendingSize(); | 
| 78 | 78 | 
| 79   // Checks for consistency inside the book-keeping structures. Used for | 79   // Checks for consistency inside the book-keeping structures. Used for | 
| 80   // testing. | 80   // testing. | 
| 81   bool CheckConsistency(); | 81   bool CheckConsistency(); | 
| 82 | 82 | 
| 83   // True if any memory is allocated. | 83   // True if any memory is allocated. | 
| 84   bool InUse(); | 84   bool InUse(); | 
| 85 | 85 | 
|  | 86   // Return bytes of memory that is IN_USE | 
|  | 87   size_t bytes_in_use() const { return bytes_in_use_; } | 
|  | 88 | 
| 86  private: | 89  private: | 
| 87   // Status of a block of memory, for book-keeping. | 90   // Status of a block of memory, for book-keeping. | 
| 88   enum State { | 91   enum State { | 
| 89     IN_USE, | 92     IN_USE, | 
| 90     FREE, | 93     FREE, | 
| 91     FREE_PENDING_TOKEN | 94     FREE_PENDING_TOKEN | 
| 92   }; | 95   }; | 
| 93 | 96 | 
| 94   // Book-keeping sturcture that describes a block of memory. | 97   // Book-keeping sturcture that describes a block of memory. | 
| 95   struct Block { | 98   struct Block { | 
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 127 | 130 | 
| 128   // Allocates a block of memory inside a given block, splitting it in two | 131   // Allocates a block of memory inside a given block, splitting it in two | 
| 129   // (unless that block is of the exact requested size). | 132   // (unless that block is of the exact requested size). | 
| 130   // NOTE: this will invalidate block indices. | 133   // NOTE: this will invalidate block indices. | 
| 131   // Returns the offset of the allocated block (NOTE: this is different from | 134   // Returns the offset of the allocated block (NOTE: this is different from | 
| 132   // the other functions that return a block index). | 135   // the other functions that return a block index). | 
| 133   Offset AllocInBlock(BlockIndex index, unsigned int size); | 136   Offset AllocInBlock(BlockIndex index, unsigned int size); | 
| 134 | 137 | 
| 135   CommandBufferHelper *helper_; | 138   CommandBufferHelper *helper_; | 
| 136   Container blocks_; | 139   Container blocks_; | 
|  | 140   size_t bytes_in_use_; | 
| 137 | 141 | 
| 138   DISALLOW_IMPLICIT_CONSTRUCTORS(FencedAllocator); | 142   DISALLOW_IMPLICIT_CONSTRUCTORS(FencedAllocator); | 
| 139 }; | 143 }; | 
| 140 | 144 | 
| 141 // This class functions just like FencedAllocator, but its API uses pointers | 145 // This class functions just like FencedAllocator, but its API uses pointers | 
| 142 // instead of offsets. | 146 // instead of offsets. | 
| 143 class FencedAllocatorWrapper { | 147 class FencedAllocatorWrapper { | 
| 144  public: | 148  public: | 
| 145   FencedAllocatorWrapper(unsigned int size, | 149   FencedAllocatorWrapper(unsigned int size, | 
| 146                          CommandBufferHelper* helper, | 150                          CommandBufferHelper* helper, | 
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 236     return allocator_.CheckConsistency(); | 240     return allocator_.CheckConsistency(); | 
| 237   } | 241   } | 
| 238 | 242 | 
| 239   // True if any memory is allocated. | 243   // True if any memory is allocated. | 
| 240   bool InUse() { | 244   bool InUse() { | 
| 241     return allocator_.InUse(); | 245     return allocator_.InUse(); | 
| 242   } | 246   } | 
| 243 | 247 | 
| 244   FencedAllocator &allocator() { return allocator_; } | 248   FencedAllocator &allocator() { return allocator_; } | 
| 245 | 249 | 
|  | 250   size_t bytes_in_use() const { return allocator_.bytes_in_use(); } | 
|  | 251 | 
| 246  private: | 252  private: | 
| 247   FencedAllocator allocator_; | 253   FencedAllocator allocator_; | 
| 248   void* base_; | 254   void* base_; | 
| 249   DISALLOW_IMPLICIT_CONSTRUCTORS(FencedAllocatorWrapper); | 255   DISALLOW_IMPLICIT_CONSTRUCTORS(FencedAllocatorWrapper); | 
| 250 }; | 256 }; | 
| 251 | 257 | 
| 252 }  // namespace gpu | 258 }  // namespace gpu | 
| 253 | 259 | 
| 254 #endif  // GPU_COMMAND_BUFFER_CLIENT_FENCED_ALLOCATOR_H_ | 260 #endif  // GPU_COMMAND_BUFFER_CLIENT_FENCED_ALLOCATOR_H_ | 
| OLD | NEW | 
|---|