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