blob: 94a89fd0346f5b927fb1c7779da2fe95898ebb43 [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"
Brian Osman11052242016-10-27 14:47:55 -040011#include "GrRenderTargetContext.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 }
Brian Salomond818ebf2018-07-02 14:08:49 +000017 return !fScissorState.enabled() || GrClip::IsInsideClip(fScissorState.rect(), rect);
csmartdaltonbf4a8f92016-09-06 10:01:06 -070018}
19
20void GrFixedClip::getConservativeBounds(int w, int h, SkIRect* devResult, bool* iior) const {
21 devResult->setXYWH(0, 0, w, h);
Brian Salomond818ebf2018-07-02 14:08:49 +000022 if (fScissorState.enabled()) {
cdalton846c0512016-05-13 10:25:00 -070023 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
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050032bool GrFixedClip::isRRect(const SkRect& rtBounds, SkRRect* rr, GrAA* aa) const {
csmartdaltonbf4a8f92016-09-06 10:01:06 -070033 if (fWindowRectsState.enabled()) {
34 return false;
35 }
Brian Salomond818ebf2018-07-02 14:08:49 +000036 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);
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050042 *aa = GrAA::kNo;
csmartdaltonbf4a8f92016-09-06 10:01:06 -070043 return true;
44 }
45 return false;
46};
47
Chris Daltonbbfd5162017-11-07 13:35:22 -070048bool GrFixedClip::apply(int rtWidth, int rtHeight, GrAppliedHardClip* out, SkRect* bounds) const {
Brian Salomond818ebf2018-07-02 14:08:49 +000049 if (fScissorState.enabled()) {
Chris Daltonbbfd5162017-11-07 13:35:22 -070050 SkIRect tightScissor = SkIRect::MakeWH(rtWidth, rtHeight);
csmartdaltonbf4a8f92016-09-06 10:01:06 -070051 if (!tightScissor.intersect(fScissorState.rect())) {
cdalton846c0512016-05-13 10:25:00 -070052 return false;
53 }
Brian Salomon97180af2017-03-14 13:42:58 -040054 if (IsOutsideClip(tightScissor, *bounds)) {
cdalton846c0512016-05-13 10:25:00 -070055 return false;
56 }
Brian Salomon97180af2017-03-14 13:42:58 -040057 if (!IsInsideClip(fScissorState.rect(), *bounds)) {
58 out->addScissor(tightScissor, bounds);
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}