GrXferProcessor.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. * Copyright 2015 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/GrXferProcessor.h"
  8. #include "src/gpu/GrCaps.h"
  9. #include "src/gpu/GrPipeline.h"
  10. GrXferProcessor::GrXferProcessor(ClassID classID)
  11. : INHERITED(classID)
  12. , fWillReadDstColor(false)
  13. , fDstReadUsesMixedSamples(false)
  14. , fIsLCD(false) {}
  15. GrXferProcessor::GrXferProcessor(ClassID classID, bool willReadDstColor, bool hasMixedSamples,
  16. GrProcessorAnalysisCoverage coverage)
  17. : INHERITED(classID)
  18. , fWillReadDstColor(willReadDstColor)
  19. , fDstReadUsesMixedSamples(willReadDstColor && hasMixedSamples)
  20. , fIsLCD(GrProcessorAnalysisCoverage::kLCD == coverage) {}
  21. bool GrXferProcessor::hasSecondaryOutput() const {
  22. if (!this->willReadDstColor()) {
  23. return this->onHasSecondaryOutput();
  24. }
  25. return this->dstReadUsesMixedSamples();
  26. }
  27. void GrXferProcessor::getGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b,
  28. const GrSurfaceOrigin* originIfDstTexture) const {
  29. uint32_t key = this->willReadDstColor() ? 0x1 : 0x0;
  30. if (key) {
  31. if (originIfDstTexture) {
  32. key |= 0x2;
  33. if (kTopLeft_GrSurfaceOrigin == *originIfDstTexture) {
  34. key |= 0x4;
  35. }
  36. }
  37. if (this->dstReadUsesMixedSamples()) {
  38. key |= 0x8;
  39. }
  40. }
  41. if (fIsLCD) {
  42. key |= 0x10;
  43. }
  44. b->add32(key);
  45. this->onGetGLSLProcessorKey(caps, b);
  46. }
  47. #ifdef SK_DEBUG
  48. static const char* equation_string(GrBlendEquation eq) {
  49. switch (eq) {
  50. case kAdd_GrBlendEquation:
  51. return "add";
  52. case kSubtract_GrBlendEquation:
  53. return "subtract";
  54. case kReverseSubtract_GrBlendEquation:
  55. return "reverse_subtract";
  56. case kScreen_GrBlendEquation:
  57. return "screen";
  58. case kOverlay_GrBlendEquation:
  59. return "overlay";
  60. case kDarken_GrBlendEquation:
  61. return "darken";
  62. case kLighten_GrBlendEquation:
  63. return "lighten";
  64. case kColorDodge_GrBlendEquation:
  65. return "color_dodge";
  66. case kColorBurn_GrBlendEquation:
  67. return "color_burn";
  68. case kHardLight_GrBlendEquation:
  69. return "hard_light";
  70. case kSoftLight_GrBlendEquation:
  71. return "soft_light";
  72. case kDifference_GrBlendEquation:
  73. return "difference";
  74. case kExclusion_GrBlendEquation:
  75. return "exclusion";
  76. case kMultiply_GrBlendEquation:
  77. return "multiply";
  78. case kHSLHue_GrBlendEquation:
  79. return "hsl_hue";
  80. case kHSLSaturation_GrBlendEquation:
  81. return "hsl_saturation";
  82. case kHSLColor_GrBlendEquation:
  83. return "hsl_color";
  84. case kHSLLuminosity_GrBlendEquation:
  85. return "hsl_luminosity";
  86. case kIllegal_GrBlendEquation:
  87. SkASSERT(false);
  88. return "<illegal>";
  89. }
  90. return "";
  91. }
  92. static const char* coeff_string(GrBlendCoeff coeff) {
  93. switch (coeff) {
  94. case kZero_GrBlendCoeff:
  95. return "zero";
  96. case kOne_GrBlendCoeff:
  97. return "one";
  98. case kSC_GrBlendCoeff:
  99. return "src_color";
  100. case kISC_GrBlendCoeff:
  101. return "inv_src_color";
  102. case kDC_GrBlendCoeff:
  103. return "dst_color";
  104. case kIDC_GrBlendCoeff:
  105. return "inv_dst_color";
  106. case kSA_GrBlendCoeff:
  107. return "src_alpha";
  108. case kISA_GrBlendCoeff:
  109. return "inv_src_alpha";
  110. case kDA_GrBlendCoeff:
  111. return "dst_alpha";
  112. case kIDA_GrBlendCoeff:
  113. return "inv_dst_alpha";
  114. case kConstC_GrBlendCoeff:
  115. return "const_color";
  116. case kIConstC_GrBlendCoeff:
  117. return "inv_const_color";
  118. case kConstA_GrBlendCoeff:
  119. return "const_alpha";
  120. case kIConstA_GrBlendCoeff:
  121. return "inv_const_alpha";
  122. case kS2C_GrBlendCoeff:
  123. return "src2_color";
  124. case kIS2C_GrBlendCoeff:
  125. return "inv_src2_color";
  126. case kS2A_GrBlendCoeff:
  127. return "src2_alpha";
  128. case kIS2A_GrBlendCoeff:
  129. return "inv_src2_alpha";
  130. case kIllegal_GrBlendCoeff:
  131. SkASSERT(false);
  132. return "<illegal>";
  133. }
  134. return "";
  135. }
  136. SkString GrXferProcessor::BlendInfo::dump() const {
  137. SkString out;
  138. out.printf("write_color(%d) equation(%s) src_coeff(%s) dst_coeff:(%s) const(0x%08x)",
  139. fWriteColor, equation_string(fEquation), coeff_string(fSrcBlend),
  140. coeff_string(fDstBlend), fBlendConstant.toBytes_RGBA());
  141. return out;
  142. }
  143. #endif
  144. ///////////////////////////////////////////////////////////////////////////////
  145. GrXPFactory::AnalysisProperties GrXPFactory::GetAnalysisProperties(
  146. const GrXPFactory* factory,
  147. const GrProcessorAnalysisColor& color,
  148. const GrProcessorAnalysisCoverage& coverage,
  149. const GrCaps& caps,
  150. GrClampType clampType) {
  151. AnalysisProperties result;
  152. if (factory) {
  153. result = factory->analysisProperties(color, coverage, caps, clampType);
  154. } else {
  155. result = GrPorterDuffXPFactory::SrcOverAnalysisProperties(color, coverage, caps,
  156. clampType);
  157. }
  158. SkASSERT(!(result & AnalysisProperties::kRequiresDstTexture));
  159. if ((result & AnalysisProperties::kReadsDstInShader) &&
  160. !caps.shaderCaps()->dstReadInShaderSupport()) {
  161. result |= AnalysisProperties::kRequiresDstTexture |
  162. AnalysisProperties::kRequiresNonOverlappingDraws;
  163. }
  164. return result;
  165. }
  166. sk_sp<const GrXferProcessor> GrXPFactory::MakeXferProcessor(const GrXPFactory* factory,
  167. const GrProcessorAnalysisColor& color,
  168. GrProcessorAnalysisCoverage coverage,
  169. bool hasMixedSamples,
  170. const GrCaps& caps,
  171. GrClampType clampType) {
  172. SkASSERT(!hasMixedSamples || caps.shaderCaps()->dualSourceBlendingSupport());
  173. if (factory) {
  174. return factory->makeXferProcessor(color, coverage, hasMixedSamples, caps, clampType);
  175. } else {
  176. return GrPorterDuffXPFactory::MakeSrcOverXferProcessor(color, coverage, hasMixedSamples,
  177. caps);
  178. }
  179. }