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