blob: c42214b2711e2cff55d20301a3c12e44a3c37189 [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
cdalton846c0512016-05-13 10:25:00 -070013bool GrFixedClip::quickContains(const SkRect& rect) const {
14 if (fHasStencilClip) {
15 return false;
16 }
csmartdaltond211e782016-08-15 11:17:19 -070017 return !fScissorState.enabled() || GrClip::IsInsideClip(fScissorState.rect(), rect);
cdalton846c0512016-05-13 10:25:00 -070018}
19
20void GrFixedClip::getConservativeBounds(int width, int height, SkIRect* devResult,
21 bool* isIntersectionOfRects) const {
22 devResult->setXYWH(0, 0, width, height);
23 if (fScissorState.enabled()) {
24 if (!devResult->intersect(fScissorState.rect())) {
25 devResult->setEmpty();
26 }
27 }
28 if (isIntersectionOfRects) {
29 *isIntersectionOfRects = true;
30 }
31}
32
csmartdaltond211e782016-08-15 11:17:19 -070033bool GrFixedClip::apply(GrContext*, GrDrawContext* drawContext, bool isHWAntiAlias,
34 bool hasUserStencilSettings, GrAppliedClip* out) const {
cdalton846c0512016-05-13 10:25:00 -070035 if (fScissorState.enabled()) {
cdalton846c0512016-05-13 10:25:00 -070036 SkIRect tightScissor;
37 if (!tightScissor.intersect(fScissorState.rect(),
robertphillips976f5f02016-06-03 10:59:20 -070038 SkIRect::MakeWH(drawContext->width(), drawContext->height()))) {
cdalton846c0512016-05-13 10:25:00 -070039 return false;
40 }
csmartdaltond211e782016-08-15 11:17:19 -070041 if (IsOutsideClip(tightScissor, out->clippedDrawBounds())) {
cdalton846c0512016-05-13 10:25:00 -070042 return false;
43 }
csmartdaltond211e782016-08-15 11:17:19 -070044 if (!IsInsideClip(fScissorState.rect(), out->clippedDrawBounds())) {
45 out->addScissor(tightScissor);
bsalomon6cc90062016-07-08 11:31:22 -070046 }
cdalton846c0512016-05-13 10:25:00 -070047 }
robertphillips5f2fa472016-05-19 11:36:25 -070048
csmartdaltond211e782016-08-15 11:17:19 -070049 if (fHasStencilClip) {
50 out->addStencilClip();
51 }
52
cdalton846c0512016-05-13 10:25:00 -070053 return true;
54}