blob: e551f9b966ba0938379bc321abc571e44d4b4af0 [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 }
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
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 }
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);
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
Brian Salomon97180af2017-03-14 13:42:58 -040048bool GrFixedClip::apply(GrContext*, GrRenderTargetContext* rtc, bool, bool, GrAppliedClip* out,
49 SkRect* bounds) const {
csmartdaltonbf4a8f92016-09-06 10:01:06 -070050 if (fScissorState.enabled()) {
Robert Phillips784b7bf2016-12-09 13:35:02 -050051 SkIRect tightScissor = SkIRect::MakeWH(rtc->width(), rtc->height());
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}