blob: 6e76191dff0ede718cd8a61e871c45961e92ff06 [file] [log] [blame]
* Copyright 2015 Google Inc.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
#ifndef GrClearOp_DEFINED
#define GrClearOp_DEFINED
#include "GrFixedClip.h"
#include "GrOp.h"
class GrOpFlushState;
class GrClearOp final : public GrOp {
static std::unique_ptr<GrClearOp> Make(GrContext* context,
const GrFixedClip& clip,
GrColor color,
GrSurfaceProxy* dstProxy);
static std::unique_ptr<GrClearOp> Make(GrContext* context,
const SkIRect& rect,
GrColor color,
bool fullScreen);
const char* name() const override { return "Clear"; }
SkString dumpInfo() const override {
SkString string;
string.appendf("Scissor [ ");
if (fClip.scissorEnabled()) {
const SkIRect& r = fClip.scissorRect();
string.appendf("L: %d, T: %d, R: %d, B: %d", r.fLeft, r.fTop, r.fRight, r.fBottom);
} else {
string.appendf("], Color: 0x%08x\n", fColor);
return string;
GrColor color() const { return fColor; }
void setColor(GrColor color) { fColor = color; }
friend class GrOpMemoryPool; // for ctors
GrClearOp(const GrFixedClip& clip, GrColor color, GrSurfaceProxy* proxy);
GrClearOp(const SkIRect& rect, GrColor color, bool fullScreen)
, fClip(GrFixedClip(rect))
, fColor(color) {
if (fullScreen) {
this->setBounds(SkRect::Make(rect), HasAABloat::kNo, IsZeroArea::kNo);
bool onCombineIfPossible(GrOp* t, const GrCaps& caps) override {
// This could be much more complicated. Currently we look at cases where the new clear
// contains the old clear, or when the new clear is a subset of the old clear and is the
// same color.
GrClearOp* cb = t->cast<GrClearOp>();
if (fClip.windowRectsState() != cb->fClip.windowRectsState()) {
return false;
if (cb->contains(this)) {
fClip = cb->fClip;
fColor = cb->fColor;
return true;
} else if (cb->fColor == fColor && this->contains(cb)) {
return true;
return false;
bool contains(const GrClearOp* that) const {
// The constructor ensures that scissor gets disabled on any clip that fills the entire RT.
return !fClip.scissorEnabled() ||
(that->fClip.scissorEnabled() &&
void onPrepare(GrOpFlushState*) override {}
void onExecute(GrOpFlushState* state) override;
GrFixedClip fClip;
GrColor fColor;
typedef GrOp INHERITED;