blob: 744bb27a81acfca6339c6b81896ed738f00da0a2 [file] [log] [blame]
csmartdalton02fa32c2016-08-19 13:29:27 -07001/*
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 "GrClip.h"
csmartdaltonbf4a8f92016-09-06 10:01:06 -070012#include "GrScissorState.h"
13#include "GrWindowRectsState.h"
csmartdalton02fa32c2016-08-19 13:29:27 -070014
15/**
csmartdalton29df7602016-08-31 11:55:52 -070016 * GrFixedClip is a clip that gets implemented by fixed-function hardware.
csmartdalton02fa32c2016-08-19 13:29:27 -070017 */
18class GrFixedClip final : public GrClip {
19public:
csmartdalton29df7602016-08-31 11:55:52 -070020 GrFixedClip() = default;
21 explicit GrFixedClip(const SkIRect& scissorRect) : fScissorState(scissorRect) {}
csmartdalton02fa32c2016-08-19 13:29:27 -070022
csmartdalton29df7602016-08-31 11:55:52 -070023 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 bool SK_WARN_UNUSED_RESULT intersect(const SkIRect& irect) {
30 return fScissorState.intersect(irect);
csmartdalton02fa32c2016-08-19 13:29:27 -070031 }
32
csmartdaltonbf4a8f92016-09-06 10:01:06 -070033 const GrWindowRectsState& windowRectsState() const { return fWindowRectsState; }
34 bool hasWindowRectangles() const { return fWindowRectsState.enabled(); }
35
36 void disableWindowRectangles() { fWindowRectsState.setDisabled(); }
37
Brian Salomon9a767722017-03-13 17:57:28 -040038 void setWindowRectangles(const GrWindowRectangles& windows, GrWindowRectsState::Mode mode) {
39 fWindowRectsState.set(windows, mode);
csmartdalton02fa32c2016-08-19 13:29:27 -070040 }
csmartdalton02fa32c2016-08-19 13:29:27 -070041
csmartdaltonbf4a8f92016-09-06 10:01:06 -070042 bool quickContains(const SkRect&) const override;
43 void getConservativeBounds(int w, int h, SkIRect* devResult, bool* iior) const override;
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050044 bool isRRect(const SkRect& rtBounds, SkRRect* rr, GrAA*) const override;
Brian Salomon97180af2017-03-14 13:42:58 -040045 bool apply(GrContext*, GrRenderTargetContext*, bool, bool, GrAppliedClip*,
46 SkRect*) const override;
csmartdalton02fa32c2016-08-19 13:29:27 -070047
csmartdalton29df7602016-08-31 11:55:52 -070048 static const GrFixedClip& Disabled();
49
50private:
csmartdaltonbf4a8f92016-09-06 10:01:06 -070051 GrScissorState fScissorState;
52 GrWindowRectsState fWindowRectsState;
csmartdalton02fa32c2016-08-19 13:29:27 -070053};
54
55#endif