GrPathRendererChain.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * Copyright 2011 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/GrPathRendererChain.h"
  8. #include "include/gpu/GrContext.h"
  9. #include "include/private/GrRecordingContext.h"
  10. #include "src/gpu/GrCaps.h"
  11. #include "src/gpu/GrContextPriv.h"
  12. #include "src/gpu/GrGpu.h"
  13. #include "src/gpu/GrRecordingContextPriv.h"
  14. #include "src/gpu/GrShaderCaps.h"
  15. #include "src/gpu/ccpr/GrCoverageCountingPathRenderer.h"
  16. #include "src/gpu/ops/GrAAConvexPathRenderer.h"
  17. #include "src/gpu/ops/GrAAHairLinePathRenderer.h"
  18. #include "src/gpu/ops/GrAALinearizingConvexPathRenderer.h"
  19. #include "src/gpu/ops/GrDashLinePathRenderer.h"
  20. #include "src/gpu/ops/GrDefaultPathRenderer.h"
  21. #include "src/gpu/ops/GrSmallPathRenderer.h"
  22. #include "src/gpu/ops/GrStencilAndCoverPathRenderer.h"
  23. #include "src/gpu/ops/GrTessellatingPathRenderer.h"
  24. GrPathRendererChain::GrPathRendererChain(GrRecordingContext* context, const Options& options) {
  25. const GrCaps& caps = *context->priv().caps();
  26. if (options.fGpuPathRenderers & GpuPathRenderers::kDashLine) {
  27. fChain.push_back(sk_make_sp<GrDashLinePathRenderer>());
  28. }
  29. if (options.fGpuPathRenderers & GpuPathRenderers::kAAConvex) {
  30. fChain.push_back(sk_make_sp<GrAAConvexPathRenderer>());
  31. }
  32. if (options.fGpuPathRenderers & GpuPathRenderers::kCoverageCounting) {
  33. using AllowCaching = GrCoverageCountingPathRenderer::AllowCaching;
  34. if (auto ccpr = GrCoverageCountingPathRenderer::CreateIfSupported(
  35. caps, AllowCaching(options.fAllowPathMaskCaching),
  36. context->priv().contextID())) {
  37. fCoverageCountingPathRenderer = ccpr.get();
  38. context->priv().addOnFlushCallbackObject(fCoverageCountingPathRenderer);
  39. fChain.push_back(std::move(ccpr));
  40. }
  41. }
  42. if (options.fGpuPathRenderers & GpuPathRenderers::kAAHairline) {
  43. fChain.push_back(sk_make_sp<GrAAHairLinePathRenderer>());
  44. }
  45. if (options.fGpuPathRenderers & GpuPathRenderers::kAALinearizing) {
  46. fChain.push_back(sk_make_sp<GrAALinearizingConvexPathRenderer>());
  47. }
  48. if (options.fGpuPathRenderers & GpuPathRenderers::kSmall) {
  49. auto spr = sk_make_sp<GrSmallPathRenderer>();
  50. context->priv().addOnFlushCallbackObject(spr.get());
  51. fChain.push_back(std::move(spr));
  52. }
  53. if (options.fGpuPathRenderers & GpuPathRenderers::kStencilAndCover) {
  54. auto direct = context->priv().asDirectContext();
  55. if (direct) {
  56. auto resourceProvider = direct->priv().resourceProvider();
  57. sk_sp<GrPathRenderer> pr(
  58. GrStencilAndCoverPathRenderer::Create(resourceProvider, caps));
  59. if (pr) {
  60. fChain.push_back(std::move(pr));
  61. }
  62. }
  63. }
  64. if (options.fGpuPathRenderers & GpuPathRenderers::kTessellating) {
  65. fChain.push_back(sk_make_sp<GrTessellatingPathRenderer>());
  66. }
  67. // We always include the default path renderer (as well as SW), so we can draw any path
  68. fChain.push_back(sk_make_sp<GrDefaultPathRenderer>());
  69. }
  70. GrPathRenderer* GrPathRendererChain::getPathRenderer(
  71. const GrPathRenderer::CanDrawPathArgs& args,
  72. DrawType drawType,
  73. GrPathRenderer::StencilSupport* stencilSupport) {
  74. GR_STATIC_ASSERT(GrPathRenderer::kNoSupport_StencilSupport <
  75. GrPathRenderer::kStencilOnly_StencilSupport);
  76. GR_STATIC_ASSERT(GrPathRenderer::kStencilOnly_StencilSupport <
  77. GrPathRenderer::kNoRestriction_StencilSupport);
  78. GrPathRenderer::StencilSupport minStencilSupport;
  79. if (DrawType::kStencil == drawType) {
  80. minStencilSupport = GrPathRenderer::kStencilOnly_StencilSupport;
  81. } else if (DrawType::kStencilAndColor == drawType) {
  82. minStencilSupport = GrPathRenderer::kNoRestriction_StencilSupport;
  83. } else {
  84. minStencilSupport = GrPathRenderer::kNoSupport_StencilSupport;
  85. }
  86. if (minStencilSupport != GrPathRenderer::kNoSupport_StencilSupport) {
  87. // We don't support (and shouldn't need) stenciling of non-fill paths.
  88. if (!args.fShape->style().isSimpleFill()) {
  89. return nullptr;
  90. }
  91. }
  92. GrPathRenderer* bestPathRenderer = nullptr;
  93. for (const sk_sp<GrPathRenderer>& pr : fChain) {
  94. GrPathRenderer::StencilSupport support = GrPathRenderer::kNoSupport_StencilSupport;
  95. if (GrPathRenderer::kNoSupport_StencilSupport != minStencilSupport) {
  96. support = pr->getStencilSupport(*args.fShape);
  97. if (support < minStencilSupport) {
  98. continue;
  99. }
  100. }
  101. GrPathRenderer::CanDrawPath canDrawPath = pr->canDrawPath(args);
  102. if (GrPathRenderer::CanDrawPath::kNo == canDrawPath) {
  103. continue;
  104. }
  105. if (GrPathRenderer::CanDrawPath::kAsBackup == canDrawPath && bestPathRenderer) {
  106. continue;
  107. }
  108. if (stencilSupport) {
  109. *stencilSupport = support;
  110. }
  111. bestPathRenderer = pr.get();
  112. if (GrPathRenderer::CanDrawPath::kYes == canDrawPath) {
  113. break;
  114. }
  115. }
  116. return bestPathRenderer;
  117. }