| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "gl/builders/GrGLProgramBuilder.h" | 8 #include "gl/builders/GrGLProgramBuilder.h" |
| 9 #include "GrConvolutionEffect.h" | 9 #include "GrConvolutionEffect.h" |
| 10 #include "gl/GrGLProcessor.h" | 10 #include "gl/GrGLProcessor.h" |
| 11 #include "gl/GrGLSL.h" | 11 #include "gl/GrGLSL.h" |
| 12 #include "gl/GrGLTexture.h" | 12 #include "gl/GrGLTexture.h" |
| 13 #include "GrTBackendProcessorFactory.h" | 13 #include "GrTBackendProcessorFactory.h" |
| 14 | 14 |
| 15 // For brevity | 15 // For brevity |
| 16 typedef GrGLProgramDataManager::UniformHandle UniformHandle; | 16 typedef GrGLProgramDataManager::UniformHandle UniformHandle; |
| 17 | 17 |
| 18 class GrGLConvolutionEffect : public GrGLFragmentProcessor { | 18 class GrGLConvolutionEffect : public GrGLFragmentProcessor { |
| 19 public: | 19 public: |
| 20 GrGLConvolutionEffect(const GrBackendProcessorFactory&, const GrProcessor&); | 20 GrGLConvolutionEffect(const GrBackendProcessorFactory&, const GrProcessor&); |
| 21 | 21 |
| 22 virtual void emitCode(GrGLProgramBuilder*, | 22 virtual void emitCode(GrGLFPBuilder*, |
| 23 const GrFragmentProcessor&, | 23 const GrFragmentProcessor&, |
| 24 const GrProcessorKey&, | 24 const GrProcessorKey&, |
| 25 const char* outputColor, | 25 const char* outputColor, |
| 26 const char* inputColor, | 26 const char* inputColor, |
| 27 const TransformedCoordsArray&, | 27 const TransformedCoordsArray&, |
| 28 const TextureSamplerArray&) SK_OVERRIDE; | 28 const TextureSamplerArray&) SK_OVERRIDE; |
| 29 | 29 |
| 30 virtual void setData(const GrGLProgramDataManager& pdman, const GrProcessor&
) SK_OVERRIDE; | 30 virtual void setData(const GrGLProgramDataManager& pdman, const GrProcessor&
) SK_OVERRIDE; |
| 31 | 31 |
| 32 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe
yBuilder*); | 32 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe
yBuilder*); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 48 | 48 |
| 49 GrGLConvolutionEffect::GrGLConvolutionEffect(const GrBackendProcessorFactory& fa
ctory, | 49 GrGLConvolutionEffect::GrGLConvolutionEffect(const GrBackendProcessorFactory& fa
ctory, |
| 50 const GrProcessor& processor) | 50 const GrProcessor& processor) |
| 51 : INHERITED(factory) { | 51 : INHERITED(factory) { |
| 52 const GrConvolutionEffect& c = processor.cast<GrConvolutionEffect>(); | 52 const GrConvolutionEffect& c = processor.cast<GrConvolutionEffect>(); |
| 53 fRadius = c.radius(); | 53 fRadius = c.radius(); |
| 54 fUseBounds = c.useBounds(); | 54 fUseBounds = c.useBounds(); |
| 55 fDirection = c.direction(); | 55 fDirection = c.direction(); |
| 56 } | 56 } |
| 57 | 57 |
| 58 void GrGLConvolutionEffect::emitCode(GrGLProgramBuilder* builder, | 58 void GrGLConvolutionEffect::emitCode(GrGLFPBuilder* builder, |
| 59 const GrFragmentProcessor&, | 59 const GrFragmentProcessor&, |
| 60 const GrProcessorKey& key, | 60 const GrProcessorKey& key, |
| 61 const char* outputColor, | 61 const char* outputColor, |
| 62 const char* inputColor, | 62 const char* inputColor, |
| 63 const TransformedCoordsArray& coords, | 63 const TransformedCoordsArray& coords, |
| 64 const TextureSamplerArray& samplers) { | 64 const TextureSamplerArray& samplers) { |
| 65 fImageIncrementUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visib
ility, | 65 fImageIncrementUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visib
ility, |
| 66 kVec2f_GrSLType, "ImageIncrement"); | 66 kVec2f_GrSLType, "ImageIncrement"); |
| 67 if (this->useBounds()) { | 67 if (this->useBounds()) { |
| 68 fBoundsUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibilit
y, | 68 fBoundsUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibilit
y, |
| 69 kVec2f_GrSLType, "Bounds"); | 69 kVec2f_GrSLType, "Bounds"); |
| 70 } | 70 } |
| 71 fKernelUni = builder->addUniformArray(GrGLProgramBuilder::kFragment_Visibili
ty, | 71 fKernelUni = builder->addUniformArray(GrGLProgramBuilder::kFragment_Visibili
ty, |
| 72 kFloat_GrSLType, "Kernel", this->width
()); | 72 kFloat_GrSLType, "Kernel", this->width
()); |
| 73 | 73 |
| 74 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); | 74 GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); |
| 75 SkString coords2D = fsBuilder->ensureFSCoords2D(coords, 0); | 75 SkString coords2D = fsBuilder->ensureFSCoords2D(coords, 0); |
| 76 | 76 |
| 77 fsBuilder->codeAppendf("\t\t%s = vec4(0, 0, 0, 0);\n", outputColor); | 77 fsBuilder->codeAppendf("\t\t%s = vec4(0, 0, 0, 0);\n", outputColor); |
| 78 | 78 |
| 79 int width = this->width(); | 79 int width = this->width(); |
| 80 const GrGLShaderVar& kernel = builder->getUniformVariable(fKernelUni); | 80 const GrGLShaderVar& kernel = builder->getUniformVariable(fKernelUni); |
| 81 const char* imgInc = builder->getUniformCStr(fImageIncrementUni); | 81 const char* imgInc = builder->getUniformCStr(fImageIncrementUni); |
| 82 | 82 |
| 83 fsBuilder->codeAppendf("\t\tvec2 coord = %s - %d.0 * %s;\n", coords2D.c_str(
), fRadius, imgInc); | 83 fsBuilder->codeAppendf("\t\tvec2 coord = %s - %d.0 * %s;\n", coords2D.c_str(
), fRadius, imgInc); |
| 84 | 84 |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 } | 232 } |
| 233 | 233 |
| 234 bool useBounds = random->nextBool(); | 234 bool useBounds = random->nextBool(); |
| 235 return GrConvolutionEffect::Create(textures[texIdx], | 235 return GrConvolutionEffect::Create(textures[texIdx], |
| 236 dir, | 236 dir, |
| 237 radius, | 237 radius, |
| 238 kernel, | 238 kernel, |
| 239 useBounds, | 239 useBounds, |
| 240 bounds); | 240 bounds); |
| 241 } | 241 } |
| OLD | NEW |