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 | |
Robert Phillips | 46d7bd5 | 2021-09-01 13:02:28 -0400 | [diff] [blame] | 8 | #ifndef ClearOp_DEFINED |
| 9 | #define ClearOp_DEFINED |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 10 | |
Michael Ludwig | 9cced93 | 2020-06-08 09:30:09 -0400 | [diff] [blame] | 11 | #include "include/gpu/GrTypes.h" |
Michael Ludwig | 1e63279 | 2020-05-21 12:45:31 -0400 | [diff] [blame] | 12 | #include "src/gpu/GrScissorState.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 13 | #include "src/gpu/ops/GrOp.h" |
Robert Phillips | fbcef6e | 2017-06-15 12:07:18 -0400 | [diff] [blame] | 14 | |
| 15 | class GrOpFlushState; |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 16 | class GrRecordingContext; |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 17 | |
Robert Phillips | 46d7bd5 | 2021-09-01 13:02:28 -0400 | [diff] [blame] | 18 | namespace skgpu::v1 { |
| 19 | |
| 20 | class ClearOp final : public GrOp { |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 21 | public: |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 22 | DEFINE_OP_CLASS_ID |
reed | 1b55a96 | 2015-09-17 20:16:13 -0700 | [diff] [blame] | 23 | |
Michael Ludwig | d1d997e | 2020-06-04 15:52:44 -0400 | [diff] [blame] | 24 | // A fullscreen or scissored clear, depending on the clip and proxy dimensions |
Herb Derby | c76d409 | 2020-10-07 16:46:15 -0400 | [diff] [blame] | 25 | static GrOp::Owner MakeColor(GrRecordingContext* context, |
| 26 | const GrScissorState& scissor, |
Brian Salomon | 07bc9a2 | 2020-12-02 13:37:16 -0500 | [diff] [blame] | 27 | std::array<float, 4> color); |
Michael Ludwig | 9cced93 | 2020-06-08 09:30:09 -0400 | [diff] [blame] | 28 | |
Herb Derby | c76d409 | 2020-10-07 16:46:15 -0400 | [diff] [blame] | 29 | static GrOp::Owner MakeStencilClip(GrRecordingContext* context, |
| 30 | const GrScissorState& scissor, |
| 31 | bool insideMask); |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 32 | |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 33 | const char* name() const override { return "Clear"; } |
| 34 | |
Robert Phillips | 4b10d58 | 2020-12-02 18:27:18 -0500 | [diff] [blame] | 35 | const std::array<float, 4>& color() const { return fColor; } |
| 36 | bool stencilInsideMask() const { return fStencilInsideMask; } |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 37 | private: |
Herb Derby | c76d409 | 2020-10-07 16:46:15 -0400 | [diff] [blame] | 38 | friend class GrOp; // for ctors |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 39 | |
Michael Ludwig | 9cced93 | 2020-06-08 09:30:09 -0400 | [diff] [blame] | 40 | enum class Buffer { |
| 41 | kColor = 0b01, |
| 42 | kStencilClip = 0b10, |
| 43 | |
| 44 | kBoth = 0b11, |
| 45 | }; |
| 46 | GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(Buffer); |
| 47 | |
Robert Phillips | 46d7bd5 | 2021-09-01 13:02:28 -0400 | [diff] [blame] | 48 | ClearOp(Buffer buffer, |
| 49 | const GrScissorState& scissor, |
| 50 | std::array<float, 4> color, |
| 51 | bool stencil); |
Robert Phillips | 784b7bf | 2016-12-09 13:35:02 -0500 | [diff] [blame] | 52 | |
Herb Derby | e25c300 | 2020-10-27 15:57:27 -0400 | [diff] [blame] | 53 | CombineResult onCombineIfPossible(GrOp* t, SkArenaAlloc*, const GrCaps& caps) override; |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 54 | |
Adlai Holler | e2296f7 | 2020-11-19 13:41:26 -0500 | [diff] [blame] | 55 | void onPrePrepare(GrRecordingContext*, const GrSurfaceProxyView& writeView, GrAppliedClip*, |
John Stiles | 52cb1d0 | 2021-06-02 11:58:05 -0400 | [diff] [blame] | 56 | const GrDstProxyView&, GrXferBarrierFlags renderPassXferBarriers, |
| 57 | GrLoadOp colorLoadOp) override {} |
Robert Phillips | c655c3a | 2020-03-18 13:23:45 -0400 | [diff] [blame] | 58 | |
Brian Salomon | 742e31d | 2016-12-07 17:06:19 -0500 | [diff] [blame] | 59 | void onPrepare(GrOpFlushState*) override {} |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 60 | |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 61 | void onExecute(GrOpFlushState* state, const SkRect& chainBounds) override; |
John Stiles | af36652 | 2020-08-13 09:57:34 -0400 | [diff] [blame] | 62 | #if GR_TEST_UTILS |
| 63 | SkString onDumpInfo() const override { |
| 64 | SkString string("Scissor [ "); |
| 65 | if (fScissor.enabled()) { |
| 66 | const SkIRect& r = fScissor.rect(); |
| 67 | string.appendf("L: %d, T: %d, R: %d, B: %d", r.fLeft, r.fTop, r.fRight, r.fBottom); |
| 68 | } else { |
| 69 | string.append("disabled"); |
| 70 | } |
Brian Salomon | 07bc9a2 | 2020-12-02 13:37:16 -0500 | [diff] [blame] | 71 | string.appendf("], Color: {%g, %g, %g, %g}\n", fColor[0], fColor[1], fColor[2], fColor[3]); |
John Stiles | af36652 | 2020-08-13 09:57:34 -0400 | [diff] [blame] | 72 | return string; |
| 73 | } |
| 74 | #endif |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 75 | |
Brian Salomon | 07bc9a2 | 2020-12-02 13:37:16 -0500 | [diff] [blame] | 76 | GrScissorState fScissor; |
| 77 | std::array<float, 4> fColor; |
| 78 | bool fStencilInsideMask; |
| 79 | Buffer fBuffer; |
bsalomon | 5346983 | 2015-08-18 09:20:09 -0700 | [diff] [blame] | 80 | }; |
| 81 | |
Robert Phillips | 46d7bd5 | 2021-09-01 13:02:28 -0400 | [diff] [blame] | 82 | GR_MAKE_BITFIELD_CLASS_OPS(ClearOp::Buffer) |
Michael Ludwig | 9cced93 | 2020-06-08 09:30:09 -0400 | [diff] [blame] | 83 | |
Robert Phillips | 46d7bd5 | 2021-09-01 13:02:28 -0400 | [diff] [blame] | 84 | } // namespace skgpu::v1 |
| 85 | |
| 86 | #endif // ClearOp_DEFINED |