| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008, 2009, 2010, 2012 Apple Inc. All rights reserved. | 2 * Copyright (C) 2008, 2009, 2010, 2012 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 #include "platform/graphics/GradientGeneratedImage.h" | 26 #include "platform/graphics/GradientGeneratedImage.h" |
| 27 | 27 |
| 28 #include "platform/geometry/FloatRect.h" | 28 #include "platform/geometry/FloatRect.h" |
| 29 #include "platform/graphics/GraphicsContext.h" | 29 #include "platform/graphics/GraphicsContext.h" |
| 30 | 30 |
| 31 namespace blink { | 31 namespace blink { |
| 32 | 32 |
| 33 void GradientGeneratedImage::draw(SkCanvas* canvas, const SkPaint& paint, const
FloatRect& destRect, const FloatRect& srcRect, RespectImageOrientationEnum, Imag
eClampingMode) | 33 void GradientGeneratedImage::draw(SkCanvas* canvas, const SkPaint& paint, const
FloatRect& destRect, const FloatRect& srcRect, RespectImageOrientationEnum, Imag
eClampingMode) |
| 34 { | 34 { |
| 35 SkAutoCanvasRestore ar(canvas, true); | 35 SkRect visibleRect = srcRect; |
| 36 canvas->clipRect(destRect); | 36 if (!visibleRect.intersect(SkRect::MakeIWH(m_size.width(), m_size.height()))
) |
| 37 canvas->translate(destRect.x(), destRect.y()); | 37 return; |
| 38 if (destRect.size() != srcRect.size()) | 38 |
| 39 canvas->scale(destRect.width() / srcRect.width(), destRect.height() / sr
cRect.height()); | 39 SkMatrix transform = SkMatrix::MakeRectToRect(srcRect, destRect, SkMatrix::k
Fill_ScaleToFit); |
| 40 canvas->translate(-srcRect.x(), -srcRect.y()); | 40 SkAutoCanvasRestore autoRestore(canvas, !transform.isIdentity()); |
| 41 canvas->concat(transform); |
| 42 |
| 41 SkPaint gradientPaint(paint); | 43 SkPaint gradientPaint(paint); |
| 42 m_gradient->applyToPaint(gradientPaint); | 44 m_gradient->applyToPaint(gradientPaint); |
| 43 canvas->drawRect(SkRect::MakeWH(m_size.width(), m_size.height()), gradientPa
int); | 45 |
| 46 canvas->drawRect(visibleRect, gradientPaint); |
| 44 } | 47 } |
| 45 | 48 |
| 46 void GradientGeneratedImage::drawTile(GraphicsContext& context, const FloatRect&
srcRect) | 49 void GradientGeneratedImage::drawTile(GraphicsContext& context, const FloatRect&
srcRect) |
| 47 { | 50 { |
| 48 context.setFillGradient(m_gradient); | 51 context.setFillGradient(m_gradient); |
| 49 context.fillRect(srcRect); | 52 context.fillRect(srcRect); |
| 50 } | 53 } |
| 51 | 54 |
| 52 } // namespace blink | 55 } // namespace blink |
| OLD | NEW |