blob: 753f75da413171386f190ebb9140e9bbf9844bde [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,
Michael Ludwig1e632792020-05-21 12:45:31 -040018 const GrScissorState& scissor,
Michael Ludwig4926b072020-06-04 19:39:42 +000019 const SkPMColor4f& color,
20 const GrSurfaceProxy* dstProxy) {
21 const SkIRect rect = SkIRect::MakeSize(dstProxy->dimensions());
22 if (scissor.enabled() && !SkIRect::Intersects(scissor.rect(), rect)) {
23 return nullptr;
24 }
25
Robert Phillips9da87e02019-02-04 13:26:26 -050026 GrOpMemoryPool* pool = context->priv().opMemoryPool();
Michael Ludwig4926b072020-06-04 19:39:42 +000027 return pool->allocate<GrClearOp>(scissor, color, dstProxy);
Robert Phillips7c525e62018-06-12 10:11:12 -040028}
29
Michael Ludwig4926b072020-06-04 19:39:42 +000030GrClearOp::GrClearOp(const GrScissorState& scissor, const SkPMColor4f& color,
31 const GrSurfaceProxy* proxy)
Jim Van Verth6a40abc2017-11-02 16:56:09 +000032 : INHERITED(ClassID())
Michael Ludwig1e632792020-05-21 12:45:31 -040033 , fScissor(scissor)
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040034 , fColor(color) {
Michael Ludwig4926b072020-06-04 19:39:42 +000035 this->setBounds(scissor.enabled() ? SkRect::Make(scissor.rect()) : proxy->getBoundsRect(),
36 HasAABloat::kNo, IsHairline::kNo);
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040037}
38
Brian Salomon588cec72018-11-14 13:56:37 -050039void GrClearOp::onExecute(GrOpFlushState* state, const SkRect& chainBounds) {
Greg Daniel2d41d0d2019-08-26 11:08:51 -040040 SkASSERT(state->opsRenderPass());
Michael Ludwig1e632792020-05-21 12:45:31 -040041 state->opsRenderPass()->clear(fScissor, fColor);
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040042}