Flutter Engine
mock_texture_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/testing/mock_texture.h"
6 
7 #include "gtest/gtest.h"
8 
9 namespace flutter {
10 namespace testing {
11 
12 TEST(MockTextureTest, Callbacks) {
13  auto texture = std::make_shared<MockTexture>(0);
14 
15  ASSERT_FALSE(texture->gr_context_created());
16  texture->OnGrContextCreated();
17  ASSERT_TRUE(texture->gr_context_created());
18 
19  ASSERT_FALSE(texture->gr_context_destroyed());
20  texture->OnGrContextDestroyed();
21  ASSERT_TRUE(texture->gr_context_destroyed());
22 
23  ASSERT_FALSE(texture->unregistered());
24  texture->OnTextureUnregistered();
25  ASSERT_TRUE(texture->unregistered());
26 }
27 
28 TEST(MockTextureTest, PaintCalls) {
29  SkCanvas canvas;
30  const SkRect paint_bounds1 = SkRect::MakeWH(1.0f, 1.0f);
31  const SkRect paint_bounds2 = SkRect::MakeWH(2.0f, 2.0f);
32  const SkSamplingOptions sampling;
33  const auto expected_paint_calls = std::vector{
34  MockTexture::PaintCall{canvas, paint_bounds1, false, nullptr, sampling},
35  MockTexture::PaintCall{canvas, paint_bounds2, true, nullptr, sampling}};
36  auto texture = std::make_shared<MockTexture>(0);
37 
38  texture->Paint(canvas, paint_bounds1, false, nullptr, sampling);
39  texture->Paint(canvas, paint_bounds2, true, nullptr, sampling);
40  EXPECT_EQ(texture->paint_calls(), expected_paint_calls);
41 }
42 
43 TEST(MockTextureTest, PaintCallsWithLinearSampling) {
44  SkCanvas canvas;
45  const SkRect paint_bounds1 = SkRect::MakeWH(1.0f, 1.0f);
46  const SkRect paint_bounds2 = SkRect::MakeWH(2.0f, 2.0f);
47  const auto sampling = SkSamplingOptions(SkFilterMode::kLinear);
48  const auto expected_paint_calls = std::vector{
49  MockTexture::PaintCall{canvas, paint_bounds1, false, nullptr, sampling},
50  MockTexture::PaintCall{canvas, paint_bounds2, true, nullptr, sampling}};
51  auto texture = std::make_shared<MockTexture>(0);
52 
53  texture->Paint(canvas, paint_bounds1, false, nullptr, sampling);
54  texture->Paint(canvas, paint_bounds2, true, nullptr, sampling);
55  EXPECT_EQ(texture->paint_calls(), expected_paint_calls);
56 }
57 
58 } // namespace testing
59 } // namespace flutter
G_BEGIN_DECLS FlTexture * texture
TEST(DisplayListCanvas, DrawPaint)