blob: 7385028bafb0197e61baae0f8bac1372259368d4 [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
csmartdalton02fa32c2016-08-19 13:29:27 -07008#include "GrFixedClip.h"
joshualitt44701df2015-02-23 14:44:57 -08009
csmartdalton28341fa2016-08-17 10:00:21 -070010#include "GrAppliedClip.h"
robertphillips976f5f02016-06-03 10:59:20 -070011#include "GrDrawContext.h"
joshualitt44701df2015-02-23 14:44:57 -080012
csmartdaltonbf4a8f92016-09-06 10:01:06 -070013bool GrFixedClip::quickContains(const SkRect& rect) const {
14 if (fWindowRectsState.enabled()) {
15 return false;
16 }
17 return !fScissorState.enabled() || GrClip::IsInsideClip(fScissorState.rect(), rect);
18}
19
20void GrFixedClip::getConservativeBounds(int w, int h, SkIRect* devResult, bool* iior) const {
21 devResult->setXYWH(0, 0, w, h);
cdalton846c0512016-05-13 10:25:00 -070022 if (fScissorState.enabled()) {
23 if (!devResult->intersect(fScissorState.rect())) {
24 devResult->setEmpty();
25 }
26 }
csmartdaltonbf4a8f92016-09-06 10:01:06 -070027 if (iior) {
28 *iior = true;
cdalton846c0512016-05-13 10:25:00 -070029 }
30}
31
csmartdaltonbf4a8f92016-09-06 10:01:06 -070032bool GrFixedClip::isRRect(const SkRect& rtBounds, SkRRect* rr, bool* aa) const {
33 if (fWindowRectsState.enabled()) {
34 return false;
35 }
cdalton846c0512016-05-13 10:25:00 -070036 if (fScissorState.enabled()) {
csmartdaltonbf4a8f92016-09-06 10:01:06 -070037 SkRect rect = SkRect::Make(fScissorState.rect());
38 if (!rect.intersects(rtBounds)) {
39 return false;
40 }
41 rr->setRect(rect);
42 *aa = false;
43 return true;
44 }
45 return false;
46};
47
48bool GrFixedClip::apply(GrContext*, GrDrawContext* dc, bool, bool, GrAppliedClip* out) const {
49 if (fScissorState.enabled()) {
50 SkIRect tightScissor = SkIRect::MakeWH(dc->width(), dc->height());
51 if (!tightScissor.intersect(fScissorState.rect())) {
cdalton846c0512016-05-13 10:25:00 -070052 return false;
53 }
csmartdaltond211e782016-08-15 11:17:19 -070054 if (IsOutsideClip(tightScissor, out->clippedDrawBounds())) {
cdalton846c0512016-05-13 10:25:00 -070055 return false;
56 }
csmartdaltond211e782016-08-15 11:17:19 -070057 if (!IsInsideClip(fScissorState.rect(), out->clippedDrawBounds())) {
58 out->addScissor(tightScissor);
bsalomon6cc90062016-07-08 11:31:22 -070059 }
cdalton846c0512016-05-13 10:25:00 -070060 }
robertphillips5f2fa472016-05-19 11:36:25 -070061
csmartdaltonbf4a8f92016-09-06 10:01:06 -070062 if (fWindowRectsState.enabled()) {
63 out->addWindowRectangles(fWindowRectsState);
64 }
65
cdalton846c0512016-05-13 10:25:00 -070066 return true;
67}
csmartdalton29df7602016-08-31 11:55:52 -070068
69const GrFixedClip& GrFixedClip::Disabled() {
70 static const GrFixedClip disabled = GrFixedClip();
71 return disabled;
72}