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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 shadowBounds.offset(fDx, fDy); | 109 shadowBounds.offset(fDx, fDy); |
110 shadowBounds.outset(SkScalarMul(fSigmaX, SkIntToScalar(3)), | 110 shadowBounds.outset(SkScalarMul(fSigmaX, SkIntToScalar(3)), |
111 SkScalarMul(fSigmaY, SkIntToScalar(3))); | 111 SkScalarMul(fSigmaY, SkIntToScalar(3))); |
112 if (fShadowMode == kDrawShadowAndForeground_ShadowMode) { | 112 if (fShadowMode == kDrawShadowAndForeground_ShadowMode) { |
113 dst->join(shadowBounds); | 113 dst->join(shadowBounds); |
114 } else { | 114 } else { |
115 *dst = shadowBounds; | 115 *dst = shadowBounds; |
116 } | 116 } |
117 } | 117 } |
118 | 118 |
119 bool SkDropShadowImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix&
ctm, | 119 void SkDropShadowImageFilter::onFilterNodeBounds(const SkIRect& src, const SkMat
rix& ctm, |
120 SkIRect* dst) const { | 120 SkIRect* dst, MapDirection dire
ction) const { |
121 SkIRect bounds = src; | 121 *dst = src; |
122 SkVector offsetVec = SkVector::Make(fDx, fDy); | 122 SkVector offsetVec = SkVector::Make(fDx, fDy); |
| 123 if (kReverse_MapDirection == direction) { |
| 124 offsetVec.negate(); |
| 125 } |
123 ctm.mapVectors(&offsetVec, 1); | 126 ctm.mapVectors(&offsetVec, 1); |
124 bounds.offset(-SkScalarCeilToInt(offsetVec.x()), | 127 dst->offset(SkScalarCeilToInt(offsetVec.x()), |
125 -SkScalarCeilToInt(offsetVec.y())); | 128 SkScalarCeilToInt(offsetVec.y())); |
126 SkVector sigma = SkVector::Make(fSigmaX, fSigmaY); | 129 SkVector sigma = SkVector::Make(fSigmaX, fSigmaY); |
127 ctm.mapVectors(&sigma, 1); | 130 ctm.mapVectors(&sigma, 1); |
128 bounds.outset(SkScalarCeilToInt(SkScalarMul(sigma.x(), SkIntToScalar(3))), | 131 dst->outset(SkScalarCeilToInt(SkScalarMul(sigma.x(), SkIntToScalar(3))), |
129 SkScalarCeilToInt(SkScalarMul(sigma.y(), SkIntToScalar(3)))); | 132 SkScalarCeilToInt(SkScalarMul(sigma.y(), SkIntToScalar(3)))); |
130 if (fShadowMode == kDrawShadowAndForeground_ShadowMode) { | 133 if (fShadowMode == kDrawShadowAndForeground_ShadowMode) { |
131 bounds.join(src); | 134 dst->join(src); |
132 } | 135 } |
133 if (getInput(0) && !getInput(0)->filterBounds(bounds, ctm, &bounds)) { | |
134 return false; | |
135 } | |
136 *dst = bounds; | |
137 return true; | |
138 } | 136 } |
139 | 137 |
140 #ifndef SK_IGNORE_TO_STRING | 138 #ifndef SK_IGNORE_TO_STRING |
141 void SkDropShadowImageFilter::toString(SkString* str) const { | 139 void SkDropShadowImageFilter::toString(SkString* str) const { |
142 str->appendf("SkDropShadowImageFilter: ("); | 140 str->appendf("SkDropShadowImageFilter: ("); |
143 | 141 |
144 str->appendf("dX: %f ", fDx); | 142 str->appendf("dX: %f ", fDx); |
145 str->appendf("dY: %f ", fDy); | 143 str->appendf("dY: %f ", fDy); |
146 str->appendf("sigmaX: %f ", fSigmaX); | 144 str->appendf("sigmaX: %f ", fSigmaX); |
147 str->appendf("sigmaY: %f ", fSigmaY); | 145 str->appendf("sigmaY: %f ", fSigmaY); |
148 | 146 |
149 str->append("Color: "); | 147 str->append("Color: "); |
150 str->appendHex(fColor); | 148 str->appendHex(fColor); |
151 | 149 |
152 static const char* gModeStrings[] = { | 150 static const char* gModeStrings[] = { |
153 "kDrawShadowAndForeground", "kDrawShadowOnly" | 151 "kDrawShadowAndForeground", "kDrawShadowOnly" |
154 }; | 152 }; |
155 | 153 |
156 static_assert(kShadowModeCount == SK_ARRAY_COUNT(gModeStrings), "enum_mismat
ch"); | 154 static_assert(kShadowModeCount == SK_ARRAY_COUNT(gModeStrings), "enum_mismat
ch"); |
157 | 155 |
158 str->appendf(" mode: %s", gModeStrings[fShadowMode]); | 156 str->appendf(" mode: %s", gModeStrings[fShadowMode]); |
159 | 157 |
160 str->append(")"); | 158 str->append(")"); |
161 } | 159 } |
162 #endif | 160 #endif |
OLD | NEW |