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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 { | 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(PaintCanvas*, |
59 const SkPaint&, | 59 const PaintFlags&, |
60 const FloatRect& dstRect, | 60 const FloatRect& dstRect, |
61 const FloatRect& srcRect, | 61 const FloatRect& srcRect, |
62 RespectImageOrientationEnum, | 62 RespectImageOrientationEnum, |
63 ImageClampingMode, | 63 ImageClampingMode, |
64 const ColorBehavior&) override {} | 64 const ColorBehavior&) override {} |
65 sk_sp<SkImage> imageForCurrentFrame(const ColorBehavior&) override { | 65 sk_sp<SkImage> imageForCurrentFrame(const ColorBehavior&) override { |
66 return nullptr; | 66 return nullptr; |
67 } | 67 } |
68 }; | 68 }; |
69 | 69 |
70 TEST_F(ImageQualityControllerTest, ImageMaybeAnimated) { | 70 TEST_F(ImageQualityControllerTest, ImageMaybeAnimated) { |
71 setBodyInnerHTML("<img src='myimage'></img>"); | 71 setBodyInnerHTML("<img src='myimage'></img>"); |
72 LayoutImage* img = | 72 LayoutImage* img = |
73 toLayoutImage(document().body()->firstChild()->layoutObject()); | 73 toLayoutImage(document().body()->firstChild()->layoutObject()); |
74 | 74 |
75 RefPtr<TestImageAnimated> testImage = adoptRef(new TestImageAnimated); | 75 RefPtr<TestImageAnimated> testImage = adoptRef(new TestImageAnimated); |
76 EXPECT_EQ(InterpolationMedium, | 76 EXPECT_EQ(InterpolationMedium, |
77 controller()->chooseInterpolationQuality(*img, testImage.get(), | 77 controller()->chooseInterpolationQuality(*img, testImage.get(), |
78 nullptr, LayoutSize())); | 78 nullptr, LayoutSize())); |
79 } | 79 } |
80 | 80 |
81 class TestImageWithContrast : public Image { | 81 class TestImageWithContrast : public Image { |
82 public: | 82 public: |
83 bool maybeAnimated() override { return true; } | 83 bool maybeAnimated() override { return true; } |
84 bool currentFrameKnownToBeOpaque(MetadataMode = UseCurrentMetadata) override { | 84 bool currentFrameKnownToBeOpaque(MetadataMode = UseCurrentMetadata) override { |
85 return false; | 85 return false; |
86 } | 86 } |
87 IntSize size() const override { return IntSize(); } | 87 IntSize size() const override { return IntSize(); } |
88 void destroyDecodedData() override {} | 88 void destroyDecodedData() override {} |
89 void draw(SkCanvas*, | 89 void draw(PaintCanvas*, |
90 const SkPaint&, | 90 const PaintFlags&, |
91 const FloatRect& dstRect, | 91 const FloatRect& dstRect, |
92 const FloatRect& srcRect, | 92 const FloatRect& srcRect, |
93 RespectImageOrientationEnum, | 93 RespectImageOrientationEnum, |
94 ImageClampingMode, | 94 ImageClampingMode, |
95 const ColorBehavior&) override {} | 95 const ColorBehavior&) override {} |
96 | 96 |
97 bool isBitmapImage() const override { return true; } | 97 bool isBitmapImage() const override { return true; } |
98 sk_sp<SkImage> imageForCurrentFrame(const ColorBehavior&) override { | 98 sk_sp<SkImage> imageForCurrentFrame(const ColorBehavior&) override { |
99 return nullptr; | 99 return nullptr; |
100 } | 100 } |
(...skipping 13 matching lines...) Expand all Loading... |
114 } | 114 } |
115 | 115 |
116 class TestImageLowQuality : public Image { | 116 class TestImageLowQuality : public Image { |
117 public: | 117 public: |
118 bool maybeAnimated() override { return true; } | 118 bool maybeAnimated() override { return true; } |
119 bool currentFrameKnownToBeOpaque(MetadataMode = UseCurrentMetadata) override { | 119 bool currentFrameKnownToBeOpaque(MetadataMode = UseCurrentMetadata) override { |
120 return false; | 120 return false; |
121 } | 121 } |
122 IntSize size() const override { return IntSize(1, 1); } | 122 IntSize size() const override { return IntSize(1, 1); } |
123 void destroyDecodedData() override {} | 123 void destroyDecodedData() override {} |
124 void draw(SkCanvas*, | 124 void draw(PaintCanvas*, |
125 const SkPaint&, | 125 const PaintFlags&, |
126 const FloatRect& dstRect, | 126 const FloatRect& dstRect, |
127 const FloatRect& srcRect, | 127 const FloatRect& srcRect, |
128 RespectImageOrientationEnum, | 128 RespectImageOrientationEnum, |
129 ImageClampingMode, | 129 ImageClampingMode, |
130 const ColorBehavior&) override {} | 130 const ColorBehavior&) override {} |
131 | 131 |
132 bool isBitmapImage() const override { return true; } | 132 bool isBitmapImage() const override { return true; } |
133 sk_sp<SkImage> imageForCurrentFrame(const ColorBehavior&) override { | 133 sk_sp<SkImage> imageForCurrentFrame(const ColorBehavior&) override { |
134 return nullptr; | 134 return nullptr; |
135 } | 135 } |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 *img, testImage.get(), testImage.get(), LayoutSize(4, 4), | 347 *img, testImage.get(), testImage.get(), LayoutSize(4, 4), |
348 nextTime)); | 348 nextTime)); |
349 // Now the timer has restarted, leading to a larger fire interval. | 349 // Now the timer has restarted, leading to a larger fire interval. |
350 EXPECT_EQ(ImageQualityController::cLowQualityTimeThreshold, | 350 EXPECT_EQ(ImageQualityController::cLowQualityTimeThreshold, |
351 mockTimer->nextFireInterval()); | 351 mockTimer->nextFireInterval()); |
352 } | 352 } |
353 | 353 |
354 #endif | 354 #endif |
355 | 355 |
356 } // namespace blink | 356 } // namespace blink |
OLD | NEW |