1 | // Copyright 2013 The Flutter 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 FLOW_TESTING_MOCK_LAYER_H_ |
6 | #define FLOW_TESTING_MOCK_LAYER_H_ |
7 | |
8 | #include "flutter/flow/layers/layer.h" |
9 | |
10 | namespace flutter { |
11 | namespace testing { |
12 | |
13 | // Mock implementation of the |Layer| interface that does nothing but paint |
14 | // the specified |path| into the canvas. It records the |PrerollContext| and |
15 | // |PaintContext| data passed in by its parent |Layer|, so the test can later |
16 | // verify the data against expected values. |
17 | class MockLayer : public Layer { |
18 | public: |
19 | MockLayer(SkPath path, |
20 | SkPaint paint = SkPaint(), |
21 | bool fake_has_platform_view = false, |
22 | bool fake_needs_system_composite = false, |
23 | bool fake_reads_surface = false); |
24 | |
25 | void Preroll(PrerollContext* context, const SkMatrix& matrix) override; |
26 | void Paint(PaintContext& context) const override; |
27 | |
28 | const MutatorsStack& parent_mutators() { return parent_mutators_; } |
29 | const SkMatrix& parent_matrix() { return parent_matrix_; } |
30 | const SkRect& parent_cull_rect() { return parent_cull_rect_; } |
31 | bool parent_has_platform_view() { return parent_has_platform_view_; } |
32 | |
33 | private: |
34 | MutatorsStack parent_mutators_; |
35 | SkMatrix parent_matrix_; |
36 | SkRect parent_cull_rect_ = SkRect::MakeEmpty(); |
37 | SkPath fake_paint_path_; |
38 | SkPaint fake_paint_; |
39 | bool parent_has_platform_view_ = false; |
40 | bool fake_has_platform_view_ = false; |
41 | bool fake_needs_system_composite_ = false; |
42 | bool fake_reads_surface_ = false; |
43 | |
44 | FML_DISALLOW_COPY_AND_ASSIGN(MockLayer); |
45 | }; |
46 | |
47 | } // namespace testing |
48 | } // namespace flutter |
49 | |
50 | #endif // FLOW_TESTING_MOCK_LAYER_H_ |
51 | |