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