blob: 3e98c6cb056985d6cafdd242c9385185b706241d [file] [log] [blame]
csmartdalton28341fa2016-08-17 10:00:21 -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 GrAppliedClip_DEFINED
9#define GrAppliedClip_DEFINED
10
csmartdaltonbf4a8f92016-09-06 10:01:06 -070011#include "GrScissorState.h"
12#include "GrWindowRectsState.h"
csmartdalton28341fa2016-08-17 10:00:21 -070013
14class GrFragmentProcessor;
15
16/**
17 * Produced by GrClip. It provides a set of modifications to the drawing state that are used to
18 * create the final GrPipeline for a GrBatch.
19 */
20class GrAppliedClip : public SkNoncopyable {
21public:
22 GrAppliedClip(const SkRect& drawBounds)
23 : fHasStencilClip(false)
24 , fClippedDrawBounds(drawBounds) {
25 }
26
27 const GrScissorState& scissorState() const { return fScissorState; }
csmartdaltonbf4a8f92016-09-06 10:01:06 -070028 const GrWindowRectsState& windowRectsState() const { return fWindowRectsState; }
csmartdalton28341fa2016-08-17 10:00:21 -070029 GrFragmentProcessor* clipCoverageFragmentProcessor() const { return fClipCoverageFP.get(); }
30 bool hasStencilClip() const { return fHasStencilClip; }
31
32 /**
33 * Intersects the applied clip with the provided rect. Returns false if the draw became empty.
34 */
35 bool addScissor(const SkIRect& irect) {
36 return fScissorState.intersect(irect) && fClippedDrawBounds.intersect(SkRect::Make(irect));
37 }
38
csmartdaltonbf4a8f92016-09-06 10:01:06 -070039 void addWindowRectangles(const GrWindowRectsState& windowState) {
40 SkASSERT(!fWindowRectsState.enabled());
41 fWindowRectsState = windowState;
42 }
43
44 void addWindowRectangles(const GrWindowRectangles& windows, const SkIPoint& origin,
45 GrWindowRectsState::Mode mode) {
46 SkASSERT(!fWindowRectsState.enabled());
47 fWindowRectsState.set(windows, origin, mode);
csmartdalton28341fa2016-08-17 10:00:21 -070048 }
49
50 void addCoverageFP(sk_sp<GrFragmentProcessor> fp) {
51 SkASSERT(!fClipCoverageFP);
52 fClipCoverageFP = fp;
53 }
54
55 void addStencilClip() {
56 SkASSERT(!fHasStencilClip);
57 fHasStencilClip = true;
58 }
59
60 /**
61 * Returns the device bounds of the draw after clip has been applied. TODO: Ideally this would
62 * consider the combined effect of all clipping techniques in play (scissor, stencil, fp, etc.).
63 */
64 const SkRect& clippedDrawBounds() const { return fClippedDrawBounds; }
65
66private:
67 GrScissorState fScissorState;
csmartdaltonbf4a8f92016-09-06 10:01:06 -070068 GrWindowRectsState fWindowRectsState;
csmartdalton28341fa2016-08-17 10:00:21 -070069 sk_sp<GrFragmentProcessor> fClipCoverageFP;
70 bool fHasStencilClip;
71 SkRect fClippedDrawBounds;
72 typedef SkNoncopyable INHERITED;
73};
74
75#endif