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

Unified Diff: gpu/command_buffer/common/sync_token.cc

Issue 1394543003: Added SyncToken command buffer trait to help with IPC messages. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gpu/command_buffer/common/sync_token.h ('k') | gpu/command_buffer/service/in_process_command_buffer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gpu/command_buffer/common/sync_token.cc
diff --git a/gpu/command_buffer/common/sync_token.cc b/gpu/command_buffer/common/sync_token.cc
new file mode 100644
index 0000000000000000000000000000000000000000..15a7e34833a11b84a8adf894f9b40c7a2102626a
--- /dev/null
+++ b/gpu/command_buffer/common/sync_token.cc
@@ -0,0 +1,81 @@
+// Copyright 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.
+
+#include "gpu/command_buffer/common/sync_token.h"
+
+#include <string.h>
+
+#include "base/logging.h"
+#include "base/rand_util.h"
+
+namespace gpu {
+
+namespace {
+
+struct SyncTokenInternal {
+ CommandBufferNamespace namespace_id;
+ uint64_t command_buffer_id;
+ uint64_t release_count;
+
+ bool operator<(const SyncTokenInternal& other) const {
+ // TODO(dyen): Once all our compilers support c++11, we can replace this
+ // long list of comparisons with std::tie().
+ return (namespace_id < other.namespace_id) ||
+ ((namespace_id == other.namespace_id) &&
+ ((command_buffer_id < other.command_buffer_id) ||
+ ((command_buffer_id == other.command_buffer_id) &&
+ (release_count < other.release_count))));
+ }
+};
+
+static_assert(sizeof(SyncTokenInternal) <= GL_SYNC_TOKEN_SIZE_CHROMIUM,
+ "SyncTokenInternal must not exceed GL_SYNC_TOKEN_SIZE_CHROMIUM");
+static_assert(sizeof(SyncToken) == GL_SYNC_TOKEN_SIZE_CHROMIUM,
+ "No additional members other than data are allowed in SyncToken");
+
+} // namespace
+
+SyncToken::SyncToken() {
+ memset(data, 0, sizeof(data));
+}
+
+SyncToken::SyncToken(CommandBufferNamespace namespace_id,
+ uint64_t command_buffer_id,
+ uint64_t release_count) {
+ memset(data, 0, sizeof(data));
+ SetData(namespace_id, command_buffer_id, release_count);
+}
+
+CommandBufferNamespace SyncToken::GetNamespaceId() const {
+ return reinterpret_cast<const SyncTokenInternal*>(data)->namespace_id;
+}
+
+uint64_t SyncToken::GetCommandBufferId() const {
+ return reinterpret_cast<const SyncTokenInternal*>(data)->command_buffer_id;
+}
+
+uint64_t SyncToken::GetReleaseCount() const {
+ return reinterpret_cast<const SyncTokenInternal*>(data)->release_count;
+}
+
+void SyncToken::SetData(CommandBufferNamespace namespace_id,
+ uint64_t command_buffer_id,
+ uint64_t release_count) {
+ SyncTokenInternal* sync_token_internal =
+ reinterpret_cast<SyncTokenInternal*>(data);
piman 2015/10/10 00:40:55 I think because SyncToken::data is not guaranteed
+ sync_token_internal->namespace_id = namespace_id;
+ sync_token_internal->command_buffer_id = command_buffer_id;
+ sync_token_internal->release_count = release_count;
+}
+
+bool SyncToken::operator<(const SyncToken& other) const {
+ const SyncTokenInternal* sync_token_internal =
+ reinterpret_cast<const SyncTokenInternal*>(data);
+ const SyncTokenInternal* other_sync_token_internal =
+ reinterpret_cast<const SyncTokenInternal*>(other.data);
+
+ return *sync_token_internal < *other_sync_token_internal;
+}
+
+} // namespace gpu
« no previous file with comments | « gpu/command_buffer/common/sync_token.h ('k') | gpu/command_buffer/service/in_process_command_buffer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698