blob: 5856e8a096f1098c142bbe0bcf547351c2521987 [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
Herb Derbyc76d4092020-10-07 16:46:15 -040023 static GrOp::Owner MakeColor(GrRecordingContext* context,
24 const GrScissorState& scissor,
Brian Salomon07bc9a22020-12-02 13:37:16 -050025 std::array<float, 4> color);
Michael Ludwig9cced932020-06-08 09:30:09 -040026
Herb Derbyc76d4092020-10-07 16:46:15 -040027 static GrOp::Owner 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:
Herb Derbyc76d4092020-10-07 16:46:15 -040034 friend class GrOp; // for ctors
Robert Phillips7c525e62018-06-12 10:11:12 -040035
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
Brian Salomon07bc9a22020-12-02 13:37:16 -050044 GrClearOp(Buffer buffer,
45 const GrScissorState& scissor,
46 std::array<float, 4> color,
47 bool stencil);
Robert Phillips784b7bf2016-12-09 13:35:02 -050048
Herb Derbye25c3002020-10-27 15:57:27 -040049 CombineResult onCombineIfPossible(GrOp* t, SkArenaAlloc*, const GrCaps& caps) override;
bsalomon53469832015-08-18 09:20:09 -070050
Adlai Hollere2296f72020-11-19 13:41:26 -050051 void onPrePrepare(GrRecordingContext*, const GrSurfaceProxyView& writeView, GrAppliedClip*,
Greg Danield358cbe2020-09-11 09:33:54 -040052 const GrXferProcessor::DstProxyView&,
Greg Daniel42dbca52020-11-20 10:22:43 -050053 GrXferBarrierFlags renderPassXferBarriers, GrLoadOp colorLoadOp) override {}
Robert Phillipsc655c3a2020-03-18 13:23:45 -040054
Brian Salomon742e31d2016-12-07 17:06:19 -050055 void onPrepare(GrOpFlushState*) override {}
bsalomon53469832015-08-18 09:20:09 -070056
Brian Salomon588cec72018-11-14 13:56:37 -050057 void onExecute(GrOpFlushState* state, const SkRect& chainBounds) override;
John Stilesaf366522020-08-13 09:57:34 -040058#if GR_TEST_UTILS
59 SkString onDumpInfo() const override {
60 SkString string("Scissor [ ");
61 if (fScissor.enabled()) {
62 const SkIRect& r = fScissor.rect();
63 string.appendf("L: %d, T: %d, R: %d, B: %d", r.fLeft, r.fTop, r.fRight, r.fBottom);
64 } else {
65 string.append("disabled");
66 }
Brian Salomon07bc9a22020-12-02 13:37:16 -050067 string.appendf("], Color: {%g, %g, %g, %g}\n", fColor[0], fColor[1], fColor[2], fColor[3]);
John Stilesaf366522020-08-13 09:57:34 -040068 return string;
69 }
70#endif
bsalomon53469832015-08-18 09:20:09 -070071
Brian Salomon07bc9a22020-12-02 13:37:16 -050072 GrScissorState fScissor;
73 std::array<float, 4> fColor;
74 bool fStencilInsideMask;
75 Buffer fBuffer;
Robert Phillips33f83152017-05-18 20:57:43 +000076
John Stiles7571f9e2020-09-02 22:42:33 -040077 using INHERITED = GrOp;
bsalomon53469832015-08-18 09:20:09 -070078};
79
Michael Ludwig9cced932020-06-08 09:30:09 -040080GR_MAKE_BITFIELD_CLASS_OPS(GrClearOp::Buffer)
81
bsalomon53469832015-08-18 09:20:09 -070082#endif