xref: /aosp_15_r20/external/skia/src/gpu/graphite/RasterPathUtils.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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 
18 namespace skgpu::graphite {
19 
20 class Shape;
21 class Transform;
22 
23 /**
24  * The RasterMaskHelper helps generate masks using the software rendering
25  * path. It is intended to be used as:
26  *
27  *   RasterMaskHelper helper(pixmapstorage);
28  *   helper.init(...);
29  *   helper.drawShape(...);
30  *
31  * The result of this process will be the mask rendered in the Pixmap,
32  * at the upper left hand corner of the bounds.
33  *
34  * TODO: this could be extended to support clip masks, similar to GrSWMaskHelper.
35  */
36 
37 class RasterMaskHelper : SkNoncopyable {
38 public:
RasterMaskHelper(SkAutoPixmapStorage * pixels)39     RasterMaskHelper(SkAutoPixmapStorage* pixels) : fPixels(pixels) {}
40 
41     bool init(SkISize pixmapSize);
42 
43     // Draw a single shape into the bitmap (as a path) at location resultBounds
44     void drawShape(const Shape& shape,
45                    const Transform& transform,
46                    const SkStrokeRec& strokeRec,
47                    const SkIRect& resultBounds);
48 
49 private:
50     SkAutoPixmapStorage* fPixels;
51     SkDrawBase           fDraw;
52     SkRasterClip         fRasterClip;
53 };
54 
55 skgpu::UniqueKey GeneratePathMaskKey(const Shape& shape,
56                                      const Transform& transform,
57                                      const SkStrokeRec& strokeRec,
58                                      skvx::half2 maskSize);
59 }  // namespace skgpu::graphite
60 
61 #endif  // skgpu_graphite_RasterPathUtils_DEFINED
62