Flutter Engine
 
Loading...
Searching...
No Matches
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
6
9#include "gtest/gtest.h"
10
11namespace flutter {
12namespace testing {
13
14TEST(MockTextureTest, Callbacks) {
15 auto texture = std::make_shared<MockTexture>(0);
16
17 ASSERT_FALSE(texture->gr_context_created());
18 texture->OnGrContextCreated();
19 ASSERT_TRUE(texture->gr_context_created());
20
21 ASSERT_FALSE(texture->gr_context_destroyed());
22 texture->OnGrContextDestroyed();
23 ASSERT_TRUE(texture->gr_context_destroyed());
24
25 ASSERT_FALSE(texture->unregistered());
26 texture->OnTextureUnregistered();
27 ASSERT_TRUE(texture->unregistered());
28}
29
30TEST(MockTextureTest, PaintCalls) {
31 DisplayListBuilder builder;
32 const DlRect paint_bounds1 = DlRect::MakeWH(1.0f, 1.0f);
33 const DlRect paint_bounds2 = DlRect::MakeWH(2.0f, 2.0f);
35 const auto texture_image = MockTexture::MakeTestTexture(20, 20, 5);
36 auto texture = std::make_shared<MockTexture>(0, texture_image);
37
39 .canvas = &builder,
40 };
41 texture->Paint(context, paint_bounds1, false, sampling);
42 texture->Paint(context, paint_bounds2, true, sampling);
43
44 DlRect src1 = DlRect::Make(texture_image->GetBounds());
45 DlRect src2 = src1.Expand(-1.0f, -1.0f);
46
47 DisplayListBuilder expected_builder;
48 expected_builder.DrawImageRect(texture_image, src1, paint_bounds1, sampling);
49 expected_builder.DrawImageRect(texture_image, src2, paint_bounds2, sampling);
50 EXPECT_TRUE(
51 DisplayListsEQ_Verbose(builder.Build(), expected_builder.Build()));
52}
53
54TEST(MockTextureTest, PaintCallsWithLinearSampling) {
55 DisplayListBuilder builder;
56 const DlRect paint_bounds1 = DlRect::MakeWH(1.0f, 1.0f);
57 const DlRect paint_bounds2 = DlRect::MakeWH(2.0f, 2.0f);
58 const auto sampling = DlImageSampling::kLinear;
59 const auto texture_image = MockTexture::MakeTestTexture(20, 20, 5);
60 auto texture = std::make_shared<MockTexture>(0, texture_image);
61
63 .canvas = &builder,
64 };
65 texture->Paint(context, paint_bounds1, false, sampling);
66 texture->Paint(context, paint_bounds2, true, sampling);
67
68 DlRect src1 = DlRect::Make(texture_image->GetBounds());
69 DlRect src2 = src1.Expand(-1.0f, -1.0f);
70
71 DisplayListBuilder expected_builder;
72 expected_builder.DrawImageRect(texture_image, src1, paint_bounds1, sampling);
73 expected_builder.DrawImageRect(texture_image, src2, paint_bounds2, sampling);
74 EXPECT_TRUE(
75 DisplayListsEQ_Verbose(builder.Build(), expected_builder.Build()));
76}
77
78} // namespace testing
79} // namespace flutter
void DrawImageRect(const sk_sp< DlImage > &image, const DlRect &src, const DlRect &dst, DlImageSampling sampling, const DlPaint *paint=nullptr, DlSrcRectConstraint constraint=DlSrcRectConstraint::kFast) override
sk_sp< DisplayList > Build()
Definition dl_builder.cc:66
static sk_sp< DlImage > MakeTestTexture(int w, int h, int checker_size)
FlTexture * texture
TEST(NativeAssetsManagerTest, NoAvailableAssets)
bool DisplayListsEQ_Verbose(const DisplayList *a, const DisplayList *b)
static constexpr TRect MakeWH(Type width, Type height)
Definition rect.h:140
static constexpr std::enable_if_t< std::is_floating_point_v< FT >, TRect > Make(const TRect< U > &rect)
Definition rect.h:157
constexpr TRect< T > Expand(T left, T top, T right, T bottom) const
Returns a rectangle with expanded edges. Negative expansion results in shrinking.
Definition rect.h:618