| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2009, Google Inc. | 2 * Copyright 2009, Google Inc. |
| 3 * All rights reserved. | 3 * All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 */ | 30 */ |
| 31 | 31 |
| 32 | 32 |
| 33 // This file contains the definition of the IdAllocator class. | 33 // This file contains the definition of the IdAllocator class. |
| 34 | 34 |
| 35 #ifndef GPU_COMMAND_BUFFER_CLIENT_CROSS_ID_ALLOCATOR_H_ | 35 #ifndef GPU_COMMAND_BUFFER_CLIENT_ID_ALLOCATOR_H_ |
| 36 #define GPU_COMMAND_BUFFER_CLIENT_CROSS_ID_ALLOCATOR_H_ | 36 #define GPU_COMMAND_BUFFER_CLIENT_ID_ALLOCATOR_H_ |
| 37 | 37 |
| 38 #include <vector> | 38 #include <vector> |
| 39 #include "base/basictypes.h" | 39 #include "base/basictypes.h" |
| 40 #include "gpu/command_buffer/common/types.h" | 40 #include "gpu/command_buffer/common/types.h" |
| 41 #include "gpu/command_buffer/common/resource.h" | 41 #include "gpu/command_buffer/common/resource.h" |
| 42 | 42 |
| 43 namespace command_buffer { | 43 namespace gpu { |
| 44 | 44 |
| 45 // A class to manage the allocation of resource IDs. It uses a bitfield stored | 45 // A class to manage the allocation of resource IDs. It uses a bitfield stored |
| 46 // into a vector of unsigned ints. | 46 // into a vector of unsigned ints. |
| 47 class IdAllocator { | 47 class IdAllocator { |
| 48 public: | 48 public: |
| 49 IdAllocator(); | 49 IdAllocator(); |
| 50 | 50 |
| 51 // Allocates a new resource ID. | 51 // Allocates a new resource ID. |
| 52 command_buffer::ResourceId AllocateID() { | 52 gpu::ResourceId AllocateID() { |
| 53 unsigned int bit = FindFirstFree(); | 53 unsigned int bit = FindFirstFree(); |
| 54 SetBit(bit, true); | 54 SetBit(bit, true); |
| 55 return bit; | 55 return bit; |
| 56 } | 56 } |
| 57 | 57 |
| 58 // Frees a resource ID. | 58 // Frees a resource ID. |
| 59 void FreeID(command_buffer::ResourceId id) { | 59 void FreeID(gpu::ResourceId id) { |
| 60 SetBit(id, false); | 60 SetBit(id, false); |
| 61 } | 61 } |
| 62 | 62 |
| 63 // Checks whether or not a resource ID is in use. | 63 // Checks whether or not a resource ID is in use. |
| 64 bool InUse(command_buffer::ResourceId id) { | 64 bool InUse(gpu::ResourceId id) { |
| 65 return GetBit(id); | 65 return GetBit(id); |
| 66 } | 66 } |
| 67 private: | 67 private: |
| 68 void SetBit(unsigned int bit, bool value); | 68 void SetBit(unsigned int bit, bool value); |
| 69 bool GetBit(unsigned int bit) const; | 69 bool GetBit(unsigned int bit) const; |
| 70 unsigned int FindFirstFree() const; | 70 unsigned int FindFirstFree() const; |
| 71 | 71 |
| 72 std::vector<Uint32> bitmap_; | 72 std::vector<Uint32> bitmap_; |
| 73 DISALLOW_COPY_AND_ASSIGN(IdAllocator); | 73 DISALLOW_COPY_AND_ASSIGN(IdAllocator); |
| 74 }; | 74 }; |
| 75 | 75 |
| 76 } // namespace command_buffer | 76 } // namespace gpu |
| 77 | 77 |
| 78 #endif // GPU_COMMAND_BUFFER_CLIENT_CROSS_ID_ALLOCATOR_H_ | 78 #endif // GPU_COMMAND_BUFFER_CLIENT_ID_ALLOCATOR_H_ |
| OLD | NEW |