blob: ad50c7d3224145fe369f2f948fae0f6071eb1dad [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 Ludwig1e632792020-05-21 12:45:31 -040011#include "src/gpu/GrScissorState.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "src/gpu/ops/GrOp.h"
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040013
14class GrOpFlushState;
Robert Phillipsb97da532019-02-12 15:24:12 -050015class GrRecordingContext;
bsalomon53469832015-08-18 09:20:09 -070016
Brian Salomon7dae46a2016-12-14 16:21:37 -050017class GrClearOp final : public GrOp {
bsalomon53469832015-08-18 09:20:09 -070018public:
Brian Salomon25a88092016-12-01 09:36:50 -050019 DEFINE_OP_CLASS_ID
reed1b55a962015-09-17 20:16:13 -070020
Michael Ludwigd1d997e2020-06-04 15:52:44 -040021 // A fullscreen or scissored clear, depending on the clip and proxy dimensions
Robert Phillipsb97da532019-02-12 15:24:12 -050022 static std::unique_ptr<GrClearOp> Make(GrRecordingContext* context,
Michael Ludwig1e632792020-05-21 12:45:31 -040023 const GrScissorState& scissor,
Michael Ludwigd1d997e2020-06-04 15:52:44 -040024 const SkPMColor4f& color);
Robert Phillips784b7bf2016-12-09 13:35:02 -050025
bsalomon53469832015-08-18 09:20:09 -070026 const char* name() const override { return "Clear"; }
27
Brian Osman9a390ac2018-11-12 09:47:48 -050028#ifdef SK_DEBUG
Brian Salomon9dc2a9a2015-08-18 12:46:51 -040029 SkString dumpInfo() const override {
Robert Phillips1119dc32017-04-11 12:54:57 -040030 SkString string;
Robert Phillipsf5442bb2017-04-17 14:18:34 -040031 string.append(INHERITED::dumpInfo());
Robert Phillips5efd5ea2017-05-30 13:47:32 -040032 string.appendf("Scissor [ ");
Michael Ludwig1e632792020-05-21 12:45:31 -040033 if (fScissor.enabled()) {
34 const SkIRect& r = fScissor.rect();
csmartdalton29df7602016-08-31 11:55:52 -070035 string.appendf("L: %d, T: %d, R: %d, B: %d", r.fLeft, r.fTop, r.fRight, r.fBottom);
Robert Phillipsf7a72612017-03-31 10:03:45 -040036 } else {
37 string.append("disabled");
csmartdalton29df7602016-08-31 11:55:52 -070038 }
Brian Osman9a9baae2018-11-05 15:06:26 -050039 string.appendf("], Color: 0x%08x\n", fColor.toBytes_RGBA());
bsalomon53469832015-08-18 09:20:09 -070040 return string;
41 }
Brian Osman9a390ac2018-11-12 09:47:48 -050042#endif
bsalomon53469832015-08-18 09:20:09 -070043
44private:
Robert Phillips7c525e62018-06-12 10:11:12 -040045 friend class GrOpMemoryPool; // for ctors
46
Michael Ludwigd1d997e2020-06-04 15:52:44 -040047 GrClearOp(const GrScissorState& scissor, const SkPMColor4f& color);
Robert Phillips784b7bf2016-12-09 13:35:02 -050048
Michael Ludwig28b0c5d2019-12-19 14:51:00 -050049 CombineResult onCombineIfPossible(GrOp* t, GrRecordingContext::Arenas*,
50 const GrCaps& caps) override {
bsalomone63ffef2016-02-05 07:17:34 -080051 // This could be much more complicated. Currently we look at cases where the new clear
52 // contains the old clear, or when the new clear is a subset of the old clear and is the
53 // same color.
Brian Salomon7dae46a2016-12-14 16:21:37 -050054 GrClearOp* cb = t->cast<GrClearOp>();
csmartdalton29df7602016-08-31 11:55:52 -070055 if (cb->contains(this)) {
Michael Ludwig1e632792020-05-21 12:45:31 -040056 fScissor = cb->fScissor;
bsalomone63ffef2016-02-05 07:17:34 -080057 fColor = cb->fColor;
Brian Salomon7eae3e02018-08-07 14:02:38 +000058 return CombineResult::kMerged;
csmartdalton29df7602016-08-31 11:55:52 -070059 } else if (cb->fColor == fColor && this->contains(cb)) {
Brian Salomon7eae3e02018-08-07 14:02:38 +000060 return CombineResult::kMerged;
bsalomone63ffef2016-02-05 07:17:34 -080061 }
Brian Salomon7eae3e02018-08-07 14:02:38 +000062 return CombineResult::kCannotCombine;
bsalomon53469832015-08-18 09:20:09 -070063 }
64
Brian Salomon7dae46a2016-12-14 16:21:37 -050065 bool contains(const GrClearOp* that) const {
csmartdalton29df7602016-08-31 11:55:52 -070066 // The constructor ensures that scissor gets disabled on any clip that fills the entire RT.
Michael Ludwig1e632792020-05-21 12:45:31 -040067 return !fScissor.enabled() ||
68 (that->fScissor.enabled() && fScissor.rect().contains(that->fScissor.rect()));
csmartdalton29df7602016-08-31 11:55:52 -070069 }
70
Robert Phillipsc655c3a2020-03-18 13:23:45 -040071 void onPrePrepare(GrRecordingContext*,
Brian Salomon8afde5f2020-04-01 16:22:00 -040072 const GrSurfaceProxyView* writeView,
Robert Phillipsc655c3a2020-03-18 13:23:45 -040073 GrAppliedClip*,
74 const GrXferProcessor::DstProxyView&) override {}
75
Brian Salomon742e31d2016-12-07 17:06:19 -050076 void onPrepare(GrOpFlushState*) override {}
bsalomon53469832015-08-18 09:20:09 -070077
Brian Salomon588cec72018-11-14 13:56:37 -050078 void onExecute(GrOpFlushState* state, const SkRect& chainBounds) override;
bsalomon53469832015-08-18 09:20:09 -070079
Michael Ludwig1e632792020-05-21 12:45:31 -040080 GrScissorState fScissor;
81 SkPMColor4f fColor;
Robert Phillips33f83152017-05-18 20:57:43 +000082
Brian Salomon25a88092016-12-01 09:36:50 -050083 typedef GrOp INHERITED;
bsalomon53469832015-08-18 09:20:09 -070084};
85
bsalomon53469832015-08-18 09:20:09 -070086#endif