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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 | 70 |
71 fKUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibili
ty, | 71 fKUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibili
ty, |
72 kVec4f_GrSLType, kDefault_GrSLPrecision, | 72 kVec4f_GrSLType, kDefault_GrSLPrecision, |
73 "k"); | 73 "k"); |
74 const char* kUni = args.fBuilder->getUniformCStr(fKUni); | 74 const char* kUni = args.fBuilder->getUniformCStr(fKUni); |
75 | 75 |
76 add_arithmetic_code(fsBuilder, args.fInputColor, dstColor, args.fOutputC
olor, kUni, | 76 add_arithmetic_code(fsBuilder, args.fInputColor, dstColor, args.fOutputC
olor, kUni, |
77 fEnforcePMColor); | 77 fEnforcePMColor); |
78 } | 78 } |
79 | 79 |
80 void setData(const GrGLProgramDataManager& pdman, const GrProcessor& proc) o
verride { | |
81 const GrArithmeticFP& arith = proc.cast<GrArithmeticFP>(); | |
82 pdman.set4f(fKUni, arith.k1(), arith.k2(), arith.k3(), arith.k4()); | |
83 fEnforcePMColor = arith.enforcePMColor(); | |
84 } | |
85 | |
86 static void GenKey(const GrProcessor& proc, const GrGLSLCaps& caps, GrProces
sorKeyBuilder* b) { | 80 static void GenKey(const GrProcessor& proc, const GrGLSLCaps& caps, GrProces
sorKeyBuilder* b) { |
87 const GrArithmeticFP& arith = proc.cast<GrArithmeticFP>(); | 81 const GrArithmeticFP& arith = proc.cast<GrArithmeticFP>(); |
88 uint32_t key = arith.enforcePMColor() ? 1 : 0; | 82 uint32_t key = arith.enforcePMColor() ? 1 : 0; |
89 b->add32(key); | 83 b->add32(key); |
90 } | 84 } |
91 | 85 |
| 86 protected: |
| 87 void onSetData(const GrGLProgramDataManager& pdman, const GrProcessor& proc)
override { |
| 88 const GrArithmeticFP& arith = proc.cast<GrArithmeticFP>(); |
| 89 pdman.set4f(fKUni, arith.k1(), arith.k2(), arith.k3(), arith.k4()); |
| 90 fEnforcePMColor = arith.enforcePMColor(); |
| 91 } |
| 92 |
92 private: | 93 private: |
93 GrGLProgramDataManager::UniformHandle fKUni; | 94 GrGLProgramDataManager::UniformHandle fKUni; |
94 bool fEnforcePMColor; | 95 bool fEnforcePMColor; |
95 | 96 |
96 typedef GrGLFragmentProcessor INHERITED; | 97 typedef GrGLFragmentProcessor INHERITED; |
97 }; | 98 }; |
98 | 99 |
99 /////////////////////////////////////////////////////////////////////////////// | 100 /////////////////////////////////////////////////////////////////////////////// |
100 | 101 |
101 GrArithmeticFP::GrArithmeticFP(GrProcessorDataManager*, float k1, float k2, floa
t k3, float k4, | 102 GrArithmeticFP::GrArithmeticFP(GrProcessorDataManager*, float k1, float k2, floa
t k3, float k4, |
102 bool enforcePMColor, GrTexture* background) | 103 bool enforcePMColor, GrTexture* background) |
103 : fK1(k1), fK2(k2), fK3(k3), fK4(k4), fEnforcePMColor(enforcePMColor) { | 104 : fK1(k1), fK2(k2), fK3(k3), fK4(k4), fEnforcePMColor(enforcePMColor) { |
104 this->initClassID<GrArithmeticFP>(); | 105 this->initClassID<GrArithmeticFP>(); |
105 | 106 |
106 SkASSERT(background); | 107 SkASSERT(background); |
107 | 108 |
108 fBackgroundTransform.reset(kLocal_GrCoordSet, background, | 109 fBackgroundTransform.reset(kLocal_GrCoordSet, background, |
109 GrTextureParams::kNone_FilterMode); | 110 GrTextureParams::kNone_FilterMode); |
110 this->addCoordTransform(&fBackgroundTransform); | 111 this->addCoordTransform(&fBackgroundTransform); |
111 fBackgroundAccess.reset(background); | 112 fBackgroundAccess.reset(background); |
112 this->addTextureAccess(&fBackgroundAccess); | 113 this->addTextureAccess(&fBackgroundAccess); |
113 } | 114 } |
114 | 115 |
115 void GrArithmeticFP::onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyB
uilder* b) const { | 116 void GrArithmeticFP::onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyB
uilder* b) const { |
116 GLArithmeticFP::GenKey(*this, caps, b); | 117 GLArithmeticFP::GenKey(*this, caps, b); |
117 } | 118 } |
118 | 119 |
119 GrGLFragmentProcessor* GrArithmeticFP::createGLInstance() const { | 120 GrGLFragmentProcessor* GrArithmeticFP::onCreateGLInstance() const { |
120 return SkNEW_ARGS(GLArithmeticFP, (*this)); | 121 return SkNEW_ARGS(GLArithmeticFP, (*this)); |
121 } | 122 } |
122 | 123 |
123 bool GrArithmeticFP::onIsEqual(const GrFragmentProcessor& fpBase) const { | 124 bool GrArithmeticFP::onIsEqual(const GrFragmentProcessor& fpBase) const { |
124 const GrArithmeticFP& fp = fpBase.cast<GrArithmeticFP>(); | 125 const GrArithmeticFP& fp = fpBase.cast<GrArithmeticFP>(); |
125 return fK1 == fp.fK1 && | 126 return fK1 == fp.fK1 && |
126 fK2 == fp.fK2 && | 127 fK2 == fp.fK2 && |
127 fK3 == fp.fK3 && | 128 fK3 == fp.fK3 && |
128 fK4 == fp.fK4 && | 129 fK4 == fp.fK4 && |
129 fEnforcePMColor == fp.fEnforcePMColor; | 130 fEnforcePMColor == fp.fEnforcePMColor; |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 float k1 = d->fRandom->nextF(); | 303 float k1 = d->fRandom->nextF(); |
303 float k2 = d->fRandom->nextF(); | 304 float k2 = d->fRandom->nextF(); |
304 float k3 = d->fRandom->nextF(); | 305 float k3 = d->fRandom->nextF(); |
305 float k4 = d->fRandom->nextF(); | 306 float k4 = d->fRandom->nextF(); |
306 bool enforcePMColor = d->fRandom->nextBool(); | 307 bool enforcePMColor = d->fRandom->nextBool(); |
307 | 308 |
308 return GrArithmeticXPFactory::Create(k1, k2, k3, k4, enforcePMColor); | 309 return GrArithmeticXPFactory::Create(k1, k2, k3, k4, enforcePMColor); |
309 } | 310 } |
310 | 311 |
311 #endif | 312 #endif |
OLD | NEW |