OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "effects/GrCustomXfermode.h" | 8 #include "effects/GrCustomXfermode.h" |
9 | 9 |
10 #include "GrCoordTransform.h" | 10 #include "GrCoordTransform.h" |
11 #include "GrContext.h" | 11 #include "GrContext.h" |
12 #include "GrFragmentProcessor.h" | 12 #include "GrFragmentProcessor.h" |
13 #include "GrInvariantOutput.h" | 13 #include "GrInvariantOutput.h" |
14 #include "GrProcessor.h" | 14 #include "GrProcessor.h" |
15 #include "GrTexture.h" | 15 #include "GrTexture.h" |
16 #include "GrTextureAccess.h" | 16 #include "GrTextureAccess.h" |
17 #include "SkXfermode.h" | 17 #include "SkXfermode.h" |
18 #include "gl/GrGLCaps.h" | 18 #include "gl/GrGLCaps.h" |
19 #include "gl/GrGLGpu.h" | 19 #include "gl/GrGLGpu.h" |
20 #include "gl/GrGLSLBlend.h" | 20 #include "gl/GrGLSLBlend.h" |
21 #include "gl/GrGLFragmentProcessor.h" | 21 #include "gl/GrGLFragmentProcessor.h" |
22 #include "gl/GrGLProgramDataManager.h" | 22 #include "gl/GrGLProgramDataManager.h" |
23 #include "gl/builders/GrGLProgramBuilder.h" | |
24 #include "glsl/GrGLSLCaps.h" | 23 #include "glsl/GrGLSLCaps.h" |
| 24 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
| 25 #include "glsl/GrGLSLProgramBuilder.h" |
25 #include "glsl/GrGLSLProgramDataManager.h" | 26 #include "glsl/GrGLSLProgramDataManager.h" |
26 | 27 |
27 bool GrCustomXfermode::IsSupportedMode(SkXfermode::Mode mode) { | 28 bool GrCustomXfermode::IsSupportedMode(SkXfermode::Mode mode) { |
28 return mode > SkXfermode::kLastCoeffMode && mode <= SkXfermode::kLastMode; | 29 return mode > SkXfermode::kLastCoeffMode && mode <= SkXfermode::kLastMode; |
29 } | 30 } |
30 | 31 |
31 /////////////////////////////////////////////////////////////////////////////// | 32 /////////////////////////////////////////////////////////////////////////////// |
32 // Static helpers | 33 // Static helpers |
33 /////////////////////////////////////////////////////////////////////////////// | 34 /////////////////////////////////////////////////////////////////////////////// |
34 | 35 |
(...skipping 105 matching lines...) Loading... |
140 key |= xp.mode() << 3; | 141 key |= xp.mode() << 3; |
141 } | 142 } |
142 b->add32(key); | 143 b->add32(key); |
143 } | 144 } |
144 | 145 |
145 private: | 146 private: |
146 void emitOutputsForBlendState(const EmitArgs& args) override { | 147 void emitOutputsForBlendState(const EmitArgs& args) override { |
147 const CustomXP& xp = args.fXP.cast<CustomXP>(); | 148 const CustomXP& xp = args.fXP.cast<CustomXP>(); |
148 SkASSERT(xp.hasHWBlendEquation()); | 149 SkASSERT(xp.hasHWBlendEquation()); |
149 | 150 |
150 GrGLXPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 151 GrGLSLXPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(
); |
151 fsBuilder->enableAdvancedBlendEquationIfNeeded(xp.hwBlendEquation()); | 152 fsBuilder->enableAdvancedBlendEquationIfNeeded(xp.hwBlendEquation()); |
152 | 153 |
153 // Apply coverage by multiplying it into the src color before blending.
Mixed samples will | 154 // Apply coverage by multiplying it into the src color before blending.
Mixed samples will |
154 // "just work" automatically. (See onGetOptimizations()) | 155 // "just work" automatically. (See onGetOptimizations()) |
155 if (xp.readsCoverage()) { | 156 if (xp.readsCoverage()) { |
156 fsBuilder->codeAppendf("%s = %s * %s;", | 157 fsBuilder->codeAppendf("%s = %s * %s;", |
157 args.fOutputPrimary, args.fInputCoverage, arg
s.fInputColor); | 158 args.fOutputPrimary, args.fInputCoverage, arg
s.fInputColor); |
158 } else { | 159 } else { |
159 fsBuilder->codeAppendf("%s = %s;", args.fOutputPrimary, args.fInputC
olor); | 160 fsBuilder->codeAppendf("%s = %s;", args.fOutputPrimary, args.fInputC
olor); |
160 } | 161 } |
161 } | 162 } |
162 | 163 |
163 void emitBlendCodeForDstRead(GrGLSLXPBuilder* pb, const char* srcColor, cons
t char* dstColor, | 164 void emitBlendCodeForDstRead(GrGLSLXPBuilder* pb, const char* srcColor, cons
t char* dstColor, |
164 const char* outColor, const GrXferProcessor& pr
oc) override { | 165 const char* outColor, const GrXferProcessor& pr
oc) override { |
165 const CustomXP& xp = proc.cast<CustomXP>(); | 166 const CustomXP& xp = proc.cast<CustomXP>(); |
166 SkASSERT(!xp.hasHWBlendEquation()); | 167 SkASSERT(!xp.hasHWBlendEquation()); |
167 | 168 |
168 GrGLXPFragmentBuilder* fsBuilder = pb->getFragmentShaderBuilder(); | 169 GrGLSLXPFragmentBuilder* fsBuilder = pb->getFragmentShaderBuilder(); |
169 GrGLSLBlend::AppendMode(fsBuilder, srcColor, dstColor, outColor, xp.mode
()); | 170 GrGLSLBlend::AppendMode(fsBuilder, srcColor, dstColor, outColor, xp.mode
()); |
170 } | 171 } |
171 | 172 |
172 void onSetData(const GrGLSLProgramDataManager&, const GrXferProcessor&) over
ride {} | 173 void onSetData(const GrGLSLProgramDataManager&, const GrXferProcessor&) over
ride {} |
173 | 174 |
174 typedef GrGLXferProcessor INHERITED; | 175 typedef GrGLXferProcessor INHERITED; |
175 }; | 176 }; |
176 | 177 |
177 /////////////////////////////////////////////////////////////////////////////// | 178 /////////////////////////////////////////////////////////////////////////////// |
178 | 179 |
(...skipping 214 matching lines...) Loading... |
393 | 394 |
394 /////////////////////////////////////////////////////////////////////////////// | 395 /////////////////////////////////////////////////////////////////////////////// |
395 | 396 |
396 GrXPFactory* GrCustomXfermode::CreateXPFactory(SkXfermode::Mode mode) { | 397 GrXPFactory* GrCustomXfermode::CreateXPFactory(SkXfermode::Mode mode) { |
397 if (!GrCustomXfermode::IsSupportedMode(mode)) { | 398 if (!GrCustomXfermode::IsSupportedMode(mode)) { |
398 return nullptr; | 399 return nullptr; |
399 } else { | 400 } else { |
400 return new CustomXPFactory(mode); | 401 return new CustomXPFactory(mode); |
401 } | 402 } |
402 } | 403 } |
OLD | NEW |