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