blob: 47f4fb31825c86158690d2a4141278b6b4af8939 [file] [log] [blame]
Michael Ludwig828d3412020-05-12 13:15:35 -04001/*
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
16class GrShape;
17class GrRecordingContext;
Robert Phillips4dca8312021-07-28 15:13:20 -040018namespace skgpu { namespace v1 { class SurfaceDrawContext; }}
Michael Ludwig828d3412020-05-12 13:15:35 -040019class SkMatrix;
20class 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 */
35class GrStencilMaskHelper : SkNoncopyable {
36public:
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.
Robert Phillips4dca8312021-07-28 15:13:20 -040040 GrStencilMaskHelper(GrRecordingContext*, skgpu::v1::SurfaceDrawContext*);
Michael Ludwig828d3412020-05-12 13:15:35 -040041
42 // Returns true if the stencil mask must be redrawn
43 bool init(const SkIRect& maskBounds, uint32_t genID,
44 const GrWindowRectangles& windowRects, int numFPs);
45
46 // Draw a single rect into the stencil clip using the specified op
47 void drawRect(const SkRect& rect, const SkMatrix& matrix, SkRegion::Op, GrAA);
48
49 // Draw a single filled path into the stencil clip with the specified op
50 bool drawPath(const SkPath& path, const SkMatrix& matrix, SkRegion::Op, GrAA);
51
52 // Draw a single shape into the stencil clip assuming a simple fill style, with the specified op
53 bool drawShape(const GrShape& shape, const SkMatrix& matrix, SkRegion::Op, GrAA);
54
55 // Reset the stencil buffer's clip bit to in or out.
56 void clear(bool insideStencil);
57
58 // Marks the last rendered stencil mask on the render target context
59 void finish();
60
61private:
Robert Phillips4dca8312021-07-28 15:13:20 -040062 GrRecordingContext* fContext;
63 skgpu::v1::SurfaceDrawContext* fSDC;
64 GrStencilClip fClip;
65 int fNumFPs;
Michael Ludwig828d3412020-05-12 13:15:35 -040066
John Stiles7571f9e2020-09-02 22:42:33 -040067 using INHERITED = SkNoncopyable;
Michael Ludwig828d3412020-05-12 13:15:35 -040068};
69
70#endif // GrStencilMaskHelper_DEFINED