Debian Codegraph @

src/gpu/ganesh/PathRenderer.cpp

raw
1 /*
2 * Copyright 2011 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 #include "src/gpu/ganesh/PathRenderer.h"
8
9 #include "include/core/SkMatrix.h"
10 #include "include/core/SkPath.h"
11 #include "include/core/SkRect.h"
12 #include "include/core/SkSize.h"
13 #include "include/gpu/ganesh/GrRecordingContext.h"
14 #include "include/private/gpu/ganesh/GrTypesPriv.h"
15 #include "src/gpu/ganesh/GrPaint.h"
16 #include "src/gpu/ganesh/GrRecordingContextPriv.h"
17 #include "src/gpu/ganesh/GrStyle.h"
18 #include "src/gpu/ganesh/GrUserStencilSettings.h"
19 #include "src/gpu/ganesh/SurfaceDrawContext.h"
20 #include "src/gpu/ganesh/geometry/GrStyledShape.h"
21
22 #include <utility>
23
24 namespace skgpu::ganesh {
25
26 #ifdef SK_DEBUG
27 void PathRenderer::StencilPathArgs::validate() const {
28 SkASSERT(fContext);
29 SkASSERT(fSurfaceDrawContext);
30 SkASSERT(fClipConservativeBounds);
31 SkASSERT(fViewMatrix);
32 SkASSERT(fShape);
33 SkASSERT(fShape->style().isSimpleFill());
34 SkPath path = fShape->asPath();
35 SkASSERT(!path.isInverseFillType());
36 }
37 #endif
38
39 //////////////////////////////////////////////////////////////////////////////
40
41 PathRenderer::StencilSupport PathRenderer::getStencilSupport(const GrStyledShape& shape) const {
42 SkDEBUGCODE(SkPath path = shape.asPath();)
43 SkASSERT(shape.style().isSimpleFill());
44 SkASSERT(!path.isInverseFillType());
45 return this->onGetStencilSupport(shape);
46 }
47
48 bool PathRenderer::drawPath(const DrawPathArgs& args) {
49 #ifdef SK_DEBUG
50 args.validate();
51 CanDrawPathArgs canArgs;
52 canArgs.fCaps = args.fContext->priv().caps();
53 canArgs.fProxy = args.fSurfaceDrawContext->asRenderTargetProxy();
54 canArgs.fClipConservativeBounds = args.fClipConservativeBounds;
55 canArgs.fViewMatrix = args.fViewMatrix;
56 canArgs.fShape = args.fShape;
57 canArgs.fPaint = &args.fPaint;
58 canArgs.fSurfaceProps = &args.fSurfaceDrawContext->surfaceProps();
59 canArgs.fAAType = args.fAAType;
60 canArgs.validate();
61
62 canArgs.fHasUserStencilSettings = !args.fUserStencilSettings->isUnused();
63 SkASSERT(CanDrawPath::kNo != this->canDrawPath(canArgs));
64 if (!args.fUserStencilSettings->isUnused()) {
65 SkPath path = args.fShape->asPath();
66 SkASSERT(args.fShape->style().isSimpleFill());
67 SkASSERT(kNoRestriction_StencilSupport == this->getStencilSupport(*args.fShape));
68 }
69 #endif
70 return this->onDrawPath(args);
71 }
72
73 void PathRenderer::GetPathDevBounds(const SkPath& path,
74 SkISize devSize,
75 const SkMatrix& matrix,
76 SkRect* bounds) {
77 if (path.isInverseFillType()) {
78 *bounds = SkRect::Make(devSize);
79 return;
80 }
81 *bounds = path.getBounds();
82 matrix.mapRect(bounds);
83 }
84
85 void PathRenderer::onStencilPath(const StencilPathArgs& args) {
86 static constexpr GrUserStencilSettings kIncrementStencil(
87 GrUserStencilSettings::StaticInit<
88 0xffff,
89 GrUserStencilTest::kAlways,
90 0xffff,
91 GrUserStencilOp::kReplace,
92 GrUserStencilOp::kReplace,
93 0xffff>()
94 );
95
96 GrPaint paint;
97 DrawPathArgs drawArgs{args.fContext,
98 std::move(paint),
99 &kIncrementStencil,
100 args.fSurfaceDrawContext,
101 nullptr, // clip
102 args.fClipConservativeBounds,
103 args.fViewMatrix,
104 args.fShape,
105 (GrAA::kYes == args.fDoStencilMSAA) ? GrAAType::kMSAA : GrAAType::kNone,
106 false};
107 this->drawPath(drawArgs);
108 }
109
110 } // namespace skgpu::ganesh