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 "config.h" | 5 #include "config.h" |
6 #include "core/layout/ImageQualityController.h" | 6 #include "core/layout/ImageQualityController.h" |
7 | 7 |
8 #include "core/layout/LayoutImage.h" | 8 #include "core/layout/LayoutImage.h" |
9 #include "core/layout/LayoutTestHelper.h" | 9 #include "core/layout/LayoutTestHelper.h" |
10 #include "platform/graphics/GraphicsContext.h" | 10 #include "platform/graphics/GraphicsContext.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 setBodyInnerHTML("<img src='myimage' style='image-rendering: pixelated'></im
g>"); | 43 setBodyInnerHTML("<img src='myimage' style='image-rendering: pixelated'></im
g>"); |
44 LayoutObject* obj = document().body()->firstChild()->layoutObject(); | 44 LayoutObject* obj = document().body()->firstChild()->layoutObject(); |
45 | 45 |
46 EXPECT_EQ(InterpolationNone, controller()->chooseInterpolationQuality(nullpt
r, obj, nullptr, nullptr, LayoutSize())); | 46 EXPECT_EQ(InterpolationNone, controller()->chooseInterpolationQuality(nullpt
r, obj, nullptr, nullptr, LayoutSize())); |
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 virtual bool maybeAnimated() override { return true; } | 53 bool maybeAnimated() override { return true; } |
54 virtual bool currentFrameKnownToBeOpaque() override { return false; } | 54 bool currentFrameKnownToBeOpaque() override { return false; } |
55 virtual IntSize size() const override { return IntSize(); } | 55 IntSize size() const override { return IntSize(); } |
56 virtual void destroyDecodedData(bool) override { } | 56 void destroyDecodedData(bool) override { } |
57 virtual void draw(GraphicsContext*, const FloatRect& dstRect, const FloatRec
t& srcRect, SkXfermode::Mode, RespectImageOrientationEnum) override { } | 57 void draw(SkCanvas*, const SkPaint&, const FloatRect& dstRect, const FloatRe
ct& srcRect, RespectImageOrientationEnum, const ImageFilterQualityHelper*) overr
ide { } |
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(null
ptr, img, testImage.get(), nullptr, LayoutSize())); | 66 EXPECT_EQ(InterpolationMedium, controller()->chooseInterpolationQuality(null
ptr, img, testImage.get(), nullptr, LayoutSize())); |
67 } | 67 } |
68 | 68 |
69 class TestImageWithContrast : public Image { | 69 class TestImageWithContrast : public Image { |
70 public: | 70 public: |
71 virtual bool maybeAnimated() override { return true; } | 71 bool maybeAnimated() override { return true; } |
72 virtual bool currentFrameKnownToBeOpaque() override { return false; } | 72 bool currentFrameKnownToBeOpaque() override { return false; } |
73 virtual IntSize size() const override { return IntSize(); } | 73 IntSize size() const override { return IntSize(); } |
74 virtual void destroyDecodedData(bool) override { } | 74 void destroyDecodedData(bool) override { } |
75 virtual void draw(GraphicsContext*, const FloatRect& dstRect, const FloatRec
t& srcRect, SkXfermode::Mode, RespectImageOrientationEnum) override { } | 75 void draw(SkCanvas*, const SkPaint&, const FloatRect& dstRect, const FloatRe
ct& srcRect, RespectImageOrientationEnum, const ImageFilterQualityHelper*) overr
ide { } |
76 | 76 |
77 virtual bool isBitmapImage() const override { return true; }; | 77 bool isBitmapImage() const override { return true; }; |
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(nullptr
, img, testImage.get(), testImage.get(), LayoutSize())); | 86 EXPECT_EQ(InterpolationLow, controller()->chooseInterpolationQuality(nullptr
, img, testImage.get(), testImage.get(), LayoutSize())); |
87 } | 87 } |
88 | 88 |
89 class TestImageLowQuality : public Image { | 89 class TestImageLowQuality : public Image { |
90 public: | 90 public: |
91 virtual bool maybeAnimated() override { return true; } | 91 bool maybeAnimated() override { return true; } |
92 virtual bool currentFrameKnownToBeOpaque() override { return false; } | 92 bool currentFrameKnownToBeOpaque() override { return false; } |
93 virtual IntSize size() const override { return IntSize(1, 1); } | 93 IntSize size() const override { return IntSize(1, 1); } |
94 virtual void destroyDecodedData(bool) override { } | 94 void destroyDecodedData(bool) override { } |
95 virtual void draw(GraphicsContext*, const FloatRect& dstRect, const FloatRec
t& srcRect, SkXfermode::Mode, RespectImageOrientationEnum) override { } | 95 void draw(SkCanvas*, const SkPaint&, const FloatRect& dstRect, const FloatRe
ct& srcRect, RespectImageOrientationEnum, const ImageFilterQualityHelper*) overr
ide { } |
96 | 96 |
97 virtual bool isBitmapImage() const override { return true; }; | 97 bool isBitmapImage() const override { return true; }; |
98 }; | 98 }; |
99 | 99 |
100 TEST_F(ImageQualityControllerTest, MediumQualityFilterForUnscaledImage) | 100 TEST_F(ImageQualityControllerTest, MediumQualityFilterForUnscaledImage) |
101 { | 101 { |
102 setBodyInnerHTML("<img src='myimage'></img>"); | 102 setBodyInnerHTML("<img src='myimage'></img>"); |
103 LayoutImage* img = toLayoutImage(document().body()->firstChild()->layoutObje
ct()); | 103 LayoutImage* img = toLayoutImage(document().body()->firstChild()->layoutObje
ct()); |
104 | 104 |
105 RefPtr<TestImageLowQuality> testImage = adoptRef(new TestImageLowQuality); | 105 RefPtr<TestImageLowQuality> testImage = adoptRef(new TestImageLowQuality); |
106 OwnPtr<DisplayItemList> displayItemList = DisplayItemList::create(); | 106 OwnPtr<DisplayItemList> displayItemList = DisplayItemList::create(); |
107 GraphicsContext context(displayItemList.get()); | 107 GraphicsContext context(displayItemList.get()); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 EXPECT_FALSE(mockTimer->isActive()); | 204 EXPECT_FALSE(mockTimer->isActive()); |
205 // Painted at the same size, so even though timer is still executing, don't
go to low quality. | 205 // Painted at the same size, so even though timer is still executing, don't
go to low quality. |
206 EXPECT_EQ(InterpolationLow, controller()->chooseInterpolationQuality(&contex
t, img, testImage.get(), testImage.get(), LayoutSize(4, 4))); | 206 EXPECT_EQ(InterpolationLow, controller()->chooseInterpolationQuality(&contex
t, img, testImage.get(), testImage.get(), LayoutSize(4, 4))); |
207 // 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. | 207 // 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. |
208 EXPECT_FALSE(mockTimer->isActive()); | 208 EXPECT_FALSE(mockTimer->isActive()); |
209 } | 209 } |
210 | 210 |
211 #endif | 211 #endif |
212 | 212 |
213 } // namespace blink | 213 } // namespace blink |
OLD | NEW |