Flutter Engine
The 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
5#include "flutter/flow/testing/mock_texture.h"
6
7#include "flutter/display_list/dl_builder.h"
8#include "flutter/testing/display_list_testing.h"
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 SkRect paint_bounds1 = SkRect::MakeWH(1.0f, 1.0f);
33 const SkRect paint_bounds2 = SkRect::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 SkRect src1 = SkRect::Make(texture_image->bounds());
45 SkRect src2 = src1.makeInset(1.0, 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);
51 DisplayListsEQ_Verbose(builder.Build(), expected_builder.Build()));
52}
53
54TEST(MockTextureTest, PaintCallsWithLinearSampling) {
55 DisplayListBuilder builder;
56 const SkRect paint_bounds1 = SkRect::MakeWH(1.0f, 1.0f);
57 const SkRect paint_bounds2 = SkRect::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 SkRect src1 = SkRect::Make(texture_image->bounds());
69 SkRect src2 = src1.makeInset(1.0, 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);
75 DisplayListsEQ_Verbose(builder.Build(), expected_builder.Build()));
76}
77
78} // namespace testing
79} // namespace flutter
#define TEST(S, s, D, expected)
sk_sp< DisplayList > Build()
Definition dl_builder.cc:67
void DrawImageRect(const sk_sp< DlImage > &image, const SkRect &src, const SkRect &dst, DlImageSampling sampling, const DlPaint *paint=nullptr, SrcRectConstraint constraint=SrcRectConstraint::kFast) override
static sk_sp< DlImage > MakeTestTexture(int w, int h, int checker_size)
FlTexture * texture
bool DisplayListsEQ_Verbose(const DisplayList *a, const DisplayList *b)
static SkRect Make(const SkISize &size)
Definition SkRect.h:669
SkRect makeInset(float dx, float dy) const
Definition SkRect.h:987
static constexpr SkRect MakeWH(float w, float h)
Definition SkRect.h:609
#define EXPECT_TRUE(handle)
Definition unit_test.h:685