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