| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 namespace o3d { | 43 namespace o3d { |
| 44 namespace command_buffer { | 44 namespace command_buffer { |
| 45 | 45 |
| 46 // A class to manage the allocation of resource IDs. It uses a bitfield stored | 46 // A class to manage the allocation of resource IDs. It uses a bitfield stored |
| 47 // into a vector of unsigned ints. | 47 // into a vector of unsigned ints. |
| 48 class IdAllocator { | 48 class IdAllocator { |
| 49 public: | 49 public: |
| 50 IdAllocator(); | 50 IdAllocator(); |
| 51 | 51 |
| 52 // Allocates a new resource ID. | 52 // Allocates a new resource ID. |
| 53 command_buffer::ResourceID AllocateID() { | 53 command_buffer::ResourceId AllocateID() { |
| 54 unsigned int bit = FindFirstFree(); | 54 unsigned int bit = FindFirstFree(); |
| 55 SetBit(bit, true); | 55 SetBit(bit, true); |
| 56 return bit; | 56 return bit; |
| 57 } | 57 } |
| 58 | 58 |
| 59 // Frees a resource ID. | 59 // Frees a resource ID. |
| 60 void FreeID(command_buffer::ResourceID id) { | 60 void FreeID(command_buffer::ResourceId id) { |
| 61 SetBit(id, false); | 61 SetBit(id, false); |
| 62 } | 62 } |
| 63 | 63 |
| 64 // Checks whether or not a resource ID is in use. | 64 // Checks whether or not a resource ID is in use. |
| 65 bool InUse(command_buffer::ResourceID id) { | 65 bool InUse(command_buffer::ResourceId id) { |
| 66 return GetBit(id); | 66 return GetBit(id); |
| 67 } | 67 } |
| 68 private: | 68 private: |
| 69 void SetBit(unsigned int bit, bool value); | 69 void SetBit(unsigned int bit, bool value); |
| 70 bool GetBit(unsigned int bit) const; | 70 bool GetBit(unsigned int bit) const; |
| 71 unsigned int FindFirstFree() const; | 71 unsigned int FindFirstFree() const; |
| 72 | 72 |
| 73 std::vector<Uint32> bitmap_; | 73 std::vector<Uint32> bitmap_; |
| 74 DISALLOW_COPY_AND_ASSIGN(IdAllocator); | 74 DISALLOW_COPY_AND_ASSIGN(IdAllocator); |
| 75 }; | 75 }; |
| 76 | 76 |
| 77 } // namespace command_buffer | 77 } // namespace command_buffer |
| 78 } // namespace o3d | 78 } // namespace o3d |
| 79 | 79 |
| 80 #endif // O3D_COMMAND_BUFFER_CLIENT_CROSS_ID_ALLOCATOR_H_ | 80 #endif // O3D_COMMAND_BUFFER_CLIENT_CROSS_ID_ALLOCATOR_H_ |
| OLD | NEW |