xref: /aosp_15_r20/external/skia/src/gpu/ganesh/ops/SoftwarePathRenderer.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2012 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 #ifndef SoftwarePathRenderer_DEFINED
8 #define SoftwarePathRenderer_DEFINED
9 
10 #include "src/gpu/ganesh/PathRenderer.h"
11 
12 class GrClip;
13 class GrPaint;
14 class GrProxyProvider;
15 class GrStyledShape;
16 class GrSurfaceProxyView;
17 class SkMatrix;
18 struct GrUserStencilSettings;
19 struct SkIPoint;
20 struct SkIRect;
21 struct SkRect;
22 
23 namespace skgpu::ganesh {
24 class SurfaceDrawContext;
25 
26 /**
27  * This class uses the software side to render a path to an SkBitmap and
28  * then uploads the result to the gpu
29  */
30 class SoftwarePathRenderer final : public PathRenderer {
31 public:
name()32     const char* name() const override { return "SW"; }
33 
SoftwarePathRenderer(GrProxyProvider * proxyProvider,bool allowCaching)34     SoftwarePathRenderer(GrProxyProvider* proxyProvider, bool allowCaching)
35             : fProxyProvider(proxyProvider)
36             , fAllowCaching(allowCaching) {
37     }
38 
39     static bool GetShapeAndClipBounds(SurfaceDrawContext*,
40                                       const GrClip*,
41                                       const GrStyledShape&,
42                                       const SkMatrix& viewMatrix,
43                                       SkIRect* unclippedDevShapeBounds,
44                                       SkIRect* clippedDevShapeBounds,
45                                       SkIRect* devClipBounds);
46 
47 private:
48     static void DrawNonAARect(SurfaceDrawContext*,
49                               GrPaint&&,
50                               const GrUserStencilSettings&,
51                               const GrClip*,
52                               const SkMatrix& viewMatrix,
53                               const SkRect& rect,
54                               const SkMatrix& localMatrix);
55     static void DrawAroundInvPath(SurfaceDrawContext*,
56                                   GrPaint&&,
57                                   const GrUserStencilSettings&,
58                                   const GrClip*,
59                                   const SkMatrix& viewMatrix,
60                                   const SkIRect& devClipBounds,
61                                   const SkIRect& devPathBounds);
62 
63     // This utility draws a path mask using a provided paint. The rectangle is drawn in device
64     // space. The 'viewMatrix' will be used to ensure the correct local coords are provided to
65     // any fragment processors in the paint.
66     static void DrawToTargetWithShapeMask(GrSurfaceProxyView,
67                                           SurfaceDrawContext*,
68                                           GrPaint&&,
69                                           const GrUserStencilSettings&,
70                                           const GrClip*,
71                                           const SkMatrix& viewMatrix,
72                                           const SkIPoint& textureOriginInDeviceSpace,
73                                           const SkIRect& deviceSpaceRectToDraw);
74 
onGetStencilSupport(const GrStyledShape &)75     StencilSupport onGetStencilSupport(const GrStyledShape&) const override {
76         return PathRenderer::kNoSupport_StencilSupport;
77     }
78 
79     CanDrawPath onCanDrawPath(const CanDrawPathArgs&) const override;
80 
81     bool onDrawPath(const DrawPathArgs&) override;
82 
83 private:
84     GrProxyProvider* fProxyProvider;
85     bool             fAllowCaching;
86 };
87 
88 }  // namespace skgpu::ganesh
89 
90 #endif // SoftwarePathRenderer_DEFINED
91