Chromium Code Reviews| Index: cc/animation/element_id.h |
| diff --git a/cc/animation/element_id.h b/cc/animation/element_id.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..069e3bc1fe396aaaf8fe12f5e3e58656a9482dcf |
| --- /dev/null |
| +++ b/cc/animation/element_id.h |
| @@ -0,0 +1,64 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CC_ANIMATION_ELEMENT_ID_H_ |
| +#define CC_ANIMATION_ELEMENT_ID_H_ |
| + |
| +#include <cstdint> |
| +#include <functional> |
| +#include <iosfwd> |
| +#include <memory> |
| +#include <stddef.h> |
| + |
| +#include "cc/base/cc_export.h" |
| + |
| +namespace base { |
| +class Value; |
| +namespace trace_event { |
| +class TracedValue; |
| +} // namespace trace_event |
| +} // namespace base |
| + |
| +namespace cc { |
| + |
| +namespace proto { |
| +class ElementId; |
| +} // namespace proto |
| + |
| +// ------------------------------*IMPORTANT*--------------------------------- |
| +// ElementId has a corresponding proto defined in cc/proto/element_id.proto. |
| +// When making any changes here, but sure to update the proto. |
| + |
| +struct CC_EXPORT ElementId { |
|
Ian Vollick
2016/06/01 18:08:26
Why a struct?
1. Catch bugs. I started with a typ
|
| + explicit ElementId(uint64_t value) : value(value) {} |
| + ElementId() : value(0ul) {} |
| + |
| + inline bool operator==(const ElementId& o) const { return o.value == value; } |
| + inline bool operator!=(const ElementId& o) const { return o.value != value; } |
| + inline bool operator<(const ElementId& o) const { return value < o.value; } |
| + inline explicit operator bool() const { return !!value; } |
| + |
| + void AddToTracedValue(base::trace_event::TracedValue* res) const; |
| + std::unique_ptr<base::Value> AsValue() const; |
| + |
| + void ToProtobuf(proto::ElementId* proto) const; |
| + void FromProtobuf(const proto::ElementId& proto); |
| + |
| + uint64_t value; |
|
Ian Vollick
2016/06/01 18:08:25
I went with a uint64_t here because I wanted cc to
ajuma
2016/06/01 23:53:42
(1) has the nice feature that you avoid bitwise OR
Ian Vollick
2016/06/02 19:03:11
I've tried out the helper function in the latest p
|
| +}; |
| + |
| +ElementId CC_EXPORT LayerIdToElementIdForTesting(int layer_id); |
| + |
| +struct ElementIdHash { |
| + size_t operator()(ElementId key) const { |
| + return std::hash<uint64_t>()(key.value); |
| + } |
| +}; |
| + |
| +// Stream operator so ElementId can be used in assertion statements. |
| +CC_EXPORT std::ostream& operator<<(std::ostream& out, const ElementId& id); |
| + |
| +} // namespace cc |
| + |
| +#endif // CC_ANIMATION_ELEMENT_ID_H_ |