blob: 8d02106c2d77ba95eebabafaa4bc7facad01c4e1 [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 Osmancf860852018-10-31 14:04:39 -040019 , fInputColor(paint.getColor4f())
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 Osman9a390ac2018-11-12 09:47:48 -050024#ifdef SK_DEBUG
Brian Salomon82c263f2016-12-15 09:54:06 -050025SkString GrDrawPathOp::dumpInfo() const {
bsalomon1fcc01c2015-09-09 09:48:06 -070026 SkString string;
stephana1dc17212016-04-25 07:01:22 -070027 string.printf("PATH: 0x%p", fPath.get());
robertphillips44fbc792016-06-29 06:56:12 -070028 string.append(INHERITED::dumpInfo());
bsalomon1fcc01c2015-09-09 09:48:06 -070029 return string;
30}
Brian Osman9a390ac2018-11-12 09:47:48 -050031#endif
bsalomon1fcc01c2015-09-09 09:48:06 -070032
Brian Salomon972b2f62017-07-31 12:37:02 -040033GrPipeline::InitArgs GrDrawPathOpBase::pipelineInitArgs(const GrOpFlushState& state) {
Brian Salomon54d212e2017-03-21 14:22:38 -040034 static constexpr GrUserStencilSettings kCoverPass{
35 GrUserStencilSettings::StaticInit<
36 0x0000,
37 GrUserStencilTest::kNotEqual,
38 0xffff,
39 GrUserStencilOp::kZero,
40 GrUserStencilOp::kKeep,
41 0xffff>()
42 };
43 GrPipeline::InitArgs args;
Brian Salomon611572c2017-04-28 08:57:12 -040044 if (GrAATypeIsHW(fAAType)) {
45 args.fFlags |= GrPipeline::kHWAntialias_Flag;
46 }
Brian Salomon54d212e2017-03-21 14:22:38 -040047 args.fUserStencil = &kCoverPass;
Brian Salomon54d212e2017-03-21 14:22:38 -040048 args.fCaps = &state.caps();
Robert Phillips9bee2e52017-05-29 12:37:20 -040049 args.fResourceProvider = state.resourceProvider();
Robert Phillipsbb581ce2017-05-29 15:05:15 -040050 args.fDstProxy = state.drawOpArgs().fDstProxy;
Brian Salomon972b2f62017-07-31 12:37:02 -040051 return args;
Brian Salomon2bf4b3a2017-03-16 14:19:07 -040052}
53
Brian Salomon54d212e2017-03-21 14:22:38 -040054//////////////////////////////////////////////////////////////////////////////
55
56void init_stencil_pass_settings(const GrOpFlushState& flushState,
57 GrPathRendering::FillType fillType, GrStencilSettings* stencil) {
58 const GrAppliedClip* appliedClip = flushState.drawOpArgs().fAppliedClip;
59 bool stencilClip = appliedClip && appliedClip->hasStencilClip();
60 stencil->reset(GrPathRendering::GetStencilPassSettings(fillType), stencilClip,
Robert Phillips2890fbf2017-07-26 15:48:41 -040061 flushState.drawOpArgs().renderTarget()->renderTargetPriv().numStencilBits());
Brian Salomon54d212e2017-03-21 14:22:38 -040062}
63
64//////////////////////////////////////////////////////////////////////////////
65
Robert Phillips7c525e62018-06-12 10:11:12 -040066std::unique_ptr<GrDrawOp> GrDrawPathOp::Make(GrContext* context,
67 const SkMatrix& viewMatrix,
68 GrPaint&& paint,
69 GrAAType aaType,
70 GrPath* path) {
Robert Phillipsc994a932018-06-19 13:09:54 -040071 GrOpMemoryPool* pool = context->contextPriv().opMemoryPool();
72
73 return pool->allocate<GrDrawPathOp>(viewMatrix, std::move(paint), aaType, path);
Robert Phillips7c525e62018-06-12 10:11:12 -040074}
75
Brian Salomon588cec72018-11-14 13:56:37 -050076void GrDrawPathOp::onExecute(GrOpFlushState* state, const SkRect& chainBounds) {
Brian Salomon49348902018-06-26 09:12:38 -040077 GrAppliedClip appliedClip = state->detachAppliedClip();
78 GrPipeline::FixedDynamicState fixedDynamicState(appliedClip.scissorState().rect());
Brian Salomonbfd18cd2017-08-09 16:27:09 -040079 GrPipeline pipeline(this->pipelineInitArgs(*state), this->detachProcessors(),
Brian Salomon49348902018-06-26 09:12:38 -040080 std::move(appliedClip));
Brian Salomone7d30482017-03-29 12:09:15 -040081 sk_sp<GrPathProcessor> pathProc(GrPathProcessor::Create(this->color(), this->viewMatrix()));
Brian Salomon54d212e2017-03-21 14:22:38 -040082
83 GrStencilSettings stencil;
84 init_stencil_pass_settings(*state, this->fillType(), &stencil);
Robert Phillipsd0fe8752019-01-31 14:13:59 -050085 state->gpu()->pathRendering()->drawPath(state->drawOpArgs().renderTarget(),
86 state->drawOpArgs().origin(),
87 *pathProc, pipeline, fixedDynamicState, stencil,
Brian Salomon49348902018-06-26 09:12:38 -040088 fPath.get());
Brian Salomon54d212e2017-03-21 14:22:38 -040089}
90
91//////////////////////////////////////////////////////////////////////////////
92
cdaltoncdd46822015-12-08 10:48:31 -080093inline void pre_translate_transform_values(const float* xforms,
94 GrPathRendering::PathTransformType type, int count,
95 SkScalar x, SkScalar y, float* dst) {
96 if (0 == x && 0 == y) {
97 memcpy(dst, xforms, count * GrPathRendering::PathTransformSize(type) * sizeof(float));
bsalomon1fcc01c2015-09-09 09:48:06 -070098 return;
99 }
cdaltoncdd46822015-12-08 10:48:31 -0800100 switch (type) {
101 case GrPathRendering::kNone_PathTransformType:
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400102 SK_ABORT("Cannot pre-translate kNone_PathTransformType.");
cdaltoncdd46822015-12-08 10:48:31 -0800103 break;
104 case GrPathRendering::kTranslateX_PathTransformType:
105 SkASSERT(0 == y);
106 for (int i = 0; i < count; i++) {
107 dst[i] = xforms[i] + x;
108 }
109 break;
110 case GrPathRendering::kTranslateY_PathTransformType:
111 SkASSERT(0 == x);
112 for (int i = 0; i < count; i++) {
113 dst[i] = xforms[i] + y;
114 }
115 break;
116 case GrPathRendering::kTranslate_PathTransformType:
117 for (int i = 0; i < 2 * count; i += 2) {
118 dst[i] = xforms[i] + x;
119 dst[i + 1] = xforms[i + 1] + y;
120 }
121 break;
122 case GrPathRendering::kAffine_PathTransformType:
123 for (int i = 0; i < 6 * count; i += 6) {
124 dst[i] = xforms[i];
125 dst[i + 1] = xforms[i + 1];
126 dst[i + 2] = xforms[i] * x + xforms[i + 1] * y + xforms[i + 2];
127 dst[i + 3] = xforms[i + 3];
128 dst[i + 4] = xforms[i + 4];
129 dst[i + 5] = xforms[i + 3] * x + xforms[i + 4] * y + xforms[i + 5];
130 }
131 break;
132 default:
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400133 SK_ABORT("Unknown transform type.");
cdaltoncdd46822015-12-08 10:48:31 -0800134 break;
bsalomon1fcc01c2015-09-09 09:48:06 -0700135 }
bsalomon1fcc01c2015-09-09 09:48:06 -0700136}