blob: 56ecb13a797336384a0c8f8fffc2a927f7b319c7 [file] [log] [blame]
bsalomon53469832015-08-18 09:20:09 -07001/*
2 * Copyright 2015 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.
6 */
7
Brian Salomon7dae46a2016-12-14 16:21:37 -05008#ifndef GrClearOp_DEFINED
9#define GrClearOp_DEFINED
bsalomon53469832015-08-18 09:20:09 -070010
csmartdalton29df7602016-08-31 11:55:52 -070011#include "GrFixedClip.h"
Brian Salomon25a88092016-12-01 09:36:50 -050012#include "GrOp.h"
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040013
14class GrOpFlushState;
bsalomon53469832015-08-18 09:20:09 -070015
Brian Salomon7dae46a2016-12-14 16:21:37 -050016class GrClearOp final : public GrOp {
bsalomon53469832015-08-18 09:20:09 -070017public:
Brian Salomon25a88092016-12-01 09:36:50 -050018 DEFINE_OP_CLASS_ID
reed1b55a962015-09-17 20:16:13 -070019
Brian Salomonf8334782017-01-03 09:42:58 -050020 static std::unique_ptr<GrClearOp> Make(const GrFixedClip& clip, GrColor color,
Jim Van Verth6a40abc2017-11-02 16:56:09 +000021 GrSurfaceProxy* dstProxy) {
Robert Phillips5efd5ea2017-05-30 13:47:32 -040022 const SkIRect rect = SkIRect::MakeWH(dstProxy->width(), dstProxy->height());
23 if (clip.scissorEnabled() && !SkIRect::Intersects(clip.scissorRect(), rect)) {
Robert Phillipsf7a72612017-03-31 10:03:45 -040024 return nullptr;
csmartdalton29df7602016-08-31 11:55:52 -070025 }
Robert Phillipsf7a72612017-03-31 10:03:45 -040026
Jim Van Verth6a40abc2017-11-02 16:56:09 +000027 return std::unique_ptr<GrClearOp>(new GrClearOp(clip, color, dstProxy));
bsalomon53469832015-08-18 09:20:09 -070028 }
29
Robert Phillipsf7a72612017-03-31 10:03:45 -040030 static std::unique_ptr<GrClearOp> Make(const SkIRect& rect, GrColor color,
Brian Salomonf8334782017-01-03 09:42:58 -050031 bool fullScreen) {
Robert Phillipsf7a72612017-03-31 10:03:45 -040032 SkASSERT(fullScreen || !rect.isEmpty());
33
Robert Phillips5efd5ea2017-05-30 13:47:32 -040034 return std::unique_ptr<GrClearOp>(new GrClearOp(rect, color, fullScreen));
Robert Phillips784b7bf2016-12-09 13:35:02 -050035 }
36
bsalomon53469832015-08-18 09:20:09 -070037 const char* name() const override { return "Clear"; }
38
Brian Salomon9dc2a9a2015-08-18 12:46:51 -040039 SkString dumpInfo() const override {
Robert Phillips1119dc32017-04-11 12:54:57 -040040 SkString string;
Robert Phillipsf5442bb2017-04-17 14:18:34 -040041 string.append(INHERITED::dumpInfo());
Robert Phillips5efd5ea2017-05-30 13:47:32 -040042 string.appendf("Scissor [ ");
csmartdalton29df7602016-08-31 11:55:52 -070043 if (fClip.scissorEnabled()) {
44 const SkIRect& r = fClip.scissorRect();
45 string.appendf("L: %d, T: %d, R: %d, B: %d", r.fLeft, r.fTop, r.fRight, r.fBottom);
Robert Phillipsf7a72612017-03-31 10:03:45 -040046 } else {
47 string.append("disabled");
csmartdalton29df7602016-08-31 11:55:52 -070048 }
Robert Phillipsf5442bb2017-04-17 14:18:34 -040049 string.appendf("], Color: 0x%08x\n", fColor);
bsalomon53469832015-08-18 09:20:09 -070050 return string;
51 }
52
Robert Phillipsf5442bb2017-04-17 14:18:34 -040053 GrColor color() const { return fColor; }
bsalomonfd8d0132016-08-11 11:25:33 -070054 void setColor(GrColor color) { fColor = color; }
55
bsalomon53469832015-08-18 09:20:09 -070056private:
Jim Van Verth6a40abc2017-11-02 16:56:09 +000057 GrClearOp(const GrFixedClip& clip, GrColor color, GrSurfaceProxy* proxy);
robertphillips9199a9f2016-07-13 07:48:43 -070058
Robert Phillips5efd5ea2017-05-30 13:47:32 -040059 GrClearOp(const SkIRect& rect, GrColor color, bool fullScreen)
Robert Phillips784b7bf2016-12-09 13:35:02 -050060 : INHERITED(ClassID())
61 , fClip(GrFixedClip(rect))
Robert Phillips5efd5ea2017-05-30 13:47:32 -040062 , fColor(color) {
Robert Phillipsf7a72612017-03-31 10:03:45 -040063
Robert Phillips784b7bf2016-12-09 13:35:02 -050064 if (fullScreen) {
65 fClip.disableScissor();
66 }
67 this->setBounds(SkRect::Make(rect), HasAABloat::kNo, IsZeroArea::kNo);
68 }
69
Brian Salomon25a88092016-12-01 09:36:50 -050070 bool onCombineIfPossible(GrOp* t, const GrCaps& caps) override {
bsalomone63ffef2016-02-05 07:17:34 -080071 // This could be much more complicated. Currently we look at cases where the new clear
72 // contains the old clear, or when the new clear is a subset of the old clear and is the
73 // same color.
Brian Salomon7dae46a2016-12-14 16:21:37 -050074 GrClearOp* cb = t->cast<GrClearOp>();
Brian Salomon9a767722017-03-13 17:57:28 -040075 if (fClip.windowRectsState() != cb->fClip.windowRectsState()) {
csmartdaltonbf4a8f92016-09-06 10:01:06 -070076 return false;
77 }
csmartdalton29df7602016-08-31 11:55:52 -070078 if (cb->contains(this)) {
79 fClip = cb->fClip;
bsalomon88cf17d2016-07-08 06:40:56 -070080 this->replaceBounds(*t);
bsalomone63ffef2016-02-05 07:17:34 -080081 fColor = cb->fColor;
82 return true;
csmartdalton29df7602016-08-31 11:55:52 -070083 } else if (cb->fColor == fColor && this->contains(cb)) {
bsalomone63ffef2016-02-05 07:17:34 -080084 return true;
85 }
bsalomon53469832015-08-18 09:20:09 -070086 return false;
87 }
88
Brian Salomon7dae46a2016-12-14 16:21:37 -050089 bool contains(const GrClearOp* that) const {
csmartdalton29df7602016-08-31 11:55:52 -070090 // The constructor ensures that scissor gets disabled on any clip that fills the entire RT.
91 return !fClip.scissorEnabled() ||
92 (that->fClip.scissorEnabled() &&
93 fClip.scissorRect().contains(that->fClip.scissorRect()));
94 }
95
Brian Salomon742e31d2016-12-07 17:06:19 -050096 void onPrepare(GrOpFlushState*) override {}
bsalomon53469832015-08-18 09:20:09 -070097
Robert Phillipsfbcef6e2017-06-15 12:07:18 -040098 void onExecute(GrOpFlushState* state) override;
bsalomon53469832015-08-18 09:20:09 -070099
Robert Phillips5efd5ea2017-05-30 13:47:32 -0400100 GrFixedClip fClip;
101 GrColor fColor;
Robert Phillips33f83152017-05-18 20:57:43 +0000102
Brian Salomon25a88092016-12-01 09:36:50 -0500103 typedef GrOp INHERITED;
bsalomon53469832015-08-18 09:20:09 -0700104};
105
bsalomon53469832015-08-18 09:20:09 -0700106#endif