Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
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
20
21namespace impeller {
22namespace testing {
23
24namespace {
25std::string GetTestName() {
26 std::string suite_name =
27 ::testing::UnitTest::GetInstance()->current_test_suite()->name();
28 std::string test_name =
29 ::testing::UnitTest::GetInstance()->current_test_info()->name();
30 std::stringstream ss;
31 ss << "impeller_" << suite_name << "_" << test_name;
32 return ss.str();
33}
34
35std::string GetGoldenFilename() {
36 return GetTestName() + ".png";
37}
38
39bool SaveScreenshot(std::unique_ptr<Screenshot> screenshot) {
40 if (!screenshot || !screenshot->GetBytes()) {
41 return false;
42 }
43 std::string test_name = GetTestName();
44 std::string filename = GetGoldenFilename();
46 test_name, filename, screenshot->GetWidth(), screenshot->GetHeight());
47 return screenshot->WriteToPNG(
48 WorkingDirectory::Instance()->GetFilenamePath(filename));
49}
50
51PlaygroundSwitches GetPlaygroundSwitches() {
52 PlaygroundSwitches switches;
53 switches.enable_wide_gamut = false;
54 return switches;
55}
56} // namespace
57
58class GoldenTests : public ::testing::Test {
59 public:
61 : screenshotter_(new MetalGoldenScreenshotter(GetPlaygroundSwitches())) {}
62
63 MetalGoldenScreenshotter& Screenshotter() { return *screenshotter_; }
64
65 void SetUp() override {
67 "gpu_string",
68 Screenshotter().GetPlayground().GetContext()->DescribeGpuModel());
69 }
70
71 private:
72 // This must be placed before any other members that may use the
73 // autorelease pool.
74 fml::ScopedNSAutoreleasePool autorelease_pool_;
75
76 std::unique_ptr<MetalGoldenScreenshotter> screenshotter_;
77};
78
79TEST_F(GoldenTests, ConicalGradient) {
81 flutter::DlPaint paint;
83
84 flutter::DlColor colors[2] = {flutter::DlColor::RGBA(1, 0, 0, 1),
85 flutter::DlColor::RGBA(0, 0, 1, 1)};
86 Scalar stops[2] = {0, 1};
87
89 /*start_center=*/{125, 125}, //
90 /*start_radius=*/125, {180, 180}, //
91 /*end_radius=*/0, //
92 /*stop_count=*/2, //
93 /*colors=*/colors, //
94 /*stops=*/stops, //
95 /*tile_mode=*/flutter::DlTileMode::kClamp //
96 ));
97
98 builder.DrawRect(DlRect::MakeXYWH(10, 10, 250, 250), paint);
99
100 auto aiks_context =
101 AiksContext(Screenshotter().GetPlayground().GetContext(), nullptr);
102 auto screenshot = Screenshotter().MakeScreenshot(
103 aiks_context,
104 DisplayListToTexture(builder.Build(), {240, 240}, aiks_context));
105 ASSERT_TRUE(SaveScreenshot(std::move(screenshot)));
106}
107} // namespace testing
108} // namespace impeller
sk_sp< DisplayList > Build()
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)
MetalGoldenScreenshotter & Screenshotter()
static std::unique_ptr< Screenshot > MakeScreenshot(std::shared_ptr< Context > &context, const std::shared_ptr< Texture > &texture)
static WorkingDirectory * Instance()
@ kFill
fills interior of shapes
TEST_F(GoldenTests, ConicalGradient)
float Scalar
Definition scalar.h:19
std::shared_ptr< Texture > DisplayListToTexture(const sk_sp< flutter::DisplayList > &display_list, ISize size, AiksContext &context, bool reset_host_buffer, bool generate_mips, std::optional< PixelFormat > target_pixel_format)
Render the provided display list to a texture with the given size.
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