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 
5 #ifndef COMPONENTS_VIZ_SERVICE_DISPLAY_DELEGATED_INK_POINT_PIXEL_TEST_HELPER_H_
6 #define COMPONENTS_VIZ_SERVICE_DISPLAY_DELEGATED_INK_POINT_PIXEL_TEST_HELPER_H_
7 
8 #include <vector>
9 
10 #include "components/viz/common/delegated_ink_metadata.h"
11 
12 namespace viz {
13 
14 class DelegatedInkPoint;
15 class DelegatedInkPointRendererBase;
16 class DirectRenderer;
17 
18 // Helper class for running pixel tests to flex the delegated ink point
19 // renderers. |renderer_| must be supplied, either when constructed or later
20 // after cc::PixelTest::SetUp() has run, which creates the renderer. Then it
21 // can be used to create and give ink metadata and points to |renderer_|'s
22 // delegated ink point renderer. The metadata and points are stored so that the
23 // information can be used for future points and metadata (i.e. when a point
24 // needs to match the metadata for the first point of a trail) or when
25 // determining the damage rect to apply to a render pass.
26 class DelegatedInkPointPixelTestHelper {
27  public:
28   DelegatedInkPointPixelTestHelper();
29   ~DelegatedInkPointPixelTestHelper();
30 
31   explicit DelegatedInkPointPixelTestHelper(DirectRenderer* renderer);
32   void SetRendererAndCreateInkRenderer(DirectRenderer* renderer);
33   DelegatedInkPointRendererBase* GetInkRenderer();
34 
35   void CreateAndSendMetadata(const gfx::PointF& point,
36                              float diameter,
37                              SkColor color,
38                              const gfx::RectF& presentation_area);
39 
40   void CreateAndSendMetadataFromLastPoint();
41 
42   void CreateAndSendPoint(const gfx::PointF& point, base::TimeTicks timestamp);
43   void CreateAndSendPointFromMetadata();
44   // Used when sending multiple points to be drawn as a single trail, so it uses
45   // the most recently provided point's timestamp to determine the new one.
46   void CreateAndSendPointFromLastPoint(const gfx::PointF& point);
47 
48   gfx::Rect GetDelegatedInkDamageRect();
49 
metadata()50   const DelegatedInkMetadata& metadata() { return metadata_; }
51 
52  private:
53   DirectRenderer* renderer_ = nullptr;
54   std::vector<DelegatedInkPoint> ink_points_;
55   DelegatedInkMetadata metadata_;
56 };
57 
58 }  // namespace viz
59 
60 #endif  // COMPONENTS_VIZ_SERVICE_DISPLAY_DELEGATED_INK_POINT_PIXEL_TEST_HELPER_H_
61