blob: 287fc7d4557f229cb340b4a71e305c8c3197b3f8 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "src/gpu/ops/GrClearOp.h"
Robert Phillipsb0e93a22017-08-29 08:26:54 -04009
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "include/private/GrRecordingContext.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "src/gpu/GrMemoryPool.h"
12#include "src/gpu/GrOpFlushState.h"
Greg Daniel2d41d0d2019-08-26 11:08:51 -040013#include "src/gpu/GrOpsRenderPass.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050014#include "src/gpu/GrProxyProvider.h"
15#include "src/gpu/GrRecordingContextPriv.h"
Robert Phillipsb0e93a22017-08-29 08:26:54 -040016
Robert Phillipsb97da532019-02-12 15:24:12 -050017std::unique_ptr<GrClearOp> GrClearOp::Make(GrRecordingContext* context,
Robert Phillips7c525e62018-06-12 10:11:12 -040018 const GrFixedClip& clip,
Brian Osman9a9baae2018-11-05 15:06:26 -050019 const SkPMColor4f& color,
Robert Phillips7c525e62018-06-12 10:11:12 -040020 GrSurfaceProxy* dstProxy) {
21 const SkIRect rect = SkIRect::MakeWH(dstProxy->width(), dstProxy->height());
Brian Salomond818ebf2018-07-02 14:08:49 +000022 if (clip.scissorEnabled() && !SkIRect::Intersects(clip.scissorRect(), rect)) {
Robert Phillips7c525e62018-06-12 10:11:12 -040023 return nullptr;
24 }
25
Robert Phillips9da87e02019-02-04 13:26:26 -050026 GrOpMemoryPool* pool = context->priv().opMemoryPool();
Robert Phillipsc994a932018-06-19 13:09:54 -040027
28 return pool->allocate<GrClearOp>(clip, color, dstProxy);
Robert Phillips7c525e62018-06-12 10:11:12 -040029}
30
Robert Phillipsb97da532019-02-12 15:24:12 -050031std::unique_ptr<GrClearOp> GrClearOp::Make(GrRecordingContext* context,
Robert Phillips7c525e62018-06-12 10:11:12 -040032 const SkIRect& rect,
Brian Osman9a9baae2018-11-05 15:06:26 -050033 const SkPMColor4f& color,
Robert Phillips7c525e62018-06-12 10:11:12 -040034 bool fullScreen) {
35 SkASSERT(fullScreen || !rect.isEmpty());
36
Robert Phillips9da87e02019-02-04 13:26:26 -050037 GrOpMemoryPool* pool = context->priv().opMemoryPool();
Robert Phillipsc994a932018-06-19 13:09:54 -040038
39 return pool->allocate<GrClearOp>(rect, color, fullScreen);
Robert Phillips7c525e62018-06-12 10:11:12 -040040}
41
Brian Osman9a9baae2018-11-05 15:06:26 -050042GrClearOp::GrClearOp(const GrFixedClip& clip, const SkPMColor4f& color, GrSurfaceProxy* proxy)
Jim Van Verth6a40abc2017-11-02 16:56:09 +000043 : INHERITED(ClassID())
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040044 , fClip(clip)
45 , fColor(color) {
46 const SkIRect rtRect = SkIRect::MakeWH(proxy->width(), proxy->height());
Brian Salomond818ebf2018-07-02 14:08:49 +000047 if (fClip.scissorEnabled()) {
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040048 // 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 Phillips1afd4cd2018-01-08 13:40:32 -050054 if (GrProxyProvider::IsFunctionallyExact(proxy) && fClip.scissorRect() == rtRect) {
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040055 fClip.disableScissor();
56 }
57 }
Brian Salomond818ebf2018-07-02 14:08:49 +000058 this->setBounds(SkRect::Make(fClip.scissorEnabled() ? fClip.scissorRect() : rtRect),
59 HasAABloat::kNo, IsZeroArea::kNo);
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040060}
61
Brian Salomon588cec72018-11-14 13:56:37 -050062void GrClearOp::onExecute(GrOpFlushState* state, const SkRect& chainBounds) {
Greg Daniel2d41d0d2019-08-26 11:08:51 -040063 SkASSERT(state->opsRenderPass());
64 state->opsRenderPass()->clear(fClip, fColor);
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040065}