blob: 6fb7d23ed1a317dc6584b838957f21ca523b553b [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
38 void setWindowRectangles(const GrWindowRectangles& windows, const SkIPoint& origin,
39 GrWindowRectsState::Mode mode) {
40 fWindowRectsState.set(windows, origin, mode);
csmartdalton02fa32c2016-08-19 13:29:27 -070041 }
csmartdalton02fa32c2016-08-19 13:29:27 -070042
csmartdaltonbf4a8f92016-09-06 10:01:06 -070043 bool quickContains(const SkRect&) const override;
44 void getConservativeBounds(int w, int h, SkIRect* devResult, bool* iior) const override;
45 bool isRRect(const SkRect& rtBounds, SkRRect* rr, bool* aa) const override;
46 bool apply(GrContext*, GrDrawContext*, bool, bool, GrAppliedClip* out) 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