blob: b8413e6df419172a13be12b0f1f9d2b58b1625b2 [file] [log] [blame]
bsalomon@google.com170bd792012-12-05 22:26:11 +00001/*
csmartdalton77f2fae2016-08-08 09:55:06 -07002 * Copyright 2016 Google Inc.
bsalomon@google.com170bd792012-12-05 22:26:11 +00003 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
george9eb182a2014-06-20 12:01:06 -07008#ifndef GrReducedClip_DEFINED
9#define GrReducedClip_DEFINED
10
csmartdaltonbf4a8f92016-09-06 10:01:06 -070011#include "GrWindowRectangles.h"
bsalomon@google.com170bd792012-12-05 22:26:11 +000012#include "SkClipStack.h"
13#include "SkTLList.h"
14
csmartdaltonbde96c62016-08-31 12:54:46 -070015class GrContext;
16class GrDrawContext;
17
csmartdalton77f2fae2016-08-08 09:55:06 -070018/**
19 * This class takes a clip stack and produces a reduced set of elements that are equivalent to
20 * applying that full stack within a specified query rectangle.
21 */
tfarinabf54e492014-10-23 17:47:18 -070022class SK_API GrReducedClip {
23public:
csmartdaltonbf4a8f92016-09-06 10:01:06 -070024 GrReducedClip(const SkClipStack&, const SkRect& queryBounds, int maxWindowRectangles = 0);
csmartdalton77f2fae2016-08-08 09:55:06 -070025
26 /**
csmartdaltonbf4a8f92016-09-06 10:01:06 -070027 * If hasIBounds() is true, this is the bounding box within which the clip elements are valid.
28 * The caller must not modify any pixels outside this box. Undefined if hasIBounds() is false.
csmartdalton77f2fae2016-08-08 09:55:06 -070029 */
csmartdaltond211e782016-08-15 11:17:19 -070030 const SkIRect& ibounds() const { SkASSERT(fHasIBounds); return fIBounds; }
31 int left() const { return this->ibounds().left(); }
32 int top() const { return this->ibounds().top(); }
33 int width() const { return this->ibounds().width(); }
34 int height() const { return this->ibounds().height(); }
35
36 /**
37 * Indicates whether ibounds() are defined. They will always be defined if the elements() are
38 * nonempty.
39 */
40 bool hasIBounds() const { return fHasIBounds; }
csmartdalton77f2fae2016-08-08 09:55:06 -070041
csmartdaltonbf4a8f92016-09-06 10:01:06 -070042 /**
43 * If nonempty, this is a set of "exclusive" windows within which the clip elements are NOT
44 * valid. The caller must not modify any pixels inside these windows.
45 */
46 const GrWindowRectangles& windowRectangles() const { return fWindowRects; }
47
bsalomonf045d602015-11-18 19:01:12 -080048 typedef SkTLList<SkClipStack::Element, 16> ElementList;
bsalomon@google.com170bd792012-12-05 22:26:11 +000049
csmartdalton77f2fae2016-08-08 09:55:06 -070050 /**
csmartdaltonbf4a8f92016-09-06 10:01:06 -070051 * Populated with a minimal list of elements required to fully implement the clip.
csmartdalton77f2fae2016-08-08 09:55:06 -070052 */
53 const ElementList& elements() const { return fElements; }
54
55 /**
csmartdalton8d3f92a2016-08-17 09:39:38 -070056 * If elements() are nonempty, uniquely identifies the list of elements within ibounds().
57 * Otherwise undefined.
58 */
59 int32_t elementsGenID() const { SkASSERT(!fElements.isEmpty()); return fElementsGenID; }
60
61 /**
csmartdalton77f2fae2016-08-08 09:55:06 -070062 * Indicates whether antialiasing is required to process any of the clip elements.
63 */
64 bool requiresAA() const { return fRequiresAA; }
65
66 enum class InitialState : bool {
67 kAllIn,
68 kAllOut
tfarinabf54e492014-10-23 17:47:18 -070069 };
bsalomon@google.com170bd792012-12-05 22:26:11 +000070
csmartdalton77f2fae2016-08-08 09:55:06 -070071 InitialState initialState() const { return fInitialState; }
72
csmartdaltonbde96c62016-08-31 12:54:46 -070073 bool drawAlphaClipMask(GrDrawContext*) const;
74 bool drawStencilClipMask(GrContext*, GrDrawContext*, const SkIPoint& clipOrigin) const;
75
csmartdalton77f2fae2016-08-08 09:55:06 -070076private:
csmartdaltonbf4a8f92016-09-06 10:01:06 -070077 void walkStack(const SkClipStack&, const SkRect& queryBounds, int maxWindowRectangles);
78 void addInteriorWindowRectangles(int maxWindowRectangles);
79 void addWindowRectangle(const SkRect& elementInteriorRect, bool elementIsAA);
csmartdalton5ecbbbe2016-08-23 13:26:40 -070080 bool intersectIBounds(const SkIRect&);
81
csmartdaltonbf4a8f92016-09-06 10:01:06 -070082 SkIRect fIBounds;
83 bool fHasIBounds;
84 GrWindowRectangles fWindowRects;
85 ElementList fElements;
86 int32_t fElementsGenID;
87 bool fRequiresAA;
88 InitialState fInitialState;
bsalomon@google.com170bd792012-12-05 22:26:11 +000089};
90
george9eb182a2014-06-20 12:01:06 -070091#endif