blob: d682bee8e5070dc51c32ac66c405448903a0c27b [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "src/gpu/GrClip.h"
12#include "src/gpu/GrScissorState.h"
13#include "src/gpu/GrWindowRectsState.h"
csmartdalton02fa32c2016-08-19 13:29:27 -070014
15/**
Chris Daltonbbfd5162017-11-07 13:35:22 -070016 * Implements GrHardClip with scissor and window rectangles.
csmartdalton02fa32c2016-08-19 13:29:27 -070017 */
Chris Daltonbbfd5162017-11-07 13:35:22 -070018class GrFixedClip final : public GrHardClip {
csmartdalton02fa32c2016-08-19 13:29:27 -070019public:
Michael Ludwigd1d997e2020-06-04 15:52:44 -040020 explicit GrFixedClip(const SkISize& rtDims) : fScissorState(rtDims) {}
21 GrFixedClip(const SkISize& rtDims, const SkIRect& scissorRect)
22 : GrFixedClip(rtDims) {
23 SkAssertResult(fScissorState.set(scissorRect));
24 }
csmartdalton02fa32c2016-08-19 13:29:27 -070025
csmartdalton29df7602016-08-31 11:55:52 -070026 const GrScissorState& scissorState() const { return fScissorState; }
Brian Salomond818ebf2018-07-02 14:08:49 +000027 bool scissorEnabled() const { return fScissorState.enabled(); }
Michael Ludwigd1d997e2020-06-04 15:52:44 -040028 // Returns the scissor rect or rt bounds if the scissor test is not enabled.
29 const SkIRect& scissorRect() const { return fScissorState.rect(); }
csmartdalton29df7602016-08-31 11:55:52 -070030
31 void disableScissor() { fScissorState.setDisabled(); }
32
Michael Ludwigd1d997e2020-06-04 15:52:44 -040033 bool SK_WARN_UNUSED_RESULT setScissor(const SkIRect& irect) {
34 return fScissorState.set(irect);
Brian Salomond818ebf2018-07-02 14:08:49 +000035 }
csmartdalton29df7602016-08-31 11:55:52 -070036 bool SK_WARN_UNUSED_RESULT intersect(const SkIRect& irect) {
37 return fScissorState.intersect(irect);
csmartdalton02fa32c2016-08-19 13:29:27 -070038 }
39
csmartdaltonbf4a8f92016-09-06 10:01:06 -070040 const GrWindowRectsState& windowRectsState() const { return fWindowRectsState; }
41 bool hasWindowRectangles() const { return fWindowRectsState.enabled(); }
42
43 void disableWindowRectangles() { fWindowRectsState.setDisabled(); }
44
Brian Salomon9a767722017-03-13 17:57:28 -040045 void setWindowRectangles(const GrWindowRectangles& windows, GrWindowRectsState::Mode mode) {
46 fWindowRectsState.set(windows, mode);
csmartdalton02fa32c2016-08-19 13:29:27 -070047 }
csmartdalton02fa32c2016-08-19 13:29:27 -070048
Michael Ludwig4e3cab72020-06-30 11:12:46 -040049 SkIRect getConservativeBounds() const final;
Michael Ludwig6397e802020-08-05 15:50:01 -040050 Effect apply(GrAppliedHardClip*, SkIRect*) const final;
51 PreClipResult preApply(const SkRect& drawBounds, GrAA aa) const final;
csmartdalton02fa32c2016-08-19 13:29:27 -070052
csmartdalton29df7602016-08-31 11:55:52 -070053private:
csmartdaltonbf4a8f92016-09-06 10:01:06 -070054 GrScissorState fScissorState;
55 GrWindowRectsState fWindowRectsState;
csmartdalton02fa32c2016-08-19 13:29:27 -070056};
57
58#endif