| 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 |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 /////////////////////////////////////////////////////////////////////////////// | 159 /////////////////////////////////////////////////////////////////////////////// |
| 160 | 160 |
| 161 class GLArithmeticXP : public GrGLXferProcessor { | 161 class GLArithmeticXP : public GrGLXferProcessor { |
| 162 public: | 162 public: |
| 163 GLArithmeticXP(const GrProcessor&) | 163 GLArithmeticXP(const GrProcessor&) |
| 164 : fEnforcePMColor(true) { | 164 : fEnforcePMColor(true) { |
| 165 } | 165 } |
| 166 | 166 |
| 167 ~GLArithmeticXP() SK_OVERRIDE {} | 167 ~GLArithmeticXP() SK_OVERRIDE {} |
| 168 | 168 |
| 169 void emitCode(const EmitArgs& args) SK_OVERRIDE { | |
| 170 GrGLFPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | |
| 171 | |
| 172 const char* dstColor = fsBuilder->dstColor(); | |
| 173 | |
| 174 fKUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Visibility, | |
| 175 kVec4f_GrSLType, kDefault_GrSLPrecision, | |
| 176 "k"); | |
| 177 const char* kUni = args.fPB->getUniformCStr(fKUni); | |
| 178 | |
| 179 add_arithmetic_code(fsBuilder, args.fInputColor, dstColor, args.fOutputP
rimary, kUni, | |
| 180 fEnforcePMColor); | |
| 181 | |
| 182 fsBuilder->codeAppendf("%s = %s * %s + (vec4(1.0) - %s) * %s;", | |
| 183 args.fOutputPrimary, args.fOutputPrimary, args.fI
nputCoverage, | |
| 184 args.fInputCoverage, dstColor); | |
| 185 } | |
| 186 | |
| 187 void setData(const GrGLProgramDataManager& pdman, | |
| 188 const GrXferProcessor& processor) SK_OVERRIDE { | |
| 189 const GrArithmeticXP& arith = processor.cast<GrArithmeticXP>(); | |
| 190 pdman.set4f(fKUni, arith.k1(), arith.k2(), arith.k3(), arith.k4()); | |
| 191 fEnforcePMColor = arith.enforcePMColor(); | |
| 192 }; | |
| 193 | |
| 194 static void GenKey(const GrProcessor& processor, const GrGLCaps& caps, | 169 static void GenKey(const GrProcessor& processor, const GrGLCaps& caps, |
| 195 GrProcessorKeyBuilder* b) { | 170 GrProcessorKeyBuilder* b) { |
| 196 const GrArithmeticXP& arith = processor.cast<GrArithmeticXP>(); | 171 const GrArithmeticXP& arith = processor.cast<GrArithmeticXP>(); |
| 197 uint32_t key = arith.enforcePMColor() ? 1 : 0; | 172 uint32_t key = arith.enforcePMColor() ? 1 : 0; |
| 198 b->add32(key); | 173 b->add32(key); |
| 199 } | 174 } |
| 200 | 175 |
| 201 private: | 176 private: |
| 177 void onEmitCode(const EmitArgs& args) SK_OVERRIDE { |
| 178 GrGLFPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
| 179 |
| 180 const char* dstColor = fsBuilder->dstColor(); |
| 181 |
| 182 fKUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Visibility, |
| 183 kVec4f_GrSLType, kDefault_GrSLPrecision, |
| 184 "k"); |
| 185 const char* kUni = args.fPB->getUniformCStr(fKUni); |
| 186 |
| 187 add_arithmetic_code(fsBuilder, args.fInputColor, dstColor, args.fOutputP
rimary, kUni, |
| 188 fEnforcePMColor); |
| 189 |
| 190 fsBuilder->codeAppendf("%s = %s * %s + (vec4(1.0) - %s) * %s;", |
| 191 args.fOutputPrimary, args.fOutputPrimary, args.fI
nputCoverage, |
| 192 args.fInputCoverage, dstColor); |
| 193 } |
| 194 |
| 195 void onSetData(const GrGLProgramDataManager& pdman, |
| 196 const GrXferProcessor& processor) SK_OVERRIDE { |
| 197 const GrArithmeticXP& arith = processor.cast<GrArithmeticXP>(); |
| 198 pdman.set4f(fKUni, arith.k1(), arith.k2(), arith.k3(), arith.k4()); |
| 199 fEnforcePMColor = arith.enforcePMColor(); |
| 200 }; |
| 201 |
| 202 GrGLProgramDataManager::UniformHandle fKUni; | 202 GrGLProgramDataManager::UniformHandle fKUni; |
| 203 bool fEnforcePMColor; | 203 bool fEnforcePMColor; |
| 204 | 204 |
| 205 typedef GrGLXferProcessor INHERITED; | 205 typedef GrGLXferProcessor INHERITED; |
| 206 }; | 206 }; |
| 207 | 207 |
| 208 /////////////////////////////////////////////////////////////////////////////// | 208 /////////////////////////////////////////////////////////////////////////////// |
| 209 | 209 |
| 210 GrArithmeticXP::GrArithmeticXP(float k1, float k2, float k3, float k4, bool enfo
rcePMColor) | 210 GrArithmeticXP::GrArithmeticXP(float k1, float k2, float k3, float k4, bool enfo
rcePMColor, |
| 211 : fK1(k1) | 211 const GrDeviceCoordTexture* dstCopy, bool willRea
dDstColor) |
| 212 : INHERITED(dstCopy, willReadDstColor) |
| 213 , fK1(k1) |
| 212 , fK2(k2) | 214 , fK2(k2) |
| 213 , fK3(k3) | 215 , fK3(k3) |
| 214 , fK4(k4) | 216 , fK4(k4) |
| 215 , fEnforcePMColor(enforcePMColor) { | 217 , fEnforcePMColor(enforcePMColor) { |
| 216 this->initClassID<GrPorterDuffXferProcessor>(); | 218 this->initClassID<GrPorterDuffXferProcessor>(); |
| 217 this->setWillReadDstColor(); | |
| 218 } | 219 } |
| 219 | 220 |
| 220 void GrArithmeticXP::getGLProcessorKey(const GrGLCaps& caps, GrProcessorKeyBuild
er* b) const { | 221 void GrArithmeticXP::onGetGLProcessorKey(const GrGLCaps& caps, GrProcessorKeyBui
lder* b) const { |
| 221 GLArithmeticXP::GenKey(*this, caps, b); | 222 GLArithmeticXP::GenKey(*this, caps, b); |
| 222 } | 223 } |
| 223 | 224 |
| 224 GrGLXferProcessor* GrArithmeticXP::createGLInstance() const { | 225 GrGLXferProcessor* GrArithmeticXP::createGLInstance() const { |
| 225 return SkNEW_ARGS(GLArithmeticXP, (*this)); | 226 return SkNEW_ARGS(GLArithmeticXP, (*this)); |
| 226 } | 227 } |
| 227 | 228 |
| 228 GrXferProcessor::OptFlags GrArithmeticXP::getOptimizations(const GrProcOptInfo&
colorPOI, | 229 GrXferProcessor::OptFlags GrArithmeticXP::getOptimizations(const GrProcOptInfo&
colorPOI, |
| 229 const GrProcOptInfo&
coveragePOI, | 230 const GrProcOptInfo&
coveragePOI, |
| 230 bool doesStencilWrite
, | 231 bool doesStencilWrite
, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 261 float k1 = random->nextF(); | 262 float k1 = random->nextF(); |
| 262 float k2 = random->nextF(); | 263 float k2 = random->nextF(); |
| 263 float k3 = random->nextF(); | 264 float k3 = random->nextF(); |
| 264 float k4 = random->nextF(); | 265 float k4 = random->nextF(); |
| 265 bool enforcePMColor = random->nextBool(); | 266 bool enforcePMColor = random->nextBool(); |
| 266 | 267 |
| 267 return GrArithmeticXPFactory::Create(k1, k2, k3, k4, enforcePMColor); | 268 return GrArithmeticXPFactory::Create(k1, k2, k3, k4, enforcePMColor); |
| 268 } | 269 } |
| 269 | 270 |
| 270 #endif | 271 #endif |
| OLD | NEW |