1/*
2 * Copyright 2016 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 GrClearStencilClipOp_DEFINED
9#define GrClearStencilClipOp_DEFINED
10
11#include "GrFixedClip.h"
12#include "GrGpuCommandBuffer.h"
13#include "GrOp.h"
14#include "GrOpFlushState.h"
15#include "GrRenderTargetProxy.h"
16
17class GrClearStencilClipOp final : public GrOp {
18public:
19    DEFINE_OP_CLASS_ID
20
21    static std::unique_ptr<GrOp> Make(const GrFixedClip& clip, bool insideStencilMask,
22                                      GrRenderTargetProxy* proxy) {
23        return std::unique_ptr<GrOp>(new GrClearStencilClipOp(clip, insideStencilMask, proxy));
24    }
25
26    const char* name() const override { return "ClearStencilClip"; }
27
28    SkString dumpInfo() const override {
29        SkString string("Scissor [");
30        if (fClip.scissorEnabled()) {
31            const SkIRect& r = fClip.scissorRect();
32            string.appendf("L: %d, T: %d, R: %d, B: %d", r.fLeft, r.fTop, r.fRight, r.fBottom);
33        } else {
34            string.append("disabled");
35        }
36        string.appendf("], insideMask: %s\n", fInsideStencilMask ? "true" : "false");
37        string.append(INHERITED::dumpInfo());
38        return string;
39    }
40
41private:
42    GrClearStencilClipOp(const GrFixedClip& clip, bool insideStencilMask,
43                         GrRenderTargetProxy* proxy)
44            : INHERITED(ClassID())
45            , fClip(clip)
46            , fInsideStencilMask(insideStencilMask) {
47        const SkRect& bounds = fClip.scissorEnabled()
48                                            ? SkRect::Make(fClip.scissorRect())
49                                            : SkRect::MakeIWH(proxy->width(), proxy->height());
50        this->setBounds(bounds, HasAABloat::kNo, IsZeroArea::kNo);
51    }
52
53    bool onCombineIfPossible(GrOp* t, const GrCaps& caps) override { return false; }
54
55    void onPrepare(GrOpFlushState*) override {}
56
57    void onExecute(GrOpFlushState* state) override {
58        SkASSERT(state->rtCommandBuffer());
59        state->rtCommandBuffer()->clearStencilClip(fClip, fInsideStencilMask);
60    }
61
62    const GrFixedClip fClip;
63    const bool        fInsideStencilMask;
64
65    typedef GrOp INHERITED;
66};
67
68#endif
69