GrPaint.cpp 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright 2013 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #include "src/gpu/GrPaint.h"
  8. #include "src/gpu/GrXferProcessor.h"
  9. #include "src/gpu/effects/GrCoverageSetOpXP.h"
  10. #include "src/gpu/effects/GrPorterDuffXferProcessor.h"
  11. #include "src/gpu/effects/generated/GrSimpleTextureEffect.h"
  12. GrPaint::GrPaint(const GrPaint& that)
  13. : fXPFactory(that.fXPFactory)
  14. , fColorFragmentProcessors(that.fColorFragmentProcessors.count())
  15. , fCoverageFragmentProcessors(that.fCoverageFragmentProcessors.count())
  16. , fTrivial(that.fTrivial)
  17. , fColor(that.fColor) {
  18. for (int i = 0; i < that.fColorFragmentProcessors.count(); ++i) {
  19. fColorFragmentProcessors.push_back(that.fColorFragmentProcessors[i]->clone());
  20. SkASSERT(fColorFragmentProcessors[i]);
  21. }
  22. for (int i = 0; i < that.fCoverageFragmentProcessors.count(); ++i) {
  23. fCoverageFragmentProcessors.push_back(that.fCoverageFragmentProcessors[i]->clone());
  24. SkASSERT(fCoverageFragmentProcessors[i]);
  25. }
  26. }
  27. void GrPaint::setPorterDuffXPFactory(SkBlendMode mode) {
  28. this->setXPFactory(GrPorterDuffXPFactory::Get(mode));
  29. }
  30. void GrPaint::setCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage) {
  31. this->setXPFactory(GrCoverageSetOpXPFactory::Get(regionOp, invertCoverage));
  32. }
  33. void GrPaint::addColorTextureProcessor(sk_sp<GrTextureProxy> proxy, const SkMatrix& matrix) {
  34. this->addColorFragmentProcessor(GrSimpleTextureEffect::Make(std::move(proxy), matrix));
  35. }
  36. void GrPaint::addColorTextureProcessor(sk_sp<GrTextureProxy> proxy, const SkMatrix& matrix,
  37. const GrSamplerState& samplerState) {
  38. this->addColorFragmentProcessor(GrSimpleTextureEffect::Make(std::move(proxy), matrix,
  39. samplerState));
  40. }
  41. void GrPaint::addCoverageTextureProcessor(sk_sp<GrTextureProxy> proxy,
  42. const SkMatrix& matrix) {
  43. this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Make(std::move(proxy), matrix));
  44. }
  45. void GrPaint::addCoverageTextureProcessor(sk_sp<GrTextureProxy> proxy,
  46. const SkMatrix& matrix,
  47. const GrSamplerState& params) {
  48. this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Make(std::move(proxy), matrix,
  49. params));
  50. }
  51. bool GrPaint::isConstantBlendedColor(SkPMColor4f* constantColor) const {
  52. // This used to do a more sophisticated analysis but now it just explicitly looks for common
  53. // cases.
  54. static const GrXPFactory* kSrc = GrPorterDuffXPFactory::Get(SkBlendMode::kSrc);
  55. static const GrXPFactory* kClear = GrPorterDuffXPFactory::Get(SkBlendMode::kClear);
  56. if (kClear == fXPFactory) {
  57. *constantColor = SK_PMColor4fTRANSPARENT;
  58. return true;
  59. }
  60. if (this->numColorFragmentProcessors()) {
  61. return false;
  62. }
  63. if (kSrc == fXPFactory || (!fXPFactory && fColor.isOpaque())) {
  64. *constantColor = fColor;
  65. return true;
  66. }
  67. return false;
  68. }