blob: faf77c3ff55adabc2912ca99d963d326af4c7f6b [file] [log] [blame]
bsalomon53469832015-08-18 09:20:09 -07001/*
2 * Copyright 2015 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
Brian Salomon7dae46a2016-12-14 16:21:37 -05008#ifndef GrClearOp_DEFINED
9#define GrClearOp_DEFINED
bsalomon53469832015-08-18 09:20:09 -070010
Michael Ludwig9cced932020-06-08 09:30:09 -040011#include "include/gpu/GrTypes.h"
Michael Ludwig1e632792020-05-21 12:45:31 -040012#include "src/gpu/GrScissorState.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050013#include "src/gpu/ops/GrOp.h"
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040014
15class GrOpFlushState;
Robert Phillipsb97da532019-02-12 15:24:12 -050016class GrRecordingContext;
bsalomon53469832015-08-18 09:20:09 -070017
Brian Salomon7dae46a2016-12-14 16:21:37 -050018class GrClearOp final : public GrOp {
bsalomon53469832015-08-18 09:20:09 -070019public:
Brian Salomon25a88092016-12-01 09:36:50 -050020 DEFINE_OP_CLASS_ID
reed1b55a962015-09-17 20:16:13 -070021
Michael Ludwigd1d997e2020-06-04 15:52:44 -040022 // A fullscreen or scissored clear, depending on the clip and proxy dimensions
Michael Ludwig9cced932020-06-08 09:30:09 -040023 static std::unique_ptr<GrClearOp> MakeColor(GrRecordingContext* context,
24 const GrScissorState& scissor,
25 const SkPMColor4f& color);
26
27 static std::unique_ptr<GrClearOp> MakeStencilClip(GrRecordingContext* context,
28 const GrScissorState& scissor,
29 bool insideMask);
Robert Phillips784b7bf2016-12-09 13:35:02 -050030
bsalomon53469832015-08-18 09:20:09 -070031 const char* name() const override { return "Clear"; }
32
bsalomon53469832015-08-18 09:20:09 -070033private:
Robert Phillips7c525e62018-06-12 10:11:12 -040034 friend class GrOpMemoryPool; // for ctors
35
Michael Ludwig9cced932020-06-08 09:30:09 -040036 enum class Buffer {
37 kColor = 0b01,
38 kStencilClip = 0b10,
39
40 kBoth = 0b11,
41 };
42 GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(Buffer);
43
44 GrClearOp(Buffer buffer, const GrScissorState& scissor, const SkPMColor4f& color, bool stencil);
Robert Phillips784b7bf2016-12-09 13:35:02 -050045
Michael Ludwig28b0c5d2019-12-19 14:51:00 -050046 CombineResult onCombineIfPossible(GrOp* t, GrRecordingContext::Arenas*,
Michael Ludwig9cced932020-06-08 09:30:09 -040047 const GrCaps& caps) override;
bsalomon53469832015-08-18 09:20:09 -070048
Michael Ludwig9cced932020-06-08 09:30:09 -040049 void onPrePrepare(GrRecordingContext*, const GrSurfaceProxyView* writeView, GrAppliedClip*,
Robert Phillipsc655c3a2020-03-18 13:23:45 -040050 const GrXferProcessor::DstProxyView&) override {}
51
Brian Salomon742e31d2016-12-07 17:06:19 -050052 void onPrepare(GrOpFlushState*) override {}
bsalomon53469832015-08-18 09:20:09 -070053
Brian Salomon588cec72018-11-14 13:56:37 -050054 void onExecute(GrOpFlushState* state, const SkRect& chainBounds) override;
John Stilesaf366522020-08-13 09:57:34 -040055#if GR_TEST_UTILS
56 SkString onDumpInfo() const override {
57 SkString string("Scissor [ ");
58 if (fScissor.enabled()) {
59 const SkIRect& r = fScissor.rect();
60 string.appendf("L: %d, T: %d, R: %d, B: %d", r.fLeft, r.fTop, r.fRight, r.fBottom);
61 } else {
62 string.append("disabled");
63 }
64 string.appendf("], Color: 0x%08x\n", fColor.toBytes_RGBA());
65 return string;
66 }
67#endif
bsalomon53469832015-08-18 09:20:09 -070068
Michael Ludwig1e632792020-05-21 12:45:31 -040069 GrScissorState fScissor;
70 SkPMColor4f fColor;
Michael Ludwig9cced932020-06-08 09:30:09 -040071 bool fStencilInsideMask;
72 Buffer fBuffer;
Robert Phillips33f83152017-05-18 20:57:43 +000073
Brian Salomon25a88092016-12-01 09:36:50 -050074 typedef GrOp INHERITED;
bsalomon53469832015-08-18 09:20:09 -070075};
76
Michael Ludwig9cced932020-06-08 09:30:09 -040077GR_MAKE_BITFIELD_CLASS_OPS(GrClearOp::Buffer)
78
bsalomon53469832015-08-18 09:20:09 -070079#endif