1/*
2 * Copyright 2020 Google Inc.
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 GrSimpleMeshDrawOpHelperWithStencil_DEFINED
9#define GrSimpleMeshDrawOpHelperWithStencil_DEFINED
10
11#include "src/gpu/ops/GrSimpleMeshDrawOpHelper.h"
12
13/**
14 * This class extends GrSimpleMeshDrawOpHelper to support an optional GrUserStencilSettings. This
15 * uses private inheritance because it non-virtually overrides methods in the base class and should
16 * never be used with a GrSimpleMeshDrawOpHelper pointer or reference.
17 */
18class GrSimpleMeshDrawOpHelperWithStencil : private GrSimpleMeshDrawOpHelper {
19public:
20    using InputFlags = GrSimpleMeshDrawOpHelper::InputFlags;
21
22    using GrSimpleMeshDrawOpHelper::visitProxies;
23    using GrSimpleMeshDrawOpHelper::createPipeline;
24
25    GrProgramInfo* createProgramInfoWithStencil(const GrCaps*,
26                                                SkArenaAlloc*,
27                                                const GrSurfaceProxyView& writeView,
28                                                bool usesMSAASurface,
29                                                GrAppliedClip&&,
30                                                const GrDstProxyView&,
31                                                GrGeometryProcessor*,
32                                                GrPrimitiveType,
33                                                GrXferBarrierFlags renderPassXferBarriers,
34                                                GrLoadOp colorLoadOp);
35
36    // using declarations can't be templated, so this is a pass through function instead.
37    template <typename Op, typename... OpArgs>
38    static GrOp::Owner FactoryHelper(GrRecordingContext* context, GrPaint&& paint,
39                                     OpArgs... opArgs) {
40        return GrSimpleMeshDrawOpHelper::FactoryHelper<Op, OpArgs...>(
41                context, std::move(paint), std::forward<OpArgs>(opArgs)...);
42    }
43
44    GrSimpleMeshDrawOpHelperWithStencil(GrProcessorSet*, GrAAType, const GrUserStencilSettings*,
45                                        InputFlags = InputFlags::kNone);
46
47    GrDrawOp::FixedFunctionFlags fixedFunctionFlags() const;
48
49    GrProcessorSet::Analysis finalizeProcessors(const GrCaps& caps, const GrAppliedClip* clip,
50                                                GrClampType clampType,
51                                                GrProcessorAnalysisCoverage geometryCoverage,
52                                                GrProcessorAnalysisColor* geometryColor) {
53        return this->INHERITED::finalizeProcessors(caps, clip, fStencilSettings, clampType,
54                                                   geometryCoverage, geometryColor);
55    }
56
57    GrProcessorSet::Analysis finalizeProcessors(const GrCaps&, const GrAppliedClip*, GrClampType,
58                                                GrProcessorAnalysisCoverage geometryCoverage,
59                                                SkPMColor4f* geometryColor, bool* wideColor);
60
61    using GrSimpleMeshDrawOpHelper::aaType;
62    using GrSimpleMeshDrawOpHelper::setAAType;
63    using GrSimpleMeshDrawOpHelper::isTrivial;
64    using GrSimpleMeshDrawOpHelper::usesLocalCoords;
65    using GrSimpleMeshDrawOpHelper::compatibleWithCoverageAsAlpha;
66    using GrSimpleMeshDrawOpHelper::detachProcessorSet;
67    using GrSimpleMeshDrawOpHelper::pipelineFlags;
68
69    bool isCompatible(const GrSimpleMeshDrawOpHelperWithStencil& that, const GrCaps&,
70                      const SkRect& thisBounds, const SkRect& thatBounds,
71                      bool ignoreAAType = false) const;
72
73#if GR_TEST_UTILS
74    SkString dumpInfo() const;
75#endif
76
77    const GrUserStencilSettings* stencilSettings() const { return fStencilSettings; }
78
79private:
80    const GrUserStencilSettings* fStencilSettings;
81    using INHERITED = GrSimpleMeshDrawOpHelper;
82};
83
84#endif
85