blob: f55a2499b47e8340b45c33f94338c2e04a0548e9 [file] [log] [blame]
joshualitt44701df2015-02-23 14:44:57 -08001/*
2 * Copyright 2010 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#include "GrClip.h"
9
cdalton846c0512016-05-13 10:25:00 -070010#include "GrClipMaskManager.h"
robertphillips976f5f02016-06-03 10:59:20 -070011#include "GrDrawContext.h"
joshualitt44701df2015-02-23 14:44:57 -080012
cdalton846c0512016-05-13 10:25:00 -070013void GrNoClip::getConservativeBounds(int width, int height, SkIRect* devResult,
14 bool* isIntersectionOfRects) const {
15 devResult->setXYWH(0, 0, width, height);
16 if (isIntersectionOfRects) {
17 *isIntersectionOfRects = true;
joshualitt44701df2015-02-23 14:44:57 -080018 }
19}
joshualitt9ece6a92015-02-23 17:03:33 -080020
cdalton846c0512016-05-13 10:25:00 -070021bool GrFixedClip::quickContains(const SkRect& rect) const {
22 if (fHasStencilClip) {
23 return false;
24 }
25 if (!fScissorState.enabled()) {
26 return true;
27 }
28 return fScissorState.rect().contains(rect);
29}
30
31void GrFixedClip::getConservativeBounds(int width, int height, SkIRect* devResult,
32 bool* isIntersectionOfRects) const {
33 devResult->setXYWH(0, 0, width, height);
34 if (fScissorState.enabled()) {
35 if (!devResult->intersect(fScissorState.rect())) {
36 devResult->setEmpty();
37 }
38 }
39 if (isIntersectionOfRects) {
40 *isIntersectionOfRects = true;
41 }
42}
43
robertphillips59cf61a2016-07-13 09:18:21 -070044bool GrFixedClip::apply(GrContext*,
robertphillips976f5f02016-06-03 10:59:20 -070045 GrDrawContext* drawContext,
robertphillips59cf61a2016-07-13 09:18:21 -070046 const SkRect* devBounds,
47 bool isHWAntiAlias,
48 bool hasUserStencilSettings,
49 GrAppliedClip* out) const {
bsalomon6cc90062016-07-08 11:31:22 -070050 SkASSERT(!fDeviceBounds.isLargest());
cdalton846c0512016-05-13 10:25:00 -070051 if (fScissorState.enabled()) {
cdalton846c0512016-05-13 10:25:00 -070052 SkIRect tightScissor;
53 if (!tightScissor.intersect(fScissorState.rect(),
robertphillips976f5f02016-06-03 10:59:20 -070054 SkIRect::MakeWH(drawContext->width(), drawContext->height()))) {
cdalton846c0512016-05-13 10:25:00 -070055 return false;
56 }
57 if (devBounds && !devBounds->intersects(SkRect::Make(tightScissor))) {
58 return false;
59 }
msarettba3880f2016-07-12 18:48:21 -070060 if (fHasStencilClip) {
61 out->makeScissoredStencil(tightScissor, &fDeviceBounds);
62 } else {
63 out->makeScissored(tightScissor);
bsalomon6cc90062016-07-08 11:31:22 -070064 }
msarettba3880f2016-07-12 18:48:21 -070065 return true;
cdalton846c0512016-05-13 10:25:00 -070066 }
robertphillips5f2fa472016-05-19 11:36:25 -070067
bsalomon6cc90062016-07-08 11:31:22 -070068 out->makeStencil(fHasStencilClip, fDeviceBounds);
cdalton846c0512016-05-13 10:25:00 -070069 return true;
70}
71
72bool GrClipStackClip::quickContains(const SkRect& rect) const {
73 if (!fStack) {
74 return true;
75 }
76 return fStack->quickContains(rect.makeOffset(SkIntToScalar(fOrigin.x()),
77 SkIntToScalar(fOrigin.y())));
78}
79
80void GrClipStackClip::getConservativeBounds(int width, int height, SkIRect* devResult,
81 bool* isIntersectionOfRects) const {
82 if (!fStack) {
83 devResult->setXYWH(0, 0, width, height);
84 if (isIntersectionOfRects) {
85 *isIntersectionOfRects = true;
86 }
87 return;
88 }
89 SkRect devBounds;
90 fStack->getConservativeBounds(-fOrigin.x(), -fOrigin.y(), width, height, &devBounds,
91 isIntersectionOfRects);
92 devBounds.roundOut(devResult);
93}
94
robertphillips976f5f02016-06-03 10:59:20 -070095bool GrClipStackClip::apply(GrContext* context,
robertphillips59cf61a2016-07-13 09:18:21 -070096 GrDrawContext* drawContext,
97 const SkRect* devBounds,
98 bool useHWAA,
99 bool hasUserStencilSettings,
100 GrAppliedClip* out) const {
101 return GrClipMaskManager::SetupClipping(context, drawContext, *this, devBounds,
102 useHWAA, hasUserStencilSettings, out);
joshualitt9ece6a92015-02-23 17:03:33 -0800103}