Flutter Engine
 
Loading...
Searching...
No Matches
golden_tests.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
7#include "gtest/gtest.h"
8
9#include <sstream>
10
16#include "impeller/display_list/dl_dispatcher.h" // nogncheck
21
22namespace impeller {
23namespace testing {
24
25namespace {
26std::string GetTestName() {
27 std::string suite_name =
28 ::testing::UnitTest::GetInstance()->current_test_suite()->name();
29 std::string test_name =
30 ::testing::UnitTest::GetInstance()->current_test_info()->name();
31 std::stringstream ss;
32 ss << "impeller_" << suite_name << "_" << test_name;
33 return ss.str();
34}
35
36std::string GetGoldenFilename() {
37 return GetTestName() + ".png";
38}
39
40bool SaveScreenshot(std::unique_ptr<Screenshot> screenshot) {
41 if (!screenshot || !screenshot->GetBytes()) {
42 return false;
43 }
44 std::string test_name = GetTestName();
45 std::string filename = GetGoldenFilename();
47 test_name, filename, screenshot->GetWidth(), screenshot->GetHeight());
48 return screenshot->WriteToPNG(
49 WorkingDirectory::Instance()->GetFilenamePath(filename));
50}
51
52PlaygroundSwitches GetPlaygroundSwitches() {
53 PlaygroundSwitches switches;
54 switches.enable_wide_gamut = false;
55 return switches;
56}
57} // namespace
58
59class GoldenTests : public ::testing::Test {
60 public:
62 : screenshotter_(new MetalScreenshotter(GetPlaygroundSwitches())) {}
63
64 MetalScreenshotter& Screenshotter() { return *screenshotter_; }
65
66 void SetUp() override {
68 "gpu_string",
69 Screenshotter().GetPlayground().GetContext()->DescribeGpuModel());
70 }
71
72 private:
73 // This must be placed before any other members that may use the
74 // autorelease pool.
75 fml::ScopedNSAutoreleasePool autorelease_pool_;
76
77 std::unique_ptr<MetalScreenshotter> screenshotter_;
78};
79
80TEST_F(GoldenTests, ConicalGradient) {
82 flutter::DlPaint paint;
84
85 flutter::DlColor colors[2] = {flutter::DlColor::RGBA(1, 0, 0, 1),
86 flutter::DlColor::RGBA(0, 0, 1, 1)};
87 Scalar stops[2] = {0, 1};
88
90 /*start_center=*/{125, 125}, //
91 /*start_radius=*/125, {180, 180}, //
92 /*end_radius=*/0, //
93 /*stop_count=*/2, //
94 /*colors=*/colors, //
95 /*stops=*/stops, //
96 /*tile_mode=*/flutter::DlTileMode::kClamp //
97 ));
98
99 builder.DrawRect(DlRect::MakeXYWH(10, 10, 250, 250), paint);
100
101 auto aiks_context =
102 AiksContext(Screenshotter().GetPlayground().GetContext(), nullptr);
103 auto screenshot = Screenshotter().MakeScreenshot(
104 aiks_context,
105 DisplayListToTexture(builder.Build(), {240, 240}, aiks_context));
106 ASSERT_TRUE(SaveScreenshot(std::move(screenshot)));
107}
108} // namespace testing
109} // namespace impeller
sk_sp< DisplayList > Build()
Definition dl_builder.cc:66
void DrawRect(const DlRect &rect, const DlPaint &paint) override
static std::shared_ptr< DlColorSource > MakeConical(DlPoint start_center, DlScalar start_radius, DlPoint end_center, DlScalar end_radius, uint32_t stop_count, const DlColor *colors, const float *stops, DlTileMode tile_mode, const DlMatrix *matrix=nullptr)
DlPaint & setDrawStyle(DlDrawStyle style)
Definition dl_paint.h:93
DlPaint & setColorSource(std::nullptr_t source)
Definition dl_paint.h:131
static GoldenDigest * Instance()
void AddDimension(const std::string &name, const std::string &value)
void AddImage(const std::string &test_name, const std::string &filename, int32_t width, int32_t height)
MetalScreenshotter & Screenshotter()
virtual std::unique_ptr< Screenshot > MakeScreenshot(AiksContext &aiks_context, const std::shared_ptr< Texture > texture)=0
static WorkingDirectory * Instance()
@ kFill
fills interior of shapes
TEST_F(GoldenTests, ConicalGradient)
std::shared_ptr< Texture > DisplayListToTexture(const sk_sp< flutter::DisplayList > &display_list, ISize size, AiksContext &context, bool reset_host_buffer, bool generate_mips)
Render the provided display list to a texture with the given size.
float Scalar
Definition scalar.h:19
static constexpr DlColor RGBA(DlScalar r, DlScalar g, DlScalar b, DlScalar a)
Construct a 32 bit color from floating point R, G, B, and A color channels.
Definition dl_color.h:48
static constexpr TRect MakeXYWH(Type x, Type y, Type width, Type height)
Definition rect.h:136