• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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(GrContext* context,
21                                            const GrFixedClip& clip,
22                                            const SkPMColor4f& color,
23                                            GrSurfaceProxy* dstProxy);
24 
25     static std::unique_ptr<GrClearOp> Make(GrContext* context,
26                                            const SkIRect& rect,
27                                            const SkPMColor4f& color,
28                                            bool fullScreen);
29 
name()30     const char* name() const override { return "Clear"; }
31 
32 #ifdef SK_DEBUG
dumpInfo()33     SkString dumpInfo() const override {
34         SkString string;
35         string.append(INHERITED::dumpInfo());
36         string.appendf("Scissor [ ");
37         if (fClip.scissorEnabled()) {
38             const SkIRect& r = fClip.scissorRect();
39             string.appendf("L: %d, T: %d, R: %d, B: %d", r.fLeft, r.fTop, r.fRight, r.fBottom);
40         } else {
41             string.append("disabled");
42         }
43         string.appendf("], Color: 0x%08x\n", fColor.toBytes_RGBA());
44         return string;
45     }
46 #endif
47 
color()48     const SkPMColor4f& color() const { return fColor; }
setColor(const SkPMColor4f & color)49     void setColor(const SkPMColor4f& color) { fColor = color; }
50 
51 private:
52     friend class GrOpMemoryPool; // for ctors
53 
54     GrClearOp(const GrFixedClip& clip, const SkPMColor4f& color, GrSurfaceProxy* proxy);
55 
GrClearOp(const SkIRect & rect,const SkPMColor4f & color,bool fullScreen)56     GrClearOp(const SkIRect& rect, const SkPMColor4f& color, bool fullScreen)
57         : INHERITED(ClassID())
58         , fClip(GrFixedClip(rect))
59         , fColor(color) {
60 
61         if (fullScreen) {
62             fClip.disableScissor();
63         }
64         this->setBounds(SkRect::Make(rect), HasAABloat::kNo, IsZeroArea::kNo);
65     }
66 
onCombineIfPossible(GrOp * t,const GrCaps & caps)67     CombineResult onCombineIfPossible(GrOp* t, const GrCaps& caps) override {
68         // This could be much more complicated. Currently we look at cases where the new clear
69         // contains the old clear, or when the new clear is a subset of the old clear and is the
70         // same color.
71         GrClearOp* cb = t->cast<GrClearOp>();
72         if (fClip.windowRectsState() != cb->fClip.windowRectsState()) {
73             return CombineResult::kCannotCombine;
74         }
75         if (cb->contains(this)) {
76             fClip = cb->fClip;
77             fColor = cb->fColor;
78             return CombineResult::kMerged;
79         } else if (cb->fColor == fColor && this->contains(cb)) {
80             return CombineResult::kMerged;
81         }
82         return CombineResult::kCannotCombine;
83     }
84 
contains(const GrClearOp * that)85     bool contains(const GrClearOp* that) const {
86         // The constructor ensures that scissor gets disabled on any clip that fills the entire RT.
87         return !fClip.scissorEnabled() ||
88                (that->fClip.scissorEnabled() &&
89                 fClip.scissorRect().contains(that->fClip.scissorRect()));
90     }
91 
onPrepare(GrOpFlushState *)92     void onPrepare(GrOpFlushState*) override {}
93 
94     void onExecute(GrOpFlushState* state, const SkRect& chainBounds) override;
95 
96     GrFixedClip fClip;
97     SkPMColor4f fColor;
98 
99     typedef GrOp INHERITED;
100 };
101 
102 #endif
103