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/playback/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/test/fake_content_layer_client.h" | 14 #include "cc/test/fake_content_layer_client.h" |
15 #include "cc/test/fake_recording_source.h" | 15 #include "cc/test/fake_recording_source.h" |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 display_list->Raster(generator.canvas(), nullptr, gfx::Rect(), 1.f); | 113 display_list->Raster(generator.canvas(), nullptr, gfx::Rect(), 1.f); |
114 } | 114 } |
115 | 115 |
116 for (int y = 0; y < 4; ++y) { | 116 for (int y = 0; y < 4; ++y) { |
117 for (int x = 0; x < 4; ++x) { | 117 for (int x = 0; x < 4; ++x) { |
118 std::vector<PositionScaleDrawImage> images = GetDiscardableImagesInRect( | 118 std::vector<PositionScaleDrawImage> images = GetDiscardableImagesInRect( |
119 image_map, gfx::Rect(x * 512, y * 512, 500, 500)); | 119 image_map, gfx::Rect(x * 512, y * 512, 500, 500)); |
120 std::vector<gfx::Rect> inset_rects = InsetImageRects(images); | 120 std::vector<gfx::Rect> inset_rects = InsetImageRects(images); |
121 if ((x + y) & 1) { | 121 if ((x + y) & 1) { |
122 EXPECT_EQ(1u, images.size()) << x << " " << y; | 122 EXPECT_EQ(1u, images.size()) << x << " " << y; |
123 EXPECT_TRUE(images[0].image == discardable_image[y][x]) << x << " " | 123 EXPECT_TRUE(images[0].image == discardable_image[y][x]) |
124 << y; | 124 << x << " " << y; |
125 EXPECT_EQ(gfx::Rect(x * 512 + 6, y * 512 + 6, 500, 500), | 125 EXPECT_EQ(gfx::Rect(x * 512 + 6, y * 512 + 6, 500, 500), |
126 inset_rects[0]); | 126 inset_rects[0]); |
127 EXPECT_EQ(images[0].image_rect, | 127 EXPECT_EQ(images[0].image_rect, |
128 image_map.GetRectForImage(images[0].image->uniqueID())); | 128 image_map.GetRectForImage(images[0].image->uniqueID())); |
129 } else { | 129 } else { |
130 EXPECT_EQ(0u, images.size()) << x << " " << y; | 130 EXPECT_EQ(0u, images.size()) << x << " " << y; |
131 } | 131 } |
132 } | 132 } |
133 } | 133 } |
134 | 134 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 display_list->Raster(generator.canvas(), nullptr, gfx::Rect(), 1.f); | 200 display_list->Raster(generator.canvas(), nullptr, gfx::Rect(), 1.f); |
201 } | 201 } |
202 | 202 |
203 for (int y = 0; y < 4; ++y) { | 203 for (int y = 0; y < 4; ++y) { |
204 for (int x = 0; x < 4; ++x) { | 204 for (int x = 0; x < 4; ++x) { |
205 std::vector<PositionScaleDrawImage> images = GetDiscardableImagesInRect( | 205 std::vector<PositionScaleDrawImage> images = GetDiscardableImagesInRect( |
206 image_map, gfx::Rect(1024 + x * 512, y * 512, 500, 500)); | 206 image_map, gfx::Rect(1024 + x * 512, y * 512, 500, 500)); |
207 std::vector<gfx::Rect> inset_rects = InsetImageRects(images); | 207 std::vector<gfx::Rect> inset_rects = InsetImageRects(images); |
208 if ((x + y) & 1) { | 208 if ((x + y) & 1) { |
209 EXPECT_EQ(1u, images.size()) << x << " " << y; | 209 EXPECT_EQ(1u, images.size()) << x << " " << y; |
210 EXPECT_TRUE(images[0].image == discardable_image[y][x]) << x << " " | 210 EXPECT_TRUE(images[0].image == discardable_image[y][x]) |
211 << y; | 211 << x << " " << y; |
212 EXPECT_EQ(gfx::Rect(1024 + x * 512 + 6, y * 512 + 6, 500, 500), | 212 EXPECT_EQ(gfx::Rect(1024 + x * 512 + 6, y * 512 + 6, 500, 500), |
213 inset_rects[0]); | 213 inset_rects[0]); |
214 EXPECT_EQ(images[0].image_rect, | 214 EXPECT_EQ(images[0].image_rect, |
215 image_map.GetRectForImage(images[0].image->uniqueID())); | 215 image_map.GetRectForImage(images[0].image->uniqueID())); |
216 } else { | 216 } else { |
217 EXPECT_EQ(0u, images.size()) << x << " " << y; | 217 EXPECT_EQ(0u, images.size()) << x << " " << y; |
218 } | 218 } |
219 } | 219 } |
220 } | 220 } |
221 // Capture 4 pixel refs. | 221 // Capture 4 pixel refs. |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 display_list->Raster(generator.canvas(), nullptr, gfx::Rect(), 1.f); | 316 display_list->Raster(generator.canvas(), nullptr, gfx::Rect(), 1.f); |
317 } | 317 } |
318 | 318 |
319 for (int y = 0; y < 4; ++y) { | 319 for (int y = 0; y < 4; ++y) { |
320 for (int x = 0; x < 4; ++x) { | 320 for (int x = 0; x < 4; ++x) { |
321 std::vector<PositionScaleDrawImage> images = GetDiscardableImagesInRect( | 321 std::vector<PositionScaleDrawImage> images = GetDiscardableImagesInRect( |
322 image_map, gfx::Rect(x * 512 + 256, y * 512 + 256, 1, 1)); | 322 image_map, gfx::Rect(x * 512 + 256, y * 512 + 256, 1, 1)); |
323 std::vector<gfx::Rect> inset_rects = InsetImageRects(images); | 323 std::vector<gfx::Rect> inset_rects = InsetImageRects(images); |
324 if ((x + y) & 1) { | 324 if ((x + y) & 1) { |
325 EXPECT_EQ(1u, images.size()) << x << " " << y; | 325 EXPECT_EQ(1u, images.size()) << x << " " << y; |
326 EXPECT_TRUE(images[0].image == discardable_image[y][x]) << x << " " | 326 EXPECT_TRUE(images[0].image == discardable_image[y][x]) |
327 << y; | 327 << x << " " << y; |
328 EXPECT_EQ(gfx::Rect(x * 512 + 6, y * 512 + 6, 500, 500), | 328 EXPECT_EQ(gfx::Rect(x * 512 + 6, y * 512 + 6, 500, 500), |
329 inset_rects[0]); | 329 inset_rects[0]); |
330 EXPECT_EQ(images[0].image_rect, | 330 EXPECT_EQ(images[0].image_rect, |
331 image_map.GetRectForImage(images[0].image->uniqueID())); | 331 image_map.GetRectForImage(images[0].image->uniqueID())); |
332 } else { | 332 } else { |
333 EXPECT_EQ(0u, images.size()) << x << " " << y; | 333 EXPECT_EQ(0u, images.size()) << x << " " << y; |
334 } | 334 } |
335 } | 335 } |
336 } | 336 } |
337 } | 337 } |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 display_list->Raster(generator.canvas(), nullptr, gfx::Rect(), 1.f); | 609 display_list->Raster(generator.canvas(), nullptr, gfx::Rect(), 1.f); |
610 } | 610 } |
611 | 611 |
612 for (int y = 0; y < 4; ++y) { | 612 for (int y = 0; y < 4; ++y) { |
613 for (int x = 0; x < 4; ++x) { | 613 for (int x = 0; x < 4; ++x) { |
614 std::vector<PositionScaleDrawImage> images = GetDiscardableImagesInRect( | 614 std::vector<PositionScaleDrawImage> images = GetDiscardableImagesInRect( |
615 image_map, gfx::Rect(x * 512, y * 512, 500, 500)); | 615 image_map, gfx::Rect(x * 512, y * 512, 500, 500)); |
616 std::vector<gfx::Rect> inset_rects = InsetImageRects(images); | 616 std::vector<gfx::Rect> inset_rects = InsetImageRects(images); |
617 if ((x + y) & 1) { | 617 if ((x + y) & 1) { |
618 EXPECT_EQ(1u, images.size()) << x << " " << y; | 618 EXPECT_EQ(1u, images.size()) << x << " " << y; |
619 EXPECT_TRUE(images[0].image == discardable_image[y][x]) << x << " " | 619 EXPECT_TRUE(images[0].image == discardable_image[y][x]) |
620 << y; | 620 << x << " " << y; |
621 EXPECT_EQ(gfx::Rect(x * 512 + 6, y * 512 + 6, 500, 500), | 621 EXPECT_EQ(gfx::Rect(x * 512 + 6, y * 512 + 6, 500, 500), |
622 inset_rects[0]); | 622 inset_rects[0]); |
623 EXPECT_EQ(std::max(x * 0.5f, kMinScale), images[0].scale.fWidth); | 623 EXPECT_EQ(std::max(x * 0.5f, kMinScale), images[0].scale.fWidth); |
624 EXPECT_EQ(std::max(y * 0.5f, kMinScale), images[0].scale.fHeight); | 624 EXPECT_EQ(std::max(y * 0.5f, kMinScale), images[0].scale.fHeight); |
625 } else { | 625 } else { |
626 EXPECT_EQ(0u, images.size()) << x << " " << y; | 626 EXPECT_EQ(0u, images.size()) << x << " " << y; |
627 } | 627 } |
628 } | 628 } |
629 } | 629 } |
630 | 630 |
631 // Capture 4 pixel refs. | 631 // Capture 4 pixel refs. |
632 std::vector<PositionScaleDrawImage> images = | 632 std::vector<PositionScaleDrawImage> images = |
633 GetDiscardableImagesInRect(image_map, gfx::Rect(512, 512, 2048, 2048)); | 633 GetDiscardableImagesInRect(image_map, gfx::Rect(512, 512, 2048, 2048)); |
634 std::vector<gfx::Rect> inset_rects = InsetImageRects(images); | 634 std::vector<gfx::Rect> inset_rects = InsetImageRects(images); |
635 EXPECT_EQ(4u, images.size()); | 635 EXPECT_EQ(4u, images.size()); |
636 EXPECT_TRUE(images[0].image == discardable_image[1][2]); | 636 EXPECT_TRUE(images[0].image == discardable_image[1][2]); |
637 EXPECT_EQ(gfx::Rect(2 * 512 + 6, 512 + 6, 500, 500), inset_rects[0]); | 637 EXPECT_EQ(gfx::Rect(2 * 512 + 6, 512 + 6, 500, 500), inset_rects[0]); |
638 EXPECT_TRUE(images[1].image == discardable_image[2][1]); | 638 EXPECT_TRUE(images[1].image == discardable_image[2][1]); |
639 EXPECT_EQ(gfx::Rect(512 + 6, 2 * 512 + 6, 500, 500), inset_rects[1]); | 639 EXPECT_EQ(gfx::Rect(512 + 6, 2 * 512 + 6, 500, 500), inset_rects[1]); |
640 EXPECT_TRUE(images[2].image == discardable_image[2][3]); | 640 EXPECT_TRUE(images[2].image == discardable_image[2][3]); |
641 EXPECT_EQ(gfx::Rect(3 * 512 + 6, 2 * 512 + 6, 500, 500), inset_rects[2]); | 641 EXPECT_EQ(gfx::Rect(3 * 512 + 6, 2 * 512 + 6, 500, 500), inset_rects[2]); |
642 EXPECT_TRUE(images[3].image == discardable_image[3][2]); | 642 EXPECT_TRUE(images[3].image == discardable_image[3][2]); |
643 EXPECT_EQ(gfx::Rect(2 * 512 + 6, 3 * 512 + 6, 500, 500), inset_rects[3]); | 643 EXPECT_EQ(gfx::Rect(2 * 512 + 6, 3 * 512 + 6, 500, 500), inset_rects[3]); |
644 } | 644 } |
645 | 645 |
646 } // namespace cc | 646 } // namespace cc |
OLD | NEW |