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 #ifndef UI_GFX_GENERIC_SHARED_MEMORY_ID_H_ |
| 6 #define UI_GFX_GENERIC_SHARED_MEMORY_ID_H_ |
| 7 |
| 8 #include "base/trace_event/memory_allocator_dump.h" |
| 9 #include "ui/gfx/gfx_export.h" |
| 10 |
| 11 namespace gfx { |
| 12 |
| 13 // Defines an ID type which is used across all types of shared memory |
| 14 // allocations in content/. This ID type is in ui/gfx, as components outside |
| 15 // content/ may need to hold an ID (but should not generate one). |
| 16 class GFX_EXPORT GenericSharedMemoryId { |
| 17 public: |
| 18 int id; |
| 19 |
| 20 // Invalid ID is -1 to match semantics of base::StaticAtomicSequenceNumber. |
| 21 GenericSharedMemoryId() : id(-1) {} |
| 22 explicit GenericSharedMemoryId(int id) : id(id) {} |
| 23 GenericSharedMemoryId(const GenericSharedMemoryId& other) = default; |
| 24 GenericSharedMemoryId& operator=(const GenericSharedMemoryId& other) = |
| 25 default; |
| 26 |
| 27 bool operator==(const GenericSharedMemoryId& other) const { |
| 28 return id == other.id; |
| 29 } |
| 30 |
| 31 bool operator<(const GenericSharedMemoryId& other) const { |
| 32 return id < other.id; |
| 33 } |
| 34 }; |
| 35 |
| 36 // Generates GUID which can be used to trace shared memory using its |
| 37 // GenericSharedMemoryId. |
| 38 GFX_EXPORT base::trace_event::MemoryAllocatorDumpGuid |
| 39 GetGenericSharedMemoryGUIDForTracing( |
| 40 uint64_t tracing_process_id, |
| 41 GenericSharedMemoryId generic_shared_memory_id); |
| 42 |
| 43 } // namespace gfx |
| 44 |
| 45 namespace BASE_HASH_NAMESPACE { |
| 46 template <> |
| 47 struct hash<gfx::GenericSharedMemoryId> { |
| 48 size_t operator()(gfx::GenericSharedMemoryId key) const { |
| 49 return BASE_HASH_NAMESPACE::hash<int>()(key.id); |
| 50 } |
| 51 }; |
| 52 } // namespace BASE_HASH_NAMESPACE |
| 53 |
| 54 #endif // UI_GFX_GENERIC_SHARED_MEMORY_ID_H_ |
OLD | NEW |