1414#include " flutter/fml/log_settings.h"
1515#include " flutter/fml/unique_fd.h"
1616#include " flutter/shell/common/persistent_cache.h"
17+ #include " flutter/shell/common/serialization_callbacks.h"
1718#include " flutter/shell/common/shell_test.h"
1819#include " flutter/shell/common/switches.h"
1920#include " flutter/shell/version/version.h"
2021#include " flutter/testing/testing.h"
2122#include " include/core/SkPicture.h"
23+ #include " include/core/SkPictureRecorder.h"
24+ #include " include/core/SkSerialProcs.h"
2225
2326namespace flutter {
2427namespace testing {
@@ -36,7 +39,7 @@ class SkpWarmupTest : public ShellTest {
3639 public:
3740 SkpWarmupTest () {}
3841
39- void TestWarmup (const LayerTreeBuilder& builder) {
42+ void TestWarmup (const SkISize& draw_size, const LayerTreeBuilder& builder) {
4043 // Create a temp dir to store the persistent cache
4144 fml::ScopedTemporaryDirectory dir;
4245 PersistentCache::SetCacheDirectoryPath (dir.path ());
@@ -60,7 +63,7 @@ class SkpWarmupTest : public ShellTest {
6063 auto cache = PersistentCache::GetCacheForProcess ()->LoadSkSLs ();
6164 ASSERT_EQ (cache.size (), 0u );
6265
63- PumpOneFrame (shell.get (), 100 , 100 , builder);
66+ PumpOneFrame (shell.get (), draw_size. width (), draw_size. height () , builder);
6467 firstFrameLatch.Wait ();
6568 WaitForIO (shell.get ());
6669
@@ -97,8 +100,11 @@ class SkpWarmupTest : public ShellTest {
97100 // Deserialize
98101 sk_sp<SkData> data = SkData::MakeFromFD (fd.get ());
99102 std::unique_ptr<SkMemoryStream> stream = SkMemoryStream::Make (data);
100- sk_sp<SkPicture> picture = SkPicture::MakeFromStream (
101- stream.get (), /* const SkDeserialProcs* */ nullptr );
103+
104+ SkDeserialProcs procs = {0 };
105+ procs.fImageProc = DeserializeImageWithoutData;
106+ sk_sp<SkPicture> picture =
107+ SkPicture::MakeFromStream (stream.get (), &procs);
102108 pictures.push_back (std::move (picture));
103109 fd.reset ();
104110 }
@@ -118,7 +124,7 @@ class SkpWarmupTest : public ShellTest {
118124 PlatformViewNotifyCreated (shell.get ());
119125 RunEngine (shell.get (), std::move (config2));
120126 firstFrameLatch.Reset ();
121- PumpOneFrame (shell.get (), 100 , 100 , builder);
127+ PumpOneFrame (shell.get (), draw_size. width (), draw_size. height () , builder);
122128 firstFrameLatch.Wait ();
123129 WaitForIO (shell.get ());
124130
@@ -167,7 +173,8 @@ class SkpWarmupTest : public ShellTest {
167173
168174 // Draw orignal material again
169175 firstFrameLatch.Reset ();
170- PumpOneFrame (shell.get (), 100 , 100 , builder);
176+ PumpOneFrame (shell.get (), draw_size.width (), draw_size.height (), builder);
177+
171178 firstFrameLatch.Wait ();
172179 WaitForIO (shell.get ());
173180
@@ -183,15 +190,56 @@ class SkpWarmupTest : public ShellTest {
183190};
184191
185192TEST_F (SkpWarmupTest, Basic) {
193+ SkISize draw_size = SkISize::Make (100 , 100 );
186194 // Draw something to trigger shader compilations.
187- LayerTreeBuilder builder = [](std::shared_ptr<ContainerLayer> root) {
188- SkPath path;
189- path.addCircle (50 , 50 , 20 );
190- auto physical_shape_layer = std::make_shared<PhysicalShapeLayer>(
191- SK_ColorRED, SK_ColorBLUE, 1 .0f , path, Clip::antiAlias);
192- root->Add (physical_shape_layer);
195+ LayerTreeBuilder builder =
196+ [&draw_size](std::shared_ptr<ContainerLayer> root) {
197+ SkPath path;
198+ path.addCircle (draw_size.width () / 2 , draw_size.height () / 2 , 20 );
199+ auto physical_shape_layer = std::make_shared<PhysicalShapeLayer>(
200+ SK_ColorRED, SK_ColorBLUE, 1 .0f , path, Clip::antiAlias);
201+ root->Add (physical_shape_layer);
202+ };
203+ TestWarmup (draw_size, builder);
204+ }
205+
206+ TEST_F (SkpWarmupTest, Image) {
207+ SkISize draw_size = SkISize::Make (100 , 100 );
208+ // We reuse this builder to draw the same content sever times in this test
209+ LayerTreeBuilder builder = [&draw_size,
210+ this ](std::shared_ptr<ContainerLayer> root) {
211+ SkPictureRecorder recorder;
212+ auto canvas =
213+ recorder.beginRecording (draw_size.width (), draw_size.height ());
214+
215+ // include an image so we can test that the warmup works even with image
216+ // data excluded from the skp
217+ auto image_size =
218+ SkISize::Make (draw_size.width () / 2 , draw_size.height () / 2 );
219+ auto color_space = SkColorSpace::MakeSRGB ();
220+ auto info =
221+ SkImageInfo::Make (image_size, SkColorType::kRGBA_8888_SkColorType ,
222+ SkAlphaType::kPremul_SkAlphaType , color_space);
223+ sk_sp<SkData> image_data =
224+ SkData::MakeUninitialized (image_size.width () * image_size.height () * 4 );
225+ memset (image_data->writable_data (), 0x0f , image_data->size ());
226+ sk_sp<SkImage> image =
227+ SkImage::MakeRasterData (info, image_data, image_size.width () * 4 );
228+
229+ canvas->drawImage (image, image_size.width (), image_size.height ());
230+
231+ auto picture = recorder.finishRecordingAsPicture ();
232+
233+ fml::RefPtr<SkiaUnrefQueue> queue = fml::MakeRefCounted<SkiaUnrefQueue>(
234+ this ->GetCurrentTaskRunner (), fml::TimeDelta::FromSeconds (0 ));
235+ auto picture_layer = std::make_shared<PictureLayer>(
236+ SkPoint::Make (0 , 0 ), SkiaGPUObject<SkPicture>(picture, queue),
237+ /* is_complex */ false ,
238+ /* will_change */ false );
239+ root->Add (picture_layer);
193240 };
194- TestWarmup (builder);
241+
242+ TestWarmup (draw_size, builder);
195243}
196244
197245#endif
0 commit comments