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