Home | History | Annotate | Download | only in ops
      1 /*
      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 
      8 #ifndef GrClearOp_DEFINED
      9 #define GrClearOp_DEFINED
     10 
     11 #include "GrFixedClip.h"
     12 #include "GrOp.h"
     13 
     14 class GrOpFlushState;
     15 
     16 class GrClearOp final : public GrOp {
     17 public:
     18     DEFINE_OP_CLASS_ID
     19 
     20     static std::unique_ptr<GrClearOp> Make(const GrFixedClip& clip, GrColor color,
     21                                            GrSurfaceProxy* dstProxy) {
     22         const SkIRect rect = SkIRect::MakeWH(dstProxy->width(), dstProxy->height());
     23         if (clip.scissorEnabled() && !SkIRect::Intersects(clip.scissorRect(), rect)) {
     24             return nullptr;
     25         }
     26 
     27         return std::unique_ptr<GrClearOp>(new GrClearOp(clip, color, dstProxy));
     28     }
     29 
     30     static std::unique_ptr<GrClearOp> Make(const SkIRect& rect, GrColor color,
     31                                            bool fullScreen) {
     32         SkASSERT(fullScreen || !rect.isEmpty());
     33 
     34         return std::unique_ptr<GrClearOp>(new GrClearOp(rect, color, fullScreen));
     35     }
     36 
     37     const char* name() const override { return "Clear"; }
     38 
     39     SkString dumpInfo() const override {
     40         SkString string;
     41         string.append(INHERITED::dumpInfo());
     42         string.appendf("Scissor [ ");
     43         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);
     46         } else {
     47             string.append("disabled");
     48         }
     49         string.appendf("], Color: 0x%08x\n", fColor);
     50         return string;
     51     }
     52 
     53     GrColor color() const { return fColor; }
     54     void setColor(GrColor color) { fColor = color; }
     55 
     56 private:
     57     GrClearOp(const GrFixedClip& clip, GrColor color, GrSurfaceProxy* proxy);
     58 
     59     GrClearOp(const SkIRect& rect, GrColor color, bool fullScreen)
     60         : INHERITED(ClassID())
     61         , fClip(GrFixedClip(rect))
     62         , fColor(color) {
     63 
     64         if (fullScreen) {
     65             fClip.disableScissor();
     66         }
     67         this->setBounds(SkRect::Make(rect), HasAABloat::kNo, IsZeroArea::kNo);
     68     }
     69 
     70     bool onCombineIfPossible(GrOp* t, const GrCaps& caps) override {
     71         // 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.
     74         GrClearOp* cb = t->cast<GrClearOp>();
     75         if (fClip.windowRectsState() != cb->fClip.windowRectsState()) {
     76             return false;
     77         }
     78         if (cb->contains(this)) {
     79             fClip = cb->fClip;
     80             this->replaceBounds(*t);
     81             fColor = cb->fColor;
     82             return true;
     83         } else if (cb->fColor == fColor && this->contains(cb)) {
     84             return true;
     85         }
     86         return false;
     87     }
     88 
     89     bool contains(const GrClearOp* that) const {
     90         // 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 
     96     void onPrepare(GrOpFlushState*) override {}
     97 
     98     void onExecute(GrOpFlushState* state) override;
     99 
    100     GrFixedClip fClip;
    101     GrColor     fColor;
    102 
    103     typedef GrOp INHERITED;
    104 };
    105 
    106 #endif
    107