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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 return SkGetPackedA32(l); | 49 return SkGetPackedA32(l); |
50 } | 50 } |
51 | 51 |
52 template<SkDisplacementMapEffect::ChannelSelectorType typeX, | 52 template<SkDisplacementMapEffect::ChannelSelectorType typeX, |
53 SkDisplacementMapEffect::ChannelSelectorType typeY> | 53 SkDisplacementMapEffect::ChannelSelectorType typeY> |
54 void computeDisplacement(const SkVector& scale, SkBitmap* dst, | 54 void computeDisplacement(const SkVector& scale, SkBitmap* dst, |
55 SkBitmap* displ, const SkIPoint& offset, | 55 SkBitmap* displ, const SkIPoint& offset, |
56 SkBitmap* src, | 56 SkBitmap* src, |
57 const SkIRect& bounds) | 57 const SkIRect& bounds) |
58 { | 58 { |
59 static const SkScalar Inv8bit = SkScalarDiv(SK_Scalar1, 255.0f); | 59 static const SkScalar Inv8bit = SkScalarInvert(255); |
60 const int srcW = src->width(); | 60 const int srcW = src->width(); |
61 const int srcH = src->height(); | 61 const int srcH = src->height(); |
62 const SkVector scaleForColor = SkVector::Make(SkScalarMul(scale.fX, Inv8bit)
, | 62 const SkVector scaleForColor = SkVector::Make(SkScalarMul(scale.fX, Inv8bit)
, |
63 SkScalarMul(scale.fY, Inv8bit)
); | 63 SkScalarMul(scale.fY, Inv8bit)
); |
64 const SkVector scaleAdj = SkVector::Make(SK_ScalarHalf - SkScalarMul(scale.f
X, SK_ScalarHalf), | 64 const SkVector scaleAdj = SkVector::Make(SK_ScalarHalf - SkScalarMul(scale.f
X, SK_ScalarHalf), |
65 SK_ScalarHalf - SkScalarMul(scale.f
Y, SK_ScalarHalf)); | 65 SK_ScalarHalf - SkScalarMul(scale.f
Y, SK_ScalarHalf)); |
66 const SkUnPreMultiply::Scale* table = SkUnPreMultiply::GetScaleTable(); | 66 const SkUnPreMultiply::Scale* table = SkUnPreMultiply::GetScaleTable(); |
67 SkPMColor* dstPtr = dst->getAddr32(0, 0); | 67 SkPMColor* dstPtr = dst->getAddr32(0, 0); |
68 for (int y = bounds.top(); y < bounds.bottom(); ++y) { | 68 for (int y = bounds.top(); y < bounds.bottom(); ++y) { |
69 const SkPMColor* displPtr = displ->getAddr32(bounds.left() + offset.fX, | 69 const SkPMColor* displPtr = displ->getAddr32(bounds.left() + offset.fX, |
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 fsBuilder->codeAppend("-vec2(0.5));\t\t"); | 618 fsBuilder->codeAppend("-vec2(0.5));\t\t"); |
619 | 619 |
620 fGLDomain.sampleTexture(fsBuilder, domain, outputColor, SkString(cCoords), s
amplers[1]); | 620 fGLDomain.sampleTexture(fsBuilder, domain, outputColor, SkString(cCoords), s
amplers[1]); |
621 fsBuilder->codeAppend(";\n"); | 621 fsBuilder->codeAppend(";\n"); |
622 } | 622 } |
623 | 623 |
624 void GrGLDisplacementMapEffect::setData(const GrGLProgramDataManager& pdman, | 624 void GrGLDisplacementMapEffect::setData(const GrGLProgramDataManager& pdman, |
625 const GrProcessor& proc) { | 625 const GrProcessor& proc) { |
626 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap
Effect>(); | 626 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap
Effect>(); |
627 GrTexture* colorTex = displacementMap.texture(1); | 627 GrTexture* colorTex = displacementMap.texture(1); |
628 SkScalar scaleX = SkScalarDiv(displacementMap.scale().fX, SkIntToScalar(colo
rTex->width())); | 628 SkScalar scaleX = displacementMap.scale().fX / colorTex->width(); |
629 SkScalar scaleY = SkScalarDiv(displacementMap.scale().fY, SkIntToScalar(colo
rTex->height())); | 629 SkScalar scaleY = displacementMap.scale().fY / colorTex->height(); |
630 pdman.set2f(fScaleUni, SkScalarToFloat(scaleX), | 630 pdman.set2f(fScaleUni, SkScalarToFloat(scaleX), |
631 colorTex->origin() == kTopLeft_GrSurfaceOrigin ? | 631 colorTex->origin() == kTopLeft_GrSurfaceOrigin ? |
632 SkScalarToFloat(scaleY) : SkScalarToFloat(-scaleY)); | 632 SkScalarToFloat(scaleY) : SkScalarToFloat(-scaleY)); |
633 fGLDomain.setData(pdman, displacementMap.domain(), colorTex->origin()); | 633 fGLDomain.setData(pdman, displacementMap.domain(), colorTex->origin()); |
634 } | 634 } |
635 | 635 |
636 void GrGLDisplacementMapEffect::GenKey(const GrProcessor& proc, | 636 void GrGLDisplacementMapEffect::GenKey(const GrProcessor& proc, |
637 const GrGLSLCaps&, GrProcessorKeyBuilder*
b) { | 637 const GrGLSLCaps&, GrProcessorKeyBuilder*
b) { |
638 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap
Effect>(); | 638 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap
Effect>(); |
639 | 639 |
640 uint32_t xKey = displacementMap.xChannelSelector(); | 640 uint32_t xKey = displacementMap.xChannelSelector(); |
641 uint32_t yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBit
s; | 641 uint32_t yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBit
s; |
642 | 642 |
643 b->add32(xKey | yKey); | 643 b->add32(xKey | yKey); |
644 } | 644 } |
645 #endif | 645 #endif |
646 | 646 |
OLD | NEW |