| 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 "include/gpu/GrTypes.h" |
| 12 | #include "src/gpu/GrScissorState.h" |
| 13 | #include "src/gpu/ops/GrOp.h" |
| 14 | |
| 15 | class GrOpFlushState; |
| 16 | class GrRecordingContext; |
| 17 | |
| 18 | class GrClearOp final : public GrOp { |
| 19 | public: |
| 20 | DEFINE_OP_CLASS_ID |
| 21 | |
| 22 | // A fullscreen or scissored clear, depending on the clip and proxy dimensions |
| 23 | static std::unique_ptr<GrClearOp> MakeColor(GrRecordingContext* context, |
| 24 | const GrScissorState& scissor, |
| 25 | const SkPMColor4f& color); |
| 26 | |
| 27 | static std::unique_ptr<GrClearOp> MakeStencilClip(GrRecordingContext* context, |
| 28 | const GrScissorState& scissor, |
| 29 | bool insideMask); |
| 30 | |
| 31 | const char* name() const override { return "Clear" ; } |
| 32 | |
| 33 | private: |
| 34 | friend class GrOpMemoryPool; // for ctors |
| 35 | |
| 36 | enum class Buffer { |
| 37 | kColor = 0b01, |
| 38 | kStencilClip = 0b10, |
| 39 | |
| 40 | kBoth = 0b11, |
| 41 | }; |
| 42 | GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(Buffer); |
| 43 | |
| 44 | GrClearOp(Buffer buffer, const GrScissorState& scissor, const SkPMColor4f& color, bool stencil); |
| 45 | |
| 46 | CombineResult onCombineIfPossible(GrOp* t, GrRecordingContext::Arenas*, |
| 47 | const GrCaps& caps) override; |
| 48 | |
| 49 | void onPrePrepare(GrRecordingContext*, const GrSurfaceProxyView* writeView, GrAppliedClip*, |
| 50 | const GrXferProcessor::DstProxyView&) override {} |
| 51 | |
| 52 | void onPrepare(GrOpFlushState*) override {} |
| 53 | |
| 54 | void onExecute(GrOpFlushState* state, const SkRect& chainBounds) override; |
| 55 | #if GR_TEST_UTILS |
| 56 | SkString onDumpInfo() const override { |
| 57 | SkString string("Scissor [ " ); |
| 58 | if (fScissor.enabled()) { |
| 59 | const SkIRect& r = fScissor.rect(); |
| 60 | string.appendf("L: %d, T: %d, R: %d, B: %d" , r.fLeft, r.fTop, r.fRight, r.fBottom); |
| 61 | } else { |
| 62 | string.append("disabled" ); |
| 63 | } |
| 64 | string.appendf("], Color: 0x%08x\n" , fColor.toBytes_RGBA()); |
| 65 | return string; |
| 66 | } |
| 67 | #endif |
| 68 | |
| 69 | GrScissorState fScissor; |
| 70 | SkPMColor4f fColor; |
| 71 | bool fStencilInsideMask; |
| 72 | Buffer fBuffer; |
| 73 | |
| 74 | typedef GrOp INHERITED; |
| 75 | }; |
| 76 | |
| 77 | GR_MAKE_BITFIELD_CLASS_OPS(GrClearOp::Buffer) |
| 78 | |
| 79 | #endif |
| 80 | |