Index: gpu/command_buffer/service/fence_sync_manager.h |
diff --git a/gpu/command_buffer/service/fence_sync_manager.h b/gpu/command_buffer/service/fence_sync_manager.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..fc59d432cd3c69c627e7029fb63594ba5dd08182 |
--- /dev/null |
+++ b/gpu/command_buffer/service/fence_sync_manager.h |
@@ -0,0 +1,61 @@ |
+// Copyright (c) 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef GPU_COMMAND_BUFFER_SERVICE_SYNC_FENCE_MANAGER_H_ |
+#define GPU_COMMAND_BUFFER_SERVICE_SYNC_FENCE_MANAGER_H_ |
+ |
+#include <functional> |
+#include <queue> |
+ |
+#include "base/callback.h" |
+#include "gpu/gpu_export.h" |
+ |
+namespace gpu { |
+ |
+// This class manages the sync fences, which allow cross-channel |
+// synchronization. |
+class GPU_EXPORT FenceSyncManager { |
+ public: |
+ FenceSyncManager(); |
+ ~FenceSyncManager(); |
+ |
+ void AddFenceSyncCallback(uint32_t max_order_number, |
+ uint32_t release, |
+ const base::Closure& callback); |
+ |
+ bool IsFenceSyncReleased(uint32_t release) const { |
+ return release <= fence_sync_release_; |
+ } |
+ |
+ void ReleaseFenceSync(uint32_t release); |
+ |
+ private: |
+ struct FenceSyncCallback { |
+ uint32_t release_count; |
+ base::Closure callback_closure; |
+ |
+ FenceSyncCallback(uint32_t release, const base::Closure& callback); |
+ ~FenceSyncCallback(); |
+ |
+ bool operator>(const FenceSyncCallback& rhs) const { |
+ return release_count > rhs.release_count; |
+ } |
+ }; |
+ typedef std::priority_queue<FenceSyncCallback, |
+ std::vector<FenceSyncCallback>, |
+ std::greater<FenceSyncCallback>> CallbackQueue; |
+ |
+ // Current fence sync release that has been signaled. |
+ uint32_t fence_sync_release_; |
+ |
+ // In well defined fence sync operations, fence syncs are released in order |
+ // so simply having a priority queue for callbacks is enough. |
+ CallbackQueue fence_callback_queue_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(FenceSyncManager); |
+}; |
+ |
+} // namespace gpu |
+ |
+#endif // GPU_COMMAND_BUFFER_SERVICE_SYNC_FENCE_MANAGER_H_ |