blob: 2977d9d72b23766887fcb2c03072bb61aa665fa2 [file] [log] [blame]
Andrew Top200ce4b2018-01-29 13:43:50 -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
Xiaoming Shi73dfa202020-03-12 11:31:35 -07008#include "src/gpu/GrFixedClip.h"
Andrew Top200ce4b2018-01-29 13:43:50 -08009
Xiaoming Shi73dfa202020-03-12 11:31:35 -070010#include "src/gpu/GrAppliedClip.h"
11#include "src/gpu/GrRenderTargetContext.h"
Andrew Top200ce4b2018-01-29 13:43:50 -080012
13bool 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
20void 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
32bool 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 Shi73dfa202020-03-12 11:31:35 -070048bool GrFixedClip::apply(int rtWidth, int rtHeight, GrAppliedHardClip* out, SkRect* bounds) const {
Andrew Top200ce4b2018-01-29 13:43:50 -080049 if (fScissorState.enabled()) {
Xiaoming Shi73dfa202020-03-12 11:31:35 -070050 SkIRect tightScissor = SkIRect::MakeWH(rtWidth, rtHeight);
Andrew Top200ce4b2018-01-29 13:43:50 -080051 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
69const GrFixedClip& GrFixedClip::Disabled() {
70 static const GrFixedClip disabled = GrFixedClip();
71 return disabled;
72}