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 "GrConfigConversionEffect.h" | 8 #include "GrConfigConversionEffect.h" |
9 #include "GrContext.h" | 9 #include "GrContext.h" |
10 #include "GrDrawContext.h" | 10 #include "GrDrawContext.h" |
11 #include "GrInvariantOutput.h" | 11 #include "GrInvariantOutput.h" |
12 #include "GrSimpleTextureEffect.h" | 12 #include "GrSimpleTextureEffect.h" |
13 #include "SkMatrix.h" | 13 #include "SkMatrix.h" |
14 #include "gl/GrGLFragmentProcessor.h" | 14 #include "gl/GrGLFragmentProcessor.h" |
15 #include "gl/builders/GrGLProgramBuilder.h" | 15 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
| 16 #include "glsl/GrGLSLProgramBuilder.h" |
16 | 17 |
17 class GrGLConfigConversionEffect : public GrGLFragmentProcessor { | 18 class GrGLConfigConversionEffect : public GrGLFragmentProcessor { |
18 public: | 19 public: |
19 GrGLConfigConversionEffect(const GrProcessor& processor) { | 20 GrGLConfigConversionEffect(const GrProcessor& processor) { |
20 const GrConfigConversionEffect& configConversionEffect = | 21 const GrConfigConversionEffect& configConversionEffect = |
21 processor.cast<GrConfigConversionEffect>(); | 22 processor.cast<GrConfigConversionEffect>(); |
22 fSwapRedAndBlue = configConversionEffect.swapsRedAndBlue(); | 23 fSwapRedAndBlue = configConversionEffect.swapsRedAndBlue(); |
23 fPMConversion = configConversionEffect.pmConversion(); | 24 fPMConversion = configConversionEffect.pmConversion(); |
24 } | 25 } |
25 | 26 |
26 virtual void emitCode(EmitArgs& args) override { | 27 virtual void emitCode(EmitArgs& args) override { |
27 // Using highp for GLES here in order to avoid some precision issues on
specific GPUs. | 28 // Using highp for GLES here in order to avoid some precision issues on
specific GPUs. |
28 GrGLSLShaderVar tmpVar("tmpColor", kVec4f_GrSLType, 0, kHigh_GrSLPrecisi
on); | 29 GrGLSLShaderVar tmpVar("tmpColor", kVec4f_GrSLType, 0, kHigh_GrSLPrecisi
on); |
29 SkString tmpDecl; | 30 SkString tmpDecl; |
30 tmpVar.appendDecl(args.fBuilder->glslCaps(), &tmpDecl); | 31 tmpVar.appendDecl(args.fBuilder->glslCaps(), &tmpDecl); |
31 | 32 |
32 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder
(); | 33 GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuild
er(); |
33 | 34 |
34 fsBuilder->codeAppendf("%s;", tmpDecl.c_str()); | 35 fsBuilder->codeAppendf("%s;", tmpDecl.c_str()); |
35 | 36 |
36 fsBuilder->codeAppendf("%s = ", tmpVar.c_str()); | 37 fsBuilder->codeAppendf("%s = ", tmpVar.c_str()); |
37 fsBuilder->appendTextureLookup(args.fSamplers[0], args.fCoords[0].c_str(
), | 38 fsBuilder->appendTextureLookup(args.fSamplers[0], args.fCoords[0].c_str(
), |
38 args.fCoords[0].getType()); | 39 args.fCoords[0].getType()); |
39 fsBuilder->codeAppend(";"); | 40 fsBuilder->codeAppend(";"); |
40 | 41 |
41 if (GrConfigConversionEffect::kNone_PMConversion == fPMConversion) { | 42 if (GrConfigConversionEffect::kNone_PMConversion == fPMConversion) { |
42 SkASSERT(fSwapRedAndBlue); | 43 SkASSERT(fSwapRedAndBlue); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 } else { | 136 } else { |
136 swapRB = d->fRandom->nextBool(); | 137 swapRB = d->fRandom->nextBool(); |
137 } | 138 } |
138 return new GrConfigConversionEffect(d->fTextures[GrProcessorUnitTest::kSkiaP
MTextureIdx], | 139 return new GrConfigConversionEffect(d->fTextures[GrProcessorUnitTest::kSkiaP
MTextureIdx], |
139 swapRB, pmConv, GrTest::TestMatrix(d->fR
andom)); | 140 swapRB, pmConv, GrTest::TestMatrix(d->fR
andom)); |
140 } | 141 } |
141 | 142 |
142 /////////////////////////////////////////////////////////////////////////////// | 143 /////////////////////////////////////////////////////////////////////////////// |
143 | 144 |
144 void GrConfigConversionEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, | 145 void GrConfigConversionEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, |
145 GrProcessorKeyBuilder* b) const
{ | 146 GrProcessorKeyBuilder* b) con
st { |
146 GrGLConfigConversionEffect::GenKey(*this, caps, b); | 147 GrGLConfigConversionEffect::GenKey(*this, caps, b); |
147 } | 148 } |
148 | 149 |
149 GrGLFragmentProcessor* GrConfigConversionEffect::onCreateGLInstance() const { | 150 GrGLFragmentProcessor* GrConfigConversionEffect::onCreateGLInstance() const { |
150 return new GrGLConfigConversionEffect(*this); | 151 return new GrGLConfigConversionEffect(*this); |
151 } | 152 } |
152 | 153 |
153 | 154 |
154 | 155 |
155 void GrConfigConversionEffect::TestForPreservingPMConversions(GrContext* context
, | 156 void GrConfigConversionEffect::TestForPreservingPMConversions(GrContext* context
, |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 } else { | 298 } else { |
298 if (kRGBA_8888_GrPixelConfig != texture->config() && | 299 if (kRGBA_8888_GrPixelConfig != texture->config() && |
299 kBGRA_8888_GrPixelConfig != texture->config() && | 300 kBGRA_8888_GrPixelConfig != texture->config() && |
300 kNone_PMConversion != pmConversion) { | 301 kNone_PMConversion != pmConversion) { |
301 // The PM conversions assume colors are 0..255 | 302 // The PM conversions assume colors are 0..255 |
302 return nullptr; | 303 return nullptr; |
303 } | 304 } |
304 return new GrConfigConversionEffect(texture, swapRedAndBlue, pmConversio
n, matrix); | 305 return new GrConfigConversionEffect(texture, swapRedAndBlue, pmConversio
n, matrix); |
305 } | 306 } |
306 } | 307 } |
OLD | NEW |