| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 #include "GrMatrixConvolutionEffect.h" | 7 #include "GrMatrixConvolutionEffect.h" |
| 8 #include "gl/GrGLFragmentProcessor.h" | 8 #include "gl/GrGLFragmentProcessor.h" |
| 9 #include "gl/GrGLTexture.h" | 9 #include "gl/GrGLTexture.h" |
| 10 #include "gl/builders/GrGLProgramBuilder.h" | 10 #include "gl/builders/GrGLProgramBuilder.h" |
| 11 #include "glsl/GrGLSLProgramDataManager.h" |
| 11 | 12 |
| 12 class GrGLMatrixConvolutionEffect : public GrGLFragmentProcessor { | 13 class GrGLMatrixConvolutionEffect : public GrGLFragmentProcessor { |
| 13 public: | 14 public: |
| 14 GrGLMatrixConvolutionEffect(const GrProcessor&); | 15 GrGLMatrixConvolutionEffect(const GrProcessor&); |
| 15 virtual void emitCode(EmitArgs&) override; | 16 virtual void emitCode(EmitArgs&) override; |
| 16 | 17 |
| 17 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
KeyBuilder*); | 18 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
KeyBuilder*); |
| 18 | 19 |
| 19 protected: | 20 protected: |
| 20 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; | 21 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override
; |
| 21 | 22 |
| 22 private: | 23 private: |
| 23 typedef GrGLProgramDataManager::UniformHandle UniformHandle; | 24 typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; |
| 24 SkISize fKernelSize; | 25 SkISize fKernelSize; |
| 25 bool fConvolveAlpha; | 26 bool fConvolveAlpha; |
| 26 | 27 |
| 27 UniformHandle fKernelUni; | 28 UniformHandle fKernelUni; |
| 28 UniformHandle fImageIncrementUni; | 29 UniformHandle fImageIncrementUni; |
| 29 UniformHandle fKernelOffsetUni; | 30 UniformHandle fKernelOffsetUni; |
| 30 UniformHandle fGainUni; | 31 UniformHandle fGainUni; |
| 31 UniformHandle fBiasUni; | 32 UniformHandle fBiasUni; |
| 32 GrTextureDomain::GLDomain fDomain; | 33 GrTextureDomain::GLDomain fDomain; |
| 33 | 34 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 void GrGLMatrixConvolutionEffect::GenKey(const GrProcessor& processor, | 105 void GrGLMatrixConvolutionEffect::GenKey(const GrProcessor& processor, |
| 105 const GrGLSLCaps&, GrProcessorKeyBuilde
r* b) { | 106 const GrGLSLCaps&, GrProcessorKeyBuilde
r* b) { |
| 106 const GrMatrixConvolutionEffect& m = processor.cast<GrMatrixConvolutionEffec
t>(); | 107 const GrMatrixConvolutionEffect& m = processor.cast<GrMatrixConvolutionEffec
t>(); |
| 107 SkASSERT(m.kernelSize().width() <= 0x7FFF && m.kernelSize().height() <= 0xFF
FF); | 108 SkASSERT(m.kernelSize().width() <= 0x7FFF && m.kernelSize().height() <= 0xFF
FF); |
| 108 uint32_t key = m.kernelSize().width() << 16 | m.kernelSize().height(); | 109 uint32_t key = m.kernelSize().width() << 16 | m.kernelSize().height(); |
| 109 key |= m.convolveAlpha() ? 1 << 31 : 0; | 110 key |= m.convolveAlpha() ? 1 << 31 : 0; |
| 110 b->add32(key); | 111 b->add32(key); |
| 111 b->add32(GrTextureDomain::GLDomain::DomainKey(m.domain())); | 112 b->add32(GrTextureDomain::GLDomain::DomainKey(m.domain())); |
| 112 } | 113 } |
| 113 | 114 |
| 114 void GrGLMatrixConvolutionEffect::onSetData(const GrGLProgramDataManager& pdman, | 115 void GrGLMatrixConvolutionEffect::onSetData(const GrGLSLProgramDataManager& pdma
n, |
| 115 const GrProcessor& processor) { | 116 const GrProcessor& processor) { |
| 116 const GrMatrixConvolutionEffect& conv = processor.cast<GrMatrixConvolutionEf
fect>(); | 117 const GrMatrixConvolutionEffect& conv = processor.cast<GrMatrixConvolutionEf
fect>(); |
| 117 GrTexture& texture = *conv.texture(0); | 118 GrTexture& texture = *conv.texture(0); |
| 118 // the code we generated was for a specific kernel size | 119 // the code we generated was for a specific kernel size |
| 119 SkASSERT(conv.kernelSize() == fKernelSize); | 120 SkASSERT(conv.kernelSize() == fKernelSize); |
| 120 float imageIncrement[2]; | 121 float imageIncrement[2]; |
| 121 float ySign = texture.origin() == kTopLeft_GrSurfaceOrigin ? 1.0f : -1.0f; | 122 float ySign = texture.origin() == kTopLeft_GrSurfaceOrigin ? 1.0f : -1.0f; |
| 122 imageIncrement[0] = 1.0f / texture.width(); | 123 imageIncrement[0] = 1.0f / texture.width(); |
| 123 imageIncrement[1] = ySign / texture.height(); | 124 imageIncrement[1] = ySign / texture.height(); |
| 124 pdman.set2fv(fImageIncrementUni, 1, imageIncrement); | 125 pdman.set2fv(fImageIncrementUni, 1, imageIncrement); |
| 125 pdman.set2fv(fKernelOffsetUni, 1, conv.kernelOffset()); | 126 pdman.set2fv(fKernelOffsetUni, 1, conv.kernelOffset()); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 return GrMatrixConvolutionEffect::Create(d->fTextures[texIdx], | 245 return GrMatrixConvolutionEffect::Create(d->fTextures[texIdx], |
| 245 bounds, | 246 bounds, |
| 246 kernelSize, | 247 kernelSize, |
| 247 kernel.get(), | 248 kernel.get(), |
| 248 gain, | 249 gain, |
| 249 bias, | 250 bias, |
| 250 kernelOffset, | 251 kernelOffset, |
| 251 tileMode, | 252 tileMode, |
| 252 convolveAlpha); | 253 convolveAlpha); |
| 253 } | 254 } |
| OLD | NEW |