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 
8 #ifndef GrSoftwarePathRenderer_DEFINED
9 #define GrSoftwarePathRenderer_DEFINED
10 
11 #include "GrPathRenderer.h"
12 
13 class GrProxyProvider;
14 
15 /**
16  * This class uses the software side to render a path to an SkBitmap and
17  * then uploads the result to the gpu
18  */
19 class GrSoftwarePathRenderer : public GrPathRenderer {
20 public:
21     GrSoftwarePathRenderer(GrProxyProvider* proxyProvider, bool allowCaching)
22             : fProxyProvider(proxyProvider)
23             , fAllowCaching(allowCaching) {
24     }
25 
26 private:
27     static void DrawNonAARect(GrRenderTargetContext* renderTargetContext,
28                               GrPaint&& paint,
29                               const GrUserStencilSettings& userStencilSettings,
30                               const GrClip& clip,
31                               const SkMatrix& viewMatrix,
32                               const SkRect& rect,
33                               const SkMatrix& localMatrix);
34     static void DrawAroundInvPath(GrRenderTargetContext* renderTargetContext,
35                                   GrPaint&& paint,
36                                   const GrUserStencilSettings& userStencilSettings,
37                                   const GrClip& clip,
38                                   const SkMatrix& viewMatrix,
39                                   const SkIRect& devClipBounds,
40                                   const SkIRect& devPathBounds);
41 
42     // This utility draws a path mask using a provided paint. The rectangle is drawn in device
43     // space. The 'viewMatrix' will be used to ensure the correct local coords are provided to
44     // any fragment processors in the paint.
45     static void DrawToTargetWithShapeMask(sk_sp<GrTextureProxy> proxy,
46                                           GrRenderTargetContext* renderTargetContext,
47                                           GrPaint&& paint,
48                                           const GrUserStencilSettings& userStencilSettings,
49                                           const GrClip& clip,
50                                           const SkMatrix& viewMatrix,
51                                           const SkIPoint& textureOriginInDeviceSpace,
52                                           const SkIRect& deviceSpaceRectToDraw);
53 
54     StencilSupport onGetStencilSupport(const GrShape&) const override {
55         return GrPathRenderer::kNoSupport_StencilSupport;
56     }
57 
58     CanDrawPath onCanDrawPath(const CanDrawPathArgs&) const override;
59 
60     bool onDrawPath(const DrawPathArgs&) override;
61 
62 private:
63     GrProxyProvider*       fProxyProvider;
64     bool                   fAllowCaching;
65 
66     typedef GrPathRenderer INHERITED;
67 };
68 
69 #endif
70