Robert Phillips | fbcef6e | 2017-06-15 12:07:18 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 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. |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include "GrClearOp.h" |
| 9 | |
| 10 | #include "GrGpuCommandBuffer.h" |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 11 | #include "GrMemoryPool.h" |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 12 | #include "GrOpFlushState.h" |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 13 | #include "GrProxyProvider.h" |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 14 | #include "GrRecordingContext.h" |
| 15 | #include "GrRecordingContextPriv.h" |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 16 | |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 17 | std::unique_ptr<GrClearOp> GrClearOp::Make(GrRecordingContext* context, |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 18 | const GrFixedClip& clip, |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 19 | const SkPMColor4f& color, |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 20 | GrSurfaceProxy* dstProxy) { |
| 21 | const SkIRect rect = SkIRect::MakeWH(dstProxy->width(), dstProxy->height()); |
Brian Salomon | d818ebf | 2018-07-02 14:08:49 +0000 | [diff] [blame] | 22 | if (clip.scissorEnabled() && !SkIRect::Intersects(clip.scissorRect(), rect)) { |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 23 | return nullptr; |
| 24 | } |
| 25 | |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 26 | GrOpMemoryPool* pool = context->priv().opMemoryPool(); |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 27 | |
| 28 | return pool->allocate<GrClearOp>(clip, color, dstProxy); |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 29 | } |
| 30 | |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 31 | std::unique_ptr<GrClearOp> GrClearOp::Make(GrRecordingContext* context, |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 32 | const SkIRect& rect, |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 33 | const SkPMColor4f& color, |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 34 | bool fullScreen) { |
| 35 | SkASSERT(fullScreen || !rect.isEmpty()); |
| 36 | |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 37 | GrOpMemoryPool* pool = context->priv().opMemoryPool(); |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 38 | |
| 39 | return pool->allocate<GrClearOp>(rect, color, fullScreen); |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 40 | } |
| 41 | |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 42 | GrClearOp::GrClearOp(const GrFixedClip& clip, const SkPMColor4f& color, GrSurfaceProxy* proxy) |
Jim Van Verth | 6a40abc | 2017-11-02 16:56:09 +0000 | [diff] [blame] | 43 | : INHERITED(ClassID()) |
Robert Phillips | fbcef6e | 2017-06-15 12:07:18 -0400 | [diff] [blame] | 44 | , fClip(clip) |
| 45 | , fColor(color) { |
| 46 | const SkIRect rtRect = SkIRect::MakeWH(proxy->width(), proxy->height()); |
Brian Salomon | d818ebf | 2018-07-02 14:08:49 +0000 | [diff] [blame] | 47 | if (fClip.scissorEnabled()) { |
Robert Phillips | fbcef6e | 2017-06-15 12:07:18 -0400 | [diff] [blame] | 48 | // Don't let scissors extend outside the RT. This may improve op combining. |
| 49 | if (!fClip.intersect(rtRect)) { |
| 50 | SkASSERT(0); // should be caught upstream |
| 51 | fClip = GrFixedClip(SkIRect::MakeEmpty()); |
| 52 | } |
| 53 | |
Robert Phillips | 1afd4cd | 2018-01-08 13:40:32 -0500 | [diff] [blame] | 54 | if (GrProxyProvider::IsFunctionallyExact(proxy) && fClip.scissorRect() == rtRect) { |
Robert Phillips | fbcef6e | 2017-06-15 12:07:18 -0400 | [diff] [blame] | 55 | fClip.disableScissor(); |
| 56 | } |
| 57 | } |
Brian Salomon | d818ebf | 2018-07-02 14:08:49 +0000 | [diff] [blame] | 58 | this->setBounds(SkRect::Make(fClip.scissorEnabled() ? fClip.scissorRect() : rtRect), |
| 59 | HasAABloat::kNo, IsZeroArea::kNo); |
Robert Phillips | fbcef6e | 2017-06-15 12:07:18 -0400 | [diff] [blame] | 60 | } |
| 61 | |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 62 | void GrClearOp::onExecute(GrOpFlushState* state, const SkRect& chainBounds) { |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 63 | SkASSERT(state->rtCommandBuffer()); |
| 64 | state->rtCommandBuffer()->clear(fClip, fColor); |
Robert Phillips | fbcef6e | 2017-06-15 12:07:18 -0400 | [diff] [blame] | 65 | } |