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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 } | 153 } |
154 | 154 |
155 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrArithmeticFP); | 155 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrArithmeticFP); |
156 | 156 |
157 /////////////////////////////////////////////////////////////////////////////// | 157 /////////////////////////////////////////////////////////////////////////////// |
158 // Xfer Processor | 158 // Xfer Processor |
159 /////////////////////////////////////////////////////////////////////////////// | 159 /////////////////////////////////////////////////////////////////////////////// |
160 | 160 |
161 class ArithmeticXP : public GrXferProcessor { | 161 class ArithmeticXP : public GrXferProcessor { |
162 public: | 162 public: |
163 static GrXferProcessor* Create(float k1, float k2, float k3, float k4, bool
enforcePMColor, | 163 ArithmeticXP(const DstTexture*, bool hasMixedSamples, |
164 const DstTexture* dstTexture, bool willReadDs
tColor) { | 164 float k1, float k2, float k3, float k4, bool enforcePMColor); |
165 return SkNEW_ARGS(ArithmeticXP, (k1, k2, k3, k4, enforcePMColor, dstText
ure, | |
166 willReadDstColor)); | |
167 } | |
168 | |
169 ~ArithmeticXP() override {}; | |
170 | 165 |
171 const char* name() const override { return "Arithmetic"; } | 166 const char* name() const override { return "Arithmetic"; } |
172 | 167 |
173 GrGLXferProcessor* createGLInstance() const override; | 168 GrGLXferProcessor* createGLInstance() const override; |
174 | 169 |
175 float k1() const { return fK1; } | 170 float k1() const { return fK1; } |
176 float k2() const { return fK2; } | 171 float k2() const { return fK2; } |
177 float k3() const { return fK3; } | 172 float k3() const { return fK3; } |
178 float k4() const { return fK4; } | 173 float k4() const { return fK4; } |
179 bool enforcePMColor() const { return fEnforcePMColor; } | 174 bool enforcePMColor() const { return fEnforcePMColor; } |
180 | 175 |
181 private: | 176 private: |
182 ArithmeticXP(float k1, float k2, float k3, float k4, bool enforcePMColor, | |
183 const DstTexture*, bool willReadDstColor); | |
184 | |
185 GrXferProcessor::OptFlags onGetOptimizations(const GrProcOptInfo& colorPOI, | 177 GrXferProcessor::OptFlags onGetOptimizations(const GrProcOptInfo& colorPOI, |
186 const GrProcOptInfo& coveragePO
I, | 178 const GrProcOptInfo& coveragePO
I, |
187 bool doesStencilWrite, | 179 bool doesStencilWrite, |
188 GrColor* overrideColor, | 180 GrColor* overrideColor, |
189 const GrCaps& caps) override; | 181 const GrCaps& caps) override; |
190 | 182 |
191 void onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) c
onst override; | 183 void onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) c
onst override; |
192 | 184 |
193 bool onIsEqual(const GrXferProcessor& xpBase) const override { | 185 bool onIsEqual(const GrXferProcessor& xpBase) const override { |
194 const ArithmeticXP& xp = xpBase.cast<ArithmeticXP>(); | 186 const ArithmeticXP& xp = xpBase.cast<ArithmeticXP>(); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 }; | 238 }; |
247 | 239 |
248 GrGLProgramDataManager::UniformHandle fKUni; | 240 GrGLProgramDataManager::UniformHandle fKUni; |
249 bool fEnforcePMColor; | 241 bool fEnforcePMColor; |
250 | 242 |
251 typedef GrGLXferProcessor INHERITED; | 243 typedef GrGLXferProcessor INHERITED; |
252 }; | 244 }; |
253 | 245 |
254 /////////////////////////////////////////////////////////////////////////////// | 246 /////////////////////////////////////////////////////////////////////////////// |
255 | 247 |
256 ArithmeticXP::ArithmeticXP(float k1, float k2, float k3, float k4, bool enforceP
MColor, | 248 ArithmeticXP::ArithmeticXP(const DstTexture* dstTexture, bool hasMixedSamples, |
257 const DstTexture* dstTexture, bool willReadDstColor) | 249 float k1, float k2, float k3, float k4, bool enforceP
MColor) |
258 : INHERITED(dstTexture, willReadDstColor) | 250 : INHERITED(dstTexture, true, hasMixedSamples) |
259 , fK1(k1) | 251 , fK1(k1) |
260 , fK2(k2) | 252 , fK2(k2) |
261 , fK3(k3) | 253 , fK3(k3) |
262 , fK4(k4) | 254 , fK4(k4) |
263 , fEnforcePMColor(enforcePMColor) { | 255 , fEnforcePMColor(enforcePMColor) { |
264 this->initClassID<ArithmeticXP>(); | 256 this->initClassID<ArithmeticXP>(); |
265 } | 257 } |
266 | 258 |
267 void ArithmeticXP::onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBui
lder* b) const { | 259 void ArithmeticXP::onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBui
lder* b) const { |
268 GLArithmeticXP::GenKey(*this, caps, b); | 260 GLArithmeticXP::GenKey(*this, caps, b); |
(...skipping 16 matching lines...) Expand all Loading... |
285 GrArithmeticXPFactory::GrArithmeticXPFactory(float k1, float k2, float k3, float
k4, | 277 GrArithmeticXPFactory::GrArithmeticXPFactory(float k1, float k2, float k3, float
k4, |
286 bool enforcePMColor) | 278 bool enforcePMColor) |
287 : fK1(k1), fK2(k2), fK3(k3), fK4(k4), fEnforcePMColor(enforcePMColor) { | 279 : fK1(k1), fK2(k2), fK3(k3), fK4(k4), fEnforcePMColor(enforcePMColor) { |
288 this->initClassID<GrArithmeticXPFactory>(); | 280 this->initClassID<GrArithmeticXPFactory>(); |
289 } | 281 } |
290 | 282 |
291 GrXferProcessor* | 283 GrXferProcessor* |
292 GrArithmeticXPFactory::onCreateXferProcessor(const GrCaps& caps, | 284 GrArithmeticXPFactory::onCreateXferProcessor(const GrCaps& caps, |
293 const GrProcOptInfo& colorPOI, | 285 const GrProcOptInfo& colorPOI, |
294 const GrProcOptInfo& coveragePOI, | 286 const GrProcOptInfo& coveragePOI, |
| 287 bool hasMixedSamples, |
295 const DstTexture* dstTexture) const
{ | 288 const DstTexture* dstTexture) const
{ |
296 return ArithmeticXP::Create(fK1, fK2, fK3, fK4, fEnforcePMColor, dstTexture, | 289 return SkNEW_ARGS(ArithmeticXP, (dstTexture, hasMixedSamples, fK1, fK2, fK3,
fK4, |
297 this->willReadDstColor(caps, colorPOI, coverageP
OI)); | 290 fEnforcePMColor)); |
298 } | 291 } |
299 | 292 |
300 | 293 |
301 void GrArithmeticXPFactory::getInvariantBlendedColor(const GrProcOptInfo& colorP
OI, | 294 void GrArithmeticXPFactory::getInvariantBlendedColor(const GrProcOptInfo& colorP
OI, |
302 InvariantBlendedColor* blen
dedColor) const { | 295 InvariantBlendedColor* blen
dedColor) const { |
303 blendedColor->fWillBlendWithDst = true; | 296 blendedColor->fWillBlendWithDst = true; |
304 | 297 |
305 // TODO: We could try to optimize this more. For example if fK1 and fK3 are
zero, then we won't | 298 // TODO: We could try to optimize this more. For example if fK1 and fK3 are
zero, then we won't |
306 // be blending the color with dst at all so we can know what the output colo
r is (up to the | 299 // be blending the color with dst at all so we can know what the output colo
r is (up to the |
307 // valid color components passed in). | 300 // valid color components passed in). |
308 blendedColor->fKnownColorFlags = kNone_GrColorComponentFlags; | 301 blendedColor->fKnownColorFlags = kNone_GrColorComponentFlags; |
309 } | 302 } |
310 | 303 |
311 GR_DEFINE_XP_FACTORY_TEST(GrArithmeticXPFactory); | 304 GR_DEFINE_XP_FACTORY_TEST(GrArithmeticXPFactory); |
312 | 305 |
313 GrXPFactory* GrArithmeticXPFactory::TestCreate(SkRandom* random, | 306 GrXPFactory* GrArithmeticXPFactory::TestCreate(SkRandom* random, |
314 GrContext*, | 307 GrContext*, |
315 const GrCaps&, | 308 const GrCaps&, |
316 GrTexture*[]) { | 309 GrTexture*[]) { |
317 float k1 = random->nextF(); | 310 float k1 = random->nextF(); |
318 float k2 = random->nextF(); | 311 float k2 = random->nextF(); |
319 float k3 = random->nextF(); | 312 float k3 = random->nextF(); |
320 float k4 = random->nextF(); | 313 float k4 = random->nextF(); |
321 bool enforcePMColor = random->nextBool(); | 314 bool enforcePMColor = random->nextBool(); |
322 | 315 |
323 return GrArithmeticXPFactory::Create(k1, k2, k3, k4, enforcePMColor); | 316 return GrArithmeticXPFactory::Create(k1, k2, k3, k4, enforcePMColor); |
324 } | 317 } |
325 | 318 |
326 #endif | 319 #endif |
OLD | NEW |