blob: 169bcddc06fdcd1509bb3cd4e0b9791e363fde8b [file] [log] [blame]
robertphillips@google.comf4c2c522012-04-27 12:08:47 +00001/*
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 Phillips17dc6582021-08-17 11:57:31 -04008#ifndef SoftwarePathRenderer_DEFINED
9#define SoftwarePathRenderer_DEFINED
robertphillips@google.comf4c2c522012-04-27 12:08:47 +000010
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "src/gpu/GrPathRenderer.h"
Brian Salomon99a813c2020-03-02 12:50:47 -050012#include "src/gpu/GrSurfaceProxyView.h"
robertphillips@google.comf4c2c522012-04-27 12:08:47 +000013
Robert Phillips1afd4cd2018-01-08 13:40:32 -050014class GrProxyProvider;
robertphillips@google.comb4f06d72012-05-15 12:10:05 +000015
Robert Phillips17dc6582021-08-17 11:57:31 -040016namespace skgpu::v1 {
17
robertphillips@google.comb4f06d72012-05-15 12:10:05 +000018/**
robertphillips@google.comb4f06d72012-05-15 12:10:05 +000019 * This class uses the software side to render a path to an SkBitmap and
20 * then uploads the result to the gpu
21 */
Robert Phillips17dc6582021-08-17 11:57:31 -040022class SoftwarePathRenderer final : public GrPathRenderer {
robertphillips@google.comf4c2c522012-04-27 12:08:47 +000023public:
Robert Phillips17dc6582021-08-17 11:57:31 -040024 const char* name() const override { return "SW"; }
Robert Phillipsa6286052020-04-13 10:55:08 -040025
Robert Phillips17dc6582021-08-17 11:57:31 -040026 SoftwarePathRenderer(GrProxyProvider* proxyProvider, bool allowCaching)
Robert Phillips1afd4cd2018-01-08 13:40:32 -050027 : fProxyProvider(proxyProvider)
28 , fAllowCaching(allowCaching) {
29 }
30
Robert Phillips17dc6582021-08-17 11:57:31 -040031 static bool GetShapeAndClipBounds(SurfaceDrawContext*,
Robert Phillips4dca8312021-07-28 15:13:20 -040032 const GrClip*,
33 const GrStyledShape&,
34 const SkMatrix& viewMatrix,
Robert Phillips20390c32018-08-17 11:01:03 -040035 SkIRect* unclippedDevShapeBounds,
36 SkIRect* clippedDevShapeBounds,
37 SkIRect* devClipBounds);
38
bsalomon0aff2fa2015-07-31 06:48:27 -070039private:
Robert Phillips17dc6582021-08-17 11:57:31 -040040 static void DrawNonAARect(SurfaceDrawContext*,
Robert Phillips4dca8312021-07-28 15:13:20 -040041 GrPaint&&,
42 const GrUserStencilSettings&,
43 const GrClip*,
robertphillips976f5f02016-06-03 10:59:20 -070044 const SkMatrix& viewMatrix,
45 const SkRect& rect,
46 const SkMatrix& localMatrix);
Robert Phillips17dc6582021-08-17 11:57:31 -040047 static void DrawAroundInvPath(SurfaceDrawContext*,
Robert Phillips4dca8312021-07-28 15:13:20 -040048 GrPaint&&,
49 const GrUserStencilSettings&,
50 const GrClip*,
robertphillips976f5f02016-06-03 10:59:20 -070051 const SkMatrix& viewMatrix,
52 const SkIRect& devClipBounds,
53 const SkIRect& devPathBounds);
54
Brian Osmanc7da1462017-08-17 16:14:25 -040055 // 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 Daniel9f0dfbd2020-02-10 11:47:11 -050058 static void DrawToTargetWithShapeMask(GrSurfaceProxyView,
Robert Phillips17dc6582021-08-17 11:57:31 -040059 SurfaceDrawContext*,
Robert Phillips4dca8312021-07-28 15:13:20 -040060 GrPaint&&,
61 const GrUserStencilSettings&,
62 const GrClip*,
Brian Osmanc7da1462017-08-17 16:14:25 -040063 const SkMatrix& viewMatrix,
64 const SkIPoint& textureOriginInDeviceSpace,
65 const SkIRect& deviceSpaceRectToDraw);
66
Michael Ludwig2686d692020-04-17 20:21:37 +000067 StencilSupport onGetStencilSupport(const GrStyledShape&) const override {
robertphillipse7d4b2f2015-08-13 07:57:10 -070068 return GrPathRenderer::kNoSupport_StencilSupport;
69 }
halcanary9d524f22016-03-29 09:03:52 -070070
Chris Dalton5ed44232017-09-07 13:22:46 -060071 CanDrawPath onCanDrawPath(const CanDrawPathArgs&) const override;
bsalomon@google.com45a15f52012-12-10 19:10:17 +000072
bsalomon0aff2fa2015-07-31 06:48:27 -070073 bool onDrawPath(const DrawPathArgs&) override;
rmistry@google.comd6176b02012-08-23 18:14:13 +000074
robertphillips@google.comf4c2c522012-04-27 12:08:47 +000075private:
Robert Phillips17dc6582021-08-17 11:57:31 -040076 GrProxyProvider* fProxyProvider;
77 bool fAllowCaching;
robertphillips@google.comf4c2c522012-04-27 12:08:47 +000078
John Stiles7571f9e2020-09-02 22:42:33 -040079 using INHERITED = GrPathRenderer;
robertphillips@google.comf4c2c522012-04-27 12:08:47 +000080};
81
Robert Phillips17dc6582021-08-17 11:57:31 -040082} // namespace skgpu::v1
83
84#endif // SoftwarePathRenderer_DEFINED