blob: 26854c6dfe253c8e7d3627061aa5d3598737416e [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
Robert Phillips46d7bd52021-09-01 13:02:28 -04008#ifndef ClearOp_DEFINED
9#define ClearOp_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
Robert Phillips46d7bd52021-09-01 13:02:28 -040018namespace skgpu::v1 {
19
20class ClearOp final : public GrOp {
bsalomon53469832015-08-18 09:20:09 -070021public:
Brian Salomon25a88092016-12-01 09:36:50 -050022 DEFINE_OP_CLASS_ID
reed1b55a962015-09-17 20:16:13 -070023
Michael Ludwigd1d997e2020-06-04 15:52:44 -040024 // A fullscreen or scissored clear, depending on the clip and proxy dimensions
Herb Derbyc76d4092020-10-07 16:46:15 -040025 static GrOp::Owner MakeColor(GrRecordingContext* context,
26 const GrScissorState& scissor,
Brian Salomon07bc9a22020-12-02 13:37:16 -050027 std::array<float, 4> color);
Michael Ludwig9cced932020-06-08 09:30:09 -040028
Herb Derbyc76d4092020-10-07 16:46:15 -040029 static GrOp::Owner MakeStencilClip(GrRecordingContext* context,
30 const GrScissorState& scissor,
31 bool insideMask);
Robert Phillips784b7bf2016-12-09 13:35:02 -050032
bsalomon53469832015-08-18 09:20:09 -070033 const char* name() const override { return "Clear"; }
34
Robert Phillips4b10d582020-12-02 18:27:18 -050035 const std::array<float, 4>& color() const { return fColor; }
36 bool stencilInsideMask() const { return fStencilInsideMask; }
bsalomon53469832015-08-18 09:20:09 -070037private:
Herb Derbyc76d4092020-10-07 16:46:15 -040038 friend class GrOp; // for ctors
Robert Phillips7c525e62018-06-12 10:11:12 -040039
Michael Ludwig9cced932020-06-08 09:30:09 -040040 enum class Buffer {
41 kColor = 0b01,
42 kStencilClip = 0b10,
43
44 kBoth = 0b11,
45 };
46 GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(Buffer);
47
Robert Phillips46d7bd52021-09-01 13:02:28 -040048 ClearOp(Buffer buffer,
49 const GrScissorState& scissor,
50 std::array<float, 4> color,
51 bool stencil);
Robert Phillips784b7bf2016-12-09 13:35:02 -050052
Herb Derbye25c3002020-10-27 15:57:27 -040053 CombineResult onCombineIfPossible(GrOp* t, SkArenaAlloc*, const GrCaps& caps) override;
bsalomon53469832015-08-18 09:20:09 -070054
Adlai Hollere2296f72020-11-19 13:41:26 -050055 void onPrePrepare(GrRecordingContext*, const GrSurfaceProxyView& writeView, GrAppliedClip*,
John Stiles52cb1d02021-06-02 11:58:05 -040056 const GrDstProxyView&, GrXferBarrierFlags renderPassXferBarriers,
57 GrLoadOp colorLoadOp) override {}
Robert Phillipsc655c3a2020-03-18 13:23:45 -040058
Brian Salomon742e31d2016-12-07 17:06:19 -050059 void onPrepare(GrOpFlushState*) override {}
bsalomon53469832015-08-18 09:20:09 -070060
Brian Salomon588cec72018-11-14 13:56:37 -050061 void onExecute(GrOpFlushState* state, const SkRect& chainBounds) override;
John Stilesaf366522020-08-13 09:57:34 -040062#if GR_TEST_UTILS
63 SkString onDumpInfo() const override {
64 SkString string("Scissor [ ");
65 if (fScissor.enabled()) {
66 const SkIRect& r = fScissor.rect();
67 string.appendf("L: %d, T: %d, R: %d, B: %d", r.fLeft, r.fTop, r.fRight, r.fBottom);
68 } else {
69 string.append("disabled");
70 }
Brian Salomon07bc9a22020-12-02 13:37:16 -050071 string.appendf("], Color: {%g, %g, %g, %g}\n", fColor[0], fColor[1], fColor[2], fColor[3]);
John Stilesaf366522020-08-13 09:57:34 -040072 return string;
73 }
74#endif
bsalomon53469832015-08-18 09:20:09 -070075
Brian Salomon07bc9a22020-12-02 13:37:16 -050076 GrScissorState fScissor;
77 std::array<float, 4> fColor;
78 bool fStencilInsideMask;
79 Buffer fBuffer;
bsalomon53469832015-08-18 09:20:09 -070080};
81
Robert Phillips46d7bd52021-09-01 13:02:28 -040082GR_MAKE_BITFIELD_CLASS_OPS(ClearOp::Buffer)
Michael Ludwig9cced932020-06-08 09:30:09 -040083
Robert Phillips46d7bd52021-09-01 13:02:28 -040084} // namespace skgpu::v1
85
86#endif // ClearOp_DEFINED