1 /*
2  * Copyright 2016 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 GrFixedClip_DEFINED
9 #define GrFixedClip_DEFINED
10 
11 #include "src/gpu/GrClip.h"
12 #include "src/gpu/GrScissorState.h"
13 #include "src/gpu/GrWindowRectsState.h"
14 
15 /**
16  * Implements GrHardClip with scissor and window rectangles.
17  */
18 class GrFixedClip final : public GrHardClip {
19 public:
GrFixedClip(const SkISize & rtDims)20     explicit GrFixedClip(const SkISize& rtDims) : fScissorState(rtDims) {}
GrFixedClip(const SkISize & rtDims,const SkIRect & scissorRect)21     GrFixedClip(const SkISize& rtDims, const SkIRect& scissorRect)
22             : GrFixedClip(rtDims) {
23         SkAssertResult(fScissorState.set(scissorRect));
24     }
25 
scissorState()26     const GrScissorState& scissorState() const { return fScissorState; }
scissorEnabled()27     bool scissorEnabled() const { return fScissorState.enabled(); }
28     // Returns the scissor rect or rt bounds if the scissor test is not enabled.
scissorRect()29     const SkIRect& scissorRect() const { return fScissorState.rect(); }
30 
disableScissor()31     void disableScissor() { fScissorState.setDisabled(); }
32 
setScissor(const SkIRect & irect)33     bool SK_WARN_UNUSED_RESULT setScissor(const SkIRect& irect) {
34         return fScissorState.set(irect);
35     }
intersect(const SkIRect & irect)36     bool SK_WARN_UNUSED_RESULT intersect(const SkIRect& irect) {
37         return fScissorState.intersect(irect);
38     }
39 
windowRectsState()40     const GrWindowRectsState& windowRectsState() const { return fWindowRectsState; }
hasWindowRectangles()41     bool hasWindowRectangles() const { return fWindowRectsState.enabled(); }
42 
disableWindowRectangles()43     void disableWindowRectangles() { fWindowRectsState.setDisabled(); }
44 
setWindowRectangles(const GrWindowRectangles & windows,GrWindowRectsState::Mode mode)45     void setWindowRectangles(const GrWindowRectangles& windows, GrWindowRectsState::Mode mode) {
46         fWindowRectsState.set(windows, mode);
47     }
48 
49     SkIRect getConservativeBounds() const final;
50     Effect apply(GrAppliedHardClip*, SkIRect*) const final;
51     PreClipResult preApply(const SkRect& drawBounds, GrAA aa) const final;
52 
53 private:
54     GrScissorState       fScissorState;
55     GrWindowRectsState   fWindowRectsState;
56 };
57 
58 #endif
59