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

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

Issue 1925533003: High CPU and increased memory usage fix for high-res (GIF, WEBP...) animations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebasing. DCHECK. Thanks fmalita@. Created 4 years, 6 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 EXPECT_EQ(InterpolationNone, controller()->chooseInterpolationQuality(*obj, nullptr, nullptr, LayoutSize())); 45 EXPECT_EQ(InterpolationNone, controller()->chooseInterpolationQuality(*obj, nullptr, nullptr, LayoutSize()));
46 } 46 }
47 47
48 #if !USE(LOW_QUALITY_IMAGE_INTERPOLATION) 48 #if !USE(LOW_QUALITY_IMAGE_INTERPOLATION)
49 49
50 class TestImageAnimated : public Image { 50 class TestImageAnimated : public Image {
51 public: 51 public:
52 bool maybeAnimated() override { return true; } 52 bool maybeAnimated() override { return true; }
53 bool currentFrameKnownToBeOpaque(MetadataMode = UseCurrentMetadata) override { return false; } 53 bool currentFrameKnownToBeOpaque(MetadataMode = UseCurrentMetadata) override { return false; }
54 IntSize size() const override { return IntSize(); } 54 IntSize size() const override { return IntSize(); }
55 void destroyDecodedData(bool) override { } 55 void destroyDecodedData() override { }
56 void draw(SkCanvas*, const SkPaint&, const FloatRect& dstRect, const FloatRe ct& srcRect, RespectImageOrientationEnum, ImageClampingMode) override { } 56 void draw(SkCanvas*, const SkPaint&, const FloatRect& dstRect, const FloatRe ct& srcRect, RespectImageOrientationEnum, ImageClampingMode) override { }
57 PassRefPtr<SkImage> imageForCurrentFrame() override { return nullptr; } 57 PassRefPtr<SkImage> imageForCurrentFrame() override { return nullptr; }
58 }; 58 };
59 59
60 TEST_F(ImageQualityControllerTest, ImageMaybeAnimated) 60 TEST_F(ImageQualityControllerTest, ImageMaybeAnimated)
61 { 61 {
62 setBodyInnerHTML("<img src='myimage'></img>"); 62 setBodyInnerHTML("<img src='myimage'></img>");
63 LayoutImage* img = toLayoutImage(document().body()->firstChild()->layoutObje ct()); 63 LayoutImage* img = toLayoutImage(document().body()->firstChild()->layoutObje ct());
64 64
65 RefPtr<TestImageAnimated> testImage = adoptRef(new TestImageAnimated); 65 RefPtr<TestImageAnimated> testImage = adoptRef(new TestImageAnimated);
66 EXPECT_EQ(InterpolationMedium, controller()->chooseInterpolationQuality(*img , testImage.get(), nullptr, LayoutSize())); 66 EXPECT_EQ(InterpolationMedium, controller()->chooseInterpolationQuality(*img , testImage.get(), nullptr, LayoutSize()));
67 } 67 }
68 68
69 class TestImageWithContrast : public Image { 69 class TestImageWithContrast : public Image {
70 public: 70 public:
71 bool maybeAnimated() override { return true; } 71 bool maybeAnimated() override { return true; }
72 bool currentFrameKnownToBeOpaque(MetadataMode = UseCurrentMetadata) override { return false; } 72 bool currentFrameKnownToBeOpaque(MetadataMode = UseCurrentMetadata) override { return false; }
73 IntSize size() const override { return IntSize(); } 73 IntSize size() const override { return IntSize(); }
74 void destroyDecodedData(bool) override { } 74 void destroyDecodedData() override { }
75 void draw(SkCanvas*, const SkPaint&, const FloatRect& dstRect, const FloatRe ct& srcRect, RespectImageOrientationEnum, ImageClampingMode) override { } 75 void draw(SkCanvas*, const SkPaint&, const FloatRect& dstRect, const FloatRe ct& srcRect, RespectImageOrientationEnum, ImageClampingMode) override { }
76 76
77 bool isBitmapImage() const override { return true; } 77 bool isBitmapImage() const override { return true; }
78 PassRefPtr<SkImage> imageForCurrentFrame() override { return nullptr; } 78 PassRefPtr<SkImage> imageForCurrentFrame() override { return nullptr; }
79 }; 79 };
80 80
81 TEST_F(ImageQualityControllerTest, LowQualityFilterForContrast) 81 TEST_F(ImageQualityControllerTest, LowQualityFilterForContrast)
82 { 82 {
83 setBodyInnerHTML("<img src='myimage' style='image-rendering: -webkit-optimiz e-contrast'></img>"); 83 setBodyInnerHTML("<img src='myimage' style='image-rendering: -webkit-optimiz e-contrast'></img>");
84 LayoutImage* img = toLayoutImage(document().body()->firstChild()->layoutObje ct()); 84 LayoutImage* img = toLayoutImage(document().body()->firstChild()->layoutObje ct());
85 85
86 RefPtr<TestImageWithContrast> testImage = adoptRef(new TestImageWithContrast ); 86 RefPtr<TestImageWithContrast> testImage = adoptRef(new TestImageWithContrast );
87 EXPECT_EQ(InterpolationLow, controller()->chooseInterpolationQuality(*img, t estImage.get(), testImage.get(), LayoutSize())); 87 EXPECT_EQ(InterpolationLow, controller()->chooseInterpolationQuality(*img, t estImage.get(), testImage.get(), LayoutSize()));
88 } 88 }
89 89
90 class TestImageLowQuality : public Image { 90 class TestImageLowQuality : public Image {
91 public: 91 public:
92 bool maybeAnimated() override { return true; } 92 bool maybeAnimated() override { return true; }
93 bool currentFrameKnownToBeOpaque(MetadataMode = UseCurrentMetadata) override { return false; } 93 bool currentFrameKnownToBeOpaque(MetadataMode = UseCurrentMetadata) override { return false; }
94 IntSize size() const override { return IntSize(1, 1); } 94 IntSize size() const override { return IntSize(1, 1); }
95 void destroyDecodedData(bool) override { } 95 void destroyDecodedData() override { }
96 void draw(SkCanvas*, const SkPaint&, const FloatRect& dstRect, const FloatRe ct& srcRect, RespectImageOrientationEnum, ImageClampingMode) override { } 96 void draw(SkCanvas*, const SkPaint&, const FloatRect& dstRect, const FloatRe ct& srcRect, RespectImageOrientationEnum, ImageClampingMode) override { }
97 97
98 bool isBitmapImage() const override { return true; } 98 bool isBitmapImage() const override { return true; }
99 PassRefPtr<SkImage> imageForCurrentFrame() override { return nullptr; } 99 PassRefPtr<SkImage> imageForCurrentFrame() override { return nullptr; }
100 }; 100 };
101 101
102 TEST_F(ImageQualityControllerTest, MediumQualityFilterForUnscaledImage) 102 TEST_F(ImageQualityControllerTest, MediumQualityFilterForUnscaledImage)
103 { 103 {
104 setBodyInnerHTML("<img src='myimage'></img>"); 104 setBodyInnerHTML("<img src='myimage'></img>");
105 LayoutImage* img = toLayoutImage(document().body()->firstChild()->layoutObje ct()); 105 LayoutImage* img = toLayoutImage(document().body()->firstChild()->layoutObje ct());
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 // This animation is far enough in the future to make the timer restart, sin ce it is half over. 267 // This animation is far enough in the future to make the timer restart, sin ce it is half over.
268 nextTime = 0.1 + ImageQualityController::cTimerRestartThreshold + 0.01; 268 nextTime = 0.1 + ImageQualityController::cTimerRestartThreshold + 0.01;
269 EXPECT_EQ(true, controller()->shouldPaintAtLowQuality(*img, testImage.get(), testImage.get(), LayoutSize(4, 4), nextTime)); 269 EXPECT_EQ(true, controller()->shouldPaintAtLowQuality(*img, testImage.get(), testImage.get(), LayoutSize(4, 4), nextTime));
270 // Now the timer has restarted, leading to a larger fire interval. 270 // Now the timer has restarted, leading to a larger fire interval.
271 EXPECT_EQ(ImageQualityController::cLowQualityTimeThreshold, mockTimer->nextF ireInterval()); 271 EXPECT_EQ(ImageQualityController::cLowQualityTimeThreshold, mockTimer->nextF ireInterval());
272 } 272 }
273 273
274 #endif 274 #endif
275 275
276 } // namespace blink 276 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fetch/ImageResource.cpp ('k') | third_party/WebKit/Source/core/svg/graphics/SVGImage.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698