bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 1 | /* |
| 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 Salomon | 7dae46a | 2016-12-14 16:21:37 -0500 | [diff] [blame] | 8 | #ifndef GrClearOp_DEFINED |
| 9 | #define GrClearOp_DEFINED |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 10 | |
Michael Ludwig | 1e63279 | 2020-05-21 12:45:31 -0400 | [diff] [blame] | 11 | #include "src/gpu/GrScissorState.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "src/gpu/ops/GrOp.h" |
Robert Phillips | fbcef6e | 2017-06-15 12:07:18 -0400 | [diff] [blame] | 13 | |
| 14 | class GrOpFlushState; |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 15 | class GrRecordingContext; |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 16 | |
Brian Salomon | 7dae46a | 2016-12-14 16:21:37 -0500 | [diff] [blame] | 17 | class GrClearOp final : public GrOp { |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 18 | public: |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 19 | DEFINE_OP_CLASS_ID |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 20 | |
Michael Ludwig | d1d997e | 2020-06-04 15:52:44 -0400 | [diff] [blame^] | 21 | // A fullscreen or scissored clear, depending on the clip and proxy dimensions |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 22 | static std::unique_ptr<GrClearOp> Make(GrRecordingContext* context, |
Michael Ludwig | 1e63279 | 2020-05-21 12:45:31 -0400 | [diff] [blame] | 23 | const GrScissorState& scissor, |
Michael Ludwig | d1d997e | 2020-06-04 15:52:44 -0400 | [diff] [blame^] | 24 | const SkPMColor4f& color); |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 25 | |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 26 | const char* name() const override { return "Clear"; } |
| 27 | |
Brian Osman | 9a390ac | 2018-11-12 09:47:48 -0500 | [diff] [blame] | 28 | #ifdef SK_DEBUG |
Brian Salomon | 9dc2a9a | 2015-08-18 12:46:51 -0400 | [diff] [blame] | 29 | SkString dumpInfo() const override { |
Robert Phillips | 1119dc3 | 2017-04-11 12:54:57 -0400 | [diff] [blame] | 30 | SkString string; |
Robert Phillips | f5442bb | 2017-04-17 14:18:34 -0400 | [diff] [blame] | 31 | string.append(INHERITED::dumpInfo()); |
Robert Phillips | 5efd5ea | 2017-05-30 13:47:32 -0400 | [diff] [blame] | 32 | string.appendf("Scissor [ "); |
Michael Ludwig | 1e63279 | 2020-05-21 12:45:31 -0400 | [diff] [blame] | 33 | if (fScissor.enabled()) { |
| 34 | const SkIRect& r = fScissor.rect(); |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 35 | string.appendf("L: %d, T: %d, R: %d, B: %d", r.fLeft, r.fTop, r.fRight, r.fBottom); |
Robert Phillips | f7a7261 | 2017-03-31 10:03:45 -0400 | [diff] [blame] | 36 | } else { |
| 37 | string.append("disabled"); |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 38 | } |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 39 | string.appendf("], Color: 0x%08x\n", fColor.toBytes_RGBA()); |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 40 | return string; |
| 41 | } |
Brian Osman | 9a390ac | 2018-11-12 09:47:48 -0500 | [diff] [blame] | 42 | #endif |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 43 | |
| 44 | private: |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 45 | friend class GrOpMemoryPool; // for ctors |
| 46 | |
Michael Ludwig | d1d997e | 2020-06-04 15:52:44 -0400 | [diff] [blame^] | 47 | GrClearOp(const GrScissorState& scissor, const SkPMColor4f& color); |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 48 | |
Michael Ludwig | 28b0c5d | 2019-12-19 14:51:00 -0500 | [diff] [blame] | 49 | CombineResult onCombineIfPossible(GrOp* t, GrRecordingContext::Arenas*, |
| 50 | const GrCaps& caps) override { |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 51 | // 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 Salomon | 7dae46a | 2016-12-14 16:21:37 -0500 | [diff] [blame] | 54 | GrClearOp* cb = t->cast<GrClearOp>(); |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 55 | if (cb->contains(this)) { |
Michael Ludwig | 1e63279 | 2020-05-21 12:45:31 -0400 | [diff] [blame] | 56 | fScissor = cb->fScissor; |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 57 | fColor = cb->fColor; |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 58 | return CombineResult::kMerged; |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 59 | } else if (cb->fColor == fColor && this->contains(cb)) { |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 60 | return CombineResult::kMerged; |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 61 | } |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 62 | return CombineResult::kCannotCombine; |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Brian Salomon | 7dae46a | 2016-12-14 16:21:37 -0500 | [diff] [blame] | 65 | bool contains(const GrClearOp* that) const { |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 66 | // The constructor ensures that scissor gets disabled on any clip that fills the entire RT. |
Michael Ludwig | 1e63279 | 2020-05-21 12:45:31 -0400 | [diff] [blame] | 67 | return !fScissor.enabled() || |
| 68 | (that->fScissor.enabled() && fScissor.rect().contains(that->fScissor.rect())); |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 69 | } |
| 70 | |
Robert Phillips | c655c3a | 2020-03-18 13:23:45 -0400 | [diff] [blame] | 71 | void onPrePrepare(GrRecordingContext*, |
Brian Salomon | 8afde5f | 2020-04-01 16:22:00 -0400 | [diff] [blame] | 72 | const GrSurfaceProxyView* writeView, |
Robert Phillips | c655c3a | 2020-03-18 13:23:45 -0400 | [diff] [blame] | 73 | GrAppliedClip*, |
| 74 | const GrXferProcessor::DstProxyView&) override {} |
| 75 | |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 76 | void onPrepare(GrOpFlushState*) override {} |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 77 | |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 78 | void onExecute(GrOpFlushState* state, const SkRect& chainBounds) override; |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 79 | |
Michael Ludwig | 1e63279 | 2020-05-21 12:45:31 -0400 | [diff] [blame] | 80 | GrScissorState fScissor; |
| 81 | SkPMColor4f fColor; |
Robert Phillips | 33f8315 | 2017-05-18 20:57:43 +0000 | [diff] [blame] | 82 | |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 83 | typedef GrOp INHERITED; |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 84 | }; |
| 85 | |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 86 | #endif |