• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2024 Google LLC
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 skgpu_graphite_RasterPathUtils_DEFINED
9 #define skgpu_graphite_RasterPathUtils_DEFINED
10 
11 #include "include/private/base/SkNoncopyable.h"
12 #include "src/base/SkVx.h"
13 #include "src/core/SkAutoPixmapStorage.h"
14 #include "src/core/SkDrawBase.h"
15 #include "src/core/SkRasterClip.h"
16 #include "src/gpu/ResourceKey.h"
17 #include "src/gpu/graphite/ClipStack.h"
18 
19 namespace skgpu::graphite {
20 
21 class Shape;
22 class Transform;
23 
24 /**
25  * The RasterMaskHelper helps generate masks using the software rendering
26  * path. It is intended to be used as:
27  *
28  *   RasterMaskHelper helper(pixmapstorage);
29  *   helper.init(...);
30  *   helper.drawShape(...);
31  *
32  * The result of this process will be the mask rendered in the Pixmap,
33  * at the upper left hand corner of the bounds.
34  *
35  * This can be used for clip masks as well, by doing:
36  *   helper.drawClip(...);
37  *
38  * Rasterized clip masks will include the inversion in the mask; rasterized path
39  * masks assume that the CoverageMask shader will handle the inversion.
40  */
41 
42 class RasterMaskHelper : SkNoncopyable {
43 public:
RasterMaskHelper(SkAutoPixmapStorage * pixels)44     RasterMaskHelper(SkAutoPixmapStorage* pixels) : fPixels(pixels) {}
45 
46     bool init(SkISize pixmapSize, SkIVector transformedMaskOffset);
47 
48     void clear(uint8_t alpha, const SkIRect& resultBounds);
49 
50     // Draw a single shape into the bitmap (as a path) at location resultBounds.
51     void drawShape(const Shape& shape,
52                    const Transform& localToDevice,
53                    const SkStrokeRec& strokeRec,
54                    const SkIRect& resultBounds);
55 
56     // Draw a single shape into the bitmap (as a path) at location resultBounds.
57     // Variant used for clipping.
58     void drawClip(const Shape& shape,
59                   const Transform& localToDevice,
60                   uint8_t alpha,
61                   const SkIRect& resultBounds);
62 
63 private:
64     SkAutoPixmapStorage* fPixels;
65     SkDrawBase           fDraw;
66     SkIVector            fTransformedMaskOffset = {0, 0};
67     SkRasterClip         fRasterClip;
68 };
69 
70 skgpu::UniqueKey GeneratePathMaskKey(const Shape& shape,
71                                      const Transform& transform,
72                                      const SkStrokeRec& strokeRec,
73                                      skvx::half2 maskOrigin,
74                                      skvx::half2 maskSize);
75 
76 skgpu::UniqueKey GenerateClipMaskKey(uint32_t stackRecordID,
77                                      const ClipStack::ElementList* elementsForMask);
78 
79 }  // namespace skgpu::graphite
80 
81 #endif  // skgpu_graphite_RasterPathUtils_DEFINED
82