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