| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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_COMMON_SYNC_TOKEN_H_ | 5 #ifndef GPU_COMMAND_BUFFER_COMMON_SYNC_TOKEN_H_ |
| 6 #define GPU_COMMAND_BUFFER_COMMON_SYNC_TOKEN_H_ | 6 #define GPU_COMMAND_BUFFER_COMMON_SYNC_TOKEN_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <string.h> | 9 #include <string.h> |
| 10 | 10 |
| 11 #include "gpu/command_buffer/common/constants.h" | 11 #include "gpu/command_buffer/common/constants.h" |
| 12 #include "gpu/gpu_export.h" | 12 #include "gpu/gpu_export.h" |
| 13 | 13 |
| 14 // From glextchromium.h. | 14 // From glextchromium.h. |
| 15 #ifndef GL_SYNC_TOKEN_SIZE_CHROMIUM | 15 #ifndef GL_SYNC_TOKEN_SIZE_CHROMIUM |
| 16 #define GL_SYNC_TOKEN_SIZE_CHROMIUM 24 | 16 #define GL_SYNC_TOKEN_SIZE_CHROMIUM 24 |
| 17 #endif | 17 #endif |
| 18 | 18 |
| 19 namespace gpu { | 19 namespace gpu { |
| 20 | 20 |
| 21 // A Sync Token is a binary blob which represents a waitable fence sync | 21 // A Sync Token is a binary blob which represents a waitable fence sync |
| 22 // on a particular command buffer namespace and id. | 22 // on a particular command buffer namespace and id. |
| 23 // See src/gpu/GLES2/extensions/CHROMIUM/CHROMIUM_sync_point.txt for more | 23 // See src/gpu/GLES2/extensions/CHROMIUM/CHROMIUM_sync_point.txt for more |
| 24 // details. | 24 // details. |
| 25 struct GPU_EXPORT SyncToken { | 25 struct GPU_EXPORT SyncToken { |
| 26 SyncToken() | 26 SyncToken() |
| 27 : verified_flush_(false), | 27 : verified_flush_(false), |
| 28 namespace_id_(CommandBufferNamespace::INVALID), | 28 namespace_id_(CommandBufferNamespace::INVALID), |
| 29 extra_data_field_(0), | |
| 30 command_buffer_id_(0), | 29 command_buffer_id_(0), |
| 31 release_count_(0) {} | 30 release_count_(0) {} |
| 32 | 31 |
| 33 // TODO(dyen): This is an intermediate conversion constructor while we | 32 // TODO(dyen): This is an intermediate conversion constructor while we |
| 34 // are converting from the old sync point system. Remove once conversion | 33 // are converting from the old sync point system. Remove once conversion |
| 35 // is finished. | 34 // is finished. |
| 36 explicit SyncToken(uint32_t sync_point) | 35 explicit SyncToken(uint32_t sync_point) |
| 37 : verified_flush_(sync_point ? true : false), | 36 : verified_flush_(sync_point ? true : false), |
| 38 namespace_id_(sync_point ? gpu::CommandBufferNamespace::OLD_SYNC_POINTS | 37 namespace_id_(sync_point ? gpu::CommandBufferNamespace::OLD_SYNC_POINTS |
| 39 : gpu::CommandBufferNamespace::INVALID), | 38 : gpu::CommandBufferNamespace::INVALID), |
| 40 extra_data_field_(0), | |
| 41 command_buffer_id_(0), | 39 command_buffer_id_(0), |
| 42 release_count_(sync_point) {} | 40 release_count_(sync_point) {} |
| 43 | 41 |
| 44 SyncToken(CommandBufferNamespace namespace_id, | 42 SyncToken(CommandBufferNamespace namespace_id, |
| 45 int32_t extra_data_field, | |
| 46 uint64_t command_buffer_id, | 43 uint64_t command_buffer_id, |
| 47 uint64_t release_count) | 44 uint64_t release_count) |
| 48 : verified_flush_(false), | 45 : verified_flush_(false), |
| 49 namespace_id_(namespace_id), | 46 namespace_id_(namespace_id), |
| 50 extra_data_field_(extra_data_field), | |
| 51 command_buffer_id_(command_buffer_id), | 47 command_buffer_id_(command_buffer_id), |
| 52 release_count_(release_count) {} | 48 release_count_(release_count) {} |
| 53 | 49 |
| 54 void Set(CommandBufferNamespace namespace_id, | 50 void Set(CommandBufferNamespace namespace_id, |
| 55 int32_t extra_data_field, | |
| 56 uint64_t command_buffer_id, | 51 uint64_t command_buffer_id, |
| 57 uint64_t release_count) { | 52 uint64_t release_count) { |
| 58 namespace_id_ = namespace_id; | 53 namespace_id_ = namespace_id; |
| 59 extra_data_field_ = extra_data_field; | |
| 60 command_buffer_id_ = command_buffer_id; | 54 command_buffer_id_ = command_buffer_id; |
| 61 release_count_ = release_count; | 55 release_count_ = release_count; |
| 62 } | 56 } |
| 63 | 57 |
| 64 void Clear() { | 58 void Clear() { |
| 65 verified_flush_ = false; | 59 verified_flush_ = false; |
| 66 namespace_id_ = CommandBufferNamespace::INVALID; | 60 namespace_id_ = CommandBufferNamespace::INVALID; |
| 67 extra_data_field_ = 0; | |
| 68 command_buffer_id_ = 0; | 61 command_buffer_id_ = 0; |
| 69 release_count_ = 0; | 62 release_count_ = 0; |
| 70 } | 63 } |
| 71 | 64 |
| 72 void SetVerifyFlush() { | 65 void SetVerifyFlush() { |
| 73 verified_flush_ = true; | 66 verified_flush_ = true; |
| 74 } | 67 } |
| 75 | 68 |
| 76 bool HasData() const { | 69 bool HasData() const { |
| 77 return namespace_id_ != CommandBufferNamespace::INVALID; | 70 return namespace_id_ != CommandBufferNamespace::INVALID; |
| 78 } | 71 } |
| 79 | 72 |
| 80 int8_t* GetData() { return reinterpret_cast<int8_t*>(this); } | 73 int8_t* GetData() { return reinterpret_cast<int8_t*>(this); } |
| 81 | 74 |
| 82 const int8_t* GetConstData() const { | 75 const int8_t* GetConstData() const { |
| 83 return reinterpret_cast<const int8_t*>(this); | 76 return reinterpret_cast<const int8_t*>(this); |
| 84 } | 77 } |
| 85 | 78 |
| 86 bool verified_flush() const { return verified_flush_; } | 79 bool verified_flush() const { return verified_flush_; } |
| 87 CommandBufferNamespace namespace_id() const { return namespace_id_; } | 80 CommandBufferNamespace namespace_id() const { return namespace_id_; } |
| 88 uint64_t command_buffer_id() const { return command_buffer_id_; } | 81 uint64_t command_buffer_id() const { return command_buffer_id_; } |
| 89 uint64_t release_count() const { return release_count_; } | 82 uint64_t release_count() const { return release_count_; } |
| 90 | 83 |
| 91 // This extra data field can be used by command buffers to add extra | |
| 92 // information to identify unverified sync tokens. The current purpose | |
| 93 // of this field is only for unverified sync tokens which only exist within | |
| 94 // the same process so this information will not survive cross-process IPCs. | |
| 95 int32_t extra_data_field() const { return extra_data_field_; } | |
| 96 | |
| 97 bool operator<(const SyncToken& other) const { | 84 bool operator<(const SyncToken& other) const { |
| 98 // TODO(dyen): Once all our compilers support c++11, we can replace this | 85 // TODO(dyen): Once all our compilers support c++11, we can replace this |
| 99 // long list of comparisons with std::tie(). | 86 // long list of comparisons with std::tie(). |
| 100 return (namespace_id_ < other.namespace_id()) || | 87 return (namespace_id_ < other.namespace_id()) || |
| 101 ((namespace_id_ == other.namespace_id()) && | 88 ((namespace_id_ == other.namespace_id()) && |
| 102 ((command_buffer_id_ < other.command_buffer_id()) || | 89 ((command_buffer_id_ < other.command_buffer_id()) || |
| 103 ((command_buffer_id_ == other.command_buffer_id()) && | 90 ((command_buffer_id_ == other.command_buffer_id()) && |
| 104 (release_count_ < other.release_count())))); | 91 (release_count_ < other.release_count())))); |
| 105 } | 92 } |
| 106 | 93 |
| 107 bool operator==(const SyncToken& other) const { | 94 bool operator==(const SyncToken& other) const { |
| 108 return verified_flush_ == other.verified_flush() && | 95 return verified_flush_ == other.verified_flush() && |
| 109 namespace_id_ == other.namespace_id() && | 96 namespace_id_ == other.namespace_id() && |
| 110 extra_data_field_ == other.extra_data_field() && | |
| 111 command_buffer_id_ == other.command_buffer_id() && | 97 command_buffer_id_ == other.command_buffer_id() && |
| 112 release_count_ == other.release_count(); | 98 release_count_ == other.release_count(); |
| 113 } | 99 } |
| 114 | 100 |
| 115 bool operator!=(const SyncToken& other) const { return !(*this == other); } | 101 bool operator!=(const SyncToken& other) const { return !(*this == other); } |
| 116 | 102 |
| 117 private: | 103 private: |
| 118 bool verified_flush_; | 104 bool verified_flush_; |
| 119 CommandBufferNamespace namespace_id_; | 105 CommandBufferNamespace namespace_id_; |
| 120 int32_t extra_data_field_; | |
| 121 uint64_t command_buffer_id_; | 106 uint64_t command_buffer_id_; |
| 122 uint64_t release_count_; | 107 uint64_t release_count_; |
| 123 }; | 108 }; |
| 124 | 109 |
| 125 static_assert(sizeof(SyncToken) <= GL_SYNC_TOKEN_SIZE_CHROMIUM, | 110 static_assert(sizeof(SyncToken) <= GL_SYNC_TOKEN_SIZE_CHROMIUM, |
| 126 "SyncToken size must not exceed GL_SYNC_TOKEN_SIZE_CHROMIUM"); | 111 "SyncToken size must not exceed GL_SYNC_TOKEN_SIZE_CHROMIUM"); |
| 127 | 112 |
| 128 } // namespace gpu | 113 } // namespace gpu |
| 129 | 114 |
| 130 #endif // GPU_COMMAND_BUFFER_COMMON_SYNC_TOKEN_H_ | 115 #endif // GPU_COMMAND_BUFFER_COMMON_SYNC_TOKEN_H_ |
| OLD | NEW |