| 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 MOCK_CONST_METHOD0(GetMaximumMemoryLimitBytes, size_t()); | 35 MOCK_CONST_METHOD0(GetMaximumMemoryLimitBytes, size_t()); |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 TEST(ImageHijackCanvasTest, NonLazyImagesSkipped) { | 38 TEST(ImageHijackCanvasTest, NonLazyImagesSkipped) { |
| 39 // Use a strict mock so that if *any* ImageDecodeCache methods are called, we | 39 // Use a strict mock so that if *any* ImageDecodeCache methods are called, we |
| 40 // will hit an error. | 40 // will hit an error. |
| 41 testing::StrictMock<MockImageDecodeCache> image_decode_cache; | 41 testing::StrictMock<MockImageDecodeCache> image_decode_cache; |
| 42 ImageIdFlatSet images_to_skip; | 42 SkImageIdFlatSet images_to_skip; |
| 43 gfx::ColorSpace target_color_space = gfx::ColorSpace::CreateSRGB(); | 43 gfx::ColorSpace target_color_space = gfx::ColorSpace::CreateSRGB(); |
| 44 ImageHijackCanvas canvas(100, 100, &image_decode_cache, &images_to_skip, | 44 ImageHijackCanvas canvas(100, 100, &image_decode_cache, &images_to_skip, |
| 45 target_color_space); | 45 target_color_space); |
| 46 | 46 |
| 47 // Use an SkBitmap backed image to ensure that the image is not | 47 // Use an SkBitmap backed image to ensure that the image is not |
| 48 // lazy-generated. | 48 // lazy-generated. |
| 49 SkBitmap bitmap; | 49 SkBitmap bitmap; |
| 50 bitmap.allocN32Pixels(10, 10, true); | 50 bitmap.allocN32Pixels(10, 10, true); |
| 51 sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); | 51 sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap); |
| 52 | 52 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 65 canvas.drawPath(path, image_paint); | 65 canvas.drawPath(path, image_paint); |
| 66 canvas.drawOval(paint_rect, image_paint); | 66 canvas.drawOval(paint_rect, image_paint); |
| 67 canvas.drawArc(paint_rect, 0, 40, true, image_paint); | 67 canvas.drawArc(paint_rect, 0, 40, true, image_paint); |
| 68 canvas.drawRRect(SkRRect::MakeRect(paint_rect), image_paint); | 68 canvas.drawRRect(SkRRect::MakeRect(paint_rect), image_paint); |
| 69 } | 69 } |
| 70 | 70 |
| 71 TEST(ImageHijackCanvasTest, ImagesToSkipAreSkipped) { | 71 TEST(ImageHijackCanvasTest, ImagesToSkipAreSkipped) { |
| 72 // Use a strict mock so that if *any* ImageDecodeCache methods are called, we | 72 // Use a strict mock so that if *any* ImageDecodeCache methods are called, we |
| 73 // will hit an error. | 73 // will hit an error. |
| 74 testing::StrictMock<MockImageDecodeCache> image_decode_cache; | 74 testing::StrictMock<MockImageDecodeCache> image_decode_cache; |
| 75 ImageIdFlatSet images_to_skip; | 75 SkImageIdFlatSet images_to_skip; |
| 76 sk_sp<SkImage> image = CreateDiscardableImage(gfx::Size(10, 10)); | 76 sk_sp<SkImage> image = CreateDiscardableImage(gfx::Size(10, 10)); |
| 77 images_to_skip.insert(image->uniqueID()); | 77 images_to_skip.insert(image->uniqueID()); |
| 78 gfx::ColorSpace target_color_space = gfx::ColorSpace::CreateSRGB(); | 78 gfx::ColorSpace target_color_space = gfx::ColorSpace::CreateSRGB(); |
| 79 ImageHijackCanvas canvas(100, 100, &image_decode_cache, &images_to_skip, | 79 ImageHijackCanvas canvas(100, 100, &image_decode_cache, &images_to_skip, |
| 80 target_color_space); | 80 target_color_space); |
| 81 | 81 |
| 82 SkPaint paint; | 82 SkPaint paint; |
| 83 canvas.drawImage(image, 0, 0, &paint); | 83 canvas.drawImage(image, 0, 0, &paint); |
| 84 canvas.drawImageRect(image, SkRect::MakeXYWH(0, 0, 10, 10), | 84 canvas.drawImageRect(image, SkRect::MakeXYWH(0, 0, 10, 10), |
| 85 SkRect::MakeXYWH(10, 10, 10, 10), &paint); | 85 SkRect::MakeXYWH(10, 10, 10, 10), &paint); |
| 86 paint.setShader(image->makeShader(SkShader::kClamp_TileMode, | 86 paint.setShader(image->makeShader(SkShader::kClamp_TileMode, |
| 87 SkShader::kClamp_TileMode, nullptr)); | 87 SkShader::kClamp_TileMode, nullptr)); |
| 88 canvas.drawRect(SkRect::MakeXYWH(10, 10, 10, 10), paint); | 88 canvas.drawRect(SkRect::MakeXYWH(10, 10, 10, 10), paint); |
| 89 } | 89 } |
| 90 | 90 |
| 91 TEST(ImageHijackCanvasTest, ClippedOpsAreSkipped) { | 91 TEST(ImageHijackCanvasTest, ClippedOpsAreSkipped) { |
| 92 testing::StrictMock<MockImageDecodeCache> image_decode_cache; | 92 testing::StrictMock<MockImageDecodeCache> image_decode_cache; |
| 93 ImageIdFlatSet images_to_skip; | 93 SkImageIdFlatSet images_to_skip; |
| 94 gfx::ColorSpace target_color_space = gfx::ColorSpace::CreateSRGB(); | 94 gfx::ColorSpace target_color_space = gfx::ColorSpace::CreateSRGB(); |
| 95 ImageHijackCanvas canvas(100, 100, &image_decode_cache, &images_to_skip, | 95 ImageHijackCanvas canvas(100, 100, &image_decode_cache, &images_to_skip, |
| 96 target_color_space); | 96 target_color_space); |
| 97 SkPaint paint; | 97 SkPaint paint; |
| 98 SkRect draw_rect = SkRect::MakeXYWH(200, 200, 100, 100); | 98 SkRect draw_rect = SkRect::MakeXYWH(200, 200, 100, 100); |
| 99 sk_sp<SkImage> image = CreateDiscardableImage(gfx::Size(10, 10)); | 99 sk_sp<SkImage> image = CreateDiscardableImage(gfx::Size(10, 10)); |
| 100 canvas.drawImage(image, 200, 200, &paint); | 100 canvas.drawImage(image, 200, 200, &paint); |
| 101 canvas.drawImageRect(image, SkRect::MakeXYWH(0, 0, 10, 10), draw_rect, | 101 canvas.drawImageRect(image, SkRect::MakeXYWH(0, 0, 10, 10), draw_rect, |
| 102 &paint); | 102 &paint); |
| 103 paint.setShader(image->makeShader(SkShader::kClamp_TileMode, | 103 paint.setShader(image->makeShader(SkShader::kClamp_TileMode, |
| 104 SkShader::kClamp_TileMode, nullptr)); | 104 SkShader::kClamp_TileMode, nullptr)); |
| 105 canvas.drawRect(draw_rect, paint); | 105 canvas.drawRect(draw_rect, paint); |
| 106 SkPath path; | 106 SkPath path; |
| 107 path.addRect(draw_rect, SkPath::kCW_Direction); | 107 path.addRect(draw_rect, SkPath::kCW_Direction); |
| 108 canvas.drawPath(path, paint); | 108 canvas.drawPath(path, paint); |
| 109 canvas.drawOval(draw_rect, paint); | 109 canvas.drawOval(draw_rect, paint); |
| 110 canvas.drawArc(draw_rect, 0, 40, true, paint); | 110 canvas.drawArc(draw_rect, 0, 40, true, paint); |
| 111 canvas.drawRRect(SkRRect::MakeRect(draw_rect), paint); | 111 canvas.drawRRect(SkRRect::MakeRect(draw_rect), paint); |
| 112 } | 112 } |
| 113 | 113 |
| 114 } // namespace | 114 } // namespace |
| 115 | 115 |
| 116 } // namespace cc | 116 } // namespace cc |
| OLD | NEW |