| 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 "glsl/GrGLSLFragmentProcessor.h" |
| 21 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 21 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
| 22 #include "glsl/GrGLSLProgramBuilder.h" | 22 #include "glsl/GrGLSLProgramBuilder.h" |
| 23 #include "glsl/GrGLSLProgramDataManager.h" | 23 #include "glsl/GrGLSLProgramDataManager.h" |
| 24 #endif | 24 #endif |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 #define kChannelSelectorKeyBits 3; // Max value is 4, so 3 bits are required at
most | 28 #define kChannelSelectorKeyBits 3; // Max value is 4, so 3 bits are required at
most |
| 29 | 29 |
| 30 template<SkDisplacementMapEffect::ChannelSelectorType type> | 30 template<SkDisplacementMapEffect::ChannelSelectorType type> |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 if (this->getColorInput()) { | 297 if (this->getColorInput()) { |
| 298 this->getColorInput()->toString(str); | 298 this->getColorInput()->toString(str); |
| 299 } | 299 } |
| 300 str->appendf("))"); | 300 str->appendf("))"); |
| 301 } | 301 } |
| 302 #endif | 302 #endif |
| 303 | 303 |
| 304 /////////////////////////////////////////////////////////////////////////////// | 304 /////////////////////////////////////////////////////////////////////////////// |
| 305 | 305 |
| 306 #if SK_SUPPORT_GPU | 306 #if SK_SUPPORT_GPU |
| 307 class GrGLDisplacementMapEffect : public GrGLFragmentProcessor { | 307 class GrGLDisplacementMapEffect : public GrGLSLFragmentProcessor { |
| 308 public: | 308 public: |
| 309 GrGLDisplacementMapEffect(const GrProcessor&); | 309 GrGLDisplacementMapEffect(const GrProcessor&); |
| 310 virtual ~GrGLDisplacementMapEffect(); | 310 virtual ~GrGLDisplacementMapEffect(); |
| 311 | 311 |
| 312 virtual void emitCode(EmitArgs&) override; | 312 virtual void emitCode(EmitArgs&) override; |
| 313 | 313 |
| 314 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
KeyBuilder*); | 314 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
KeyBuilder*); |
| 315 | 315 |
| 316 const GrTextureDomain::GLDomain& glDomain() const { return fGLDomain; } | 316 const GrTextureDomain::GLDomain& glDomain() const { return fGLDomain; } |
| 317 | 317 |
| 318 protected: | 318 protected: |
| 319 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override
; | 319 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override
; |
| 320 | 320 |
| 321 private: | 321 private: |
| 322 SkDisplacementMapEffect::ChannelSelectorType fXChannelSelector; | 322 SkDisplacementMapEffect::ChannelSelectorType fXChannelSelector; |
| 323 SkDisplacementMapEffect::ChannelSelectorType fYChannelSelector; | 323 SkDisplacementMapEffect::ChannelSelectorType fYChannelSelector; |
| 324 GrGLSLProgramDataManager::UniformHandle fScaleUni; | 324 GrGLSLProgramDataManager::UniformHandle fScaleUni; |
| 325 GrTextureDomain::GLDomain fGLDomain; | 325 GrTextureDomain::GLDomain fGLDomain; |
| 326 | 326 |
| 327 typedef GrGLFragmentProcessor INHERITED; | 327 typedef GrGLSLFragmentProcessor INHERITED; |
| 328 }; | 328 }; |
| 329 | 329 |
| 330 /////////////////////////////////////////////////////////////////////////////// | 330 /////////////////////////////////////////////////////////////////////////////// |
| 331 | 331 |
| 332 class GrDisplacementMapEffect : public GrFragmentProcessor { | 332 class GrDisplacementMapEffect : public GrFragmentProcessor { |
| 333 public: | 333 public: |
| 334 static GrFragmentProcessor* Create( | 334 static GrFragmentProcessor* Create( |
| 335 SkDisplacementMapEffect::ChannelSelectorType xChannelSelector, | 335 SkDisplacementMapEffect::ChannelSelectorType xChannelSelector, |
| 336 SkDisplacementMapEffect::ChannelSelectorType yChannelSelector, SkVec
tor scale, | 336 SkDisplacementMapEffect::ChannelSelectorType yChannelSelector, SkVec
tor scale, |
| 337 GrTexture* displacement, const SkMatrix& offsetMatrix, GrTexture* co
lor, | 337 GrTexture* displacement, const SkMatrix& offsetMatrix, GrTexture* co
lor, |
| 338 const SkISize& colorDimensions) { | 338 const SkISize& colorDimensions) { |
| 339 return new GrDisplacementMapEffect(xChannelSelector, yChannelSelector, s
cale, displacement, | 339 return new GrDisplacementMapEffect(xChannelSelector, yChannelSelector, s
cale, displacement, |
| 340 offsetMatrix, color, colorDimensions)
; | 340 offsetMatrix, color, colorDimensions)
; |
| 341 } | 341 } |
| 342 | 342 |
| 343 virtual ~GrDisplacementMapEffect(); | 343 virtual ~GrDisplacementMapEffect(); |
| 344 | 344 |
| 345 SkDisplacementMapEffect::ChannelSelectorType xChannelSelector() const | 345 SkDisplacementMapEffect::ChannelSelectorType xChannelSelector() const |
| 346 { return fXChannelSelector; } | 346 { return fXChannelSelector; } |
| 347 SkDisplacementMapEffect::ChannelSelectorType yChannelSelector() const | 347 SkDisplacementMapEffect::ChannelSelectorType yChannelSelector() const |
| 348 { return fYChannelSelector; } | 348 { return fYChannelSelector; } |
| 349 const SkVector& scale() const { return fScale; } | 349 const SkVector& scale() const { return fScale; } |
| 350 | 350 |
| 351 const char* name() const override { return "DisplacementMap"; } | 351 const char* name() const override { return "DisplacementMap"; } |
| 352 const GrTextureDomain& domain() const { return fDomain; } | 352 const GrTextureDomain& domain() const { return fDomain; } |
| 353 | 353 |
| 354 private: | 354 private: |
| 355 GrGLFragmentProcessor* onCreateGLInstance() const override { | 355 GrGLSLFragmentProcessor* onCreateGLInstance() const override { |
| 356 return new GrGLDisplacementMapEffect(*this); | 356 return new GrGLDisplacementMapEffect(*this); |
| 357 } | 357 } |
| 358 | 358 |
| 359 virtual void onGetGLProcessorKey(const GrGLSLCaps& caps, | 359 virtual void onGetGLProcessorKey(const GrGLSLCaps& caps, |
| 360 GrProcessorKeyBuilder* b) const override { | 360 GrProcessorKeyBuilder* b) const override { |
| 361 GrGLDisplacementMapEffect::GenKey(*this, caps, b); | 361 GrGLDisplacementMapEffect::GenKey(*this, caps, b); |
| 362 } | 362 } |
| 363 | 363 |
| 364 bool onIsEqual(const GrFragmentProcessor&) const override; | 364 bool onIsEqual(const GrFragmentProcessor&) const override; |
| 365 | 365 |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 const GrGLSLCaps&, GrProcessorKeyBuilder*
b) { | 628 const GrGLSLCaps&, GrProcessorKeyBuilder*
b) { |
| 629 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap
Effect>(); | 629 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap
Effect>(); |
| 630 | 630 |
| 631 uint32_t xKey = displacementMap.xChannelSelector(); | 631 uint32_t xKey = displacementMap.xChannelSelector(); |
| 632 uint32_t yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBit
s; | 632 uint32_t yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBit
s; |
| 633 | 633 |
| 634 b->add32(xKey | yKey); | 634 b->add32(xKey | yKey); |
| 635 } | 635 } |
| 636 #endif | 636 #endif |
| 637 | 637 |
| OLD | NEW |