blob: dc1b93987a6328997b4a1f8079e112e78bf4414b [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,
Brian Osman9a9baae2018-11-05 15:06:26 -050019 const SkPMColor4f& color,
Robert Phillips7c525e62018-06-12 10:11:12 -040020 GrSurfaceProxy* dstProxy) {
Brian Salomon9f2b86c2019-10-22 10:37:46 -040021 const SkIRect rect = SkIRect::MakeSize(dstProxy->dimensions());
Michael Ludwig1e632792020-05-21 12:45:31 -040022 if (scissor.enabled() && !SkIRect::Intersects(scissor.rect(), 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
Michael Ludwig1e632792020-05-21 12:45:31 -040028 return pool->allocate<GrClearOp>(scissor, 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
Michael Ludwig1e632792020-05-21 12:45:31 -040042GrClearOp::GrClearOp(const GrScissorState& scissor, const SkPMColor4f& color, GrSurfaceProxy* proxy)
Jim Van Verth6a40abc2017-11-02 16:56:09 +000043 : INHERITED(ClassID())
Michael Ludwig1e632792020-05-21 12:45:31 -040044 , fScissor(scissor)
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040045 , fColor(color) {
Brian Salomon9f2b86c2019-10-22 10:37:46 -040046 const SkIRect rtRect = SkIRect::MakeSize(proxy->dimensions());
Michael Ludwig1e632792020-05-21 12:45:31 -040047 if (fScissor.enabled()) {
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040048 // Don't let scissors extend outside the RT. This may improve op combining.
Michael Ludwig1e632792020-05-21 12:45:31 -040049 if (!fScissor.intersect(rtRect)) {
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040050 SkASSERT(0); // should be caught upstream
Michael Ludwig1e632792020-05-21 12:45:31 -040051 fScissor.set(SkIRect::MakeEmpty());
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040052 }
53
Michael Ludwig1e632792020-05-21 12:45:31 -040054 if (proxy->isFunctionallyExact() && fScissor.rect() == rtRect) {
55 fScissor.setDisabled();
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040056 }
57 }
Michael Ludwig1e632792020-05-21 12:45:31 -040058 this->setBounds(SkRect::Make(fScissor.enabled() ? fScissor.rect() : rtRect),
Greg Daniel5faf4742019-10-01 15:14:44 -040059 HasAABloat::kNo, IsHairline::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());
Michael Ludwig1e632792020-05-21 12:45:31 -040064 state->opsRenderPass()->clear(fScissor, fColor);
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040065}