OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #include "cc/playback/image_hijack_canvas.h" | 4 #include "cc/playback/image_hijack_canvas.h" |
5 | 5 |
| 6 #include "cc/test/skia_common.h" |
6 #include "cc/tiles/image_decode_cache.h" | 7 #include "cc/tiles/image_decode_cache.h" |
7 #include "testing/gmock/include/gmock/gmock.h" | 8 #include "testing/gmock/include/gmock/gmock.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "third_party/skia/include/core/SkBitmap.h" | 10 #include "third_party/skia/include/core/SkBitmap.h" |
10 #include "third_party/skia/include/core/SkImage.h" | 11 #include "third_party/skia/include/core/SkImage.h" |
11 #include "third_party/skia/include/core/SkPath.h" | 12 #include "third_party/skia/include/core/SkPath.h" |
12 | 13 |
13 namespace cc { | 14 namespace cc { |
14 namespace { | 15 namespace { |
15 | 16 |
(...skipping 13 matching lines...) Expand all Loading... |
29 MOCK_METHOD1(SetShouldAggressivelyFreeResources, | 30 MOCK_METHOD1(SetShouldAggressivelyFreeResources, |
30 void(bool aggressively_free_resources)); | 31 void(bool aggressively_free_resources)); |
31 MOCK_METHOD2(GetOutOfRasterDecodeTaskForImageAndRef, | 32 MOCK_METHOD2(GetOutOfRasterDecodeTaskForImageAndRef, |
32 bool(const DrawImage& image, scoped_refptr<TileTask>* task)); | 33 bool(const DrawImage& image, scoped_refptr<TileTask>* task)); |
33 }; | 34 }; |
34 | 35 |
35 TEST(ImageHijackCanvasTest, NonLazyImagesSkipped) { | 36 TEST(ImageHijackCanvasTest, NonLazyImagesSkipped) { |
36 // Use a strict mock so that if *any* ImageDecodeCache methods are called, we | 37 // Use a strict mock so that if *any* ImageDecodeCache methods are called, we |
37 // will hit an error. | 38 // will hit an error. |
38 testing::StrictMock<MockImageDecodeCache> image_decode_cache; | 39 testing::StrictMock<MockImageDecodeCache> image_decode_cache; |
39 ImageHijackCanvas canvas(100, 100, &image_decode_cache); | 40 ImageIdFlatSet images_to_skip; |
| 41 ImageHijackCanvas canvas(100, 100, &image_decode_cache, &images_to_skip); |
40 | 42 |
41 // Use an SkBitmap backed image to ensure that the image is not | 43 // Use an SkBitmap backed image to ensure that the image is not |
42 // lazy-generated. | 44 // lazy-generated. |
43 SkBitmap bitmap; | 45 SkBitmap bitmap; |
44 bitmap.allocN32Pixels(10, 10, true); | 46 bitmap.allocN32Pixels(10, 10, true); |
45 sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); | 47 sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
46 | 48 |
47 SkPaint paint; | 49 SkPaint paint; |
48 canvas.drawImage(image, 0, 0, &paint); | 50 canvas.drawImage(image, 0, 0, &paint); |
49 canvas.drawImageRect(image, SkRect::MakeXYWH(0, 0, 10, 10), | 51 canvas.drawImageRect(image, SkRect::MakeXYWH(0, 0, 10, 10), |
50 SkRect::MakeXYWH(10, 10, 10, 10), &paint); | 52 SkRect::MakeXYWH(10, 10, 10, 10), &paint); |
51 | 53 |
52 SkPaint image_paint; | 54 SkPaint image_paint; |
53 image_paint.setShader( | 55 image_paint.setShader( |
54 image->makeShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMode)); | 56 image->makeShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMode)); |
55 SkRect paint_rect = SkRect::MakeXYWH(0, 0, 100, 100); | 57 SkRect paint_rect = SkRect::MakeXYWH(0, 0, 100, 100); |
56 canvas.drawRect(paint_rect, image_paint); | 58 canvas.drawRect(paint_rect, image_paint); |
57 SkPath path; | 59 SkPath path; |
58 path.addRect(paint_rect, SkPath::kCW_Direction); | 60 path.addRect(paint_rect, SkPath::kCW_Direction); |
59 canvas.drawPath(path, image_paint); | 61 canvas.drawPath(path, image_paint); |
60 canvas.drawOval(paint_rect, image_paint); | 62 canvas.drawOval(paint_rect, image_paint); |
61 canvas.drawArc(paint_rect, 0, 40, true, image_paint); | 63 canvas.drawArc(paint_rect, 0, 40, true, image_paint); |
62 canvas.drawRRect(SkRRect::MakeRect(paint_rect), image_paint); | 64 canvas.drawRRect(SkRRect::MakeRect(paint_rect), image_paint); |
63 } | 65 } |
64 | 66 |
| 67 TEST(ImageHijackCanvasTest, ImagesToSkipAreSkipped) { |
| 68 // Use a strict mock so that if *any* ImageDecodeCache methods are called, we |
| 69 // will hit an error. |
| 70 testing::StrictMock<MockImageDecodeCache> image_decode_cache; |
| 71 ImageIdFlatSet images_to_skip; |
| 72 sk_sp<SkImage> image = CreateDiscardableImage(gfx::Size(10, 10)); |
| 73 images_to_skip.insert(image->uniqueID()); |
| 74 ImageHijackCanvas canvas(100, 100, &image_decode_cache, &images_to_skip); |
| 75 |
| 76 SkPaint paint; |
| 77 canvas.drawImage(image, 0, 0, &paint); |
| 78 canvas.drawImageRect(image, SkRect::MakeXYWH(0, 0, 10, 10), |
| 79 SkRect::MakeXYWH(10, 10, 10, 10), &paint); |
| 80 paint.setShader(image->makeShader(SkShader::kClamp_TileMode, |
| 81 SkShader::kClamp_TileMode, nullptr)); |
| 82 canvas.drawRect(SkRect::MakeXYWH(10, 10, 10, 10), paint); |
| 83 } |
| 84 |
65 } // namespace | 85 } // namespace |
66 | 86 |
67 } // namespace cc | 87 } // namespace cc |
OLD | NEW |