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 IdAllocator class. | 5 // This file contains the definition of the IdAllocator class. |
6 | 6 |
7 #ifndef GPU_COMMAND_BUFFER_CLIENT_ID_ALLOCATOR_H_ | 7 #ifndef GPU_COMMAND_BUFFER_CLIENT_ID_ALLOCATOR_H_ |
8 #define GPU_COMMAND_BUFFER_CLIENT_ID_ALLOCATOR_H_ | 8 #define GPU_COMMAND_BUFFER_CLIENT_ID_ALLOCATOR_H_ |
9 | 9 |
10 #include <stdint.h> | 10 #include <stdint.h> |
(...skipping 18 matching lines...) Expand all Loading... |
29 IdAllocator(); | 29 IdAllocator(); |
30 ~IdAllocator(); | 30 ~IdAllocator(); |
31 | 31 |
32 // Allocates a new resource ID. | 32 // Allocates a new resource ID. |
33 ResourceId AllocateID(); | 33 ResourceId AllocateID(); |
34 | 34 |
35 // Allocates an Id starting at or above desired_id. | 35 // Allocates an Id starting at or above desired_id. |
36 // Note: may wrap if it starts near limit. | 36 // Note: may wrap if it starts near limit. |
37 ResourceId AllocateIDAtOrAbove(ResourceId desired_id); | 37 ResourceId AllocateIDAtOrAbove(ResourceId desired_id); |
38 | 38 |
| 39 // Allocates |range| amount of contiguous ids. |
| 40 // Returns the first id to |first_id| or |kInvalidResource| if |
| 41 // allocation failed. |
| 42 ResourceId AllocateIDRange(uint32_t range); |
| 43 |
39 // Marks an id as used. Returns false if id was already used. | 44 // Marks an id as used. Returns false if id was already used. |
40 bool MarkAsUsed(ResourceId id); | 45 bool MarkAsUsed(ResourceId id); |
41 | 46 |
42 // Frees a resource ID. | 47 // Frees a resource ID. |
43 void FreeID(ResourceId id); | 48 void FreeID(ResourceId id); |
44 | 49 |
| 50 // Frees a |range| amount of contiguous ids, starting from |first_id|. |
| 51 void FreeIDRange(ResourceId first_id, uint32_t range); |
| 52 |
45 // Checks whether or not a resource ID is in use. | 53 // Checks whether or not a resource ID is in use. |
46 bool InUse(ResourceId id) const; | 54 bool InUse(ResourceId id) const; |
47 | 55 |
48 private: | 56 private: |
49 // TODO(gman): This would work much better with ranges or a hash table. | 57 // TODO(gman): This would work much better with ranges or a hash table. |
50 typedef std::set<ResourceId> ResourceIdSet; | 58 typedef std::set<ResourceId> ResourceIdSet; |
51 | 59 |
52 // The highest ID on the used list. | 60 // The highest ID on the used list. |
53 ResourceId LastUsedId() const; | 61 ResourceId LastUsedId() const; |
54 | 62 |
55 // Lowest ID that isn't on the used list. This is slow, use as a last resort. | 63 // Lowest ID that isn't on the used list. This is slow, use as a last resort. |
56 ResourceId FindFirstUnusedId() const; | 64 ResourceId FindFirstUnusedId() const; |
57 | 65 |
58 ResourceIdSet used_ids_; | 66 ResourceIdSet used_ids_; |
59 ResourceIdSet free_ids_; | 67 ResourceIdSet free_ids_; |
60 | 68 |
61 DISALLOW_COPY_AND_ASSIGN(IdAllocator); | 69 DISALLOW_COPY_AND_ASSIGN(IdAllocator); |
62 }; | 70 }; |
63 | 71 |
64 } // namespace gpu | 72 } // namespace gpu |
65 | 73 |
66 #endif // GPU_COMMAND_BUFFER_CLIENT_ID_ALLOCATOR_H_ | 74 #endif // GPU_COMMAND_BUFFER_CLIENT_ID_ALLOCATOR_H_ |
OLD | NEW |