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/raster/image_hijack_canvas.h" | 4 #include "cc/raster/image_hijack_canvas.h" |
5 | 5 |
6 #include "cc/test/skia_common.h" | 6 #include "cc/test/skia_common.h" |
7 #include "cc/tiles/image_decode_cache.h" | 7 #include "cc/tiles/image_decode_cache.h" |
8 #include "testing/gmock/include/gmock/gmock.h" | 8 #include "testing/gmock/include/gmock/gmock.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "third_party/skia/include/core/SkBitmap.h" | 10 #include "third_party/skia/include/core/SkBitmap.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 void(bool aggressively_free_resources)); | 31 void(bool aggressively_free_resources)); |
32 MOCK_METHOD2(GetOutOfRasterDecodeTaskForImageAndRef, | 32 MOCK_METHOD2(GetOutOfRasterDecodeTaskForImageAndRef, |
33 bool(const DrawImage& image, scoped_refptr<TileTask>* task)); | 33 bool(const DrawImage& image, scoped_refptr<TileTask>* task)); |
34 }; | 34 }; |
35 | 35 |
36 TEST(ImageHijackCanvasTest, NonLazyImagesSkipped) { | 36 TEST(ImageHijackCanvasTest, NonLazyImagesSkipped) { |
37 // 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 |
38 // will hit an error. | 38 // will hit an error. |
39 testing::StrictMock<MockImageDecodeCache> image_decode_cache; | 39 testing::StrictMock<MockImageDecodeCache> image_decode_cache; |
40 ImageIdFlatSet images_to_skip; | 40 ImageIdFlatSet images_to_skip; |
41 ImageHijackCanvas canvas(100, 100, &image_decode_cache, &images_to_skip); | 41 gfx::ColorSpace target_color_space = gfx::ColorSpace::CreateSRGB(); |
| 42 ImageHijackCanvas canvas(100, 100, &image_decode_cache, &images_to_skip, |
| 43 target_color_space); |
42 | 44 |
43 // Use an SkBitmap backed image to ensure that the image is not | 45 // Use an SkBitmap backed image to ensure that the image is not |
44 // lazy-generated. | 46 // lazy-generated. |
45 SkBitmap bitmap; | 47 SkBitmap bitmap; |
46 bitmap.allocN32Pixels(10, 10, true); | 48 bitmap.allocN32Pixels(10, 10, true); |
47 sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); | 49 sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
48 | 50 |
49 SkPaint paint; | 51 SkPaint paint; |
50 canvas.drawImage(image, 0, 0, &paint); | 52 canvas.drawImage(image, 0, 0, &paint); |
51 canvas.drawImageRect(image, SkRect::MakeXYWH(0, 0, 10, 10), | 53 canvas.drawImageRect(image, SkRect::MakeXYWH(0, 0, 10, 10), |
(...skipping 12 matching lines...) Expand all Loading... |
64 canvas.drawRRect(SkRRect::MakeRect(paint_rect), image_paint); | 66 canvas.drawRRect(SkRRect::MakeRect(paint_rect), image_paint); |
65 } | 67 } |
66 | 68 |
67 TEST(ImageHijackCanvasTest, ImagesToSkipAreSkipped) { | 69 TEST(ImageHijackCanvasTest, ImagesToSkipAreSkipped) { |
68 // Use a strict mock so that if *any* ImageDecodeCache methods are called, we | 70 // Use a strict mock so that if *any* ImageDecodeCache methods are called, we |
69 // will hit an error. | 71 // will hit an error. |
70 testing::StrictMock<MockImageDecodeCache> image_decode_cache; | 72 testing::StrictMock<MockImageDecodeCache> image_decode_cache; |
71 ImageIdFlatSet images_to_skip; | 73 ImageIdFlatSet images_to_skip; |
72 sk_sp<SkImage> image = CreateDiscardableImage(gfx::Size(10, 10)); | 74 sk_sp<SkImage> image = CreateDiscardableImage(gfx::Size(10, 10)); |
73 images_to_skip.insert(image->uniqueID()); | 75 images_to_skip.insert(image->uniqueID()); |
74 ImageHijackCanvas canvas(100, 100, &image_decode_cache, &images_to_skip); | 76 gfx::ColorSpace target_color_space = gfx::ColorSpace::CreateSRGB(); |
| 77 ImageHijackCanvas canvas(100, 100, &image_decode_cache, &images_to_skip, |
| 78 target_color_space); |
75 | 79 |
76 SkPaint paint; | 80 SkPaint paint; |
77 canvas.drawImage(image, 0, 0, &paint); | 81 canvas.drawImage(image, 0, 0, &paint); |
78 canvas.drawImageRect(image, SkRect::MakeXYWH(0, 0, 10, 10), | 82 canvas.drawImageRect(image, SkRect::MakeXYWH(0, 0, 10, 10), |
79 SkRect::MakeXYWH(10, 10, 10, 10), &paint); | 83 SkRect::MakeXYWH(10, 10, 10, 10), &paint); |
80 paint.setShader(image->makeShader(SkShader::kClamp_TileMode, | 84 paint.setShader(image->makeShader(SkShader::kClamp_TileMode, |
81 SkShader::kClamp_TileMode, nullptr)); | 85 SkShader::kClamp_TileMode, nullptr)); |
82 canvas.drawRect(SkRect::MakeXYWH(10, 10, 10, 10), paint); | 86 canvas.drawRect(SkRect::MakeXYWH(10, 10, 10, 10), paint); |
83 } | 87 } |
84 | 88 |
85 } // namespace | 89 } // namespace |
86 | 90 |
87 } // namespace cc | 91 } // namespace cc |
OLD | NEW |