• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 class GrClearStencilClipOp final : public GrOp {
18 public:
19     DEFINE_OP_CLASS_ID
20 
Make(const GrFixedClip & clip,bool insideStencilMask,GrRenderTargetProxy * proxy)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 
name()26     const char* name() const override { return "ClearStencilClip"; }
27 
dumpInfo()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 
41 private:
GrClearStencilClipOp(const GrFixedClip & clip,bool insideStencilMask,GrRenderTargetProxy * proxy)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 
onCombineIfPossible(GrOp * t,const GrCaps & caps)53     bool onCombineIfPossible(GrOp* t, const GrCaps& caps) override { return false; }
54 
onPrepare(GrOpFlushState *)55     void onPrepare(GrOpFlushState*) override {}
56 
onExecute(GrOpFlushState * state)57     void onExecute(GrOpFlushState* state) override {
58         SkASSERT(state->drawOpArgs().fRenderTarget);
59 
60         state->commandBuffer()->clearStencilClip(state->drawOpArgs().fRenderTarget,
61                                                  fClip, fInsideStencilMask);
62     }
63 
64     const GrFixedClip fClip;
65     const bool        fInsideStencilMask;
66 
67     typedef GrOp INHERITED;
68 };
69 
70 #endif
71