blob: f038a038c0b460a1403f2839b0c7d9ec77eda31a [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;
Robert Phillips2890fbf2017-07-26 15:48:41 -040048 args.fProxy = state.drawOpArgs().fProxy;
Brian Salomon54d212e2017-03-21 14:22:38 -040049 args.fCaps = &state.caps();
Robert Phillips9bee2e52017-05-29 12:37:20 -040050 args.fResourceProvider = state.resourceProvider();
Robert Phillipsbb581ce2017-05-29 15:05:15 -040051 args.fDstProxy = state.drawOpArgs().fDstProxy;
Brian Salomon972b2f62017-07-31 12:37:02 -040052 return args;
Brian Salomon2bf4b3a2017-03-16 14:19:07 -040053}
54
Brian Salomon54d212e2017-03-21 14:22:38 -040055//////////////////////////////////////////////////////////////////////////////
56
57void init_stencil_pass_settings(const GrOpFlushState& flushState,
58 GrPathRendering::FillType fillType, GrStencilSettings* stencil) {
59 const GrAppliedClip* appliedClip = flushState.drawOpArgs().fAppliedClip;
60 bool stencilClip = appliedClip && appliedClip->hasStencilClip();
61 stencil->reset(GrPathRendering::GetStencilPassSettings(fillType), stencilClip,
Robert Phillips2890fbf2017-07-26 15:48:41 -040062 flushState.drawOpArgs().renderTarget()->renderTargetPriv().numStencilBits());
Brian Salomon54d212e2017-03-21 14:22:38 -040063}
64
65//////////////////////////////////////////////////////////////////////////////
66
Robert Phillips7c525e62018-06-12 10:11:12 -040067std::unique_ptr<GrDrawOp> GrDrawPathOp::Make(GrContext* context,
68 const SkMatrix& viewMatrix,
69 GrPaint&& paint,
70 GrAAType aaType,
71 GrPath* path) {
Robert Phillipsc994a932018-06-19 13:09:54 -040072 GrOpMemoryPool* pool = context->contextPriv().opMemoryPool();
73
74 return pool->allocate<GrDrawPathOp>(viewMatrix, std::move(paint), aaType, path);
Robert Phillips7c525e62018-06-12 10:11:12 -040075}
76
Brian Salomon588cec72018-11-14 13:56:37 -050077void GrDrawPathOp::onExecute(GrOpFlushState* state, const SkRect& chainBounds) {
Brian Salomon49348902018-06-26 09:12:38 -040078 GrAppliedClip appliedClip = state->detachAppliedClip();
79 GrPipeline::FixedDynamicState fixedDynamicState(appliedClip.scissorState().rect());
Brian Salomonbfd18cd2017-08-09 16:27:09 -040080 GrPipeline pipeline(this->pipelineInitArgs(*state), this->detachProcessors(),
Brian Salomon49348902018-06-26 09:12:38 -040081 std::move(appliedClip));
Brian Salomone7d30482017-03-29 12:09:15 -040082 sk_sp<GrPathProcessor> pathProc(GrPathProcessor::Create(this->color(), this->viewMatrix()));
Brian Salomon54d212e2017-03-21 14:22:38 -040083
84 GrStencilSettings stencil;
85 init_stencil_pass_settings(*state, this->fillType(), &stencil);
Brian Salomon49348902018-06-26 09:12:38 -040086 state->gpu()->pathRendering()->drawPath(*pathProc, pipeline, fixedDynamicState, stencil,
87 fPath.get());
Brian Salomon54d212e2017-03-21 14:22:38 -040088}
89
90//////////////////////////////////////////////////////////////////////////////
91
cdaltoncdd46822015-12-08 10:48:31 -080092inline void pre_translate_transform_values(const float* xforms,
93 GrPathRendering::PathTransformType type, int count,
94 SkScalar x, SkScalar y, float* dst) {
95 if (0 == x && 0 == y) {
96 memcpy(dst, xforms, count * GrPathRendering::PathTransformSize(type) * sizeof(float));
bsalomon1fcc01c2015-09-09 09:48:06 -070097 return;
98 }
cdaltoncdd46822015-12-08 10:48:31 -080099 switch (type) {
100 case GrPathRendering::kNone_PathTransformType:
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400101 SK_ABORT("Cannot pre-translate kNone_PathTransformType.");
cdaltoncdd46822015-12-08 10:48:31 -0800102 break;
103 case GrPathRendering::kTranslateX_PathTransformType:
104 SkASSERT(0 == y);
105 for (int i = 0; i < count; i++) {
106 dst[i] = xforms[i] + x;
107 }
108 break;
109 case GrPathRendering::kTranslateY_PathTransformType:
110 SkASSERT(0 == x);
111 for (int i = 0; i < count; i++) {
112 dst[i] = xforms[i] + y;
113 }
114 break;
115 case GrPathRendering::kTranslate_PathTransformType:
116 for (int i = 0; i < 2 * count; i += 2) {
117 dst[i] = xforms[i] + x;
118 dst[i + 1] = xforms[i + 1] + y;
119 }
120 break;
121 case GrPathRendering::kAffine_PathTransformType:
122 for (int i = 0; i < 6 * count; i += 6) {
123 dst[i] = xforms[i];
124 dst[i + 1] = xforms[i + 1];
125 dst[i + 2] = xforms[i] * x + xforms[i + 1] * y + xforms[i + 2];
126 dst[i + 3] = xforms[i + 3];
127 dst[i + 4] = xforms[i + 4];
128 dst[i + 5] = xforms[i + 3] * x + xforms[i + 4] * y + xforms[i + 5];
129 }
130 break;
131 default:
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400132 SK_ABORT("Unknown transform type.");
cdaltoncdd46822015-12-08 10:48:31 -0800133 break;
bsalomon1fcc01c2015-09-09 09:48:06 -0700134 }
bsalomon1fcc01c2015-09-09 09:48:06 -0700135}