Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / ui / gfx / generic_shared_memory_id.h
blob1c3be79362c22c955bd968cdcbd8051cb3be0d03
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.
5 #ifndef UI_GFX_GENERIC_SHARED_MEMORY_ID_H_
6 #define UI_GFX_GENERIC_SHARED_MEMORY_ID_H_
8 #include "base/trace_event/memory_allocator_dump.h"
9 #include "ui/gfx/gfx_export.h"
11 namespace gfx {
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;
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;
27 bool operator==(const GenericSharedMemoryId& other) const {
28 return id == other.id;
31 bool operator<(const GenericSharedMemoryId& other) const {
32 return id < other.id;
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);
43 } // namespace gfx
45 namespace BASE_HASH_NAMESPACE {
47 template <>
48 struct hash<gfx::GenericSharedMemoryId> {
49 size_t operator()(gfx::GenericSharedMemoryId key) const {
50 return BASE_HASH_NAMESPACE::hash<int>()(key.id);
54 template <typename Second>
55 struct hash<std::pair<gfx::GenericSharedMemoryId, Second>> {
56 size_t operator()(
57 const std::pair<gfx::GenericSharedMemoryId, Second>& pair) const {
58 return base::HashPair(pair.first.id, pair.second);
62 } // namespace BASE_HASH_NAMESPACE
64 #endif // UI_GFX_GENERIC_SHARED_MEMORY_ID_H_