blob: fbac02f9a7470f624230378ae7ff74a585f0999c [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "src/gpu/GrFixedClip.h"
12#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,
Robert Phillips7c525e62018-06-12 10:11:12 -040022 const GrFixedClip& clip,
Brian Osman9a9baae2018-11-05 15:06:26 -050023 const SkPMColor4f& color,
Robert Phillips7c525e62018-06-12 10:11:12 -040024 GrSurfaceProxy* dstProxy);
Robert Phillipsf7a72612017-03-31 10:03:45 -040025
Robert Phillipsb97da532019-02-12 15:24:12 -050026 static std::unique_ptr<GrClearOp> Make(GrRecordingContext* context,
Robert Phillips7c525e62018-06-12 10:11:12 -040027 const SkIRect& rect,
Brian Osman9a9baae2018-11-05 15:06:26 -050028 const SkPMColor4f& color,
Robert Phillips7c525e62018-06-12 10:11:12 -040029 bool fullScreen);
Robert Phillips784b7bf2016-12-09 13:35:02 -050030
bsalomon53469832015-08-18 09:20:09 -070031 const char* name() const override { return "Clear"; }
32
Brian Osman9a390ac2018-11-12 09:47:48 -050033#ifdef SK_DEBUG
Brian Salomon9dc2a9a2015-08-18 12:46:51 -040034 SkString dumpInfo() const override {
Robert Phillips1119dc32017-04-11 12:54:57 -040035 SkString string;
Robert Phillipsf5442bb2017-04-17 14:18:34 -040036 string.append(INHERITED::dumpInfo());
Robert Phillips5efd5ea2017-05-30 13:47:32 -040037 string.appendf("Scissor [ ");
Brian Salomond818ebf2018-07-02 14:08:49 +000038 if (fClip.scissorEnabled()) {
csmartdalton29df7602016-08-31 11:55:52 -070039 const SkIRect& r = fClip.scissorRect();
40 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 -040041 } else {
42 string.append("disabled");
csmartdalton29df7602016-08-31 11:55:52 -070043 }
Brian Osman9a9baae2018-11-05 15:06:26 -050044 string.appendf("], Color: 0x%08x\n", fColor.toBytes_RGBA());
bsalomon53469832015-08-18 09:20:09 -070045 return string;
46 }
Brian Osman9a390ac2018-11-12 09:47:48 -050047#endif
bsalomon53469832015-08-18 09:20:09 -070048
Brian Osman9a9baae2018-11-05 15:06:26 -050049 const SkPMColor4f& color() const { return fColor; }
50 void setColor(const SkPMColor4f& color) { fColor = color; }
bsalomonfd8d0132016-08-11 11:25:33 -070051
bsalomon53469832015-08-18 09:20:09 -070052private:
Robert Phillips7c525e62018-06-12 10:11:12 -040053 friend class GrOpMemoryPool; // for ctors
54
Brian Osman9a9baae2018-11-05 15:06:26 -050055 GrClearOp(const GrFixedClip& clip, const SkPMColor4f& color, GrSurfaceProxy* proxy);
robertphillips9199a9f2016-07-13 07:48:43 -070056
Brian Osman9a9baae2018-11-05 15:06:26 -050057 GrClearOp(const SkIRect& rect, const SkPMColor4f& color, bool fullScreen)
Robert Phillips784b7bf2016-12-09 13:35:02 -050058 : INHERITED(ClassID())
59 , fClip(GrFixedClip(rect))
Robert Phillips5efd5ea2017-05-30 13:47:32 -040060 , fColor(color) {
Robert Phillipsf7a72612017-03-31 10:03:45 -040061
Robert Phillips784b7bf2016-12-09 13:35:02 -050062 if (fullScreen) {
63 fClip.disableScissor();
64 }
Greg Daniel5faf4742019-10-01 15:14:44 -040065 this->setBounds(SkRect::Make(rect), HasAABloat::kNo, IsHairline::kNo);
Robert Phillips784b7bf2016-12-09 13:35:02 -050066 }
67
Michael Ludwig28b0c5d2019-12-19 14:51:00 -050068 CombineResult onCombineIfPossible(GrOp* t, GrRecordingContext::Arenas*,
69 const GrCaps& caps) override {
bsalomone63ffef2016-02-05 07:17:34 -080070 // This could be much more complicated. Currently we look at cases where the new clear
71 // contains the old clear, or when the new clear is a subset of the old clear and is the
72 // same color.
Brian Salomon7dae46a2016-12-14 16:21:37 -050073 GrClearOp* cb = t->cast<GrClearOp>();
Brian Salomon9a767722017-03-13 17:57:28 -040074 if (fClip.windowRectsState() != cb->fClip.windowRectsState()) {
Brian Salomon7eae3e02018-08-07 14:02:38 +000075 return CombineResult::kCannotCombine;
csmartdaltonbf4a8f92016-09-06 10:01:06 -070076 }
csmartdalton29df7602016-08-31 11:55:52 -070077 if (cb->contains(this)) {
78 fClip = cb->fClip;
bsalomone63ffef2016-02-05 07:17:34 -080079 fColor = cb->fColor;
Brian Salomon7eae3e02018-08-07 14:02:38 +000080 return CombineResult::kMerged;
csmartdalton29df7602016-08-31 11:55:52 -070081 } else if (cb->fColor == fColor && this->contains(cb)) {
Brian Salomon7eae3e02018-08-07 14:02:38 +000082 return CombineResult::kMerged;
bsalomone63ffef2016-02-05 07:17:34 -080083 }
Brian Salomon7eae3e02018-08-07 14:02:38 +000084 return CombineResult::kCannotCombine;
bsalomon53469832015-08-18 09:20:09 -070085 }
86
Brian Salomon7dae46a2016-12-14 16:21:37 -050087 bool contains(const GrClearOp* that) const {
csmartdalton29df7602016-08-31 11:55:52 -070088 // The constructor ensures that scissor gets disabled on any clip that fills the entire RT.
Brian Salomond818ebf2018-07-02 14:08:49 +000089 return !fClip.scissorEnabled() ||
90 (that->fClip.scissorEnabled() &&
91 fClip.scissorRect().contains(that->fClip.scissorRect()));
csmartdalton29df7602016-08-31 11:55:52 -070092 }
93
Robert Phillipsc655c3a2020-03-18 13:23:45 -040094 void onPrePrepare(GrRecordingContext*,
Brian Salomon8afde5f2020-04-01 16:22:00 -040095 const GrSurfaceProxyView* writeView,
Robert Phillipsc655c3a2020-03-18 13:23:45 -040096 GrAppliedClip*,
97 const GrXferProcessor::DstProxyView&) override {}
98
Brian Salomon742e31d2016-12-07 17:06:19 -050099 void onPrepare(GrOpFlushState*) override {}
bsalomon53469832015-08-18 09:20:09 -0700100
Brian Salomon588cec72018-11-14 13:56:37 -0500101 void onExecute(GrOpFlushState* state, const SkRect& chainBounds) override;
bsalomon53469832015-08-18 09:20:09 -0700102
Robert Phillips5efd5ea2017-05-30 13:47:32 -0400103 GrFixedClip fClip;
Brian Osman9a9baae2018-11-05 15:06:26 -0500104 SkPMColor4f fColor;
Robert Phillips33f83152017-05-18 20:57:43 +0000105
Brian Salomon25a88092016-12-01 09:36:50 -0500106 typedef GrOp INHERITED;
bsalomon53469832015-08-18 09:20:09 -0700107};
108
bsalomon53469832015-08-18 09:20:09 -0700109#endif