paint_worklet_input.cc 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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/paint_worklet_input.h"
  5. namespace cc {
  6. PaintWorkletInput::PropertyKey::PropertyKey(
  7. const std::string& custom_property_name,
  8. ElementId element_id)
  9. : custom_property_name(custom_property_name), element_id(element_id) {}
  10. PaintWorkletInput::PropertyKey::PropertyKey(
  11. NativePropertyType native_property_type,
  12. ElementId element_id)
  13. : native_property_type(native_property_type), element_id(element_id) {}
  14. PaintWorkletInput::PropertyKey::PropertyKey(const PropertyKey& other) = default;
  15. PaintWorkletInput::PropertyKey::~PropertyKey() = default;
  16. bool PaintWorkletInput::PropertyKey::operator==(
  17. const PropertyKey& other) const {
  18. return custom_property_name == other.custom_property_name &&
  19. native_property_type == other.native_property_type &&
  20. element_id == other.element_id;
  21. }
  22. bool PaintWorkletInput::PropertyKey::operator!=(
  23. const PropertyKey& other) const {
  24. return !(*this == other);
  25. }
  26. bool PaintWorkletInput::PropertyKey::operator<(const PropertyKey& other) const {
  27. if (custom_property_name.has_value() &&
  28. !other.custom_property_name.has_value())
  29. return true;
  30. if (!custom_property_name.has_value() &&
  31. other.custom_property_name.has_value())
  32. return false;
  33. if (custom_property_name.has_value() &&
  34. other.custom_property_name.has_value()) {
  35. if (custom_property_name.value() == other.custom_property_name.value())
  36. return element_id < other.element_id;
  37. return custom_property_name.value() < other.custom_property_name.value();
  38. }
  39. if (native_property_type.value() == other.native_property_type.value())
  40. return element_id < other.element_id;
  41. return native_property_type.value() < other.native_property_type.value();
  42. }
  43. PaintWorkletInput::PropertyValue::PropertyValue() = default;
  44. PaintWorkletInput::PropertyValue::PropertyValue(float value)
  45. : float_value(value) {}
  46. PaintWorkletInput::PropertyValue::PropertyValue(SkColor4f value)
  47. : color_value(value) {}
  48. PaintWorkletInput::PropertyValue::PropertyValue(const PropertyValue& other) =
  49. default;
  50. PaintWorkletInput::PropertyValue::~PropertyValue() = default;
  51. bool PaintWorkletInput::PropertyValue::has_value() const {
  52. DCHECK(float_value.has_value() != color_value.has_value() ||
  53. (!float_value.has_value() && !color_value.has_value()));
  54. return float_value.has_value() || color_value.has_value();
  55. }
  56. void PaintWorkletInput::PropertyValue::reset() {
  57. float_value.reset();
  58. color_value.reset();
  59. }
  60. bool PaintWorkletInput::KnownToBeOpaque() const {
  61. return false;
  62. }
  63. } // namespace cc