skottie_text_property_value.cc 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright 2022 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/skottie_text_property_value.h"
  5. #include <utility>
  6. #include "base/hash/hash.h"
  7. namespace cc {
  8. SkottieTextPropertyValue::SkottieTextPropertyValue(std::string text,
  9. gfx::RectF box)
  10. : box_(std::move(box)) {
  11. SetText(std::move(text));
  12. }
  13. SkottieTextPropertyValue::SkottieTextPropertyValue(
  14. const SkottieTextPropertyValue& other) = default;
  15. SkottieTextPropertyValue& SkottieTextPropertyValue::operator=(
  16. const SkottieTextPropertyValue& other) = default;
  17. SkottieTextPropertyValue::~SkottieTextPropertyValue() = default;
  18. bool SkottieTextPropertyValue::operator==(
  19. const SkottieTextPropertyValue& other) const {
  20. return text_hash_ == other.text_hash_ && box_ == other.box_;
  21. }
  22. bool SkottieTextPropertyValue::operator!=(
  23. const SkottieTextPropertyValue& other) const {
  24. return !(*this == other);
  25. }
  26. void SkottieTextPropertyValue::SetText(std::string text) {
  27. size_t incoming_text_hash = base::FastHash(text);
  28. if (incoming_text_hash == text_hash_)
  29. return;
  30. text_hash_ = incoming_text_hash;
  31. text_ = base::RefCountedString::TakeString(&text);
  32. }
  33. } // namespace cc