Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(160)

Side by Side Diff: cc/trees/element_id.h

Issue 2860293002: Change cc::ElementId to be a uint64_t (Closed)
Patch Set: none Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 CC_TREES_ELEMENT_ID_H_ 5 #ifndef CC_TREES_ELEMENT_ID_H_
6 #define CC_TREES_ELEMENT_ID_H_ 6 #define CC_TREES_ELEMENT_ID_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h>
9 10
10 #include <cstdint> 11 #include <cstdint>
11 #include <functional> 12 #include <functional>
12 #include <iosfwd> 13 #include <iosfwd>
13 #include <memory> 14 #include <memory>
14 15
15 #include "base/hash.h"
16 #include "cc/cc_export.h" 16 #include "cc/cc_export.h"
17 17
18 namespace base {
19 class Value;
20 namespace trace_event {
21 class TracedValue;
22 } // namespace trace_event
23 } // namespace base
24
25 namespace cc { 18 namespace cc {
26 19
27 // Element ids are chosen by cc's clients and can be used as a stable identifier 20 // Element ids are chosen by cc's clients and can be used as a stable identifier
28 // across updates. 21 // across updates.
29 // 22 //
30 // Historically, the layer tree stored all compositing data but this has been 23 // Historically, the layer tree stored all compositing data but this has been
31 // refactored over time into auxilliary structures such as property trees. 24 // refactored over time into auxilliary structures such as property trees.
32 // 25 //
33 // In composited scrolling, Layers directly reference scroll tree nodes 26 // In composited scrolling, Layers directly reference scroll tree nodes
34 // (Layer::scroll_tree_index) but scroll tree nodes are being refactored to 27 // (Layer::scroll_tree_index) but scroll tree nodes are being refactored to
35 // reference stable element ids instead of layers. Scroll property nodes have 28 // reference stable element ids instead of layers. Scroll property nodes have
36 // unique element ids that blink creates from scrollable areas (though this is 29 // unique element ids that blink creates from scrollable areas (though this is
37 // opaque to the compositor). This refactoring of scroll nodes keeping a 30 // opaque to the compositor). This refactoring of scroll nodes keeping a
38 // scrolling element id instead of a scrolling layer id allows for more general 31 // scrolling element id instead of a scrolling layer id allows for more general
39 // compositing where, for example, multiple layers scroll with one scroll node. 32 // compositing where, for example, multiple layers scroll with one scroll node.
40 // 33 //
41 // The animation system (see: ElementAnimations and blink::ElementAnimations) is 34 // The animation system (see: ElementAnimations and blink::ElementAnimations) is
42 // another auxilliary structure to the layer tree and uses element ids as a 35 // another auxilliary structure to the layer tree and uses element ids as a
43 // stable identifier for animation targets. A Layer's element id can change over 36 // stable identifier for animation targets. A Layer's element id can change over
44 // the Layer's lifetime because non-default ElementIds are only set during an 37 // the Layer's lifetime because non-default ElementIds are only set during an
45 // animation's lifetime. 38 // animation's lifetime.
39
40 static const uint64_t kInvalidElementId = 0;
41
42 // Non-test code in cc should never need to construct an ElementId with a newly
43 // minted id.
46 struct CC_EXPORT ElementId { 44 struct CC_EXPORT ElementId {
47 ElementId(int primaryId, int secondaryId) 45 typedef uint64_t Id;
wkorman 2017/05/08 18:23:24 Can we use 'using' here instead?
48 : primaryId(primaryId), secondaryId(secondaryId) {} 46 Id id = kInvalidElementId;
49 ElementId() : ElementId(0, 0) {}
50 47
51 bool operator==(const ElementId& o) const; 48 bool operator==(const ElementId& o) const;
52 bool operator!=(const ElementId& o) const; 49 bool operator!=(const ElementId& o) const;
53 bool operator<(const ElementId& o) const; 50 bool operator<(const ElementId& o) const;
54 51
55 // An ElementId's conversion to a boolean value depends only on its primaryId.
56 explicit operator bool() const; 52 explicit operator bool() const;
57
58 void AddToTracedValue(base::trace_event::TracedValue* res) const;
59 std::unique_ptr<base::Value> AsValue() const;
60
61 // The compositor treats this as an opaque handle and should not know how to
62 // interpret these bits. Non-blink cc clients typically operate in terms of
63 // layers and may set this value to match the client's layer id.
64 int primaryId;
65 int secondaryId;
66 };
67
68 CC_EXPORT ElementId LayerIdToElementIdForTesting(int layer_id);
69
70 struct CC_EXPORT ElementIdHash {
71 size_t operator()(ElementId key) const;
72 }; 53 };
73 54
74 // Stream operator so ElementId can be used in assertion statements. 55 // Stream operator so ElementId can be used in assertion statements.
75 CC_EXPORT std::ostream& operator<<(std::ostream& out, const ElementId& id); 56 CC_EXPORT std::ostream& operator<<(std::ostream& out, const ElementId& id);
76 57
77 } // namespace cc 58 } // namespace cc
78 59
79 #endif // CC_TREES_ELEMENT_ID_H_ 60 #endif // CC_TREES_ELEMENT_ID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698