44
55#include " flutter/flow/raster_cache.h"
66
7- #include " flutter/flow/layers/container_layer.h"
87#include " gtest/gtest.h"
98#include " third_party/skia/include/core/SkPicture.h"
109#include " third_party/skia/include/core/SkPictureRecorder.h"
@@ -30,14 +29,16 @@ TEST(RasterCache, SimpleInitialization) {
3029 ASSERT_TRUE (true );
3130}
3231
33- TEST (RasterCache, ThresholdIsRespectedForPictures ) {
32+ TEST (RasterCache, ThresholdIsRespected ) {
3433 size_t threshold = 2 ;
3534 flutter::RasterCache cache (threshold);
3635
3736 SkMatrix matrix = SkMatrix::I ();
3837
3938 auto picture = GetSamplePicture ();
4039
40+ sk_sp<SkImage> image;
41+
4142 sk_sp<SkColorSpace> srgb = SkColorSpace::MakeSRGB ();
4243 ASSERT_FALSE (
4344 cache.Prepare (NULL , picture.get (), matrix, srgb.get (), true , false ));
@@ -60,28 +61,21 @@ TEST(RasterCache, ThresholdIsRespectedForPictures) {
6061 ASSERT_TRUE (cache.Get (*picture, matrix).is_valid ());
6162}
6263
63- TEST (RasterCache, ThresholdIsRespectedForLayers ) {
64- size_t threshold = 2 ;
64+ TEST (RasterCache, AccessThresholdOfZeroDisablesCaching ) {
65+ size_t threshold = 0 ;
6566 flutter::RasterCache cache (threshold);
6667
6768 SkMatrix matrix = SkMatrix::I ();
6869
69- ContainerLayer layer;
70-
71- sk_sp<SkColorSpace> srgb = SkColorSpace::MakeSRGB ();
72- ASSERT_FALSE (cache.Prepare (nullptr , &layer, matrix));
73- ASSERT_FALSE (cache.Prepare (nullptr , &layer, matrix));
74- ASSERT_FALSE (cache.Prepare (nullptr , &layer, matrix));
75-
76- // 1st access.
77- ASSERT_FALSE (cache.Get (&layer, matrix).is_valid ());
70+ auto picture = GetSamplePicture ();
7871
79- ASSERT_FALSE (cache. Prepare ( nullptr , &layer, matrix)) ;
72+ sk_sp<SkImage> image ;
8073
81- // 2st access.
82- ASSERT_FALSE (cache.Get (&layer, matrix).is_valid ());
74+ sk_sp<SkColorSpace> srgb = SkColorSpace::MakeSRGB ();
75+ ASSERT_FALSE (
76+ cache.Prepare (NULL , picture.get (), matrix, srgb.get (), true , false ));
8377
84- // Calling Prepare now would crash due to the nullptr.
78+ ASSERT_FALSE (cache. Get (*picture, matrix). is_valid ());
8579}
8680
8781TEST (RasterCache, PictureCacheLimitPerFrameIsRespectedWhenZero) {
@@ -92,6 +86,8 @@ TEST(RasterCache, PictureCacheLimitPerFrameIsRespectedWhenZero) {
9286
9387 auto picture = GetSamplePicture ();
9488
89+ sk_sp<SkImage> image;
90+
9591 sk_sp<SkColorSpace> srgb = SkColorSpace::MakeSRGB ();
9692 ASSERT_FALSE (
9793 cache.Prepare (NULL , picture.get (), matrix, srgb.get (), true , false ));
@@ -107,6 +103,8 @@ TEST(RasterCache, SweepsRemoveUnusedFrames) {
107103
108104 auto picture = GetSamplePicture ();
109105
106+ sk_sp<SkImage> image;
107+
110108 sk_sp<SkColorSpace> srgb = SkColorSpace::MakeSRGB ();
111109 ASSERT_FALSE (cache.Prepare (NULL , picture.get (), matrix, srgb.get (), true ,
112110 false )); // 1
@@ -124,29 +122,5 @@ TEST(RasterCache, SweepsRemoveUnusedFrames) {
124122 ASSERT_FALSE (cache.Get (*picture, matrix).is_valid ());
125123}
126124
127- TEST (RasterCache, TryRasterizngOnlyOnce) {
128- size_t threshold = 1 ;
129- flutter::RasterCache cache (threshold);
130-
131- SkMatrix matrix = SkMatrix::I ();
132- // Test picture too large to successfully rasterize.
133- auto picture = SkPicture::MakePlaceholder (SkRect::MakeWH (2e12 , 2e12 ));
134-
135- sk_sp<SkColorSpace> srgb = SkColorSpace::MakeSRGB ();
136- ASSERT_FALSE (cache.Prepare (nullptr , picture.get (), matrix, srgb.get (), true ,
137- false )); // 1
138- ASSERT_FALSE (cache.Get (*picture, matrix).is_valid ());
139-
140- // Rasterization ran, though Get() below returns an invalid image.
141- ASSERT_TRUE (cache.Prepare (nullptr , picture.get (), matrix, srgb.get (), true ,
142- false )); // 2
143- ASSERT_FALSE (cache.Get (*picture, matrix).is_valid ());
144-
145- // This time we should not try again to rasterize.
146- ASSERT_FALSE (cache.Prepare (nullptr , picture.get (), matrix, srgb.get (), true ,
147- false )); // 2
148- ASSERT_FALSE (cache.Get (*picture, matrix).is_valid ());
149- }
150-
151125} // namespace testing
152126} // namespace flutter
0 commit comments