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" |
| 12 | #include "src/gpu/GrRecordingContextPriv.h" |
| 13 | #include "src/gpu/GrRenderTargetContext.h" |
| 14 | #include "src/gpu/GrRenderTargetPriv.h" |
| 15 | #include "src/gpu/ops/GrDrawPathOp.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; |
Greg Daniel | 2c3398d | 2019-06-19 11:58:01 -0400 | [diff] [blame^] | 54 | args.fOutputSwizzle = state.drawOpArgs().fOutputSwizzle; |
Brian Salomon | 972b2f6 | 2017-07-31 12:37:02 -0400 | [diff] [blame] | 55 | return args; |
Brian Salomon | 2bf4b3a | 2017-03-16 14:19:07 -0400 | [diff] [blame] | 56 | } |
| 57 | |
Chris Dalton | b8fff0d | 2019-03-05 10:11:58 -0700 | [diff] [blame] | 58 | const GrProcessorSet::Analysis& GrDrawPathOpBase::doProcessorAnalysis( |
Brian Osman | 5ced0bf | 2019-03-15 10:15:29 -0400 | [diff] [blame] | 59 | const GrCaps& caps, const GrAppliedClip* clip, GrFSAAType fsaaType, |
| 60 | GrClampType clampType) { |
Chris Dalton | b8fff0d | 2019-03-05 10:11:58 -0700 | [diff] [blame] | 61 | fAnalysis = fProcessorSet.finalize( |
| 62 | fInputColor, GrProcessorAnalysisCoverage::kNone, clip, &kCoverPass, fsaaType, caps, |
Brian Osman | 5ced0bf | 2019-03-15 10:15:29 -0400 | [diff] [blame] | 63 | clampType, &fInputColor); |
Chris Dalton | b8fff0d | 2019-03-05 10:11:58 -0700 | [diff] [blame] | 64 | return fAnalysis; |
| 65 | } |
| 66 | |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 67 | ////////////////////////////////////////////////////////////////////////////// |
| 68 | |
| 69 | void init_stencil_pass_settings(const GrOpFlushState& flushState, |
| 70 | GrPathRendering::FillType fillType, GrStencilSettings* stencil) { |
| 71 | const GrAppliedClip* appliedClip = flushState.drawOpArgs().fAppliedClip; |
| 72 | bool stencilClip = appliedClip && appliedClip->hasStencilClip(); |
| 73 | stencil->reset(GrPathRendering::GetStencilPassSettings(fillType), stencilClip, |
Robert Phillips | 2890fbf | 2017-07-26 15:48:41 -0400 | [diff] [blame] | 74 | flushState.drawOpArgs().renderTarget()->renderTargetPriv().numStencilBits()); |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | ////////////////////////////////////////////////////////////////////////////// |
| 78 | |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 79 | std::unique_ptr<GrDrawOp> GrDrawPathOp::Make(GrRecordingContext* context, |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 80 | const SkMatrix& viewMatrix, |
| 81 | GrPaint&& paint, |
Chris Dalton | 09e5689 | 2019-03-13 00:22:01 -0600 | [diff] [blame] | 82 | GrAA aa, |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 83 | GrPath* path) { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 84 | GrOpMemoryPool* pool = context->priv().opMemoryPool(); |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 85 | |
Chris Dalton | 09e5689 | 2019-03-13 00:22:01 -0600 | [diff] [blame] | 86 | return pool->allocate<GrDrawPathOp>(viewMatrix, std::move(paint), aa, path); |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 87 | } |
| 88 | |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 89 | void GrDrawPathOp::onExecute(GrOpFlushState* state, const SkRect& chainBounds) { |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 90 | GrAppliedClip appliedClip = state->detachAppliedClip(); |
| 91 | GrPipeline::FixedDynamicState fixedDynamicState(appliedClip.scissorState().rect()); |
Brian Salomon | bfd18cd | 2017-08-09 16:27:09 -0400 | [diff] [blame] | 92 | GrPipeline pipeline(this->pipelineInitArgs(*state), this->detachProcessors(), |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 93 | std::move(appliedClip)); |
Brian Salomon | e7d3048 | 2017-03-29 12:09:15 -0400 | [diff] [blame] | 94 | sk_sp<GrPathProcessor> pathProc(GrPathProcessor::Create(this->color(), this->viewMatrix())); |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 95 | |
| 96 | GrStencilSettings stencil; |
| 97 | init_stencil_pass_settings(*state, this->fillType(), &stencil); |
Robert Phillips | d0fe875 | 2019-01-31 14:13:59 -0500 | [diff] [blame] | 98 | state->gpu()->pathRendering()->drawPath(state->drawOpArgs().renderTarget(), |
| 99 | state->drawOpArgs().origin(), |
| 100 | *pathProc, pipeline, fixedDynamicState, stencil, |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 101 | fPath.get()); |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | ////////////////////////////////////////////////////////////////////////////// |
| 105 | |
cdalton | cdd4682 | 2015-12-08 10:48:31 -0800 | [diff] [blame] | 106 | inline void pre_translate_transform_values(const float* xforms, |
| 107 | GrPathRendering::PathTransformType type, int count, |
| 108 | SkScalar x, SkScalar y, float* dst) { |
| 109 | if (0 == x && 0 == y) { |
| 110 | memcpy(dst, xforms, count * GrPathRendering::PathTransformSize(type) * sizeof(float)); |
bsalomon | 1fcc01c | 2015-09-09 09:48:06 -0700 | [diff] [blame] | 111 | return; |
| 112 | } |
cdalton | cdd4682 | 2015-12-08 10:48:31 -0800 | [diff] [blame] | 113 | switch (type) { |
| 114 | case GrPathRendering::kNone_PathTransformType: |
Ben Wagner | b4aab9a | 2017-08-16 10:53:04 -0400 | [diff] [blame] | 115 | SK_ABORT("Cannot pre-translate kNone_PathTransformType."); |
cdalton | cdd4682 | 2015-12-08 10:48:31 -0800 | [diff] [blame] | 116 | break; |
| 117 | case GrPathRendering::kTranslateX_PathTransformType: |
| 118 | SkASSERT(0 == y); |
| 119 | for (int i = 0; i < count; i++) { |
| 120 | dst[i] = xforms[i] + x; |
| 121 | } |
| 122 | break; |
| 123 | case GrPathRendering::kTranslateY_PathTransformType: |
| 124 | SkASSERT(0 == x); |
| 125 | for (int i = 0; i < count; i++) { |
| 126 | dst[i] = xforms[i] + y; |
| 127 | } |
| 128 | break; |
| 129 | case GrPathRendering::kTranslate_PathTransformType: |
| 130 | for (int i = 0; i < 2 * count; i += 2) { |
| 131 | dst[i] = xforms[i] + x; |
| 132 | dst[i + 1] = xforms[i + 1] + y; |
| 133 | } |
| 134 | break; |
| 135 | case GrPathRendering::kAffine_PathTransformType: |
| 136 | for (int i = 0; i < 6 * count; i += 6) { |
| 137 | dst[i] = xforms[i]; |
| 138 | dst[i + 1] = xforms[i + 1]; |
| 139 | dst[i + 2] = xforms[i] * x + xforms[i + 1] * y + xforms[i + 2]; |
| 140 | dst[i + 3] = xforms[i + 3]; |
| 141 | dst[i + 4] = xforms[i + 4]; |
| 142 | dst[i + 5] = xforms[i + 3] * x + xforms[i + 4] * y + xforms[i + 5]; |
| 143 | } |
| 144 | break; |
| 145 | default: |
Ben Wagner | b4aab9a | 2017-08-16 10:53:04 -0400 | [diff] [blame] | 146 | SK_ABORT("Unknown transform type."); |
cdalton | cdd4682 | 2015-12-08 10:48:31 -0800 | [diff] [blame] | 147 | break; |
bsalomon | 1fcc01c | 2015-09-09 09:48:06 -0700 | [diff] [blame] | 148 | } |
bsalomon | 1fcc01c | 2015-09-09 09:48:06 -0700 | [diff] [blame] | 149 | } |