Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(422)

Side by Side Diff: src/effects/SkDisplacementMapEffect.cpp

Issue 1135053002: stop calling SkScalarDiv (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix xpsdevice Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/effects/SkDashPathEffect.cpp ('k') | src/effects/SkEmbossMaskFilter.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « src/effects/SkDashPathEffect.cpp ('k') | src/effects/SkEmbossMaskFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698