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: |
20 | GrFixedClip() = default; |
21 | explicit GrFixedClip(const SkIRect& scissorRect) : fScissorState(scissorRect) {} |
22 | |
23 | const GrScissorState& scissorState() const { return fScissorState; } |
24 | bool scissorEnabled() const { return fScissorState.enabled(); } |
25 | const SkIRect& scissorRect() const { SkASSERT(scissorEnabled()); return fScissorState.rect(); } |
26 | |
27 | void disableScissor() { fScissorState.setDisabled(); } |
28 | |
29 | void setScissor(const SkIRect& irect) { |
30 | fScissorState.set(irect); |
31 | } |
32 | bool SK_WARN_UNUSED_RESULT intersect(const SkIRect& irect) { |
33 | return fScissorState.intersect(irect); |
34 | } |
35 | |
36 | const GrWindowRectsState& windowRectsState() const { return fWindowRectsState; } |
37 | bool hasWindowRectangles() const { return fWindowRectsState.enabled(); } |
38 | |
39 | void disableWindowRectangles() { fWindowRectsState.setDisabled(); } |
40 | |
41 | void setWindowRectangles(const GrWindowRectangles& windows, GrWindowRectsState::Mode mode) { |
42 | fWindowRectsState.set(windows, mode); |
43 | } |
44 | |
45 | bool quickContains(const SkRect&) const override; |
46 | void getConservativeBounds(int w, int h, SkIRect* devResult, bool* iior) const override; |
47 | bool isRRect(const SkRect& rtBounds, SkRRect* rr, GrAA*) const override; |
48 | bool apply(int rtWidth, int rtHeight, GrAppliedHardClip*, SkRect*) const override; |
49 | |
50 | static const GrFixedClip& Disabled(); |
51 | |
52 | private: |
53 | GrScissorState fScissorState; |
54 | GrWindowRectsState fWindowRectsState; |
55 | }; |
56 | |
57 | #endif |
58 | |