| 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 |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "cc/base/region.h" | 13 #include "cc/base/region.h" |
| 14 #include "cc/paint/clip_display_item.h" |
| 15 #include "cc/paint/discardable_image_store.h" |
| 16 #include "cc/paint/paint_flags.h" |
| 17 #include "cc/paint/paint_recorder.h" |
| 14 #include "cc/test/fake_content_layer_client.h" | 18 #include "cc/test/fake_content_layer_client.h" |
| 15 #include "cc/test/fake_recording_source.h" | 19 #include "cc/test/fake_recording_source.h" |
| 16 #include "cc/test/skia_common.h" | 20 #include "cc/test/skia_common.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "third_party/skia/include/core/SkCanvas.h" | 22 #include "third_party/skia/include/core/SkCanvas.h" |
| 19 #include "third_party/skia/include/core/SkGraphics.h" | 23 #include "third_party/skia/include/core/SkGraphics.h" |
| 20 #include "third_party/skia/include/core/SkImageGenerator.h" | 24 #include "third_party/skia/include/core/SkImageGenerator.h" |
| 21 #include "third_party/skia/include/core/SkRefCnt.h" | 25 #include "third_party/skia/include/core/SkRefCnt.h" |
| 22 #include "ui/gfx/geometry/rect.h" | 26 #include "ui/gfx/geometry/rect.h" |
| 23 #include "ui/gfx/skia_util.h" | 27 #include "ui/gfx/skia_util.h" |
| 24 | 28 |
| 25 namespace cc { | 29 namespace cc { |
| 26 namespace { | 30 namespace { |
| 27 | 31 |
| 28 struct PositionScaleDrawImage { | 32 struct PositionScaleDrawImage { |
| 29 PositionScaleDrawImage(sk_sp<const SkImage> image, | 33 PositionScaleDrawImage(sk_sp<const SkImage> image, |
| 30 const gfx::Rect& image_rect, | 34 const gfx::Rect& image_rect, |
| 31 const SkSize& scale) | 35 const SkSize& scale) |
| 32 : image(std::move(image)), image_rect(image_rect), scale(scale) {} | 36 : image(std::move(image)), image_rect(image_rect), scale(scale) {} |
| 33 sk_sp<const SkImage> image; | 37 sk_sp<const SkImage> image; |
| 34 gfx::Rect image_rect; | 38 gfx::Rect image_rect; |
| 35 SkSize scale; | 39 SkSize scale; |
| 36 }; | 40 }; |
| 37 | 41 |
| 42 sk_sp<PaintRecord> CreateRecording( |
| 43 const sk_sp<const SkImage>& discardable_image, |
| 44 const gfx::Rect& visible_rect) { |
| 45 PaintRecorder recorder; |
| 46 PaintCanvas* canvas = |
| 47 recorder.beginRecording(visible_rect.width(), visible_rect.height()); |
| 48 canvas->drawImage( |
| 49 PaintImage(discardable_image, PaintImage::AnimationType::STATIC, |
| 50 PaintImage::CompletionState::DONE), |
| 51 0, 0, nullptr); |
| 52 sk_sp<PaintRecord> record = recorder.finishRecordingAsPicture(); |
| 53 return record; |
| 54 } |
| 55 |
| 38 } // namespace | 56 } // namespace |
| 39 | 57 |
| 40 class DiscardableImageMapTest : public testing::Test { | 58 class DiscardableImageMapTest : public testing::Test { |
| 41 public: | 59 public: |
| 42 std::vector<PositionScaleDrawImage> GetDiscardableImagesInRect( | 60 std::vector<PositionScaleDrawImage> GetDiscardableImagesInRect( |
| 43 const DiscardableImageMap& image_map, | 61 const DiscardableImageMap& image_map, |
| 44 const gfx::Rect& rect) { | 62 const gfx::Rect& rect) { |
| 45 std::vector<DrawImage> draw_images; | 63 std::vector<DrawImage> draw_images; |
| 46 // 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 |
| 47 // is passed correctly to the resulting DrawImages. | 65 // is passed correctly to the resulting DrawImages. |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 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), |
| 106 flags); | 124 flags); |
| 107 } | 125 } |
| 108 } | 126 } |
| 109 } | 127 } |
| 110 | 128 |
| 111 scoped_refptr<DisplayItemList> display_list = | 129 scoped_refptr<DisplayItemList> display_list = |
| 112 content_layer_client.PaintContentsToDisplayList( | 130 content_layer_client.PaintContentsToDisplayList( |
| 113 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); | 131 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); |
| 114 | 132 |
| 115 DiscardableImageMap image_map; | 133 const DiscardableImageMap& image_map = |
| 116 { | 134 display_list->discardable_image_map_for_testing(); |
| 117 DiscardableImageMap::ScopedMetadataGenerator generator(&image_map, | |
| 118 visible_rect.size()); | |
| 119 display_list->Raster(generator.canvas(), nullptr, gfx::Rect(), 1.f); | |
| 120 } | |
| 121 | 135 |
| 122 for (int y = 0; y < 4; ++y) { | 136 for (int y = 0; y < 4; ++y) { |
| 123 for (int x = 0; x < 4; ++x) { | 137 for (int x = 0; x < 4; ++x) { |
| 124 std::vector<PositionScaleDrawImage> images = GetDiscardableImagesInRect( | 138 std::vector<PositionScaleDrawImage> images = GetDiscardableImagesInRect( |
| 125 image_map, gfx::Rect(x * 512, y * 512, 500, 500)); | 139 image_map, gfx::Rect(x * 512, y * 512, 500, 500)); |
| 126 std::vector<gfx::Rect> inset_rects = InsetImageRects(images); | 140 std::vector<gfx::Rect> inset_rects = InsetImageRects(images); |
| 127 if ((x + y) & 1) { | 141 if ((x + y) & 1) { |
| 128 EXPECT_EQ(1u, images.size()) << x << " " << y; | 142 EXPECT_EQ(1u, images.size()) << x << " " << y; |
| 129 EXPECT_TRUE(images[0].image == discardable_image[y][x]) | 143 EXPECT_TRUE(images[0].image == discardable_image[y][x]) |
| 130 << x << " " << y; | 144 << x << " " << y; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 discardable_image[y][x], | 206 discardable_image[y][x], |
| 193 gfx::Point(1024 + x * 512 + 6, y * 512 + 6), flags); | 207 gfx::Point(1024 + x * 512 + 6, y * 512 + 6), flags); |
| 194 } | 208 } |
| 195 } | 209 } |
| 196 } | 210 } |
| 197 | 211 |
| 198 scoped_refptr<DisplayItemList> display_list = | 212 scoped_refptr<DisplayItemList> display_list = |
| 199 content_layer_client.PaintContentsToDisplayList( | 213 content_layer_client.PaintContentsToDisplayList( |
| 200 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); | 214 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); |
| 201 | 215 |
| 202 DiscardableImageMap image_map; | 216 const DiscardableImageMap& image_map = |
| 203 { | 217 display_list->discardable_image_map_for_testing(); |
| 204 DiscardableImageMap::ScopedMetadataGenerator generator(&image_map, | |
| 205 layer_size); | |
| 206 display_list->Raster(generator.canvas(), nullptr, gfx::Rect(), 1.f); | |
| 207 } | |
| 208 | 218 |
| 209 for (int y = 0; y < 4; ++y) { | 219 for (int y = 0; y < 4; ++y) { |
| 210 for (int x = 0; x < 4; ++x) { | 220 for (int x = 0; x < 4; ++x) { |
| 211 std::vector<PositionScaleDrawImage> images = GetDiscardableImagesInRect( | 221 std::vector<PositionScaleDrawImage> images = GetDiscardableImagesInRect( |
| 212 image_map, gfx::Rect(1024 + x * 512, y * 512, 500, 500)); | 222 image_map, gfx::Rect(1024 + x * 512, y * 512, 500, 500)); |
| 213 std::vector<gfx::Rect> inset_rects = InsetImageRects(images); | 223 std::vector<gfx::Rect> inset_rects = InsetImageRects(images); |
| 214 if ((x + y) & 1) { | 224 if ((x + y) & 1) { |
| 215 EXPECT_EQ(1u, images.size()) << x << " " << y; | 225 EXPECT_EQ(1u, images.size()) << x << " " << y; |
| 216 EXPECT_TRUE(images[0].image == discardable_image[y][x]) | 226 EXPECT_TRUE(images[0].image == discardable_image[y][x]) |
| 217 << x << " " << y; | 227 << x << " " << y; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 discardable_image[y][x], gfx::Point(x * 512 + 6, y * 512 + 6), | 318 discardable_image[y][x], gfx::Point(x * 512 + 6, y * 512 + 6), |
| 309 flags); | 319 flags); |
| 310 } | 320 } |
| 311 } | 321 } |
| 312 } | 322 } |
| 313 | 323 |
| 314 scoped_refptr<DisplayItemList> display_list = | 324 scoped_refptr<DisplayItemList> display_list = |
| 315 content_layer_client.PaintContentsToDisplayList( | 325 content_layer_client.PaintContentsToDisplayList( |
| 316 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); | 326 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); |
| 317 | 327 |
| 318 DiscardableImageMap image_map; | 328 const DiscardableImageMap& image_map = |
| 319 { | 329 display_list->discardable_image_map_for_testing(); |
| 320 DiscardableImageMap::ScopedMetadataGenerator generator(&image_map, | |
| 321 visible_rect.size()); | |
| 322 display_list->Raster(generator.canvas(), nullptr, gfx::Rect(), 1.f); | |
| 323 } | |
| 324 | 330 |
| 325 for (int y = 0; y < 4; ++y) { | 331 for (int y = 0; y < 4; ++y) { |
| 326 for (int x = 0; x < 4; ++x) { | 332 for (int x = 0; x < 4; ++x) { |
| 327 std::vector<PositionScaleDrawImage> images = GetDiscardableImagesInRect( | 333 std::vector<PositionScaleDrawImage> images = GetDiscardableImagesInRect( |
| 328 image_map, gfx::Rect(x * 512 + 256, y * 512 + 256, 1, 1)); | 334 image_map, gfx::Rect(x * 512 + 256, y * 512 + 256, 1, 1)); |
| 329 std::vector<gfx::Rect> inset_rects = InsetImageRects(images); | 335 std::vector<gfx::Rect> inset_rects = InsetImageRects(images); |
| 330 if ((x + y) & 1) { | 336 if ((x + y) & 1) { |
| 331 EXPECT_EQ(1u, images.size()) << x << " " << y; | 337 EXPECT_EQ(1u, images.size()) << x << " " << y; |
| 332 EXPECT_TRUE(images[0].image == discardable_image[y][x]) | 338 EXPECT_TRUE(images[0].image == discardable_image[y][x]) |
| 333 << x << " " << y; | 339 << x << " " << y; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 350 sk_sp<SkImage> discardable_image = | 356 sk_sp<SkImage> discardable_image = |
| 351 CreateDiscardableImage(gfx::Size(1 << 25, 1 << 25)); | 357 CreateDiscardableImage(gfx::Size(1 << 25, 1 << 25)); |
| 352 PaintFlags flags; | 358 PaintFlags flags; |
| 353 content_layer_client.add_draw_image(discardable_image, gfx::Point(0, 0), | 359 content_layer_client.add_draw_image(discardable_image, gfx::Point(0, 0), |
| 354 flags); | 360 flags); |
| 355 | 361 |
| 356 scoped_refptr<DisplayItemList> display_list = | 362 scoped_refptr<DisplayItemList> display_list = |
| 357 content_layer_client.PaintContentsToDisplayList( | 363 content_layer_client.PaintContentsToDisplayList( |
| 358 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); | 364 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); |
| 359 | 365 |
| 360 DiscardableImageMap image_map; | 366 const DiscardableImageMap& image_map = |
| 361 { | 367 display_list->discardable_image_map_for_testing(); |
| 362 DiscardableImageMap::ScopedMetadataGenerator generator(&image_map, | |
| 363 visible_rect.size()); | |
| 364 display_list->Raster(generator.canvas(), nullptr, gfx::Rect(), 1.f); | |
| 365 } | |
| 366 std::vector<PositionScaleDrawImage> images = | 368 std::vector<PositionScaleDrawImage> images = |
| 367 GetDiscardableImagesInRect(image_map, gfx::Rect(0, 0, 1, 1)); | 369 GetDiscardableImagesInRect(image_map, gfx::Rect(0, 0, 1, 1)); |
| 368 std::vector<gfx::Rect> inset_rects = InsetImageRects(images); | 370 std::vector<gfx::Rect> inset_rects = InsetImageRects(images); |
| 369 EXPECT_EQ(1u, images.size()); | 371 EXPECT_EQ(1u, images.size()); |
| 370 EXPECT_TRUE(images[0].image == discardable_image); | 372 EXPECT_TRUE(images[0].image == discardable_image); |
| 371 EXPECT_EQ(gfx::Rect(0, 0, 2048, 2048), inset_rects[0]); | 373 EXPECT_EQ(gfx::Rect(0, 0, 2048, 2048), inset_rects[0]); |
| 372 EXPECT_EQ(images[0].image_rect, | 374 EXPECT_EQ(images[0].image_rect, |
| 373 image_map.GetRectForImage(images[0].image->uniqueID())); | 375 image_map.GetRectForImage(images[0].image->uniqueID())); |
| 374 } | 376 } |
| 375 | 377 |
| 376 TEST_F(DiscardableImageMapTest, PaintDestroyedWhileImageIsDrawn) { | 378 TEST_F(DiscardableImageMapTest, PaintDestroyedWhileImageIsDrawn) { |
| 377 gfx::Rect visible_rect(2048, 2048); | 379 gfx::Rect visible_rect(2048, 2048); |
| 378 FakeContentLayerClient content_layer_client; | 380 FakeContentLayerClient content_layer_client; |
| 379 content_layer_client.set_bounds(visible_rect.size()); | 381 content_layer_client.set_bounds(visible_rect.size()); |
| 380 | 382 |
| 381 sk_sp<SkImage> discardable_image = CreateDiscardableImage(gfx::Size(10, 10)); | 383 sk_sp<SkImage> discardable_image = CreateDiscardableImage(gfx::Size(10, 10)); |
| 384 sk_sp<PaintRecord> record = CreateRecording(discardable_image, visible_rect); |
| 382 | 385 |
| 383 DiscardableImageMap image_map; | 386 DiscardableImageMap image_map; |
| 384 { | 387 { |
| 385 DiscardableImageMap::ScopedMetadataGenerator generator(&image_map, | 388 DiscardableImageMap::ScopedMetadataGenerator generator(&image_map, |
| 386 visible_rect.size()); | 389 visible_rect.size()); |
| 390 DiscardableImageStore* image_store = generator.image_store(); |
| 387 { | 391 { |
| 388 std::unique_ptr<SkPaint> paint(new SkPaint()); | 392 std::unique_ptr<SkPaint> paint(new SkPaint()); |
| 389 generator.canvas()->saveLayer(gfx::RectToSkRect(visible_rect), | 393 image_store->NoDrawCanvas()->saveLayer(gfx::RectToSkRect(visible_rect), |
| 390 paint.get()); | 394 paint.get()); |
| 391 } | 395 } |
| 392 generator.canvas()->drawImage(discardable_image, 0, 0, nullptr); | 396 record->GatherDiscardableImages(image_store); |
| 393 generator.canvas()->restore(); | 397 image_store->NoDrawCanvas()->restore(); |
| 394 } | 398 } |
| 395 | 399 |
| 396 std::vector<PositionScaleDrawImage> images = | 400 std::vector<PositionScaleDrawImage> images = |
| 397 GetDiscardableImagesInRect(image_map, gfx::Rect(0, 0, 1, 1)); | 401 GetDiscardableImagesInRect(image_map, gfx::Rect(0, 0, 1, 1)); |
| 398 EXPECT_EQ(1u, images.size()); | 402 EXPECT_EQ(1u, images.size()); |
| 399 EXPECT_TRUE(images[0].image == discardable_image); | 403 EXPECT_TRUE(images[0].image == discardable_image); |
| 400 } | 404 } |
| 401 | 405 |
| 402 TEST_F(DiscardableImageMapTest, NullPaintOnSaveLayer) { | 406 TEST_F(DiscardableImageMapTest, NullPaintOnSaveLayer) { |
| 403 gfx::Rect visible_rect(2048, 2048); | 407 gfx::Rect visible_rect(2048, 2048); |
| 404 FakeContentLayerClient content_layer_client; | 408 FakeContentLayerClient content_layer_client; |
| 405 content_layer_client.set_bounds(visible_rect.size()); | 409 content_layer_client.set_bounds(visible_rect.size()); |
| 406 | 410 |
| 407 sk_sp<SkImage> discardable_image = CreateDiscardableImage(gfx::Size(10, 10)); | 411 sk_sp<SkImage> discardable_image = CreateDiscardableImage(gfx::Size(10, 10)); |
| 412 sk_sp<PaintRecord> record = CreateRecording(discardable_image, visible_rect); |
| 408 | 413 |
| 409 DiscardableImageMap image_map; | 414 DiscardableImageMap image_map; |
| 410 { | 415 { |
| 411 DiscardableImageMap::ScopedMetadataGenerator generator(&image_map, | 416 DiscardableImageMap::ScopedMetadataGenerator generator(&image_map, |
| 412 visible_rect.size()); | 417 visible_rect.size()); |
| 418 DiscardableImageStore* image_store = generator.image_store(); |
| 413 SkPaint* null_paint = nullptr; | 419 SkPaint* null_paint = nullptr; |
| 414 generator.canvas()->saveLayer(gfx::RectToSkRect(visible_rect), null_paint); | 420 image_store->NoDrawCanvas()->saveLayer(gfx::RectToSkRect(visible_rect), |
| 415 generator.canvas()->drawImage(discardable_image, 0, 0, nullptr); | 421 null_paint); |
| 416 generator.canvas()->restore(); | 422 record->GatherDiscardableImages(image_store); |
| 423 image_store->NoDrawCanvas()->restore(); |
| 417 } | 424 } |
| 418 | 425 |
| 419 std::vector<PositionScaleDrawImage> images = | 426 std::vector<PositionScaleDrawImage> images = |
| 420 GetDiscardableImagesInRect(image_map, gfx::Rect(0, 0, 1, 1)); | 427 GetDiscardableImagesInRect(image_map, gfx::Rect(0, 0, 1, 1)); |
| 421 EXPECT_EQ(1u, images.size()); | 428 EXPECT_EQ(1u, images.size()); |
| 422 EXPECT_TRUE(images[0].image == discardable_image); | 429 EXPECT_TRUE(images[0].image == discardable_image); |
| 423 } | 430 } |
| 424 | 431 |
| 425 TEST_F(DiscardableImageMapTest, GetDiscardableImagesInRectMaxImage) { | 432 TEST_F(DiscardableImageMapTest, GetDiscardableImagesInRectMaxImage) { |
| 426 gfx::Rect visible_rect(2048, 2048); | 433 gfx::Rect visible_rect(2048, 2048); |
| 427 FakeContentLayerClient content_layer_client; | 434 FakeContentLayerClient content_layer_client; |
| 428 content_layer_client.set_bounds(visible_rect.size()); | 435 content_layer_client.set_bounds(visible_rect.size()); |
| 429 | 436 |
| 430 int dimension = std::numeric_limits<int>::max(); | 437 int dimension = std::numeric_limits<int>::max(); |
| 431 sk_sp<SkImage> discardable_image = | 438 sk_sp<SkImage> discardable_image = |
| 432 CreateDiscardableImage(gfx::Size(dimension, dimension)); | 439 CreateDiscardableImage(gfx::Size(dimension, dimension)); |
| 433 PaintFlags flags; | 440 PaintFlags flags; |
| 434 content_layer_client.add_draw_image(discardable_image, gfx::Point(42, 42), | 441 content_layer_client.add_draw_image(discardable_image, gfx::Point(42, 42), |
| 435 flags); | 442 flags); |
| 436 | 443 |
| 437 scoped_refptr<DisplayItemList> display_list = | 444 scoped_refptr<DisplayItemList> display_list = |
| 438 content_layer_client.PaintContentsToDisplayList( | 445 content_layer_client.PaintContentsToDisplayList( |
| 439 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); | 446 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); |
| 440 | 447 |
| 441 DiscardableImageMap image_map; | 448 const DiscardableImageMap& image_map = |
| 442 { | 449 display_list->discardable_image_map_for_testing(); |
| 443 DiscardableImageMap::ScopedMetadataGenerator generator(&image_map, | |
| 444 visible_rect.size()); | |
| 445 display_list->Raster(generator.canvas(), nullptr, visible_rect, 1.f); | |
| 446 } | |
| 447 std::vector<PositionScaleDrawImage> images = | 450 std::vector<PositionScaleDrawImage> images = |
| 448 GetDiscardableImagesInRect(image_map, gfx::Rect(42, 42, 1, 1)); | 451 GetDiscardableImagesInRect(image_map, gfx::Rect(42, 42, 1, 1)); |
| 449 std::vector<gfx::Rect> inset_rects = InsetImageRects(images); | 452 std::vector<gfx::Rect> inset_rects = InsetImageRects(images); |
| 450 EXPECT_EQ(1u, images.size()); | 453 EXPECT_EQ(1u, images.size()); |
| 451 EXPECT_TRUE(images[0].image == discardable_image); | 454 EXPECT_TRUE(images[0].image == discardable_image); |
| 452 EXPECT_EQ(gfx::Rect(42, 42, 2006, 2006), inset_rects[0]); | 455 EXPECT_EQ(gfx::Rect(42, 42, 2006, 2006), inset_rects[0]); |
| 453 EXPECT_EQ(images[0].image_rect, | 456 EXPECT_EQ(images[0].image_rect, |
| 454 image_map.GetRectForImage(images[0].image->uniqueID())); | 457 image_map.GetRectForImage(images[0].image->uniqueID())); |
| 455 } | 458 } |
| 456 | 459 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 473 flags); | 476 flags); |
| 474 content_layer_client.add_draw_image(discardable_image, gfx::Point(10000, 0), | 477 content_layer_client.add_draw_image(discardable_image, gfx::Point(10000, 0), |
| 475 flags); | 478 flags); |
| 476 content_layer_client.add_draw_image(discardable_image, | 479 content_layer_client.add_draw_image(discardable_image, |
| 477 gfx::Point(-10000, 500), flags); | 480 gfx::Point(-10000, 500), flags); |
| 478 | 481 |
| 479 scoped_refptr<DisplayItemList> display_list = | 482 scoped_refptr<DisplayItemList> display_list = |
| 480 content_layer_client.PaintContentsToDisplayList( | 483 content_layer_client.PaintContentsToDisplayList( |
| 481 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); | 484 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); |
| 482 | 485 |
| 483 DiscardableImageMap image_map; | 486 const DiscardableImageMap& image_map = |
| 484 { | 487 display_list->discardable_image_map_for_testing(); |
| 485 DiscardableImageMap::ScopedMetadataGenerator generator(&image_map, | |
| 486 visible_rect.size()); | |
| 487 display_list->Raster(generator.canvas(), nullptr, visible_rect, 1.f); | |
| 488 } | |
| 489 std::vector<PositionScaleDrawImage> images = | 488 std::vector<PositionScaleDrawImage> images = |
| 490 GetDiscardableImagesInRect(image_map, gfx::Rect(0, 0, 1, 1)); | 489 GetDiscardableImagesInRect(image_map, gfx::Rect(0, 0, 1, 1)); |
| 491 std::vector<gfx::Rect> inset_rects = InsetImageRects(images); | 490 std::vector<gfx::Rect> inset_rects = InsetImageRects(images); |
| 492 EXPECT_EQ(1u, images.size()); | 491 EXPECT_EQ(1u, images.size()); |
| 493 EXPECT_EQ(gfx::Rect(0, 0, dimension, dimension), inset_rects[0]); | 492 EXPECT_EQ(gfx::Rect(0, 0, dimension, dimension), inset_rects[0]); |
| 494 | 493 |
| 495 images = GetDiscardableImagesInRect(image_map, gfx::Rect(10000, 0, 1, 1)); | 494 images = GetDiscardableImagesInRect(image_map, gfx::Rect(10000, 0, 1, 1)); |
| 496 inset_rects = InsetImageRects(images); | 495 inset_rects = InsetImageRects(images); |
| 497 EXPECT_EQ(2u, images.size()); | 496 EXPECT_EQ(2u, images.size()); |
| 498 EXPECT_EQ(gfx::Rect(10000, 0, dimension - 10000, dimension), inset_rects[1]); | 497 EXPECT_EQ(gfx::Rect(10000, 0, dimension - 10000, dimension), inset_rects[1]); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 528 flags); | 527 flags); |
| 529 content_layer_client.add_draw_image(discardable_image, gfx::Point(950, 951), | 528 content_layer_client.add_draw_image(discardable_image, gfx::Point(950, 951), |
| 530 flags); | 529 flags); |
| 531 content_layer_client.add_draw_image(long_discardable_image, | 530 content_layer_client.add_draw_image(long_discardable_image, |
| 532 gfx::Point(-100, 500), flags); | 531 gfx::Point(-100, 500), flags); |
| 533 | 532 |
| 534 scoped_refptr<DisplayItemList> display_list = | 533 scoped_refptr<DisplayItemList> display_list = |
| 535 content_layer_client.PaintContentsToDisplayList( | 534 content_layer_client.PaintContentsToDisplayList( |
| 536 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); | 535 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); |
| 537 | 536 |
| 538 DiscardableImageMap image_map; | 537 const DiscardableImageMap& image_map = |
| 539 { | 538 display_list->discardable_image_map_for_testing(); |
| 540 DiscardableImageMap::ScopedMetadataGenerator generator(&image_map, | |
| 541 visible_rect.size()); | |
| 542 display_list->Raster(generator.canvas(), nullptr, visible_rect, 1.f); | |
| 543 } | |
| 544 std::vector<PositionScaleDrawImage> images = | 539 std::vector<PositionScaleDrawImage> images = |
| 545 GetDiscardableImagesInRect(image_map, gfx::Rect(0, 0, 1, 1)); | 540 GetDiscardableImagesInRect(image_map, gfx::Rect(0, 0, 1, 1)); |
| 546 std::vector<gfx::Rect> inset_rects = InsetImageRects(images); | 541 std::vector<gfx::Rect> inset_rects = InsetImageRects(images); |
| 547 EXPECT_EQ(1u, images.size()); | 542 EXPECT_EQ(1u, images.size()); |
| 548 EXPECT_EQ(gfx::Rect(0, 0, 90, 89), inset_rects[0]); | 543 EXPECT_EQ(gfx::Rect(0, 0, 90, 89), inset_rects[0]); |
| 549 | 544 |
| 550 images = GetDiscardableImagesInRect(image_map, gfx::Rect(999, 999, 1, 1)); | 545 images = GetDiscardableImagesInRect(image_map, gfx::Rect(999, 999, 1, 1)); |
| 551 inset_rects = InsetImageRects(images); | 546 inset_rects = InsetImageRects(images); |
| 552 EXPECT_EQ(1u, images.size()); | 547 EXPECT_EQ(1u, images.size()); |
| 553 EXPECT_EQ(gfx::Rect(950, 951, 50, 49), inset_rects[0]); | 548 EXPECT_EQ(gfx::Rect(950, 951, 50, 49), inset_rects[0]); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 content_layer_client.add_draw_rect( | 596 content_layer_client.add_draw_rect( |
| 602 gfx::Rect(x * 512 + 6, y * 512 + 6, 500, 500), flags); | 597 gfx::Rect(x * 512 + 6, y * 512 + 6, 500, 500), flags); |
| 603 } | 598 } |
| 604 } | 599 } |
| 605 } | 600 } |
| 606 | 601 |
| 607 scoped_refptr<DisplayItemList> display_list = | 602 scoped_refptr<DisplayItemList> display_list = |
| 608 content_layer_client.PaintContentsToDisplayList( | 603 content_layer_client.PaintContentsToDisplayList( |
| 609 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); | 604 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL); |
| 610 | 605 |
| 611 DiscardableImageMap image_map; | 606 const DiscardableImageMap& image_map = |
| 612 { | 607 display_list->discardable_image_map_for_testing(); |
| 613 DiscardableImageMap::ScopedMetadataGenerator generator(&image_map, | |
| 614 visible_rect.size()); | |
| 615 display_list->Raster(generator.canvas(), nullptr, gfx::Rect(), 1.f); | |
| 616 } | |
| 617 | 608 |
| 618 for (int y = 0; y < 4; ++y) { | 609 for (int y = 0; y < 4; ++y) { |
| 619 for (int x = 0; x < 4; ++x) { | 610 for (int x = 0; x < 4; ++x) { |
| 620 std::vector<PositionScaleDrawImage> images = GetDiscardableImagesInRect( | 611 std::vector<PositionScaleDrawImage> images = GetDiscardableImagesInRect( |
| 621 image_map, gfx::Rect(x * 512, y * 512, 500, 500)); | 612 image_map, gfx::Rect(x * 512, y * 512, 500, 500)); |
| 622 std::vector<gfx::Rect> inset_rects = InsetImageRects(images); | 613 std::vector<gfx::Rect> inset_rects = InsetImageRects(images); |
| 623 if ((x + y) & 1) { | 614 if ((x + y) & 1) { |
| 624 EXPECT_EQ(1u, images.size()) << x << " " << y; | 615 EXPECT_EQ(1u, images.size()) << x << " " << y; |
| 625 EXPECT_TRUE(images[0].image == discardable_image[y][x]) | 616 EXPECT_TRUE(images[0].image == discardable_image[y][x]) |
| 626 << x << " " << y; | 617 << x << " " << y; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 642 EXPECT_TRUE(images[0].image == discardable_image[1][2]); | 633 EXPECT_TRUE(images[0].image == discardable_image[1][2]); |
| 643 EXPECT_EQ(gfx::Rect(2 * 512 + 6, 512 + 6, 500, 500), inset_rects[0]); | 634 EXPECT_EQ(gfx::Rect(2 * 512 + 6, 512 + 6, 500, 500), inset_rects[0]); |
| 644 EXPECT_TRUE(images[1].image == discardable_image[2][1]); | 635 EXPECT_TRUE(images[1].image == discardable_image[2][1]); |
| 645 EXPECT_EQ(gfx::Rect(512 + 6, 2 * 512 + 6, 500, 500), inset_rects[1]); | 636 EXPECT_EQ(gfx::Rect(512 + 6, 2 * 512 + 6, 500, 500), inset_rects[1]); |
| 646 EXPECT_TRUE(images[2].image == discardable_image[2][3]); | 637 EXPECT_TRUE(images[2].image == discardable_image[2][3]); |
| 647 EXPECT_EQ(gfx::Rect(3 * 512 + 6, 2 * 512 + 6, 500, 500), inset_rects[2]); | 638 EXPECT_EQ(gfx::Rect(3 * 512 + 6, 2 * 512 + 6, 500, 500), inset_rects[2]); |
| 648 EXPECT_TRUE(images[3].image == discardable_image[3][2]); | 639 EXPECT_TRUE(images[3].image == discardable_image[3][2]); |
| 649 EXPECT_EQ(gfx::Rect(2 * 512 + 6, 3 * 512 + 6, 500, 500), inset_rects[3]); | 640 EXPECT_EQ(gfx::Rect(2 * 512 + 6, 3 * 512 + 6, 500, 500), inset_rects[3]); |
| 650 } | 641 } |
| 651 | 642 |
| 643 TEST_F(DiscardableImageMapTest, ClipsImageRects) { |
| 644 gfx::Rect visible_rect(500, 500); |
| 645 |
| 646 sk_sp<const SkImage> discardable_image = |
| 647 CreateDiscardableImage(gfx::Size(500, 500)); |
| 648 sk_sp<PaintRecord> record = CreateRecording(discardable_image, visible_rect); |
| 649 |
| 650 scoped_refptr<DisplayItemList> display_list = new DisplayItemList; |
| 651 display_list->CreateAndAppendPairedBeginItem<ClipDisplayItem>( |
| 652 gfx::Rect(250, 250), std::vector<SkRRect>(), false); |
| 653 display_list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
| 654 gfx::Rect(500, 500), record); |
| 655 display_list->CreateAndAppendPairedEndItem<EndClipDisplayItem>(); |
| 656 display_list->Finalize(); |
| 657 |
| 658 const DiscardableImageMap& image_map = |
| 659 display_list->discardable_image_map_for_testing(); |
| 660 std::vector<PositionScaleDrawImage> images = |
| 661 GetDiscardableImagesInRect(image_map, visible_rect); |
| 662 std::vector<gfx::Rect> inset_rects = InsetImageRects(images); |
| 663 EXPECT_EQ(1u, images.size()); |
| 664 EXPECT_TRUE(images[0].image == discardable_image); |
| 665 EXPECT_EQ(gfx::Rect(250, 250), inset_rects[0]); |
| 666 } |
| 667 |
| 652 } // namespace cc | 668 } // namespace cc |
| OLD | NEW |