• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2020 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 StencilMaskHelper_DEFINED
9 #define StencilMaskHelper_DEFINED
10 
11 #include "include/core/SkRegion.h"
12 #include "src/gpu/ganesh/StencilClip.h"
13 
14 class GrShape;
15 class GrRecordingContext;
16 class SkMatrix;
17 struct SkRect;
18 class SkRRect;
19 
20 namespace skgpu::ganesh {
21 
22 class SurfaceDrawContext;
23 
24 /**
25  * The StencilMaskHelper helps generate clip masks using the stencil buffer.
26  * It is intended to be used as:
27  *
28  *   StencilMaskHelper helper;
29  *   helper.init(...);
30  *
31  *      draw one or more paths/rects specifying the required boolean ops
32  *
33  *   helper.finish();
34  *
35  * The result of this process will be the mask stored in the clip bits of the stencil buffer.
36  */
37 class StencilMaskHelper : SkNoncopyable {
38 public:
39     // Configure the helper to update the stencil mask within the given rectangle, respecting the
40     // set window rectangles. It will use the provided context and render target to draw into, both
41     // of which must outlive the helper.
42     StencilMaskHelper(GrRecordingContext*, SurfaceDrawContext*);
43 
44     // Returns true if the stencil mask must be redrawn
45     bool init(const SkIRect& maskBounds, uint32_t genID,
46               const GrWindowRectangles& windowRects, int numFPs);
47 
48     // Draw a single rect into the stencil clip using the specified op
49     void drawRect(const SkRect& rect, const SkMatrix& matrix, SkRegion::Op, GrAA);
50 
51     // Draw a single filled path into the stencil clip with the specified op
52     bool drawPath(const SkPath& path, const SkMatrix& matrix, SkRegion::Op, GrAA);
53 
54     // Draw a single shape into the stencil clip assuming a simple fill style, with the specified op
55     bool drawShape(const GrShape& shape, const SkMatrix& matrix, SkRegion::Op, GrAA);
56 
57     // Reset the stencil buffer's clip bit to in or out.
58     void clear(bool insideStencil);
59 
60     // Marks the last rendered stencil mask on the render target context
61     void finish();
62 
63 private:
64     GrRecordingContext* fContext;
65     SurfaceDrawContext* fSDC;
66     StencilClip         fClip;
67     int                 fNumFPs;
68 
69     using INHERITED = SkNoncopyable;
70 };
71 
72 }  // namespace skgpu::ganesh
73 
74 #endif // StencilMaskHelper_DEFINED
75