5#include "flutter/flow/layers/performance_overlay_layer.h"
10#include "flutter/flow/flow_test_utils.h"
11#include "flutter/flow/raster_cache.h"
12#include "flutter/flow/testing/layer_test.h"
13#include "flutter/shell/common/base64.h"
14#include "flutter/testing/mock_canvas.h"
28template <
class T, std::
size_t N>
29constexpr int size(
const T (&array)[
N])
noexcept {
33constexpr int kMockedTimes[] = {17, 1, 4, 24, 4, 25, 30, 4, 13, 34,
34 14, 0, 18, 9, 32, 36, 26, 23, 5, 8,
35 32, 18, 29, 16, 29, 18, 0, 36, 33, 10};
37static std::string GetGoldenFilePath(
int refresh_rate,
bool is_new) {
42 << refresh_rate <<
"fps" << (is_new ?
"_new" :
"") <<
".png";
46static void TestPerformanceOverlayLayerGold(
int refresh_rate) {
47 std::string golden_file_path = GetGoldenFilePath(refresh_rate,
false);
48 std::string new_golden_file_path = GetGoldenFilePath(refresh_rate,
true);
50 FixedRefreshRateStopwatch mock_stopwatch(
52 for (
int i = 0;
i <
size(kMockedTimes); ++
i) {
53 mock_stopwatch.SetLapTime(
59 DlSkCanvasAdapter canvas(
surface->getCanvas());
61 ASSERT_TRUE(
surface !=
nullptr);
63 LayerStateStack state_stack;
64 state_stack.set_delegate(&canvas);
70 .gr_context =
nullptr,
71 .view_embedder =
nullptr,
72 .raster_time = mock_stopwatch,
73 .ui_time = mock_stopwatch,
74 .texture_registry =
nullptr,
75 .raster_cache =
nullptr,
89 layer.Paint(paint_context);
98 <<
"Golden file not found: " << golden_file_path <<
".\n"
99 <<
"Please either set --golden-dir, or make sure that the unit test is "
100 <<
"run from the right directory (e.g., flutter/engine/src).";
104#if !defined(FML_OS_LINUX)
105 GTEST_SKIP() <<
"Skipping golden tests on non-Linux OSes";
107 const bool golden_data_matches = golden_data->
equals(snapshot_data.
get());
108 if (!golden_data_matches) {
110 wstream.write(snapshot_data->
data(), snapshot_data->
size());
115 char* b64_char =
static_cast<char*
>(b64_data->
writable_data());
117 b64_char[b64_size] = 0;
120 <<
"Golden file mismatch. Please check " <<
"the difference between "
121 << golden_file_path <<
" and " << new_golden_file_path
122 <<
", and replace the former "
123 <<
"with the latter if the difference looks good.\nS\n"
124 <<
"See also the base64 encoded " << new_golden_file_path <<
":\n"
136 auto layer = std::make_shared<PerformanceOverlayLayer>(overlay_opts);
138 layer->Preroll(preroll_context());
140 EXPECT_FALSE(layer->needs_painting(paint_context()));
143 EXPECT_DEATH_IF_SUPPORTED(layer->Paint(paint_context()),
"");
148 const uint64_t overlay_opts = 0;
149 auto layer = std::make_shared<PerformanceOverlayLayer>(overlay_opts);
153 layer->set_paint_bounds(layer_bounds);
155 layer->Preroll(preroll_context());
156 EXPECT_EQ(layer->paint_bounds(), layer_bounds);
157 EXPECT_TRUE(layer->needs_painting(paint_context()));
160 layer->Paint(paint_context());
161 EXPECT_EQ(mock_canvas().draw_calls(), std::vector<MockCanvas::DrawCall>());
167 auto layer = std::make_shared<PerformanceOverlayLayer>(overlay_opts);
171 layer->set_paint_bounds(layer_bounds);
173 layer->Preroll(preroll_context());
174 EXPECT_EQ(layer->paint_bounds(), layer_bounds);
175 EXPECT_TRUE(layer->needs_painting(paint_context()));
177 layer->Paint(paint_context());
179 paint_context().raster_time,
"Raster",
"");
180 auto overlay_text_data = overlay_text->serialize(
SkSerialProcs{});
188#if defined(OS_FUCHSIA)
189 GTEST_SKIP() <<
"Expectation requires a valid default font manager";
191 EXPECT_EQ(mock_canvas().draw_calls(),
202 auto layer = std::make_shared<PerformanceOverlayLayer>(overlay_opts);
204 layer->Preroll(preroll_context());
205 layer->Paint(paint_context());
206 auto data = mock_canvas().draw_calls().front().data;
207 auto image_data = std::get<MockCanvas::DrawImageDataNoPaint>(
data);
208 auto first_draw_width = image_data.image->width();
211 layer = std::make_shared<PerformanceOverlayLayer>(overlay_opts);
213 layer->Preroll(preroll_context());
214 layer->Paint(paint_context());
215 data = mock_canvas().draw_calls().back().data;
216 image_data = std::get<MockCanvas::DrawImageDataNoPaint>(
data);
217 auto refreshed_draw_width = image_data.image->width();
219 EXPECT_NE(first_draw_width, refreshed_draw_width);
223 TestPerformanceOverlayLayerGold(60);
227 TestPerformanceOverlayLayerGold(90);
231 TestPerformanceOverlayLayerGold(120);
constexpr SkColor SK_ColorTRANSPARENT
static sk_sp< SkData > MakeUninitialized(size_t length)
bool equals(const SkData *other) const
const void * data() const
static sk_sp< SkData > MakeFromFileName(const char path[])
static constexpr TimeDelta FromMilliseconds(int64_t millis)
SK_API bool Encode(SkWStream *dst, const SkPixmap &src, const Options &options)
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
TEST_F(DisplayListTest, Defaults)
LayerTestBase<::testing::Test > LayerTest
TEST(DisplayListComplexity, EmptyDisplayList)
const int kVisualizeEngineStatistics
const std::string & GetFontFile()
const int kDisplayEngineStatistics
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
const int kVisualizeRasterizerStatistics
const int kDisplayRasterizerStatistics
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
const std::string & GetGoldenDir()
Milliseconds RefreshRateToFrameBudget(T refresh_rate)
static SkImageInfo MakeN32Premul(int width, int height)
static constexpr SkPoint Make(float x, float y)
static constexpr SkRect MakeEmpty()
static constexpr SkRect MakeWH(float w, float h)
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
static size_t Encode(const void *src, size_t length, void *dst)
static size_t EncodedSize(size_t srcDataLength)
LayerStateStack & state_stack
#define EXPECT_TRUE(handle)