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 "GrSimpleTextureEffect.h" | 8 #include "GrSimpleTextureEffect.h" |
9 #include "GrInvariantOutput.h" | 9 #include "GrInvariantOutput.h" |
10 #include "GrTexture.h" | 10 #include "GrTexture.h" |
| 11 #include "glsl/GrGLSLColorSpaceXformHelper.h" |
11 #include "glsl/GrGLSLFragmentProcessor.h" | 12 #include "glsl/GrGLSLFragmentProcessor.h" |
12 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 13 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
13 | 14 |
14 class GrGLSimpleTextureEffect : public GrGLSLFragmentProcessor { | 15 class GrGLSimpleTextureEffect : public GrGLSLFragmentProcessor { |
15 public: | 16 public: |
16 void emitCode(EmitArgs& args) override { | 17 void emitCode(EmitArgs& args) override { |
| 18 const GrSimpleTextureEffect& textureEffect = args.fFp.cast<GrSimpleTextu
reEffect>(); |
| 19 GrGLSLColorSpaceXformHelper colorSpaceHelper(args.fUniformHandler, |
| 20 textureEffect.colorSpaceXfo
rm(), |
| 21 &fColorSpaceXformUni); |
| 22 |
17 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; | 23 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
18 fragBuilder->codeAppendf("%s = ", args.fOutputColor); | 24 fragBuilder->codeAppendf("%s = ", args.fOutputColor); |
19 fragBuilder->appendTextureLookupAndModulate(args.fInputColor, | 25 fragBuilder->appendTextureLookupAndModulate(args.fInputColor, |
20 args.fTexSamplers[0], | 26 args.fTexSamplers[0], |
21 args.fCoords[0].c_str(), | 27 args.fCoords[0].c_str(), |
22 args.fCoords[0].getType()); | 28 args.fCoords[0].getType(), |
| 29 &colorSpaceHelper); |
23 fragBuilder->codeAppend(";"); | 30 fragBuilder->codeAppend(";"); |
24 } | 31 } |
25 | 32 |
| 33 static inline void GenKey(const GrProcessor& effect, const GrGLSLCaps&, |
| 34 GrProcessorKeyBuilder* b) { |
| 35 const GrSimpleTextureEffect& textureEffect = effect.cast<GrSimpleTexture
Effect>(); |
| 36 b->add32(GrColorSpaceXform::XformKey(textureEffect.colorSpaceXform())); |
| 37 } |
| 38 |
| 39 protected: |
| 40 void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& pro
cessor) override { |
| 41 const GrSimpleTextureEffect& textureEffect = processor.cast<GrSimpleText
ureEffect>(); |
| 42 if (SkToBool(textureEffect.colorSpaceXform())) { |
| 43 pdman.setMatrix4f(fColorSpaceXformUni, textureEffect.colorSpaceXform
()->srcToDst()); |
| 44 } |
| 45 } |
| 46 |
26 private: | 47 private: |
27 typedef GrGLSLFragmentProcessor INHERITED; | 48 typedef GrGLSLFragmentProcessor INHERITED; |
| 49 |
| 50 UniformHandle fColorSpaceXformUni; |
28 }; | 51 }; |
29 | 52 |
30 /////////////////////////////////////////////////////////////////////////////// | 53 /////////////////////////////////////////////////////////////////////////////// |
31 | 54 |
32 void GrSimpleTextureEffect::onComputeInvariantOutput(GrInvariantOutput* inout) c
onst { | 55 void GrSimpleTextureEffect::onComputeInvariantOutput(GrInvariantOutput* inout) c
onst { |
33 this->updateInvariantOutputForModulation(inout); | 56 this->updateInvariantOutputForModulation(inout); |
34 } | 57 } |
35 | 58 |
36 void GrSimpleTextureEffect::onGetGLSLProcessorKey(const GrGLSLCaps& caps, | 59 void GrSimpleTextureEffect::onGetGLSLProcessorKey(const GrGLSLCaps& caps, |
37 GrProcessorKeyBuilder* b) cons
t { | 60 GrProcessorKeyBuilder* b) cons
t { |
(...skipping 25 matching lines...) Expand all Loading... |
63 | 86 |
64 static const GrCoordSet kCoordSets[] = { | 87 static const GrCoordSet kCoordSets[] = { |
65 kLocal_GrCoordSet, | 88 kLocal_GrCoordSet, |
66 kDevice_GrCoordSet | 89 kDevice_GrCoordSet |
67 }; | 90 }; |
68 GrCoordSet coordSet = kCoordSets[d->fRandom->nextULessThan(SK_ARRAY_COUNT(kC
oordSets))]; | 91 GrCoordSet coordSet = kCoordSets[d->fRandom->nextULessThan(SK_ARRAY_COUNT(kC
oordSets))]; |
69 | 92 |
70 const SkMatrix& matrix = GrTest::TestMatrix(d->fRandom); | 93 const SkMatrix& matrix = GrTest::TestMatrix(d->fRandom); |
71 return GrSimpleTextureEffect::Make(d->fTextures[texIdx], nullptr, matrix, co
ordSet); | 94 return GrSimpleTextureEffect::Make(d->fTextures[texIdx], nullptr, matrix, co
ordSet); |
72 } | 95 } |
OLD | NEW |