blob: 7eee3941f26ba2ec938c8c9079737be72667ca96 [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 Salomona2194192018-07-02 09:00:27 -040017 return fScissorState.scissorTest() == GrScissorTest::kDisabled ||
18 GrClip::IsInsideClip(fScissorState.rect(), rect);
csmartdaltonbf4a8f92016-09-06 10:01:06 -070019}
20
21void GrFixedClip::getConservativeBounds(int w, int h, SkIRect* devResult, bool* iior) const {
22 devResult->setXYWH(0, 0, w, h);
Brian Salomona2194192018-07-02 09:00:27 -040023 if (fScissorState.scissorTest() == GrScissorTest::kEnabled) {
cdalton846c0512016-05-13 10:25:00 -070024 if (!devResult->intersect(fScissorState.rect())) {
25 devResult->setEmpty();
26 }
27 }
csmartdaltonbf4a8f92016-09-06 10:01:06 -070028 if (iior) {
29 *iior = true;
cdalton846c0512016-05-13 10:25:00 -070030 }
31}
32
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050033bool GrFixedClip::isRRect(const SkRect& rtBounds, SkRRect* rr, GrAA* aa) const {
csmartdaltonbf4a8f92016-09-06 10:01:06 -070034 if (fWindowRectsState.enabled()) {
35 return false;
36 }
Brian Salomona2194192018-07-02 09:00:27 -040037 if (fScissorState.scissorTest() == GrScissorTest::kEnabled) {
csmartdaltonbf4a8f92016-09-06 10:01:06 -070038 SkRect rect = SkRect::Make(fScissorState.rect());
39 if (!rect.intersects(rtBounds)) {
40 return false;
41 }
42 rr->setRect(rect);
Brian Salomon0e8fc8b2016-12-09 15:10:07 -050043 *aa = GrAA::kNo;
csmartdaltonbf4a8f92016-09-06 10:01:06 -070044 return true;
45 }
46 return false;
47};
48
Chris Daltonbbfd5162017-11-07 13:35:22 -070049bool GrFixedClip::apply(int rtWidth, int rtHeight, GrAppliedHardClip* out, SkRect* bounds) const {
Brian Salomona2194192018-07-02 09:00:27 -040050 if (fScissorState.scissorTest() == GrScissorTest::kEnabled) {
Chris Daltonbbfd5162017-11-07 13:35:22 -070051 SkIRect tightScissor = SkIRect::MakeWH(rtWidth, rtHeight);
csmartdaltonbf4a8f92016-09-06 10:01:06 -070052 if (!tightScissor.intersect(fScissorState.rect())) {
cdalton846c0512016-05-13 10:25:00 -070053 return false;
54 }
Brian Salomon97180af2017-03-14 13:42:58 -040055 if (IsOutsideClip(tightScissor, *bounds)) {
cdalton846c0512016-05-13 10:25:00 -070056 return false;
57 }
Brian Salomon97180af2017-03-14 13:42:58 -040058 if (!IsInsideClip(fScissorState.rect(), *bounds)) {
59 out->addScissor(tightScissor, bounds);
bsalomon6cc90062016-07-08 11:31:22 -070060 }
cdalton846c0512016-05-13 10:25:00 -070061 }
robertphillips5f2fa472016-05-19 11:36:25 -070062
csmartdaltonbf4a8f92016-09-06 10:01:06 -070063 if (fWindowRectsState.enabled()) {
64 out->addWindowRectangles(fWindowRectsState);
65 }
66
cdalton846c0512016-05-13 10:25:00 -070067 return true;
68}
csmartdalton29df7602016-08-31 11:55:52 -070069
70const GrFixedClip& GrFixedClip::Disabled() {
71 static const GrFixedClip disabled = GrFixedClip();
72 return disabled;
73}