| OLD | NEW |
| 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 | 9 |
| 10 #include <cstdint> | 10 #include <cstdint> |
| 11 #include <functional> | 11 #include <functional> |
| 12 #include <iosfwd> | 12 #include <iosfwd> |
| 13 #include <memory> | 13 #include <memory> |
| 14 | 14 |
| 15 #include "base/hash.h" | 15 #include "base/hash.h" |
| 16 #include "cc/cc_export.h" | 16 #include "cc/cc_export.h" |
| 17 | 17 |
| 18 namespace base { | 18 namespace base { |
| 19 class Value; | 19 class Value; |
| 20 namespace trace_event { | 20 namespace trace_event { |
| 21 class TracedValue; | 21 class TracedValue; |
| 22 } // namespace trace_event | 22 } // namespace trace_event |
| 23 } // namespace base | 23 } // namespace base |
| 24 | 24 |
| 25 namespace cc { | 25 namespace cc { |
| 26 | 26 |
| 27 using ElementIdType = uint64_t; |
| 28 |
| 29 static const ElementIdType kInvalidElementId = 0; |
| 30 |
| 27 // Element ids are chosen by cc's clients and can be used as a stable identifier | 31 // Element ids are chosen by cc's clients and can be used as a stable identifier |
| 28 // across updates. | 32 // across updates. |
| 29 // | 33 // |
| 30 // Historically, the layer tree stored all compositing data but this has been | 34 // Historically, the layer tree stored all compositing data but this has been |
| 31 // refactored over time into auxilliary structures such as property trees. | 35 // refactored over time into auxilliary structures such as property trees. |
| 32 // | 36 // |
| 33 // In composited scrolling, Layers directly reference scroll tree nodes | 37 // In composited scrolling, Layers directly reference scroll tree nodes |
| 34 // (Layer::scroll_tree_index) but scroll tree nodes are being refactored to | 38 // (Layer::scroll_tree_index) but scroll tree nodes are being refactored to |
| 35 // reference stable element ids instead of layers. Scroll property nodes have | 39 // reference stable element ids instead of layers. Scroll property nodes have |
| 36 // unique element ids that blink creates from scrollable areas (though this is | 40 // unique element ids that blink creates from scrollable areas (though this is |
| 37 // opaque to the compositor). This refactoring of scroll nodes keeping a | 41 // 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 | 42 // 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. | 43 // compositing where, for example, multiple layers scroll with one scroll node. |
| 40 // | 44 // |
| 41 // The animation system (see: ElementAnimations and blink::ElementAnimations) is | 45 // The animation system (see: ElementAnimations and blink::ElementAnimations) is |
| 42 // another auxilliary structure to the layer tree and uses element ids as a | 46 // 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 | 47 // 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 | 48 // the Layer's lifetime because non-default ElementIds are only set during an |
| 45 // animation's lifetime. | 49 // animation's lifetime. |
| 46 struct CC_EXPORT ElementId { | 50 struct CC_EXPORT ElementId { |
| 47 ElementId(int primaryId, int secondaryId) | 51 explicit ElementId(int id) : id_(id) {} |
| 48 : primaryId(primaryId), secondaryId(secondaryId) {} | 52 ElementId() : ElementId(kInvalidElementId) {} |
| 49 ElementId() : ElementId(0, 0) {} | |
| 50 | 53 |
| 51 bool operator==(const ElementId& o) const; | 54 bool operator==(const ElementId& o) const; |
| 52 bool operator!=(const ElementId& o) const; | 55 bool operator!=(const ElementId& o) const; |
| 53 bool operator<(const ElementId& o) const; | 56 bool operator<(const ElementId& o) const; |
| 54 | 57 |
| 55 // An ElementId's conversion to a boolean value depends only on its primaryId. | 58 // An ElementId's conversion to a boolean value depends only on its primaryId. |
| 56 explicit operator bool() const; | 59 explicit operator bool() const; |
| 57 | 60 |
| 58 void AddToTracedValue(base::trace_event::TracedValue* res) const; | 61 void AddToTracedValue(base::trace_event::TracedValue* res) const; |
| 59 std::unique_ptr<base::Value> AsValue() const; | 62 std::unique_ptr<base::Value> AsValue() const; |
| 60 | 63 |
| 61 // The compositor treats this as an opaque handle and should not know how to | 64 // 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 | 65 // 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. | 66 // layers and may set this value to match the client's layer id. |
| 64 int primaryId; | 67 ElementIdType id_; |
| 65 int secondaryId; | |
| 66 }; | 68 }; |
| 67 | 69 |
| 68 CC_EXPORT ElementId LayerIdToElementIdForTesting(int layer_id); | 70 ElementId CC_EXPORT LayerIdToElementIdForTesting(int layer_id); |
| 69 | 71 |
| 70 struct CC_EXPORT ElementIdHash { | 72 struct CC_EXPORT ElementIdHash { |
| 71 size_t operator()(ElementId key) const; | 73 size_t operator()(ElementId key) const; |
| 72 }; | 74 }; |
| 73 | 75 |
| 74 // Stream operator so ElementId can be used in assertion statements. | 76 // Stream operator so ElementId can be used in assertion statements. |
| 75 CC_EXPORT std::ostream& operator<<(std::ostream& out, const ElementId& id); | 77 CC_EXPORT std::ostream& operator<<(std::ostream& out, const ElementId& id); |
| 76 | 78 |
| 77 } // namespace cc | 79 } // namespace cc |
| 78 | 80 |
| 79 #endif // CC_TREES_ELEMENT_ID_H_ | 81 #endif // CC_TREES_ELEMENT_ID_H_ |
| OLD | NEW |