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 "SkDisplacementMapEffect.h" | 8 #include "SkDisplacementMapEffect.h" |
9 #include "SkReadBuffer.h" | 9 #include "SkReadBuffer.h" |
10 #include "SkWriteBuffer.h" | 10 #include "SkWriteBuffer.h" |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 buffer.writeInt((int) fYChannelSelector); | 206 buffer.writeInt((int) fYChannelSelector); |
207 buffer.writeScalar(fScale); | 207 buffer.writeScalar(fScale); |
208 } | 208 } |
209 | 209 |
210 bool SkDisplacementMapEffect::onFilterImage(Proxy* proxy, | 210 bool SkDisplacementMapEffect::onFilterImage(Proxy* proxy, |
211 const SkBitmap& src, | 211 const SkBitmap& src, |
212 const Context& ctx, | 212 const Context& ctx, |
213 SkBitmap* dst, | 213 SkBitmap* dst, |
214 SkIPoint* offset) const { | 214 SkIPoint* offset) const { |
215 SkBitmap displ = src, color = src; | 215 SkBitmap displ = src, color = src; |
216 const SkImageFilter* colorInput = getColorInput(); | 216 const SkImageFilter* colorInput = this->getColorInput(); |
217 const SkImageFilter* displInput = getDisplacementInput(); | 217 const SkImageFilter* displInput = this->getDisplacementInput(); |
218 SkIPoint colorOffset = SkIPoint::Make(0, 0), displOffset = SkIPoint::Make(0,
0); | 218 SkIPoint colorOffset = SkIPoint::Make(0, 0), displOffset = SkIPoint::Make(0,
0); |
219 if ((colorInput && !colorInput->filterImage(proxy, src, ctx, &color, &colorO
ffset)) || | 219 if ((colorInput && !colorInput->filterImage(proxy, src, ctx, &color, &colorO
ffset)) || |
220 (displInput && !displInput->filterImage(proxy, src, ctx, &displ, &displO
ffset))) { | 220 (displInput && !displInput->filterImage(proxy, src, ctx, &displ, &displO
ffset))) { |
221 return false; | 221 return false; |
222 } | 222 } |
223 if ((displ.colorType() != kN32_SkColorType) || | 223 if ((displ.colorType() != kN32_SkColorType) || |
224 (color.colorType() != kN32_SkColorType)) { | 224 (color.colorType() != kN32_SkColorType)) { |
225 return false; | 225 return false; |
226 } | 226 } |
227 SkIRect bounds; | 227 SkIRect bounds; |
(...skipping 25 matching lines...) Expand all Loading... |
253 | 253 |
254 computeDisplacement(fXChannelSelector, fYChannelSelector, scale, dst, | 254 computeDisplacement(fXChannelSelector, fYChannelSelector, scale, dst, |
255 &displ, colorOffset - displOffset, &color, colorBounds); | 255 &displ, colorOffset - displOffset, &color, colorBounds); |
256 | 256 |
257 offset->fX = bounds.left(); | 257 offset->fX = bounds.left(); |
258 offset->fY = bounds.top(); | 258 offset->fY = bounds.top(); |
259 return true; | 259 return true; |
260 } | 260 } |
261 | 261 |
262 void SkDisplacementMapEffect::computeFastBounds(const SkRect& src, SkRect* dst)
const { | 262 void SkDisplacementMapEffect::computeFastBounds(const SkRect& src, SkRect* dst)
const { |
263 if (getColorInput()) { | 263 if (this->getColorInput()) { |
264 getColorInput()->computeFastBounds(src, dst); | 264 this->getColorInput()->computeFastBounds(src, dst); |
265 } else { | 265 } else { |
266 *dst = src; | 266 *dst = src; |
267 } | 267 } |
268 dst->outset(fScale * SK_ScalarHalf, fScale * SK_ScalarHalf); | 268 dst->outset(fScale * SK_ScalarHalf, fScale * SK_ScalarHalf); |
269 } | 269 } |
270 | 270 |
271 bool SkDisplacementMapEffect::onFilterBounds(const SkIRect& src, const SkMatrix&
ctm, | 271 bool SkDisplacementMapEffect::onFilterBounds(const SkIRect& src, const SkMatrix&
ctm, |
272 SkIRect* dst) const { | 272 SkIRect* dst) const { |
273 SkIRect bounds = src; | 273 SkIRect bounds = src; |
274 SkVector scale = SkVector::Make(fScale, fScale); | 274 SkVector scale = SkVector::Make(fScale, fScale); |
275 ctm.mapVectors(&scale, 1); | 275 ctm.mapVectors(&scale, 1); |
276 bounds.outset(SkScalarCeilToInt(scale.fX * SK_ScalarHalf), | 276 bounds.outset(SkScalarCeilToInt(scale.fX * SK_ScalarHalf), |
277 SkScalarCeilToInt(scale.fY * SK_ScalarHalf)); | 277 SkScalarCeilToInt(scale.fY * SK_ScalarHalf)); |
278 if (getColorInput()) { | 278 if (this->getColorInput()) { |
279 return getColorInput()->filterBounds(bounds, ctm, dst); | 279 return this->getColorInput()->filterBounds(bounds, ctm, dst); |
280 } | 280 } |
281 *dst = bounds; | 281 *dst = bounds; |
282 return true; | 282 return true; |
283 } | 283 } |
284 | 284 |
285 #ifndef SK_IGNORE_TO_STRING | 285 #ifndef SK_IGNORE_TO_STRING |
286 void SkDisplacementMapEffect::toString(SkString* str) const { | 286 void SkDisplacementMapEffect::toString(SkString* str) const { |
287 str->appendf("SkDisplacementMapEffect: ("); | 287 str->appendf("SkDisplacementMapEffect: ("); |
288 str->appendf("scale: %f ", fScale); | 288 str->appendf("scale: %f ", fScale); |
289 str->appendf("displacement: ("); | 289 str->appendf("displacement: ("); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 SkDisplacementMapEffect::ChannelSelectorType fYChannelSelector; | 391 SkDisplacementMapEffect::ChannelSelectorType fYChannelSelector; |
392 SkVector fScale; | 392 SkVector fScale; |
393 | 393 |
394 typedef GrFragmentProcessor INHERITED; | 394 typedef GrFragmentProcessor INHERITED; |
395 }; | 395 }; |
396 | 396 |
397 bool SkDisplacementMapEffect::filterImageGPU(Proxy* proxy, const SkBitmap& src,
const Context& ctx, | 397 bool SkDisplacementMapEffect::filterImageGPU(Proxy* proxy, const SkBitmap& src,
const Context& ctx, |
398 SkBitmap* result, SkIPoint* offset)
const { | 398 SkBitmap* result, SkIPoint* offset)
const { |
399 SkBitmap colorBM = src; | 399 SkBitmap colorBM = src; |
400 SkIPoint colorOffset = SkIPoint::Make(0, 0); | 400 SkIPoint colorOffset = SkIPoint::Make(0, 0); |
401 if (getColorInput() && !getColorInput()->getInputResultGPU(proxy, src, ctx,
&colorBM, | 401 if (this->getColorInput() && |
402 &colorOffset)) { | 402 !this->getColorInput()->getInputResultGPU(proxy, src, ctx, &colorBM, &co
lorOffset)) { |
403 return false; | 403 return false; |
404 } | 404 } |
405 SkBitmap displacementBM = src; | 405 SkBitmap displacementBM = src; |
406 SkIPoint displacementOffset = SkIPoint::Make(0, 0); | 406 SkIPoint displacementOffset = SkIPoint::Make(0, 0); |
407 if (getDisplacementInput() && | 407 if (this->getDisplacementInput() && |
408 !getDisplacementInput()->getInputResultGPU(proxy, src, ctx, &displacemen
tBM, | 408 !this->getDisplacementInput()->getInputResultGPU(proxy, src, ctx, &displ
acementBM, |
409 &displacementOffset)) { | 409 &displacementOffset)) { |
410 return false; | 410 return false; |
411 } | 411 } |
412 SkIRect bounds; | 412 SkIRect bounds; |
413 // Since GrDisplacementMapEffect does bounds checking on color pixel access,
we don't need to | 413 // Since GrDisplacementMapEffect does bounds checking on color pixel access,
we don't need to |
414 // pad the color bitmap to bounds here. | 414 // pad the color bitmap to bounds here. |
415 if (!this->applyCropRect(ctx, colorBM, colorOffset, &bounds)) { | 415 if (!this->applyCropRect(ctx, colorBM, colorOffset, &bounds)) { |
416 return false; | 416 return false; |
417 } | 417 } |
418 SkIRect displBounds; | 418 SkIRect displBounds; |
419 if (!this->applyCropRect(ctx, proxy, displacementBM, | 419 if (!this->applyCropRect(ctx, proxy, displacementBM, |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 const GrGLSLCaps&, GrProcessorKeyBuilder*
b) { | 647 const GrGLSLCaps&, GrProcessorKeyBuilder*
b) { |
648 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap
Effect>(); | 648 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap
Effect>(); |
649 | 649 |
650 uint32_t xKey = displacementMap.xChannelSelector(); | 650 uint32_t xKey = displacementMap.xChannelSelector(); |
651 uint32_t yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBit
s; | 651 uint32_t yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBit
s; |
652 | 652 |
653 b->add32(xKey | yKey); | 653 b->add32(xKey | yKey); |
654 } | 654 } |
655 #endif | 655 #endif |
656 | 656 |
OLD | NEW |