blob: 3eccd801b5f5f7ed6810ff0e343ab73ee867f9f6 [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 }
24 if (!fScissorState.enabled()) {
25 return true;
26 }
27 return fScissorState.rect().contains(rect);
28}
29
30void GrFixedClip::getConservativeBounds(int width, int height, SkIRect* devResult,
31 bool* isIntersectionOfRects) const {
32 devResult->setXYWH(0, 0, width, height);
33 if (fScissorState.enabled()) {
34 if (!devResult->intersect(fScissorState.rect())) {
35 devResult->setEmpty();
36 }
37 }
38 if (isIntersectionOfRects) {
39 *isIntersectionOfRects = true;
40 }
41}
42
robertphillips59cf61a2016-07-13 09:18:21 -070043bool GrFixedClip::apply(GrContext*,
robertphillips976f5f02016-06-03 10:59:20 -070044 GrDrawContext* drawContext,
robertphillips59cf61a2016-07-13 09:18:21 -070045 const SkRect* devBounds,
46 bool isHWAntiAlias,
47 bool hasUserStencilSettings,
48 GrAppliedClip* out) const {
bsalomon6cc90062016-07-08 11:31:22 -070049 SkASSERT(!fDeviceBounds.isLargest());
cdalton846c0512016-05-13 10:25:00 -070050 if (fScissorState.enabled()) {
cdalton846c0512016-05-13 10:25:00 -070051 SkIRect tightScissor;
52 if (!tightScissor.intersect(fScissorState.rect(),
robertphillips976f5f02016-06-03 10:59:20 -070053 SkIRect::MakeWH(drawContext->width(), drawContext->height()))) {
cdalton846c0512016-05-13 10:25:00 -070054 return false;
55 }
csmartdaltoncbecb082016-07-22 08:59:08 -070056 if (devBounds && IsOutsideClip(tightScissor, *devBounds)) {
cdalton846c0512016-05-13 10:25:00 -070057 return false;
58 }
csmartdaltoncbecb082016-07-22 08:59:08 -070059 if (!devBounds || !IsInsideClip(fScissorState.rect(), *devBounds)) {
csmartdalton97f6cd52016-07-13 13:37:08 -070060 if (fHasStencilClip) {
61 out->makeScissoredStencil(tightScissor, &fDeviceBounds);
62 } else {
63 out->makeScissored(tightScissor);
64 }
65 return true;
bsalomon6cc90062016-07-08 11:31:22 -070066 }
cdalton846c0512016-05-13 10:25:00 -070067 }
robertphillips5f2fa472016-05-19 11:36:25 -070068
bsalomon6cc90062016-07-08 11:31:22 -070069 out->makeStencil(fHasStencilClip, fDeviceBounds);
cdalton846c0512016-05-13 10:25:00 -070070 return true;
71}