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