joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 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 | |
csmartdalton | 02fa32c | 2016-08-19 13:29:27 -0700 | [diff] [blame^] | 8 | #include "GrFixedClip.h" |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 9 | |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 10 | #include "GrAppliedClip.h" |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 11 | #include "GrDrawContext.h" |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 12 | |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 13 | bool GrFixedClip::quickContains(const SkRect& rect) const { |
| 14 | if (fHasStencilClip) { |
| 15 | return false; |
| 16 | } |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 17 | return !fScissorState.enabled() || GrClip::IsInsideClip(fScissorState.rect(), rect); |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 18 | } |
| 19 | |
| 20 | void GrFixedClip::getConservativeBounds(int width, int height, SkIRect* devResult, |
| 21 | bool* isIntersectionOfRects) const { |
| 22 | devResult->setXYWH(0, 0, width, height); |
| 23 | if (fScissorState.enabled()) { |
| 24 | if (!devResult->intersect(fScissorState.rect())) { |
| 25 | devResult->setEmpty(); |
| 26 | } |
| 27 | } |
| 28 | if (isIntersectionOfRects) { |
| 29 | *isIntersectionOfRects = true; |
| 30 | } |
| 31 | } |
| 32 | |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 33 | bool GrFixedClip::apply(GrContext*, GrDrawContext* drawContext, bool isHWAntiAlias, |
| 34 | bool hasUserStencilSettings, GrAppliedClip* out) const { |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 35 | if (fScissorState.enabled()) { |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 36 | SkIRect tightScissor; |
| 37 | if (!tightScissor.intersect(fScissorState.rect(), |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 38 | SkIRect::MakeWH(drawContext->width(), drawContext->height()))) { |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 39 | return false; |
| 40 | } |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 41 | if (IsOutsideClip(tightScissor, out->clippedDrawBounds())) { |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 42 | return false; |
| 43 | } |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 44 | if (!IsInsideClip(fScissorState.rect(), out->clippedDrawBounds())) { |
| 45 | out->addScissor(tightScissor); |
bsalomon | 6cc9006 | 2016-07-08 11:31:22 -0700 | [diff] [blame] | 46 | } |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 47 | } |
robertphillips | 5f2fa47 | 2016-05-19 11:36:25 -0700 | [diff] [blame] | 48 | |
csmartdalton | d211e78 | 2016-08-15 11:17:19 -0700 | [diff] [blame] | 49 | if (fHasStencilClip) { |
| 50 | out->addStencilClip(); |
| 51 | } |
| 52 | |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 53 | return true; |
| 54 | } |