1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45

cc / paint / skottie_text_property_value.cc [blame]

// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "cc/paint/skottie_text_property_value.h"

#include <utility>

#include "base/hash/hash.h"

namespace cc {

SkottieTextPropertyValue::SkottieTextPropertyValue(std::string text,
                                                   gfx::RectF box)
    : box_(std::move(box)) {
  SetText(std::move(text));
}

SkottieTextPropertyValue::SkottieTextPropertyValue(
    const SkottieTextPropertyValue& other) = default;

SkottieTextPropertyValue& SkottieTextPropertyValue::operator=(
    const SkottieTextPropertyValue& other) = default;

SkottieTextPropertyValue::~SkottieTextPropertyValue() = default;

bool SkottieTextPropertyValue::operator==(
    const SkottieTextPropertyValue& other) const {
  return text_hash_ == other.text_hash_ && box_ == other.box_;
}

bool SkottieTextPropertyValue::operator!=(
    const SkottieTextPropertyValue& other) const {
  return !(*this == other);
}

void SkottieTextPropertyValue::SetText(std::string text) {
  size_t incoming_text_hash = base::FastHash(text);
  if (incoming_text_hash == text_hash_)
    return;
  text_hash_ = incoming_text_hash;
  text_ = base::MakeRefCounted<base::RefCountedString>(std::move(text));
}

}  // namespace cc