robertphillips@google.com | f4c2c52 | 2012-04-27 12:08:47 +0000 | [diff] [blame] | 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 | |
Robert Phillips | 17dc658 | 2021-08-17 11:57:31 -0400 | [diff] [blame^] | 8 | #ifndef SoftwarePathRenderer_DEFINED |
| 9 | #define SoftwarePathRenderer_DEFINED |
robertphillips@google.com | f4c2c52 | 2012-04-27 12:08:47 +0000 | [diff] [blame] | 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "src/gpu/GrPathRenderer.h" |
Brian Salomon | 99a813c | 2020-03-02 12:50:47 -0500 | [diff] [blame] | 12 | #include "src/gpu/GrSurfaceProxyView.h" |
robertphillips@google.com | f4c2c52 | 2012-04-27 12:08:47 +0000 | [diff] [blame] | 13 | |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 14 | class GrProxyProvider; |
robertphillips@google.com | b4f06d7 | 2012-05-15 12:10:05 +0000 | [diff] [blame] | 15 | |
Robert Phillips | 17dc658 | 2021-08-17 11:57:31 -0400 | [diff] [blame^] | 16 | namespace skgpu::v1 { |
| 17 | |
robertphillips@google.com | b4f06d7 | 2012-05-15 12:10:05 +0000 | [diff] [blame] | 18 | /** |
robertphillips@google.com | b4f06d7 | 2012-05-15 12:10:05 +0000 | [diff] [blame] | 19 | * This class uses the software side to render a path to an SkBitmap and |
| 20 | * then uploads the result to the gpu |
| 21 | */ |
Robert Phillips | 17dc658 | 2021-08-17 11:57:31 -0400 | [diff] [blame^] | 22 | class SoftwarePathRenderer final : public GrPathRenderer { |
robertphillips@google.com | f4c2c52 | 2012-04-27 12:08:47 +0000 | [diff] [blame] | 23 | public: |
Robert Phillips | 17dc658 | 2021-08-17 11:57:31 -0400 | [diff] [blame^] | 24 | const char* name() const override { return "SW"; } |
Robert Phillips | a628605 | 2020-04-13 10:55:08 -0400 | [diff] [blame] | 25 | |
Robert Phillips | 17dc658 | 2021-08-17 11:57:31 -0400 | [diff] [blame^] | 26 | SoftwarePathRenderer(GrProxyProvider* proxyProvider, bool allowCaching) |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 27 | : fProxyProvider(proxyProvider) |
| 28 | , fAllowCaching(allowCaching) { |
| 29 | } |
| 30 | |
Robert Phillips | 17dc658 | 2021-08-17 11:57:31 -0400 | [diff] [blame^] | 31 | static bool GetShapeAndClipBounds(SurfaceDrawContext*, |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 32 | const GrClip*, |
| 33 | const GrStyledShape&, |
| 34 | const SkMatrix& viewMatrix, |
Robert Phillips | 20390c3 | 2018-08-17 11:01:03 -0400 | [diff] [blame] | 35 | SkIRect* unclippedDevShapeBounds, |
| 36 | SkIRect* clippedDevShapeBounds, |
| 37 | SkIRect* devClipBounds); |
| 38 | |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 39 | private: |
Robert Phillips | 17dc658 | 2021-08-17 11:57:31 -0400 | [diff] [blame^] | 40 | static void DrawNonAARect(SurfaceDrawContext*, |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 41 | GrPaint&&, |
| 42 | const GrUserStencilSettings&, |
| 43 | const GrClip*, |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 44 | const SkMatrix& viewMatrix, |
| 45 | const SkRect& rect, |
| 46 | const SkMatrix& localMatrix); |
Robert Phillips | 17dc658 | 2021-08-17 11:57:31 -0400 | [diff] [blame^] | 47 | static void DrawAroundInvPath(SurfaceDrawContext*, |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 48 | GrPaint&&, |
| 49 | const GrUserStencilSettings&, |
| 50 | const GrClip*, |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 51 | const SkMatrix& viewMatrix, |
| 52 | const SkIRect& devClipBounds, |
| 53 | const SkIRect& devPathBounds); |
| 54 | |
Brian Osman | c7da146 | 2017-08-17 16:14:25 -0400 | [diff] [blame] | 55 | // This utility draws a path mask using a provided paint. The rectangle is drawn in device |
| 56 | // space. The 'viewMatrix' will be used to ensure the correct local coords are provided to |
| 57 | // any fragment processors in the paint. |
Greg Daniel | 9f0dfbd | 2020-02-10 11:47:11 -0500 | [diff] [blame] | 58 | static void DrawToTargetWithShapeMask(GrSurfaceProxyView, |
Robert Phillips | 17dc658 | 2021-08-17 11:57:31 -0400 | [diff] [blame^] | 59 | SurfaceDrawContext*, |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 60 | GrPaint&&, |
| 61 | const GrUserStencilSettings&, |
| 62 | const GrClip*, |
Brian Osman | c7da146 | 2017-08-17 16:14:25 -0400 | [diff] [blame] | 63 | const SkMatrix& viewMatrix, |
| 64 | const SkIPoint& textureOriginInDeviceSpace, |
| 65 | const SkIRect& deviceSpaceRectToDraw); |
| 66 | |
Michael Ludwig | 2686d69 | 2020-04-17 20:21:37 +0000 | [diff] [blame] | 67 | StencilSupport onGetStencilSupport(const GrStyledShape&) const override { |
robertphillips | e7d4b2f | 2015-08-13 07:57:10 -0700 | [diff] [blame] | 68 | return GrPathRenderer::kNoSupport_StencilSupport; |
| 69 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 70 | |
Chris Dalton | 5ed4423 | 2017-09-07 13:22:46 -0600 | [diff] [blame] | 71 | CanDrawPath onCanDrawPath(const CanDrawPathArgs&) const override; |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 72 | |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 73 | bool onDrawPath(const DrawPathArgs&) override; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 74 | |
robertphillips@google.com | f4c2c52 | 2012-04-27 12:08:47 +0000 | [diff] [blame] | 75 | private: |
Robert Phillips | 17dc658 | 2021-08-17 11:57:31 -0400 | [diff] [blame^] | 76 | GrProxyProvider* fProxyProvider; |
| 77 | bool fAllowCaching; |
robertphillips@google.com | f4c2c52 | 2012-04-27 12:08:47 +0000 | [diff] [blame] | 78 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 79 | using INHERITED = GrPathRenderer; |
robertphillips@google.com | f4c2c52 | 2012-04-27 12:08:47 +0000 | [diff] [blame] | 80 | }; |
| 81 | |
Robert Phillips | 17dc658 | 2021-08-17 11:57:31 -0400 | [diff] [blame^] | 82 | } // namespace skgpu::v1 |
| 83 | |
| 84 | #endif // SoftwarePathRenderer_DEFINED |