| 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 "SkFlattenableBuffers.h" | 9 #include "SkFlattenableBuffers.h" |
| 10 #include "SkUnPreMultiply.h" | 10 #include "SkUnPreMultiply.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 | 42 |
| 43 template<> uint32_t getValue<SkDisplacementMapEffect::kA_ChannelSelectorType>( | 43 template<> uint32_t getValue<SkDisplacementMapEffect::kA_ChannelSelectorType>( |
| 44 SkColor l, const SkUnPreMultiply::Scale*) { | 44 SkColor l, const SkUnPreMultiply::Scale*) { |
| 45 return SkGetPackedA32(l); | 45 return SkGetPackedA32(l); |
| 46 } | 46 } |
| 47 | 47 |
| 48 template<SkDisplacementMapEffect::ChannelSelectorType typeX, | 48 template<SkDisplacementMapEffect::ChannelSelectorType typeX, |
| 49 SkDisplacementMapEffect::ChannelSelectorType typeY> | 49 SkDisplacementMapEffect::ChannelSelectorType typeY> |
| 50 void computeDisplacement(SkScalar scale, SkBitmap* dst, SkBitmap* displ, SkBitma
p* src, const SkIRect& bounds) | 50 void computeDisplacement(SkScalar scale, SkBitmap* dst, SkBitmap* displ, SkBitma
p* src, const SkIRect& bounds) |
| 51 { | 51 { |
| 52 static const SkScalar Inv8bit = SkScalarDiv(SK_Scalar1, SkFloatToScalar(255.
0f)); | 52 static const SkScalar Inv8bit = SkScalarDiv(SK_Scalar1, 255.0f); |
| 53 const int srcW = src->width(); | 53 const int srcW = src->width(); |
| 54 const int srcH = src->height(); | 54 const int srcH = src->height(); |
| 55 const SkScalar scaleForColor = SkScalarMul(scale, Inv8bit); | 55 const SkScalar scaleForColor = SkScalarMul(scale, Inv8bit); |
| 56 const SkScalar scaleAdj = SK_ScalarHalf - SkScalarMul(scale, SK_ScalarHalf); | 56 const SkScalar scaleAdj = SK_ScalarHalf - SkScalarMul(scale, SK_ScalarHalf); |
| 57 const SkUnPreMultiply::Scale* table = SkUnPreMultiply::GetScaleTable(); | 57 const SkUnPreMultiply::Scale* table = SkUnPreMultiply::GetScaleTable(); |
| 58 SkPMColor* dstPtr = dst->getAddr32(0, 0); | 58 SkPMColor* dstPtr = dst->getAddr32(0, 0); |
| 59 for (int y = bounds.top(); y < bounds.bottom(); ++y) { | 59 for (int y = bounds.top(); y < bounds.bottom(); ++y) { |
| 60 const SkPMColor* displPtr = displ->getAddr32(bounds.left(), y); | 60 const SkPMColor* displPtr = displ->getAddr32(bounds.left(), y); |
| 61 for (int x = bounds.left(); x < bounds.right(); ++x, ++displPtr) { | 61 for (int x = bounds.left(); x < bounds.right(); ++x, ++displPtr) { |
| 62 const SkScalar displX = SkScalarMul(scaleForColor, | 62 const SkScalar displX = SkScalarMul(scaleForColor, |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 GrEffectUnitTest::kAlphaTextureIdx; | 406 GrEffectUnitTest::kAlphaTextureIdx; |
| 407 int texIdxColor = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx : | 407 int texIdxColor = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx : |
| 408 GrEffectUnitTest::kAlphaTextureIdx; | 408 GrEffectUnitTest::kAlphaTextureIdx; |
| 409 static const int kMaxComponent = 4; | 409 static const int kMaxComponent = 4; |
| 410 SkDisplacementMapEffect::ChannelSelectorType xChannelSelector = | 410 SkDisplacementMapEffect::ChannelSelectorType xChannelSelector = |
| 411 static_cast<SkDisplacementMapEffect::ChannelSelectorType>( | 411 static_cast<SkDisplacementMapEffect::ChannelSelectorType>( |
| 412 random->nextRangeU(1, kMaxComponent)); | 412 random->nextRangeU(1, kMaxComponent)); |
| 413 SkDisplacementMapEffect::ChannelSelectorType yChannelSelector = | 413 SkDisplacementMapEffect::ChannelSelectorType yChannelSelector = |
| 414 static_cast<SkDisplacementMapEffect::ChannelSelectorType>( | 414 static_cast<SkDisplacementMapEffect::ChannelSelectorType>( |
| 415 random->nextRangeU(1, kMaxComponent)); | 415 random->nextRangeU(1, kMaxComponent)); |
| 416 SkScalar scale = random->nextRangeScalar(0, SkFloatToScalar(100.0f)); | 416 SkScalar scale = random->nextRangeScalar(0, 100.0f); |
| 417 | 417 |
| 418 return GrDisplacementMapEffect::Create(xChannelSelector, yChannelSelector, s
cale, | 418 return GrDisplacementMapEffect::Create(xChannelSelector, yChannelSelector, s
cale, |
| 419 textures[texIdxDispl], textures[texId
xColor]); | 419 textures[texIdxDispl], textures[texId
xColor]); |
| 420 } | 420 } |
| 421 | 421 |
| 422 /////////////////////////////////////////////////////////////////////////////// | 422 /////////////////////////////////////////////////////////////////////////////// |
| 423 | 423 |
| 424 GrGLDisplacementMapEffect::GrGLDisplacementMapEffect(const GrBackendEffectFactor
y& factory, | 424 GrGLDisplacementMapEffect::GrGLDisplacementMapEffect(const GrBackendEffectFactor
y& factory, |
| 425 const GrDrawEffect& drawEff
ect) | 425 const GrDrawEffect& drawEff
ect) |
| 426 : INHERITED(factory) | 426 : INHERITED(factory) |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 const GrGLCaps&) { | 524 const GrGLCaps&) { |
| 525 const GrDisplacementMapEffect& displacementMap = | 525 const GrDisplacementMapEffect& displacementMap = |
| 526 drawEffect.castEffect<GrDisplacementMapEffect>(); | 526 drawEffect.castEffect<GrDisplacementMapEffect>(); |
| 527 | 527 |
| 528 EffectKey xKey = displacementMap.xChannelSelector(); | 528 EffectKey xKey = displacementMap.xChannelSelector(); |
| 529 EffectKey yKey = displacementMap.yChannelSelector() << SkDisplacementMapEffe
ct::kKeyBits; | 529 EffectKey yKey = displacementMap.yChannelSelector() << SkDisplacementMapEffe
ct::kKeyBits; |
| 530 | 530 |
| 531 return xKey | yKey; | 531 return xKey | yKey; |
| 532 } | 532 } |
| 533 #endif | 533 #endif |
| OLD | NEW |