Flutter Engine
platform_view_layer_unittests.cc
Go to the documentation of this file.
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 #include "flutter/flow/layers/clip_rect_layer.h"
6 #include "flutter/flow/layers/platform_view_layer.h"
7 
8 #include "flutter/flow/testing/layer_test.h"
9 #include "flutter/flow/testing/mock_embedder.h"
10 #include "flutter/flow/testing/mock_layer.h"
11 #include "flutter/fml/macros.h"
12 #include "flutter/testing/mock_canvas.h"
13 
14 namespace flutter {
15 namespace testing {
16 
18 
19 TEST_F(PlatformViewLayerTest, NullViewEmbedderDoesntPrerollCompositeOrPaint) {
20  const SkPoint layer_offset = SkPoint::Make(0.0f, 0.0f);
21  const SkSize layer_size = SkSize::Make(8.0f, 8.0f);
22  const int64_t view_id = 0;
23  auto layer =
24  std::make_shared<PlatformViewLayer>(layer_offset, layer_size, view_id);
25 
26  layer->Preroll(preroll_context(), SkMatrix());
27  EXPECT_FALSE(preroll_context()->has_platform_view);
28  EXPECT_EQ(layer->paint_bounds(),
29  SkRect::MakeSize(layer_size)
30  .makeOffset(layer_offset.fX, layer_offset.fY));
31  EXPECT_TRUE(layer->needs_painting(paint_context()));
32  EXPECT_FALSE(layer->subtree_has_platform_view());
33 
34  layer->Paint(paint_context());
35  EXPECT_EQ(paint_context().leaf_nodes_canvas, &mock_canvas());
36  EXPECT_EQ(mock_canvas().draw_calls(), std::vector<MockCanvas::DrawCall>());
37 }
38 
39 TEST_F(PlatformViewLayerTest, ClippedPlatformViewPrerollsAndPaintsNothing) {
40  const SkPoint layer_offset = SkPoint::Make(0.0f, 0.0f);
41  const SkSize layer_size = SkSize::Make(8.0f, 8.0f);
42  const SkRect child_clip = SkRect::MakeLTRB(20.0f, 20.0f, 40.0f, 40.0f);
43  const SkRect parent_clip = SkRect::MakeLTRB(50.0f, 50.0f, 80.0f, 80.0f);
44  const int64_t view_id = 0;
45  auto layer =
46  std::make_shared<PlatformViewLayer>(layer_offset, layer_size, view_id);
47  auto child_clip_layer =
48  std::make_shared<ClipRectLayer>(child_clip, Clip::hardEdge);
49  auto parent_clip_layer =
50  std::make_shared<ClipRectLayer>(parent_clip, Clip::hardEdge);
51  parent_clip_layer->Add(child_clip_layer);
52  child_clip_layer->Add(layer);
53 
54  auto embedder = MockViewEmbedder();
55  preroll_context()->view_embedder = &embedder;
56 
57  parent_clip_layer->Preroll(preroll_context(), SkMatrix());
58  EXPECT_TRUE(preroll_context()->has_platform_view);
59  EXPECT_EQ(layer->paint_bounds(),
60  SkRect::MakeSize(layer_size)
61  .makeOffset(layer_offset.fX, layer_offset.fY));
62  EXPECT_TRUE(layer->needs_painting(paint_context()));
63  EXPECT_TRUE(child_clip_layer->needs_painting(paint_context()));
64  EXPECT_TRUE(parent_clip_layer->needs_painting(paint_context()));
65  EXPECT_TRUE(layer->subtree_has_platform_view());
66  EXPECT_TRUE(child_clip_layer->subtree_has_platform_view());
67  EXPECT_TRUE(parent_clip_layer->subtree_has_platform_view());
68 
69  parent_clip_layer->Paint(paint_context());
70  EXPECT_EQ(paint_context().leaf_nodes_canvas, &mock_canvas());
71  EXPECT_EQ(
72  mock_canvas().draw_calls(),
73  std::vector(
76  1, MockCanvas::ClipRectData{parent_clip, SkClipOp::kIntersect,
77  MockCanvas::kHard_ClipEdgeStyle}},
80  2, MockCanvas::ClipRectData{child_clip, SkClipOp::kIntersect,
81  MockCanvas::kHard_ClipEdgeStyle}},
84 }
85 
86 } // namespace testing
87 } // namespace flutter
LayerTestBase<::testing::Test > LayerTest
Definition: layer_test.h:151
TEST_F(BackdropFilterLayerTest, PaintingEmptyLayerDies)