bsalomon | 1fcc01c | 2015-09-09 09:48:06 -0700 | [diff] [blame] | 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/private/GrRecordingContext.h" |
| 9 | #include "include/private/SkTemplates.h" |
| 10 | #include "src/gpu/GrAppliedClip.h" |
| 11 | #include "src/gpu/GrMemoryPool.h" |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 12 | #include "src/gpu/GrProgramInfo.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 13 | #include "src/gpu/GrRecordingContextPriv.h" |
| 14 | #include "src/gpu/GrRenderTargetContext.h" |
| 15 | #include "src/gpu/GrRenderTargetPriv.h" |
| 16 | #include "src/gpu/ops/GrDrawPathOp.h" |
Robert Phillips | 3968fcb | 2019-12-05 16:40:31 -0500 | [diff] [blame] | 17 | #include "src/gpu/ops/GrSimpleMeshDrawOpHelper.h" |
Brian Salomon | c48af93 | 2017-03-16 19:51:42 +0000 | [diff] [blame] | 18 | |
Chris Dalton | b8fff0d | 2019-03-05 10:11:58 -0700 | [diff] [blame] | 19 | static constexpr GrUserStencilSettings kCoverPass{ |
| 20 | GrUserStencilSettings::StaticInit< |
| 21 | 0x0000, |
| 22 | GrUserStencilTest::kNotEqual, |
| 23 | 0xffff, |
| 24 | GrUserStencilOp::kZero, |
| 25 | GrUserStencilOp::kKeep, |
| 26 | 0xffff>() |
| 27 | }; |
| 28 | |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 29 | GrDrawPathOpBase::GrDrawPathOpBase(uint32_t classID, const SkMatrix& viewMatrix, GrPaint&& paint, |
Chris Dalton | 09e5689 | 2019-03-13 00:22:01 -0600 | [diff] [blame] | 30 | GrPathRendering::FillType fill, GrAA aa) |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 31 | : INHERITED(classID) |
| 32 | , fViewMatrix(viewMatrix) |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 33 | , fInputColor(paint.getColor4f()) |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 34 | , fFillType(fill) |
Chris Dalton | 09e5689 | 2019-03-13 00:22:01 -0600 | [diff] [blame] | 35 | , fDoAA(GrAA::kYes == aa) |
Brian Salomon | 611572c | 2017-04-28 08:57:12 -0400 | [diff] [blame] | 36 | , fProcessorSet(std::move(paint)) {} |
cdalton | 193d9cf | 2016-05-12 11:52:02 -0700 | [diff] [blame] | 37 | |
Brian Osman | 9a390ac | 2018-11-12 09:47:48 -0500 | [diff] [blame] | 38 | #ifdef SK_DEBUG |
Brian Salomon | 82c263f | 2016-12-15 09:54:06 -0500 | [diff] [blame] | 39 | SkString GrDrawPathOp::dumpInfo() const { |
bsalomon | 1fcc01c | 2015-09-09 09:48:06 -0700 | [diff] [blame] | 40 | SkString string; |
stephana | 1dc1721 | 2016-04-25 07:01:22 -0700 | [diff] [blame] | 41 | string.printf("PATH: 0x%p", fPath.get()); |
robertphillips | 44fbc79 | 2016-06-29 06:56:12 -0700 | [diff] [blame] | 42 | string.append(INHERITED::dumpInfo()); |
bsalomon | 1fcc01c | 2015-09-09 09:48:06 -0700 | [diff] [blame] | 43 | return string; |
| 44 | } |
Brian Osman | 9a390ac | 2018-11-12 09:47:48 -0500 | [diff] [blame] | 45 | #endif |
bsalomon | 1fcc01c | 2015-09-09 09:48:06 -0700 | [diff] [blame] | 46 | |
Chris Dalton | b8fff0d | 2019-03-05 10:11:58 -0700 | [diff] [blame] | 47 | const GrProcessorSet::Analysis& GrDrawPathOpBase::doProcessorAnalysis( |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 48 | const GrCaps& caps, const GrAppliedClip* clip, bool hasMixedSampledCoverage, |
Brian Osman | 5ced0bf | 2019-03-15 10:15:29 -0400 | [diff] [blame] | 49 | GrClampType clampType) { |
Chris Dalton | b8fff0d | 2019-03-05 10:11:58 -0700 | [diff] [blame] | 50 | fAnalysis = fProcessorSet.finalize( |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 51 | fInputColor, GrProcessorAnalysisCoverage::kNone, clip, &kCoverPass, |
| 52 | hasMixedSampledCoverage, caps, clampType, &fInputColor); |
Chris Dalton | b8fff0d | 2019-03-05 10:11:58 -0700 | [diff] [blame] | 53 | return fAnalysis; |
| 54 | } |
| 55 | |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 56 | ////////////////////////////////////////////////////////////////////////////// |
| 57 | |
| 58 | void init_stencil_pass_settings(const GrOpFlushState& flushState, |
| 59 | GrPathRendering::FillType fillType, GrStencilSettings* stencil) { |
Robert Phillips | 405413f | 2019-10-04 10:39:28 -0400 | [diff] [blame] | 60 | const GrAppliedClip* appliedClip = flushState.drawOpArgs().appliedClip(); |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 61 | bool stencilClip = appliedClip && appliedClip->hasStencilClip(); |
Chris Dalton | 5e8cdfd | 2019-11-11 15:23:30 -0700 | [diff] [blame] | 62 | GrRenderTarget* rt = flushState.drawOpArgs().proxy()->peekRenderTarget(); |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 63 | stencil->reset(GrPathRendering::GetStencilPassSettings(fillType), stencilClip, |
Chris Dalton | 5e8cdfd | 2019-11-11 15:23:30 -0700 | [diff] [blame] | 64 | rt->renderTargetPriv().numStencilBits()); |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | ////////////////////////////////////////////////////////////////////////////// |
| 68 | |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 69 | std::unique_ptr<GrDrawOp> GrDrawPathOp::Make(GrRecordingContext* context, |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 70 | const SkMatrix& viewMatrix, |
| 71 | GrPaint&& paint, |
Chris Dalton | 09e5689 | 2019-03-13 00:22:01 -0600 | [diff] [blame] | 72 | GrAA aa, |
Robert Phillips | e1efd38 | 2019-08-21 10:07:10 -0400 | [diff] [blame] | 73 | sk_sp<const GrPath> path) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 74 | GrOpMemoryPool* pool = context->priv().opMemoryPool(); |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 75 | |
Robert Phillips | e1efd38 | 2019-08-21 10:07:10 -0400 | [diff] [blame] | 76 | return pool->allocate<GrDrawPathOp>(viewMatrix, std::move(paint), aa, std::move(path)); |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 77 | } |
| 78 | |
Robert Phillips | 3968fcb | 2019-12-05 16:40:31 -0500 | [diff] [blame] | 79 | void GrDrawPathOp::onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) { |
Robert Phillips | 3968fcb | 2019-12-05 16:40:31 -0500 | [diff] [blame] | 80 | GrPipeline::InputFlags pipelineFlags = GrPipeline::InputFlags::kNone; |
| 81 | if (this->doAA()) { |
| 82 | pipelineFlags |= GrPipeline::InputFlags::kHWAntialias; |
| 83 | } |
| 84 | |
| 85 | auto pipeline = GrSimpleMeshDrawOpHelper::CreatePipeline(flushState, |
| 86 | this->detachProcessorSet(), |
| 87 | pipelineFlags, |
| 88 | &kCoverPass); |
| 89 | |
Brian Salomon | e7d3048 | 2017-03-29 12:09:15 -0400 | [diff] [blame] | 90 | sk_sp<GrPathProcessor> pathProc(GrPathProcessor::Create(this->color(), this->viewMatrix())); |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 91 | |
Robert Phillips | 3968fcb | 2019-12-05 16:40:31 -0500 | [diff] [blame] | 92 | GrRenderTargetProxy* proxy = flushState->proxy(); |
| 93 | GrProgramInfo programInfo(proxy->numSamples(), |
| 94 | proxy->numStencilSamples(), |
| 95 | proxy->backendFormat(), |
Brian Salomon | 8afde5f | 2020-04-01 16:22:00 -0400 | [diff] [blame^] | 96 | flushState->writeView()->origin(), |
Robert Phillips | 3968fcb | 2019-12-05 16:40:31 -0500 | [diff] [blame] | 97 | pipeline, |
Robert Phillips | 67a625e | 2019-11-15 15:37:07 -0500 | [diff] [blame] | 98 | pathProc.get(), |
Robert Phillips | cea290f | 2019-11-06 11:21:03 -0500 | [diff] [blame] | 99 | GrPrimitiveType::kPath); |
Robert Phillips | 901aff0 | 2019-10-08 12:32:56 -0400 | [diff] [blame] | 100 | |
Chris Dalton | 304e14d | 2020-03-17 14:29:06 -0600 | [diff] [blame] | 101 | flushState->bindPipelineAndScissorClip(programInfo, this->bounds()); |
| 102 | flushState->bindTextures(programInfo.primProc(), nullptr, programInfo.pipeline()); |
| 103 | |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 104 | GrStencilSettings stencil; |
Robert Phillips | 3968fcb | 2019-12-05 16:40:31 -0500 | [diff] [blame] | 105 | init_stencil_pass_settings(*flushState, this->fillType(), &stencil); |
| 106 | flushState->gpu()->pathRendering()->drawPath(proxy->peekRenderTarget(), |
| 107 | programInfo, stencil, fPath.get()); |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | ////////////////////////////////////////////////////////////////////////////// |
| 111 | |
cdalton | cdd4682 | 2015-12-08 10:48:31 -0800 | [diff] [blame] | 112 | inline void pre_translate_transform_values(const float* xforms, |
| 113 | GrPathRendering::PathTransformType type, int count, |
| 114 | SkScalar x, SkScalar y, float* dst) { |
| 115 | if (0 == x && 0 == y) { |
| 116 | memcpy(dst, xforms, count * GrPathRendering::PathTransformSize(type) * sizeof(float)); |
bsalomon | 1fcc01c | 2015-09-09 09:48:06 -0700 | [diff] [blame] | 117 | return; |
| 118 | } |
cdalton | cdd4682 | 2015-12-08 10:48:31 -0800 | [diff] [blame] | 119 | switch (type) { |
| 120 | case GrPathRendering::kNone_PathTransformType: |
Ben Wagner | b4aab9a | 2017-08-16 10:53:04 -0400 | [diff] [blame] | 121 | SK_ABORT("Cannot pre-translate kNone_PathTransformType."); |
cdalton | cdd4682 | 2015-12-08 10:48:31 -0800 | [diff] [blame] | 122 | break; |
| 123 | case GrPathRendering::kTranslateX_PathTransformType: |
| 124 | SkASSERT(0 == y); |
| 125 | for (int i = 0; i < count; i++) { |
| 126 | dst[i] = xforms[i] + x; |
| 127 | } |
| 128 | break; |
| 129 | case GrPathRendering::kTranslateY_PathTransformType: |
| 130 | SkASSERT(0 == x); |
| 131 | for (int i = 0; i < count; i++) { |
| 132 | dst[i] = xforms[i] + y; |
| 133 | } |
| 134 | break; |
| 135 | case GrPathRendering::kTranslate_PathTransformType: |
| 136 | for (int i = 0; i < 2 * count; i += 2) { |
| 137 | dst[i] = xforms[i] + x; |
| 138 | dst[i + 1] = xforms[i + 1] + y; |
| 139 | } |
| 140 | break; |
| 141 | case GrPathRendering::kAffine_PathTransformType: |
| 142 | for (int i = 0; i < 6 * count; i += 6) { |
| 143 | dst[i] = xforms[i]; |
| 144 | dst[i + 1] = xforms[i + 1]; |
| 145 | dst[i + 2] = xforms[i] * x + xforms[i + 1] * y + xforms[i + 2]; |
| 146 | dst[i + 3] = xforms[i + 3]; |
| 147 | dst[i + 4] = xforms[i + 4]; |
| 148 | dst[i + 5] = xforms[i + 3] * x + xforms[i + 4] * y + xforms[i + 5]; |
| 149 | } |
| 150 | break; |
| 151 | default: |
Ben Wagner | b4aab9a | 2017-08-16 10:53:04 -0400 | [diff] [blame] | 152 | SK_ABORT("Unknown transform type."); |
cdalton | cdd4682 | 2015-12-08 10:48:31 -0800 | [diff] [blame] | 153 | break; |
bsalomon | 1fcc01c | 2015-09-09 09:48:06 -0700 | [diff] [blame] | 154 | } |
bsalomon | 1fcc01c | 2015-09-09 09:48:06 -0700 | [diff] [blame] | 155 | } |