| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2011 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 10 matching lines...) Expand all Loading... |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "config.h" | 26 #include "config.h" |
| 27 #include "platform/graphics/CrossfadeGeneratedImage.h" | 27 #include "platform/graphics/CrossfadeGeneratedImage.h" |
| 28 | 28 |
| 29 #include "platform/geometry/FloatRect.h" | 29 #include "platform/geometry/FloatRect.h" |
| 30 #include "platform/graphics/GraphicsContext.h" | 30 #include "platform/graphics/GraphicsContext.h" |
| 31 #include "platform/weborigin/KURL.h" |
| 31 | 32 |
| 32 namespace blink { | 33 namespace blink { |
| 33 | 34 |
| 34 CrossfadeGeneratedImage::CrossfadeGeneratedImage(Image* fromImage, Image* toImag
e, float percentage, IntSize crossfadeSize, const IntSize& size) | 35 CrossfadeGeneratedImage::CrossfadeGeneratedImage(Image* fromImage, Image* toImag
e, float percentage, IntSize crossfadeSize, const IntSize& size) |
| 35 : GeneratedImage(size) | 36 : GeneratedImage(size) |
| 36 , m_fromImage(fromImage) | 37 , m_fromImage(fromImage) |
| 37 , m_toImage(toImage) | 38 , m_toImage(toImage) |
| 38 , m_percentage(percentage) | 39 , m_percentage(percentage) |
| 39 , m_crossfadeSize(crossfadeSize) | 40 , m_crossfadeSize(crossfadeSize) |
| 40 { | 41 { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 56 canvas->saveLayer(nullptr, &layerPaint); | 57 canvas->saveLayer(nullptr, &layerPaint); |
| 57 | 58 |
| 58 SkPaint imagePaint(paint); | 59 SkPaint imagePaint(paint); |
| 59 imagePaint.setXfermodeMode(SkXfermode::kSrcOver_Mode); | 60 imagePaint.setXfermodeMode(SkXfermode::kSrcOver_Mode); |
| 60 int imageAlpha = clampedAlphaForBlending(1 - m_percentage); | 61 int imageAlpha = clampedAlphaForBlending(1 - m_percentage); |
| 61 imagePaint.setAlpha(imageAlpha > 255 ? 255 : imageAlpha); | 62 imagePaint.setAlpha(imageAlpha > 255 ? 255 : imageAlpha); |
| 62 imagePaint.setAntiAlias(paint.isAntiAlias()); | 63 imagePaint.setAntiAlias(paint.isAntiAlias()); |
| 63 // TODO(junov): This code should probably be propagating the RespectImageOri
entationEnum | 64 // TODO(junov): This code should probably be propagating the RespectImageOri
entationEnum |
| 64 // form CrossfadeGeneratedImage::draw. Code was written this way during refa
ctoring to | 65 // form CrossfadeGeneratedImage::draw. Code was written this way during refa
ctoring to |
| 65 // avoid modifying existing behavior, but this warrants further investigatio
n. crbug.com/472634 | 66 // avoid modifying existing behavior, but this warrants further investigatio
n. crbug.com/472634 |
| 66 m_fromImage->draw(canvas, imagePaint, destRect, fromImageRect, DoNotRespectI
mageOrientation, clampMode); | 67 m_fromImage->draw(canvas, imagePaint, destRect, fromImageRect, DoNotRespectI
mageOrientation, clampMode, KURL()); // TODO(davve): empty url |
| 67 imagePaint.setXfermodeMode(SkXfermode::kPlus_Mode); | 68 imagePaint.setXfermodeMode(SkXfermode::kPlus_Mode); |
| 68 imageAlpha = clampedAlphaForBlending(m_percentage); | 69 imageAlpha = clampedAlphaForBlending(m_percentage); |
| 69 imagePaint.setAlpha(imageAlpha > 255 ? 255 : imageAlpha); | 70 imagePaint.setAlpha(imageAlpha > 255 ? 255 : imageAlpha); |
| 70 m_toImage->draw(canvas, imagePaint, destRect, toImageRect, DoNotRespectImage
Orientation, clampMode); | 71 m_toImage->draw(canvas, imagePaint, destRect, toImageRect, DoNotRespectImage
Orientation, clampMode, KURL()); // TODO(davve): empty url |
| 71 } | 72 } |
| 72 | 73 |
| 73 void CrossfadeGeneratedImage::draw(SkCanvas* canvas, const SkPaint& paint, const
FloatRect& dstRect, const FloatRect& srcRect, RespectImageOrientationEnum, Imag
eClampingMode clampMode) | 74 void CrossfadeGeneratedImage::draw(SkCanvas* canvas, const SkPaint& paint, const
FloatRect& dstRect, const FloatRect& srcRect, RespectImageOrientationEnum, Imag
eClampingMode clampMode, const KURL&) |
| 74 { | 75 { |
| 75 // Draw nothing if either of the images hasn't loaded yet. | 76 // Draw nothing if either of the images hasn't loaded yet. |
| 76 if (m_fromImage == Image::nullImage() || m_toImage == Image::nullImage()) | 77 if (m_fromImage == Image::nullImage() || m_toImage == Image::nullImage()) |
| 77 return; | 78 return; |
| 78 | 79 |
| 79 SkAutoCanvasRestore ar(canvas, true); | 80 SkAutoCanvasRestore ar(canvas, true); |
| 80 canvas->clipRect(dstRect); | 81 canvas->clipRect(dstRect); |
| 81 canvas->translate(dstRect.x(), dstRect.y()); | 82 canvas->translate(dstRect.x(), dstRect.y()); |
| 82 if (dstRect.size() != srcRect.size()) | 83 if (dstRect.size() != srcRect.size()) |
| 83 canvas->scale(dstRect.width() / srcRect.width(), dstRect.height() / srcR
ect.height()); | 84 canvas->scale(dstRect.width() / srcRect.width(), dstRect.height() / srcR
ect.height()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 95 | 96 |
| 96 SkPaint paint = context->fillPaint(); | 97 SkPaint paint = context->fillPaint(); |
| 97 paint.setXfermodeMode(SkXfermode::kSrcOver_Mode); | 98 paint.setXfermodeMode(SkXfermode::kSrcOver_Mode); |
| 98 paint.setAntiAlias(context->shouldAntialias()); | 99 paint.setAntiAlias(context->shouldAntialias()); |
| 99 FloatRect destRect(FloatPoint(), m_crossfadeSize); | 100 FloatRect destRect(FloatPoint(), m_crossfadeSize); |
| 100 paint.setFilterQuality(context->computeFilterQuality(this, destRect, srcRect
)); | 101 paint.setFilterQuality(context->computeFilterQuality(this, destRect, srcRect
)); |
| 101 drawCrossfade(context->canvas(), paint, ClampImageToSourceRect); | 102 drawCrossfade(context->canvas(), paint, ClampImageToSourceRect); |
| 102 } | 103 } |
| 103 | 104 |
| 104 } // namespace blink | 105 } // namespace blink |
| OLD | NEW |