blob: cc8a86d937e3e24aae620b66ec4da90426fe5930 [file] [log] [blame]
bsalomon1fcc01c2015-09-09 09:48:06 -07001/*
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 Salomon82c263f2016-12-15 09:54:06 -05008#include "GrDrawPathOp.h"
Brian Salomon54d212e2017-03-21 14:22:38 -04009#include "GrAppliedClip.h"
Robert Phillips7c525e62018-06-12 10:11:12 -040010#include "GrMemoryPool.h"
Brian Salomon54d212e2017-03-21 14:22:38 -040011#include "GrRenderTargetContext.h"
Brian Salomonc48af932017-03-16 19:51:42 +000012#include "GrRenderTargetPriv.h"
Brian Salomon54d212e2017-03-21 14:22:38 -040013#include "SkTemplates.h"
Brian Salomonc48af932017-03-16 19:51:42 +000014
Brian Salomon54d212e2017-03-21 14:22:38 -040015GrDrawPathOpBase::GrDrawPathOpBase(uint32_t classID, const SkMatrix& viewMatrix, GrPaint&& paint,
Brian Salomon48d1b4c2017-04-08 07:38:53 -040016 GrPathRendering::FillType fill, GrAAType aaType)
Brian Salomon54d212e2017-03-21 14:22:38 -040017 : INHERITED(classID)
18 , fViewMatrix(viewMatrix)
Brian Salomon48d1b4c2017-04-08 07:38:53 -040019 , fInputColor(paint.getColor())
Brian Salomon54d212e2017-03-21 14:22:38 -040020 , fFillType(fill)
Brian Salomon611572c2017-04-28 08:57:12 -040021 , fAAType(aaType)
Brian Salomon611572c2017-04-28 08:57:12 -040022 , fProcessorSet(std::move(paint)) {}
cdalton193d9cf2016-05-12 11:52:02 -070023
Brian Salomon82c263f2016-12-15 09:54:06 -050024SkString GrDrawPathOp::dumpInfo() const {
bsalomon1fcc01c2015-09-09 09:48:06 -070025 SkString string;
stephana1dc17212016-04-25 07:01:22 -070026 string.printf("PATH: 0x%p", fPath.get());
robertphillips44fbc792016-06-29 06:56:12 -070027 string.append(INHERITED::dumpInfo());
bsalomon1fcc01c2015-09-09 09:48:06 -070028 return string;
29}
30
Brian Salomon972b2f62017-07-31 12:37:02 -040031GrPipeline::InitArgs GrDrawPathOpBase::pipelineInitArgs(const GrOpFlushState& state) {
Brian Salomon54d212e2017-03-21 14:22:38 -040032 static constexpr GrUserStencilSettings kCoverPass{
33 GrUserStencilSettings::StaticInit<
34 0x0000,
35 GrUserStencilTest::kNotEqual,
36 0xffff,
37 GrUserStencilOp::kZero,
38 GrUserStencilOp::kKeep,
39 0xffff>()
40 };
41 GrPipeline::InitArgs args;
Brian Salomon611572c2017-04-28 08:57:12 -040042 if (GrAATypeIsHW(fAAType)) {
43 args.fFlags |= GrPipeline::kHWAntialias_Flag;
44 }
Brian Salomon54d212e2017-03-21 14:22:38 -040045 args.fUserStencil = &kCoverPass;
Robert Phillips2890fbf2017-07-26 15:48:41 -040046 args.fProxy = state.drawOpArgs().fProxy;
Brian Salomon54d212e2017-03-21 14:22:38 -040047 args.fCaps = &state.caps();
Robert Phillips9bee2e52017-05-29 12:37:20 -040048 args.fResourceProvider = state.resourceProvider();
Robert Phillipsbb581ce2017-05-29 15:05:15 -040049 args.fDstProxy = state.drawOpArgs().fDstProxy;
Brian Salomon972b2f62017-07-31 12:37:02 -040050 return args;
Brian Salomon2bf4b3a2017-03-16 14:19:07 -040051}
52
Brian Salomon54d212e2017-03-21 14:22:38 -040053//////////////////////////////////////////////////////////////////////////////
54
55void init_stencil_pass_settings(const GrOpFlushState& flushState,
56 GrPathRendering::FillType fillType, GrStencilSettings* stencil) {
57 const GrAppliedClip* appliedClip = flushState.drawOpArgs().fAppliedClip;
58 bool stencilClip = appliedClip && appliedClip->hasStencilClip();
59 stencil->reset(GrPathRendering::GetStencilPassSettings(fillType), stencilClip,
Robert Phillips2890fbf2017-07-26 15:48:41 -040060 flushState.drawOpArgs().renderTarget()->renderTargetPriv().numStencilBits());
Brian Salomon54d212e2017-03-21 14:22:38 -040061}
62
63//////////////////////////////////////////////////////////////////////////////
64
Robert Phillips7c525e62018-06-12 10:11:12 -040065std::unique_ptr<GrDrawOp> GrDrawPathOp::Make(GrContext* context,
66 const SkMatrix& viewMatrix,
67 GrPaint&& paint,
68 GrAAType aaType,
69 GrPath* path) {
Robert Phillipsc994a932018-06-19 13:09:54 -040070 GrOpMemoryPool* pool = context->contextPriv().opMemoryPool();
71
72 return pool->allocate<GrDrawPathOp>(viewMatrix, std::move(paint), aaType, path);
Robert Phillips7c525e62018-06-12 10:11:12 -040073}
74
Brian Salomon54d212e2017-03-21 14:22:38 -040075void GrDrawPathOp::onExecute(GrOpFlushState* state) {
Brian Salomon49348902018-06-26 09:12:38 -040076 GrAppliedClip appliedClip = state->detachAppliedClip();
77 GrPipeline::FixedDynamicState fixedDynamicState(appliedClip.scissorState().rect());
Brian Salomonbfd18cd2017-08-09 16:27:09 -040078 GrPipeline pipeline(this->pipelineInitArgs(*state), this->detachProcessors(),
Brian Salomon49348902018-06-26 09:12:38 -040079 std::move(appliedClip));
Brian Salomone7d30482017-03-29 12:09:15 -040080 sk_sp<GrPathProcessor> pathProc(GrPathProcessor::Create(this->color(), this->viewMatrix()));
Brian Salomon54d212e2017-03-21 14:22:38 -040081
82 GrStencilSettings stencil;
83 init_stencil_pass_settings(*state, this->fillType(), &stencil);
Brian Salomon49348902018-06-26 09:12:38 -040084 state->gpu()->pathRendering()->drawPath(*pathProc, pipeline, fixedDynamicState, stencil,
85 fPath.get());
Brian Salomon54d212e2017-03-21 14:22:38 -040086}
87
88//////////////////////////////////////////////////////////////////////////////
89
cdaltoncdd46822015-12-08 10:48:31 -080090inline 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));
bsalomon1fcc01c2015-09-09 09:48:06 -070095 return;
96 }
cdaltoncdd46822015-12-08 10:48:31 -080097 switch (type) {
98 case GrPathRendering::kNone_PathTransformType:
Ben Wagnerb4aab9a2017-08-16 10:53:04 -040099 SK_ABORT("Cannot pre-translate kNone_PathTransformType.");
cdaltoncdd46822015-12-08 10:48:31 -0800100 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:
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400130 SK_ABORT("Unknown transform type.");
cdaltoncdd46822015-12-08 10:48:31 -0800131 break;
bsalomon1fcc01c2015-09-09 09:48:06 -0700132 }
bsalomon1fcc01c2015-09-09 09:48:06 -0700133}