OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkDropShadowImageFilter.h" | 8 #include "SkDropShadowImageFilter.h" |
9 | 9 |
10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
11 #include "SkBlurImageFilter.h" | 11 #include "SkBlurImageFilter.h" |
12 #include "SkCanvas.h" | 12 #include "SkCanvas.h" |
13 #include "SkColorMatrixFilter.h" | 13 #include "SkColorMatrixFilter.h" |
14 #include "SkDevice.h" | 14 #include "SkDevice.h" |
15 #include "SkReadBuffer.h" | 15 #include "SkReadBuffer.h" |
16 #include "SkWriteBuffer.h" | 16 #include "SkWriteBuffer.h" |
17 | 17 |
18 SkDropShadowImageFilter::SkDropShadowImageFilter(SkScalar dx, SkScalar dy, SkSca
lar sigma, SkColor color, SkImageFilter* input) | 18 SkDropShadowImageFilter::SkDropShadowImageFilter(SkScalar dx, SkScalar dy, SkSca
lar sigma, |
| 19 SkColor color, SkImageFilter* i
nput) |
19 : INHERITED(input) | 20 : INHERITED(input) |
20 , fDx(dx) | 21 , fDx(dx) |
21 , fDy(dy) | 22 , fDy(dy) |
22 , fSigmaX(sigma) | 23 , fSigmaX(sigma) |
23 , fSigmaY(sigma) | 24 , fSigmaY(sigma) |
24 , fColor(color) | 25 , fColor(color) |
25 { | 26 { |
26 } | 27 } |
27 | 28 |
28 SkDropShadowImageFilter::SkDropShadowImageFilter(SkScalar dx, SkScalar dy, SkSca
lar sigmaX, SkScalar sigmaY, SkColor color, SkImageFilter* input, const CropRect
* cropRect) | 29 SkDropShadowImageFilter::SkDropShadowImageFilter(SkScalar dx, SkScalar dy, |
| 30 SkScalar sigmaX, SkScalar sigma
Y, SkColor color, |
| 31 SkImageFilter* input, const Cro
pRect* cropRect) |
29 : INHERITED(input, cropRect) | 32 : INHERITED(input, cropRect) |
30 , fDx(dx) | 33 , fDx(dx) |
31 , fDy(dy) | 34 , fDy(dy) |
32 , fSigmaX(sigmaX) | 35 , fSigmaX(sigmaX) |
33 , fSigmaY(sigmaY) | 36 , fSigmaY(sigmaY) |
34 , fColor(color) | 37 , fColor(color) |
35 { | 38 { |
36 } | 39 } |
37 | 40 |
38 SkDropShadowImageFilter::SkDropShadowImageFilter(SkReadBuffer& buffer) | 41 SkDropShadowImageFilter::SkDropShadowImageFilter(SkReadBuffer& buffer) |
(...skipping 12 matching lines...) Expand all Loading... |
51 void SkDropShadowImageFilter::flatten(SkWriteBuffer& buffer) const | 54 void SkDropShadowImageFilter::flatten(SkWriteBuffer& buffer) const |
52 { | 55 { |
53 this->INHERITED::flatten(buffer); | 56 this->INHERITED::flatten(buffer); |
54 buffer.writeScalar(fDx); | 57 buffer.writeScalar(fDx); |
55 buffer.writeScalar(fDy); | 58 buffer.writeScalar(fDy); |
56 buffer.writeScalar(fSigmaX); | 59 buffer.writeScalar(fSigmaX); |
57 buffer.writeScalar(fSigmaY); | 60 buffer.writeScalar(fSigmaY); |
58 buffer.writeColor(fColor); | 61 buffer.writeColor(fColor); |
59 } | 62 } |
60 | 63 |
61 bool SkDropShadowImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& source
, const Context& ctx, SkBitmap* result, SkIPoint* offset) const | 64 bool SkDropShadowImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& source
, |
| 65 const Context& ctx, |
| 66 SkBitmap* result, SkIPoint* offset)
const |
62 { | 67 { |
63 SkBitmap src = source; | 68 SkBitmap src = source; |
64 SkIPoint srcOffset = SkIPoint::Make(0, 0); | 69 SkIPoint srcOffset = SkIPoint::Make(0, 0); |
65 if (getInput(0) && !getInput(0)->filterImage(proxy, source, ctx, &src, &srcO
ffset)) | 70 if (getInput(0) && !getInput(0)->filterImage(proxy, source, ctx, &src, &srcO
ffset)) |
66 return false; | 71 return false; |
67 | 72 |
68 SkIRect bounds; | 73 SkIRect bounds; |
69 if (!this->applyCropRect(ctx, src, srcOffset, &bounds)) { | 74 if (!this->applyCropRect(ctx, src, srcOffset, &bounds)) { |
70 return false; | 75 return false; |
71 } | 76 } |
72 | 77 |
73 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds
.height())); | 78 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds
.height())); |
74 if (NULL == device.get()) { | 79 if (NULL == device.get()) { |
75 return false; | 80 return false; |
76 } | 81 } |
77 SkCanvas canvas(device.get()); | 82 SkCanvas canvas(device.get()); |
78 | 83 |
79 SkVector sigma, localSigma = SkVector::Make(fSigmaX, fSigmaY); | 84 SkVector sigma, localSigma = SkVector::Make(fSigmaX, fSigmaY); |
80 ctx.ctm().mapVectors(&sigma, &localSigma, 1); | 85 ctx.ctm().mapVectors(&sigma, &localSigma, 1); |
81 sigma.fX = SkMaxScalar(0, sigma.fX); | 86 sigma.fX = SkMaxScalar(0, sigma.fX); |
82 sigma.fY = SkMaxScalar(0, sigma.fY); | 87 sigma.fY = SkMaxScalar(0, sigma.fY); |
83 SkAutoTUnref<SkImageFilter> blurFilter(SkBlurImageFilter::Create(sigma.fX, s
igma.fY)); | 88 SkAutoTUnref<SkImageFilter> blurFilter(SkBlurImageFilter::Create(sigma.fX, s
igma.fY)); |
84 SkAutoTUnref<SkColorFilter> colorFilter(SkColorFilter::CreateModeFilter(fCol
or, SkXfermode::kSrcIn_Mode)); | 89 SkAutoTUnref<SkColorFilter> colorFilter( |
| 90 SkColorFilter::CreateModeFilter(fColor, SkXfermode::kSrcIn_Mode)); |
85 SkPaint paint; | 91 SkPaint paint; |
86 paint.setImageFilter(blurFilter.get()); | 92 paint.setImageFilter(blurFilter.get()); |
87 paint.setColorFilter(colorFilter.get()); | 93 paint.setColorFilter(colorFilter.get()); |
88 paint.setXfermodeMode(SkXfermode::kSrcOver_Mode); | 94 paint.setXfermodeMode(SkXfermode::kSrcOver_Mode); |
89 SkVector offsetVec, localOffsetVec = SkVector::Make(fDx, fDy); | 95 SkVector offsetVec, localOffsetVec = SkVector::Make(fDx, fDy); |
90 ctx.ctm().mapVectors(&offsetVec, &localOffsetVec, 1); | 96 ctx.ctm().mapVectors(&offsetVec, &localOffsetVec, 1); |
91 canvas.translate(SkIntToScalar(srcOffset.fX - bounds.fLeft), | 97 canvas.translate(SkIntToScalar(srcOffset.fX - bounds.fLeft), |
92 SkIntToScalar(srcOffset.fY - bounds.fTop)); | 98 SkIntToScalar(srcOffset.fY - bounds.fTop)); |
93 canvas.drawBitmap(src, offsetVec.fX, offsetVec.fY, &paint); | 99 canvas.drawBitmap(src, offsetVec.fX, offsetVec.fY, &paint); |
94 canvas.drawBitmap(src, 0, 0); | 100 canvas.drawBitmap(src, 0, 0); |
(...skipping 28 matching lines...) Expand all Loading... |
123 bounds.offset(-SkScalarCeilToInt(offsetVec.x()), | 129 bounds.offset(-SkScalarCeilToInt(offsetVec.x()), |
124 -SkScalarCeilToInt(offsetVec.y())); | 130 -SkScalarCeilToInt(offsetVec.y())); |
125 SkVector sigma, localSigma = SkVector::Make(fSigmaX, fSigmaY); | 131 SkVector sigma, localSigma = SkVector::Make(fSigmaX, fSigmaY); |
126 ctm.mapVectors(&sigma, &localSigma, 1); | 132 ctm.mapVectors(&sigma, &localSigma, 1); |
127 bounds.outset(SkScalarCeilToInt(SkScalarMul(sigma.x(), SkIntToScalar(3))), | 133 bounds.outset(SkScalarCeilToInt(SkScalarMul(sigma.x(), SkIntToScalar(3))), |
128 SkScalarCeilToInt(SkScalarMul(sigma.y(), SkIntToScalar(3)))); | 134 SkScalarCeilToInt(SkScalarMul(sigma.y(), SkIntToScalar(3)))); |
129 bounds.join(src); | 135 bounds.join(src); |
130 *dst = bounds; | 136 *dst = bounds; |
131 return true; | 137 return true; |
132 } | 138 } |
OLD | NEW |