| 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_ANIMATION_ELEMENT_ID_H_ | 5 #ifndef CC_ANIMATION_ELEMENT_ID_H_ |
| 6 #define CC_ANIMATION_ELEMENT_ID_H_ | 6 #define CC_ANIMATION_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/base/cc_export.h" | 16 #include "cc/base/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 namespace proto { | |
| 28 class ElementId; | |
| 29 } // namespace proto | |
| 30 | |
| 31 // ------------------------------*IMPORTANT*--------------------------------- | |
| 32 // ElementId has a corresponding proto defined in cc/proto/element_id.proto. | |
| 33 // When making any changes here, but sure to update the proto. | |
| 34 | |
| 35 // An "element" is really an animation target. It retains the name element to be | 27 // An "element" is really an animation target. It retains the name element to be |
| 36 // symmetric with ElementAnimations and blink::ElementAnimations, but is not | 28 // symmetric with ElementAnimations and blink::ElementAnimations, but is not |
| 37 // in fact tied to the notion of a blink element. It is also not associated with | 29 // in fact tied to the notion of a blink element. It is also not associated with |
| 38 // the notion of a Layer. Ultimately, these ids will be used to look up the | 30 // the notion of a Layer. Ultimately, these ids will be used to look up the |
| 39 // property tree node associated with the given animation. | 31 // property tree node associated with the given animation. |
| 40 // | 32 // |
| 41 // These ids are chosen by cc's clients to permit the destruction and | 33 // These ids are chosen by cc's clients to permit the destruction and |
| 42 // restoration of cc entities (when visuals are hidden and shown) but maintain | 34 // restoration of cc entities (when visuals are hidden and shown) but maintain |
| 43 // stable identifiers. There will be a single layer for an ElementId, but | 35 // stable identifiers. There will be a single layer for an ElementId, but |
| 44 // not every layer will have an id. | 36 // not every layer will have an id. |
| 45 struct CC_EXPORT ElementId { | 37 struct CC_EXPORT ElementId { |
| 46 ElementId(int primaryId, int secondaryId) | 38 ElementId(int primaryId, int secondaryId) |
| 47 : primaryId(primaryId), secondaryId(secondaryId) {} | 39 : primaryId(primaryId), secondaryId(secondaryId) {} |
| 48 ElementId() : ElementId(0, 0) {} | 40 ElementId() : ElementId(0, 0) {} |
| 49 | 41 |
| 50 bool operator==(const ElementId& o) const; | 42 bool operator==(const ElementId& o) const; |
| 51 bool operator!=(const ElementId& o) const; | 43 bool operator!=(const ElementId& o) const; |
| 52 bool operator<(const ElementId& o) const; | 44 bool operator<(const ElementId& o) const; |
| 53 | 45 |
| 54 // An ElementId's conversion to a boolean value depends only on its primaryId. | 46 // An ElementId's conversion to a boolean value depends only on its primaryId. |
| 55 explicit operator bool() const; | 47 explicit operator bool() const; |
| 56 | 48 |
| 57 void AddToTracedValue(base::trace_event::TracedValue* res) const; | 49 void AddToTracedValue(base::trace_event::TracedValue* res) const; |
| 58 std::unique_ptr<base::Value> AsValue() const; | 50 std::unique_ptr<base::Value> AsValue() const; |
| 59 | 51 |
| 60 void ToProtobuf(proto::ElementId* proto) const; | |
| 61 void FromProtobuf(const proto::ElementId& proto); | |
| 62 | |
| 63 // The compositor treats this as an opaque handle and should not know how to | 52 // The compositor treats this as an opaque handle and should not know how to |
| 64 // interpret these bits. Non-blink cc clients typically operate in terms of | 53 // interpret these bits. Non-blink cc clients typically operate in terms of |
| 65 // layers and may set this value to match the client's layer id. | 54 // layers and may set this value to match the client's layer id. |
| 66 int primaryId; | 55 int primaryId; |
| 67 int secondaryId; | 56 int secondaryId; |
| 68 }; | 57 }; |
| 69 | 58 |
| 70 CC_EXPORT ElementId LayerIdToElementIdForTesting(int layer_id); | 59 CC_EXPORT ElementId LayerIdToElementIdForTesting(int layer_id); |
| 71 | 60 |
| 72 struct CC_EXPORT ElementIdHash { | 61 struct CC_EXPORT ElementIdHash { |
| 73 size_t operator()(ElementId key) const; | 62 size_t operator()(ElementId key) const; |
| 74 }; | 63 }; |
| 75 | 64 |
| 76 // Stream operator so ElementId can be used in assertion statements. | 65 // Stream operator so ElementId can be used in assertion statements. |
| 77 CC_EXPORT std::ostream& operator<<(std::ostream& out, const ElementId& id); | 66 CC_EXPORT std::ostream& operator<<(std::ostream& out, const ElementId& id); |
| 78 | 67 |
| 79 } // namespace cc | 68 } // namespace cc |
| 80 | 69 |
| 81 #endif // CC_ANIMATION_ELEMENT_ID_H_ | 70 #endif // CC_ANIMATION_ELEMENT_ID_H_ |
| OLD | NEW |