blob: 612ff2085d3ce106e476854c259446414e0aef97 [file] [log] [blame]
Robert Phillipsfbcef6e2017-06-15 12:07:18 -04001/*
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 Phillipsb0e93a22017-08-29 08:26:54 -04006 */
7
8#include "GrClearOp.h"
9
10#include "GrGpuCommandBuffer.h"
Robert Phillips7c525e62018-06-12 10:11:12 -040011#include "GrMemoryPool.h"
Robert Phillipsb0e93a22017-08-29 08:26:54 -040012#include "GrOpFlushState.h"
Robert Phillips1afd4cd2018-01-08 13:40:32 -050013#include "GrProxyProvider.h"
Robert Phillipsb0e93a22017-08-29 08:26:54 -040014
Robert Phillips7c525e62018-06-12 10:11:12 -040015std::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 Salomond818ebf2018-07-02 14:08:49 +000020 if (clip.scissorEnabled() && !SkIRect::Intersects(clip.scissorRect(), rect)) {
Robert Phillips7c525e62018-06-12 10:11:12 -040021 return nullptr;
22 }
23
Robert Phillipsc994a932018-06-19 13:09:54 -040024 GrOpMemoryPool* pool = context->contextPriv().opMemoryPool();
25
26 return pool->allocate<GrClearOp>(clip, color, dstProxy);
Robert Phillips7c525e62018-06-12 10:11:12 -040027}
28
29std::unique_ptr<GrClearOp> GrClearOp::Make(GrContext* context,
30 const SkIRect& rect,
31 GrColor color,
32 bool fullScreen) {
33 SkASSERT(fullScreen || !rect.isEmpty());
34
Robert Phillipsc994a932018-06-19 13:09:54 -040035 GrOpMemoryPool* pool = context->contextPriv().opMemoryPool();
36
37 return pool->allocate<GrClearOp>(rect, color, fullScreen);
Robert Phillips7c525e62018-06-12 10:11:12 -040038}
39
Jim Van Verth6a40abc2017-11-02 16:56:09 +000040GrClearOp::GrClearOp(const GrFixedClip& clip, GrColor color, GrSurfaceProxy* proxy)
41 : INHERITED(ClassID())
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040042 , fClip(clip)
43 , fColor(color) {
44 const SkIRect rtRect = SkIRect::MakeWH(proxy->width(), proxy->height());
Brian Salomond818ebf2018-07-02 14:08:49 +000045 if (fClip.scissorEnabled()) {
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040046 // 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 Phillips1afd4cd2018-01-08 13:40:32 -050052 if (GrProxyProvider::IsFunctionallyExact(proxy) && fClip.scissorRect() == rtRect) {
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040053 fClip.disableScissor();
54 }
55 }
Brian Salomond818ebf2018-07-02 14:08:49 +000056 this->setBounds(SkRect::Make(fClip.scissorEnabled() ? fClip.scissorRect() : rtRect),
57 HasAABloat::kNo, IsZeroArea::kNo);
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040058}
59
60void GrClearOp::onExecute(GrOpFlushState* state) {
Greg Daniel500d58b2017-08-24 15:59:33 -040061 SkASSERT(state->rtCommandBuffer());
62 state->rtCommandBuffer()->clear(fClip, fColor);
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040063}