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