blob: d74d93558597030f7fde31fa06c66d7aa857ff07 [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
cdalton846c0512016-05-13 10:25:00 -070010#include "GrClipMaskManager.h"
robertphillips976f5f02016-06-03 10:59:20 -070011#include "GrDrawContext.h"
joshualitt44701df2015-02-23 14:44:57 -080012
cdalton846c0512016-05-13 10:25:00 -070013void GrNoClip::getConservativeBounds(int width, int height, SkIRect* devResult,
14 bool* isIntersectionOfRects) const {
15 devResult->setXYWH(0, 0, width, height);
16 if (isIntersectionOfRects) {
17 *isIntersectionOfRects = true;
joshualitt44701df2015-02-23 14:44:57 -080018 }
19}
joshualitt9ece6a92015-02-23 17:03:33 -080020
cdalton846c0512016-05-13 10:25:00 -070021bool GrFixedClip::quickContains(const SkRect& rect) const {
22 if (fHasStencilClip) {
23 return false;
24 }
25 if (!fScissorState.enabled()) {
26 return true;
27 }
28 return fScissorState.rect().contains(rect);
29}
30
31void GrFixedClip::getConservativeBounds(int width, int height, SkIRect* devResult,
32 bool* isIntersectionOfRects) const {
33 devResult->setXYWH(0, 0, width, height);
34 if (fScissorState.enabled()) {
35 if (!devResult->intersect(fScissorState.rect())) {
36 devResult->setEmpty();
37 }
38 }
39 if (isIntersectionOfRects) {
40 *isIntersectionOfRects = true;
41 }
42}
43
robertphillips976f5f02016-06-03 10:59:20 -070044bool GrFixedClip::apply(GrContext*, const GrPipelineBuilder& pipelineBuilder,
45 GrDrawContext* drawContext,
cdalton846c0512016-05-13 10:25:00 -070046 const SkRect* devBounds, GrAppliedClip* out) const {
47 if (fScissorState.enabled()) {
cdalton846c0512016-05-13 10:25:00 -070048 SkIRect tightScissor;
49 if (!tightScissor.intersect(fScissorState.rect(),
robertphillips976f5f02016-06-03 10:59:20 -070050 SkIRect::MakeWH(drawContext->width(), drawContext->height()))) {
cdalton846c0512016-05-13 10:25:00 -070051 return false;
52 }
53 if (devBounds && !devBounds->intersects(SkRect::Make(tightScissor))) {
54 return false;
55 }
robertphillips5f2fa472016-05-19 11:36:25 -070056 out->makeScissoredStencil(fHasStencilClip, tightScissor);
57 return true;
cdalton846c0512016-05-13 10:25:00 -070058 }
robertphillips5f2fa472016-05-19 11:36:25 -070059
60 out->makeStencil(fHasStencilClip);
cdalton846c0512016-05-13 10:25:00 -070061 return true;
62}
63
64bool GrClipStackClip::quickContains(const SkRect& rect) const {
65 if (!fStack) {
66 return true;
67 }
68 return fStack->quickContains(rect.makeOffset(SkIntToScalar(fOrigin.x()),
69 SkIntToScalar(fOrigin.y())));
70}
71
72void GrClipStackClip::getConservativeBounds(int width, int height, SkIRect* devResult,
73 bool* isIntersectionOfRects) const {
74 if (!fStack) {
75 devResult->setXYWH(0, 0, width, height);
76 if (isIntersectionOfRects) {
77 *isIntersectionOfRects = true;
78 }
79 return;
80 }
81 SkRect devBounds;
82 fStack->getConservativeBounds(-fOrigin.x(), -fOrigin.y(), width, height, &devBounds,
83 isIntersectionOfRects);
84 devBounds.roundOut(devResult);
85}
86
robertphillips976f5f02016-06-03 10:59:20 -070087bool GrClipStackClip::apply(GrContext* context,
88 const GrPipelineBuilder& pipelineBuilder, GrDrawContext* drawContext,
89 const SkRect* devBounds, GrAppliedClip* out) const {
90 return GrClipMaskManager::SetupClipping(context, pipelineBuilder, drawContext,
91 *this, devBounds, out);
joshualitt9ece6a92015-02-23 17:03:33 -080092}