Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(469)

Side by Side Diff: gpu/command_buffer/common/id_allocator.h

Issue 7554015: Implemented support for GL constext share groups in the renderer process. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include "../common/types.h" 12 #include "../common/types.h"
13 13
14 // TODO(apatrick): Having regular GL flush semantics on the client side, it
15 // probably isn't necessary to round trip to the service to allocate IDs.
16 // Retire this code.
17
14 namespace gpu { 18 namespace gpu {
15 19
16 // A resource ID, key to the resource maps. 20 // A resource ID, key to the resource maps.
17 typedef uint32 ResourceId; 21 typedef uint32 ResourceId;
18 // Invalid resource ID. 22 // Invalid resource ID.
19 static const ResourceId kInvalidResource = 0u; 23 static const ResourceId kInvalidResource = 0u;
20 24
21 // A class to manage the allocation of resource IDs. 25 class IdAllocatorInterface {
22 class IdAllocator {
23 public: 26 public:
24 IdAllocator(); 27 virtual ~IdAllocatorInterface();
25 ~IdAllocator();
26 28
27 // Allocates a new resource ID. 29 // Allocates a new resource ID.
28 ResourceId AllocateID(); 30 virtual ResourceId AllocateID() = 0;
29 31
30 // Allocates an Id starting at or above desired_id. 32 // Allocates an Id starting at or above desired_id.
31 // Note: may wrap if it starts near limit. 33 // Note: may wrap if it starts near limit.
32 ResourceId AllocateIDAtOrAbove(ResourceId desired_id); 34 virtual ResourceId AllocateIDAtOrAbove(ResourceId desired_id) = 0;
33 35
34 // 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.
35 bool MarkAsUsed(ResourceId id); 37 virtual bool MarkAsUsed(ResourceId id) = 0;
36 38
37 // Frees a resource ID. 39 // Frees a resource ID.
38 void FreeID(ResourceId id); 40 virtual void FreeID(ResourceId id) = 0;
39 41
40 // Checks whether or not a resource ID is in use. 42 // Checks whether or not a resource ID is in use.
41 bool InUse(ResourceId id) const; 43 virtual bool InUse(ResourceId id) const = 0;
44 };
45
46 // A class to manage the allocation of resource IDs.
47 class IdAllocator : public IdAllocatorInterface {
48 public:
49 IdAllocator();
50 virtual ~IdAllocator();
51
52 // Implement IdAllocatorInterface.
53 virtual ResourceId AllocateID();
54 virtual ResourceId AllocateIDAtOrAbove(ResourceId desired_id);
55 virtual bool MarkAsUsed(ResourceId id);
56 virtual void FreeID(ResourceId id);
57 virtual bool InUse(ResourceId id) const;
42 58
43 private: 59 private:
44 // TODO(gman): This would work much better with ranges or a hash table. 60 // TODO(gman): This would work much better with ranges or a hash table.
45 typedef std::set<ResourceId> ResourceIdSet; 61 typedef std::set<ResourceId> ResourceIdSet;
46 62
47 // The highest ID on the used list. 63 // The highest ID on the used list.
48 ResourceId LastUsedId() const; 64 ResourceId LastUsedId() const;
49 65
50 // Lowest ID that isn't on the used list. This is slow, use as a last resort. 66 // Lowest ID that isn't on the used list. This is slow, use as a last resort.
51 ResourceId FindFirstUnusedId() const; 67 ResourceId FindFirstUnusedId() const;
52 68
53 ResourceIdSet used_ids_; 69 ResourceIdSet used_ids_;
54 ResourceIdSet free_ids_; 70 ResourceIdSet free_ids_;
55 71
56 DISALLOW_COPY_AND_ASSIGN(IdAllocator); 72 DISALLOW_COPY_AND_ASSIGN(IdAllocator);
57 }; 73 };
58 74
75 // A class to manage the allocation of resource IDs that are never reused. This
76 // implementation does not track which IDs are currently used. It is usedul for
jamesr 2011/08/03 21:51:20 typo: usedul -> useful
77 // shared and programs which cannot be implicitly created by binding a
78 // previously unused ID.
79 class NonReusedIdAllocator : public IdAllocatorInterface {
80 public:
81 NonReusedIdAllocator();
82 virtual ~NonReusedIdAllocator();
83
84 // Implement IdAllocatorInterface.
85 virtual ResourceId AllocateID();
86 virtual ResourceId AllocateIDAtOrAbove(ResourceId desired_id);
87 virtual bool MarkAsUsed(ResourceId id);
88 virtual void FreeID(ResourceId id);
89 virtual bool InUse(ResourceId id) const;
90
91 private:
92 ResourceId last_id_;
93
94 DISALLOW_COPY_AND_ASSIGN(NonReusedIdAllocator);
95 };
96
59 } // namespace gpu 97 } // namespace gpu
60 98
61 #endif // GPU_COMMAND_BUFFER_CLIENT_ID_ALLOCATOR_H_ 99 #endif // GPU_COMMAND_BUFFER_CLIENT_ID_ALLOCATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698