blob: 156686e5df1dffebbb52e6c35dcb88b3cc432609 [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"
Brian Salomoneebe7352020-12-09 16:37:04 -050011#include "src/gpu/GrSurfaceDrawContext.h"
joshualitt44701df2015-02-23 14:44:57 -080012
Michael Ludwige06a8972020-06-11 10:29:00 -040013SkIRect GrFixedClip::getConservativeBounds() const {
14 return fScissorState.rect();
cdalton846c0512016-05-13 10:25:00 -070015}
16
Michael Ludwig6397e802020-08-05 15:50:01 -040017GrClip::PreClipResult GrFixedClip::preApply(const SkRect& drawBounds, GrAA aa) const {
18 SkIRect pixelBounds = GetPixelIBounds(drawBounds, aa);
19 if (!SkIRect::Intersects(fScissorState.rect(), pixelBounds)) {
Michael Ludwig4e3cab72020-06-30 11:12:46 -040020 return Effect::kClippedOut;
Michael Ludwige06a8972020-06-11 10:29:00 -040021 }
Michael Ludwig97164142020-06-24 10:33:43 -040022
Michael Ludwig4e3cab72020-06-30 11:12:46 -040023 if (fWindowRectsState.enabled()) {
24 return Effect::kClipped;
Michael Ludwig97164142020-06-24 10:33:43 -040025 }
Michael Ludwig4e3cab72020-06-30 11:12:46 -040026
Michael Ludwig6397e802020-08-05 15:50:01 -040027 if (!fScissorState.enabled() || fScissorState.rect().contains(pixelBounds)) {
Michael Ludwig4e3cab72020-06-30 11:12:46 -040028 // Either no scissor or the scissor doesn't clip the draw
29 return Effect::kUnclipped;
30 }
31 // Report the scissor as a degenerate round rect
32 return {SkRect::Make(fScissorState.rect()), GrAA::kNo};
33}
34
Michael Ludwig6397e802020-08-05 15:50:01 -040035GrClip::Effect GrFixedClip::apply(GrAppliedHardClip* out, SkIRect* bounds) const {
36 if (!SkIRect::Intersects(fScissorState.rect(), *bounds)) {
Michael Ludwig4e3cab72020-06-30 11:12:46 -040037 return Effect::kClippedOut;
38 }
39
40 Effect effect = Effect::kUnclipped;
Michael Ludwig6397e802020-08-05 15:50:01 -040041 if (fScissorState.enabled() && !fScissorState.rect().contains(*bounds)) {
42 SkAssertResult(bounds->intersect(fScissorState.rect()));
43 out->setScissor(*bounds);
Michael Ludwig4e3cab72020-06-30 11:12:46 -040044 effect = Effect::kClipped;
cdalton846c0512016-05-13 10:25:00 -070045 }
robertphillips5f2fa472016-05-19 11:36:25 -070046
csmartdaltonbf4a8f92016-09-06 10:01:06 -070047 if (fWindowRectsState.enabled()) {
48 out->addWindowRectangles(fWindowRectsState);
Michael Ludwig4e3cab72020-06-30 11:12:46 -040049 // We could iterate each window rectangle to check for intersection, but be conservative
50 // and report that it's clipped
51 effect = Effect::kClipped;
csmartdaltonbf4a8f92016-09-06 10:01:06 -070052 }
53
Michael Ludwig4e3cab72020-06-30 11:12:46 -040054 return effect;
cdalton846c0512016-05-13 10:25:00 -070055}