Andrew Top | 200ce4b | 2018-01-29 13:43:50 -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 | |
Xiaoming Shi | 73dfa20 | 2020-03-12 11:31:35 -0700 | [diff] [blame] | 8 | #include "src/gpu/GrFixedClip.h" |
Andrew Top | 200ce4b | 2018-01-29 13:43:50 -0800 | [diff] [blame] | 9 | |
Xiaoming Shi | 73dfa20 | 2020-03-12 11:31:35 -0700 | [diff] [blame] | 10 | #include "src/gpu/GrAppliedClip.h" |
| 11 | #include "src/gpu/GrRenderTargetContext.h" |
Andrew Top | 200ce4b | 2018-01-29 13:43:50 -0800 | [diff] [blame] | 12 | |
| 13 | bool GrFixedClip::quickContains(const SkRect& rect) const { |
| 14 | if (fWindowRectsState.enabled()) { |
| 15 | return false; |
| 16 | } |
| 17 | return !fScissorState.enabled() || GrClip::IsInsideClip(fScissorState.rect(), rect); |
| 18 | } |
| 19 | |
| 20 | void GrFixedClip::getConservativeBounds(int w, int h, SkIRect* devResult, bool* iior) const { |
| 21 | devResult->setXYWH(0, 0, w, h); |
| 22 | if (fScissorState.enabled()) { |
| 23 | if (!devResult->intersect(fScissorState.rect())) { |
| 24 | devResult->setEmpty(); |
| 25 | } |
| 26 | } |
| 27 | if (iior) { |
| 28 | *iior = true; |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | bool GrFixedClip::isRRect(const SkRect& rtBounds, SkRRect* rr, GrAA* aa) const { |
| 33 | if (fWindowRectsState.enabled()) { |
| 34 | return false; |
| 35 | } |
| 36 | if (fScissorState.enabled()) { |
| 37 | SkRect rect = SkRect::Make(fScissorState.rect()); |
| 38 | if (!rect.intersects(rtBounds)) { |
| 39 | return false; |
| 40 | } |
| 41 | rr->setRect(rect); |
| 42 | *aa = GrAA::kNo; |
| 43 | return true; |
| 44 | } |
| 45 | return false; |
| 46 | }; |
| 47 | |
Xiaoming Shi | 73dfa20 | 2020-03-12 11:31:35 -0700 | [diff] [blame] | 48 | bool GrFixedClip::apply(int rtWidth, int rtHeight, GrAppliedHardClip* out, SkRect* bounds) const { |
Andrew Top | 200ce4b | 2018-01-29 13:43:50 -0800 | [diff] [blame] | 49 | if (fScissorState.enabled()) { |
Xiaoming Shi | 73dfa20 | 2020-03-12 11:31:35 -0700 | [diff] [blame] | 50 | SkIRect tightScissor = SkIRect::MakeWH(rtWidth, rtHeight); |
Andrew Top | 200ce4b | 2018-01-29 13:43:50 -0800 | [diff] [blame] | 51 | if (!tightScissor.intersect(fScissorState.rect())) { |
| 52 | return false; |
| 53 | } |
| 54 | if (IsOutsideClip(tightScissor, *bounds)) { |
| 55 | return false; |
| 56 | } |
| 57 | if (!IsInsideClip(fScissorState.rect(), *bounds)) { |
| 58 | out->addScissor(tightScissor, bounds); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | if (fWindowRectsState.enabled()) { |
| 63 | out->addWindowRectangles(fWindowRectsState); |
| 64 | } |
| 65 | |
| 66 | return true; |
| 67 | } |
| 68 | |
| 69 | const GrFixedClip& GrFixedClip::Disabled() { |
| 70 | static const GrFixedClip disabled = GrFixedClip(); |
| 71 | return disabled; |
| 72 | } |