Index: gpu/command_buffer/common/id_allocator.h |
=================================================================== |
--- gpu/command_buffer/common/id_allocator.h (revision 95161) |
+++ gpu/command_buffer/common/id_allocator.h (working copy) |
@@ -11,6 +11,10 @@ |
#include <utility> |
#include "../common/types.h" |
+// TODO(apatrick): Having regular GL flush semantics on the client side, it |
+// probably isn't necessary to round trip to the service to allocate IDs. |
+// Retire this code. |
+ |
namespace gpu { |
// A resource ID, key to the resource maps. |
@@ -18,28 +22,40 @@ |
// Invalid resource ID. |
static const ResourceId kInvalidResource = 0u; |
-// A class to manage the allocation of resource IDs. |
-class IdAllocator { |
+class IdAllocatorInterface { |
public: |
- IdAllocator(); |
- ~IdAllocator(); |
+ virtual ~IdAllocatorInterface(); |
// Allocates a new resource ID. |
- ResourceId AllocateID(); |
+ virtual ResourceId AllocateID() = 0; |
// Allocates an Id starting at or above desired_id. |
// Note: may wrap if it starts near limit. |
- ResourceId AllocateIDAtOrAbove(ResourceId desired_id); |
+ virtual ResourceId AllocateIDAtOrAbove(ResourceId desired_id) = 0; |
// Marks an id as used. Returns false if id was already used. |
- bool MarkAsUsed(ResourceId id); |
+ virtual bool MarkAsUsed(ResourceId id) = 0; |
// Frees a resource ID. |
- void FreeID(ResourceId id); |
+ virtual void FreeID(ResourceId id) = 0; |
// Checks whether or not a resource ID is in use. |
- bool InUse(ResourceId id) const; |
+ virtual bool InUse(ResourceId id) const = 0; |
+}; |
+// A class to manage the allocation of resource IDs. |
+class IdAllocator : public IdAllocatorInterface { |
+ public: |
+ IdAllocator(); |
+ virtual ~IdAllocator(); |
+ |
+ // Implement IdAllocatorInterface. |
+ virtual ResourceId AllocateID(); |
+ virtual ResourceId AllocateIDAtOrAbove(ResourceId desired_id); |
+ virtual bool MarkAsUsed(ResourceId id); |
+ virtual void FreeID(ResourceId id); |
+ virtual bool InUse(ResourceId id) const; |
+ |
private: |
// TODO(gman): This would work much better with ranges or a hash table. |
typedef std::set<ResourceId> ResourceIdSet; |
@@ -56,6 +72,28 @@ |
DISALLOW_COPY_AND_ASSIGN(IdAllocator); |
}; |
+// A class to manage the allocation of resource IDs that are never reused. This |
+// implementation does not track which IDs are currently used. It is usedul for |
jamesr
2011/08/03 21:51:20
typo: usedul -> useful
|
+// shared and programs which cannot be implicitly created by binding a |
+// previously unused ID. |
+class NonReusedIdAllocator : public IdAllocatorInterface { |
+ public: |
+ NonReusedIdAllocator(); |
+ virtual ~NonReusedIdAllocator(); |
+ |
+ // Implement IdAllocatorInterface. |
+ virtual ResourceId AllocateID(); |
+ virtual ResourceId AllocateIDAtOrAbove(ResourceId desired_id); |
+ virtual bool MarkAsUsed(ResourceId id); |
+ virtual void FreeID(ResourceId id); |
+ virtual bool InUse(ResourceId id) const; |
+ |
+ private: |
+ ResourceId last_id_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(NonReusedIdAllocator); |
+}; |
+ |
} // namespace gpu |
#endif // GPU_COMMAND_BUFFER_CLIENT_ID_ALLOCATOR_H_ |