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
3 // found in the LICENSE file.
5 #ifndef GPU_COMMAND_BUFFER_SERVICE_SYNC_POINT_MANAGER_H_
6 #define GPU_COMMAND_BUFFER_SERVICE_SYNC_POINT_MANAGER_H_
10 #include "base/callback.h"
11 #include "base/containers/hash_tables.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/synchronization/lock.h"
15 #include "gpu/gpu_export.h"
18 class SequenceChecker
;
23 // This class manages the sync points, which allow cross-channel
25 class GPU_EXPORT SyncPointManager
26 : public base::RefCountedThreadSafe
<SyncPointManager
> {
28 // InProcessCommandBuffer allows threaded calls since it can call into
29 // SyncPointManager from client threads, or from multiple service threads
30 // used in Android WebView.
31 static SyncPointManager
* Create(bool allow_threaded_calls
);
33 // Generates a sync point, returning its ID. This can me called on any thread.
34 // IDs start at a random number. Never return 0.
35 uint32
GenerateSyncPoint();
37 // Retires a sync point. This will call all the registered callbacks for this
38 // sync point. This can only be called on the main thread.
39 void RetireSyncPoint(uint32 sync_point
);
41 // Adds a callback to the sync point. The callback will be called when the
42 // sync point is retired, or immediately (from within that function) if the
43 // sync point was already retired (or not created yet). This can only be
44 // called on the main thread.
45 void AddSyncPointCallback(uint32 sync_point
, const base::Closure
& callback
);
47 bool IsSyncPointRetired(uint32 sync_point
);
50 friend class base::RefCountedThreadSafe
<SyncPointManager
>;
51 typedef std::vector
<base::Closure
> ClosureList
;
52 typedef base::hash_map
<uint32
, ClosureList
> SyncPointMap
;
54 explicit SyncPointManager(bool allow_threaded_calls
);
56 void CheckSequencedThread();
58 scoped_ptr
<base::SequenceChecker
> sequence_checker_
;
60 // Protects the 2 fields below. Note: callbacks shouldn't be called with this
63 SyncPointMap sync_point_map_
;
64 uint32 next_sync_point_
;
66 DISALLOW_COPY_AND_ASSIGN(SyncPointManager
);
71 #endif // GPU_COMMAND_BUFFER_SERVICE_SYNC_POINT_MANAGER_H_