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 | |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 11 | #include "GrFixedClip.h" |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 12 | #include "GrOp.h" |
Robert Phillips | fbcef6e | 2017-06-15 12:07:18 -0400 | [diff] [blame] | 13 | |
| 14 | class GrOpFlushState; |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 15 | |
Brian Salomon | 7dae46a | 2016-12-14 16:21:37 -0500 | [diff] [blame] | 16 | class GrClearOp final : public GrOp { |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 17 | public: |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 18 | DEFINE_OP_CLASS_ID |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 19 | |
Brian Salomon | f833478 | 2017-01-03 09:42:58 -0500 | [diff] [blame] | 20 | static std::unique_ptr<GrClearOp> Make(const GrFixedClip& clip, GrColor color, |
Jim Van Verth | 6a40abc | 2017-11-02 16:56:09 +0000 | [diff] [blame] | 21 | GrSurfaceProxy* dstProxy) { |
Robert Phillips | 5efd5ea | 2017-05-30 13:47:32 -0400 | [diff] [blame] | 22 | const SkIRect rect = SkIRect::MakeWH(dstProxy->width(), dstProxy->height()); |
| 23 | if (clip.scissorEnabled() && !SkIRect::Intersects(clip.scissorRect(), rect)) { |
Robert Phillips | f7a7261 | 2017-03-31 10:03:45 -0400 | [diff] [blame] | 24 | return nullptr; |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 25 | } |
Robert Phillips | f7a7261 | 2017-03-31 10:03:45 -0400 | [diff] [blame] | 26 | |
Jim Van Verth | 6a40abc | 2017-11-02 16:56:09 +0000 | [diff] [blame] | 27 | return std::unique_ptr<GrClearOp>(new GrClearOp(clip, color, dstProxy)); |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 28 | } |
| 29 | |
Robert Phillips | f7a7261 | 2017-03-31 10:03:45 -0400 | [diff] [blame] | 30 | static std::unique_ptr<GrClearOp> Make(const SkIRect& rect, GrColor color, |
Brian Salomon | f833478 | 2017-01-03 09:42:58 -0500 | [diff] [blame] | 31 | bool fullScreen) { |
Robert Phillips | f7a7261 | 2017-03-31 10:03:45 -0400 | [diff] [blame] | 32 | SkASSERT(fullScreen || !rect.isEmpty()); |
| 33 | |
Robert Phillips | 5efd5ea | 2017-05-30 13:47:32 -0400 | [diff] [blame] | 34 | return std::unique_ptr<GrClearOp>(new GrClearOp(rect, color, fullScreen)); |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 35 | } |
| 36 | |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 37 | const char* name() const override { return "Clear"; } |
| 38 | |
Brian Salomon | 9dc2a9a | 2015-08-18 12:46:51 -0400 | [diff] [blame] | 39 | SkString dumpInfo() const override { |
Robert Phillips | 1119dc3 | 2017-04-11 12:54:57 -0400 | [diff] [blame] | 40 | SkString string; |
Robert Phillips | f5442bb | 2017-04-17 14:18:34 -0400 | [diff] [blame] | 41 | string.append(INHERITED::dumpInfo()); |
Robert Phillips | 5efd5ea | 2017-05-30 13:47:32 -0400 | [diff] [blame] | 42 | string.appendf("Scissor [ "); |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 43 | if (fClip.scissorEnabled()) { |
| 44 | const SkIRect& r = fClip.scissorRect(); |
| 45 | 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] | 46 | } else { |
| 47 | string.append("disabled"); |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 48 | } |
Robert Phillips | f5442bb | 2017-04-17 14:18:34 -0400 | [diff] [blame] | 49 | string.appendf("], Color: 0x%08x\n", fColor); |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 50 | return string; |
| 51 | } |
| 52 | |
Robert Phillips | f5442bb | 2017-04-17 14:18:34 -0400 | [diff] [blame] | 53 | GrColor color() const { return fColor; } |
bsalomon | fd8d013 | 2016-08-11 11:25:33 -0700 | [diff] [blame] | 54 | void setColor(GrColor color) { fColor = color; } |
| 55 | |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 56 | private: |
Jim Van Verth | 6a40abc | 2017-11-02 16:56:09 +0000 | [diff] [blame] | 57 | GrClearOp(const GrFixedClip& clip, GrColor color, GrSurfaceProxy* proxy); |
robertphillips | 9199a9f | 2016-07-13 07:48:43 -0700 | [diff] [blame] | 58 | |
Robert Phillips | 5efd5ea | 2017-05-30 13:47:32 -0400 | [diff] [blame] | 59 | GrClearOp(const SkIRect& rect, GrColor color, bool fullScreen) |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 60 | : INHERITED(ClassID()) |
| 61 | , fClip(GrFixedClip(rect)) |
Robert Phillips | 5efd5ea | 2017-05-30 13:47:32 -0400 | [diff] [blame] | 62 | , fColor(color) { |
Robert Phillips | f7a7261 | 2017-03-31 10:03:45 -0400 | [diff] [blame] | 63 | |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 64 | if (fullScreen) { |
| 65 | fClip.disableScissor(); |
| 66 | } |
| 67 | this->setBounds(SkRect::Make(rect), HasAABloat::kNo, IsZeroArea::kNo); |
| 68 | } |
| 69 | |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 70 | bool onCombineIfPossible(GrOp* t, const GrCaps& caps) override { |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 71 | // This could be much more complicated. Currently we look at cases where the new clear |
| 72 | // contains the old clear, or when the new clear is a subset of the old clear and is the |
| 73 | // same color. |
Brian Salomon | 7dae46a | 2016-12-14 16:21:37 -0500 | [diff] [blame] | 74 | GrClearOp* cb = t->cast<GrClearOp>(); |
Brian Salomon | 9a76772 | 2017-03-13 17:57:28 -0400 | [diff] [blame] | 75 | if (fClip.windowRectsState() != cb->fClip.windowRectsState()) { |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 76 | return false; |
| 77 | } |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 78 | if (cb->contains(this)) { |
| 79 | fClip = cb->fClip; |
bsalomon | 88cf17d | 2016-07-08 06:40:56 -0700 | [diff] [blame] | 80 | this->replaceBounds(*t); |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 81 | fColor = cb->fColor; |
| 82 | return true; |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 83 | } else if (cb->fColor == fColor && this->contains(cb)) { |
bsalomon | e63ffef | 2016-02-05 07:17:34 -0800 | [diff] [blame] | 84 | return true; |
| 85 | } |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 86 | return false; |
| 87 | } |
| 88 | |
Brian Salomon | 7dae46a | 2016-12-14 16:21:37 -0500 | [diff] [blame] | 89 | bool contains(const GrClearOp* that) const { |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 90 | // The constructor ensures that scissor gets disabled on any clip that fills the entire RT. |
| 91 | return !fClip.scissorEnabled() || |
| 92 | (that->fClip.scissorEnabled() && |
| 93 | fClip.scissorRect().contains(that->fClip.scissorRect())); |
| 94 | } |
| 95 | |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 96 | void onPrepare(GrOpFlushState*) override {} |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 97 | |
Robert Phillips | fbcef6e | 2017-06-15 12:07:18 -0400 | [diff] [blame] | 98 | void onExecute(GrOpFlushState* state) override; |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 99 | |
Robert Phillips | 5efd5ea | 2017-05-30 13:47:32 -0400 | [diff] [blame] | 100 | GrFixedClip fClip; |
| 101 | GrColor fColor; |
Robert Phillips | 33f8315 | 2017-05-18 20:57:43 +0000 | [diff] [blame] | 102 | |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 103 | typedef GrOp INHERITED; |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 104 | }; |
| 105 | |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 106 | #endif |