delegated_ink_metadata.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // Copyright 2020 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. #ifndef UI_GFX_DELEGATED_INK_METADATA_H_
  5. #define UI_GFX_DELEGATED_INK_METADATA_H_
  6. #include <string>
  7. #include "base/time/time.h"
  8. #include "third_party/skia/include/core/SkColor.h"
  9. #include "ui/gfx/geometry/rect_f.h"
  10. #include "ui/gfx/gfx_export.h"
  11. namespace gfx {
  12. // This class stores all the metadata that is gathered when the WebAPI
  13. // updateInkTrailStartPoint is called. This metadata flows from blink,
  14. // through cc, and into viz in order to produce a delegated ink trail on the
  15. // end of what was already rendered.
  16. //
  17. // Explainer for the feature:
  18. // https://github.com/WICG/ink-enhancement/blob/main/README.md
  19. class GFX_EXPORT DelegatedInkMetadata {
  20. public:
  21. DelegatedInkMetadata() = default;
  22. DelegatedInkMetadata(const PointF& pt,
  23. double diameter,
  24. SkColor color,
  25. base::TimeTicks timestamp,
  26. const RectF& area,
  27. bool hovering)
  28. : point_(pt),
  29. diameter_(diameter),
  30. color_(color),
  31. timestamp_(timestamp),
  32. presentation_area_(area),
  33. is_hovering_(hovering) {}
  34. DelegatedInkMetadata(const PointF& pt,
  35. double diameter,
  36. SkColor color,
  37. base::TimeTicks timestamp,
  38. const RectF& area,
  39. base::TimeTicks frame_time,
  40. bool hovering)
  41. : point_(pt),
  42. diameter_(diameter),
  43. color_(color),
  44. timestamp_(timestamp),
  45. presentation_area_(area),
  46. frame_time_(frame_time),
  47. is_hovering_(hovering) {}
  48. DelegatedInkMetadata(const DelegatedInkMetadata& other) = default;
  49. DelegatedInkMetadata& operator=(const DelegatedInkMetadata& other) = default;
  50. const PointF& point() const { return point_; }
  51. double diameter() const { return diameter_; }
  52. SkColor color() const { return color_; }
  53. base::TimeTicks timestamp() const { return timestamp_; }
  54. const RectF& presentation_area() const { return presentation_area_; }
  55. base::TimeTicks frame_time() const { return frame_time_; }
  56. bool is_hovering() const { return is_hovering_; }
  57. void set_frame_time(base::TimeTicks frame_time) { frame_time_ = frame_time; }
  58. uint64_t trace_id() const {
  59. // Use mask to distinguish from DelegatedInkPoint::trace_id().
  60. // Using microseconds provides uniqueness of trace_id per
  61. // DelegatedInkMetadata.
  62. return static_cast<uint64_t>(timestamp_.since_origin().InMicroseconds()) |
  63. (uint64_t{1} << 63);
  64. }
  65. std::string ToString() const;
  66. private:
  67. // Location of the pointerevent relative to the root frame.
  68. PointF point_;
  69. // Width of the trail, in physical pixels.
  70. double diameter_ = 0;
  71. // Color to draw the ink trail.
  72. SkColor color_ = 0;
  73. // Timestamp from the pointerevent for the ink point.
  74. base::TimeTicks timestamp_;
  75. // The rect to clip the ink trail to, defaults to the containing viewport.
  76. RectF presentation_area_;
  77. // Frame time of the layer tree that this metadata is on.
  78. base::TimeTicks frame_time_;
  79. // True if the left mouse button is up or if a stylus with hovering
  80. // capabilities is hovering over the screen when updateInkTrailStartPoint is
  81. // called.
  82. bool is_hovering_ = false;
  83. };
  84. } // namespace gfx
  85. #endif // UI_GFX_DELEGATED_INK_METADATA_H_