4
4
5
5
#include " flutter/flow/raster_cache.h"
6
6
7
- #include " flutter/flow/layers/container_layer.h"
8
7
#include " gtest/gtest.h"
9
8
#include " third_party/skia/include/core/SkPicture.h"
10
9
#include " third_party/skia/include/core/SkPictureRecorder.h"
@@ -30,14 +29,16 @@ TEST(RasterCache, SimpleInitialization) {
30
29
ASSERT_TRUE (true );
31
30
}
32
31
33
- TEST (RasterCache, ThresholdIsRespectedForPictures ) {
32
+ TEST (RasterCache, ThresholdIsRespected ) {
34
33
size_t threshold = 2 ;
35
34
flutter::RasterCache cache (threshold);
36
35
37
36
SkMatrix matrix = SkMatrix::I ();
38
37
39
38
auto picture = GetSamplePicture ();
40
39
40
+ sk_sp<SkImage> image;
41
+
41
42
sk_sp<SkColorSpace> srgb = SkColorSpace::MakeSRGB ();
42
43
ASSERT_FALSE (
43
44
cache.Prepare (NULL , picture.get (), matrix, srgb.get (), true , false ));
@@ -60,28 +61,21 @@ TEST(RasterCache, ThresholdIsRespectedForPictures) {
60
61
ASSERT_TRUE (cache.Get (*picture, matrix).is_valid ());
61
62
}
62
63
63
- TEST (RasterCache, ThresholdIsRespectedForLayers ) {
64
- size_t threshold = 2 ;
64
+ TEST (RasterCache, AccessThresholdOfZeroDisablesCaching ) {
65
+ size_t threshold = 0 ;
65
66
flutter::RasterCache cache (threshold);
66
67
67
68
SkMatrix matrix = SkMatrix::I ();
68
69
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 ();
78
71
79
- ASSERT_FALSE (cache. Prepare ( nullptr , &layer, matrix)) ;
72
+ sk_sp<SkImage> image ;
80
73
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 ));
83
77
84
- // Calling Prepare now would crash due to the nullptr.
78
+ ASSERT_FALSE (cache. Get (*picture, matrix). is_valid ());
85
79
}
86
80
87
81
TEST (RasterCache, PictureCacheLimitPerFrameIsRespectedWhenZero) {
@@ -92,6 +86,8 @@ TEST(RasterCache, PictureCacheLimitPerFrameIsRespectedWhenZero) {
92
86
93
87
auto picture = GetSamplePicture ();
94
88
89
+ sk_sp<SkImage> image;
90
+
95
91
sk_sp<SkColorSpace> srgb = SkColorSpace::MakeSRGB ();
96
92
ASSERT_FALSE (
97
93
cache.Prepare (NULL , picture.get (), matrix, srgb.get (), true , false ));
@@ -107,6 +103,8 @@ TEST(RasterCache, SweepsRemoveUnusedFrames) {
107
103
108
104
auto picture = GetSamplePicture ();
109
105
106
+ sk_sp<SkImage> image;
107
+
110
108
sk_sp<SkColorSpace> srgb = SkColorSpace::MakeSRGB ();
111
109
ASSERT_FALSE (cache.Prepare (NULL , picture.get (), matrix, srgb.get (), true ,
112
110
false )); // 1
@@ -124,29 +122,5 @@ TEST(RasterCache, SweepsRemoveUnusedFrames) {
124
122
ASSERT_FALSE (cache.Get (*picture, matrix).is_valid ());
125
123
}
126
124
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
-
151
125
} // namespace testing
152
126
} // namespace flutter
0 commit comments