OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/paint/discardable_image_map.h" | 5 #include "cc/paint/discardable_image_map.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "third_party/skia/include/core/SkCanvas.h" | 22 #include "third_party/skia/include/core/SkCanvas.h" |
23 #include "third_party/skia/include/core/SkGraphics.h" | 23 #include "third_party/skia/include/core/SkGraphics.h" |
24 #include "third_party/skia/include/core/SkImageGenerator.h" | 24 #include "third_party/skia/include/core/SkImageGenerator.h" |
25 #include "third_party/skia/include/core/SkRefCnt.h" | 25 #include "third_party/skia/include/core/SkRefCnt.h" |
26 #include "ui/gfx/geometry/rect.h" | 26 #include "ui/gfx/geometry/rect.h" |
27 #include "ui/gfx/skia_util.h" | 27 #include "ui/gfx/skia_util.h" |
28 | 28 |
29 namespace cc { | 29 namespace cc { |
30 namespace { | 30 namespace { |
31 | 31 |
| 32 PaintImage CreateDiscardablePaintImage(const gfx::Size& size) { |
| 33 return PaintImage(PaintImage::GetNextId(), CreateDiscardableImage(size)); |
| 34 } |
| 35 |
32 struct PositionScaleDrawImage { | 36 struct PositionScaleDrawImage { |
33 PositionScaleDrawImage(sk_sp<const SkImage> image, | 37 PositionScaleDrawImage(const PaintImage& image, |
34 const gfx::Rect& image_rect, | 38 const gfx::Rect& image_rect, |
35 const SkSize& scale) | 39 const SkSize& scale) |
36 : image(std::move(image)), image_rect(image_rect), scale(scale) {} | 40 : image(image), image_rect(image_rect), scale(scale) {} |
37 sk_sp<const SkImage> image; | 41 PaintImage image; |
38 gfx::Rect image_rect; | 42 gfx::Rect image_rect; |
39 SkSize scale; | 43 SkSize scale; |
40 }; | 44 }; |
41 | 45 |
42 sk_sp<PaintRecord> CreateRecording(const sk_sp<SkImage>& discardable_image, | 46 sk_sp<PaintRecord> CreateRecording(const PaintImage& discardable_image, |
43 const gfx::Rect& visible_rect) { | 47 const gfx::Rect& visible_rect) { |
44 PaintRecorder recorder; | 48 PaintRecorder recorder; |
45 PaintCanvas* canvas = | 49 PaintCanvas* canvas = |
46 recorder.beginRecording(visible_rect.width(), visible_rect.height()); | 50 recorder.beginRecording(visible_rect.width(), visible_rect.height()); |
47 canvas->drawImage(PaintImage(PaintImage::GetNextId(), discardable_image, | 51 canvas->drawImage(discardable_image, 0, 0, nullptr); |
48 PaintImage::AnimationType::STATIC, | |
49 PaintImage::CompletionState::DONE), | |
50 0, 0, nullptr); | |
51 sk_sp<PaintRecord> record = recorder.finishRecordingAsPicture(); | 52 sk_sp<PaintRecord> record = recorder.finishRecordingAsPicture(); |
52 return record; | 53 return record; |
53 } | 54 } |
54 | 55 |
55 } // namespace | 56 } // namespace |
56 | 57 |
57 class DiscardableImageMapTest : public testing::Test { | 58 class DiscardableImageMapTest : public testing::Test { |
58 public: | 59 public: |
59 std::vector<PositionScaleDrawImage> GetDiscardableImagesInRect( | 60 std::vector<PositionScaleDrawImage> GetDiscardableImagesInRect( |
60 const DiscardableImageMap& image_map, | 61 const DiscardableImageMap& image_map, |
61 const gfx::Rect& rect) { | 62 const gfx::Rect& rect) { |
62 std::vector<DrawImage> draw_images; | 63 std::vector<DrawImage> draw_images; |
63 // Choose a not-SRGB-and-not-invalid target color space to verify that it | 64 // Choose a not-SRGB-and-not-invalid target color space to verify that it |
64 // is passed correctly to the resulting DrawImages. | 65 // is passed correctly to the resulting DrawImages. |
65 gfx::ColorSpace target_color_space = gfx::ColorSpace::CreateXYZD50(); | 66 gfx::ColorSpace target_color_space = gfx::ColorSpace::CreateXYZD50(); |
66 image_map.GetDiscardableImagesInRect(rect, 1.f, target_color_space, | 67 image_map.GetDiscardableImagesInRect(rect, 1.f, target_color_space, |
67 &draw_images); | 68 &draw_images); |
68 | 69 |
69 std::vector<PositionScaleDrawImage> position_draw_images; | 70 std::vector<PositionScaleDrawImage> position_draw_images; |
70 for (size_t index : image_map.images_rtree_.Search(rect)) { | 71 for (size_t index : image_map.images_rtree_.Search(rect)) { |
71 position_draw_images.push_back( | 72 position_draw_images.push_back(PositionScaleDrawImage( |
72 PositionScaleDrawImage(image_map.all_images_[index].first.image(), | 73 image_map.all_images_[index].first.paint_image(), |
73 image_map.all_images_[index].second, | 74 image_map.all_images_[index].second, |
74 image_map.all_images_[index].first.scale())); | 75 image_map.all_images_[index].first.scale())); |
75 } | 76 } |
76 | 77 |
77 EXPECT_EQ(draw_images.size(), position_draw_images.size()); | 78 EXPECT_EQ(draw_images.size(), position_draw_images.size()); |
78 for (size_t i = 0; i < draw_images.size(); ++i) { | 79 for (size_t i = 0; i < draw_images.size(); ++i) { |
79 EXPECT_TRUE(draw_images[i].image() == position_draw_images[i].image); | 80 EXPECT_TRUE(draw_images[i].paint_image() == |
| 81 position_draw_images[i].image); |
80 EXPECT_EQ(draw_images[i].target_color_space(), target_color_space); | 82 EXPECT_EQ(draw_images[i].target_color_space(), target_color_space); |
81 } | 83 } |
82 return position_draw_images; | 84 return position_draw_images; |
83 } | 85 } |
84 | 86 |
85 // Note that the image rtree outsets the images by 1, see the comment in | 87 // Note that the image rtree outsets the images by 1, see the comment in |
86 // DiscardableImagesMetadataCanvas::AddImage. | 88 // DiscardableImagesMetadataCanvas::AddImage. |
87 std::vector<gfx::Rect> InsetImageRects( | 89 std::vector<gfx::Rect> InsetImageRects( |
88 const std::vector<PositionScaleDrawImage>& images) { | 90 const std::vector<PositionScaleDrawImage>& images) { |
89 std::vector<gfx::Rect> result; | 91 std::vector<gfx::Rect> result; |
(...skipping 13 matching lines...) Expand all Loading... |
103 // Discardable pixel refs are found in the following grids: | 105 // Discardable pixel refs are found in the following grids: |
104 // |---|---|---|---| | 106 // |---|---|---|---| |
105 // | | x | | x | | 107 // | | x | | x | |
106 // |---|---|---|---| | 108 // |---|---|---|---| |
107 // | x | | x | | | 109 // | x | | x | | |
108 // |---|---|---|---| | 110 // |---|---|---|---| |
109 // | | x | | x | | 111 // | | x | | x | |
110 // |---|---|---|---| | 112 // |---|---|---|---| |
111 // | x | | x | | | 113 // | x | | x | | |
112 // |---|---|---|---| | 114 // |---|---|---|---| |
113 sk_sp<SkImage> discardable_image[4][4]; | 115 PaintImage discardable_image[4][4]; |
114 for (int y = 0; y < 4; ++y) { | 116 for (int y = 0; y < 4; ++y) { |
115 for (int x = 0; x < 4; ++x) { | 117 for (int x = 0; x < 4; ++x) { |
116 if ((x + y) & 1) { | 118 if ((x + y) & 1) { |
117 discardable_image[y][x] = CreateDiscardableImage(gfx::Size(500, 500)); | 119 discardable_image[y][x] = |
| 120 CreateDiscardablePaintImage(gfx::Size(500, 500)); |
118 PaintFlags flags; | 121 PaintFlags flags; |
119 content_layer_client.add_draw_image( | 122 content_layer_client.add_draw_image( |
120 discardable_image[y][x], gfx::Point(x * 512 + 6, y * 512 + 6), | 123 discardable_image[y][x], gfx::Point(x * 512 + 6, y * 512 + 6), |
121 flags); | 124 flags); |
122 } | 125 } |
123 } | 126 } |
124 } | 127 } |
125 | 128 |
126 scoped_refptr<DisplayItemList> display_list = | 129 scoped_refptr<DisplayItemList> display_list = |
127 content_layer_client.PaintContentsToDisplayList( | 130 content_layer_client.PaintContentsToDisplayList( |
128 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); | 131 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); |
129 display_list->GenerateDiscardableImagesMetadata(); | 132 display_list->GenerateDiscardableImagesMetadata(); |
130 | 133 |
131 const DiscardableImageMap& image_map = | 134 const DiscardableImageMap& image_map = |
132 display_list->discardable_image_map_for_testing(); | 135 display_list->discardable_image_map_for_testing(); |
133 | 136 |
134 for (int y = 0; y < 4; ++y) { | 137 for (int y = 0; y < 4; ++y) { |
135 for (int x = 0; x < 4; ++x) { | 138 for (int x = 0; x < 4; ++x) { |
136 std::vector<PositionScaleDrawImage> images = GetDiscardableImagesInRect( | 139 std::vector<PositionScaleDrawImage> images = GetDiscardableImagesInRect( |
137 image_map, gfx::Rect(x * 512, y * 512, 500, 500)); | 140 image_map, gfx::Rect(x * 512, y * 512, 500, 500)); |
138 std::vector<gfx::Rect> inset_rects = InsetImageRects(images); | 141 std::vector<gfx::Rect> inset_rects = InsetImageRects(images); |
139 if ((x + y) & 1) { | 142 if ((x + y) & 1) { |
140 EXPECT_EQ(1u, images.size()) << x << " " << y; | 143 EXPECT_EQ(1u, images.size()) << x << " " << y; |
141 EXPECT_TRUE(images[0].image == discardable_image[y][x]) | 144 EXPECT_TRUE(images[0].image == discardable_image[y][x]) |
142 << x << " " << y; | 145 << x << " " << y; |
143 EXPECT_EQ(gfx::Rect(x * 512 + 6, y * 512 + 6, 500, 500), | 146 EXPECT_EQ(gfx::Rect(x * 512 + 6, y * 512 + 6, 500, 500), |
144 inset_rects[0]); | 147 inset_rects[0]); |
145 EXPECT_EQ(images[0].image_rect, | 148 EXPECT_EQ(images[0].image_rect, |
146 image_map.GetRectForImage(images[0].image->uniqueID())); | 149 image_map.GetRectForImage(images[0].image.stable_id())); |
147 } else { | 150 } else { |
148 EXPECT_EQ(0u, images.size()) << x << " " << y; | 151 EXPECT_EQ(0u, images.size()) << x << " " << y; |
149 } | 152 } |
150 } | 153 } |
151 } | 154 } |
152 | 155 |
153 // Capture 4 pixel refs. | 156 // Capture 4 pixel refs. |
154 std::vector<PositionScaleDrawImage> images = | 157 std::vector<PositionScaleDrawImage> images = |
155 GetDiscardableImagesInRect(image_map, gfx::Rect(512, 512, 2048, 2048)); | 158 GetDiscardableImagesInRect(image_map, gfx::Rect(512, 512, 2048, 2048)); |
156 std::vector<gfx::Rect> inset_rects = InsetImageRects(images); | 159 std::vector<gfx::Rect> inset_rects = InsetImageRects(images); |
157 EXPECT_EQ(4u, images.size()); | 160 EXPECT_EQ(4u, images.size()); |
158 | 161 |
159 EXPECT_TRUE(images[0].image == discardable_image[1][2]); | 162 EXPECT_TRUE(images[0].image == discardable_image[1][2]); |
160 EXPECT_EQ(gfx::Rect(2 * 512 + 6, 512 + 6, 500, 500), inset_rects[0]); | 163 EXPECT_EQ(gfx::Rect(2 * 512 + 6, 512 + 6, 500, 500), inset_rects[0]); |
161 EXPECT_EQ(images[0].image_rect, | 164 EXPECT_EQ(images[0].image_rect, |
162 image_map.GetRectForImage(images[0].image->uniqueID())); | 165 image_map.GetRectForImage(images[0].image.stable_id())); |
163 | 166 |
164 EXPECT_TRUE(images[1].image == discardable_image[2][1]); | 167 EXPECT_TRUE(images[1].image == discardable_image[2][1]); |
165 EXPECT_EQ(gfx::Rect(512 + 6, 2 * 512 + 6, 500, 500), inset_rects[1]); | 168 EXPECT_EQ(gfx::Rect(512 + 6, 2 * 512 + 6, 500, 500), inset_rects[1]); |
166 EXPECT_EQ(images[1].image_rect, | 169 EXPECT_EQ(images[1].image_rect, |
167 image_map.GetRectForImage(images[1].image->uniqueID())); | 170 image_map.GetRectForImage(images[1].image.stable_id())); |
168 | 171 |
169 EXPECT_TRUE(images[2].image == discardable_image[2][3]); | 172 EXPECT_TRUE(images[2].image == discardable_image[2][3]); |
170 EXPECT_EQ(gfx::Rect(3 * 512 + 6, 2 * 512 + 6, 500, 500), inset_rects[2]); | 173 EXPECT_EQ(gfx::Rect(3 * 512 + 6, 2 * 512 + 6, 500, 500), inset_rects[2]); |
171 EXPECT_EQ(images[2].image_rect, | 174 EXPECT_EQ(images[2].image_rect, |
172 image_map.GetRectForImage(images[2].image->uniqueID())); | 175 image_map.GetRectForImage(images[2].image.stable_id())); |
173 | 176 |
174 EXPECT_TRUE(images[3].image == discardable_image[3][2]); | 177 EXPECT_TRUE(images[3].image == discardable_image[3][2]); |
175 EXPECT_EQ(gfx::Rect(2 * 512 + 6, 3 * 512 + 6, 500, 500), inset_rects[3]); | 178 EXPECT_EQ(gfx::Rect(2 * 512 + 6, 3 * 512 + 6, 500, 500), inset_rects[3]); |
176 EXPECT_EQ(images[3].image_rect, | 179 EXPECT_EQ(images[3].image_rect, |
177 image_map.GetRectForImage(images[3].image->uniqueID())); | 180 image_map.GetRectForImage(images[3].image.stable_id())); |
178 } | 181 } |
179 | 182 |
180 TEST_F(DiscardableImageMapTest, GetDiscardableImagesInRectNonZeroLayer) { | 183 TEST_F(DiscardableImageMapTest, GetDiscardableImagesInRectNonZeroLayer) { |
181 gfx::Rect visible_rect(1024, 0, 2048, 2048); | 184 gfx::Rect visible_rect(1024, 0, 2048, 2048); |
182 // Make sure visible rect fits into the layer size. | 185 // Make sure visible rect fits into the layer size. |
183 gfx::Size layer_size(visible_rect.right(), visible_rect.bottom()); | 186 gfx::Size layer_size(visible_rect.right(), visible_rect.bottom()); |
184 FakeContentLayerClient content_layer_client; | 187 FakeContentLayerClient content_layer_client; |
185 content_layer_client.set_bounds(layer_size); | 188 content_layer_client.set_bounds(layer_size); |
186 | 189 |
187 // Discardable pixel refs are found in the following grids: | 190 // Discardable pixel refs are found in the following grids: |
188 // |---|---|---|---| | 191 // |---|---|---|---| |
189 // | | x | | x | | 192 // | | x | | x | |
190 // |---|---|---|---| | 193 // |---|---|---|---| |
191 // | x | | x | | | 194 // | x | | x | | |
192 // |---|---|---|---| | 195 // |---|---|---|---| |
193 // | | x | | x | | 196 // | | x | | x | |
194 // |---|---|---|---| | 197 // |---|---|---|---| |
195 // | x | | x | | | 198 // | x | | x | | |
196 // |---|---|---|---| | 199 // |---|---|---|---| |
197 sk_sp<SkImage> discardable_image[4][4]; | 200 PaintImage discardable_image[4][4]; |
198 for (int y = 0; y < 4; ++y) { | 201 for (int y = 0; y < 4; ++y) { |
199 for (int x = 0; x < 4; ++x) { | 202 for (int x = 0; x < 4; ++x) { |
200 if ((x + y) & 1) { | 203 if ((x + y) & 1) { |
201 discardable_image[y][x] = CreateDiscardableImage(gfx::Size(500, 500)); | 204 discardable_image[y][x] = |
| 205 CreateDiscardablePaintImage(gfx::Size(500, 500)); |
202 PaintFlags flags; | 206 PaintFlags flags; |
203 content_layer_client.add_draw_image( | 207 content_layer_client.add_draw_image( |
204 discardable_image[y][x], | 208 discardable_image[y][x], |
205 gfx::Point(1024 + x * 512 + 6, y * 512 + 6), flags); | 209 gfx::Point(1024 + x * 512 + 6, y * 512 + 6), flags); |
206 } | 210 } |
207 } | 211 } |
208 } | 212 } |
209 | 213 |
210 scoped_refptr<DisplayItemList> display_list = | 214 scoped_refptr<DisplayItemList> display_list = |
211 content_layer_client.PaintContentsToDisplayList( | 215 content_layer_client.PaintContentsToDisplayList( |
212 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); | 216 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); |
213 display_list->GenerateDiscardableImagesMetadata(); | 217 display_list->GenerateDiscardableImagesMetadata(); |
214 | 218 |
215 const DiscardableImageMap& image_map = | 219 const DiscardableImageMap& image_map = |
216 display_list->discardable_image_map_for_testing(); | 220 display_list->discardable_image_map_for_testing(); |
217 | 221 |
218 for (int y = 0; y < 4; ++y) { | 222 for (int y = 0; y < 4; ++y) { |
219 for (int x = 0; x < 4; ++x) { | 223 for (int x = 0; x < 4; ++x) { |
220 std::vector<PositionScaleDrawImage> images = GetDiscardableImagesInRect( | 224 std::vector<PositionScaleDrawImage> images = GetDiscardableImagesInRect( |
221 image_map, gfx::Rect(1024 + x * 512, y * 512, 500, 500)); | 225 image_map, gfx::Rect(1024 + x * 512, y * 512, 500, 500)); |
222 std::vector<gfx::Rect> inset_rects = InsetImageRects(images); | 226 std::vector<gfx::Rect> inset_rects = InsetImageRects(images); |
223 if ((x + y) & 1) { | 227 if ((x + y) & 1) { |
224 EXPECT_EQ(1u, images.size()) << x << " " << y; | 228 EXPECT_EQ(1u, images.size()) << x << " " << y; |
225 EXPECT_TRUE(images[0].image == discardable_image[y][x]) | 229 EXPECT_TRUE(images[0].image == discardable_image[y][x]) |
226 << x << " " << y; | 230 << x << " " << y; |
227 EXPECT_EQ(gfx::Rect(1024 + x * 512 + 6, y * 512 + 6, 500, 500), | 231 EXPECT_EQ(gfx::Rect(1024 + x * 512 + 6, y * 512 + 6, 500, 500), |
228 inset_rects[0]); | 232 inset_rects[0]); |
229 EXPECT_EQ(images[0].image_rect, | 233 EXPECT_EQ(images[0].image_rect, |
230 image_map.GetRectForImage(images[0].image->uniqueID())); | 234 image_map.GetRectForImage(images[0].image.stable_id())); |
231 } else { | 235 } else { |
232 EXPECT_EQ(0u, images.size()) << x << " " << y; | 236 EXPECT_EQ(0u, images.size()) << x << " " << y; |
233 } | 237 } |
234 } | 238 } |
235 } | 239 } |
236 // Capture 4 pixel refs. | 240 // Capture 4 pixel refs. |
237 { | 241 { |
238 std::vector<PositionScaleDrawImage> images = GetDiscardableImagesInRect( | 242 std::vector<PositionScaleDrawImage> images = GetDiscardableImagesInRect( |
239 image_map, gfx::Rect(1024 + 512, 512, 2048, 2048)); | 243 image_map, gfx::Rect(1024 + 512, 512, 2048, 2048)); |
240 std::vector<gfx::Rect> inset_rects = InsetImageRects(images); | 244 std::vector<gfx::Rect> inset_rects = InsetImageRects(images); |
241 EXPECT_EQ(4u, images.size()); | 245 EXPECT_EQ(4u, images.size()); |
242 | 246 |
243 EXPECT_TRUE(images[0].image == discardable_image[1][2]); | 247 EXPECT_TRUE(images[0].image == discardable_image[1][2]); |
244 EXPECT_EQ(gfx::Rect(1024 + 2 * 512 + 6, 512 + 6, 500, 500), inset_rects[0]); | 248 EXPECT_EQ(gfx::Rect(1024 + 2 * 512 + 6, 512 + 6, 500, 500), inset_rects[0]); |
245 EXPECT_EQ(images[0].image_rect, | 249 EXPECT_EQ(images[0].image_rect, |
246 image_map.GetRectForImage(images[0].image->uniqueID())); | 250 image_map.GetRectForImage(images[0].image.stable_id())); |
247 | 251 |
248 EXPECT_TRUE(images[1].image == discardable_image[2][1]); | 252 EXPECT_TRUE(images[1].image == discardable_image[2][1]); |
249 EXPECT_EQ(gfx::Rect(1024 + 512 + 6, 2 * 512 + 6, 500, 500), inset_rects[1]); | 253 EXPECT_EQ(gfx::Rect(1024 + 512 + 6, 2 * 512 + 6, 500, 500), inset_rects[1]); |
250 EXPECT_EQ(images[1].image_rect, | 254 EXPECT_EQ(images[1].image_rect, |
251 image_map.GetRectForImage(images[1].image->uniqueID())); | 255 image_map.GetRectForImage(images[1].image.stable_id())); |
252 | 256 |
253 EXPECT_TRUE(images[2].image == discardable_image[2][3]); | 257 EXPECT_TRUE(images[2].image == discardable_image[2][3]); |
254 EXPECT_EQ(gfx::Rect(1024 + 3 * 512 + 6, 2 * 512 + 6, 500, 500), | 258 EXPECT_EQ(gfx::Rect(1024 + 3 * 512 + 6, 2 * 512 + 6, 500, 500), |
255 inset_rects[2]); | 259 inset_rects[2]); |
256 EXPECT_EQ(images[2].image_rect, | 260 EXPECT_EQ(images[2].image_rect, |
257 image_map.GetRectForImage(images[2].image->uniqueID())); | 261 image_map.GetRectForImage(images[2].image.stable_id())); |
258 | 262 |
259 EXPECT_TRUE(images[3].image == discardable_image[3][2]); | 263 EXPECT_TRUE(images[3].image == discardable_image[3][2]); |
260 EXPECT_EQ(gfx::Rect(1024 + 2 * 512 + 6, 3 * 512 + 6, 500, 500), | 264 EXPECT_EQ(gfx::Rect(1024 + 2 * 512 + 6, 3 * 512 + 6, 500, 500), |
261 inset_rects[3]); | 265 inset_rects[3]); |
262 EXPECT_EQ(images[3].image_rect, | 266 EXPECT_EQ(images[3].image_rect, |
263 image_map.GetRectForImage(images[3].image->uniqueID())); | 267 image_map.GetRectForImage(images[3].image.stable_id())); |
264 } | 268 } |
265 | 269 |
266 // Non intersecting rects | 270 // Non intersecting rects |
267 { | 271 { |
268 std::vector<PositionScaleDrawImage> images = | 272 std::vector<PositionScaleDrawImage> images = |
269 GetDiscardableImagesInRect(image_map, gfx::Rect(0, 0, 1000, 1000)); | 273 GetDiscardableImagesInRect(image_map, gfx::Rect(0, 0, 1000, 1000)); |
270 EXPECT_EQ(0u, images.size()); | 274 EXPECT_EQ(0u, images.size()); |
271 } | 275 } |
272 { | 276 { |
273 std::vector<PositionScaleDrawImage> images = | 277 std::vector<PositionScaleDrawImage> images = |
274 GetDiscardableImagesInRect(image_map, gfx::Rect(3500, 0, 1000, 1000)); | 278 GetDiscardableImagesInRect(image_map, gfx::Rect(3500, 0, 1000, 1000)); |
275 EXPECT_EQ(0u, images.size()); | 279 EXPECT_EQ(0u, images.size()); |
276 } | 280 } |
277 { | 281 { |
278 std::vector<PositionScaleDrawImage> images = | 282 std::vector<PositionScaleDrawImage> images = |
279 GetDiscardableImagesInRect(image_map, gfx::Rect(0, 1100, 1000, 1000)); | 283 GetDiscardableImagesInRect(image_map, gfx::Rect(0, 1100, 1000, 1000)); |
280 EXPECT_EQ(0u, images.size()); | 284 EXPECT_EQ(0u, images.size()); |
281 } | 285 } |
282 { | 286 { |
283 std::vector<PositionScaleDrawImage> images = GetDiscardableImagesInRect( | 287 std::vector<PositionScaleDrawImage> images = GetDiscardableImagesInRect( |
284 image_map, gfx::Rect(3500, 1100, 1000, 1000)); | 288 image_map, gfx::Rect(3500, 1100, 1000, 1000)); |
285 EXPECT_EQ(0u, images.size()); | 289 EXPECT_EQ(0u, images.size()); |
286 } | 290 } |
287 | 291 |
288 // Image not present in the list. | 292 // Image not present in the list. |
289 { | 293 { |
290 sk_sp<SkImage> image = CreateDiscardableImage(gfx::Size(500, 500)); | 294 PaintImage image = CreateDiscardablePaintImage(gfx::Size(500, 500)); |
291 EXPECT_EQ(gfx::Rect(), image_map.GetRectForImage(image->uniqueID())); | 295 EXPECT_EQ(gfx::Rect(), image_map.GetRectForImage(image.stable_id())); |
292 } | 296 } |
293 } | 297 } |
294 | 298 |
295 TEST_F(DiscardableImageMapTest, GetDiscardableImagesInRectOnePixelQuery) { | 299 TEST_F(DiscardableImageMapTest, GetDiscardableImagesInRectOnePixelQuery) { |
296 gfx::Rect visible_rect(2048, 2048); | 300 gfx::Rect visible_rect(2048, 2048); |
297 FakeContentLayerClient content_layer_client; | 301 FakeContentLayerClient content_layer_client; |
298 content_layer_client.set_bounds(visible_rect.size()); | 302 content_layer_client.set_bounds(visible_rect.size()); |
299 | 303 |
300 // Discardable pixel refs are found in the following grids: | 304 // Discardable pixel refs are found in the following grids: |
301 // |---|---|---|---| | 305 // |---|---|---|---| |
302 // | | x | | x | | 306 // | | x | | x | |
303 // |---|---|---|---| | 307 // |---|---|---|---| |
304 // | x | | x | | | 308 // | x | | x | | |
305 // |---|---|---|---| | 309 // |---|---|---|---| |
306 // | | x | | x | | 310 // | | x | | x | |
307 // |---|---|---|---| | 311 // |---|---|---|---| |
308 // | x | | x | | | 312 // | x | | x | | |
309 // |---|---|---|---| | 313 // |---|---|---|---| |
310 sk_sp<SkImage> discardable_image[4][4]; | 314 PaintImage discardable_image[4][4]; |
311 for (int y = 0; y < 4; ++y) { | 315 for (int y = 0; y < 4; ++y) { |
312 for (int x = 0; x < 4; ++x) { | 316 for (int x = 0; x < 4; ++x) { |
313 if ((x + y) & 1) { | 317 if ((x + y) & 1) { |
314 discardable_image[y][x] = CreateDiscardableImage(gfx::Size(500, 500)); | 318 discardable_image[y][x] = |
| 319 CreateDiscardablePaintImage(gfx::Size(500, 500)); |
315 PaintFlags flags; | 320 PaintFlags flags; |
316 content_layer_client.add_draw_image( | 321 content_layer_client.add_draw_image( |
317 discardable_image[y][x], gfx::Point(x * 512 + 6, y * 512 + 6), | 322 discardable_image[y][x], gfx::Point(x * 512 + 6, y * 512 + 6), |
318 flags); | 323 flags); |
319 } | 324 } |
320 } | 325 } |
321 } | 326 } |
322 | 327 |
323 scoped_refptr<DisplayItemList> display_list = | 328 scoped_refptr<DisplayItemList> display_list = |
324 content_layer_client.PaintContentsToDisplayList( | 329 content_layer_client.PaintContentsToDisplayList( |
325 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); | 330 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); |
326 display_list->GenerateDiscardableImagesMetadata(); | 331 display_list->GenerateDiscardableImagesMetadata(); |
327 | 332 |
328 const DiscardableImageMap& image_map = | 333 const DiscardableImageMap& image_map = |
329 display_list->discardable_image_map_for_testing(); | 334 display_list->discardable_image_map_for_testing(); |
330 | 335 |
331 for (int y = 0; y < 4; ++y) { | 336 for (int y = 0; y < 4; ++y) { |
332 for (int x = 0; x < 4; ++x) { | 337 for (int x = 0; x < 4; ++x) { |
333 std::vector<PositionScaleDrawImage> images = GetDiscardableImagesInRect( | 338 std::vector<PositionScaleDrawImage> images = GetDiscardableImagesInRect( |
334 image_map, gfx::Rect(x * 512 + 256, y * 512 + 256, 1, 1)); | 339 image_map, gfx::Rect(x * 512 + 256, y * 512 + 256, 1, 1)); |
335 std::vector<gfx::Rect> inset_rects = InsetImageRects(images); | 340 std::vector<gfx::Rect> inset_rects = InsetImageRects(images); |
336 if ((x + y) & 1) { | 341 if ((x + y) & 1) { |
337 EXPECT_EQ(1u, images.size()) << x << " " << y; | 342 EXPECT_EQ(1u, images.size()) << x << " " << y; |
338 EXPECT_TRUE(images[0].image == discardable_image[y][x]) | 343 EXPECT_TRUE(images[0].image == discardable_image[y][x]) |
339 << x << " " << y; | 344 << x << " " << y; |
340 EXPECT_EQ(gfx::Rect(x * 512 + 6, y * 512 + 6, 500, 500), | 345 EXPECT_EQ(gfx::Rect(x * 512 + 6, y * 512 + 6, 500, 500), |
341 inset_rects[0]); | 346 inset_rects[0]); |
342 EXPECT_EQ(images[0].image_rect, | 347 EXPECT_EQ(images[0].image_rect, |
343 image_map.GetRectForImage(images[0].image->uniqueID())); | 348 image_map.GetRectForImage(images[0].image.stable_id())); |
344 } else { | 349 } else { |
345 EXPECT_EQ(0u, images.size()) << x << " " << y; | 350 EXPECT_EQ(0u, images.size()) << x << " " << y; |
346 } | 351 } |
347 } | 352 } |
348 } | 353 } |
349 } | 354 } |
350 | 355 |
351 TEST_F(DiscardableImageMapTest, GetDiscardableImagesInRectMassiveImage) { | 356 TEST_F(DiscardableImageMapTest, GetDiscardableImagesInRectMassiveImage) { |
352 gfx::Rect visible_rect(2048, 2048); | 357 gfx::Rect visible_rect(2048, 2048); |
353 FakeContentLayerClient content_layer_client; | 358 FakeContentLayerClient content_layer_client; |
354 content_layer_client.set_bounds(visible_rect.size()); | 359 content_layer_client.set_bounds(visible_rect.size()); |
355 | 360 |
356 sk_sp<SkImage> discardable_image = | 361 PaintImage discardable_image = |
357 CreateDiscardableImage(gfx::Size(1 << 25, 1 << 25)); | 362 CreateDiscardablePaintImage(gfx::Size(1 << 25, 1 << 25)); |
358 PaintFlags flags; | 363 PaintFlags flags; |
359 content_layer_client.add_draw_image(discardable_image, gfx::Point(0, 0), | 364 content_layer_client.add_draw_image(discardable_image, gfx::Point(0, 0), |
360 flags); | 365 flags); |
361 | 366 |
362 scoped_refptr<DisplayItemList> display_list = | 367 scoped_refptr<DisplayItemList> display_list = |
363 content_layer_client.PaintContentsToDisplayList( | 368 content_layer_client.PaintContentsToDisplayList( |
364 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); | 369 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); |
365 display_list->GenerateDiscardableImagesMetadata(); | 370 display_list->GenerateDiscardableImagesMetadata(); |
366 | 371 |
367 const DiscardableImageMap& image_map = | 372 const DiscardableImageMap& image_map = |
368 display_list->discardable_image_map_for_testing(); | 373 display_list->discardable_image_map_for_testing(); |
369 std::vector<PositionScaleDrawImage> images = | 374 std::vector<PositionScaleDrawImage> images = |
370 GetDiscardableImagesInRect(image_map, gfx::Rect(0, 0, 1, 1)); | 375 GetDiscardableImagesInRect(image_map, gfx::Rect(0, 0, 1, 1)); |
371 std::vector<gfx::Rect> inset_rects = InsetImageRects(images); | 376 std::vector<gfx::Rect> inset_rects = InsetImageRects(images); |
372 EXPECT_EQ(1u, images.size()); | 377 EXPECT_EQ(1u, images.size()); |
373 EXPECT_TRUE(images[0].image == discardable_image); | 378 EXPECT_TRUE(images[0].image == discardable_image); |
374 EXPECT_EQ(gfx::Rect(0, 0, 2048, 2048), inset_rects[0]); | 379 EXPECT_EQ(gfx::Rect(0, 0, 2048, 2048), inset_rects[0]); |
375 EXPECT_EQ(images[0].image_rect, | 380 EXPECT_EQ(images[0].image_rect, |
376 image_map.GetRectForImage(images[0].image->uniqueID())); | 381 image_map.GetRectForImage(images[0].image.stable_id())); |
377 } | 382 } |
378 | 383 |
379 TEST_F(DiscardableImageMapTest, PaintDestroyedWhileImageIsDrawn) { | 384 TEST_F(DiscardableImageMapTest, PaintDestroyedWhileImageIsDrawn) { |
380 gfx::Rect visible_rect(2048, 2048); | 385 gfx::Rect visible_rect(2048, 2048); |
381 FakeContentLayerClient content_layer_client; | 386 FakeContentLayerClient content_layer_client; |
382 content_layer_client.set_bounds(visible_rect.size()); | 387 content_layer_client.set_bounds(visible_rect.size()); |
383 | 388 |
384 sk_sp<SkImage> discardable_image = CreateDiscardableImage(gfx::Size(10, 10)); | 389 PaintImage discardable_image = CreateDiscardablePaintImage(gfx::Size(10, 10)); |
385 sk_sp<PaintRecord> record = CreateRecording(discardable_image, visible_rect); | 390 sk_sp<PaintRecord> record = CreateRecording(discardable_image, visible_rect); |
386 | 391 |
387 DiscardableImageMap image_map; | 392 DiscardableImageMap image_map; |
388 { | 393 { |
389 DiscardableImageMap::ScopedMetadataGenerator generator(&image_map, | 394 DiscardableImageMap::ScopedMetadataGenerator generator(&image_map, |
390 visible_rect.size()); | 395 visible_rect.size()); |
391 DiscardableImageStore* image_store = generator.image_store(); | 396 DiscardableImageStore* image_store = generator.image_store(); |
392 { | 397 { |
393 std::unique_ptr<SkPaint> paint(new SkPaint()); | 398 std::unique_ptr<SkPaint> paint(new SkPaint()); |
394 image_store->GetNoDrawCanvas()->saveLayer(gfx::RectToSkRect(visible_rect), | 399 image_store->GetNoDrawCanvas()->saveLayer(gfx::RectToSkRect(visible_rect), |
395 paint.get()); | 400 paint.get()); |
396 } | 401 } |
397 image_store->GatherDiscardableImages(record.get()); | 402 image_store->GatherDiscardableImages(record.get()); |
398 image_store->GetNoDrawCanvas()->restore(); | 403 image_store->GetNoDrawCanvas()->restore(); |
399 } | 404 } |
400 | 405 |
401 std::vector<PositionScaleDrawImage> images = | 406 std::vector<PositionScaleDrawImage> images = |
402 GetDiscardableImagesInRect(image_map, gfx::Rect(0, 0, 1, 1)); | 407 GetDiscardableImagesInRect(image_map, gfx::Rect(0, 0, 1, 1)); |
403 EXPECT_EQ(1u, images.size()); | 408 EXPECT_EQ(1u, images.size()); |
404 EXPECT_TRUE(images[0].image == discardable_image); | 409 EXPECT_TRUE(images[0].image == discardable_image); |
405 } | 410 } |
406 | 411 |
407 TEST_F(DiscardableImageMapTest, NullPaintOnSaveLayer) { | 412 TEST_F(DiscardableImageMapTest, NullPaintOnSaveLayer) { |
408 gfx::Rect visible_rect(2048, 2048); | 413 gfx::Rect visible_rect(2048, 2048); |
409 FakeContentLayerClient content_layer_client; | 414 FakeContentLayerClient content_layer_client; |
410 content_layer_client.set_bounds(visible_rect.size()); | 415 content_layer_client.set_bounds(visible_rect.size()); |
411 | 416 |
412 sk_sp<SkImage> discardable_image = CreateDiscardableImage(gfx::Size(10, 10)); | 417 PaintImage discardable_image = CreateDiscardablePaintImage(gfx::Size(10, 10)); |
413 sk_sp<PaintRecord> record = CreateRecording(discardable_image, visible_rect); | 418 sk_sp<PaintRecord> record = CreateRecording(discardable_image, visible_rect); |
414 | 419 |
415 DiscardableImageMap image_map; | 420 DiscardableImageMap image_map; |
416 { | 421 { |
417 DiscardableImageMap::ScopedMetadataGenerator generator(&image_map, | 422 DiscardableImageMap::ScopedMetadataGenerator generator(&image_map, |
418 visible_rect.size()); | 423 visible_rect.size()); |
419 DiscardableImageStore* image_store = generator.image_store(); | 424 DiscardableImageStore* image_store = generator.image_store(); |
420 SkPaint* null_paint = nullptr; | 425 SkPaint* null_paint = nullptr; |
421 image_store->GetNoDrawCanvas()->saveLayer(gfx::RectToSkRect(visible_rect), | 426 image_store->GetNoDrawCanvas()->saveLayer(gfx::RectToSkRect(visible_rect), |
422 null_paint); | 427 null_paint); |
423 image_store->GatherDiscardableImages(record.get()); | 428 image_store->GatherDiscardableImages(record.get()); |
424 image_store->GetNoDrawCanvas()->restore(); | 429 image_store->GetNoDrawCanvas()->restore(); |
425 } | 430 } |
426 | 431 |
427 std::vector<PositionScaleDrawImage> images = | 432 std::vector<PositionScaleDrawImage> images = |
428 GetDiscardableImagesInRect(image_map, gfx::Rect(0, 0, 1, 1)); | 433 GetDiscardableImagesInRect(image_map, gfx::Rect(0, 0, 1, 1)); |
429 EXPECT_EQ(1u, images.size()); | 434 EXPECT_EQ(1u, images.size()); |
430 EXPECT_TRUE(images[0].image == discardable_image); | 435 EXPECT_TRUE(images[0].image == discardable_image); |
431 } | 436 } |
432 | 437 |
433 TEST_F(DiscardableImageMapTest, GetDiscardableImagesInRectMaxImage) { | 438 TEST_F(DiscardableImageMapTest, GetDiscardableImagesInRectMaxImage) { |
434 gfx::Rect visible_rect(2048, 2048); | 439 gfx::Rect visible_rect(2048, 2048); |
435 FakeContentLayerClient content_layer_client; | 440 FakeContentLayerClient content_layer_client; |
436 content_layer_client.set_bounds(visible_rect.size()); | 441 content_layer_client.set_bounds(visible_rect.size()); |
437 | 442 |
438 int dimension = std::numeric_limits<int>::max(); | 443 int dimension = std::numeric_limits<int>::max(); |
439 sk_sp<SkImage> discardable_image = | 444 PaintImage discardable_image = |
440 CreateDiscardableImage(gfx::Size(dimension, dimension)); | 445 CreateDiscardablePaintImage(gfx::Size(dimension, dimension)); |
441 PaintFlags flags; | 446 PaintFlags flags; |
442 content_layer_client.add_draw_image(discardable_image, gfx::Point(42, 42), | 447 content_layer_client.add_draw_image(discardable_image, gfx::Point(42, 42), |
443 flags); | 448 flags); |
444 | 449 |
445 scoped_refptr<DisplayItemList> display_list = | 450 scoped_refptr<DisplayItemList> display_list = |
446 content_layer_client.PaintContentsToDisplayList( | 451 content_layer_client.PaintContentsToDisplayList( |
447 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); | 452 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); |
448 display_list->GenerateDiscardableImagesMetadata(); | 453 display_list->GenerateDiscardableImagesMetadata(); |
449 | 454 |
450 const DiscardableImageMap& image_map = | 455 const DiscardableImageMap& image_map = |
451 display_list->discardable_image_map_for_testing(); | 456 display_list->discardable_image_map_for_testing(); |
452 std::vector<PositionScaleDrawImage> images = | 457 std::vector<PositionScaleDrawImage> images = |
453 GetDiscardableImagesInRect(image_map, gfx::Rect(42, 42, 1, 1)); | 458 GetDiscardableImagesInRect(image_map, gfx::Rect(42, 42, 1, 1)); |
454 std::vector<gfx::Rect> inset_rects = InsetImageRects(images); | 459 std::vector<gfx::Rect> inset_rects = InsetImageRects(images); |
455 EXPECT_EQ(1u, images.size()); | 460 EXPECT_EQ(1u, images.size()); |
456 EXPECT_TRUE(images[0].image == discardable_image); | 461 EXPECT_TRUE(images[0].image == discardable_image); |
457 EXPECT_EQ(gfx::Rect(42, 42, 2006, 2006), inset_rects[0]); | 462 EXPECT_EQ(gfx::Rect(42, 42, 2006, 2006), inset_rects[0]); |
458 EXPECT_EQ(images[0].image_rect, | 463 EXPECT_EQ(images[0].image_rect, |
459 image_map.GetRectForImage(images[0].image->uniqueID())); | 464 image_map.GetRectForImage(images[0].image.stable_id())); |
460 } | 465 } |
461 | 466 |
462 TEST_F(DiscardableImageMapTest, GetDiscardableImagesInRectMaxImageMaxLayer) { | 467 TEST_F(DiscardableImageMapTest, GetDiscardableImagesInRectMaxImageMaxLayer) { |
463 // At large values of integer x, x != static_cast<int>(static_cast<float>(x)). | 468 // At large values of integer x, x != static_cast<int>(static_cast<float>(x)). |
464 // So, make sure the dimension can be converted back and forth for the | 469 // So, make sure the dimension can be converted back and forth for the |
465 // purposes of the unittest. Also, at near max int values, Skia seems to skip | 470 // purposes of the unittest. Also, at near max int values, Skia seems to skip |
466 // some draw calls, so we subtract 64 since we only care about "really large" | 471 // some draw calls, so we subtract 64 since we only care about "really large" |
467 // values, not necessarily max int values. | 472 // values, not necessarily max int values. |
468 int dimension = static_cast<int>( | 473 int dimension = static_cast<int>( |
469 static_cast<float>(std::numeric_limits<int>::max() - 64)); | 474 static_cast<float>(std::numeric_limits<int>::max() - 64)); |
470 gfx::Rect visible_rect(dimension, dimension); | 475 gfx::Rect visible_rect(dimension, dimension); |
471 FakeContentLayerClient content_layer_client; | 476 FakeContentLayerClient content_layer_client; |
472 content_layer_client.set_bounds(visible_rect.size()); | 477 content_layer_client.set_bounds(visible_rect.size()); |
473 | 478 |
474 sk_sp<SkImage> discardable_image = | 479 PaintImage discardable_image = |
475 CreateDiscardableImage(gfx::Size(dimension, dimension)); | 480 CreateDiscardablePaintImage(gfx::Size(dimension, dimension)); |
476 PaintFlags flags; | 481 PaintFlags flags; |
477 content_layer_client.add_draw_image(discardable_image, gfx::Point(0, 0), | 482 content_layer_client.add_draw_image(discardable_image, gfx::Point(0, 0), |
478 flags); | 483 flags); |
479 content_layer_client.add_draw_image(discardable_image, gfx::Point(10000, 0), | 484 content_layer_client.add_draw_image(discardable_image, gfx::Point(10000, 0), |
480 flags); | 485 flags); |
481 content_layer_client.add_draw_image(discardable_image, | 486 content_layer_client.add_draw_image(discardable_image, |
482 gfx::Point(-10000, 500), flags); | 487 gfx::Point(-10000, 500), flags); |
483 | 488 |
484 scoped_refptr<DisplayItemList> display_list = | 489 scoped_refptr<DisplayItemList> display_list = |
485 content_layer_client.PaintContentsToDisplayList( | 490 content_layer_client.PaintContentsToDisplayList( |
(...skipping 19 matching lines...) Expand all Loading... |
505 // The expected value is whatever the value is converted to float and then | 510 // The expected value is whatever the value is converted to float and then |
506 // back to int. | 511 // back to int. |
507 int expected10k = static_cast<int>(static_cast<float>(dimension - 10000)); | 512 int expected10k = static_cast<int>(static_cast<float>(dimension - 10000)); |
508 images = GetDiscardableImagesInRect(image_map, gfx::Rect(0, 500, 1, 1)); | 513 images = GetDiscardableImagesInRect(image_map, gfx::Rect(0, 500, 1, 1)); |
509 inset_rects = InsetImageRects(images); | 514 inset_rects = InsetImageRects(images); |
510 EXPECT_EQ(2u, images.size()); | 515 EXPECT_EQ(2u, images.size()); |
511 EXPECT_EQ(gfx::Rect(0, 500, expected10k, dimension - 500), inset_rects[1]); | 516 EXPECT_EQ(gfx::Rect(0, 500, expected10k, dimension - 500), inset_rects[1]); |
512 EXPECT_EQ(gfx::Rect(0, 0, dimension, dimension), inset_rects[0]); | 517 EXPECT_EQ(gfx::Rect(0, 0, dimension, dimension), inset_rects[0]); |
513 | 518 |
514 EXPECT_EQ(images[0].image_rect, | 519 EXPECT_EQ(images[0].image_rect, |
515 image_map.GetRectForImage(discardable_image->uniqueID())); | 520 image_map.GetRectForImage(discardable_image.stable_id())); |
516 } | 521 } |
517 | 522 |
518 TEST_F(DiscardableImageMapTest, GetDiscardableImagesRectInBounds) { | 523 TEST_F(DiscardableImageMapTest, GetDiscardableImagesRectInBounds) { |
519 gfx::Rect visible_rect(1000, 1000); | 524 gfx::Rect visible_rect(1000, 1000); |
520 FakeContentLayerClient content_layer_client; | 525 FakeContentLayerClient content_layer_client; |
521 content_layer_client.set_bounds(visible_rect.size()); | 526 content_layer_client.set_bounds(visible_rect.size()); |
522 | 527 |
523 sk_sp<SkImage> discardable_image = | 528 PaintImage discardable_image = |
524 CreateDiscardableImage(gfx::Size(100, 100)); | 529 CreateDiscardablePaintImage(gfx::Size(100, 100)); |
525 sk_sp<SkImage> long_discardable_image = | 530 PaintImage long_discardable_image = |
526 CreateDiscardableImage(gfx::Size(10000, 100)); | 531 CreateDiscardablePaintImage(gfx::Size(10000, 100)); |
527 | 532 |
528 PaintFlags flags; | 533 PaintFlags flags; |
529 content_layer_client.add_draw_image(discardable_image, gfx::Point(-10, -11), | 534 content_layer_client.add_draw_image(discardable_image, gfx::Point(-10, -11), |
530 flags); | 535 flags); |
531 content_layer_client.add_draw_image(discardable_image, gfx::Point(950, 951), | 536 content_layer_client.add_draw_image(discardable_image, gfx::Point(950, 951), |
532 flags); | 537 flags); |
533 content_layer_client.add_draw_image(long_discardable_image, | 538 content_layer_client.add_draw_image(long_discardable_image, |
534 gfx::Point(-100, 500), flags); | 539 gfx::Point(-100, 500), flags); |
535 | 540 |
536 scoped_refptr<DisplayItemList> display_list = | 541 scoped_refptr<DisplayItemList> display_list = |
(...skipping 17 matching lines...) Expand all Loading... |
554 images = GetDiscardableImagesInRect(image_map, gfx::Rect(0, 500, 1, 1)); | 559 images = GetDiscardableImagesInRect(image_map, gfx::Rect(0, 500, 1, 1)); |
555 inset_rects = InsetImageRects(images); | 560 inset_rects = InsetImageRects(images); |
556 EXPECT_EQ(1u, images.size()); | 561 EXPECT_EQ(1u, images.size()); |
557 EXPECT_EQ(gfx::Rect(0, 500, 1000, 100), inset_rects[0]); | 562 EXPECT_EQ(gfx::Rect(0, 500, 1000, 100), inset_rects[0]); |
558 | 563 |
559 gfx::Rect discardable_image_rect; | 564 gfx::Rect discardable_image_rect; |
560 discardable_image_rect.Union(gfx::Rect(0, 0, 90, 89)); | 565 discardable_image_rect.Union(gfx::Rect(0, 0, 90, 89)); |
561 discardable_image_rect.Union(gfx::Rect(950, 951, 50, 49)); | 566 discardable_image_rect.Union(gfx::Rect(950, 951, 50, 49)); |
562 discardable_image_rect.Inset(-1, -1, -1, -1); | 567 discardable_image_rect.Inset(-1, -1, -1, -1); |
563 EXPECT_EQ(discardable_image_rect, | 568 EXPECT_EQ(discardable_image_rect, |
564 image_map.GetRectForImage(discardable_image->uniqueID())); | 569 image_map.GetRectForImage(discardable_image.stable_id())); |
565 | 570 |
566 EXPECT_EQ(gfx::Rect(-1, 499, 1002, 102), | 571 EXPECT_EQ(gfx::Rect(-1, 499, 1002, 102), |
567 image_map.GetRectForImage(long_discardable_image->uniqueID())); | 572 image_map.GetRectForImage(long_discardable_image.stable_id())); |
568 } | 573 } |
569 | 574 |
570 TEST_F(DiscardableImageMapTest, GetDiscardableImagesInShader) { | 575 TEST_F(DiscardableImageMapTest, GetDiscardableImagesInShader) { |
571 gfx::Rect visible_rect(2048, 2048); | 576 gfx::Rect visible_rect(2048, 2048); |
572 FakeContentLayerClient content_layer_client; | 577 FakeContentLayerClient content_layer_client; |
573 content_layer_client.set_bounds(visible_rect.size()); | 578 content_layer_client.set_bounds(visible_rect.size()); |
574 | 579 |
575 // Discardable pixel refs are found in the following grids: | 580 // Discardable pixel refs are found in the following grids: |
576 // |---|---|---|---| | 581 // |---|---|---|---| |
577 // | | x | | x | | 582 // | | x | | x | |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 const DiscardableImageMap& image_map = | 616 const DiscardableImageMap& image_map = |
612 display_list->discardable_image_map_for_testing(); | 617 display_list->discardable_image_map_for_testing(); |
613 | 618 |
614 for (int y = 0; y < 4; ++y) { | 619 for (int y = 0; y < 4; ++y) { |
615 for (int x = 0; x < 4; ++x) { | 620 for (int x = 0; x < 4; ++x) { |
616 std::vector<PositionScaleDrawImage> images = GetDiscardableImagesInRect( | 621 std::vector<PositionScaleDrawImage> images = GetDiscardableImagesInRect( |
617 image_map, gfx::Rect(x * 512, y * 512, 500, 500)); | 622 image_map, gfx::Rect(x * 512, y * 512, 500, 500)); |
618 std::vector<gfx::Rect> inset_rects = InsetImageRects(images); | 623 std::vector<gfx::Rect> inset_rects = InsetImageRects(images); |
619 if ((x + y) & 1) { | 624 if ((x + y) & 1) { |
620 EXPECT_EQ(1u, images.size()) << x << " " << y; | 625 EXPECT_EQ(1u, images.size()) << x << " " << y; |
621 EXPECT_TRUE(images[0].image == discardable_image[y][x]) | 626 EXPECT_TRUE(images[0].image.sk_image() == discardable_image[y][x]) |
622 << x << " " << y; | 627 << x << " " << y; |
623 EXPECT_EQ(gfx::Rect(x * 512 + 6, y * 512 + 6, 500, 500), | 628 EXPECT_EQ(gfx::Rect(x * 512 + 6, y * 512 + 6, 500, 500), |
624 inset_rects[0]); | 629 inset_rects[0]); |
625 EXPECT_EQ(std::max(x * 0.5f, kMinScale), images[0].scale.fWidth); | 630 EXPECT_EQ(std::max(x * 0.5f, kMinScale), images[0].scale.fWidth); |
626 EXPECT_EQ(std::max(y * 0.5f, kMinScale), images[0].scale.fHeight); | 631 EXPECT_EQ(std::max(y * 0.5f, kMinScale), images[0].scale.fHeight); |
627 } else { | 632 } else { |
628 EXPECT_EQ(0u, images.size()) << x << " " << y; | 633 EXPECT_EQ(0u, images.size()) << x << " " << y; |
629 } | 634 } |
630 } | 635 } |
631 } | 636 } |
632 | 637 |
633 // Capture 4 pixel refs. | 638 // Capture 4 pixel refs. |
634 std::vector<PositionScaleDrawImage> images = | 639 std::vector<PositionScaleDrawImage> images = |
635 GetDiscardableImagesInRect(image_map, gfx::Rect(512, 512, 2048, 2048)); | 640 GetDiscardableImagesInRect(image_map, gfx::Rect(512, 512, 2048, 2048)); |
636 std::vector<gfx::Rect> inset_rects = InsetImageRects(images); | 641 std::vector<gfx::Rect> inset_rects = InsetImageRects(images); |
637 EXPECT_EQ(4u, images.size()); | 642 EXPECT_EQ(4u, images.size()); |
638 EXPECT_TRUE(images[0].image == discardable_image[1][2]); | 643 EXPECT_TRUE(images[0].image.sk_image() == discardable_image[1][2]); |
639 EXPECT_EQ(gfx::Rect(2 * 512 + 6, 512 + 6, 500, 500), inset_rects[0]); | 644 EXPECT_EQ(gfx::Rect(2 * 512 + 6, 512 + 6, 500, 500), inset_rects[0]); |
640 EXPECT_TRUE(images[1].image == discardable_image[2][1]); | 645 EXPECT_TRUE(images[1].image.sk_image() == discardable_image[2][1]); |
641 EXPECT_EQ(gfx::Rect(512 + 6, 2 * 512 + 6, 500, 500), inset_rects[1]); | 646 EXPECT_EQ(gfx::Rect(512 + 6, 2 * 512 + 6, 500, 500), inset_rects[1]); |
642 EXPECT_TRUE(images[2].image == discardable_image[2][3]); | 647 EXPECT_TRUE(images[2].image.sk_image() == discardable_image[2][3]); |
643 EXPECT_EQ(gfx::Rect(3 * 512 + 6, 2 * 512 + 6, 500, 500), inset_rects[2]); | 648 EXPECT_EQ(gfx::Rect(3 * 512 + 6, 2 * 512 + 6, 500, 500), inset_rects[2]); |
644 EXPECT_TRUE(images[3].image == discardable_image[3][2]); | 649 EXPECT_TRUE(images[3].image.sk_image() == discardable_image[3][2]); |
645 EXPECT_EQ(gfx::Rect(2 * 512 + 6, 3 * 512 + 6, 500, 500), inset_rects[3]); | 650 EXPECT_EQ(gfx::Rect(2 * 512 + 6, 3 * 512 + 6, 500, 500), inset_rects[3]); |
646 } | 651 } |
647 | 652 |
648 TEST_F(DiscardableImageMapTest, ClipsImageRects) { | 653 TEST_F(DiscardableImageMapTest, ClipsImageRects) { |
649 gfx::Rect visible_rect(500, 500); | 654 gfx::Rect visible_rect(500, 500); |
650 | 655 |
651 sk_sp<SkImage> discardable_image = | 656 PaintImage discardable_image = |
652 CreateDiscardableImage(gfx::Size(500, 500)); | 657 CreateDiscardablePaintImage(gfx::Size(500, 500)); |
653 sk_sp<PaintRecord> record = CreateRecording(discardable_image, visible_rect); | 658 sk_sp<PaintRecord> record = CreateRecording(discardable_image, visible_rect); |
654 | 659 |
655 scoped_refptr<DisplayItemList> display_list = new DisplayItemList; | 660 scoped_refptr<DisplayItemList> display_list = new DisplayItemList; |
656 display_list->CreateAndAppendPairedBeginItem<ClipDisplayItem>( | 661 display_list->CreateAndAppendPairedBeginItem<ClipDisplayItem>( |
657 gfx::Rect(250, 250), std::vector<SkRRect>(), false); | 662 gfx::Rect(250, 250), std::vector<SkRRect>(), false); |
658 display_list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 663 display_list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
659 gfx::Rect(500, 500), record); | 664 gfx::Rect(500, 500), record); |
660 display_list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); | 665 display_list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); |
661 display_list->Finalize(); | 666 display_list->Finalize(); |
662 display_list->GenerateDiscardableImagesMetadata(); | 667 display_list->GenerateDiscardableImagesMetadata(); |
663 | 668 |
664 const DiscardableImageMap& image_map = | 669 const DiscardableImageMap& image_map = |
665 display_list->discardable_image_map_for_testing(); | 670 display_list->discardable_image_map_for_testing(); |
666 std::vector<PositionScaleDrawImage> images = | 671 std::vector<PositionScaleDrawImage> images = |
667 GetDiscardableImagesInRect(image_map, visible_rect); | 672 GetDiscardableImagesInRect(image_map, visible_rect); |
668 std::vector<gfx::Rect> inset_rects = InsetImageRects(images); | 673 std::vector<gfx::Rect> inset_rects = InsetImageRects(images); |
669 EXPECT_EQ(1u, images.size()); | 674 EXPECT_EQ(1u, images.size()); |
670 EXPECT_TRUE(images[0].image == discardable_image); | 675 EXPECT_TRUE(images[0].image == discardable_image); |
671 EXPECT_EQ(gfx::Rect(250, 250), inset_rects[0]); | 676 EXPECT_EQ(gfx::Rect(250, 250), inset_rects[0]); |
672 } | 677 } |
673 | 678 |
674 TEST_F(DiscardableImageMapTest, GathersDiscardableImagesFromNestedOps) { | 679 TEST_F(DiscardableImageMapTest, GathersDiscardableImagesFromNestedOps) { |
675 sk_sp<PaintRecord> internal_record = sk_make_sp<PaintRecord>(); | 680 sk_sp<PaintRecord> internal_record = sk_make_sp<PaintRecord>(); |
676 sk_sp<SkImage> discardable_image = | 681 PaintImage discardable_image = |
677 CreateDiscardableImage(gfx::Size(100, 100)); | 682 CreateDiscardablePaintImage(gfx::Size(100, 100)); |
678 internal_record->push<DrawImageOp>( | 683 internal_record->push<DrawImageOp>(discardable_image, 0.f, 0.f, nullptr); |
679 PaintImage(PaintImage::GetNextId(), discardable_image, | |
680 PaintImage::AnimationType::STATIC, | |
681 PaintImage::CompletionState::DONE), | |
682 0.f, 0.f, nullptr); | |
683 | 684 |
684 sk_sp<PaintRecord> list_record = sk_make_sp<PaintRecord>(); | 685 sk_sp<PaintRecord> list_record = sk_make_sp<PaintRecord>(); |
685 sk_sp<SkImage> discardable_image2 = | 686 PaintImage discardable_image2 = |
686 CreateDiscardableImage(gfx::Size(100, 100)); | 687 CreateDiscardablePaintImage(gfx::Size(100, 100)); |
687 list_record->push<DrawImageOp>( | 688 list_record->push<DrawImageOp>(discardable_image2, 100.f, 100.f, nullptr); |
688 PaintImage(PaintImage::GetNextId(), discardable_image2, | |
689 PaintImage::AnimationType::STATIC, | |
690 PaintImage::CompletionState::DONE), | |
691 100.f, 100.f, nullptr); | |
692 scoped_refptr<DisplayItemList> display_list = new DisplayItemList; | 689 scoped_refptr<DisplayItemList> display_list = new DisplayItemList; |
693 display_list->CreateAndAppendDrawingItem<DrawingDisplayItem>( | 690 display_list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
694 gfx::Rect(100, 100, 100, 100), list_record); | 691 gfx::Rect(100, 100, 100, 100), list_record); |
695 display_list->Finalize(); | 692 display_list->Finalize(); |
696 | 693 |
697 PaintOpBuffer buffer; | 694 PaintOpBuffer buffer; |
698 buffer.push<DrawRecordOp>(internal_record); | 695 buffer.push<DrawRecordOp>(internal_record); |
699 buffer.push<DrawDisplayItemListOp>(display_list); | 696 buffer.push<DrawDisplayItemListOp>(display_list); |
700 DiscardableImageMap image_map_; | 697 DiscardableImageMap image_map_; |
701 { | 698 { |
702 DiscardableImageMap::ScopedMetadataGenerator generator(&image_map_, | 699 DiscardableImageMap::ScopedMetadataGenerator generator(&image_map_, |
703 gfx::Size(200, 200)); | 700 gfx::Size(200, 200)); |
704 generator.image_store()->GatherDiscardableImages(&buffer); | 701 generator.image_store()->GatherDiscardableImages(&buffer); |
705 } | 702 } |
706 | 703 |
707 gfx::ColorSpace target_color_space; | 704 gfx::ColorSpace target_color_space; |
708 std::vector<DrawImage> images; | 705 std::vector<DrawImage> images; |
709 image_map_.GetDiscardableImagesInRect(gfx::Rect(0, 0, 5, 95), 1.f, | 706 image_map_.GetDiscardableImagesInRect(gfx::Rect(0, 0, 5, 95), 1.f, |
710 target_color_space, &images); | 707 target_color_space, &images); |
711 EXPECT_EQ(1u, images.size()); | 708 EXPECT_EQ(1u, images.size()); |
712 EXPECT_TRUE(discardable_image == images[0].image()); | 709 EXPECT_TRUE(discardable_image == images[0].paint_image()); |
713 | 710 |
714 images.clear(); | 711 images.clear(); |
715 image_map_.GetDiscardableImagesInRect(gfx::Rect(105, 105, 5, 95), 1.f, | 712 image_map_.GetDiscardableImagesInRect(gfx::Rect(105, 105, 5, 95), 1.f, |
716 target_color_space, &images); | 713 target_color_space, &images); |
717 EXPECT_EQ(1u, images.size()); | 714 EXPECT_EQ(1u, images.size()); |
718 EXPECT_TRUE(discardable_image2 == images[0].image()); | 715 EXPECT_TRUE(discardable_image2 == images[0].paint_image()); |
719 } | 716 } |
720 | 717 |
721 } // namespace cc | 718 } // namespace cc |
OLD | NEW |