Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 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. | |
| 4 | |
| 5 #include "gpu/command_buffer/common/sync_token.h" | |
| 6 | |
| 7 #include <string.h> | |
| 8 | |
| 9 #include "base/logging.h" | |
| 10 #include "base/rand_util.h" | |
| 11 | |
| 12 namespace gpu { | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 struct SyncTokenInternal { | |
| 17 CommandBufferNamespace namespace_id; | |
| 18 uint64_t command_buffer_id; | |
| 19 uint64_t release_count; | |
| 20 | |
| 21 bool operator<(const SyncTokenInternal& other) const { | |
| 22 // TODO(dyen): Once all our compilers support c++11, we can replace this | |
| 23 // long list of comparisons with std::tie(). | |
| 24 return (namespace_id < other.namespace_id) || | |
| 25 ((namespace_id == other.namespace_id) && | |
| 26 ((command_buffer_id < other.command_buffer_id) || | |
| 27 ((command_buffer_id == other.command_buffer_id) && | |
| 28 (release_count < other.release_count)))); | |
| 29 } | |
| 30 }; | |
| 31 | |
| 32 static_assert(sizeof(SyncTokenInternal) <= GL_SYNC_TOKEN_SIZE_CHROMIUM, | |
| 33 "SyncTokenInternal must not exceed GL_SYNC_TOKEN_SIZE_CHROMIUM"); | |
| 34 static_assert(sizeof(SyncToken) == GL_SYNC_TOKEN_SIZE_CHROMIUM, | |
| 35 "No additional members other than data are allowed in SyncToken"); | |
| 36 | |
| 37 } // namespace | |
| 38 | |
| 39 SyncToken::SyncToken() { | |
| 40 memset(data, 0, sizeof(data)); | |
| 41 } | |
| 42 | |
| 43 SyncToken::SyncToken(CommandBufferNamespace namespace_id, | |
| 44 uint64_t command_buffer_id, | |
| 45 uint64_t release_count) { | |
| 46 memset(data, 0, sizeof(data)); | |
| 47 SetData(namespace_id, command_buffer_id, release_count); | |
| 48 } | |
| 49 | |
| 50 CommandBufferNamespace SyncToken::GetNamespaceId() const { | |
| 51 return reinterpret_cast<const SyncTokenInternal*>(data)->namespace_id; | |
| 52 } | |
| 53 | |
| 54 uint64_t SyncToken::GetCommandBufferId() const { | |
| 55 return reinterpret_cast<const SyncTokenInternal*>(data)->command_buffer_id; | |
| 56 } | |
| 57 | |
| 58 uint64_t SyncToken::GetReleaseCount() const { | |
| 59 return reinterpret_cast<const SyncTokenInternal*>(data)->release_count; | |
| 60 } | |
| 61 | |
| 62 void SyncToken::SetData(CommandBufferNamespace namespace_id, | |
| 63 uint64_t command_buffer_id, | |
| 64 uint64_t release_count) { | |
| 65 SyncTokenInternal* sync_token_internal = | |
| 66 reinterpret_cast<SyncTokenInternal*>(data); | |
|
piman
2015/10/10 00:40:55
I think because SyncToken::data is not guaranteed
| |
| 67 sync_token_internal->namespace_id = namespace_id; | |
| 68 sync_token_internal->command_buffer_id = command_buffer_id; | |
| 69 sync_token_internal->release_count = release_count; | |
| 70 } | |
| 71 | |
| 72 bool SyncToken::operator<(const SyncToken& other) const { | |
| 73 const SyncTokenInternal* sync_token_internal = | |
| 74 reinterpret_cast<const SyncTokenInternal*>(data); | |
| 75 const SyncTokenInternal* other_sync_token_internal = | |
| 76 reinterpret_cast<const SyncTokenInternal*>(other.data); | |
| 77 | |
| 78 return *sync_token_internal < *other_sync_token_internal; | |
| 79 } | |
| 80 | |
| 81 } // namespace gpu | |
| OLD | NEW |