File: delegated_ink_metadata.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (119 lines) | stat: -rw-r--r-- 4,464 bytes parent folder | download | duplicates (5)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_GFX_DELEGATED_INK_METADATA_H_
#define UI_GFX_DELEGATED_INK_METADATA_H_

#include <string>

#include "base/component_export.h"
#include "base/time/time.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/geometry/rect_f.h"

namespace gfx {

// Maximum number of points that can be drawn. This is used to limit the total
// number of ink trail tokens that we will store, and the total number of points
// that we will store to provide to the Direct Composition APIs. It should match
// the exact number of points that the OS Compositor will store to draw as part
// of a trail.
inline constexpr int kMaximumNumberOfDelegatedInkPoints = 128;

// This class stores all the metadata that is gathered when the WebAPI
// updateInkTrailStartPoint is called. This metadata flows from blink,
// through cc, and into viz in order to produce a delegated ink trail on the
// end of what was already rendered.
//
// Explainer for the feature:
// https://github.com/WICG/ink-enhancement/blob/main/README.md
class COMPONENT_EXPORT(GFX) DelegatedInkMetadata {
 public:
  DelegatedInkMetadata() = default;
  bool operator==(const DelegatedInkMetadata& o) const = default;
  DelegatedInkMetadata(const PointF& pt,
                       double diameter,
                       SkColor color,
                       base::TimeTicks timestamp,
                       const RectF& area,
                       bool hovering)
      : point_(pt),
        diameter_(diameter),
        color_(color),
        timestamp_(timestamp),
        presentation_area_(area),
        is_hovering_(hovering) {}
  DelegatedInkMetadata(const PointF& pt,
                       double diameter,
                       SkColor color,
                       base::TimeTicks timestamp,
                       const RectF& area,
                       base::TimeTicks frame_time,
                       bool hovering,
                       std::uint64_t render_pass_id)
      : point_(pt),
        diameter_(diameter),
        color_(color),
        timestamp_(timestamp),
        presentation_area_(area),
        frame_time_(frame_time),
        is_hovering_(hovering),
        render_pass_id_(render_pass_id) {}
  DelegatedInkMetadata(const DelegatedInkMetadata& other) = default;
  DelegatedInkMetadata& operator=(const DelegatedInkMetadata& other) = default;

  const PointF& point() const { return point_; }
  double diameter() const { return diameter_; }
  SkColor color() const { return color_; }
  base::TimeTicks timestamp() const { return timestamp_; }
  const RectF& presentation_area() const { return presentation_area_; }
  base::TimeTicks frame_time() const { return frame_time_; }
  std::uint64_t render_pass_id() const { return render_pass_id_; }
  bool is_hovering() const { return is_hovering_; }
  void set_render_pass_id(std::uint64_t render_pass_id) {
    render_pass_id_ = render_pass_id;
  }
  void set_frame_time(base::TimeTicks frame_time) { frame_time_ = frame_time; }
  uint64_t trace_id() const {
    // Use mask to distinguish from DelegatedInkPoint::trace_id().
    // Using microseconds provides uniqueness of trace_id per
    // DelegatedInkMetadata.
    return static_cast<uint64_t>(timestamp_.since_origin().InMicroseconds()) |
           (uint64_t{1} << 63);
  }
  std::string ToString() const;

 private:
  // Location of the pointerevent relative to the root frame.
  PointF point_;

  // Width of the trail, in physical pixels.
  double diameter_ = 0;

  // Color to draw the ink trail.
  SkColor color_ = 0;

  // Timestamp from the pointerevent for the ink point.
  base::TimeTicks timestamp_;

  // The rect to clip the ink trail to, defaults to the containing viewport.
  RectF presentation_area_;

  // Frame time of the layer tree that this metadata is on.
  base::TimeTicks frame_time_;

  // True if the left mouse button is up or if a stylus with hovering
  // capabilities is hovering over the screen when updateInkTrailStartPoint is
  // called.
  bool is_hovering_ = false;

  // Id of the render pass that will have the delegated ink drawn on top of.
  // This is used when delegated ink is rendered by Skia. Only used within the
  // gpu process - not serialized over mojo.
  std::uint64_t render_pass_id_ = 0;
};

}  // namespace gfx

#endif  // UI_GFX_DELEGATED_INK_METADATA_H_