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

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

Issue 1857543002: Don't recreate SkImages for high-res (GIF, WEBP...) animations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review #4 fix. Thanks @pkasting. Created 4 years, 8 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 EXPECT_EQ(InterpolationNone, controller()->chooseInterpolationQuality(*obj, nullptr, nullptr, LayoutSize())); 44 EXPECT_EQ(InterpolationNone, controller()->chooseInterpolationQuality(*obj, nullptr, nullptr, LayoutSize()));
45 } 45 }
46 46
47 #if !USE(LOW_QUALITY_IMAGE_INTERPOLATION) 47 #if !USE(LOW_QUALITY_IMAGE_INTERPOLATION)
48 48
49 class TestImageAnimated : public Image { 49 class TestImageAnimated : public Image {
50 public: 50 public:
51 bool maybeAnimated() override { return true; } 51 bool maybeAnimated() override { return true; }
52 bool currentFrameKnownToBeOpaque(MetadataMode = UseCurrentMetadata) override { return false; } 52 bool currentFrameKnownToBeOpaque(MetadataMode = UseCurrentMetadata) override { return false; }
53 IntSize size() const override { return IntSize(); } 53 IntSize size() const override { return IntSize(); }
54 void destroyDecodedData(bool) override { } 54 void destroyDecodedData() override { }
55 void draw(SkCanvas*, const SkPaint&, const FloatRect& dstRect, const FloatRe ct& srcRect, RespectImageOrientationEnum, ImageClampingMode) override { } 55 void draw(SkCanvas*, const SkPaint&, const FloatRect& dstRect, const FloatRe ct& srcRect, RespectImageOrientationEnum, ImageClampingMode) override { }
56 PassRefPtr<SkImage> imageForCurrentFrame() override { return nullptr; } 56 PassRefPtr<SkImage> imageForCurrentFrame() override { return nullptr; }
57 }; 57 };
58 58
59 TEST_F(ImageQualityControllerTest, ImageMaybeAnimated) 59 TEST_F(ImageQualityControllerTest, ImageMaybeAnimated)
60 { 60 {
61 setBodyInnerHTML("<img src='myimage'></img>"); 61 setBodyInnerHTML("<img src='myimage'></img>");
62 LayoutImage* img = toLayoutImage(document().body()->firstChild()->layoutObje ct()); 62 LayoutImage* img = toLayoutImage(document().body()->firstChild()->layoutObje ct());
63 63
64 RefPtr<TestImageAnimated> testImage = adoptRef(new TestImageAnimated); 64 RefPtr<TestImageAnimated> testImage = adoptRef(new TestImageAnimated);
65 EXPECT_EQ(InterpolationMedium, controller()->chooseInterpolationQuality(*img , testImage.get(), nullptr, LayoutSize())); 65 EXPECT_EQ(InterpolationMedium, controller()->chooseInterpolationQuality(*img , testImage.get(), nullptr, LayoutSize()));
66 } 66 }
67 67
68 class TestImageWithContrast : public Image { 68 class TestImageWithContrast : public Image {
69 public: 69 public:
70 bool maybeAnimated() override { return true; } 70 bool maybeAnimated() override { return true; }
71 bool currentFrameKnownToBeOpaque(MetadataMode = UseCurrentMetadata) override { return false; } 71 bool currentFrameKnownToBeOpaque(MetadataMode = UseCurrentMetadata) override { return false; }
72 IntSize size() const override { return IntSize(); } 72 IntSize size() const override { return IntSize(); }
73 void destroyDecodedData(bool) override { } 73 void destroyDecodedData() override { }
74 void draw(SkCanvas*, const SkPaint&, const FloatRect& dstRect, const FloatRe ct& srcRect, RespectImageOrientationEnum, ImageClampingMode) override { } 74 void draw(SkCanvas*, const SkPaint&, const FloatRect& dstRect, const FloatRe ct& srcRect, RespectImageOrientationEnum, ImageClampingMode) override { }
75 75
76 bool isBitmapImage() const override { return true; } 76 bool isBitmapImage() const override { return true; }
77 PassRefPtr<SkImage> imageForCurrentFrame() override { return nullptr; } 77 PassRefPtr<SkImage> imageForCurrentFrame() override { return nullptr; }
78 }; 78 };
79 79
80 TEST_F(ImageQualityControllerTest, LowQualityFilterForContrast) 80 TEST_F(ImageQualityControllerTest, LowQualityFilterForContrast)
81 { 81 {
82 setBodyInnerHTML("<img src='myimage' style='image-rendering: -webkit-optimiz e-contrast'></img>"); 82 setBodyInnerHTML("<img src='myimage' style='image-rendering: -webkit-optimiz e-contrast'></img>");
83 LayoutImage* img = toLayoutImage(document().body()->firstChild()->layoutObje ct()); 83 LayoutImage* img = toLayoutImage(document().body()->firstChild()->layoutObje ct());
84 84
85 RefPtr<TestImageWithContrast> testImage = adoptRef(new TestImageWithContrast ); 85 RefPtr<TestImageWithContrast> testImage = adoptRef(new TestImageWithContrast );
86 EXPECT_EQ(InterpolationLow, controller()->chooseInterpolationQuality(*img, t estImage.get(), testImage.get(), LayoutSize())); 86 EXPECT_EQ(InterpolationLow, controller()->chooseInterpolationQuality(*img, t estImage.get(), testImage.get(), LayoutSize()));
87 } 87 }
88 88
89 class TestImageLowQuality : public Image { 89 class TestImageLowQuality : public Image {
90 public: 90 public:
91 bool maybeAnimated() override { return true; } 91 bool maybeAnimated() override { return true; }
92 bool currentFrameKnownToBeOpaque(MetadataMode = UseCurrentMetadata) override { return false; } 92 bool currentFrameKnownToBeOpaque(MetadataMode = UseCurrentMetadata) override { return false; }
93 IntSize size() const override { return IntSize(1, 1); } 93 IntSize size() const override { return IntSize(1, 1); }
94 void destroyDecodedData(bool) override { } 94 void destroyDecodedData() override { }
95 void draw(SkCanvas*, const SkPaint&, const FloatRect& dstRect, const FloatRe ct& srcRect, RespectImageOrientationEnum, ImageClampingMode) override { } 95 void draw(SkCanvas*, const SkPaint&, const FloatRect& dstRect, const FloatRe ct& srcRect, RespectImageOrientationEnum, ImageClampingMode) override { }
96 96
97 bool isBitmapImage() const override { return true; } 97 bool isBitmapImage() const override { return true; }
98 PassRefPtr<SkImage> imageForCurrentFrame() override { return nullptr; } 98 PassRefPtr<SkImage> imageForCurrentFrame() override { return nullptr; }
99 }; 99 };
100 100
101 TEST_F(ImageQualityControllerTest, MediumQualityFilterForUnscaledImage) 101 TEST_F(ImageQualityControllerTest, MediumQualityFilterForUnscaledImage)
102 { 102 {
103 setBodyInnerHTML("<img src='myimage'></img>"); 103 setBodyInnerHTML("<img src='myimage'></img>");
104 LayoutImage* img = toLayoutImage(document().body()->firstChild()->layoutObje ct()); 104 LayoutImage* img = toLayoutImage(document().body()->firstChild()->layoutObje ct());
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 EXPECT_FALSE(mockTimer->isActive()); 199 EXPECT_FALSE(mockTimer->isActive());
200 // Painted at the same size, so even though timer is still executing, don't go to low quality. 200 // Painted at the same size, so even though timer is still executing, don't go to low quality.
201 EXPECT_EQ(InterpolationLow, controller()->chooseInterpolationQuality(*img, t estImage.get(), testImage.get(), LayoutSize(4, 4))); 201 EXPECT_EQ(InterpolationLow, controller()->chooseInterpolationQuality(*img, t estImage.get(), testImage.get(), LayoutSize(4, 4)));
202 // Check that the timer was not kicked. It should not have been, since the i mage was painted at the same size as last time. 202 // Check that the timer was not kicked. It should not have been, since the i mage was painted at the same size as last time.
203 EXPECT_FALSE(mockTimer->isActive()); 203 EXPECT_FALSE(mockTimer->isActive());
204 } 204 }
205 205
206 #endif 206 #endif
207 207
208 } // namespace blink 208 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698