blob: f1e5b50d9578674634437c691cc06eb89ab4a660 [file] [log] [blame]
robertphillips9199a9f2016-07-13 07:48:43 -07001/*
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 GrClearStencilClipBatch_DEFINED
9#define GrClearStencilClipBatch_DEFINED
10
11#include "GrBatch.h"
12#include "GrBatchFlushState.h"
csmartdalton29df7602016-08-31 11:55:52 -070013#include "GrFixedClip.h"
robertphillips9199a9f2016-07-13 07:48:43 -070014#include "GrGpu.h"
15#include "GrGpuCommandBuffer.h"
16#include "GrRenderTarget.h"
17
18class GrClearStencilClipBatch final : public GrBatch {
19public:
20 DEFINE_BATCH_CLASS_ID
21
csmartdalton29df7602016-08-31 11:55:52 -070022 GrClearStencilClipBatch(const GrFixedClip& clip, bool insideStencilMask, GrRenderTarget* rt)
robertphillips9199a9f2016-07-13 07:48:43 -070023 : INHERITED(ClassID())
csmartdalton29df7602016-08-31 11:55:52 -070024 , fClip(clip)
25 , fInsideStencilMask(insideStencilMask)
robertphillips9199a9f2016-07-13 07:48:43 -070026 , fRenderTarget(rt) {
csmartdalton29df7602016-08-31 11:55:52 -070027 const SkRect& bounds = fClip.scissorEnabled() ? SkRect::Make(fClip.scissorRect())
28 : SkRect::MakeIWH(rt->width(), rt->height());
29 this->setBounds(bounds, HasAABloat::kNo, IsZeroArea::kNo);
robertphillips9199a9f2016-07-13 07:48:43 -070030 }
31
32 const char* name() const override { return "ClearStencilClip"; }
33
Robert Phillips294870f2016-11-11 12:38:40 -050034 // TODO: this needs to be updated to return GrSurfaceProxy::UniqueID
35 GrGpuResource::UniqueID renderTargetUniqueID() const override {
36 return fRenderTarget.get()->uniqueID();
37 }
robertphillips9199a9f2016-07-13 07:48:43 -070038 GrRenderTarget* renderTarget() const override { return fRenderTarget.get(); }
39
40 SkString dumpInfo() const override {
csmartdalton29df7602016-08-31 11:55:52 -070041 SkString string("Scissor [");
42 if (fClip.scissorEnabled()) {
43 const SkIRect& r = fClip.scissorRect();
44 string.appendf("L: %d, T: %d, R: %d, B: %d", r.fLeft, r.fTop, r.fRight, r.fBottom);
45 }
Robert Phillips294870f2016-11-11 12:38:40 -050046 string.appendf("], IC: %d, RT: %d", fInsideStencilMask,
47 fRenderTarget.get()->uniqueID().asUInt());
robertphillips9199a9f2016-07-13 07:48:43 -070048 string.append(INHERITED::dumpInfo());
49 return string;
50 }
51
52private:
53 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { return false; }
54
55 void onPrepare(GrBatchFlushState*) override {}
56
Greg Daniel36a77ee2016-10-18 10:33:25 -040057 void onDraw(GrBatchFlushState* state, const SkRect& /*bounds*/) override {
Greg Daniel65a09272016-10-12 09:47:22 -040058 state->commandBuffer()->clearStencilClip(fClip, fInsideStencilMask);
robertphillips9199a9f2016-07-13 07:48:43 -070059 }
60
csmartdalton29df7602016-08-31 11:55:52 -070061 const GrFixedClip fClip;
62 const bool fInsideStencilMask;
robertphillips9199a9f2016-07-13 07:48:43 -070063 GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget;
64
65 typedef GrBatch INHERITED;
66};
67
68#endif