OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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.h" | 8 #include "SkArithmeticMode.h" |
9 #include "SkColorPriv.h" | 9 #include "SkColorPriv.h" |
10 #include "SkReadBuffer.h" | 10 #include "SkReadBuffer.h" |
11 #include "SkWriteBuffer.h" | 11 #include "SkWriteBuffer.h" |
12 #include "SkString.h" | 12 #include "SkString.h" |
13 #include "SkUnPreMultiply.h" | 13 #include "SkUnPreMultiply.h" |
14 #if SK_SUPPORT_GPU | 14 #if SK_SUPPORT_GPU |
15 #include "GrContext.h" | 15 #include "GrContext.h" |
16 #include "GrCoordTransform.h" | 16 #include "GrCoordTransform.h" |
17 #include "GrInvariantOutput.h" | 17 #include "GrInvariantOutput.h" |
18 #include "gl/GrGLProcessor.h" | 18 #include "gl/GrGLProcessor.h" |
19 #include "gl/builders/GrGLProgramBuilder.h" | 19 #include "gl/builders/GrGLProgramBuilder.h" |
20 #include "GrTBackendProcessorFactory.h" | |
21 #endif | 20 #endif |
22 | 21 |
23 static const bool gUseUnpremul = false; | 22 static const bool gUseUnpremul = false; |
24 | 23 |
25 class SkArithmeticMode_scalar : public SkXfermode { | 24 class SkArithmeticMode_scalar : public SkXfermode { |
26 public: | 25 public: |
27 static SkArithmeticMode_scalar* Create(SkScalar k1, SkScalar k2, SkScalar k3
, SkScalar k4, | 26 static SkArithmeticMode_scalar* Create(SkScalar k1, SkScalar k2, SkScalar k3
, SkScalar k4, |
28 bool enforcePMColor) { | 27 bool enforcePMColor) { |
29 return SkNEW_ARGS(SkArithmeticMode_scalar, (k1, k2, k3, k4, enforcePMCol
or)); | 28 return SkNEW_ARGS(SkArithmeticMode_scalar, (k1, k2, k3, k4, enforcePMCol
or)); |
30 } | 29 } |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 return SkArithmeticMode_scalar::Create(k1, k2, k3, k4, enforcePMColor); | 233 return SkArithmeticMode_scalar::Create(k1, k2, k3, k4, enforcePMColor); |
235 } | 234 } |
236 | 235 |
237 | 236 |
238 ////////////////////////////////////////////////////////////////////////////// | 237 ////////////////////////////////////////////////////////////////////////////// |
239 | 238 |
240 #if SK_SUPPORT_GPU | 239 #if SK_SUPPORT_GPU |
241 | 240 |
242 class GrGLArithmeticEffect : public GrGLFragmentProcessor { | 241 class GrGLArithmeticEffect : public GrGLFragmentProcessor { |
243 public: | 242 public: |
244 GrGLArithmeticEffect(const GrBackendProcessorFactory&, const GrProcessor&); | 243 GrGLArithmeticEffect(const GrProcessor&); |
245 virtual ~GrGLArithmeticEffect(); | 244 virtual ~GrGLArithmeticEffect(); |
246 | 245 |
247 virtual void emitCode(GrGLFPBuilder*, | 246 virtual void emitCode(GrGLFPBuilder*, |
248 const GrFragmentProcessor&, | 247 const GrFragmentProcessor&, |
249 const char* outputColor, | 248 const char* outputColor, |
250 const char* inputColor, | 249 const char* inputColor, |
251 const TransformedCoordsArray&, | 250 const TransformedCoordsArray&, |
252 const TextureSamplerArray&) SK_OVERRIDE; | 251 const TextureSamplerArray&) SK_OVERRIDE; |
253 | 252 |
254 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; | 253 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; |
(...skipping 11 matching lines...) Expand all Loading... |
266 | 265 |
267 class GrArithmeticEffect : public GrFragmentProcessor { | 266 class GrArithmeticEffect : public GrFragmentProcessor { |
268 public: | 267 public: |
269 static GrFragmentProcessor* Create(float k1, float k2, float k3, float k4, b
ool enforcePMColor, | 268 static GrFragmentProcessor* Create(float k1, float k2, float k3, float k4, b
ool enforcePMColor, |
270 GrTexture* background) { | 269 GrTexture* background) { |
271 return SkNEW_ARGS(GrArithmeticEffect, (k1, k2, k3, k4, enforcePMColor, b
ackground)); | 270 return SkNEW_ARGS(GrArithmeticEffect, (k1, k2, k3, k4, enforcePMColor, b
ackground)); |
272 } | 271 } |
273 | 272 |
274 virtual ~GrArithmeticEffect(); | 273 virtual ~GrArithmeticEffect(); |
275 | 274 |
276 virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERR
IDE; | 275 virtual const char* name() const SK_OVERRIDE { return "Arithmetic"; } |
277 | 276 |
278 typedef GrGLArithmeticEffect GLProcessor; | 277 virtual void getGLProcessorKey(const GrGLCaps& caps, |
279 static const char* Name() { return "Arithmetic"; } | 278 GrProcessorKeyBuilder* b) const SK_OVERRIDE { |
| 279 GrGLArithmeticEffect::GenKey(*this, caps, b); |
| 280 } |
| 281 |
| 282 virtual GrGLFragmentProcessor* createGLInstance() const SK_OVERRIDE { |
| 283 return SkNEW_ARGS(GrGLArithmeticEffect, (*this)); |
| 284 } |
| 285 |
| 286 virtual uint32_t classID() const { |
| 287 static uint32_t id = GenClassID(); |
| 288 return id; |
| 289 } |
| 290 |
280 GrTexture* backgroundTexture() const { return fBackgroundAccess.getTexture()
; } | 291 GrTexture* backgroundTexture() const { return fBackgroundAccess.getTexture()
; } |
281 | 292 |
282 float k1() const { return fK1; } | 293 float k1() const { return fK1; } |
283 float k2() const { return fK2; } | 294 float k2() const { return fK2; } |
284 float k3() const { return fK3; } | 295 float k3() const { return fK3; } |
285 float k4() const { return fK4; } | 296 float k4() const { return fK4; } |
286 bool enforcePMColor() const { return fEnforcePMColor; } | 297 bool enforcePMColor() const { return fEnforcePMColor; } |
287 | 298 |
288 private: | 299 private: |
289 virtual bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE; | 300 virtual bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 | 333 |
323 bool GrArithmeticEffect::onIsEqual(const GrFragmentProcessor& sBase) const { | 334 bool GrArithmeticEffect::onIsEqual(const GrFragmentProcessor& sBase) const { |
324 const GrArithmeticEffect& s = sBase.cast<GrArithmeticEffect>(); | 335 const GrArithmeticEffect& s = sBase.cast<GrArithmeticEffect>(); |
325 return fK1 == s.fK1 && | 336 return fK1 == s.fK1 && |
326 fK2 == s.fK2 && | 337 fK2 == s.fK2 && |
327 fK3 == s.fK3 && | 338 fK3 == s.fK3 && |
328 fK4 == s.fK4 && | 339 fK4 == s.fK4 && |
329 fEnforcePMColor == s.fEnforcePMColor; | 340 fEnforcePMColor == s.fEnforcePMColor; |
330 } | 341 } |
331 | 342 |
332 const GrBackendFragmentProcessorFactory& GrArithmeticEffect::getFactory() const
{ | |
333 return GrTBackendFragmentProcessorFactory<GrArithmeticEffect>::getInstance()
; | |
334 } | |
335 | |
336 void GrArithmeticEffect::onComputeInvariantOutput(GrInvariantOutput* inout) cons
t { | 343 void GrArithmeticEffect::onComputeInvariantOutput(GrInvariantOutput* inout) cons
t { |
337 // TODO: optimize this | 344 // TODO: optimize this |
338 inout->setToUnknown(GrInvariantOutput::kWill_ReadInput); | 345 inout->setToUnknown(GrInvariantOutput::kWill_ReadInput); |
339 } | 346 } |
340 | 347 |
341 /////////////////////////////////////////////////////////////////////////////// | 348 /////////////////////////////////////////////////////////////////////////////// |
342 | 349 |
343 GrGLArithmeticEffect::GrGLArithmeticEffect(const GrBackendProcessorFactory& fact
ory, | 350 GrGLArithmeticEffect::GrGLArithmeticEffect(const GrProcessor&) |
344 const GrProcessor&) | 351 : fEnforcePMColor(true) { |
345 : INHERITED(factory), | |
346 fEnforcePMColor(true) { | |
347 } | 352 } |
348 | 353 |
349 GrGLArithmeticEffect::~GrGLArithmeticEffect() { | 354 GrGLArithmeticEffect::~GrGLArithmeticEffect() { |
350 } | 355 } |
351 | 356 |
352 void GrGLArithmeticEffect::emitCode(GrGLFPBuilder* builder, | 357 void GrGLArithmeticEffect::emitCode(GrGLFPBuilder* builder, |
353 const GrFragmentProcessor& fp, | 358 const GrFragmentProcessor& fp, |
354 const char* outputColor, | 359 const char* outputColor, |
355 const char* inputColor, | 360 const char* inputColor, |
356 const TransformedCoordsArray& coords, | 361 const TransformedCoordsArray& coords, |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 background); | 445 background); |
441 } | 446 } |
442 return true; | 447 return true; |
443 } | 448 } |
444 | 449 |
445 #endif | 450 #endif |
446 | 451 |
447 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkArithmeticMode) | 452 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkArithmeticMode) |
448 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkArithmeticMode_scalar) | 453 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkArithmeticMode_scalar) |
449 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 454 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |