blob: 9fa0091fd96799038a4c2bb07680928e2f8c431d [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 Phillipsb97da532019-02-12 15:24:12 -050014#include "GrRecordingContext.h"
15#include "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 Daniel500d58b2017-08-24 15:59:33 -040063 SkASSERT(state->rtCommandBuffer());
64 state->rtCommandBuffer()->clear(fClip, fColor);
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040065}