| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 | 79 |
| 80 add_arithmetic_code(fsBuilder, inputColor, dstColor, outputColor, kUni,
fEnforcePMColor); | 80 add_arithmetic_code(fsBuilder, inputColor, dstColor, outputColor, kUni,
fEnforcePMColor); |
| 81 } | 81 } |
| 82 | 82 |
| 83 void setData(const GrGLProgramDataManager& pdman, const GrProcessor& proc) o
verride { | 83 void setData(const GrGLProgramDataManager& pdman, const GrProcessor& proc) o
verride { |
| 84 const GrArithmeticFP& arith = proc.cast<GrArithmeticFP>(); | 84 const GrArithmeticFP& arith = proc.cast<GrArithmeticFP>(); |
| 85 pdman.set4f(fKUni, arith.k1(), arith.k2(), arith.k3(), arith.k4()); | 85 pdman.set4f(fKUni, arith.k1(), arith.k2(), arith.k3(), arith.k4()); |
| 86 fEnforcePMColor = arith.enforcePMColor(); | 86 fEnforcePMColor = arith.enforcePMColor(); |
| 87 } | 87 } |
| 88 | 88 |
| 89 static void GenKey(const GrProcessor& proc, const GrGLCaps& caps, GrProcesso
rKeyBuilder* b) { | 89 static void GenKey(const GrProcessor& proc, const GrGLSLCaps& caps, GrProces
sorKeyBuilder* b) { |
| 90 const GrArithmeticFP& arith = proc.cast<GrArithmeticFP>(); | 90 const GrArithmeticFP& arith = proc.cast<GrArithmeticFP>(); |
| 91 uint32_t key = arith.enforcePMColor() ? 1 : 0; | 91 uint32_t key = arith.enforcePMColor() ? 1 : 0; |
| 92 b->add32(key); | 92 b->add32(key); |
| 93 } | 93 } |
| 94 | 94 |
| 95 private: | 95 private: |
| 96 GrGLProgramDataManager::UniformHandle fKUni; | 96 GrGLProgramDataManager::UniformHandle fKUni; |
| 97 bool fEnforcePMColor; | 97 bool fEnforcePMColor; |
| 98 | 98 |
| 99 typedef GrGLFragmentProcessor INHERITED; | 99 typedef GrGLFragmentProcessor INHERITED; |
| 100 }; | 100 }; |
| 101 | 101 |
| 102 /////////////////////////////////////////////////////////////////////////////// | 102 /////////////////////////////////////////////////////////////////////////////// |
| 103 | 103 |
| 104 GrArithmeticFP::GrArithmeticFP(float k1, float k2, float k3, float k4, | 104 GrArithmeticFP::GrArithmeticFP(float k1, float k2, float k3, float k4, |
| 105 bool enforcePMColor, GrTexture* background) | 105 bool enforcePMColor, GrTexture* background) |
| 106 : fK1(k1), fK2(k2), fK3(k3), fK4(k4), fEnforcePMColor(enforcePMColor) { | 106 : fK1(k1), fK2(k2), fK3(k3), fK4(k4), fEnforcePMColor(enforcePMColor) { |
| 107 this->initClassID<GrArithmeticFP>(); | 107 this->initClassID<GrArithmeticFP>(); |
| 108 | 108 |
| 109 SkASSERT(background); | 109 SkASSERT(background); |
| 110 | 110 |
| 111 fBackgroundTransform.reset(kLocal_GrCoordSet, background, | 111 fBackgroundTransform.reset(kLocal_GrCoordSet, background, |
| 112 GrTextureParams::kNone_FilterMode); | 112 GrTextureParams::kNone_FilterMode); |
| 113 this->addCoordTransform(&fBackgroundTransform); | 113 this->addCoordTransform(&fBackgroundTransform); |
| 114 fBackgroundAccess.reset(background); | 114 fBackgroundAccess.reset(background); |
| 115 this->addTextureAccess(&fBackgroundAccess); | 115 this->addTextureAccess(&fBackgroundAccess); |
| 116 } | 116 } |
| 117 | 117 |
| 118 void GrArithmeticFP::getGLProcessorKey(const GrGLCaps& caps, GrProcessorKeyBuild
er* b) const { | 118 void GrArithmeticFP::getGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBui
lder* b) const { |
| 119 GLArithmeticFP::GenKey(*this, caps, b); | 119 GLArithmeticFP::GenKey(*this, caps, b); |
| 120 } | 120 } |
| 121 | 121 |
| 122 GrGLFragmentProcessor* GrArithmeticFP::createGLInstance() const { | 122 GrGLFragmentProcessor* GrArithmeticFP::createGLInstance() const { |
| 123 return SkNEW_ARGS(GLArithmeticFP, (*this)); | 123 return SkNEW_ARGS(GLArithmeticFP, (*this)); |
| 124 } | 124 } |
| 125 | 125 |
| 126 bool GrArithmeticFP::onIsEqual(const GrFragmentProcessor& fpBase) const { | 126 bool GrArithmeticFP::onIsEqual(const GrFragmentProcessor& fpBase) const { |
| 127 const GrArithmeticFP& fp = fpBase.cast<GrArithmeticFP>(); | 127 const GrArithmeticFP& fp = fpBase.cast<GrArithmeticFP>(); |
| 128 return fK1 == fp.fK1 && | 128 return fK1 == fp.fK1 && |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 float k1() const { return fK1; } | 184 float k1() const { return fK1; } |
| 185 float k2() const { return fK2; } | 185 float k2() const { return fK2; } |
| 186 float k3() const { return fK3; } | 186 float k3() const { return fK3; } |
| 187 float k4() const { return fK4; } | 187 float k4() const { return fK4; } |
| 188 bool enforcePMColor() const { return fEnforcePMColor; } | 188 bool enforcePMColor() const { return fEnforcePMColor; } |
| 189 | 189 |
| 190 private: | 190 private: |
| 191 ArithmeticXP(float k1, float k2, float k3, float k4, bool enforcePMColor, | 191 ArithmeticXP(float k1, float k2, float k3, float k4, bool enforcePMColor, |
| 192 const GrDeviceCoordTexture* dstCopy, bool willReadDstColor); | 192 const GrDeviceCoordTexture* dstCopy, bool willReadDstColor); |
| 193 | 193 |
| 194 void onGetGLProcessorKey(const GrGLCaps& caps, GrProcessorKeyBuilder* b) con
st override; | 194 void onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) c
onst override; |
| 195 | 195 |
| 196 bool onIsEqual(const GrXferProcessor& xpBase) const override { | 196 bool onIsEqual(const GrXferProcessor& xpBase) const override { |
| 197 const ArithmeticXP& xp = xpBase.cast<ArithmeticXP>(); | 197 const ArithmeticXP& xp = xpBase.cast<ArithmeticXP>(); |
| 198 if (fK1 != xp.fK1 || | 198 if (fK1 != xp.fK1 || |
| 199 fK2 != xp.fK2 || | 199 fK2 != xp.fK2 || |
| 200 fK3 != xp.fK3 || | 200 fK3 != xp.fK3 || |
| 201 fK4 != xp.fK4 || | 201 fK4 != xp.fK4 || |
| 202 fEnforcePMColor != xp.fEnforcePMColor) { | 202 fEnforcePMColor != xp.fEnforcePMColor) { |
| 203 return false; | 203 return false; |
| 204 } | 204 } |
| 205 return true; | 205 return true; |
| 206 } | 206 } |
| 207 | 207 |
| 208 float fK1, fK2, fK3, fK4; | 208 float fK1, fK2, fK3, fK4; |
| 209 bool fEnforcePMColor; | 209 bool fEnforcePMColor; |
| 210 | 210 |
| 211 typedef GrXferProcessor INHERITED; | 211 typedef GrXferProcessor INHERITED; |
| 212 }; | 212 }; |
| 213 | 213 |
| 214 /////////////////////////////////////////////////////////////////////////////// | 214 /////////////////////////////////////////////////////////////////////////////// |
| 215 | 215 |
| 216 class GLArithmeticXP : public GrGLXferProcessor { | 216 class GLArithmeticXP : public GrGLXferProcessor { |
| 217 public: | 217 public: |
| 218 GLArithmeticXP(const GrProcessor&) | 218 GLArithmeticXP(const GrProcessor&) |
| 219 : fEnforcePMColor(true) { | 219 : fEnforcePMColor(true) { |
| 220 } | 220 } |
| 221 | 221 |
| 222 ~GLArithmeticXP() override {} | 222 ~GLArithmeticXP() override {} |
| 223 | 223 |
| 224 static void GenKey(const GrProcessor& processor, const GrGLCaps& caps, | 224 static void GenKey(const GrProcessor& processor, const GrGLSLCaps& caps, |
| 225 GrProcessorKeyBuilder* b) { | 225 GrProcessorKeyBuilder* b) { |
| 226 const ArithmeticXP& arith = processor.cast<ArithmeticXP>(); | 226 const ArithmeticXP& arith = processor.cast<ArithmeticXP>(); |
| 227 uint32_t key = arith.enforcePMColor() ? 1 : 0; | 227 uint32_t key = arith.enforcePMColor() ? 1 : 0; |
| 228 b->add32(key); | 228 b->add32(key); |
| 229 } | 229 } |
| 230 | 230 |
| 231 private: | 231 private: |
| 232 void onEmitCode(const EmitArgs& args) override { | 232 void onEmitCode(const EmitArgs& args) override { |
| 233 GrGLFPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 233 GrGLFPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
| 234 | 234 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 const GrDeviceCoordTexture* dstCopy, bool willReadDst
Color) | 266 const GrDeviceCoordTexture* dstCopy, bool willReadDst
Color) |
| 267 : INHERITED(dstCopy, willReadDstColor) | 267 : INHERITED(dstCopy, willReadDstColor) |
| 268 , fK1(k1) | 268 , fK1(k1) |
| 269 , fK2(k2) | 269 , fK2(k2) |
| 270 , fK3(k3) | 270 , fK3(k3) |
| 271 , fK4(k4) | 271 , fK4(k4) |
| 272 , fEnforcePMColor(enforcePMColor) { | 272 , fEnforcePMColor(enforcePMColor) { |
| 273 this->initClassID<ArithmeticXP>(); | 273 this->initClassID<ArithmeticXP>(); |
| 274 } | 274 } |
| 275 | 275 |
| 276 void ArithmeticXP::onGetGLProcessorKey(const GrGLCaps& caps, GrProcessorKeyBuild
er* b) const { | 276 void ArithmeticXP::onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBui
lder* b) const { |
| 277 GLArithmeticXP::GenKey(*this, caps, b); | 277 GLArithmeticXP::GenKey(*this, caps, b); |
| 278 } | 278 } |
| 279 | 279 |
| 280 GrGLXferProcessor* ArithmeticXP::createGLInstance() const { | 280 GrGLXferProcessor* ArithmeticXP::createGLInstance() const { |
| 281 return SkNEW_ARGS(GLArithmeticXP, (*this)); | 281 return SkNEW_ARGS(GLArithmeticXP, (*this)); |
| 282 } | 282 } |
| 283 | 283 |
| 284 GrXferProcessor::OptFlags ArithmeticXP::getOptimizations(const GrProcOptInfo& co
lorPOI, | 284 GrXferProcessor::OptFlags ArithmeticXP::getOptimizations(const GrProcOptInfo& co
lorPOI, |
| 285 const GrProcOptInfo& co
veragePOI, | 285 const GrProcOptInfo& co
veragePOI, |
| 286 bool doesStencilWrite, | 286 bool doesStencilWrite, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 float k1 = random->nextF(); | 327 float k1 = random->nextF(); |
| 328 float k2 = random->nextF(); | 328 float k2 = random->nextF(); |
| 329 float k3 = random->nextF(); | 329 float k3 = random->nextF(); |
| 330 float k4 = random->nextF(); | 330 float k4 = random->nextF(); |
| 331 bool enforcePMColor = random->nextBool(); | 331 bool enforcePMColor = random->nextBool(); |
| 332 | 332 |
| 333 return GrArithmeticXPFactory::Create(k1, k2, k3, k4, enforcePMColor); | 333 return GrArithmeticXPFactory::Create(k1, k2, k3, k4, enforcePMColor); |
| 334 } | 334 } |
| 335 | 335 |
| 336 #endif | 336 #endif |
| OLD | NEW |