Update rive-cpp to 2.0 version
[platform/core/uifw/rive-tizen.git] / submodule / skia / src / gpu / ganesh / ops / PathTessellateOp.cpp
1 /*
2  * Copyright 2021 Google LLC.
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
8 #include "src/gpu/ganesh/ops/PathTessellateOp.h"
9
10 #include "src/gpu/ganesh/GrAppliedClip.h"
11 #include "src/gpu/ganesh/GrOpFlushState.h"
12 #include "src/gpu/ganesh/tessellate/GrPathTessellationShader.h"
13 namespace skgpu::v1 {
14
15 void PathTessellateOp::visitProxies(const GrVisitProxyFunc& func) const {
16     if (fTessellationProgram) {
17         fTessellationProgram->pipeline().visitProxies(func);
18     } else {
19         fProcessors.visitProxies(func);
20     }
21 }
22
23 GrProcessorSet::Analysis PathTessellateOp::finalize(const GrCaps& caps,
24                                                     const GrAppliedClip* clip,
25                                                     GrClampType clampType) {
26     auto analysis = fProcessors.finalize(this->headDraw().fColor,
27                                          GrProcessorAnalysisCoverage::kNone,
28                                          clip,
29                                          nullptr,
30                                          caps,
31                                          clampType,
32                                          &this->headDraw().fColor);
33     if (!analysis.usesLocalCoords()) {
34         // Since we don't need local coords, we can transform on CPU instead of in the shader. This
35         // gives us better batching potential.
36         this->headDraw().fPathMatrix = fShaderMatrix;
37         fShaderMatrix = SkMatrix::I();
38     }
39     return analysis;
40 }
41
42 GrDrawOp::CombineResult PathTessellateOp::onCombineIfPossible(GrOp* grOp,
43                                                               SkArenaAlloc*,
44                                                               const GrCaps&) {
45     auto* op = grOp->cast<PathTessellateOp>();
46     bool canMerge = fAAType == op->fAAType &&
47                     fStencil == op->fStencil &&
48                     fProcessors == op->fProcessors &&
49                     fShaderMatrix == op->fShaderMatrix;
50     if (canMerge) {
51         fTotalCombinedPathVerbCnt += op->fTotalCombinedPathVerbCnt;
52         fPatchAttribs |= op->fPatchAttribs;
53
54         if (!(fPatchAttribs & PatchAttribs::kColor) &&
55             this->headDraw().fColor != op->headDraw().fColor) {
56             // Color is no longer uniform. Move it into patch attribs.
57             fPatchAttribs |= PatchAttribs::kColor;
58         }
59
60         *fPathDrawTail = op->fPathDrawList;
61         fPathDrawTail = op->fPathDrawTail;
62         return CombineResult::kMerged;
63     }
64
65     return CombineResult::kCannotCombine;
66 }
67
68 void PathTessellateOp::prepareTessellator(const GrTessellationShader::ProgramArgs& args,
69                                           GrAppliedClip&& appliedClip) {
70     SkASSERT(!fTessellator);
71     SkASSERT(!fTessellationProgram);
72     auto* pipeline = GrTessellationShader::MakePipeline(args, fAAType, std::move(appliedClip),
73                                                         std::move(fProcessors));
74     fTessellator = PathWedgeTessellator::Make(args.fArena,
75                                               args.fCaps->shaderCaps()->infinitySupport(),
76                                               fPatchAttribs);
77     auto* tessShader = GrPathTessellationShader::Make(*args.fCaps->shaderCaps(),
78                                                       args.fArena,
79                                                       fShaderMatrix,
80                                                       this->headDraw().fColor,
81                                                       fTessellator->patchAttribs());
82     fTessellationProgram = GrTessellationShader::MakeProgram(args, tessShader, pipeline, fStencil);
83 }
84
85 void PathTessellateOp::onPrePrepare(GrRecordingContext* context,
86                                     const GrSurfaceProxyView& writeView, GrAppliedClip* clip,
87                                     const GrDstProxyView& dstProxyView,
88                                     GrXferBarrierFlags renderPassXferBarriers,
89                                     GrLoadOp colorLoadOp) {
90     // DMSAA is not supported on DDL.
91     bool usesMSAASurface = writeView.asRenderTargetProxy()->numSamples() > 1;
92     this->prepareTessellator({context->priv().recordTimeAllocator(), writeView, usesMSAASurface,
93                              &dstProxyView, renderPassXferBarriers, colorLoadOp,
94                              context->priv().caps()},
95                              (clip) ? std::move(*clip) : GrAppliedClip::Disabled());
96     SkASSERT(fTessellationProgram);
97     context->priv().recordProgramInfo(fTessellationProgram);
98 }
99
100 void PathTessellateOp::onPrepare(GrOpFlushState* flushState) {
101     if (!fTessellator) {
102         this->prepareTessellator({flushState->allocator(), flushState->writeView(),
103                                  flushState->usesMSAASurface(), &flushState->dstProxyView(),
104                                  flushState->renderPassBarriers(), flushState->colorLoadOp(),
105                                  &flushState->caps()}, flushState->detachAppliedClip());
106         SkASSERT(fTessellator);
107     }
108     fTessellator->prepare(flushState,
109                           fShaderMatrix,
110                           *fPathDrawList,
111                           fTotalCombinedPathVerbCnt);
112 }
113
114 void PathTessellateOp::onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) {
115     SkASSERT(fTessellator);
116     SkASSERT(fTessellationProgram);
117     flushState->bindPipelineAndScissorClip(*fTessellationProgram, this->bounds());
118     flushState->bindTextures(fTessellationProgram->geomProc(), nullptr,
119                              fTessellationProgram->pipeline());
120     fTessellator->draw(flushState);
121 }
122
123 } // namespace skgpu::v1