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