blob: ef9c9cdfa6b275028237c754f695ef977f6a34bf [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
8#include "GrClip.h"
9
robertphillips976f5f02016-06-03 10:59:20 -070010#include "GrDrawContext.h"
joshualitt44701df2015-02-23 14:44:57 -080011
cdalton846c0512016-05-13 10:25:00 -070012void GrNoClip::getConservativeBounds(int width, int height, SkIRect* devResult,
13 bool* isIntersectionOfRects) const {
14 devResult->setXYWH(0, 0, width, height);
15 if (isIntersectionOfRects) {
16 *isIntersectionOfRects = true;
joshualitt44701df2015-02-23 14:44:57 -080017 }
18}
joshualitt9ece6a92015-02-23 17:03:33 -080019
cdalton846c0512016-05-13 10:25:00 -070020bool GrFixedClip::quickContains(const SkRect& rect) const {
21 if (fHasStencilClip) {
22 return false;
23 }
csmartdaltond211e782016-08-15 11:17:19 -070024 return !fScissorState.enabled() || GrClip::IsInsideClip(fScissorState.rect(), rect);
cdalton846c0512016-05-13 10:25:00 -070025}
26
27void GrFixedClip::getConservativeBounds(int width, int height, SkIRect* devResult,
28 bool* isIntersectionOfRects) const {
29 devResult->setXYWH(0, 0, width, height);
30 if (fScissorState.enabled()) {
31 if (!devResult->intersect(fScissorState.rect())) {
32 devResult->setEmpty();
33 }
34 }
35 if (isIntersectionOfRects) {
36 *isIntersectionOfRects = true;
37 }
38}
39
csmartdaltond211e782016-08-15 11:17:19 -070040bool GrFixedClip::apply(GrContext*, GrDrawContext* drawContext, bool isHWAntiAlias,
41 bool hasUserStencilSettings, GrAppliedClip* out) const {
cdalton846c0512016-05-13 10:25:00 -070042 if (fScissorState.enabled()) {
cdalton846c0512016-05-13 10:25:00 -070043 SkIRect tightScissor;
44 if (!tightScissor.intersect(fScissorState.rect(),
robertphillips976f5f02016-06-03 10:59:20 -070045 SkIRect::MakeWH(drawContext->width(), drawContext->height()))) {
cdalton846c0512016-05-13 10:25:00 -070046 return false;
47 }
csmartdaltond211e782016-08-15 11:17:19 -070048 if (IsOutsideClip(tightScissor, out->clippedDrawBounds())) {
cdalton846c0512016-05-13 10:25:00 -070049 return false;
50 }
csmartdaltond211e782016-08-15 11:17:19 -070051 if (!IsInsideClip(fScissorState.rect(), out->clippedDrawBounds())) {
52 out->addScissor(tightScissor);
bsalomon6cc90062016-07-08 11:31:22 -070053 }
cdalton846c0512016-05-13 10:25:00 -070054 }
robertphillips5f2fa472016-05-19 11:36:25 -070055
csmartdaltond211e782016-08-15 11:17:19 -070056 if (fHasStencilClip) {
57 out->addStencilClip();
58 }
59
cdalton846c0512016-05-13 10:25:00 -070060 return true;
61}