| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "core/layout/ImageQualityController.h" | 5 #include "core/layout/ImageQualityController.h" |
| 6 | 6 |
| 7 #include "core/layout/LayoutImage.h" | 7 #include "core/layout/LayoutImage.h" |
| 8 #include "core/layout/LayoutTestHelper.h" | 8 #include "core/layout/LayoutTestHelper.h" |
| 9 #include "platform/graphics/GraphicsContext.h" | 9 #include "platform/graphics/GraphicsContext.h" |
| 10 #include "platform/graphics/paint/PaintController.h" | 10 #include "platform/graphics/paint/PaintController.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 bool currentFrameKnownToBeOpaque(MetadataMode = UseCurrentMetadata) override { | 53 bool currentFrameKnownToBeOpaque(MetadataMode = UseCurrentMetadata) override { |
| 54 return false; | 54 return false; |
| 55 } | 55 } |
| 56 IntSize size() const override { return IntSize(); } | 56 IntSize size() const override { return IntSize(); } |
| 57 void destroyDecodedData() override {} | 57 void destroyDecodedData() override {} |
| 58 void draw(SkCanvas*, | 58 void draw(SkCanvas*, |
| 59 const SkPaint&, | 59 const SkPaint&, |
| 60 const FloatRect& dstRect, | 60 const FloatRect& dstRect, |
| 61 const FloatRect& srcRect, | 61 const FloatRect& srcRect, |
| 62 RespectImageOrientationEnum, | 62 RespectImageOrientationEnum, |
| 63 ImageClampingMode) override {} | 63 ImageClampingMode, |
| 64 sk_sp<SkImage> imageForCurrentFrame() override { return nullptr; } | 64 const ColorBehavior&) override {} |
| 65 sk_sp<SkImage> imageForCurrentFrame(const ColorBehavior&) override { |
| 66 return nullptr; |
| 67 } |
| 65 }; | 68 }; |
| 66 | 69 |
| 67 TEST_F(ImageQualityControllerTest, ImageMaybeAnimated) { | 70 TEST_F(ImageQualityControllerTest, ImageMaybeAnimated) { |
| 68 setBodyInnerHTML("<img src='myimage'></img>"); | 71 setBodyInnerHTML("<img src='myimage'></img>"); |
| 69 LayoutImage* img = | 72 LayoutImage* img = |
| 70 toLayoutImage(document().body()->firstChild()->layoutObject()); | 73 toLayoutImage(document().body()->firstChild()->layoutObject()); |
| 71 | 74 |
| 72 RefPtr<TestImageAnimated> testImage = adoptRef(new TestImageAnimated); | 75 RefPtr<TestImageAnimated> testImage = adoptRef(new TestImageAnimated); |
| 73 EXPECT_EQ(InterpolationMedium, | 76 EXPECT_EQ(InterpolationMedium, |
| 74 controller()->chooseInterpolationQuality(*img, testImage.get(), | 77 controller()->chooseInterpolationQuality(*img, testImage.get(), |
| 75 nullptr, LayoutSize())); | 78 nullptr, LayoutSize())); |
| 76 } | 79 } |
| 77 | 80 |
| 78 class TestImageWithContrast : public Image { | 81 class TestImageWithContrast : public Image { |
| 79 public: | 82 public: |
| 80 bool maybeAnimated() override { return true; } | 83 bool maybeAnimated() override { return true; } |
| 81 bool currentFrameKnownToBeOpaque(MetadataMode = UseCurrentMetadata) override { | 84 bool currentFrameKnownToBeOpaque(MetadataMode = UseCurrentMetadata) override { |
| 82 return false; | 85 return false; |
| 83 } | 86 } |
| 84 IntSize size() const override { return IntSize(); } | 87 IntSize size() const override { return IntSize(); } |
| 85 void destroyDecodedData() override {} | 88 void destroyDecodedData() override {} |
| 86 void draw(SkCanvas*, | 89 void draw(SkCanvas*, |
| 87 const SkPaint&, | 90 const SkPaint&, |
| 88 const FloatRect& dstRect, | 91 const FloatRect& dstRect, |
| 89 const FloatRect& srcRect, | 92 const FloatRect& srcRect, |
| 90 RespectImageOrientationEnum, | 93 RespectImageOrientationEnum, |
| 91 ImageClampingMode) override {} | 94 ImageClampingMode, |
| 95 const ColorBehavior&) override {} |
| 92 | 96 |
| 93 bool isBitmapImage() const override { return true; } | 97 bool isBitmapImage() const override { return true; } |
| 94 sk_sp<SkImage> imageForCurrentFrame() override { return nullptr; } | 98 sk_sp<SkImage> imageForCurrentFrame(const ColorBehavior&) override { |
| 99 return nullptr; |
| 100 } |
| 95 }; | 101 }; |
| 96 | 102 |
| 97 TEST_F(ImageQualityControllerTest, LowQualityFilterForContrast) { | 103 TEST_F(ImageQualityControllerTest, LowQualityFilterForContrast) { |
| 98 setBodyInnerHTML( | 104 setBodyInnerHTML( |
| 99 "<img src='myimage' style='image-rendering: " | 105 "<img src='myimage' style='image-rendering: " |
| 100 "-webkit-optimize-contrast'></img>"); | 106 "-webkit-optimize-contrast'></img>"); |
| 101 LayoutImage* img = | 107 LayoutImage* img = |
| 102 toLayoutImage(document().body()->firstChild()->layoutObject()); | 108 toLayoutImage(document().body()->firstChild()->layoutObject()); |
| 103 | 109 |
| 104 RefPtr<TestImageWithContrast> testImage = adoptRef(new TestImageWithContrast); | 110 RefPtr<TestImageWithContrast> testImage = adoptRef(new TestImageWithContrast); |
| 105 EXPECT_EQ(InterpolationLow, | 111 EXPECT_EQ(InterpolationLow, |
| 106 controller()->chooseInterpolationQuality( | 112 controller()->chooseInterpolationQuality( |
| 107 *img, testImage.get(), testImage.get(), LayoutSize())); | 113 *img, testImage.get(), testImage.get(), LayoutSize())); |
| 108 } | 114 } |
| 109 | 115 |
| 110 class TestImageLowQuality : public Image { | 116 class TestImageLowQuality : public Image { |
| 111 public: | 117 public: |
| 112 bool maybeAnimated() override { return true; } | 118 bool maybeAnimated() override { return true; } |
| 113 bool currentFrameKnownToBeOpaque(MetadataMode = UseCurrentMetadata) override { | 119 bool currentFrameKnownToBeOpaque(MetadataMode = UseCurrentMetadata) override { |
| 114 return false; | 120 return false; |
| 115 } | 121 } |
| 116 IntSize size() const override { return IntSize(1, 1); } | 122 IntSize size() const override { return IntSize(1, 1); } |
| 117 void destroyDecodedData() override {} | 123 void destroyDecodedData() override {} |
| 118 void draw(SkCanvas*, | 124 void draw(SkCanvas*, |
| 119 const SkPaint&, | 125 const SkPaint&, |
| 120 const FloatRect& dstRect, | 126 const FloatRect& dstRect, |
| 121 const FloatRect& srcRect, | 127 const FloatRect& srcRect, |
| 122 RespectImageOrientationEnum, | 128 RespectImageOrientationEnum, |
| 123 ImageClampingMode) override {} | 129 ImageClampingMode, |
| 130 const ColorBehavior&) override {} |
| 124 | 131 |
| 125 bool isBitmapImage() const override { return true; } | 132 bool isBitmapImage() const override { return true; } |
| 126 sk_sp<SkImage> imageForCurrentFrame() override { return nullptr; } | 133 sk_sp<SkImage> imageForCurrentFrame(const ColorBehavior&) override { |
| 134 return nullptr; |
| 135 } |
| 127 }; | 136 }; |
| 128 | 137 |
| 129 TEST_F(ImageQualityControllerTest, MediumQualityFilterForUnscaledImage) { | 138 TEST_F(ImageQualityControllerTest, MediumQualityFilterForUnscaledImage) { |
| 130 setBodyInnerHTML("<img src='myimage'></img>"); | 139 setBodyInnerHTML("<img src='myimage'></img>"); |
| 131 LayoutImage* img = | 140 LayoutImage* img = |
| 132 toLayoutImage(document().body()->firstChild()->layoutObject()); | 141 toLayoutImage(document().body()->firstChild()->layoutObject()); |
| 133 | 142 |
| 134 RefPtr<TestImageLowQuality> testImage = adoptRef(new TestImageLowQuality); | 143 RefPtr<TestImageLowQuality> testImage = adoptRef(new TestImageLowQuality); |
| 135 EXPECT_EQ(InterpolationMedium, | 144 EXPECT_EQ(InterpolationMedium, |
| 136 controller()->chooseInterpolationQuality( | 145 controller()->chooseInterpolationQuality( |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 *img, testImage.get(), testImage.get(), LayoutSize(4, 4), | 347 *img, testImage.get(), testImage.get(), LayoutSize(4, 4), |
| 339 nextTime)); | 348 nextTime)); |
| 340 // Now the timer has restarted, leading to a larger fire interval. | 349 // Now the timer has restarted, leading to a larger fire interval. |
| 341 EXPECT_EQ(ImageQualityController::cLowQualityTimeThreshold, | 350 EXPECT_EQ(ImageQualityController::cLowQualityTimeThreshold, |
| 342 mockTimer->nextFireInterval()); | 351 mockTimer->nextFireInterval()); |
| 343 } | 352 } |
| 344 | 353 |
| 345 #endif | 354 #endif |
| 346 | 355 |
| 347 } // namespace blink | 356 } // namespace blink |
| OLD | NEW |