• 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, IsHairline::kNo);
66     }
67 
onCombineIfPossible(GrOp * t,GrRecordingContext::Arenas *,const GrCaps & caps)68     CombineResult onCombineIfPossible(GrOp* t, GrRecordingContext::Arenas*,
69                                       const GrCaps& caps) override {
70         // This could be much more complicated. Currently we look at cases where the new clear
71         // contains the old clear, or when the new clear is a subset of the old clear and is the
72         // same color.
73         GrClearOp* cb = t->cast<GrClearOp>();
74         if (fClip.windowRectsState() != cb->fClip.windowRectsState()) {
75             return CombineResult::kCannotCombine;
76         }
77         if (cb->contains(this)) {
78             fClip = cb->fClip;
79             fColor = cb->fColor;
80             return CombineResult::kMerged;
81         } else if (cb->fColor == fColor && this->contains(cb)) {
82             return CombineResult::kMerged;
83         }
84         return CombineResult::kCannotCombine;
85     }
86 
contains(const GrClearOp * that)87     bool contains(const GrClearOp* that) const {
88         // The constructor ensures that scissor gets disabled on any clip that fills the entire RT.
89         return !fClip.scissorEnabled() ||
90                (that->fClip.scissorEnabled() &&
91                 fClip.scissorRect().contains(that->fClip.scissorRect()));
92     }
93 
onPrepare(GrOpFlushState *)94     void onPrepare(GrOpFlushState*) override {}
95 
96     void onExecute(GrOpFlushState* state, const SkRect& chainBounds) override;
97 
98     GrFixedClip fClip;
99     SkPMColor4f fColor;
100 
101     typedef GrOp INHERITED;
102 };
103 
104 #endif
105