| OLD | NEW |
| 1 // Copyright (c) 2011 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 <set> | 10 #include <set> |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 | 14 |
| 15 #include "../../gpu_export.h" |
| 15 #include "../common/types.h" | 16 #include "../common/types.h" |
| 16 | 17 |
| 17 namespace gpu { | 18 namespace gpu { |
| 18 | 19 |
| 19 // A resource ID, key to the resource maps. | 20 // A resource ID, key to the resource maps. |
| 20 typedef uint32 ResourceId; | 21 typedef uint32 ResourceId; |
| 21 // Invalid resource ID. | 22 // Invalid resource ID. |
| 22 static const ResourceId kInvalidResource = 0u; | 23 static const ResourceId kInvalidResource = 0u; |
| 23 | 24 |
| 24 class IdAllocatorInterface { | 25 class GPU_EXPORT IdAllocatorInterface { |
| 25 public: | 26 public: |
| 26 virtual ~IdAllocatorInterface(); | 27 virtual ~IdAllocatorInterface(); |
| 27 | 28 |
| 28 // Allocates a new resource ID. | 29 // Allocates a new resource ID. |
| 29 virtual ResourceId AllocateID() = 0; | 30 virtual ResourceId AllocateID() = 0; |
| 30 | 31 |
| 31 // Allocates an Id starting at or above desired_id. | 32 // Allocates an Id starting at or above desired_id. |
| 32 // Note: may wrap if it starts near limit. | 33 // Note: may wrap if it starts near limit. |
| 33 virtual ResourceId AllocateIDAtOrAbove(ResourceId desired_id) = 0; | 34 virtual ResourceId AllocateIDAtOrAbove(ResourceId desired_id) = 0; |
| 34 | 35 |
| 35 // Marks an id as used. Returns false if id was already used. | 36 // Marks an id as used. Returns false if id was already used. |
| 36 virtual bool MarkAsUsed(ResourceId id) = 0; | 37 virtual bool MarkAsUsed(ResourceId id) = 0; |
| 37 | 38 |
| 38 // Frees a resource ID. | 39 // Frees a resource ID. |
| 39 virtual void FreeID(ResourceId id) = 0; | 40 virtual void FreeID(ResourceId id) = 0; |
| 40 | 41 |
| 41 // Checks whether or not a resource ID is in use. | 42 // Checks whether or not a resource ID is in use. |
| 42 virtual bool InUse(ResourceId id) const = 0; | 43 virtual bool InUse(ResourceId id) const = 0; |
| 43 }; | 44 }; |
| 44 | 45 |
| 45 // A class to manage the allocation of resource IDs. | 46 // A class to manage the allocation of resource IDs. |
| 46 class IdAllocator : public IdAllocatorInterface { | 47 class GPU_EXPORT IdAllocator : public IdAllocatorInterface { |
| 47 public: | 48 public: |
| 48 IdAllocator(); | 49 IdAllocator(); |
| 49 virtual ~IdAllocator(); | 50 virtual ~IdAllocator(); |
| 50 | 51 |
| 51 // Implement IdAllocatorInterface. | 52 // Implement IdAllocatorInterface. |
| 52 virtual ResourceId AllocateID() OVERRIDE; | 53 virtual ResourceId AllocateID() OVERRIDE; |
| 53 virtual ResourceId AllocateIDAtOrAbove(ResourceId desired_id) OVERRIDE; | 54 virtual ResourceId AllocateIDAtOrAbove(ResourceId desired_id) OVERRIDE; |
| 54 virtual bool MarkAsUsed(ResourceId id) OVERRIDE; | 55 virtual bool MarkAsUsed(ResourceId id) OVERRIDE; |
| 55 virtual void FreeID(ResourceId id) OVERRIDE; | 56 virtual void FreeID(ResourceId id) OVERRIDE; |
| 56 virtual bool InUse(ResourceId id) const OVERRIDE; | 57 virtual bool InUse(ResourceId id) const OVERRIDE; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 | 90 |
| 90 private: | 91 private: |
| 91 ResourceId last_id_; | 92 ResourceId last_id_; |
| 92 | 93 |
| 93 DISALLOW_COPY_AND_ASSIGN(NonReusedIdAllocator); | 94 DISALLOW_COPY_AND_ASSIGN(NonReusedIdAllocator); |
| 94 }; | 95 }; |
| 95 | 96 |
| 96 } // namespace gpu | 97 } // namespace gpu |
| 97 | 98 |
| 98 #endif // GPU_COMMAND_BUFFER_CLIENT_ID_ALLOCATOR_H_ | 99 #endif // GPU_COMMAND_BUFFER_CLIENT_ID_ALLOCATOR_H_ |
| OLD | NEW |