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 "SkArithmeticMode_gpu.h" | 8 #include "SkArithmeticMode_gpu.h" |
9 | 9 |
10 #if SK_SUPPORT_GPU | 10 #if SK_SUPPORT_GPU |
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 "gl/GrGLXferProcessor.h" | |
17 #include "glsl/GrGLSLFragmentProcessor.h" | 16 #include "glsl/GrGLSLFragmentProcessor.h" |
18 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 17 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
19 #include "glsl/GrGLSLProgramBuilder.h" | 18 #include "glsl/GrGLSLProgramBuilder.h" |
20 #include "glsl/GrGLSLProgramDataManager.h" | 19 #include "glsl/GrGLSLProgramDataManager.h" |
| 20 #include "glsl/GrGLSLXferProcessor.h" |
21 | 21 |
22 static const bool gUseUnpremul = false; | 22 static const bool gUseUnpremul = false; |
23 | 23 |
24 static void add_arithmetic_code(GrGLSLFragmentBuilder* fsBuilder, | 24 static void add_arithmetic_code(GrGLSLFragmentBuilder* fsBuilder, |
25 const char* srcColor, | 25 const char* srcColor, |
26 const char* dstColor, | 26 const char* dstColor, |
27 const char* outputColor, | 27 const char* outputColor, |
28 const char* kUni, | 28 const char* kUni, |
29 bool enforcePMColor) { | 29 bool enforcePMColor) { |
30 // We don't try to optimize for this case at all | 30 // We don't try to optimize for this case at all |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 // Xfer Processor | 147 // Xfer Processor |
148 /////////////////////////////////////////////////////////////////////////////// | 148 /////////////////////////////////////////////////////////////////////////////// |
149 | 149 |
150 class ArithmeticXP : public GrXferProcessor { | 150 class ArithmeticXP : public GrXferProcessor { |
151 public: | 151 public: |
152 ArithmeticXP(const DstTexture*, bool hasMixedSamples, | 152 ArithmeticXP(const DstTexture*, bool hasMixedSamples, |
153 float k1, float k2, float k3, float k4, bool enforcePMColor); | 153 float k1, float k2, float k3, float k4, bool enforcePMColor); |
154 | 154 |
155 const char* name() const override { return "Arithmetic"; } | 155 const char* name() const override { return "Arithmetic"; } |
156 | 156 |
157 GrGLXferProcessor* createGLInstance() const override; | 157 GrGLSLXferProcessor* createGLInstance() const override; |
158 | 158 |
159 float k1() const { return fK1; } | 159 float k1() const { return fK1; } |
160 float k2() const { return fK2; } | 160 float k2() const { return fK2; } |
161 float k3() const { return fK3; } | 161 float k3() const { return fK3; } |
162 float k4() const { return fK4; } | 162 float k4() const { return fK4; } |
163 bool enforcePMColor() const { return fEnforcePMColor; } | 163 bool enforcePMColor() const { return fEnforcePMColor; } |
164 | 164 |
165 private: | 165 private: |
166 GrXferProcessor::OptFlags onGetOptimizations(const GrProcOptInfo& colorPOI, | 166 GrXferProcessor::OptFlags onGetOptimizations(const GrProcOptInfo& colorPOI, |
167 const GrProcOptInfo& coveragePO
I, | 167 const GrProcOptInfo& coveragePO
I, |
(...skipping 16 matching lines...) Expand all Loading... |
184 } | 184 } |
185 | 185 |
186 float fK1, fK2, fK3, fK4; | 186 float fK1, fK2, fK3, fK4; |
187 bool fEnforcePMColor; | 187 bool fEnforcePMColor; |
188 | 188 |
189 typedef GrXferProcessor INHERITED; | 189 typedef GrXferProcessor INHERITED; |
190 }; | 190 }; |
191 | 191 |
192 /////////////////////////////////////////////////////////////////////////////// | 192 /////////////////////////////////////////////////////////////////////////////// |
193 | 193 |
194 class GLArithmeticXP : public GrGLXferProcessor { | 194 class GLArithmeticXP : public GrGLSLXferProcessor { |
195 public: | 195 public: |
196 GLArithmeticXP(const ArithmeticXP& arithmeticXP) | 196 GLArithmeticXP(const ArithmeticXP& arithmeticXP) |
197 : fEnforcePMColor(arithmeticXP.enforcePMColor()) { | 197 : fEnforcePMColor(arithmeticXP.enforcePMColor()) { |
198 } | 198 } |
199 | 199 |
200 ~GLArithmeticXP() override {} | 200 ~GLArithmeticXP() override {} |
201 | 201 |
202 static void GenKey(const GrProcessor& processor, const GrGLSLCaps& caps, | 202 static void GenKey(const GrProcessor& processor, const GrGLSLCaps& caps, |
203 GrProcessorKeyBuilder* b) { | 203 GrProcessorKeyBuilder* b) { |
204 const ArithmeticXP& arith = processor.cast<ArithmeticXP>(); | 204 const ArithmeticXP& arith = processor.cast<ArithmeticXP>(); |
(...skipping 17 matching lines...) Expand all Loading... |
222 void onSetData(const GrGLSLProgramDataManager& pdman, | 222 void onSetData(const GrGLSLProgramDataManager& pdman, |
223 const GrXferProcessor& processor) override { | 223 const GrXferProcessor& processor) override { |
224 const ArithmeticXP& arith = processor.cast<ArithmeticXP>(); | 224 const ArithmeticXP& arith = processor.cast<ArithmeticXP>(); |
225 pdman.set4f(fKUni, arith.k1(), arith.k2(), arith.k3(), arith.k4()); | 225 pdman.set4f(fKUni, arith.k1(), arith.k2(), arith.k3(), arith.k4()); |
226 fEnforcePMColor = arith.enforcePMColor(); | 226 fEnforcePMColor = arith.enforcePMColor(); |
227 }; | 227 }; |
228 | 228 |
229 GrGLSLProgramDataManager::UniformHandle fKUni; | 229 GrGLSLProgramDataManager::UniformHandle fKUni; |
230 bool fEnforcePMColor; | 230 bool fEnforcePMColor; |
231 | 231 |
232 typedef GrGLXferProcessor INHERITED; | 232 typedef GrGLSLXferProcessor INHERITED; |
233 }; | 233 }; |
234 | 234 |
235 /////////////////////////////////////////////////////////////////////////////// | 235 /////////////////////////////////////////////////////////////////////////////// |
236 | 236 |
237 ArithmeticXP::ArithmeticXP(const DstTexture* dstTexture, bool hasMixedSamples, | 237 ArithmeticXP::ArithmeticXP(const DstTexture* dstTexture, bool hasMixedSamples, |
238 float k1, float k2, float k3, float k4, bool enforceP
MColor) | 238 float k1, float k2, float k3, float k4, bool enforceP
MColor) |
239 : INHERITED(dstTexture, true, hasMixedSamples) | 239 : INHERITED(dstTexture, true, hasMixedSamples) |
240 , fK1(k1) | 240 , fK1(k1) |
241 , fK2(k2) | 241 , fK2(k2) |
242 , fK3(k3) | 242 , fK3(k3) |
243 , fK4(k4) | 243 , fK4(k4) |
244 , fEnforcePMColor(enforcePMColor) { | 244 , fEnforcePMColor(enforcePMColor) { |
245 this->initClassID<ArithmeticXP>(); | 245 this->initClassID<ArithmeticXP>(); |
246 } | 246 } |
247 | 247 |
248 void ArithmeticXP::onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBui
lder* b) const { | 248 void ArithmeticXP::onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBui
lder* b) const { |
249 GLArithmeticXP::GenKey(*this, caps, b); | 249 GLArithmeticXP::GenKey(*this, caps, b); |
250 } | 250 } |
251 | 251 |
252 GrGLXferProcessor* ArithmeticXP::createGLInstance() const { return new GLArithme
ticXP(*this); } | 252 GrGLSLXferProcessor* ArithmeticXP::createGLInstance() const { return new GLArith
meticXP(*this); } |
253 | 253 |
254 GrXferProcessor::OptFlags ArithmeticXP::onGetOptimizations(const GrProcOptInfo&
colorPOI, | 254 GrXferProcessor::OptFlags ArithmeticXP::onGetOptimizations(const GrProcOptInfo&
colorPOI, |
255 const GrProcOptInfo&
coveragePOI, | 255 const GrProcOptInfo&
coveragePOI, |
256 bool doesStencilWrite
, | 256 bool doesStencilWrite
, |
257 GrColor* overrideColo
r, | 257 GrColor* overrideColo
r, |
258 const GrCaps& caps) { | 258 const GrCaps& caps) { |
259 return GrXferProcessor::kNone_OptFlags; | 259 return GrXferProcessor::kNone_OptFlags; |
260 } | 260 } |
261 | 261 |
262 /////////////////////////////////////////////////////////////////////////////// | 262 /////////////////////////////////////////////////////////////////////////////// |
(...skipping 30 matching lines...) Expand all Loading... |
293 float k1 = d->fRandom->nextF(); | 293 float k1 = d->fRandom->nextF(); |
294 float k2 = d->fRandom->nextF(); | 294 float k2 = d->fRandom->nextF(); |
295 float k3 = d->fRandom->nextF(); | 295 float k3 = d->fRandom->nextF(); |
296 float k4 = d->fRandom->nextF(); | 296 float k4 = d->fRandom->nextF(); |
297 bool enforcePMColor = d->fRandom->nextBool(); | 297 bool enforcePMColor = d->fRandom->nextBool(); |
298 | 298 |
299 return GrArithmeticXPFactory::Create(k1, k2, k3, k4, enforcePMColor); | 299 return GrArithmeticXPFactory::Create(k1, k2, k3, k4, enforcePMColor); |
300 } | 300 } |
301 | 301 |
302 #endif | 302 #endif |
OLD | NEW |