GrDrawPathOp.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 "include/private/GrRecordingContext.h"
  8. #include "include/private/SkTemplates.h"
  9. #include "src/gpu/GrAppliedClip.h"
  10. #include "src/gpu/GrMemoryPool.h"
  11. #include "src/gpu/GrRecordingContextPriv.h"
  12. #include "src/gpu/GrRenderTargetContext.h"
  13. #include "src/gpu/GrRenderTargetPriv.h"
  14. #include "src/gpu/ops/GrDrawPathOp.h"
  15. static constexpr GrUserStencilSettings kCoverPass{
  16. GrUserStencilSettings::StaticInit<
  17. 0x0000,
  18. GrUserStencilTest::kNotEqual,
  19. 0xffff,
  20. GrUserStencilOp::kZero,
  21. GrUserStencilOp::kKeep,
  22. 0xffff>()
  23. };
  24. GrDrawPathOpBase::GrDrawPathOpBase(uint32_t classID, const SkMatrix& viewMatrix, GrPaint&& paint,
  25. GrPathRendering::FillType fill, GrAA aa)
  26. : INHERITED(classID)
  27. , fViewMatrix(viewMatrix)
  28. , fInputColor(paint.getColor4f())
  29. , fFillType(fill)
  30. , fDoAA(GrAA::kYes == aa)
  31. , fProcessorSet(std::move(paint)) {}
  32. #ifdef SK_DEBUG
  33. SkString GrDrawPathOp::dumpInfo() const {
  34. SkString string;
  35. string.printf("PATH: 0x%p", fPath.get());
  36. string.append(INHERITED::dumpInfo());
  37. return string;
  38. }
  39. #endif
  40. GrPipeline::InitArgs GrDrawPathOpBase::pipelineInitArgs(const GrOpFlushState& state) {
  41. GrPipeline::InitArgs args;
  42. if (fDoAA) {
  43. args.fInputFlags |= GrPipeline::InputFlags::kHWAntialias;
  44. }
  45. args.fUserStencil = &kCoverPass;
  46. args.fCaps = &state.caps();
  47. args.fDstProxy = state.drawOpArgs().fDstProxy;
  48. args.fOutputSwizzle = state.drawOpArgs().fOutputSwizzle;
  49. return args;
  50. }
  51. const GrProcessorSet::Analysis& GrDrawPathOpBase::doProcessorAnalysis(
  52. const GrCaps& caps, const GrAppliedClip* clip, bool hasMixedSampledCoverage,
  53. GrClampType clampType) {
  54. fAnalysis = fProcessorSet.finalize(
  55. fInputColor, GrProcessorAnalysisCoverage::kNone, clip, &kCoverPass,
  56. hasMixedSampledCoverage, caps, clampType, &fInputColor);
  57. return fAnalysis;
  58. }
  59. //////////////////////////////////////////////////////////////////////////////
  60. void init_stencil_pass_settings(const GrOpFlushState& flushState,
  61. GrPathRendering::FillType fillType, GrStencilSettings* stencil) {
  62. const GrAppliedClip* appliedClip = flushState.drawOpArgs().fAppliedClip;
  63. bool stencilClip = appliedClip && appliedClip->hasStencilClip();
  64. stencil->reset(GrPathRendering::GetStencilPassSettings(fillType), stencilClip,
  65. flushState.drawOpArgs().renderTarget()->renderTargetPriv().numStencilBits());
  66. }
  67. //////////////////////////////////////////////////////////////////////////////
  68. std::unique_ptr<GrDrawOp> GrDrawPathOp::Make(GrRecordingContext* context,
  69. const SkMatrix& viewMatrix,
  70. GrPaint&& paint,
  71. GrAA aa,
  72. GrPath* path) {
  73. GrOpMemoryPool* pool = context->priv().opMemoryPool();
  74. return pool->allocate<GrDrawPathOp>(viewMatrix, std::move(paint), aa, path);
  75. }
  76. void GrDrawPathOp::onExecute(GrOpFlushState* state, const SkRect& chainBounds) {
  77. GrAppliedClip appliedClip = state->detachAppliedClip();
  78. GrPipeline::FixedDynamicState fixedDynamicState(appliedClip.scissorState().rect());
  79. GrPipeline pipeline(this->pipelineInitArgs(*state), this->detachProcessors(),
  80. std::move(appliedClip));
  81. sk_sp<GrPathProcessor> pathProc(GrPathProcessor::Create(this->color(), this->viewMatrix()));
  82. GrStencilSettings stencil;
  83. init_stencil_pass_settings(*state, this->fillType(), &stencil);
  84. state->gpu()->pathRendering()->drawPath(state->drawOpArgs().renderTarget(),
  85. state->drawOpArgs().origin(),
  86. *pathProc, pipeline, fixedDynamicState, stencil,
  87. fPath.get());
  88. }
  89. //////////////////////////////////////////////////////////////////////////////
  90. inline void pre_translate_transform_values(const float* xforms,
  91. GrPathRendering::PathTransformType type, int count,
  92. SkScalar x, SkScalar y, float* dst) {
  93. if (0 == x && 0 == y) {
  94. memcpy(dst, xforms, count * GrPathRendering::PathTransformSize(type) * sizeof(float));
  95. return;
  96. }
  97. switch (type) {
  98. case GrPathRendering::kNone_PathTransformType:
  99. SK_ABORT("Cannot pre-translate kNone_PathTransformType.");
  100. break;
  101. case GrPathRendering::kTranslateX_PathTransformType:
  102. SkASSERT(0 == y);
  103. for (int i = 0; i < count; i++) {
  104. dst[i] = xforms[i] + x;
  105. }
  106. break;
  107. case GrPathRendering::kTranslateY_PathTransformType:
  108. SkASSERT(0 == x);
  109. for (int i = 0; i < count; i++) {
  110. dst[i] = xforms[i] + y;
  111. }
  112. break;
  113. case GrPathRendering::kTranslate_PathTransformType:
  114. for (int i = 0; i < 2 * count; i += 2) {
  115. dst[i] = xforms[i] + x;
  116. dst[i + 1] = xforms[i + 1] + y;
  117. }
  118. break;
  119. case GrPathRendering::kAffine_PathTransformType:
  120. for (int i = 0; i < 6 * count; i += 6) {
  121. dst[i] = xforms[i];
  122. dst[i + 1] = xforms[i + 1];
  123. dst[i + 2] = xforms[i] * x + xforms[i + 1] * y + xforms[i + 2];
  124. dst[i + 3] = xforms[i + 3];
  125. dst[i + 4] = xforms[i + 4];
  126. dst[i + 5] = xforms[i + 3] * x + xforms[i + 4] * y + xforms[i + 5];
  127. }
  128. break;
  129. default:
  130. SK_ABORT("Unknown transform type.");
  131. break;
  132. }
  133. }