Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Side by Side Diff: third_party/WebKit/Source/core/layout/ImageQualityControllerTest.cpp

Issue 2157953002: Change filter quality when scaling-down in drawImage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 } 47 }
48 48
49 #if !USE(LOW_QUALITY_IMAGE_INTERPOLATION) 49 #if !USE(LOW_QUALITY_IMAGE_INTERPOLATION)
50 50
51 class TestImageAnimated : public Image { 51 class TestImageAnimated : public Image {
52 public: 52 public:
53 bool maybeAnimated() override { return true; } 53 bool maybeAnimated() override { return true; }
54 bool currentFrameKnownToBeOpaque(MetadataMode = UseCurrentMetadata) override { return false; } 54 bool currentFrameKnownToBeOpaque(MetadataMode = UseCurrentMetadata) override { return false; }
55 IntSize size() const override { return IntSize(); } 55 IntSize size() const override { return IntSize(); }
56 void destroyDecodedData() override { } 56 void destroyDecodedData() override { }
57 void draw(SkCanvas*, const SkPaint&, const FloatRect& dstRect, const FloatRe ct& srcRect, RespectImageOrientationEnum, ImageClampingMode) override { } 57 void draw(SkCanvas*, const SkPaint&, const FloatRect& dstRect, const FloatRe ct& srcRect, bool imageSmoothingEnabled, RespectImageOrientationEnum, ImageClamp ingMode) override { }
58 PassRefPtr<SkImage> imageForCurrentFrame() override { return nullptr; } 58 PassRefPtr<SkImage> imageForCurrentFrame() override { return nullptr; }
59 }; 59 };
60 60
61 TEST_F(ImageQualityControllerTest, ImageMaybeAnimated) 61 TEST_F(ImageQualityControllerTest, ImageMaybeAnimated)
62 { 62 {
63 setBodyInnerHTML("<img src='myimage'></img>"); 63 setBodyInnerHTML("<img src='myimage'></img>");
64 LayoutImage* img = toLayoutImage(document().body()->firstChild()->layoutObje ct()); 64 LayoutImage* img = toLayoutImage(document().body()->firstChild()->layoutObje ct());
65 65
66 RefPtr<TestImageAnimated> testImage = adoptRef(new TestImageAnimated); 66 RefPtr<TestImageAnimated> testImage = adoptRef(new TestImageAnimated);
67 EXPECT_EQ(InterpolationMedium, controller()->chooseInterpolationQuality(*img , testImage.get(), nullptr, LayoutSize())); 67 EXPECT_EQ(InterpolationMedium, controller()->chooseInterpolationQuality(*img , testImage.get(), nullptr, LayoutSize()));
68 } 68 }
69 69
70 class TestImageWithContrast : public Image { 70 class TestImageWithContrast : public Image {
71 public: 71 public:
72 bool maybeAnimated() override { return true; } 72 bool maybeAnimated() override { return true; }
73 bool currentFrameKnownToBeOpaque(MetadataMode = UseCurrentMetadata) override { return false; } 73 bool currentFrameKnownToBeOpaque(MetadataMode = UseCurrentMetadata) override { return false; }
74 IntSize size() const override { return IntSize(); } 74 IntSize size() const override { return IntSize(); }
75 void destroyDecodedData() override { } 75 void destroyDecodedData() override { }
76 void draw(SkCanvas*, const SkPaint&, const FloatRect& dstRect, const FloatRe ct& srcRect, RespectImageOrientationEnum, ImageClampingMode) override { } 76 void draw(SkCanvas*, const SkPaint&, const FloatRect& dstRect, const FloatRe ct& srcRect, bool imageSmoothingEnabled, RespectImageOrientationEnum, ImageClamp ingMode) override { }
77 77
78 bool isBitmapImage() const override { return true; } 78 bool isBitmapImage() const override { return true; }
79 PassRefPtr<SkImage> imageForCurrentFrame() override { return nullptr; } 79 PassRefPtr<SkImage> imageForCurrentFrame() override { return nullptr; }
80 }; 80 };
81 81
82 TEST_F(ImageQualityControllerTest, LowQualityFilterForContrast) 82 TEST_F(ImageQualityControllerTest, LowQualityFilterForContrast)
83 { 83 {
84 setBodyInnerHTML("<img src='myimage' style='image-rendering: -webkit-optimiz e-contrast'></img>"); 84 setBodyInnerHTML("<img src='myimage' style='image-rendering: -webkit-optimiz e-contrast'></img>");
85 LayoutImage* img = toLayoutImage(document().body()->firstChild()->layoutObje ct()); 85 LayoutImage* img = toLayoutImage(document().body()->firstChild()->layoutObje ct());
86 86
87 RefPtr<TestImageWithContrast> testImage = adoptRef(new TestImageWithContrast ); 87 RefPtr<TestImageWithContrast> testImage = adoptRef(new TestImageWithContrast );
88 EXPECT_EQ(InterpolationLow, controller()->chooseInterpolationQuality(*img, t estImage.get(), testImage.get(), LayoutSize())); 88 EXPECT_EQ(InterpolationLow, controller()->chooseInterpolationQuality(*img, t estImage.get(), testImage.get(), LayoutSize()));
89 } 89 }
90 90
91 class TestImageLowQuality : public Image { 91 class TestImageLowQuality : public Image {
92 public: 92 public:
93 bool maybeAnimated() override { return true; } 93 bool maybeAnimated() override { return true; }
94 bool currentFrameKnownToBeOpaque(MetadataMode = UseCurrentMetadata) override { return false; } 94 bool currentFrameKnownToBeOpaque(MetadataMode = UseCurrentMetadata) override { return false; }
95 IntSize size() const override { return IntSize(1, 1); } 95 IntSize size() const override { return IntSize(1, 1); }
96 void destroyDecodedData() override { } 96 void destroyDecodedData() override { }
97 void draw(SkCanvas*, const SkPaint&, const FloatRect& dstRect, const FloatRe ct& srcRect, RespectImageOrientationEnum, ImageClampingMode) override { } 97 void draw(SkCanvas*, const SkPaint&, const FloatRect& dstRect, const FloatRe ct& srcRect, bool imageSmoothingEnabled, RespectImageOrientationEnum, ImageClamp ingMode) override { }
98 98
99 bool isBitmapImage() const override { return true; } 99 bool isBitmapImage() const override { return true; }
100 PassRefPtr<SkImage> imageForCurrentFrame() override { return nullptr; } 100 PassRefPtr<SkImage> imageForCurrentFrame() override { return nullptr; }
101 }; 101 };
102 102
103 TEST_F(ImageQualityControllerTest, MediumQualityFilterForUnscaledImage) 103 TEST_F(ImageQualityControllerTest, MediumQualityFilterForUnscaledImage)
104 { 104 {
105 setBodyInnerHTML("<img src='myimage'></img>"); 105 setBodyInnerHTML("<img src='myimage'></img>");
106 LayoutImage* img = toLayoutImage(document().body()->firstChild()->layoutObje ct()); 106 LayoutImage* img = toLayoutImage(document().body()->firstChild()->layoutObje ct());
107 107
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 // This animation is far enough in the future to make the timer restart, sin ce it is half over. 268 // This animation is far enough in the future to make the timer restart, sin ce it is half over.
269 nextTime = 0.1 + ImageQualityController::cTimerRestartThreshold + 0.01; 269 nextTime = 0.1 + ImageQualityController::cTimerRestartThreshold + 0.01;
270 EXPECT_EQ(true, controller()->shouldPaintAtLowQuality(*img, testImage.get(), testImage.get(), LayoutSize(4, 4), nextTime)); 270 EXPECT_EQ(true, controller()->shouldPaintAtLowQuality(*img, testImage.get(), testImage.get(), LayoutSize(4, 4), nextTime));
271 // Now the timer has restarted, leading to a larger fire interval. 271 // Now the timer has restarted, leading to a larger fire interval.
272 EXPECT_EQ(ImageQualityController::cLowQualityTimeThreshold, mockTimer->nextF ireInterval()); 272 EXPECT_EQ(ImageQualityController::cLowQualityTimeThreshold, mockTimer->nextF ireInterval());
273 } 273 }
274 274
275 #endif 275 #endif
276 276
277 } // namespace blink 277 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698