blob: 770a7de6981837302de0a896173838a22df9584f [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
Robert Phillipsb97da532019-02-12 15:24:12 -050021 static std::unique_ptr<GrClearOp> Make(GrRecordingContext* context,
Michael Ludwig1e632792020-05-21 12:45:31 -040022 const GrScissorState& scissor,
Michael Ludwig4926b072020-06-04 19:39:42 +000023 const SkPMColor4f& color,
24 const GrSurfaceProxy* dstProxy);
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
Michael Ludwig4926b072020-06-04 19:39:42 +000044 const SkPMColor4f& color() const { return fColor; }
45 void setColor(const SkPMColor4f& color) { fColor = color; }
46
bsalomon53469832015-08-18 09:20:09 -070047private:
Robert Phillips7c525e62018-06-12 10:11:12 -040048 friend class GrOpMemoryPool; // for ctors
49
Michael Ludwig4926b072020-06-04 19:39:42 +000050 GrClearOp(const GrScissorState& scissor, const SkPMColor4f& color, const GrSurfaceProxy* proxy);
Robert Phillips784b7bf2016-12-09 13:35:02 -050051
Michael Ludwig28b0c5d2019-12-19 14:51:00 -050052 CombineResult onCombineIfPossible(GrOp* t, GrRecordingContext::Arenas*,
53 const GrCaps& caps) override {
bsalomone63ffef2016-02-05 07:17:34 -080054 // This could be much more complicated. Currently we look at cases where the new clear
55 // contains the old clear, or when the new clear is a subset of the old clear and is the
56 // same color.
Brian Salomon7dae46a2016-12-14 16:21:37 -050057 GrClearOp* cb = t->cast<GrClearOp>();
csmartdalton29df7602016-08-31 11:55:52 -070058 if (cb->contains(this)) {
Michael Ludwig1e632792020-05-21 12:45:31 -040059 fScissor = cb->fScissor;
bsalomone63ffef2016-02-05 07:17:34 -080060 fColor = cb->fColor;
Brian Salomon7eae3e02018-08-07 14:02:38 +000061 return CombineResult::kMerged;
csmartdalton29df7602016-08-31 11:55:52 -070062 } else if (cb->fColor == fColor && this->contains(cb)) {
Brian Salomon7eae3e02018-08-07 14:02:38 +000063 return CombineResult::kMerged;
bsalomone63ffef2016-02-05 07:17:34 -080064 }
Brian Salomon7eae3e02018-08-07 14:02:38 +000065 return CombineResult::kCannotCombine;
bsalomon53469832015-08-18 09:20:09 -070066 }
67
Brian Salomon7dae46a2016-12-14 16:21:37 -050068 bool contains(const GrClearOp* that) const {
csmartdalton29df7602016-08-31 11:55:52 -070069 // The constructor ensures that scissor gets disabled on any clip that fills the entire RT.
Michael Ludwig1e632792020-05-21 12:45:31 -040070 return !fScissor.enabled() ||
71 (that->fScissor.enabled() && fScissor.rect().contains(that->fScissor.rect()));
csmartdalton29df7602016-08-31 11:55:52 -070072 }
73
Robert Phillipsc655c3a2020-03-18 13:23:45 -040074 void onPrePrepare(GrRecordingContext*,
Brian Salomon8afde5f2020-04-01 16:22:00 -040075 const GrSurfaceProxyView* writeView,
Robert Phillipsc655c3a2020-03-18 13:23:45 -040076 GrAppliedClip*,
77 const GrXferProcessor::DstProxyView&) override {}
78
Brian Salomon742e31d2016-12-07 17:06:19 -050079 void onPrepare(GrOpFlushState*) override {}
bsalomon53469832015-08-18 09:20:09 -070080
Brian Salomon588cec72018-11-14 13:56:37 -050081 void onExecute(GrOpFlushState* state, const SkRect& chainBounds) override;
bsalomon53469832015-08-18 09:20:09 -070082
Michael Ludwig1e632792020-05-21 12:45:31 -040083 GrScissorState fScissor;
84 SkPMColor4f fColor;
Robert Phillips33f83152017-05-18 20:57:43 +000085
Brian Salomon25a88092016-12-01 09:36:50 -050086 typedef GrOp INHERITED;
bsalomon53469832015-08-18 09:20:09 -070087};
88
bsalomon53469832015-08-18 09:20:09 -070089#endif