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