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 "platform/graphics/StaticBitmapImage.h" | 5 #include "platform/graphics/StaticBitmapImage.h" |
6 | 6 |
7 #include "platform/graphics/GraphicsContext.h" | 7 #include "platform/graphics/GraphicsContext.h" |
8 #include "platform/graphics/ImageObserver.h" | 8 #include "platform/graphics/ImageObserver.h" |
9 #include "third_party/skia/include/core/SkCanvas.h" | 9 #include "third_party/skia/include/core/SkCanvas.h" |
10 #include "third_party/skia/include/core/SkImage.h" | 10 #include "third_party/skia/include/core/SkImage.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 } | 33 } |
34 | 34 |
35 bool StaticBitmapImage::currentFrameKnownToBeOpaque(MetadataMode) | 35 bool StaticBitmapImage::currentFrameKnownToBeOpaque(MetadataMode) |
36 { | 36 { |
37 return m_image->isOpaque(); | 37 return m_image->isOpaque(); |
38 } | 38 } |
39 | 39 |
40 void StaticBitmapImage::draw(SkCanvas* canvas, const SkPaint& paint, const Float
Rect& dstRect, | 40 void StaticBitmapImage::draw(SkCanvas* canvas, const SkPaint& paint, const Float
Rect& dstRect, |
41 const FloatRect& srcRect, RespectImageOrientationEnum, ImageClampingMode cla
mpMode) | 41 const FloatRect& srcRect, RespectImageOrientationEnum, ImageClampingMode cla
mpMode) |
42 { | 42 { |
43 ASSERT(dstRect.width() >= 0 && dstRect.height() >= 0); | 43 // Note: Sizes < 0 should never happen, except that the layout arithmetic |
44 ASSERT(srcRect.width() >= 0 && srcRect.height() >= 0); | 44 // may overflow in degenerate use cases, so we need to check for negatives, |
| 45 // rather than only handle the isEmpty() case. See layout test |
| 46 // fast/canvas/bug544329.html |
| 47 if (dstRect.width() <= 0 || dstRect.height() <= 0 || srcRect.width() <= 0 ||
srcRect.height() <= 0) |
| 48 return; |
45 | 49 |
46 FloatRect adjustedSrcRect = srcRect; | 50 FloatRect adjustedSrcRect = srcRect; |
47 adjustedSrcRect.intersect(FloatRect(0, 0, m_image->width(), m_image->height(
))); | 51 adjustedSrcRect.intersect(FloatRect(0, 0, m_image->width(), m_image->height(
))); |
48 | 52 |
49 if (adjustedSrcRect.isEmpty() || dstRect.isEmpty()) | 53 if (adjustedSrcRect.isEmpty()) |
50 return; // Nothing to draw. | 54 return; // Nothing to draw. |
51 | 55 |
52 ASSERT(adjustedSrcRect.width() <= m_image->width() && adjustedSrcRect.height
() <= m_image->height()); | 56 ASSERT(adjustedSrcRect.width() <= m_image->width() && adjustedSrcRect.height
() <= m_image->height()); |
53 | 57 |
54 SkRect srcSkRect = adjustedSrcRect; | 58 SkRect srcSkRect = adjustedSrcRect; |
55 canvas->drawImageRect(m_image.get(), srcSkRect, dstRect, &paint, | 59 canvas->drawImageRect(m_image.get(), srcSkRect, dstRect, &paint, |
56 WebCoreClampingModeToSkiaRectConstraint(clampMode)); | 60 WebCoreClampingModeToSkiaRectConstraint(clampMode)); |
57 | 61 |
58 if (ImageObserver* observer = getImageObserver()) | 62 if (ImageObserver* observer = getImageObserver()) |
59 observer->didDraw(this); | 63 observer->didDraw(this); |
60 } | 64 } |
61 | 65 |
62 PassRefPtr<SkImage> StaticBitmapImage::imageForCurrentFrame() | 66 PassRefPtr<SkImage> StaticBitmapImage::imageForCurrentFrame() |
63 { | 67 { |
64 return m_image; | 68 return m_image; |
65 } | 69 } |
66 | 70 |
67 } // namespace blink | 71 } // namespace blink |
OLD | NEW |