Flutter Engine
texture_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/texture_layer.h"
6 
7 #include "flutter/flow/testing/layer_test.h"
8 #include "flutter/flow/testing/mock_layer.h"
9 #include "flutter/flow/testing/mock_texture.h"
10 #include "flutter/fml/macros.h"
11 #include "flutter/testing/mock_canvas.h"
12 
13 namespace flutter {
14 namespace testing {
15 
17 
18 TEST_F(TextureLayerTest, InvalidTexture) {
19  const SkPoint layer_offset = SkPoint::Make(0.0f, 0.0f);
20  const SkSize layer_size = SkSize::Make(8.0f, 8.0f);
21  auto layer = std::make_shared<TextureLayer>(layer_offset, layer_size, 0,
22  false, SkSamplingOptions());
23 
24  layer->Preroll(preroll_context(), SkMatrix());
25  EXPECT_EQ(layer->paint_bounds(),
26  (SkRect::MakeSize(layer_size)
27  .makeOffset(layer_offset.fX, layer_offset.fY)));
28  EXPECT_TRUE(layer->needs_painting(paint_context()));
29 
30  layer->Paint(paint_context());
31  EXPECT_EQ(mock_canvas().draw_calls(), std::vector<MockCanvas::DrawCall>());
32 }
33 
34 #ifndef NDEBUG
35 TEST_F(TextureLayerTest, PaintingEmptyLayerDies) {
36  const SkPoint layer_offset = SkPoint::Make(0.0f, 0.0f);
37  const SkSize layer_size = SkSize::Make(0.0f, 0.0f);
38  const int64_t texture_id = 0;
39  auto mock_texture = std::make_shared<MockTexture>(texture_id);
40  auto layer = std::make_shared<TextureLayer>(
41  layer_offset, layer_size, texture_id, false, SkSamplingOptions());
42 
43  // Ensure the texture is located by the Layer.
44  preroll_context()->texture_registry.RegisterTexture(mock_texture);
45 
46  layer->Preroll(preroll_context(), SkMatrix());
47  EXPECT_EQ(layer->paint_bounds(), kEmptyRect);
48  EXPECT_FALSE(layer->needs_painting(paint_context()));
49 
50  EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()),
51  "needs_painting\\(context\\)");
52 }
53 
54 TEST_F(TextureLayerTest, PaintBeforePrerollDies) {
55  const SkPoint layer_offset = SkPoint::Make(0.0f, 0.0f);
56  const SkSize layer_size = SkSize::Make(8.0f, 8.0f);
57  const int64_t texture_id = 0;
58  auto mock_texture = std::make_shared<MockTexture>(texture_id);
59  auto layer = std::make_shared<TextureLayer>(
60  layer_offset, layer_size, texture_id, false,
61  SkSamplingOptions(SkFilterMode::kLinear));
62 
63  // Ensure the texture is located by the Layer.
64  preroll_context()->texture_registry.RegisterTexture(mock_texture);
65 
66  EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()),
67  "needs_painting\\(context\\)");
68 }
69 #endif
70 
71 TEST_F(TextureLayerTest, PaintingWithLinearSampling) {
72  const SkPoint layer_offset = SkPoint::Make(0.0f, 0.0f);
73  const SkSize layer_size = SkSize::Make(8.0f, 8.0f);
74  const int64_t texture_id = 0;
75  auto mock_texture = std::make_shared<MockTexture>(texture_id);
76  auto layer = std::make_shared<TextureLayer>(
77  layer_offset, layer_size, texture_id, false,
78  SkSamplingOptions(SkFilterMode::kLinear));
79 
80  // Ensure the texture is located by the Layer.
81  preroll_context()->texture_registry.RegisterTexture(mock_texture);
82 
83  layer->Preroll(preroll_context(), SkMatrix());
84  EXPECT_EQ(layer->paint_bounds(),
85  (SkRect::MakeSize(layer_size)
86  .makeOffset(layer_offset.fX, layer_offset.fY)));
87  EXPECT_TRUE(layer->needs_painting(paint_context()));
88 
89  layer->Paint(paint_context());
90  EXPECT_EQ(mock_texture->paint_calls(),
91  std::vector({MockTexture::PaintCall{
92  mock_canvas(), layer->paint_bounds(), false, nullptr,
93  SkSamplingOptions(SkFilterMode::kLinear)}}));
94  EXPECT_EQ(mock_canvas().draw_calls(), std::vector<MockCanvas::DrawCall>());
95 }
96 
97 } // namespace testing
98 } // namespace flutter
int64_t texture_id
LayerTestBase<::testing::Test > LayerTest
Definition: layer_test.h:151
TEST_F(BackdropFilterLayerTest, PaintingEmptyLayerDies)
static constexpr SkRect kEmptyRect
Definition: mock_canvas.h:28