Michael Ludwig | 828d341 | 2020-05-12 13:15:35 -0400 | [diff] [blame] | 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; |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 18 | namespace skgpu { namespace v1 { class SurfaceDrawContext; }} |
Michael Ludwig | 828d341 | 2020-05-12 13:15:35 -0400 | [diff] [blame] | 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. |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 40 | GrStencilMaskHelper(GrRecordingContext*, skgpu::v1::SurfaceDrawContext*); |
Michael Ludwig | 828d341 | 2020-05-12 13:15:35 -0400 | [diff] [blame] | 41 | |
| 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 | |
| 61 | private: |
Robert Phillips | 4dca831 | 2021-07-28 15:13:20 -0400 | [diff] [blame] | 62 | GrRecordingContext* fContext; |
| 63 | skgpu::v1::SurfaceDrawContext* fSDC; |
| 64 | GrStencilClip fClip; |
| 65 | int fNumFPs; |
Michael Ludwig | 828d341 | 2020-05-12 13:15:35 -0400 | [diff] [blame] | 66 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 67 | using INHERITED = SkNoncopyable; |
Michael Ludwig | 828d341 | 2020-05-12 13:15:35 -0400 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | #endif // GrStencilMaskHelper_DEFINED |