element_id.cc 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "cc/paint/element_id.h"
  5. #include <inttypes.h>
  6. #include <limits>
  7. #include <ostream>
  8. #include <string>
  9. #include "base/strings/stringprintf.h"
  10. #include "base/trace_event/traced_value.h"
  11. namespace cc {
  12. const ElementIdType ElementId::kInvalidElementId = 0;
  13. const ElementIdType ElementId::kReservedElementId =
  14. std::numeric_limits<ElementIdType>::max();
  15. // static
  16. bool ElementId::IsValid(ElementIdType id) {
  17. return id != kInvalidElementId;
  18. }
  19. ElementId LayerIdToElementIdForTesting(int layer_id) {
  20. return ElementId(std::numeric_limits<int>::max() - layer_id);
  21. }
  22. void ElementId::AddToTracedValue(base::trace_event::TracedValue* res) const {
  23. res->BeginDictionary("element_id");
  24. res->SetInteger("id_", id_);
  25. res->EndDictionary();
  26. }
  27. ElementIdType ElementId::GetStableId() const {
  28. return id_;
  29. }
  30. std::string ElementId::ToString() const {
  31. return base::StringPrintf("(%" PRIu64 ")", id_);
  32. }
  33. size_t ElementIdHash::operator()(ElementId key) const {
  34. return std::hash<int>()(key.id_);
  35. }
  36. std::ostream& operator<<(std::ostream& out, const ElementId& id) {
  37. return out << id.ToString();
  38. }
  39. } // namespace cc