blob: d16f52a946f894079e42b533ffd97a074fa43d99 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "src/gpu/GrFixedClip.h"
joshualitt44701df2015-02-23 14:44:57 -08009
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "src/gpu/GrAppliedClip.h"
joshualitt44701df2015-02-23 14:44:57 -080011
Michael Ludwige06a8972020-06-11 10:29:00 -040012SkIRect GrFixedClip::getConservativeBounds() const {
13 return fScissorState.rect();
cdalton846c0512016-05-13 10:25:00 -070014}
15
Michael Ludwig6397e802020-08-05 15:50:01 -040016GrClip::PreClipResult GrFixedClip::preApply(const SkRect& drawBounds, GrAA aa) const {
17 SkIRect pixelBounds = GetPixelIBounds(drawBounds, aa);
18 if (!SkIRect::Intersects(fScissorState.rect(), pixelBounds)) {
Michael Ludwig4e3cab72020-06-30 11:12:46 -040019 return Effect::kClippedOut;
Michael Ludwige06a8972020-06-11 10:29:00 -040020 }
Michael Ludwig97164142020-06-24 10:33:43 -040021
Michael Ludwig4e3cab72020-06-30 11:12:46 -040022 if (fWindowRectsState.enabled()) {
23 return Effect::kClipped;
Michael Ludwig97164142020-06-24 10:33:43 -040024 }
Michael Ludwig4e3cab72020-06-30 11:12:46 -040025
Michael Ludwig6397e802020-08-05 15:50:01 -040026 if (!fScissorState.enabled() || fScissorState.rect().contains(pixelBounds)) {
Michael Ludwig4e3cab72020-06-30 11:12:46 -040027 // Either no scissor or the scissor doesn't clip the draw
28 return Effect::kUnclipped;
29 }
30 // Report the scissor as a degenerate round rect
31 return {SkRect::Make(fScissorState.rect()), GrAA::kNo};
32}
33
Michael Ludwig6397e802020-08-05 15:50:01 -040034GrClip::Effect GrFixedClip::apply(GrAppliedHardClip* out, SkIRect* bounds) const {
35 if (!SkIRect::Intersects(fScissorState.rect(), *bounds)) {
Michael Ludwig4e3cab72020-06-30 11:12:46 -040036 return Effect::kClippedOut;
37 }
38
39 Effect effect = Effect::kUnclipped;
Michael Ludwig6397e802020-08-05 15:50:01 -040040 if (fScissorState.enabled() && !fScissorState.rect().contains(*bounds)) {
41 SkAssertResult(bounds->intersect(fScissorState.rect()));
42 out->setScissor(*bounds);
Michael Ludwig4e3cab72020-06-30 11:12:46 -040043 effect = Effect::kClipped;
cdalton846c0512016-05-13 10:25:00 -070044 }
robertphillips5f2fa472016-05-19 11:36:25 -070045
csmartdaltonbf4a8f92016-09-06 10:01:06 -070046 if (fWindowRectsState.enabled()) {
47 out->addWindowRectangles(fWindowRectsState);
Michael Ludwig4e3cab72020-06-30 11:12:46 -040048 // We could iterate each window rectangle to check for intersection, but be conservative
49 // and report that it's clipped
50 effect = Effect::kClipped;
csmartdaltonbf4a8f92016-09-06 10:01:06 -070051 }
52
Michael Ludwig4e3cab72020-06-30 11:12:46 -040053 return effect;
cdalton846c0512016-05-13 10:25:00 -070054}