| 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> |
| 11 | 11 |
| 12 #include <set> | 12 #include <map> |
| 13 #include <utility> | 13 #include <utility> |
| 14 | 14 |
| 15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "gpu/gpu_export.h" | 17 #include "gpu/gpu_export.h" |
| 18 | 18 |
| 19 namespace gpu { | 19 namespace gpu { |
| 20 | 20 |
| 21 // A resource ID, key to the resource maps. | 21 // A resource ID, key to the resource maps. |
| 22 typedef uint32_t ResourceId; | 22 typedef uint32_t ResourceId; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 47 // Frees a resource ID. | 47 // Frees a resource ID. |
| 48 void FreeID(ResourceId id); | 48 void FreeID(ResourceId id); |
| 49 | 49 |
| 50 // Frees a |range| amount of contiguous ids, starting from |first_id|. | 50 // Frees a |range| amount of contiguous ids, starting from |first_id|. |
| 51 void FreeIDRange(ResourceId first_id, uint32_t range); | 51 void FreeIDRange(ResourceId first_id, uint32_t range); |
| 52 | 52 |
| 53 // Checks whether or not a resource ID is in use. | 53 // Checks whether or not a resource ID is in use. |
| 54 bool InUse(ResourceId id) const; | 54 bool InUse(ResourceId id) const; |
| 55 | 55 |
| 56 private: | 56 private: |
| 57 // TODO(gman): This would work much better with ranges or a hash table. | 57 struct Node; |
| 58 typedef std::set<ResourceId> ResourceIdSet; | 58 static int GetHeight(Node*); |
| 59 static int GetBalance(Node*); |
| 60 static void UpdateHeight(Node*); |
| 61 static Node* RotateLeft(Node* node); |
| 62 static Node* RotateRight(Node* node); |
| 63 static Node* Balance(Node*); |
| 64 static Node* ReplaceMax(Node* to_replace, Node* max_subtree); |
| 65 static Node* Delete(Node*); |
| 66 static Node* Insert(ResourceId min, ResourceId max, Node* pos); |
| 67 static Node* AddRange(uint32_t range, |
| 68 ResourceId* first_id_out, |
| 69 ResourceId first_id_min, |
| 70 ResourceId first_id_max, |
| 71 Node* pos, |
| 72 Node* left_limit, |
| 73 Node* right_limit); |
| 74 static Node* RemoveRange(ResourceId first_id, ResourceId last_id, Node* pos); |
| 75 static void Destroy(Node* pos); |
| 59 | 76 |
| 60 // The highest ID on the used list. | 77 Node* root_; |
| 61 ResourceId LastUsedId() const; | |
| 62 | |
| 63 // Lowest ID that isn't on the used list. This is slow, use as a last resort. | |
| 64 ResourceId FindFirstUnusedId() const; | |
| 65 | |
| 66 ResourceIdSet used_ids_; | |
| 67 ResourceIdSet free_ids_; | |
| 68 | 78 |
| 69 DISALLOW_COPY_AND_ASSIGN(IdAllocator); | 79 DISALLOW_COPY_AND_ASSIGN(IdAllocator); |
| 70 }; | 80 }; |
| 71 | 81 |
| 72 } // namespace gpu | 82 } // namespace gpu |
| 73 | 83 |
| 74 #endif // GPU_COMMAND_BUFFER_CLIENT_ID_ALLOCATOR_H_ | 84 #endif // GPU_COMMAND_BUFFER_CLIENT_ID_ALLOCATOR_H_ |
| OLD | NEW |