OLD | NEW |
1 // Copyright (c) 2012 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 #ifndef GPU_COMMAND_BUFFER_SERVICE_SYNC_POINT_MANAGER_H_ | 5 #ifndef GPU_COMMAND_BUFFER_SERVICE_SYNC_POINT_MANAGER_H_ |
6 #define GPU_COMMAND_BUFFER_SERVICE_SYNC_POINT_MANAGER_H_ | 6 #define GPU_COMMAND_BUFFER_SERVICE_SYNC_POINT_MANAGER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <functional> | 10 #include <functional> |
11 #include <queue> | 11 #include <queue> |
| 12 #include <unordered_map> |
12 #include <vector> | 13 #include <vector> |
13 | 14 |
14 #include "base/atomic_sequence_num.h" | 15 #include "base/atomic_sequence_num.h" |
15 #include "base/callback.h" | 16 #include "base/callback.h" |
16 #include "base/containers/hash_tables.h" | |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
18 #include "base/macros.h" | 18 #include "base/macros.h" |
19 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
20 #include "base/memory/scoped_ptr.h" | 20 #include "base/memory/scoped_ptr.h" |
21 #include "base/synchronization/condition_variable.h" | 21 #include "base/synchronization/condition_variable.h" |
22 #include "base/synchronization/lock.h" | 22 #include "base/synchronization/lock.h" |
23 #include "base/threading/thread_checker.h" | 23 #include "base/threading/thread_checker.h" |
| 24 #include "gpu/command_buffer/common/command_buffer_id.h" |
24 #include "gpu/command_buffer/common/constants.h" | 25 #include "gpu/command_buffer/common/constants.h" |
25 #include "gpu/gpu_export.h" | 26 #include "gpu/gpu_export.h" |
26 | 27 |
27 namespace base { | 28 namespace base { |
28 class SingleThreadTaskRunner; | 29 class SingleThreadTaskRunner; |
29 } // namespace base | 30 } // namespace base |
30 | 31 |
31 namespace gpu { | 32 namespace gpu { |
32 | 33 |
33 class SyncPointClient; | 34 class SyncPointClient; |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 | 242 |
242 void ReleaseFenceSync(uint64_t release); | 243 void ReleaseFenceSync(uint64_t release); |
243 | 244 |
244 private: | 245 private: |
245 friend class SyncPointManager; | 246 friend class SyncPointManager; |
246 | 247 |
247 SyncPointClient(); | 248 SyncPointClient(); |
248 SyncPointClient(SyncPointManager* sync_point_manager, | 249 SyncPointClient(SyncPointManager* sync_point_manager, |
249 scoped_refptr<SyncPointOrderData> order_data, | 250 scoped_refptr<SyncPointOrderData> order_data, |
250 CommandBufferNamespace namespace_id, | 251 CommandBufferNamespace namespace_id, |
251 uint64_t client_id); | 252 CommandBufferId client_id); |
252 | 253 |
253 // Sync point manager is guaranteed to exist in the lifetime of the client. | 254 // Sync point manager is guaranteed to exist in the lifetime of the client. |
254 SyncPointManager* sync_point_manager_; | 255 SyncPointManager* sync_point_manager_; |
255 | 256 |
256 // Keep the state that is sharable across multiple threads. | 257 // Keep the state that is sharable across multiple threads. |
257 scoped_refptr<SyncPointClientState> client_state_; | 258 scoped_refptr<SyncPointClientState> client_state_; |
258 | 259 |
259 // Unique namespace/client id pair for this sync point client. | 260 // Unique namespace/client id pair for this sync point client. |
260 const CommandBufferNamespace namespace_id_; | 261 const CommandBufferNamespace namespace_id_; |
261 const uint64_t client_id_; | 262 const CommandBufferId client_id_; |
262 | 263 |
263 DISALLOW_COPY_AND_ASSIGN(SyncPointClient); | 264 DISALLOW_COPY_AND_ASSIGN(SyncPointClient); |
264 }; | 265 }; |
265 | 266 |
266 // This class manages the sync points, which allow cross-channel | 267 // This class manages the sync points, which allow cross-channel |
267 // synchronization. | 268 // synchronization. |
268 class GPU_EXPORT SyncPointManager { | 269 class GPU_EXPORT SyncPointManager { |
269 public: | 270 public: |
270 explicit SyncPointManager(bool allow_threaded_wait); | 271 explicit SyncPointManager(bool allow_threaded_wait); |
271 ~SyncPointManager(); | 272 ~SyncPointManager(); |
272 | 273 |
273 // Creates/Destroy a sync point client which message processors should hold. | 274 // Creates/Destroy a sync point client which message processors should hold. |
274 scoped_ptr<SyncPointClient> CreateSyncPointClient( | 275 scoped_ptr<SyncPointClient> CreateSyncPointClient( |
275 scoped_refptr<SyncPointOrderData> order_data, | 276 scoped_refptr<SyncPointOrderData> order_data, |
276 CommandBufferNamespace namespace_id, | 277 CommandBufferNamespace namespace_id, |
277 uint64_t client_id); | 278 CommandBufferId client_id); |
278 | 279 |
279 // Creates a sync point client which cannot process order numbers but can only | 280 // Creates a sync point client which cannot process order numbers but can only |
280 // Wait out of order. | 281 // Wait out of order. |
281 scoped_ptr<SyncPointClient> CreateSyncPointClientWaiter(); | 282 scoped_ptr<SyncPointClient> CreateSyncPointClientWaiter(); |
282 | 283 |
283 // Finds the state of an already created sync point client. | 284 // Finds the state of an already created sync point client. |
284 scoped_refptr<SyncPointClientState> GetSyncPointClientState( | 285 scoped_refptr<SyncPointClientState> GetSyncPointClientState( |
285 CommandBufferNamespace namespace_id, uint64_t client_id); | 286 CommandBufferNamespace namespace_id, |
| 287 CommandBufferId client_id); |
286 | 288 |
287 private: | 289 private: |
288 friend class SyncPointClient; | 290 friend class SyncPointClient; |
289 friend class SyncPointOrderData; | 291 friend class SyncPointOrderData; |
290 | 292 |
291 typedef base::hash_map<uint64_t, SyncPointClient*> ClientMap; | 293 using ClientMap = std::unordered_map<CommandBufferId, |
| 294 SyncPointClient*, |
| 295 CommandBufferId::Hasher>; |
292 | 296 |
293 uint32_t GenerateOrderNumber(); | 297 uint32_t GenerateOrderNumber(); |
294 void DestroySyncPointClient(CommandBufferNamespace namespace_id, | 298 void DestroySyncPointClient(CommandBufferNamespace namespace_id, |
295 uint64_t client_id); | 299 CommandBufferId client_id); |
296 | 300 |
297 // Order number is global for all clients. | 301 // Order number is global for all clients. |
298 base::AtomicSequenceNumber global_order_num_; | 302 base::AtomicSequenceNumber global_order_num_; |
299 | 303 |
300 // Client map holds a map of clients id to client for each namespace. | 304 // Client map holds a map of clients id to client for each namespace. |
301 base::Lock client_maps_lock_; | 305 base::Lock client_maps_lock_; |
302 ClientMap client_maps_[NUM_COMMAND_BUFFER_NAMESPACES]; | 306 ClientMap client_maps_[NUM_COMMAND_BUFFER_NAMESPACES]; |
303 | 307 |
304 DISALLOW_COPY_AND_ASSIGN(SyncPointManager); | 308 DISALLOW_COPY_AND_ASSIGN(SyncPointManager); |
305 }; | 309 }; |
306 | 310 |
307 } // namespace gpu | 311 } // namespace gpu |
308 | 312 |
309 #endif // GPU_COMMAND_BUFFER_SERVICE_SYNC_POINT_MANAGER_H_ | 313 #endif // GPU_COMMAND_BUFFER_SERVICE_SYNC_POINT_MANAGER_H_ |
OLD | NEW |