1 /*
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 "src/gpu/GrFixedClip.h"
9 
10 #include "src/gpu/GrAppliedClip.h"
11 
getConservativeBounds() const12 SkIRect GrFixedClip::getConservativeBounds() const {
13     return fScissorState.rect();
14 }
15 
preApply(const SkRect& drawBounds, GrAA aa) const16 GrClip::PreClipResult GrFixedClip::preApply(const SkRect& drawBounds, GrAA aa) const {
17     SkIRect pixelBounds = GetPixelIBounds(drawBounds, aa);
18     if (!SkIRect::Intersects(fScissorState.rect(), pixelBounds)) {
19         return Effect::kClippedOut;
20     }
21 
22     if (fWindowRectsState.enabled()) {
23         return Effect::kClipped;
24     }
25 
26     if (!fScissorState.enabled() || fScissorState.rect().contains(pixelBounds)) {
27         // 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 
apply(GrAppliedHardClip* out, SkIRect* bounds) const34 GrClip::Effect GrFixedClip::apply(GrAppliedHardClip* out, SkIRect* bounds) const {
35     if (!SkIRect::Intersects(fScissorState.rect(), *bounds)) {
36         return Effect::kClippedOut;
37     }
38 
39     Effect effect = Effect::kUnclipped;
40     if (fScissorState.enabled() && !fScissorState.rect().contains(*bounds)) {
41         SkAssertResult(bounds->intersect(fScissorState.rect()));
42         out->setScissor(*bounds);
43         effect = Effect::kClipped;
44     }
45 
46     if (fWindowRectsState.enabled()) {
47         out->addWindowRectangles(fWindowRectsState);
48         // We could iterate each window rectangle to check for intersection, but be conservative
49         // and report that it's clipped
50         effect = Effect::kClipped;
51     }
52 
53     return effect;
54 }
55