| 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 | |
| 8 | #ifndef GrClearOp_DEFINED |
| 9 | #define GrClearOp_DEFINED |
| 10 | |
| 11 | #include "src/gpu/GrFixedClip.h" |
| 12 | #include "src/gpu/ops/GrOp.h" |
| 13 | |
| 14 | class GrOpFlushState; |
| 15 | class GrRecordingContext; |
| 16 | |
| 17 | class GrClearOp final : public GrOp { |
| 18 | public: |
| 19 | DEFINE_OP_CLASS_ID |
| 20 | |
| 21 | static std::unique_ptr<GrClearOp> Make(GrRecordingContext* context, |
| 22 | const GrFixedClip& clip, |
| 23 | const SkPMColor4f& color, |
| 24 | GrSurfaceProxy* dstProxy); |
| 25 | |
| 26 | static std::unique_ptr<GrClearOp> Make(GrRecordingContext* context, |
| 27 | const SkIRect& rect, |
| 28 | const SkPMColor4f& color, |
| 29 | bool fullScreen); |
| 30 | |
| 31 | const char* name() const override { return "Clear" ; } |
| 32 | |
| 33 | #ifdef SK_DEBUG |
| 34 | SkString dumpInfo() const override { |
| 35 | SkString string; |
| 36 | string.append(INHERITED::dumpInfo()); |
| 37 | string.appendf("Scissor [ " ); |
| 38 | if (fClip.scissorEnabled()) { |
| 39 | const SkIRect& r = fClip.scissorRect(); |
| 40 | string.appendf("L: %d, T: %d, R: %d, B: %d" , r.fLeft, r.fTop, r.fRight, r.fBottom); |
| 41 | } else { |
| 42 | string.append("disabled" ); |
| 43 | } |
| 44 | string.appendf("], Color: 0x%08x\n" , fColor.toBytes_RGBA()); |
| 45 | return string; |
| 46 | } |
| 47 | #endif |
| 48 | |
| 49 | const SkPMColor4f& color() const { return fColor; } |
| 50 | void setColor(const SkPMColor4f& color) { fColor = color; } |
| 51 | |
| 52 | private: |
| 53 | friend class GrOpMemoryPool; // for ctors |
| 54 | |
| 55 | GrClearOp(const GrFixedClip& clip, const SkPMColor4f& color, GrSurfaceProxy* proxy); |
| 56 | |
| 57 | GrClearOp(const SkIRect& rect, const SkPMColor4f& color, bool fullScreen) |
| 58 | : INHERITED(ClassID()) |
| 59 | , fClip(GrFixedClip(rect)) |
| 60 | , fColor(color) { |
| 61 | |
| 62 | if (fullScreen) { |
| 63 | fClip.disableScissor(); |
| 64 | } |
| 65 | this->setBounds(SkRect::Make(rect), HasAABloat::kNo, IsHairline::kNo); |
| 66 | } |
| 67 | |
| 68 | CombineResult onCombineIfPossible(GrOp* t, GrRecordingContext::Arenas*, |
| 69 | const GrCaps& caps) override { |
| 70 | // 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. |
| 73 | GrClearOp* cb = t->cast<GrClearOp>(); |
| 74 | if (fClip.windowRectsState() != cb->fClip.windowRectsState()) { |
| 75 | return CombineResult::kCannotCombine; |
| 76 | } |
| 77 | if (cb->contains(this)) { |
| 78 | fClip = cb->fClip; |
| 79 | fColor = cb->fColor; |
| 80 | return CombineResult::kMerged; |
| 81 | } else if (cb->fColor == fColor && this->contains(cb)) { |
| 82 | return CombineResult::kMerged; |
| 83 | } |
| 84 | return CombineResult::kCannotCombine; |
| 85 | } |
| 86 | |
| 87 | bool contains(const GrClearOp* that) const { |
| 88 | // The constructor ensures that scissor gets disabled on any clip that fills the entire RT. |
| 89 | return !fClip.scissorEnabled() || |
| 90 | (that->fClip.scissorEnabled() && |
| 91 | fClip.scissorRect().contains(that->fClip.scissorRect())); |
| 92 | } |
| 93 | |
| 94 | void onPrePrepare(GrRecordingContext*, |
| 95 | const GrSurfaceProxyView* writeView, |
| 96 | GrAppliedClip*, |
| 97 | const GrXferProcessor::DstProxyView&) override {} |
| 98 | |
| 99 | void onPrepare(GrOpFlushState*) override {} |
| 100 | |
| 101 | void onExecute(GrOpFlushState* state, const SkRect& chainBounds) override; |
| 102 | |
| 103 | GrFixedClip fClip; |
| 104 | SkPMColor4f fColor; |
| 105 | |
| 106 | typedef GrOp INHERITED; |
| 107 | }; |
| 108 | |
| 109 | #endif |
| 110 | |