Source code

Revision control

Other Tools

1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
* License, v. 2.0. If a copy of the MPL was not distributed with this
5
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef GFX_SCROLLABLELAYERGUID_H
8
#define GFX_SCROLLABLELAYERGUID_H
9
10
#include <stdint.h> // for uint8_t, uint32_t, uint64_t
11
#include "mozilla/HashFunctions.h" // for HashGeneric
12
#include "mozilla/gfx/Logging.h" // for Log
13
#include "mozilla/layers/LayersTypes.h" // for LayersId
14
#include "nsHashKeys.h" // for nsPrintfCString
15
#include "nsPrintfCString.h" // for nsPrintfCString
16
17
namespace mozilla {
18
namespace layers {
19
20
/**
21
* This class allows us to uniquely identify a scrollable layer. The
22
* mLayersId identifies the layer tree (corresponding to a child process
23
* and/or tab) that the scrollable layer belongs to. The mPresShellId
24
* is a temporal identifier (corresponding to the document loaded that
25
* contains the scrollable layer, which may change over time). The
26
* mScrollId corresponds to the actual frame that is scrollable.
27
*/
28
struct ScrollableLayerGuid {
29
// We use IDs to identify frames across processes.
30
typedef uint64_t ViewID;
31
typedef nsUint64HashKey ViewIDHashKey;
32
static const ViewID NULL_SCROLL_ID; // This container layer does not scroll.
33
static const ViewID START_SCROLL_ID = 2; // This is the ID that scrolling
34
// subframes will begin at.
35
36
LayersId mLayersId;
37
uint32_t mPresShellId;
38
ViewID mScrollId;
39
40
ScrollableLayerGuid() : mLayersId{0}, mPresShellId(0), mScrollId(0) {}
41
42
ScrollableLayerGuid(LayersId aLayersId, uint32_t aPresShellId,
43
ViewID aScrollId)
44
: mLayersId(aLayersId),
45
mPresShellId(aPresShellId),
46
mScrollId(aScrollId) {}
47
48
ScrollableLayerGuid(const ScrollableLayerGuid& other) = default;
49
50
~ScrollableLayerGuid() = default;
51
52
bool operator==(const ScrollableLayerGuid& other) const {
53
return mLayersId == other.mLayersId && mPresShellId == other.mPresShellId &&
54
mScrollId == other.mScrollId;
55
}
56
57
bool operator!=(const ScrollableLayerGuid& other) const {
58
return !(*this == other);
59
}
60
61
bool operator<(const ScrollableLayerGuid& other) const {
62
if (mLayersId < other.mLayersId) {
63
return true;
64
}
65
if (mLayersId == other.mLayersId) {
66
if (mPresShellId < other.mPresShellId) {
67
return true;
68
}
69
if (mPresShellId == other.mPresShellId) {
70
return mScrollId < other.mScrollId;
71
}
72
}
73
return false;
74
}
75
76
// Helper structs to use as hash/equality functions in std::unordered_map.
77
// e.g. std::unordered_map<ScrollableLayerGuid,
78
// ValueType,
79
// ScrollableLayerGuid::HashFn> myMap;
80
// std::unordered_map<ScrollableLayerGuid,
81
// ValueType,
82
// ScrollableLayerGuid::HashIgnoringPresShellFn,
83
// ScrollableLayerGuid::EqualIgnoringPresShellFn> myMap;
84
85
struct HashFn {
86
std::size_t operator()(const ScrollableLayerGuid& aGuid) const {
87
return HashGeneric(uint64_t(aGuid.mLayersId), aGuid.mPresShellId,
88
aGuid.mScrollId);
89
}
90
};
91
92
struct HashIgnoringPresShellFn {
93
std::size_t operator()(const ScrollableLayerGuid& aGuid) const {
94
return HashGeneric(uint64_t(aGuid.mLayersId), aGuid.mScrollId);
95
}
96
};
97
98
struct EqualIgnoringPresShellFn {
99
bool operator()(const ScrollableLayerGuid& lhs,
100
const ScrollableLayerGuid& rhs) const {
101
return lhs.mLayersId == rhs.mLayersId && lhs.mScrollId == rhs.mScrollId;
102
}
103
};
104
};
105
106
template <int LogLevel>
107
gfx::Log<LogLevel>& operator<<(gfx::Log<LogLevel>& log,
108
const ScrollableLayerGuid& aGuid) {
109
return log << nsPrintfCString("(0x%" PRIx64 ", %u, %" PRIu64 ")",
110
uint64_t(aGuid.mLayersId), aGuid.mPresShellId,
111
aGuid.mScrollId)
112
.get();
113
}
114
115
} // namespace layers
116
} // namespace mozilla
117
118
#endif /* GFX_SCROLLABLELAYERGUID_H */