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