| 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 24 matching lines...) Expand all Loading... |
| 35 float percentage, | 35 float percentage, |
| 36 IntSize crossfadeSize, | 36 IntSize crossfadeSize, |
| 37 const IntSize& size) | 37 const IntSize& size) |
| 38 : GeneratedImage(size), | 38 : GeneratedImage(size), |
| 39 m_fromImage(fromImage), | 39 m_fromImage(fromImage), |
| 40 m_toImage(toImage), | 40 m_toImage(toImage), |
| 41 m_percentage(percentage), | 41 m_percentage(percentage), |
| 42 m_crossfadeSize(crossfadeSize) {} | 42 m_crossfadeSize(crossfadeSize) {} |
| 43 | 43 |
| 44 void CrossfadeGeneratedImage::drawCrossfade( | 44 void CrossfadeGeneratedImage::drawCrossfade( |
| 45 SkCanvas* canvas, | 45 PaintCanvas* canvas, |
| 46 const SkPaint& paint, | 46 const SkPaint& paint, |
| 47 ImageClampingMode clampMode, | 47 ImageClampingMode clampMode, |
| 48 const ColorBehavior& colorBehavior) { | 48 const ColorBehavior& colorBehavior) { |
| 49 FloatRect fromImageRect(FloatPoint(), FloatSize(m_fromImage->size())); | 49 FloatRect fromImageRect(FloatPoint(), FloatSize(m_fromImage->size())); |
| 50 FloatRect toImageRect(FloatPoint(), FloatSize(m_toImage->size())); | 50 FloatRect toImageRect(FloatPoint(), FloatSize(m_toImage->size())); |
| 51 FloatRect destRect((FloatPoint()), FloatSize(m_crossfadeSize)); | 51 FloatRect destRect((FloatPoint()), FloatSize(m_crossfadeSize)); |
| 52 | 52 |
| 53 // TODO(junov): The various effects encoded into paint should probably be | 53 // TODO(junov): The various effects encoded into paint should probably be |
| 54 // applied here instead of inside the layer. This probably faulty behavior | 54 // applied here instead of inside the layer. This probably faulty behavior |
| 55 // was maintained in order to preserve pre-existing behavior while refactoring | 55 // was maintained in order to preserve pre-existing behavior while refactoring |
| 56 // this code. This should be investigated further. crbug.com/472634 | 56 // this code. This should be investigated further. crbug.com/472634 |
| 57 SkPaint layerPaint; | 57 PaintFlags layerPaint; |
| 58 layerPaint.setBlendMode(paint.getBlendMode()); | 58 layerPaint.setBlendMode(paint.getBlendMode()); |
| 59 SkAutoCanvasRestore ar(canvas, false); | 59 PaintCanvasAutoRestore ar(canvas, false); |
| 60 canvas->saveLayer(nullptr, &layerPaint); | 60 canvas->saveLayer(nullptr, &layerPaint); |
| 61 | 61 |
| 62 SkPaint imagePaint(paint); | 62 PaintFlags imagePaint(paint); |
| 63 imagePaint.setBlendMode(SkBlendMode::kSrcOver); | 63 imagePaint.setBlendMode(SkBlendMode::kSrcOver); |
| 64 int imageAlpha = clampedAlphaForBlending(1 - m_percentage); | 64 int imageAlpha = clampedAlphaForBlending(1 - m_percentage); |
| 65 imagePaint.setAlpha(imageAlpha > 255 ? 255 : imageAlpha); | 65 imagePaint.setAlpha(imageAlpha > 255 ? 255 : imageAlpha); |
| 66 imagePaint.setAntiAlias(paint.isAntiAlias()); | 66 imagePaint.setAntiAlias(paint.isAntiAlias()); |
| 67 // TODO(junov): This code should probably be propagating the | 67 // TODO(junov): This code should probably be propagating the |
| 68 // RespectImageOrientationEnum from CrossfadeGeneratedImage::draw(). Code was | 68 // RespectImageOrientationEnum from CrossfadeGeneratedImage::draw(). Code was |
| 69 // written this way during refactoring to avoid modifying existing behavior, | 69 // written this way during refactoring to avoid modifying existing behavior, |
| 70 // but this warrants further investigation. crbug.com/472634 | 70 // but this warrants further investigation. crbug.com/472634 |
| 71 m_fromImage->draw(canvas, imagePaint, destRect, fromImageRect, | 71 m_fromImage->draw(canvas, imagePaint, destRect, fromImageRect, |
| 72 DoNotRespectImageOrientation, clampMode, colorBehavior); | 72 DoNotRespectImageOrientation, clampMode, colorBehavior); |
| 73 imagePaint.setBlendMode(SkBlendMode::kPlus); | 73 imagePaint.setBlendMode(SkBlendMode::kPlus); |
| 74 imageAlpha = clampedAlphaForBlending(m_percentage); | 74 imageAlpha = clampedAlphaForBlending(m_percentage); |
| 75 imagePaint.setAlpha(imageAlpha > 255 ? 255 : imageAlpha); | 75 imagePaint.setAlpha(imageAlpha > 255 ? 255 : imageAlpha); |
| 76 m_toImage->draw(canvas, imagePaint, destRect, toImageRect, | 76 m_toImage->draw(canvas, imagePaint, destRect, toImageRect, |
| 77 DoNotRespectImageOrientation, clampMode, colorBehavior); | 77 DoNotRespectImageOrientation, clampMode, colorBehavior); |
| 78 } | 78 } |
| 79 | 79 |
| 80 void CrossfadeGeneratedImage::draw(SkCanvas* canvas, | 80 void CrossfadeGeneratedImage::draw(PaintCanvas* canvas, |
| 81 const SkPaint& paint, | 81 const PaintFlags& paint, |
| 82 const FloatRect& dstRect, | 82 const FloatRect& dstRect, |
| 83 const FloatRect& srcRect, | 83 const FloatRect& srcRect, |
| 84 RespectImageOrientationEnum, | 84 RespectImageOrientationEnum, |
| 85 ImageClampingMode clampMode, | 85 ImageClampingMode clampMode, |
| 86 const ColorBehavior& colorBehavior) { | 86 const ColorBehavior& colorBehavior) { |
| 87 // Draw nothing if either of the images hasn't loaded yet. | 87 // Draw nothing if either of the images hasn't loaded yet. |
| 88 if (m_fromImage == Image::nullImage() || m_toImage == Image::nullImage()) | 88 if (m_fromImage == Image::nullImage() || m_toImage == Image::nullImage()) |
| 89 return; | 89 return; |
| 90 | 90 |
| 91 SkAutoCanvasRestore ar(canvas, true); | 91 PaintCanvasAutoRestore ar(canvas, true); |
| 92 canvas->clipRect(dstRect); | 92 canvas->clipRect(dstRect); |
| 93 canvas->translate(dstRect.x(), dstRect.y()); | 93 canvas->translate(dstRect.x(), dstRect.y()); |
| 94 if (dstRect.size() != srcRect.size()) | 94 if (dstRect.size() != srcRect.size()) |
| 95 canvas->scale(dstRect.width() / srcRect.width(), | 95 canvas->scale(dstRect.width() / srcRect.width(), |
| 96 dstRect.height() / srcRect.height()); | 96 dstRect.height() / srcRect.height()); |
| 97 canvas->translate(-srcRect.x(), -srcRect.y()); | 97 canvas->translate(-srcRect.x(), -srcRect.y()); |
| 98 | 98 |
| 99 drawCrossfade(canvas, paint, clampMode, colorBehavior); | 99 drawCrossfade(canvas, paint, clampMode, colorBehavior); |
| 100 } | 100 } |
| 101 | 101 |
| 102 void CrossfadeGeneratedImage::drawTile(GraphicsContext& context, | 102 void CrossfadeGeneratedImage::drawTile(GraphicsContext& context, |
| 103 const FloatRect& srcRect) { | 103 const FloatRect& srcRect) { |
| 104 // Draw nothing if either of the images hasn't loaded yet. | 104 // Draw nothing if either of the images hasn't loaded yet. |
| 105 if (m_fromImage == Image::nullImage() || m_toImage == Image::nullImage()) | 105 if (m_fromImage == Image::nullImage() || m_toImage == Image::nullImage()) |
| 106 return; | 106 return; |
| 107 | 107 |
| 108 SkPaint paint = context.fillPaint(); | 108 PaintFlags paint = context.fillPaint(); |
| 109 paint.setBlendMode(SkBlendMode::kSrcOver); | 109 paint.setBlendMode(SkBlendMode::kSrcOver); |
| 110 paint.setAntiAlias(context.shouldAntialias()); | 110 paint.setAntiAlias(context.shouldAntialias()); |
| 111 FloatRect destRect((FloatPoint()), FloatSize(m_crossfadeSize)); | 111 FloatRect destRect((FloatPoint()), FloatSize(m_crossfadeSize)); |
| 112 paint.setFilterQuality(context.computeFilterQuality(this, destRect, srcRect)); | 112 paint.setFilterQuality(context.computeFilterQuality(this, destRect, srcRect)); |
| 113 drawCrossfade(context.canvas(), paint, ClampImageToSourceRect, | 113 drawCrossfade(context.canvas(), paint, ClampImageToSourceRect, |
| 114 context.getColorBehavior()); | 114 context.getColorBehavior()); |
| 115 } | 115 } |
| 116 | 116 |
| 117 } // namespace blink | 117 } // namespace blink |
| OLD | NEW |