File: delegated_ink_point_renderer_skia.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (101 lines) | stat: -rw-r--r-- 4,926 bytes parent folder | download | duplicates (6)
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
// 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 COMPONENTS_VIZ_SERVICE_DISPLAY_DELEGATED_INK_POINT_RENDERER_SKIA_H_
#define COMPONENTS_VIZ_SERVICE_DISPLAY_DELEGATED_INK_POINT_RENDERER_SKIA_H_

#include <vector>

#include "components/viz/service/display/delegated_ink_point_renderer_base.h"
#include "components/viz/service/viz_service_export.h"
#include "third_party/skia/include/core/SkPath.h"
#include "ui/gfx/geometry/transform.h"

class SkCanvas;

namespace viz {

// This class handles drawing the delegated ink trail when the Skia renderer
// is in use by filtering everything out with timestamps before the metadata,
// predicting another point or two, and drawing the points with bezier curves
// between them with Skia commands onto the canvas provided by the Skia
// renderer, the |current_canvas_|.
// TODO(crbug.com/40118757): Specify exactly how many points are predicted.
//
// When an ink trail is getting ready to be drawn, after points and metadata
// have already arrived, the first thing that will be called is
// FinalizePathForDraw(). This is called when determining the portion of the
// frame that needs to be redrawn, so that GetDamageRect() can return the union
// of the bounding box of the previous ink trail that had been drawn (stored in
// |new_trail_damage_rect_| at this time) and the new ink trail.
// FinalizePathForDraw() will filter points, predict new ones, and use the
// result to update |path_| with the new ink trail. It also calls
// SetDamageRect() with the new trail's damage rect, which moves the rect
// currently in |new_trail_damage_rect_| to |old_trail_damage_rect_| and the new
// damage rect goes to |new_trail_damage_rect_|. GetDamageRect() then returns
// the union of the two for drawing.
// Then, after everything else in the frame has been drawn,
// DrawDelegatedInkTrail() will be called to actually draw the |path_| that was
// determined in FinalizePathForDraw().
// After drawing and swapping the buffers has completed, the display will call
// GetDamageRect() in order to update the ink trail damage rect on the surface
// aggregator, which is used to ensure one more frame will be drawn so that a
// trail never sticks around for longer than intended.
//
// For more information on the feature, please see the explainer:
// https://github.com/WICG/ink-enhancement/blob/main/README.md
class VIZ_SERVICE_EXPORT DelegatedInkPointRendererSkia
    : public DelegatedInkPointRendererBase {
 public:
  DelegatedInkPointRendererSkia() = default;
  DelegatedInkPointRendererSkia(const DelegatedInkPointRendererSkia&) = delete;
  DelegatedInkPointRendererSkia& operator=(
      const DelegatedInkPointRendererSkia&) = delete;

  // Set |path_| that will be drawn in the DrawDelegatedInkTrail() call. This is
  // called before GetDamageRect() when determining what portion of the frame
  // needs to be redrawn - earlier in the execution than the actual drawing
  // happens. Finalizing the trail when determining the portion of the frame
  // that needs to be redrawn is necessary so that the damage rect of the new
  // trail is known and the new trail can be drawn entirely, while
  // simultaneously removing the old trail and optimizing the damage rect to be
  // as small as possible. The alternative is to use |metadata_|'s presentation
  // area as the damage rect instead - then the path could be finalized directly
  // before drawing instead. However, this could result in a noticeable
  // performance hit by drawing much more than necessary.
  void FinalizePathForDraw() override;

  // Returns the union of |old_trail_damage_rect_| and |new_trail_damage_rect_|.
  gfx::Rect GetDamageRect() override;

  // Draw the delegated ink trail to the provided canvas. Since the trail is
  // stored in root (metadata) space, it needs to be transformed to render pass
  // space.
  void DrawDelegatedInkTrail(SkCanvas* canvas,
                             const gfx::Transform& transform_to_render_pass);

 private:
  void SetDamageRect(gfx::RectF);

  // First filters the points that are stored to only keep points with a
  // timestamp equal to or later than |metadata_|'s, then predict points if
  // possible. Then converts those points into SkPoints and returns them.
  std::vector<SkPoint> GetPointsToDraw();

  int GetPathPointCountForTest() const override;

  // The path that will be drawn in DrawDelegatedInkTrail(). See class comments
  // and FinalizePathForDraw() comment to understand when and why this is
  // updated.
  SkPath path_;

  // The damage rects for the trail currently on the screen, and the next one
  // to be drawn, as of the DrawDelegatedInkTrail() call.
  gfx::RectF old_trail_damage_rect_;
  gfx::RectF new_trail_damage_rect_;
};

}  // namespace viz

#endif  // COMPONENTS_VIZ_SERVICE_DISPLAY_DELEGATED_INK_POINT_RENDERER_SKIA_H_