| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <set> | 10 #include <set> |
| 11 #include <utility> | 11 #include <utility> |
| 12 |
| 13 #include "base/compiler_specific.h" |
| 14 |
| 12 #include "../common/types.h" | 15 #include "../common/types.h" |
| 13 | 16 |
| 14 namespace gpu { | 17 namespace gpu { |
| 15 | 18 |
| 16 // A resource ID, key to the resource maps. | 19 // A resource ID, key to the resource maps. |
| 17 typedef uint32 ResourceId; | 20 typedef uint32 ResourceId; |
| 18 // Invalid resource ID. | 21 // Invalid resource ID. |
| 19 static const ResourceId kInvalidResource = 0u; | 22 static const ResourceId kInvalidResource = 0u; |
| 20 | 23 |
| 21 class IdAllocatorInterface { | 24 class IdAllocatorInterface { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 39 virtual bool InUse(ResourceId id) const = 0; | 42 virtual bool InUse(ResourceId id) const = 0; |
| 40 }; | 43 }; |
| 41 | 44 |
| 42 // A class to manage the allocation of resource IDs. | 45 // A class to manage the allocation of resource IDs. |
| 43 class IdAllocator : public IdAllocatorInterface { | 46 class IdAllocator : public IdAllocatorInterface { |
| 44 public: | 47 public: |
| 45 IdAllocator(); | 48 IdAllocator(); |
| 46 virtual ~IdAllocator(); | 49 virtual ~IdAllocator(); |
| 47 | 50 |
| 48 // Implement IdAllocatorInterface. | 51 // Implement IdAllocatorInterface. |
| 49 virtual ResourceId AllocateID(); | 52 virtual ResourceId AllocateID() OVERRIDE; |
| 50 virtual ResourceId AllocateIDAtOrAbove(ResourceId desired_id); | 53 virtual ResourceId AllocateIDAtOrAbove(ResourceId desired_id) OVERRIDE; |
| 51 virtual bool MarkAsUsed(ResourceId id); | 54 virtual bool MarkAsUsed(ResourceId id) OVERRIDE; |
| 52 virtual void FreeID(ResourceId id); | 55 virtual void FreeID(ResourceId id) OVERRIDE; |
| 53 virtual bool InUse(ResourceId id) const; | 56 virtual bool InUse(ResourceId id) const OVERRIDE; |
| 54 | 57 |
| 55 private: | 58 private: |
| 56 // TODO(gman): This would work much better with ranges or a hash table. | 59 // TODO(gman): This would work much better with ranges or a hash table. |
| 57 typedef std::set<ResourceId> ResourceIdSet; | 60 typedef std::set<ResourceId> ResourceIdSet; |
| 58 | 61 |
| 59 // The highest ID on the used list. | 62 // The highest ID on the used list. |
| 60 ResourceId LastUsedId() const; | 63 ResourceId LastUsedId() const; |
| 61 | 64 |
| 62 // Lowest ID that isn't on the used list. This is slow, use as a last resort. | 65 // Lowest ID that isn't on the used list. This is slow, use as a last resort. |
| 63 ResourceId FindFirstUnusedId() const; | 66 ResourceId FindFirstUnusedId() const; |
| 64 | 67 |
| 65 ResourceIdSet used_ids_; | 68 ResourceIdSet used_ids_; |
| 66 ResourceIdSet free_ids_; | 69 ResourceIdSet free_ids_; |
| 67 | 70 |
| 68 DISALLOW_COPY_AND_ASSIGN(IdAllocator); | 71 DISALLOW_COPY_AND_ASSIGN(IdAllocator); |
| 69 }; | 72 }; |
| 70 | 73 |
| 71 // A class to manage the allocation of resource IDs that are never reused. This | 74 // A class to manage the allocation of resource IDs that are never reused. This |
| 72 // implementation does not track which IDs are currently used. It is useful for | 75 // implementation does not track which IDs are currently used. It is useful for |
| 73 // shared and programs which cannot be implicitly created by binding a | 76 // shared and programs which cannot be implicitly created by binding a |
| 74 // previously unused ID. | 77 // previously unused ID. |
| 75 class NonReusedIdAllocator : public IdAllocatorInterface { | 78 class NonReusedIdAllocator : public IdAllocatorInterface { |
| 76 public: | 79 public: |
| 77 NonReusedIdAllocator(); | 80 NonReusedIdAllocator(); |
| 78 virtual ~NonReusedIdAllocator(); | 81 virtual ~NonReusedIdAllocator(); |
| 79 | 82 |
| 80 // Implement IdAllocatorInterface. | 83 // Implement IdAllocatorInterface. |
| 81 virtual ResourceId AllocateID(); | 84 virtual ResourceId AllocateID() OVERRIDE; |
| 82 virtual ResourceId AllocateIDAtOrAbove(ResourceId desired_id); | 85 virtual ResourceId AllocateIDAtOrAbove(ResourceId desired_id) OVERRIDE; |
| 83 virtual bool MarkAsUsed(ResourceId id); | 86 virtual bool MarkAsUsed(ResourceId id) OVERRIDE; |
| 84 virtual void FreeID(ResourceId id); | 87 virtual void FreeID(ResourceId id) OVERRIDE; |
| 85 virtual bool InUse(ResourceId id) const; | 88 virtual bool InUse(ResourceId id) const OVERRIDE; |
| 86 | 89 |
| 87 private: | 90 private: |
| 88 ResourceId last_id_; | 91 ResourceId last_id_; |
| 89 | 92 |
| 90 DISALLOW_COPY_AND_ASSIGN(NonReusedIdAllocator); | 93 DISALLOW_COPY_AND_ASSIGN(NonReusedIdAllocator); |
| 91 }; | 94 }; |
| 92 | 95 |
| 93 } // namespace gpu | 96 } // namespace gpu |
| 94 | 97 |
| 95 #endif // GPU_COMMAND_BUFFER_CLIENT_ID_ALLOCATOR_H_ | 98 #endif // GPU_COMMAND_BUFFER_CLIENT_ID_ALLOCATOR_H_ |
| OLD | NEW |