| 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 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 CrossfadeGeneratedImage::CrossfadeGeneratedImage(Image* fromImage, Image* toImag
e, float percentage, IntSize crossfadeSize, const IntSize& size) | 34 CrossfadeGeneratedImage::CrossfadeGeneratedImage(Image* fromImage, Image* toImag
e, float percentage, IntSize crossfadeSize, const IntSize& size) |
| 35 : GeneratedImage(size) | 35 : GeneratedImage(size) |
| 36 , m_fromImage(fromImage) | 36 , m_fromImage(fromImage) |
| 37 , m_toImage(toImage) | 37 , m_toImage(toImage) |
| 38 , m_percentage(percentage) | 38 , m_percentage(percentage) |
| 39 , m_crossfadeSize(crossfadeSize) | 39 , m_crossfadeSize(crossfadeSize) |
| 40 { | 40 { |
| 41 } | 41 } |
| 42 | 42 |
| 43 void CrossfadeGeneratedImage::drawCrossfade(GraphicsContext* context, SkXfermode
::Mode xferMode) | 43 void CrossfadeGeneratedImage::drawCrossfade(SkCanvas* canvas, const SkPaint& pai
nt) |
| 44 { | 44 { |
| 45 float inversePercentage = 1 - m_percentage; | 45 FloatRect fromImageRect(FloatPoint(), m_fromImage->size()); |
| 46 FloatRect toImageRect(FloatPoint(), m_toImage->size()); |
| 47 FloatRect destRect(FloatPoint(), m_crossfadeSize); |
| 46 | 48 |
| 47 IntSize fromImageSize = m_fromImage->size(); | 49 // TODO(junov): The various effects encoded into paint should probably be ap
plied here |
| 48 IntSize toImageSize = m_toImage->size(); | 50 // instead of inside the layer. This probably faulty behavior was maintaine
d in order |
| 51 // to preserve pre-existing behavior while refactoring this code. This shou
ld be |
| 52 // investigated further. crbug.com/472634 |
| 53 SkXfermode::Mode compositeOp; |
| 54 if (!SkXfermode::AsMode(paint.getXfermode(), &compositeOp)) |
| 55 compositeOp = SkXfermode::kSrcOver_Mode; |
| 56 SkPaint layerPaint; |
| 57 layerPaint.setXfermodeMode(compositeOp); |
| 58 canvas->saveLayer(nullptr, &layerPaint); |
| 49 | 59 |
| 50 context->beginLayer(1, xferMode); | 60 SkPaint imagePaint(paint); |
| 61 imagePaint.setXfermodeMode(SkXfermode::kPlus_Mode); |
| 62 imagePaint.setColor(scaleAlpha(SK_ColorBLACK, 1 - m_percentage)); |
| 63 // 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 // avoid modifying existing behavior, but this warrants further investigatio
n. crbug.com/472634 |
| 66 m_fromImage->draw(canvas, imagePaint, destRect, fromImageRect, DoNotRespectI
mageOrientation); |
| 67 imagePaint.setColor(scaleAlpha(SK_ColorBLACK, m_percentage)); |
| 68 m_toImage->draw(canvas, imagePaint, destRect, toImageRect, DoNotRespectImage
Orientation); |
| 51 | 69 |
| 52 // Draw the image we're fading away from. | 70 canvas->restore(); |
| 53 context->save(); | |
| 54 if (m_crossfadeSize != fromImageSize) { | |
| 55 context->scale( | |
| 56 static_cast<float>(m_crossfadeSize.width()) / fromImageSize.width(), | |
| 57 static_cast<float>(m_crossfadeSize.height()) / fromImageSize.height(
)); | |
| 58 } | |
| 59 context->setAlphaAsFloat(inversePercentage); | |
| 60 context->drawImage(m_fromImage, IntPoint()); | |
| 61 context->restore(); | |
| 62 | |
| 63 // Draw the image we're fading towards. | |
| 64 context->save(); | |
| 65 if (m_crossfadeSize != toImageSize) { | |
| 66 context->scale( | |
| 67 static_cast<float>(m_crossfadeSize.width()) / toImageSize.width(), | |
| 68 static_cast<float>(m_crossfadeSize.height()) / toImageSize.height())
; | |
| 69 } | |
| 70 context->setAlphaAsFloat(m_percentage); | |
| 71 context->drawImage(m_toImage, IntPoint(), SkXfermode::kPlus_Mode); | |
| 72 context->restore(); | |
| 73 | |
| 74 context->endLayer(); | |
| 75 } | 71 } |
| 76 | 72 |
| 77 void CrossfadeGeneratedImage::draw(GraphicsContext* context, const FloatRect& ds
tRect, const FloatRect& srcRect, SkXfermode::Mode compositeOp, RespectImageOrien
tationEnum) | 73 void CrossfadeGeneratedImage::draw(SkCanvas* canvas, const SkPaint& paint, const
FloatRect& dstRect, const FloatRect& srcRect, RespectImageOrientationEnum) |
| 78 { | 74 { |
| 79 // Draw nothing if either of the images hasn't loaded yet. | 75 // Draw nothing if either of the images hasn't loaded yet. |
| 80 if (m_fromImage == Image::nullImage() || m_toImage == Image::nullImage()) | 76 if (m_fromImage == Image::nullImage() || m_toImage == Image::nullImage()) |
| 81 return; | 77 return; |
| 82 | 78 |
| 83 GraphicsContextStateSaver stateSaver(*context); | 79 canvas->save(); |
| 84 context->clip(dstRect); | 80 canvas->clipRect(dstRect); |
| 85 context->translate(dstRect.x(), dstRect.y()); | 81 canvas->translate(dstRect.x(), dstRect.y()); |
| 86 if (dstRect.size() != srcRect.size()) | 82 if (dstRect.size() != srcRect.size()) |
| 87 context->scale(dstRect.width() / srcRect.width(), dstRect.height() / src
Rect.height()); | 83 canvas->scale(dstRect.width() / srcRect.width(), dstRect.height() / srcR
ect.height()); |
| 88 context->translate(-srcRect.x(), -srcRect.y()); | 84 canvas->translate(-srcRect.x(), -srcRect.y()); |
| 89 | 85 |
| 90 drawCrossfade(context, compositeOp); | 86 drawCrossfade(canvas, paint); |
| 87 canvas->restore(); |
| 91 } | 88 } |
| 92 | 89 |
| 93 void CrossfadeGeneratedImage::drawTile(GraphicsContext* context, const FloatRect
& srcRect) | 90 void CrossfadeGeneratedImage::drawTile(GraphicsContext* context, const FloatRect
& srcRect) |
| 94 { | 91 { |
| 95 // Draw nothing if either of the images hasn't loaded yet. | 92 // Draw nothing if either of the images hasn't loaded yet. |
| 96 if (m_fromImage == Image::nullImage() || m_toImage == Image::nullImage()) | 93 if (m_fromImage == Image::nullImage() || m_toImage == Image::nullImage()) |
| 97 return; | 94 return; |
| 98 | 95 |
| 99 drawCrossfade(context, SkXfermode::kSrcOver_Mode); | 96 SkPaint paint = context->fillPaint(); |
| 97 paint.setXfermodeMode(SkXfermode::kSrcOver_Mode); |
| 98 drawCrossfade(context->canvas(), paint); |
| 100 } | 99 } |
| 101 | 100 |
| 102 } // namespace blink | 101 } // namespace blink |
| OLD | NEW |