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