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 "SkDevice.h" | 9 #include "SkDevice.h" |
10 #include "SkReadBuffer.h" | 10 #include "SkReadBuffer.h" |
11 #include "SkWriteBuffer.h" | 11 #include "SkWriteBuffer.h" |
12 #include "SkUnPreMultiply.h" | 12 #include "SkUnPreMultiply.h" |
13 #include "SkColorPriv.h" | 13 #include "SkColorPriv.h" |
14 #if SK_SUPPORT_GPU | 14 #if SK_SUPPORT_GPU |
15 #include "GrContext.h" | 15 #include "GrContext.h" |
16 #include "GrDrawContext.h" | 16 #include "GrDrawContext.h" |
17 #include "GrCoordTransform.h" | 17 #include "GrCoordTransform.h" |
18 #include "GrInvariantOutput.h" | 18 #include "GrInvariantOutput.h" |
19 #include "effects/GrTextureDomain.h" | 19 #include "effects/GrTextureDomain.h" |
20 #include "gl/GrGLFragmentProcessor.h" | 20 #include "gl/GrGLFragmentProcessor.h" |
21 #include "gl/builders/GrGLProgramBuilder.h" | 21 #include "gl/builders/GrGLProgramBuilder.h" |
| 22 #include "glsl/GrGLSLProgramDataManager.h" |
22 #endif | 23 #endif |
23 | 24 |
24 namespace { | 25 namespace { |
25 | 26 |
26 #define kChannelSelectorKeyBits 3; // Max value is 4, so 3 bits are required at
most | 27 #define kChannelSelectorKeyBits 3; // Max value is 4, so 3 bits are required at
most |
27 | 28 |
28 template<SkDisplacementMapEffect::ChannelSelectorType type> | 29 template<SkDisplacementMapEffect::ChannelSelectorType type> |
29 uint32_t getValue(SkColor, const SkUnPreMultiply::Scale*) { | 30 uint32_t getValue(SkColor, const SkUnPreMultiply::Scale*) { |
30 SkDEBUGFAIL("Unknown channel selector"); | 31 SkDEBUGFAIL("Unknown channel selector"); |
31 return 0; | 32 return 0; |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 GrGLDisplacementMapEffect(const GrProcessor&); | 308 GrGLDisplacementMapEffect(const GrProcessor&); |
308 virtual ~GrGLDisplacementMapEffect(); | 309 virtual ~GrGLDisplacementMapEffect(); |
309 | 310 |
310 virtual void emitCode(EmitArgs&) override; | 311 virtual void emitCode(EmitArgs&) override; |
311 | 312 |
312 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
KeyBuilder*); | 313 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
KeyBuilder*); |
313 | 314 |
314 const GrTextureDomain::GLDomain& glDomain() const { return fGLDomain; } | 315 const GrTextureDomain::GLDomain& glDomain() const { return fGLDomain; } |
315 | 316 |
316 protected: | 317 protected: |
317 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; | 318 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override
; |
318 | 319 |
319 private: | 320 private: |
320 SkDisplacementMapEffect::ChannelSelectorType fXChannelSelector; | 321 SkDisplacementMapEffect::ChannelSelectorType fXChannelSelector; |
321 SkDisplacementMapEffect::ChannelSelectorType fYChannelSelector; | 322 SkDisplacementMapEffect::ChannelSelectorType fYChannelSelector; |
322 GrGLProgramDataManager::UniformHandle fScaleUni; | 323 GrGLSLProgramDataManager::UniformHandle fScaleUni; |
323 GrTextureDomain::GLDomain fGLDomain; | 324 GrTextureDomain::GLDomain fGLDomain; |
324 | 325 |
325 typedef GrGLFragmentProcessor INHERITED; | 326 typedef GrGLFragmentProcessor INHERITED; |
326 }; | 327 }; |
327 | 328 |
328 /////////////////////////////////////////////////////////////////////////////// | 329 /////////////////////////////////////////////////////////////////////////////// |
329 | 330 |
330 class GrDisplacementMapEffect : public GrFragmentProcessor { | 331 class GrDisplacementMapEffect : public GrFragmentProcessor { |
331 public: | 332 public: |
332 static GrFragmentProcessor* Create( | 333 static GrFragmentProcessor* Create( |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 default: | 604 default: |
604 SkDEBUGFAIL("Unknown Y channel selector"); | 605 SkDEBUGFAIL("Unknown Y channel selector"); |
605 } | 606 } |
606 fsBuilder->codeAppend("-vec2(0.5));\t\t"); | 607 fsBuilder->codeAppend("-vec2(0.5));\t\t"); |
607 | 608 |
608 fGLDomain.sampleTexture(fsBuilder, domain, args.fOutputColor, SkString(cCoor
ds), | 609 fGLDomain.sampleTexture(fsBuilder, domain, args.fOutputColor, SkString(cCoor
ds), |
609 args.fSamplers[1]); | 610 args.fSamplers[1]); |
610 fsBuilder->codeAppend(";\n"); | 611 fsBuilder->codeAppend(";\n"); |
611 } | 612 } |
612 | 613 |
613 void GrGLDisplacementMapEffect::onSetData(const GrGLProgramDataManager& pdman, | 614 void GrGLDisplacementMapEffect::onSetData(const GrGLSLProgramDataManager& pdman, |
614 const GrProcessor& proc) { | 615 const GrProcessor& proc) { |
615 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap
Effect>(); | 616 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap
Effect>(); |
616 GrTexture* colorTex = displacementMap.texture(1); | 617 GrTexture* colorTex = displacementMap.texture(1); |
617 SkScalar scaleX = displacementMap.scale().fX / colorTex->width(); | 618 SkScalar scaleX = displacementMap.scale().fX / colorTex->width(); |
618 SkScalar scaleY = displacementMap.scale().fY / colorTex->height(); | 619 SkScalar scaleY = displacementMap.scale().fY / colorTex->height(); |
619 pdman.set2f(fScaleUni, SkScalarToFloat(scaleX), | 620 pdman.set2f(fScaleUni, SkScalarToFloat(scaleX), |
620 colorTex->origin() == kTopLeft_GrSurfaceOrigin ? | 621 colorTex->origin() == kTopLeft_GrSurfaceOrigin ? |
621 SkScalarToFloat(scaleY) : SkScalarToFloat(-scaleY)); | 622 SkScalarToFloat(scaleY) : SkScalarToFloat(-scaleY)); |
622 fGLDomain.setData(pdman, displacementMap.domain(), colorTex->origin()); | 623 fGLDomain.setData(pdman, displacementMap.domain(), colorTex->origin()); |
623 } | 624 } |
624 | 625 |
625 void GrGLDisplacementMapEffect::GenKey(const GrProcessor& proc, | 626 void GrGLDisplacementMapEffect::GenKey(const GrProcessor& proc, |
626 const GrGLSLCaps&, GrProcessorKeyBuilder*
b) { | 627 const GrGLSLCaps&, GrProcessorKeyBuilder*
b) { |
627 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap
Effect>(); | 628 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap
Effect>(); |
628 | 629 |
629 uint32_t xKey = displacementMap.xChannelSelector(); | 630 uint32_t xKey = displacementMap.xChannelSelector(); |
630 uint32_t yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBit
s; | 631 uint32_t yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBit
s; |
631 | 632 |
632 b->add32(xKey | yKey); | 633 b->add32(xKey | yKey); |
633 } | 634 } |
634 #endif | 635 #endif |
635 | 636 |
OLD | NEW |