| 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 "effects/GrCustomXfermode.h" | 8 #include "effects/GrCustomXfermode.h" |
| 9 | 9 |
| 10 #include "GrCoordTransform.h" | 10 #include "GrCoordTransform.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 GR_STATIC_ASSERT(kExclusion_GrBlendEquation == SkXfermode::kExclusion_Mode +
kOffset); | 47 GR_STATIC_ASSERT(kExclusion_GrBlendEquation == SkXfermode::kExclusion_Mode +
kOffset); |
| 48 GR_STATIC_ASSERT(kMultiply_GrBlendEquation == SkXfermode::kMultiply_Mode + k
Offset); | 48 GR_STATIC_ASSERT(kMultiply_GrBlendEquation == SkXfermode::kMultiply_Mode + k
Offset); |
| 49 GR_STATIC_ASSERT(kHSLHue_GrBlendEquation == SkXfermode::kHue_Mode + kOffset)
; | 49 GR_STATIC_ASSERT(kHSLHue_GrBlendEquation == SkXfermode::kHue_Mode + kOffset)
; |
| 50 GR_STATIC_ASSERT(kHSLSaturation_GrBlendEquation == SkXfermode::kSaturation_M
ode + kOffset); | 50 GR_STATIC_ASSERT(kHSLSaturation_GrBlendEquation == SkXfermode::kSaturation_M
ode + kOffset); |
| 51 GR_STATIC_ASSERT(kHSLColor_GrBlendEquation == SkXfermode::kColor_Mode + kOff
set); | 51 GR_STATIC_ASSERT(kHSLColor_GrBlendEquation == SkXfermode::kColor_Mode + kOff
set); |
| 52 GR_STATIC_ASSERT(kHSLLuminosity_GrBlendEquation == SkXfermode::kLuminosity_M
ode + kOffset); | 52 GR_STATIC_ASSERT(kHSLLuminosity_GrBlendEquation == SkXfermode::kLuminosity_M
ode + kOffset); |
| 53 GR_STATIC_ASSERT(kGrBlendEquationCnt == SkXfermode::kLastMode + 1 + kOffset)
; | 53 GR_STATIC_ASSERT(kGrBlendEquationCnt == SkXfermode::kLastMode + 1 + kOffset)
; |
| 54 } | 54 } |
| 55 | 55 |
| 56 static bool can_use_hw_blend_equation(GrBlendEquation equation, | 56 static bool can_use_hw_blend_equation(GrBlendEquation equation, |
| 57 const GrProcOptInfo& coveragePOI, | 57 const GrPipelineOptimizations& opt, |
| 58 const GrCaps& caps) { | 58 const GrCaps& caps) { |
| 59 if (!caps.advancedBlendEquationSupport()) { | 59 if (!caps.advancedBlendEquationSupport()) { |
| 60 return false; | 60 return false; |
| 61 } | 61 } |
| 62 if (coveragePOI.isFourChannelOutput()) { | 62 if (opt.fOverrides.fUsePLSDstRead) { |
| 63 return false; |
| 64 } |
| 65 if (opt.fCoveragePOI.isFourChannelOutput()) { |
| 63 return false; // LCD coverage must be applied after the blend equation. | 66 return false; // LCD coverage must be applied after the blend equation. |
| 64 } | 67 } |
| 65 if (caps.canUseAdvancedBlendEquation(equation)) { | 68 if (caps.canUseAdvancedBlendEquation(equation)) { |
| 66 return false; | 69 return false; |
| 67 } | 70 } |
| 68 return true; | 71 return true; |
| 69 } | 72 } |
| 70 | 73 |
| 71 /////////////////////////////////////////////////////////////////////////////// | 74 /////////////////////////////////////////////////////////////////////////////// |
| 72 // Xfer Processor | 75 // Xfer Processor |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 | 330 |
| 328 void getInvariantBlendedColor(const GrProcOptInfo& colorPOI, | 331 void getInvariantBlendedColor(const GrProcOptInfo& colorPOI, |
| 329 GrXPFactory::InvariantBlendedColor*) const ove
rride; | 332 GrXPFactory::InvariantBlendedColor*) const ove
rride; |
| 330 | 333 |
| 331 private: | 334 private: |
| 332 GrXferProcessor* onCreateXferProcessor(const GrCaps& caps, | 335 GrXferProcessor* onCreateXferProcessor(const GrCaps& caps, |
| 333 const GrPipelineOptimizations& optimi
zations, | 336 const GrPipelineOptimizations& optimi
zations, |
| 334 bool hasMixedSamples, | 337 bool hasMixedSamples, |
| 335 const DstTexture*) const override; | 338 const DstTexture*) const override; |
| 336 | 339 |
| 337 bool willReadDstColor(const GrCaps& caps, | 340 bool onWillReadDstColor(const GrCaps& caps, |
| 338 const GrPipelineOptimizations& optimizations, | 341 const GrPipelineOptimizations& optimizations, |
| 339 bool hasMixedSamples) const override; | 342 bool hasMixedSamples) const override; |
| 340 | 343 |
| 341 bool onIsEqual(const GrXPFactory& xpfBase) const override { | 344 bool onIsEqual(const GrXPFactory& xpfBase) const override { |
| 342 const CustomXPFactory& xpf = xpfBase.cast<CustomXPFactory>(); | 345 const CustomXPFactory& xpf = xpfBase.cast<CustomXPFactory>(); |
| 343 return fMode == xpf.fMode; | 346 return fMode == xpf.fMode; |
| 344 } | 347 } |
| 345 | 348 |
| 346 GR_DECLARE_XP_FACTORY_TEST; | 349 GR_DECLARE_XP_FACTORY_TEST; |
| 347 | 350 |
| 348 SkXfermode::Mode fMode; | 351 SkXfermode::Mode fMode; |
| 349 GrBlendEquation fHWBlendEquation; | 352 GrBlendEquation fHWBlendEquation; |
| 350 | 353 |
| 351 typedef GrXPFactory INHERITED; | 354 typedef GrXPFactory INHERITED; |
| 352 }; | 355 }; |
| 353 | 356 |
| 354 CustomXPFactory::CustomXPFactory(SkXfermode::Mode mode) | 357 CustomXPFactory::CustomXPFactory(SkXfermode::Mode mode) |
| 355 : fMode(mode), | 358 : fMode(mode), |
| 356 fHWBlendEquation(hw_blend_equation(mode)) { | 359 fHWBlendEquation(hw_blend_equation(mode)) { |
| 357 SkASSERT(GrCustomXfermode::IsSupportedMode(fMode)); | 360 SkASSERT(GrCustomXfermode::IsSupportedMode(fMode)); |
| 358 this->initClassID<CustomXPFactory>(); | 361 this->initClassID<CustomXPFactory>(); |
| 359 } | 362 } |
| 360 | 363 |
| 361 GrXferProcessor* CustomXPFactory::onCreateXferProcessor(const GrCaps& caps, | 364 GrXferProcessor* CustomXPFactory::onCreateXferProcessor(const GrCaps& caps, |
| 362 const GrPipelineOptimiza
tions& opt, | 365 const GrPipelineOptimiza
tions& opt, |
| 363 bool hasMixedSamples, | 366 bool hasMixedSamples, |
| 364 const DstTexture* dstTex
ture) const { | 367 const DstTexture* dstTex
ture) const { |
| 365 if (can_use_hw_blend_equation(fHWBlendEquation, opt.fCoveragePOI, caps)) { | 368 if (can_use_hw_blend_equation(fHWBlendEquation, opt, caps)) { |
| 366 SkASSERT(!dstTexture || !dstTexture->texture()); | 369 SkASSERT(!dstTexture || !dstTexture->texture()); |
| 367 return new CustomXP(fMode, fHWBlendEquation); | 370 return new CustomXP(fMode, fHWBlendEquation); |
| 368 } | 371 } |
| 369 return new CustomXP(dstTexture, hasMixedSamples, fMode); | 372 return new CustomXP(dstTexture, hasMixedSamples, fMode); |
| 370 } | 373 } |
| 371 | 374 |
| 372 bool CustomXPFactory::willReadDstColor(const GrCaps& caps, | 375 bool CustomXPFactory::onWillReadDstColor(const GrCaps& caps, |
| 373 const GrPipelineOptimizations& optimizati
ons, | 376 const GrPipelineOptimizations& optimiza
tions, |
| 374 bool hasMixedSamples) const { | 377 bool hasMixedSamples) const { |
| 375 return !can_use_hw_blend_equation(fHWBlendEquation, optimizations.fCoverageP
OI, caps); | 378 return !can_use_hw_blend_equation(fHWBlendEquation, optimizations, caps); |
| 376 } | 379 } |
| 377 | 380 |
| 378 void CustomXPFactory::getInvariantBlendedColor(const GrProcOptInfo& colorPOI, | 381 void CustomXPFactory::getInvariantBlendedColor(const GrProcOptInfo& colorPOI, |
| 379 InvariantBlendedColor* blendedCol
or) const { | 382 InvariantBlendedColor* blendedCol
or) const { |
| 380 blendedColor->fWillBlendWithDst = true; | 383 blendedColor->fWillBlendWithDst = true; |
| 381 blendedColor->fKnownColorFlags = kNone_GrColorComponentFlags; | 384 blendedColor->fKnownColorFlags = kNone_GrColorComponentFlags; |
| 382 } | 385 } |
| 383 | 386 |
| 384 GR_DEFINE_XP_FACTORY_TEST(CustomXPFactory); | 387 GR_DEFINE_XP_FACTORY_TEST(CustomXPFactory); |
| 385 const GrXPFactory* CustomXPFactory::TestCreate(GrProcessorTestData* d) { | 388 const GrXPFactory* CustomXPFactory::TestCreate(GrProcessorTestData* d) { |
| 386 int mode = d->fRandom->nextRangeU(SkXfermode::kLastCoeffMode + 1, | 389 int mode = d->fRandom->nextRangeU(SkXfermode::kLastCoeffMode + 1, |
| 387 SkXfermode::kLastSeparableMode); | 390 SkXfermode::kLastSeparableMode); |
| 388 | 391 |
| 389 return new CustomXPFactory(static_cast<SkXfermode::Mode>(mode)); | 392 return new CustomXPFactory(static_cast<SkXfermode::Mode>(mode)); |
| 390 } | 393 } |
| 391 | 394 |
| 392 /////////////////////////////////////////////////////////////////////////////// | 395 /////////////////////////////////////////////////////////////////////////////// |
| 393 | 396 |
| 394 GrXPFactory* GrCustomXfermode::CreateXPFactory(SkXfermode::Mode mode) { | 397 GrXPFactory* GrCustomXfermode::CreateXPFactory(SkXfermode::Mode mode) { |
| 395 if (!GrCustomXfermode::IsSupportedMode(mode)) { | 398 if (!GrCustomXfermode::IsSupportedMode(mode)) { |
| 396 return nullptr; | 399 return nullptr; |
| 397 } else { | 400 } else { |
| 398 return new CustomXPFactory(mode); | 401 return new CustomXPFactory(mode); |
| 399 } | 402 } |
| 400 } | 403 } |
| OLD | NEW |