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" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 if (!this->applyCropRect(ctx, src, srcOffset, &bounds)) { | 74 if (!this->applyCropRect(ctx, src, srcOffset, &bounds)) { |
75 return false; | 75 return false; |
76 } | 76 } |
77 | 77 |
78 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds
.height())); | 78 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds
.height())); |
79 if (NULL == device.get()) { | 79 if (NULL == device.get()) { |
80 return false; | 80 return false; |
81 } | 81 } |
82 SkCanvas canvas(device.get()); | 82 SkCanvas canvas(device.get()); |
83 | 83 |
84 SkVector sigma, localSigma = SkVector::Make(fSigmaX, fSigmaY); | 84 SkVector sigma = SkVector::Make(fSigmaX, fSigmaY); |
85 ctx.ctm().mapVectors(&sigma, &localSigma, 1); | 85 ctx.ctm().mapVectors(&sigma, 1); |
86 sigma.fX = SkMaxScalar(0, sigma.fX); | 86 sigma.fX = SkMaxScalar(0, sigma.fX); |
87 sigma.fY = SkMaxScalar(0, sigma.fY); | 87 sigma.fY = SkMaxScalar(0, sigma.fY); |
88 SkAutoTUnref<SkImageFilter> blurFilter(SkBlurImageFilter::Create(sigma.fX, s
igma.fY)); | 88 SkAutoTUnref<SkImageFilter> blurFilter(SkBlurImageFilter::Create(sigma.fX, s
igma.fY)); |
89 SkAutoTUnref<SkColorFilter> colorFilter( | 89 SkAutoTUnref<SkColorFilter> colorFilter( |
90 SkColorFilter::CreateModeFilter(fColor, SkXfermode::kSrcIn_Mode)); | 90 SkColorFilter::CreateModeFilter(fColor, SkXfermode::kSrcIn_Mode)); |
91 SkPaint paint; | 91 SkPaint paint; |
92 paint.setImageFilter(blurFilter.get()); | 92 paint.setImageFilter(blurFilter.get()); |
93 paint.setColorFilter(colorFilter.get()); | 93 paint.setColorFilter(colorFilter.get()); |
94 paint.setXfermodeMode(SkXfermode::kSrcOver_Mode); | 94 paint.setXfermodeMode(SkXfermode::kSrcOver_Mode); |
95 SkVector offsetVec, localOffsetVec = SkVector::Make(fDx, fDy); | 95 SkVector offsetVec = SkVector::Make(fDx, fDy); |
96 ctx.ctm().mapVectors(&offsetVec, &localOffsetVec, 1); | 96 ctx.ctm().mapVectors(&offsetVec, 1); |
97 canvas.translate(SkIntToScalar(srcOffset.fX - bounds.fLeft), | 97 canvas.translate(SkIntToScalar(srcOffset.fX - bounds.fLeft), |
98 SkIntToScalar(srcOffset.fY - bounds.fTop)); | 98 SkIntToScalar(srcOffset.fY - bounds.fTop)); |
99 canvas.drawBitmap(src, offsetVec.fX, offsetVec.fY, &paint); | 99 canvas.drawBitmap(src, offsetVec.fX, offsetVec.fY, &paint); |
100 canvas.drawBitmap(src, 0, 0); | 100 canvas.drawBitmap(src, 0, 0); |
101 *result = device->accessBitmap(false); | 101 *result = device->accessBitmap(false); |
102 offset->fX = bounds.fLeft; | 102 offset->fX = bounds.fLeft; |
103 offset->fY = bounds.fTop; | 103 offset->fY = bounds.fTop; |
104 return true; | 104 return true; |
105 } | 105 } |
106 | 106 |
(...skipping 10 matching lines...) Expand all Loading... |
117 SkScalarMul(fSigmaY, SkIntToScalar(3))); | 117 SkScalarMul(fSigmaY, SkIntToScalar(3))); |
118 dst->join(shadowBounds); | 118 dst->join(shadowBounds); |
119 } | 119 } |
120 | 120 |
121 bool SkDropShadowImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix&
ctm, | 121 bool SkDropShadowImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix&
ctm, |
122 SkIRect* dst) const { | 122 SkIRect* dst) const { |
123 SkIRect bounds = src; | 123 SkIRect bounds = src; |
124 if (getInput(0) && !getInput(0)->filterBounds(src, ctm, &bounds)) { | 124 if (getInput(0) && !getInput(0)->filterBounds(src, ctm, &bounds)) { |
125 return false; | 125 return false; |
126 } | 126 } |
127 SkVector offsetVec, localOffsetVec = SkVector::Make(fDx, fDy); | 127 SkVector offsetVec = SkVector::Make(fDx, fDy); |
128 ctm.mapVectors(&offsetVec, &localOffsetVec, 1); | 128 ctm.mapVectors(&offsetVec, 1); |
129 bounds.offset(-SkScalarCeilToInt(offsetVec.x()), | 129 bounds.offset(-SkScalarCeilToInt(offsetVec.x()), |
130 -SkScalarCeilToInt(offsetVec.y())); | 130 -SkScalarCeilToInt(offsetVec.y())); |
131 SkVector sigma, localSigma = SkVector::Make(fSigmaX, fSigmaY); | 131 SkVector sigma = SkVector::Make(fSigmaX, fSigmaY); |
132 ctm.mapVectors(&sigma, &localSigma, 1); | 132 ctm.mapVectors(&sigma, 1); |
133 bounds.outset(SkScalarCeilToInt(SkScalarMul(sigma.x(), SkIntToScalar(3))), | 133 bounds.outset(SkScalarCeilToInt(SkScalarMul(sigma.x(), SkIntToScalar(3))), |
134 SkScalarCeilToInt(SkScalarMul(sigma.y(), SkIntToScalar(3)))); | 134 SkScalarCeilToInt(SkScalarMul(sigma.y(), SkIntToScalar(3)))); |
135 bounds.join(src); | 135 bounds.join(src); |
136 *dst = bounds; | 136 *dst = bounds; |
137 return true; | 137 return true; |
138 } | 138 } |
OLD | NEW |